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 {
22  myRegistry_->getElement( "rSolid" )->clear();
23 }
24 
25 // To process a BooleanSolid we should have in the meantime
26 // hit two rSolid calls and possibly one rRotation and one Translation.
27 // So, retrieve them and make the call to DDCore.
28 void
30 {
31  // new DDLBoolean will handle:
32  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
33  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>
34 
35  auto myrSolid = myRegistry_->getElement( "rSolid" ); // get rSolid children
36  auto myTranslation = myRegistry_->getElement( "Translation" ); // get Translation child
37  auto myrRotation = myRegistry_->getElement( "rRotation" ); // get rRotation child
38 
41 
42  DDName ddn1, ddn2;
43  double x=0.0, y=0.0, z=0.0;
44  DDRotation ddrot;
45 
46  // Basically check if there are rSolids or Translation or rRotation then we have
47  // should NOT have any of the attributes shown above.
48  if( myrSolid->size() == 0 )
49  {
50  // do the solids using the attributes only.
51  if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) {
52  ddn1 = getDDName(nmspace, "firstSolid");
53  ddn2 = getDDName(nmspace, "secondSolid");
54  } else {
55  std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
56  s += dumpBooleanSolid(name, nmspace);
57  throwError( s );
58  }
59  }
60  else if (myrSolid->size() == 2)
61  {
62  ddn1 = myrSolid->getDDName(nmspace, "name", 0);
63  ddn2 = myrSolid->getDDName(nmspace, "name", 1);
64  } else {
65  std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
66  s += dumpBooleanSolid(name, nmspace);
67  throwError( s );
68  }
69 
70  if (myTranslation->size() > 0)
71  {
72  atts.clear();
73  atts = myTranslation->getAttributeSet();
74  x = ev.eval(nmspace, atts.find("x")->second);
75  y = ev.eval(nmspace, atts.find("y")->second);
76  z = ev.eval(nmspace, atts.find("z")->second);
77  }
78 
79  if (myrRotation->size() > 0)
80  {
81  ddrot = DDRotation( myrRotation->getDDName (nmspace) );
82  }
83 
84  DDSolid theSolid;
85 
86  if (name == "UnionSolid") {
87  theSolid = DDSolidFactory::unionSolid (getDDName(nmspace)
88  , DDSolid(ddn1)
89  , DDSolid(ddn2)
90  , DDTranslation(x, y, z)
91  , ddrot
92  );
93  }
94  else if (name == "SubtractionSolid") {
95  theSolid = DDSolidFactory::subtraction (getDDName(nmspace)
96  , DDSolid(ddn1)
97  , DDSolid(ddn2)
98  , DDTranslation(x, y, z)
99  , ddrot
100  );
101  }
102  else if (name == "IntersectionSolid") {
103  theSolid = DDSolidFactory::intersection (getDDName(nmspace)
104  , DDSolid(ddn1)
105  , DDSolid(ddn2)
106  , DDTranslation(x, y, z)
107  , ddrot
108  );
109  }
110  else {
111  throw cms::Exception("DDException") << "DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?";
112  }
113 
114  DDLSolid::setReference(nmspace, cpv);
115 
116  // clear all "children" and attributes
117  myTranslation->clear();
118  myrRotation->clear();
119  myrSolid->clear();
120  clear();
121 }
122 
123 // This only happens on error, so I don't care how "slow" it is :-)
126 {
127  std::string s;
129 
130  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
131 
132  if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
133  if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
134  s += ">\n";
135 
136  auto myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
137  auto myTranslation = myRegistry_->getElement("Translation"); // get Translation child
138  auto myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
139  if (myrSolid->size() > 0)
140  {
141  for (size_t i = 0; i < myrSolid->size(); ++i)
142  {
143  atts = myrSolid->getAttributeSet(i);
144  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
145  }
146  }
147 
148  atts = myTranslation->getAttributeSet();
149  s+= "<Translation";
150  if (atts.find("x") != atts.end())
151  s+=" x=\"" + atts.find("x")->second + "\"";
152  if (atts.find("y") != atts.end())
153  s+= " y=\"" + atts.find("y")->second + "\"";
154  if (atts.find("z") != atts.end())
155  s+= " z=\"" + atts.find("z")->second + "\"";
156  s+="/>\n";
157 
158  atts = myrRotation->getAttributeSet();
159  if (atts.find("name") != atts.end())
160  {
161  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
162  }
163  s+= "</" + name + ">\n\n";
164  return s;
165 }
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:73
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
type of data representation of DDCompactView
Definition: DDCompactView.h:90
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:45
A DDSolid represents the shape of a part.
Definition: DDSolid.h:38
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:64
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:905
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:896
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:55
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:878
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:80
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:17