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 
21 
23 
25  : DDLSolid( myreg )
26 {}
27 
29 {}
30 
31 // Clear out rSolids.
32 void
33 DDLBooleanSolid::preProcessElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
34 {
35  myRegistry_->getElement( "rSolid" )->clear();
36 }
37 
38 // To process a BooleanSolid we should have in the meantime
39 // hit two rSolid calls and possibly one rRotation and one Translation.
40 // So, retrieve them and make the call to DDCore.
41 void
42 DDLBooleanSolid::processElement( const std::string& name, const std::string& nmspace, DDCompactView& cpv )
43 {
44  DCOUT_V( 'P', "DDLBooleanSolid::processElement started" );
45 
46  // new DDLBoolean will handle:
47  // <UnionSolid name="bs" firstSolid="blah" secondSolid="argh"> <Translation...> <rRotation .../> </UnionSolid
48  // AND <UnionSolid> <rSolid...> <rSolid...> <Translation...> <rRotation...> </UnionSolid>
49 
50  DDXMLElement* myrSolid = myRegistry_->getElement( "rSolid" ); // get rSolid children
51  DDXMLElement* myTranslation = myRegistry_->getElement( "Translation" ); // get Translation child
52  DDXMLElement* myrRotation = myRegistry_->getElement( "rRotation" ); // get rRotation child
53 
56 
57  DDName ddn1, ddn2;
58  double x=0.0, y=0.0, z=0.0;
59  DDRotation ddrot;
60 
61  // Basically check if there are rSolids or Translation or rRotation then we have
62  // should NOT have any of the attributes shown above.
63  if( myrSolid->size() == 0 )
64  {
65  // do the solids using the attributes only.
66  if ( atts.find("firstSolid") != atts.end() && atts.find("secondSolid") != atts.end() ) {
67  ddn1 = getDDName(nmspace, "firstSolid");
68  ddn2 = getDDName(nmspace, "secondSolid");
69  } else {
70  std::string s ("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
71  s += dumpBooleanSolid(name, nmspace);
72  throwError( s );
73  }
74  }
75  else if (myrSolid->size() == 2)
76  {
77  ddn1 = myrSolid->getDDName(nmspace, "name", 0);
78  ddn2 = myrSolid->getDDName(nmspace, "name", 1);
79  } else {
80  std::string s("DDLBooleanSolid did not find any solids with which to form a boolean solid.");
81  s += dumpBooleanSolid(name, nmspace);
82  throwError( s );
83  }
84 
85  if (myTranslation->size() > 0)
86  {
87  atts.clear();
88  atts = myTranslation->getAttributeSet();
89  x = ev.eval(nmspace, atts.find("x")->second);
90  y = ev.eval(nmspace, atts.find("y")->second);
91  z = ev.eval(nmspace, atts.find("z")->second);
92  }
93 
94  if (myrRotation->size() > 0)
95  {
96  ddrot = DDRotation( myrRotation->getDDName (nmspace) );
97  }
98 
99  DDSolid theSolid;
100 
101  if (name == "UnionSolid") {
102  theSolid = DDSolidFactory::unionSolid (getDDName(nmspace)
103  , DDSolid(ddn1)
104  , DDSolid(ddn2)
105  , DDTranslation(x, y, z)
106  , ddrot
107  );
108  }
109  else if (name == "SubtractionSolid") {
110  theSolid = DDSolidFactory::subtraction (getDDName(nmspace)
111  , DDSolid(ddn1)
112  , DDSolid(ddn2)
113  , DDTranslation(x, y, z)
114  , ddrot
115  );
116  }
117  else if (name == "IntersectionSolid") {
118  theSolid = DDSolidFactory::intersection (getDDName(nmspace)
119  , DDSolid(ddn1)
120  , DDSolid(ddn2)
121  , DDTranslation(x, y, z)
122  , ddrot
123  );
124  }
125  else {
126  throw DDException("DDLBooleanSolid was asked to do something other than Union-, Subtraction- or IntersectionSolid?");
127  }
128 
129  DDLSolid::setReference(nmspace, cpv);
130 
131  DCOUT_V('p', theSolid);
132 
133  // clear all "children" and attributes
134  myTranslation->clear();
135  myrRotation->clear();
136  myrSolid->clear();
137  clear();
138  DCOUT_V('P', "DDLBooleanSolid::processElement completed");
139 
140 }
141 
142 // This only happens on error, so I don't care how "slow" it is :-)
143 std::string
144 DDLBooleanSolid::dumpBooleanSolid( const std::string& name, const std::string& nmspace )
145 {
146  std::string s;
148 
149  s = std::string ("\n<") + name + " name=\"" + atts.find("name")->second + "\"";
150 
151  if (atts.find("firstSolid") != atts.end()) s+= " firstSolid=\"" + atts.find("firstSolid")->second + "\"";
152  if (atts.find("secondSolid") != atts.end()) s+= " secondSolid=\"" + atts.find("secondSolid")->second + "\"";
153  s += ">\n";
154 
155  DDXMLElement* myrSolid = myRegistry_->getElement("rSolid"); // get rSolid children
156  DDXMLElement* myTranslation = myRegistry_->getElement("Translation"); // get Translation child
157  DDXMLElement* myrRotation = myRegistry_->getElement("rRotation"); // get rRotation child
158  if (myrSolid->size() > 0)
159  {
160  for (size_t i = 0; i < myrSolid->size(); ++i)
161  {
162  atts = myrSolid->getAttributeSet(i);
163  s+="<rSolid name=\"" + atts.find("name")->second + "\"/>\n";
164  }
165  }
166 
167  atts = myTranslation->getAttributeSet();
168  s+= "<Translation";
169  if (atts.find("x") != atts.end())
170  s+=" x=\"" + atts.find("x")->second + "\"";
171  if (atts.find("y") != atts.end())
172  s+= " y=\"" + atts.find("y")->second + "\"";
173  if (atts.find("z") != atts.end())
174  s+= " z=\"" + atts.find("z")->second + "\"";
175  s+="/>\n";
176 
177  atts = myrRotation->getAttributeSet();
178  if (atts.find("name") != atts.end())
179  {
180  s+= "<rRotation name=\"" + atts.find("name")->second + "\"/>\n";
181  }
182  s+= "</" + name + ">\n\n";
183  return s;
184 }
int i
Definition: DBlmapReader.cc:9
DDLElementRegistry * myRegistry_
Definition: DDXMLElement.h:187
~DDLBooleanSolid()
Destructor.
An exception for DDD errors.
Definition: DDException.h:23
virtual const DDXMLAttribute & getAttributeSet(size_t aIndex=0) const
Get a &quot;row&quot; of attributes, i.e. one attribute set.
Definition: DDXMLElement.cc:83
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:81
double double double z
std::map< std::string, std::string > DDXMLAttribute
Definition: DDXMLElement.h:56
A DDSolid represents the shape of a part.
Definition: DDSolid.h:42
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:717
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:708
This is a base class for processing XML elements in the DDD.
Definition: DDXMLElement.h:59
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:65
static DDSolid unionSolid(const DDName &name, const DDSolid &a, const DDSolid &b, const DDTranslation &t, const DDRotation &r)
Definition: DDSolid.cc:699
string s
Definition: asciidump.py:422
Definition: DDAxes.h:10
virtual const DDName getDDName(const std::string &defaultNS, const std::string &attname=std::string("name"), size_t aIndex=0)
Definition: DDXMLElement.cc:91
void setReference(const std::string &nmspace, DDCompactView &cpv)
Definition: DDLSolid.cc:26