BLCMDplace Class Reference

Inheritance diagram for BLCMDplace:

BLCommand

List of all members.


Detailed Description

class BLCMDplace implements the place command.

Public Member Functions

 BLCMDplace ()
G4String commandName ()
int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
void defineNamedArgs ()
int handleNamedArgs (BLArgumentMap &namedArgs)
 special version of handleNamedArgs().

Private Attributes

G4double x
G4double y
G4double z
G4String parent
G4String rename
G4String rotation
G4String coordinates
G4int copies
G4int front
BLElementelement

Constructor & Destructor Documentation

BLCMDplace::BLCMDplace (  ) 

References BLCMDTYPE_PLACE, coordinates, copies, element, front, parent, BLCommand::registerCommand(), rename, rotation, BLCommand::setDescription(), BLCommand::setSynopsis(), x, y, and z.

00058 {
00059         registerCommand(BLCMDTYPE_PLACE);
00060         setSynopsis("places an element into the current group (or world).");
00061         setDescription("Every element can be placed multiple times into the\n"
00062                 "beamline. For most elements the geometrical centerpoint is\n"
00063                 "placed; for polycone the local x=y=z=0 point is placed. "
00064                 "If front is nonzero then the front of the element is "
00065                 "placed.\n"
00066                 "If z is specified, then the element is placed\n"
00067                 "at that z position relative to the center of the enclosing\n"
00068                 "group. If z is not specified, then the element is placed\n"
00069                 "immediately downstream (higher z) of the previous element\n"
00070                 "in the group, or at the upstream edge of the group if this\n"
00071                 "is the first element in the group. The 'rename' argument\n"
00072                 "can be used to change the name of the element (mostly for\n"
00073                 "traces, but also applies to other places where names are\n"
00074                 "used). When\n"
00075                 "multiple copies are placed, z refers to the first, and the\n"
00076                 "rest are placed sequentially along z.\n"
00077                 "When placing an element into the World group, Centerline\n"
00078                 "coordinates are used unless coordinates=global is present.\n"
00079                 "When centerline coordinates are used, the parameter 'Zcl' is "
00080                 "set to the highest Z value used; this is normally the Z value "
00081                 "for the front of the next element when placed sequentially "
00082                 "(i.e. with no z value given).\n"
00083                 "\nRotations:\n"
00084                 "The rotation parameter can be used to rotate this element \n"
00085                 "relative to "
00086                 "the enclosing group. The object is rotated, not the axes.\n"
00087                 "Rotations are specified as a comma-separated list of axes\n"
00088                 "and angles (in degrees): rotate=Z90,X45 rotates first by 90\n"
00089                 "degrees around Z and then by 45 degrees around X. The axes\n"
00090                 "are the local X,Y,Z coordinate axes of the enclosing group\n"
00091                 "(centerline or global coordinate axes for the World group);\n"
00092                 "groups can be rotated when placed, and are rotated as a\n"
00093                 "rigid unit (including children).\n\n"
00094                 "If parent=name is present, then the name must be an element\n"
00095                 "that accepts children, and it is used as the enclosing group;\n"
00096                 "in this case the size of the group is implied by the size\n"
00097                 "of the parent element, and z must be given (defaults to 0).\n"
00098                 "Note that a given element cannot be the parent of any other\n"
00099                 "element once it has been placed, so you must place children\n"
00100                 "into their parent before placing their parent.\n\n"
00101                 "If the special element 'OFFSET' is given, x, y, and z\n"
00102                 "specify offsets for every following place command into the\n"
00103                 "current group (incl. World), that gives a z position.");
00104         x = 0.0;
00105         y = 0.0;
00106         z = 0.0;
00107         parent = "";
00108         rename = "";
00109         rotation = "";
00110         coordinates = "Centerline";
00111         copies = 1;
00112         front = 0;
00113         element = 0;
00114 }


Member Function Documentation

G4String BLCMDplace::commandName (  )  [inline, virtual]

Implements BLCommand.

00045 { return "place"; }

int BLCMDplace::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

Implements BLCommand.

References BLCOORD_CENTERLINE, BLCOORD_GLOBAL, coordinates, copies, element, BLGroupElement::find(), BLElement::find(), front, BLCoordinates::getCoordinateType(), BLGroup::getCurrent(), BLElement::getLength(), BLGroup::getOffset(), BLElement::getPlacedFlag(), BLGroup::getWorld(), handleNamedArgs(), NO_RENAME(), parent, BLGroupElement::placeChild(), BLGroup::placeElement(), BLCommand::printError(), rename, rotation, BLGroup::setOffset(), BLElement::setPlacedFlag(), BLCommand::stringToRotationMatrix(), UNDETERMINED, x, y, and z.

00117 {
00118         if(argv.size() != 1) {
00119                 printError("Invalid place command -- need one element name");
00120                 return -1;
00121         }
00122 
00123         // handle offsets in x, y, and z
00124         if(argv[0] == "OFFSET") {
00125                 x = 0.0;
00126                 y = 0.0;
00127                 z = 0.0;
00128                 handleNamedArgs(namedArgs);
00129                 G4ThreeVector offset(x,y,z);
00130                 BLGroup::getCurrent()->setOffset(offset);
00131                 return 0;
00132         }
00133 
00134         element = BLElement::find(argv[0]);
00135         if(!element) {
00136                 printError("place: cannot find element '%s'",argv[0].c_str());
00137                 return -1;
00138         }
00139 
00140         // clear previous values
00141         x = UNDETERMINED;
00142         y = UNDETERMINED;
00143         z = UNDETERMINED;
00144         parent = "";
00145         rename = NO_RENAME;
00146         copies = 1;
00147         rotation = "";
00148         coordinates = "Centerline";
00149         front = 0;
00150 
00151         handleNamedArgs(namedArgs);
00152 
00153         if(z != UNDETERMINED && front != 0)  {
00154                 double len = element->getLength();
00155                 if(len <= 0.0)
00156                         printError("place: element length is <= 0 -- cannot use front=1");
00157                 z += len/2.0;
00158         }
00159 
00160         if(parent != "") {
00161                 BLGroupElement *ge = BLGroupElement::find(parent);
00162                 if(!ge) {
00163                         if(BLElement::find(parent) != 0) {
00164                                 printError("place: parent '%s' cannot have children",
00165                                         parent.c_str());
00166                         } else {
00167                                 printError("place: cannot find parent '%s'",
00168                                         parent.c_str());
00169                         }
00170                         return -1;
00171                 }
00172                 if(ge->getPlacedFlag()) {
00173                         printError("place: parent '%s' has already been placed",
00174                                         parent.c_str());
00175                         return -1;
00176                 }
00177                 if(z == UNDETERMINED && element->getLength() == 0) {
00178                         printError("place: element length is <= 0 -- cannot be placed sequentially");
00179                 }
00180                 if(x == UNDETERMINED) x = 0.0;
00181                 if(y == UNDETERMINED) y = 0.0;
00182                 if(z == UNDETERMINED) z = 0.0;
00183                 G4ThreeVector offset(x,y,z);
00184                 G4RotationMatrix *rot = 0;
00185                 if(rotation != "")
00186                         rot = stringToRotationMatrix(rotation);
00187                 for(int i=0; i<copies; ++i) {
00188                     ge->placeChild(element,rot,offset,rename);
00189                     offset[2] += element->getLength();
00190                 }
00191                 printf("place   %-7s parent=%s copies=%d x=%.1f y=%.1f z=%.1f ",
00192                                 argv[0].c_str(),parent.c_str(),copies,x,y,z);
00193                 if(rename != NO_RENAME)
00194                         printf("rename='%s'",rename.c_str());
00195                 if(rotation != "")
00196                         printf("rotation='%s'",rotation.c_str());
00197                 printf("\n");
00198                 element->setPlacedFlag();
00199                 return 0;
00200         }
00201 
00202         BLCoordinateType coordType = 
00203                                 BLCoordinates::getCoordinateType(coordinates);
00204         assert(coordType==BLCOORD_GLOBAL || coordType==BLCOORD_CENTERLINE);
00205 
00206         // if placing into a group, indent by 2 spaces
00207         const char *p;
00208         if(BLGroup::getCurrent() == BLGroup::getWorld())
00209                 p = "place  ";
00210         else
00211                 p = "  place";
00212 
00213         if(z == UNDETERMINED) {
00214                 if(rotation != "")
00215                         printError("place without z being given, rotation is"
00216                                         " ignored");
00217                 if(x != UNDETERMINED || y != UNDETERMINED)
00218                         printError("place without z being given, x and y are"
00219                                                 " ignored");
00220                 if(element->getLength() == 0) {
00221                         printError("place: element length is <= 0 -- cannot be placed sequentially");
00222                 }
00223                 for(int i=0; i<copies; ++i)
00224                         BLGroup::getCurrent()->placeElement(element,rename,
00225                                                 coordType==BLCOORD_GLOBAL);
00226                 printf("%-7s %-7s copies=%d sequentially along z; ",
00227                                 p,argv[0].c_str(),copies);
00228                 if(rename != NO_RENAME)
00229                         printf("rename='%s'",rename.c_str());
00230         } else {
00231                 if(x == UNDETERMINED) x = 0.0;
00232                 if(y == UNDETERMINED) y = 0.0;
00233                 G4ThreeVector offset(x,y,z);
00234                 offset += BLGroup::getCurrent()->getOffset();
00235                 G4RotationMatrix *rot = 0;
00236                 if(rotation != "")
00237                         rot = stringToRotationMatrix(rotation);
00238                 for(int i=0; i<copies; ++i) {
00239                     BLGroup::getCurrent()->placeElement(element,rot,offset,
00240                                         rename, coordType==BLCOORD_GLOBAL);
00241                     offset[2] += element->getLength();
00242                 }
00243                 printf("%-7s %-7s copies=%d x=%.1f y=%.1f z=%.1f ",
00244                                 p,argv[0].c_str(),copies,x,y,z);
00245                 if(rename != NO_RENAME)
00246                         printf("rename='%s'",rename.c_str());
00247                 if(rotation != "")
00248                         printf("rotation='%s'",rotation.c_str());
00249         }
00250         printf("\n");
00251 
00252         element->setPlacedFlag();
00253 
00254         return 0;
00255 }

void BLCMDplace::defineNamedArgs (  )  [virtual]

Reimplemented from BLCommand.

References BLCommand::argDouble(), BLCommand::argInt(), BLCommand::argString(), coordinates, copies, front, parent, rename, rotation, x, y, and z.

Referenced by handleNamedArgs().

00258 {
00259         argDouble(z,"z","Z position of element's center relative to the "
00260                 "center of the enclosing group (mm).");
00261         argDouble(x,"x","X position of element's center [default=0] (mm)");
00262         argDouble(y,"y","Y position of element's center [default=0] (mm)");
00263         argString(parent,"parent","Parent element name (must accept children).");
00264         argString(rename,"rename","Name to use for this placement; '#' will "
00265                 "be substituted by the number of placements. If the value "
00266                 "begins with '+', it is replaced with the parent's name.");
00267         argInt(copies,"copies","Number of copies (placed sequentially along z).");
00268         argInt(front,"front","Nonzero to specify z for the front, not the center.");
00269         argString(rotation,"rotation","Rotation of this object.");
00270         argString(coordinates,"coordinates","Coordinates: global or centerline (default=c).");
00271 }

int BLCMDplace::handleNamedArgs ( BLArgumentMap namedArgs  ) 

special version of handleNamedArgs().

Reimplemented from BLCommand.

References BLCommand::argChanged(), BLCommand::argFound, BLCommand::argMode, BLCommand::argName, BLCommand::argValue, BLCommand::CHANGE, BLElement::clone(), BLCommand::defineNamedArgs(), defineNamedArgs(), element, BLCommand::printError(), and BLCommand::PROCESS.

Referenced by command().

00274 {
00275         int retval = 0;
00276         argMode = PROCESS;
00277         bool isCloned = false;
00278 
00279         BLArgumentMap::iterator i;
00280         for(i=args.begin(); i!=args.end(); ++i) {
00281                 argName = i->first;
00282                 argValue = i->second;
00283                 argFound = false;
00284                 defineNamedArgs();
00285                 if(!argFound) {
00286                         // handle element args
00287                         if(!isCloned) {
00288                                 element = element->clone();
00289                                 isCloned = true;
00290                         }
00291                         element->argName = argName;
00292                         element->argValue = argValue;
00293                         element->argFound = false;
00294                         element->argMode = CHANGE;
00295                         element->defineNamedArgs();
00296                         if(!element->argFound) {
00297                                 printError("Invalid argument '%s' to place",
00298                                         argName.c_str());
00299                                 retval = -1;
00300                         }
00301                 }
00302         }
00303 
00304         if(isCloned) element->argChanged();
00305 
00306         return retval;
00307 }


Member Data Documentation

G4double BLCMDplace::x [private]

G4double BLCMDplace::y [private]

G4double BLCMDplace::z [private]

G4String BLCMDplace::parent [private]

G4String BLCMDplace::rename [private]

G4String BLCMDplace::rotation [private]

G4String BLCMDplace::coordinates [private]

G4int BLCMDplace::copies [private]

G4int BLCMDplace::front [private]


The documentation for this class was generated from the following file:
g4beamline