BLGroupElement.hh

Go to the documentation of this file.
00001 //      BLGroupElement.hh
00002 /*
00003 This source file is part of G4beamline, http://g4beamline.muonsinc.com
00004 Copyright (C) 2003,2004,2005,2006 by Tom Roberts, all rights reserved.
00005 
00006 This program is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU General Public License
00008 as published by the Free Software Foundation; either version 2
00009 of the License, or (at your option) any later version.
00010 
00011 This program is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 GNU General Public License for more details.
00015 
00016 http://www.gnu.org/copyleft/gpl.html
00017 */
00018 
00019 #ifndef BLGROUPELEMENT_HH
00020 #define BLGROUPELEMENT_HH
00021 
00022 #include <vector>
00023 #include <map>
00024 #include "G4RotationMatrix.hh"
00025 #include "G4VPhysicalVolume.hh"
00026 #include "BLElement.hh"
00027 
00028 const G4String NO_RENAME("\x01");       // permits "" to be legal rename
00029 
00030 
00031 /**     BLGroupElement - Base class for BLElement-s that can contain other 
00032  *                       BLElement-s
00033  **/
00034 class BLGroupElement : public BLElement {
00035         struct Child { G4RotationMatrix rot; G4ThreeVector offset;
00036                                 BLElement *element; G4String rename; };
00037         std::vector<Child> child;
00038         static std::map<G4String,BLGroupElement*> mapGroupElement;
00039         BLGroupElement& operator=(const BLGroupElement&);       // undefined
00040         // BLGroup grows automatically, so it needs to handle children itself
00041         friend class BLGroup;
00042 public:
00043         /// Default Constructor.
00044         BLGroupElement() : BLElement(), child() { }
00045 
00046         /// Copy Constructor for a BLGroupElement.
00047         BLGroupElement(const BLGroupElement& r) : BLElement(r), child(r.child) { }
00048 
00049         /// Destructor.
00050         ~BLGroupElement() { }
00051 
00052         /// setName() adds this BLGroupElement to mapGroupElement; calls
00053         /// BLElement::setName().
00054         void setName(G4String _name);
00055 
00056         /// getNChildren() returns the number of children.
00057         int getNChildren() { return child.size(); }
00058 
00059         /// constructChildren() will construct the children
00060         /// The enclosing BLGroupElement must already be constructed, so
00061         /// this is normally called at the end of construct().
00062         virtual void constructChildren(G4LogicalVolume *parent, 
00063                         G4String parentName,
00064                         G4RotationMatrix *parentRotation,
00065                         G4ThreeVector parentPosition);
00066 
00067         /// placeChild() will place a child within this GroupElement.
00068         /// The object being placed is rotated wrt the fixed axes of the
00069         /// group's local coordinates.
00070         virtual void placeChild(BLElement* element, G4RotationMatrix *rot,
00071                 G4ThreeVector& offset, G4String rename);
00072 
00073         /// testGeometry() will check that all children are inside this
00074         /// element, and that no children intersect each other. It then
00075         /// calls testGeometry() for any children that are GroupElement-s.
00076         /// npoints is the # of points per child to test.
00077         /// returns the number of errors detected.
00078         int testGeometry(int npoints, G4double tolerance, bool visual=false,
00079                                 G4RotationMatrix rotation=G4RotationMatrix(),
00080                                 G4ThreeVector offset=G4ThreeVector());
00081 
00082         /// isGroupElement() returns true if this is a BLGroupElement.
00083         virtual G4bool isGroupElement() { return true; }
00084 
00085         /// isWithin() tests that a point is within this element, or is
00086         /// within tolerance of being inside.
00087         /// local[] is in local coordinates of this element.
00088         virtual G4bool isWithin(G4ThreeVector &local, G4double tolerance) = 0;
00089 
00090         /// find() will find a GroupElement by name
00091         static BLGroupElement *find(G4String name);
00092 };
00093 
00094 #endif // BLGROUPELEMENT_HH
g4beamline