CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DDLBooleanSolid.cc
Go to the documentation of this file.
11 
12 class DDCompactView;
13 
15 
16 // Clear out rSolids.
18  myRegistry_->getElement("rSolid")->clear();
19 }
20 
21 // To process a BooleanSolid we should have in the meantime
22 // hit two rSolid calls and possibly one rRotation and one Translation.
23 // So, retrieve them and make the call to DDCore.
25  // new DDLBoolean will handle:
26  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
27  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>
28 
29  auto myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
30  auto myTranslation = myRegistry_->getElement("Translation"); // get Translation child
31  auto myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
32 
35 
36  DDName ddn1, ddn2;
37  double x = 0.0, y = 0.0, z = 0.0;
38  DDRotation ddrot;
39 
40  // Basically check if there are rSolids or Translation or rRotation then we have
41  // should NOT have any of the attributes shown above.
42  if (myrSolid->size() == 0) {
43  // do the solids using the attributes only.
44  if (atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end()) {
45  ddn1 = getDDName(nmspace, "firstSolid");
46  ddn2 = getDDName(nmspace, "secondSolid");
47  } else {
48  std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
49  s += dumpBooleanSolid(name, nmspace);
50  throwError(s);
51  }
52  } else if (myrSolid->size() == 2) {
53  ddn1 = myrSolid->getDDName(nmspace, "name", 0);
54  ddn2 = myrSolid->getDDName(nmspace, "name", 1);
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  if (myTranslation->size() > 0) {
62  atts.clear();
63  atts = myTranslation->getAttributeSet();
64  x = ev.eval(nmspace, atts.find("x")->second);
65  y = ev.eval(nmspace, atts.find("y")->second);
66  z = ev.eval(nmspace, atts.find("z")->second);
67  }
68 
69  if (myrRotation->size() > 0) {
70  ddrot = DDRotation(myrRotation->getDDName(nmspace));
71  }
72 
73  DDSolid theSolid;
74 
75  if (name == "UnionSolid") {
76  theSolid =
77  DDSolidFactory::unionSolid(getDDName(nmspace), DDSolid(ddn1), DDSolid(ddn2), DDTranslation(x, y, z), ddrot);
78  } else if (name == "SubtractionSolid") {
79  theSolid =
80  DDSolidFactory::subtraction(getDDName(nmspace), DDSolid(ddn1), DDSolid(ddn2), DDTranslation(x, y, z), ddrot);
81  } else if (name == "IntersectionSolid") {
82  theSolid =
83  DDSolidFactory::intersection(getDDName(nmspace), DDSolid(ddn1), DDSolid(ddn2), DDTranslation(x, y, z), ddrot);
84  } else {
85  throw cms::Exception("DDException")
86  << "DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?";
87  }
88 
89  DDLSolid::setReference(nmspace, cpv);
90 
91  // clear all "children" and attributes
92  myTranslation->clear();
93  myrRotation->clear();
94  myrSolid->clear();
95  clear();
96 }
97 
98 // This only happens on error, so I don't care how "slow" it is :-)
100  std::string s;
102 
103  s = std::string("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
104 
105  if (atts.find("firstSolid") != atts.end())
106  s += " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
107  if (atts.find("secondSolid") != atts.end())
108  s += " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
109  s += ">\n";
110 
111  auto myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
112  auto myTranslation = myRegistry_->getElement("Translation"); // get Translation child
113  auto myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
114  if (myrSolid->size() > 0) {
115  for (size_t i = 0; i < myrSolid->size(); ++i) {
116  atts = myrSolid->getAttributeSet(i);
117  s += "<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
118  }
119  }
120 
121  atts = myTranslation->getAttributeSet();
122  s += "<Translation";
123  if (atts.find("x") != atts.end())
124  s += " x=\"" + atts.find("x")->second + "\"";
125  if (atts.find("y") != atts.end())
126  s += " y=\"" + atts.find("y")->second + "\"";
127  if (atts.find("z") != atts.end())
128  s += " z=\"" + atts.find("z")->second + "\"";
129  s += "/>\n";
130 
131  atts = myrRotation->getAttributeSet();
132  if (atts.find("name") != atts.end()) {
133  s += "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
134  }
135  s += "</" + name + ">\n\n";
136  return s;
137 }
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:173
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:54
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:17
bool ev
Compact representation of the geometrical detector hierarchy.
Definition: DDCompactView.h:81
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
A DDSolid represents the shape of a part.
Definition: DDSolid.h:39
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:57
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:604
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:599
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:40
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:594
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:56
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:13