CMS 3D CMS Logo

DDLBooleanSolid.cc
Go to the documentation of this file.
11 
12 class DDCompactView;
13 
15  : DDLSolid( myreg )
16 {}
17 
18 // Clear out rSolids.
19 void
21  DDCompactView& cpv )
22 {
23  myRegistry_->getElement( "rSolid" )->clear();
24 }
25 
26 // To process a BooleanSolid we should have in the meantime
27 // hit two rSolid calls and possibly one rRotation and one Translation.
28 // So, retrieve them and make the call to DDCore.
29 void
31 {
32  // new DDLBoolean will handle:
33  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
34  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>
35 
36  auto myrSolid = myRegistry_->getElement( "rSolid" ); // get rSolid children
37  auto myTranslation = myRegistry_->getElement( "Translation" ); // get Translation child
38  auto myrRotation = myRegistry_->getElement( "rRotation" ); // get rRotation child
39 
42 
43  DDName ddn1, ddn2;
44  double x=0.0, y=0.0, z=0.0;
45  DDRotation ddrot;
46 
47  // Basically check if there are rSolids or Translation or rRotation then we have
48  // should NOT have any of the attributes shown above.
49  if( myrSolid->size() == 0 )
50  {
51  // do the solids using the attributes only.
52  if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) {
53  ddn1 = getDDName(nmspace, "firstSolid");
54  ddn2 = getDDName(nmspace, "secondSolid");
55  } else {
56  std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
57  s += dumpBooleanSolid(name, nmspace);
58  throwError( s );
59  }
60  }
61  else if (myrSolid->size() == 2)
62  {
63  ddn1 = myrSolid->getDDName(nmspace, "name", 0);
64  ddn2 = myrSolid->getDDName(nmspace, "name", 1);
65  } else {
66  std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
67  s += dumpBooleanSolid(name, nmspace);
68  throwError( s );
69  }
70 
71  if (myTranslation->size() > 0)
72  {
73  atts.clear();
74  atts = myTranslation->getAttributeSet();
75  x = ev.eval(nmspace, atts.find("x")->second);
76  y = ev.eval(nmspace, atts.find("y")->second);
77  z = ev.eval(nmspace, atts.find("z")->second);
78  }
79 
80  if (myrRotation->size() > 0)
81  {
82  ddrot = DDRotation( myrRotation->getDDName (nmspace) );
83  }
84 
85  DDSolid theSolid;
86 
87  if (name == "UnionSolid") {
88  theSolid = DDSolidFactory::unionSolid (getDDName(nmspace)
89  , DDSolid(ddn1)
90  , DDSolid(ddn2)
91  , DDTranslation(x, y, z)
92  , ddrot
93  );
94  }
95  else if (name == "SubtractionSolid") {
96  theSolid = DDSolidFactory::subtraction (getDDName(nmspace)
97  , DDSolid(ddn1)
98  , DDSolid(ddn2)
99  , DDTranslation(x, y, z)
100  , ddrot
101  );
102  }
103  else if (name == "IntersectionSolid") {
104  theSolid = DDSolidFactory::intersection (getDDName(nmspace)
105  , DDSolid(ddn1)
106  , DDSolid(ddn2)
107  , DDTranslation(x, y, z)
108  , ddrot
109  );
110  }
111  else {
112  throw cms::Exception("DDException") << "DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?";
113  }
114 
115  DDLSolid::setReference(nmspace, cpv);
116 
117  // clear all "children" and attributes
118  myTranslation->clear();
119  myrRotation->clear();
120  myrSolid->clear();
121  clear();
122 }
123 
124 // This only happens on error, so I don't care how "slow" it is :-)
127 {
128  std::string s;
130 
131  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
132 
133  if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
134  if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
135  s += ">\n";
136 
137  auto myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
138  auto myTranslation = myRegistry_->getElement("Translation"); // get Translation child
139  auto myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
140  if (myrSolid->size() > 0)
141  {
142  for (size_t i = 0; i < myrSolid->size(); ++i)
143  {
144  atts = myrSolid->getAttributeSet(i);
145  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
146  }
147  }
148 
149  atts = myTranslation->getAttributeSet();
150  s+= "<Translation";
151  if (atts.find("x") != atts.end())
152  s+=" x=\"" + atts.find("x")->second + "\"";
153  if (atts.find("y") != atts.end())
154  s+= " y=\"" + atts.find("y")->second + "\"";
155  if (atts.find("z") != atts.end())
156  s+= " z=\"" + atts.find("z")->second + "\"";
157  s+="/>\n";
158 
159  atts = myrRotation->getAttributeSet();
160  if (atts.find("name") != atts.end())
161  {
162  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
163  }
164  s+= "</" + name + ">\n\n";
165  return s;
166 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:172
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a "row" of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:72
void throwError(const std::string &keyMessage) const
format std::string for throw an error.
DDName is used to identify DDD entities uniquely.
Definition: DDName.h:15
bool ev
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:80
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:68
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
ClhepEvaluator & evaluator()
static DDSolid intersection(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:783
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
DDLBooleanSolid(DDLElementRegistry *myreg)
std::string dumpBooleanSolid(const std::string &name, const std::string &nmspace)
DDLSolid processes Box elements.
Definition: DDLSolid.h:30
static DDSolid subtraction(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:774
double eval(const std::string &ns, const std::string &expr)
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:54
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:765
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:79
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:16