CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
DDLBooleanSolid.cc
Go to the documentation of this file.
1 /***************************************************************************
2  DDLBooleanSolid.cc - description
3  -------------------
4  begin : Wed Dec 12, 2001
5  email : case@ucdhep.ucdavis.edu
6  ***************************************************************************/
7 
8 /***************************************************************************
9  * *
10  * DDDParser sub-component of DDD *
11  * *
12  ***************************************************************************/
13 
16 
20 
22 
24  : DDLSolid( myreg )
25 {}
26 
28 {}
29 
30 // Clear out rSolids.
31 void
32 DDLBooleanSolid::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
33 {
34  myRegistry_->getElement( "rSolid" )->clear();
35 }
36 
37 // To process a BooleanSolid we should have in the meantime
38 // hit two rSolid calls and possibly one rRotation and one Translation.
39 // So, retrieve them and make the call to DDCore.
40 void
41 DDLBooleanSolid::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
42 {
43  DCOUT_V( 'P', "DDLBooleanSolid::processElement started" );
44 
45  // new DDLBoolean will handle:
46  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
47  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>
48 
49  DDXMLElement* myrSolid = myRegistry_->getElement( "rSolid" ); // get rSolid children
50  DDXMLElement* myTranslation = myRegistry_->getElement( "Translation" ); // get Translation child
51  DDXMLElement* myrRotation = myRegistry_->getElement( "rRotation" ); // get rRotation child
52 
55 
56  DDName ddn1, ddn2;
57  double x=0.0, y=0.0, z=0.0;
58  DDRotation ddrot;
59 
60  // Basically check if there are rSolids or Translation or rRotation then we have
61  // should NOT have any of the attributes shown above.
62  if( myrSolid->size() == 0 )
63  {
64  // do the solids using the attributes only.
65  if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) {
66  ddn1 = getDDName(nmspace, "firstSolid");
67  ddn2 = getDDName(nmspace, "secondSolid");
68  } else {
69  std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
70  s += dumpBooleanSolid(name, nmspace);
71  throwError( s );
72  }
73  }
74  else if (myrSolid->size() == 2)
75  {
76  ddn1 = myrSolid->getDDName(nmspace, "name", 0);
77  ddn2 = myrSolid->getDDName(nmspace, "name", 1);
78  } else {
79  std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
80  s += dumpBooleanSolid(name, nmspace);
81  throwError( s );
82  }
83 
84  if (myTranslation->size() > 0)
85  {
86  atts.clear();
87  atts = myTranslation->getAttributeSet();
88  x = ev.eval(nmspace, atts.find("x")->second);
89  y = ev.eval(nmspace, atts.find("y")->second);
90  z = ev.eval(nmspace, atts.find("z")->second);
91  }
92 
93  if (myrRotation->size() > 0)
94  {
95  ddrot = DDRotation( myrRotation->getDDName (nmspace) );
96  }
97 
98  DDSolid theSolid;
99 
100  if (name == "UnionSolid") {
101  theSolid = DDSolidFactory::unionSolid (getDDName(nmspace)
102  , DDSolid(ddn1)
103  , DDSolid(ddn2)
104  , DDTranslation(x, y, z)
105  , ddrot
106  );
107  }
108  else if (name == "SubtractionSolid") {
109  theSolid = DDSolidFactory::subtraction (getDDName(nmspace)
110  , DDSolid(ddn1)
111  , DDSolid(ddn2)
112  , DDTranslation(x, y, z)
113  , ddrot
114  );
115  }
116  else if (name == "IntersectionSolid") {
117  theSolid = DDSolidFactory::intersection (getDDName(nmspace)
118  , DDSolid(ddn1)
119  , DDSolid(ddn2)
120  , DDTranslation(x, y, z)
121  , ddrot
122  );
123  }
124  else {
125  throw cms::Exception("DDException") << "DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?";
126  }
127 
128  DDLSolid::setReference(nmspace, cpv);
129 
130  DCOUT_V('p', theSolid);
131 
132  // clear all "children" and attributes
133  myTranslation->clear();
134  myrRotation->clear();
135  myrSolid->clear();
136  clear();
137  DCOUT_V('P', "DDLBooleanSolid::processElement completed");
138 
139 }
140 
141 // This only happens on error, so I don't care how "slow" it is :-)
142 std::string
143 DDLBooleanSolid::dumpBooleanSolid( const std::string& name, const std::string& nmspace )
144 {
145  std::string s;
147 
148  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
149 
150  if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
151  if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
152  s += ">\n";
153 
154  DDXMLElement* myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
155  DDXMLElement* myTranslation = myRegistry_->getElement("Translation"); // get Translation child
156  DDXMLElement* myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
157  if (myrSolid->size() > 0)
158  {
159  for (size_t i = 0; i < myrSolid->size(); ++i)
160  {
161  atts = myrSolid->getAttributeSet(i);
162  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
163  }
164  }
165 
166  atts = myTranslation->getAttributeSet();
167  s+= "<Translation";
168  if (atts.find("x") != atts.end())
169  s+=" x=\"" + atts.find("x")->second + "\"";
170  if (atts.find("y") != atts.end())
171  s+= " y=\"" + atts.find("y")->second + "\"";
172  if (atts.find("z") != atts.end())
173  s+= " z=\"" + atts.find("z")->second + "\"";
174  s+="/>\n";
175 
176  atts = myrRotation->getAttributeSet();
177  if (atts.find("name") != atts.end())
178  {
179  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
180  }
181  s+= "</" + name + ">\n\n";
182  return s;
183 }
int i
Definition: DBlmapReader.cc:9
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:186
~DDLBooleanSolid()
Destructor.
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:79
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:18
type of data representation of DDCompactView
Definition: DDCompactView.h:77
double double double z
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:55
A DDSolid represents the shape of a part.
Definition: DDSolid.h:35
ROOT::Math::DisplacementVector3D< ROOT::Math::Cartesian3D< double > > DDTranslation
Definition: DDTranslation.h:7
Represents a uniquely identifyable rotation matrix.
Definition: DDTransform.h:66
DDXMLElement * getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
static value_type & instance()
static DDSolid intersection(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:714
virtual size_t size(void) const
Number of elements accumulated.
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Processing the element.
Interface of an Expression Evaluator.
DDLBooleanSolid(DDLElementRegistry *myreg)
Constructor.
#define DCOUT_V(M_v_Y, M_v_S)
Definition: DDdebug.h:54
std::string dumpBooleanSolid(const std::string &name, const std::string &nmspace)
DDLSolid processes Box elements.
Definition: DDLSolid.h:27
virtual double eval(const std::string &ns, const std::string &expr)=0
evaluate an expression expr inside the local namespace
static DDSolid subtraction(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:705
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:58
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv)
Called by loadAttributes AFTER attributes are loaded.
The main class for processing parsed elements.
virtual void clear(void)
clear this element&#39;s contents.
Definition: DDXMLElement.cc:61
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:696
x
Definition: VDTMath.h:216
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:86
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:26