CMS 3D CMS Logo

DDLPgonGenerator.cc
Go to the documentation of this file.
2 
3 #include <stddef.h>
4 #include <map>
5 #include <utility>
6 #include <vector>
7 
13 
14 class DDCompactView;
15 
17  : DDLSolid( myreg )
18 {}
19 
20 void
22 {
23  myRegistry_->getElement("XYPoint")->clear();
24  myRegistry_->getElement("ZXYSection")->clear();
25 }
26 
27 // Upon encountering an end Extruded Polygone tag, process the XYPoints
28 // element and extract the x and y std::vectors to feed into DDCore. Then, clear
29 // the XYPoints and clear this element.
30 void
32  const std::string& nmspace,
33  DDCompactView& cpv )
34 {
35  auto myXYPoints = myRegistry_->getElement( "XYPoint" );
36  auto myZXYSection = myRegistry_->getElement( "ZXYSection" );
37 
39  DDXMLAttribute atts;
40 
41  // get x and y
42  std::vector<double> x, y;
43  for( size_t i = 0; i < myXYPoints->size(); ++i )
44  {
45  atts = myXYPoints->getAttributeSet( i );
46  auto xit = atts.find( "x" );
47  if( xit != atts.end())
48  x.push_back( ev.eval( nmspace, xit->second ));
49  auto yit = atts.find( "y" );
50  if( yit != atts.end())
51  y.push_back( ev.eval( nmspace, yit->second ));
52  }
53  assert( x.size() == y.size());
54 
55  // get zSection information
56  std::vector<double> z, zx, zy, zscale;
57 
58  for( size_t i = 0; i < myZXYSection->size(); ++i )
59  {
60  atts = myZXYSection->getAttributeSet( i );
61  auto zit = atts.find( "z" );
62  if( zit != atts.end())
63  z.push_back( ev.eval( nmspace, zit->second ));
64  auto xit = atts.find( "x" );
65  if( xit != atts.end())
66  zx.push_back( ev.eval( nmspace, xit->second ));
67  auto yit = atts.find( "y" );
68  if( yit != atts.end())
69  zy.push_back( ev.eval( nmspace, yit->second ));
70  auto sit = atts.find( "scale" );
71  if( sit != atts.end())
72  zscale.push_back( ev.eval( nmspace, sit->second ));
73  }
74  assert( z.size() == zx.size());
75  assert( z.size() == zy.size());
76  assert( z.size() == zscale.size());
77 
78  atts = getAttributeSet();
79  if( name == "ExtrudedPolygon" )
80  {
81  DDSolid extrudedpolygon =
83  x, y,
84  z, zx, zy, zscale );
85  } else
86  {
87  std::string msg = "\nDDLPgonGenerator::processElement was called with incorrect name of solid: " + name;
88  throwError( msg );
89  }
90  DDLSolid::setReference( nmspace, cpv );
91 
92  // clear out XYPoint element accumulator and ZXYSections
93  myXYPoints->clear();
94  myZXYSection->clear();
95  clear();
96 }
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.
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:37
void preProcessElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Called by loadAttributes AFTER attributes are loaded.
ClhepEvaluator & evaluator()
std::shared_ptr< DDXMLElement > getElement(const std::string &name)
THE most important part. Getting the pointer to a given element type.
DDLPgonGenerator(DDLElementRegistry *myreg)
DDLSolid processes Box elements.
Definition: DDLSolid.h:30
static DDSolid extrudedpolygon(const DDName &name, const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< double > &zx, const std::vector< double > &zy, const std::vector< double > &zscale)
Definition: DDSolid.cc:755
void processElement(const std::string &name, const std::string &nmspace, DDCompactView &cpv) override
Processing the element.
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
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