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 |
BLElement * | element |
BLCMDplace::BLCMDplace | ( | ) |
References BLCMDTYPE_PLACE, coordinates, copies, element, front, parent, BLCommand::registerCommand(), rename, rotation, BLCommand::setDescription(), BLCommand::setSynopsis(), x, y, and z.
00059 { 00060 registerCommand(BLCMDTYPE_PLACE); 00061 setSynopsis("places an element into the current group (or world)."); 00062 setDescription("Every element can be placed multiple times into the\n" 00063 "beamline. For most elements the geometrical centerpoint is\n" 00064 "placed; for polycone the local x=y=z=0 point is placed. " 00065 "If front is nonzero then the front of the element is " 00066 "placed.\n" 00067 "If z is specified, then the element is placed\n" 00068 "at that z position relative to the center of the enclosing\n" 00069 "group. If z is not specified, then the element is placed\n" 00070 "immediately downstream (higher z) of the previous element\n" 00071 "in the group, or at the upstream edge of the group if this\n" 00072 "is the first element in the group.\n\n" 00073 "The 'rename' argument can be used to change the name of the " 00074 "element (applies to traces and other uses of object names, " 00075 "such as the NTuple name of a virtualdetector). When placing " 00076 "into a group or other object, the rename argument should " 00077 "normally begin with '+' to include the parent's name; " 00078 "otherwise multiple placements of the parent will generate " 00079 "multiple objects with identical names -- that should " 00080 "be avoided for output objects like virtualdetector. " 00081 "Without a rename argument, the parent's name is included " 00082 "automatically.\n\n" 00083 "When multiple copies are placed, z refers to the first, and " 00084 "the rest are placed sequentially along z.\n" 00085 "When placing an element into the World group, Centerline\n" 00086 "coordinates are used unless coordinates=global is present.\n" 00087 "When centerline coordinates are used, the parameter 'Zcl' is " 00088 "set to the highest Z value used; this is normally the Z value " 00089 "for the front of the next element when placed sequentially " 00090 "(i.e. with no z value given).\n" 00091 "\nRotations:\n" 00092 "The rotation parameter can be used to rotate this element \n" 00093 "relative to " 00094 "the enclosing group. The object is rotated, not the axes.\n" 00095 "Rotations are specified as a comma-separated list of axes\n" 00096 "and angles (in degrees): rotate=Z90,X45 rotates first by 90\n" 00097 "degrees around Z and then by 45 degrees around X. The axes\n" 00098 "are the local X,Y,Z coordinate axes of the enclosing group\n" 00099 "(centerline or global coordinate axes for the World group);\n" 00100 "groups can be rotated when placed, and are rotated as a\n" 00101 "rigid unit (including children).\n\n" 00102 "If parent=name is present, then the name must be an element\n" 00103 "that accepts children, and it is used as the enclosing group;\n" 00104 "in this case the size of the group is implied by the size\n" 00105 "of the parent element, and z must be given (defaults to 0).\n" 00106 "Note that a given element cannot be the parent of any other\n" 00107 "element once it has been placed, so you must place children\n" 00108 "into their parent before placing their parent.\n\n" 00109 "If the special element 'OFFSET' is given, x, y, and z\n" 00110 "specify offsets for every following place command into the\n" 00111 "current group (incl. World), that gives a z position."); 00112 x = 0.0; 00113 y = 0.0; 00114 z = 0.0; 00115 parent = ""; 00116 rename = ""; 00117 rotation = ""; 00118 coordinates = "Centerline"; 00119 copies = 1; 00120 front = 0; 00121 element = 0; 00122 }
G4String BLCMDplace::commandName | ( | ) | [inline, virtual] |
int BLCMDplace::command | ( | BLArgumentVector & | argv, | |
BLArgumentMap & | namedArgs | |||
) | [virtual] |
Implements BLCommand.
References BLAssert, 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.
00125 { 00126 if(argv.size() != 1) { 00127 printError("Invalid place command -- need one element name"); 00128 return -1; 00129 } 00130 00131 // handle offsets in x, y, and z 00132 if(argv[0] == "OFFSET") { 00133 x = 0.0; 00134 y = 0.0; 00135 z = 0.0; 00136 handleNamedArgs(namedArgs); 00137 G4ThreeVector offset(x,y,z); 00138 BLGroup::getCurrent()->setOffset(offset); 00139 return 0; 00140 } 00141 00142 element = BLElement::find(argv[0]); 00143 if(!element) { 00144 printError("place: cannot find element '%s'",argv[0].c_str()); 00145 return -1; 00146 } 00147 00148 // clear previous values 00149 x = UNDETERMINED; 00150 y = UNDETERMINED; 00151 z = UNDETERMINED; 00152 parent = ""; 00153 rename = NO_RENAME; 00154 copies = 1; 00155 rotation = ""; 00156 coordinates = "Centerline"; 00157 front = 0; 00158 00159 handleNamedArgs(namedArgs); 00160 00161 if(z != UNDETERMINED && front != 0) { 00162 double len = element->getLength(); 00163 if(len <= 0.0) 00164 printError("place: element length is <= 0 -- cannot use front=1"); 00165 z += len/2.0; 00166 } 00167 00168 if(rename != NO_RENAME && rename.find_first_of('+') != 0) { 00169 if(BLGroup::getCurrent() != BLGroup::getWorld()) 00170 printf("WARNING: Multiple placements of the enclosing " 00171 "group will create multiple objects with identical names.\n"); 00172 else if(parent != "") 00173 printf("WARNING: Multiple placements of the parent " 00174 "(%s) will create multiple objects with identical names.\n", 00175 parent.c_str()); 00176 } 00177 00178 if(parent != "") { 00179 BLGroupElement *ge = BLGroupElement::find(parent); 00180 if(!ge) { 00181 if(BLElement::find(parent) != 0) { 00182 printError("place: parent '%s' cannot have children", 00183 parent.c_str()); 00184 } else { 00185 printError("place: cannot find parent '%s'", 00186 parent.c_str()); 00187 } 00188 return -1; 00189 } 00190 if(ge->getPlacedFlag()) { 00191 printError("place: parent '%s' has already been placed", 00192 parent.c_str()); 00193 return -1; 00194 } 00195 if(z == UNDETERMINED && element->getLength() == 0) { 00196 printError("place: element length is <= 0 -- cannot be placed sequentially"); 00197 } 00198 if(x == UNDETERMINED) x = 0.0; 00199 if(y == UNDETERMINED) y = 0.0; 00200 if(z == UNDETERMINED) z = 0.0; 00201 G4ThreeVector offset(x,y,z); 00202 G4RotationMatrix *rot = 0; 00203 if(rotation != "") 00204 rot = stringToRotationMatrix(rotation); 00205 for(int i=0; i<copies; ++i) { 00206 ge->placeChild(element,rot,offset,rename); 00207 offset[2] += element->getLength(); 00208 } 00209 printf("place %-7s parent=%s copies=%d x=%.1f y=%.1f z=%.1f ", 00210 argv[0].c_str(),parent.c_str(),copies,x,y,z); 00211 if(rename != NO_RENAME) 00212 printf("rename='%s'",rename.c_str()); 00213 if(rotation != "") 00214 printf("rotation='%s'",rotation.c_str()); 00215 printf("\n"); 00216 element->setPlacedFlag(); 00217 return 0; 00218 } 00219 00220 BLCoordinateType coordType = 00221 BLCoordinates::getCoordinateType(coordinates); 00222 BLAssert(coordType==BLCOORD_GLOBAL || coordType==BLCOORD_CENTERLINE); 00223 00224 // if placing into a group, indent by 2 spaces 00225 const char *p; 00226 if(BLGroup::getCurrent() == BLGroup::getWorld()) 00227 p = "place "; 00228 else 00229 p = " place"; 00230 00231 if(z == UNDETERMINED) { 00232 if(rotation != "") 00233 printError("place without z being given, rotation is" 00234 " ignored"); 00235 if(x != UNDETERMINED || y != UNDETERMINED) 00236 printError("place without z being given, x and y are" 00237 " ignored"); 00238 if(element->getLength() == 0) { 00239 printError("place: element length is <= 0 -- cannot be placed sequentially"); 00240 } 00241 for(int i=0; i<copies; ++i) 00242 BLGroup::getCurrent()->placeElement(element,rename, 00243 coordType==BLCOORD_GLOBAL); 00244 printf("%-7s %-7s copies=%d sequentially along z; ", 00245 p,argv[0].c_str(),copies); 00246 if(rename != NO_RENAME) 00247 printf("rename='%s'",rename.c_str()); 00248 } else { 00249 if(x == UNDETERMINED) x = 0.0; 00250 if(y == UNDETERMINED) y = 0.0; 00251 G4ThreeVector offset(x,y,z); 00252 offset += BLGroup::getCurrent()->getOffset(); 00253 G4RotationMatrix *rot = 0; 00254 if(rotation != "") 00255 rot = stringToRotationMatrix(rotation); 00256 for(int i=0; i<copies; ++i) { 00257 BLGroup::getCurrent()->placeElement(element,rot,offset, 00258 rename, coordType==BLCOORD_GLOBAL); 00259 offset[2] += element->getLength(); 00260 } 00261 printf("%-7s %-7s copies=%d x=%.1f y=%.1f z=%.1f ", 00262 p,argv[0].c_str(),copies,x,y,z); 00263 if(rename != NO_RENAME) 00264 printf("rename='%s'",rename.c_str()); 00265 if(rotation != "") 00266 printf("rotation='%s'",rotation.c_str()); 00267 } 00268 printf("\n"); 00269 00270 element->setPlacedFlag(); 00271 00272 return 0; 00273 }
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().
00276 { 00277 argDouble(z,"z","Z position of element's center relative to the " 00278 "center of the enclosing group (mm)."); 00279 argDouble(x,"x","X position of element's center [default=0] (mm)"); 00280 argDouble(y,"y","Y position of element's center [default=0] (mm)"); 00281 argString(parent,"parent","Parent element name (must accept children)."); 00282 argString(rename,"rename","Name to use for this placement; '#' will " 00283 "be substituted by the number of placements. If the value " 00284 "begins with '+', it is replaced with the parent's name."); 00285 argInt(copies,"copies","Number of copies (placed sequentially along z)."); 00286 argInt(front,"front","Nonzero to specify z for the front, not the center."); 00287 argString(rotation,"rotation","Rotation of this object."); 00288 argString(coordinates,"coordinates","Coordinates: global or centerline (default=c)."); 00289 }
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().
00292 { 00293 int retval = 0; 00294 argMode = PROCESS; 00295 bool isCloned = false; 00296 00297 BLArgumentMap::iterator i; 00298 for(i=args.begin(); i!=args.end(); ++i) { 00299 argName = i->first; 00300 argValue = i->second; 00301 argFound = false; 00302 defineNamedArgs(); 00303 if(!argFound) { 00304 // handle element args 00305 if(!isCloned) { 00306 element = element->clone(); 00307 isCloned = true; 00308 } 00309 element->argName = argName; 00310 element->argValue = argValue; 00311 element->argFound = false; 00312 element->argMode = CHANGE; 00313 element->defineNamedArgs(); 00314 if(!element->argFound) { 00315 printError("Invalid argument '%s' to place", 00316 argName.c_str()); 00317 retval = -1; 00318 } 00319 } 00320 } 00321 00322 if(isCloned) element->argChanged(); 00323 00324 return retval; 00325 }
G4double BLCMDplace::x [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4double BLCMDplace::y [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4double BLCMDplace::z [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4String BLCMDplace::parent [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4String BLCMDplace::rename [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4String BLCMDplace::rotation [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4String BLCMDplace::coordinates [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4int BLCMDplace::copies [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
G4int BLCMDplace::front [private] |
Referenced by BLCMDplace(), command(), and defineNamedArgs().
BLElement* BLCMDplace::element [private] |
Referenced by BLCMDplace(), command(), and handleNamedArgs().