#include <DetectorDescription/Parser/src/DDLBooleanSolid.h>
Public Member Functions | |
DDLBooleanSolid () | |
Constructor. | |
void | preProcessElement (const std::string &name, const std::string &nmspace) |
Called by loadAttributes AFTER attributes are loaded. | |
void | processElement (const std::string &name, const std::string &nmspace) |
Processing the element. | |
~DDLBooleanSolid () | |
Destructor. | |
Private Member Functions | |
std::string | dumpBooleanSolid (const std::string &name, const std::string &nmspace) |
DDLBooleanSolid.h - description ------------------- begin: Wed Dec 12, 2001 email: case@ucdhep.ucdavis.edu
This is the Intersection, Subtraction and Union processor. A BooleanSolid handles all of these because as far as the DDL is concerned, they have the same basic form, including two solid references, and potentially one translation and one rotation.
Definition at line 24 of file DDLBooleanSolid.h.
DDLBooleanSolid::DDLBooleanSolid | ( | ) |
DDLBooleanSolid::~DDLBooleanSolid | ( | ) |
std::string DDLBooleanSolid::dumpBooleanSolid | ( | const std::string & | name, | |
const std::string & | nmspace | |||
) | [private] |
Definition at line 150 of file DDLBooleanSolid.cc.
References DDXMLElement::getAttributeSet(), DDLElementRegistry::getElement(), i, s, and DDXMLElement::size().
Referenced by processElement().
00151 { 00152 std::string s; 00153 DDXMLAttribute atts = getAttributeSet(); 00154 00155 s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\""; 00156 00157 if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\""; 00158 if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\""; 00159 s += ">\n"; 00160 00161 DDXMLElement* myrSolid = DDLElementRegistry::getElement("rSolid"); // get rSolid children 00162 DDXMLElement* myTranslation = DDLElementRegistry::getElement("Translation"); // get Translation child 00163 DDXMLElement* myrRotation = DDLElementRegistry::getElement("rRotation"); // get rRotation child 00164 if (myrSolid->size() > 0) 00165 { 00166 for (size_t i = 0; i < myrSolid->size(); ++i) 00167 { 00168 atts = myrSolid->getAttributeSet(i); 00169 s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n"; 00170 } 00171 } 00172 00173 atts = myTranslation->getAttributeSet(); 00174 s+= "<Translation"; 00175 if (atts.find("x") != atts.end()) 00176 s+=" x=\"" + atts.find("x")->second + "\""; 00177 if (atts.find("y") != atts.end()) 00178 s+= " y=\"" + atts.find("y")->second + "\""; 00179 if (atts.find("z") != atts.end()) 00180 s+= " z=\"" + atts.find("z")->second + "\""; 00181 s+="/>\n"; 00182 00183 atts = myrRotation->getAttributeSet(); 00184 if (atts.find("name") != atts.end()) 00185 { 00186 s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n"; 00187 } 00188 s+= "</" + name + ">\n\n"; 00189 return s; 00190 00191 }
void DDLBooleanSolid::preProcessElement | ( | const std::string & | name, | |
const std::string & | nmspace | |||
) | [virtual] |
Called by loadAttributes AFTER attributes are loaded.
The preProcessElement method can assume that the attributes are loaded and perform any code that is necessary at the start of an element.
This would allow users to call their own code to setup anything necessary for the continued processing of the child elements.
Reimplemented from DDXMLElement.
Definition at line 40 of file DDLBooleanSolid.cc.
References DDXMLElement::clear(), and DDLElementRegistry::getElement().
00041 { 00042 DDLElementRegistry::getElement("rSolid")->clear(); 00043 }
void DDLBooleanSolid::processElement | ( | const std::string & | name, | |
const std::string & | nmspace | |||
) | [virtual] |
Processing the element.
The processElement method completes any necessary work to process the XML element.
For example, this can be used to call the DDCore to make the geometry in memory. There is a default for this so that if not declared in the inheriting class, no processing is done.
Reimplemented from DDXMLElement.
Definition at line 48 of file DDLBooleanSolid.cc.
References DDXMLElement::clear(), DCOUT_V, dumpBooleanSolid(), ExprEvalInterface::eval(), DDXMLElement::getAttributeSet(), DDXMLElement::getDDName(), DDLElementRegistry::getElement(), DDI::Singleton< I >::instance(), DDSolidFactory::intersection(), s, DDLSolid::setReference(), DDXMLElement::size(), DDSolidFactory::subtraction(), DDXMLElement::throwError(), DDSolidFactory::unionSolid(), x, y, and z.
00049 { 00050 DCOUT_V('P', "DDLBooleanSolid::processElement started"); 00051 00052 // new DDLBoolean will handle: 00053 // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid 00054 // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid> 00055 00056 DDXMLElement* myrSolid = DDLElementRegistry::getElement("rSolid"); // get rSolid children 00057 DDXMLElement* myTranslation = DDLElementRegistry::getElement("Translation"); // get Translation child 00058 DDXMLElement* myrRotation = DDLElementRegistry::getElement("rRotation"); // get rRotation child 00059 00060 ExprEvalInterface & ev = ExprEvalSingleton::instance(); 00061 DDXMLAttribute atts = getAttributeSet(); 00062 00063 DDName ddn1, ddn2; 00064 double x=0.0, y=0.0, z=0.0; 00065 DDRotation ddrot; 00066 00067 // Basically check if there are rSolids or Translation or rRotation then we have 00068 // should NOT have any of the attributes shown above. 00069 if (myrSolid->size() == 0) 00070 { 00071 // do the solids using the attributes only. 00072 if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) { 00073 ddn1 = getDDName(nmspace, "firstSolid"); 00074 ddn2 = getDDName(nmspace, "secondSolid"); 00075 } else { 00076 std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid."); 00077 s += dumpBooleanSolid(name, nmspace); 00078 throwError( s ); 00079 } 00080 } 00081 else if (myrSolid->size() == 2) 00082 { 00083 ddn1 = myrSolid->getDDName(nmspace, "name", 0); 00084 ddn2 = myrSolid->getDDName(nmspace, "name", 1); 00085 } else { 00086 std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid."); 00087 s += dumpBooleanSolid(name, nmspace); 00088 throwError( s ); 00089 } 00090 00091 if (myTranslation->size() > 0) 00092 { 00093 atts.clear(); 00094 atts = myTranslation->getAttributeSet(); 00095 x = ev.eval(nmspace, atts.find("x")->second); 00096 y = ev.eval(nmspace, atts.find("y")->second); 00097 z = ev.eval(nmspace, atts.find("z")->second); 00098 } 00099 00100 if (myrRotation->size() > 0) 00101 { 00102 ddrot = DDRotation( myrRotation->getDDName (nmspace) ); 00103 } 00104 00105 00106 DDSolid theSolid; 00107 00108 if (name == "UnionSolid") { 00109 theSolid = DDSolidFactory::unionSolid (getDDName(nmspace) 00110 , DDSolid(ddn1) 00111 , DDSolid(ddn2) 00112 , DDTranslation(x, y, z) 00113 , ddrot 00114 ); 00115 } 00116 else if (name == "SubtractionSolid") { 00117 theSolid = DDSolidFactory::subtraction (getDDName(nmspace) 00118 , DDSolid(ddn1) 00119 , DDSolid(ddn2) 00120 , DDTranslation(x, y, z) 00121 , ddrot 00122 ); 00123 } 00124 else if (name == "IntersectionSolid") { 00125 theSolid = DDSolidFactory::intersection (getDDName(nmspace) 00126 , DDSolid(ddn1) 00127 , DDSolid(ddn2) 00128 , DDTranslation(x, y, z) 00129 , ddrot 00130 ); 00131 } 00132 else { 00133 throw DDException("DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?"); 00134 } 00135 00136 DDLSolid::setReference(nmspace); 00137 00138 DCOUT_V('p', theSolid); 00139 00140 // clear all "children" and attributes 00141 myTranslation->clear(); 00142 myrRotation->clear(); 00143 myrSolid->clear(); 00144 clear(); 00145 DCOUT_V('P', "DDLBooleanSolid::processElement completed"); 00146 00147 }