Skip to content
Snippets Groups Projects
Commit f93b68b1 authored by Andrea Dell'Acqua's avatar Andrea Dell'Acqua
Browse files

add realistic implementation for arb8 and xtru

parent 7ccad300
No related branches found
No related tags found
No related merge requests found
#ifndef sectionHandler_H
#define sectionHandler_H
#include "GDMLInterface/GDMLHandler.h"
#include "GDMLInterface/GDMLController.h"
struct section {
double scalingFactor;
double xOffset;
double yOffset;
int zOrder;
double zPosition;
};
class sectionHandler:public GDMLHandler {
public:
sectionHandler(std::string n, GDMLController* c): GDMLHandler(n,c) {}
void ElementHandle() {
s.scalingFactor=getAttributeAsDouble("scalingFactor");
s.xOffset=getAttributeAsDouble("xOffset");
s.yOffset=getAttributeAsDouble("yOffset");
s.zOrder=getAttributeAsInt("zOrder");
s.zPosition=getAttributeAsDouble("zPosition");
}
section& getSection() {return s;}
private:
section s;
};
#endif /* end of include guard: */
#ifndef twoDimVertexHandler_H
#define twoDimVertexHandler_H
#include "GDMLInterface/GDMLHandler.h"
#include "GDMLInterface/GDMLController.h"
struct twoDVtx {
double xv;
double yv;
};
class twoDimVertexHandler:public GDMLHandler {
public:
twoDimVertexHandler(std::string n, GDMLController* c): GDMLHandler(n,c) {}
void ElementHandle() {
v.xv=getAttributeAsDouble("x");
v.yv=getAttributeAsDouble("y");
}
twoDVtx& getVtx() {return v;}
private:
twoDVtx v;
};
#endif /* end of include guard: */
......@@ -243,6 +243,8 @@ GeoVolume GDMLController::retrieveLogicalVolume(std::string name)
#include "GDMLInterface/quadrangularHandler.h"
#include "GDMLInterface/xtruHandler.h"
#include "GDMLInterface/arb8Handler.h"
#include "GDMLInterface/sectionHandler.h"
#include "GDMLInterface/twoDimVertexHandler.h"
void GDMLController::registerHandlers()
{
......@@ -296,4 +298,6 @@ void GDMLController::registerHandlers()
new quadrangularHandler("quadrangular",this);
new xtruHandler("xtru",this);
new arb8Handler("arb8",this);
new twoDimVertexHandler("twoDimVertex",this);
new sectionHandler("section",this);
}
......@@ -2,21 +2,69 @@
#include "GDMLInterface/GDMLHandler.h"
#include <iostream>
#include "GeoModelKernel/GeoBox.h"
#include "GeoModelXMLParser/XercesParser.h"
#include "GeoModelKernel/GeoSimplePolygonBrep.h"
#include "GeoModelKernel/GeoDefinitions.h"
#include "GDMLInterface/sectionHandler.h"
#include "GDMLInterface/twoDimVertexHandler.h"
xtruHandler::xtruHandler(std::string s,GDMLController* g):GDMLHandler(s,g)
{
// std::cout<<"constructing boxHandler!"<<std::endl;
// std::cout<<"constructing tubeHandler!"<<std::endl;
}
void xtruHandler::ElementHandle()
{
std::cout<<" this is xtruHandler. No implementation yet, returning box"<<std::endl;
StopLoop(true);
std::string name=getAttributeAsString("name");
double lunit=getAttributeAsDouble("lunit");
// This interface is only for GeoSimplePolygonBrep.Checks are performed to
// ensure a GSPB can be built out of the parameters being collected, in any
// other case an exception is thrown
GeoShape* box=new GeoBox(50.,50.,50.);
theController->saveSolid(name,box);
GeoSimplePolygonBrep* pgsb;
std::vector<section> theSections;
std::vector<twoDVtx> theVertices;
StopLoop(true);
xercesc::DOMNode *child;
for (child=XercesParser::GetCurrentElement()->getFirstChild();child!=0;child=child->getNextSibling())
{
if (child->getNodeType()==xercesc::DOMNode::ELEMENT_NODE)
{
XercesParser::elementLoop(child);
XMLHandler *h=theController->XMLStore()->GetHandler(child);
sectionHandler* sH=dynamic_cast<sectionHandler*>(h);
if (sH)
{
section s=sH->getSection();
theSections.push_back(s);
}
twoDimVertexHandler* tH=dynamic_cast<twoDimVertexHandler*>(h);
if (tH)
{
twoDVtx d=tH->getVtx();
theVertices.push_back(d);
}
}
}
if (theSections.size() != 2) throw; // we want a maximum of two sections
if (theSections[0].scalingFactor != 1. || theSections[1].scalingFactor != 1.) throw; // no scaling
if ((theSections[0].xOffset!=0 || theSections[0].yOffset!=0) || (theSections[1].xOffset!=0 || theSections[1].yOffset!=0)) throw; // no offset
if ((theSections[0].zPosition+theSections[1].zPosition) != 0) throw; // centered at z=0
pgsb=new GeoSimplePolygonBrep(std::fabs(theSections[1].zPosition));
for (auto vt: theVertices)
{
pgsb->addVertex(vt.xv,vt.yv);
}
theController->saveSolid(name,pgsb);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment