CMS 3D CMS Logo

DDLBooleanSolid.cc

Go to the documentation of this file.
00001 /***************************************************************************
00002                           DDLBooleanSolid.cc  -  description
00003                              -------------------
00004     begin                : Wed Dec 12, 2001
00005     email                : case@ucdhep.ucdavis.edu
00006  ***************************************************************************/
00007 
00008 /***************************************************************************
00009  *                                                                         *
00010  *           DDDParser sub-component of DDD                                *
00011  *                                                                         *
00012  ***************************************************************************/
00013 
00014 
00015 
00016 // Parser parts
00017 #include "DDLBooleanSolid.h"
00018 #include "DDLElementRegistry.h"
00019 #include "DDXMLElement.h"
00020 
00021 // DDCore dependencies
00022 #include "DetectorDescription/Core/interface/DDSolid.h"
00023 #include "DetectorDescription/Core/interface/DDName.h"
00024 #include "DetectorDescription/Base/interface/DDdebug.h"
00025 #include "DetectorDescription/Base/interface/DDException.h"
00026 
00027 #include "DetectorDescription/ExprAlgo/interface/ExprEvalSingleton.h"
00028 
00029 #include <string>
00030 
00031 // default constructor
00032 DDLBooleanSolid::DDLBooleanSolid()
00033 { 
00034 }
00035 
00036 // Default desctructor
00037 DDLBooleanSolid::~DDLBooleanSolid() { }
00038 
00039 // Clear out rSolids.
00040 void DDLBooleanSolid::preProcessElement (const std::string& name, const std::string& nmspace)
00041 {
00042   DDLElementRegistry::getElement("rSolid")->clear();
00043 }
00044 
00045 // To process a BooleanSolid we should have in the meantime
00046 // hit two rSolid calls and possibly one rRotation and one Translation.
00047 // So, retrieve them and make the call to DDCore.
00048 void DDLBooleanSolid::processElement (const std::string& name, const std::string& nmspace)
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 }
00148 
00149 // This only happens on error, so I don't care how "slow" it is :-)
00150 std::string DDLBooleanSolid::dumpBooleanSolid (const std::string& name, const std::string& nmspace)
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 }

Generated on Tue Jun 9 17:32:23 2009 for CMSSW by  doxygen 1.5.4