EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
EicCadFile.h
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file EicCadFile.h
1 //
2 // AYK (ayk@bnl.gov), 2014/03/07; revamped in Oct'2017;
3 //
4 // EicRoot CAD files manipulation routines; main C++ file;
5 //
6 // NB: EicColorExtension class and other debugging codes were removed on 2017/10/04;
7 //
8 
9 #include <TGeoMedium.h>
10 
11 #include <EicUnits.h>
12 #include <EicDetector.h>
13 
14 #ifndef _EIC_CAD_FILE_
15 #define _EIC_CAD_FILE_
16 
17 #include <EicCadFileConfig.h>
18 
19 #ifdef _OPENCASCADE_
20 class TopoDS_Shape;
21 class TopoDS_Face;
22 class gp_Pnt;
23 class gp_Ax3;
24 
25 class EicOpenCascadeShape {
26  friend class EicCadFile;
27  friend class EicCadWizard;
28  friend bool EicCadShapeEqual(const std::pair<unsigned, EicOpenCascadeShape> &lh,
29  const std::pair<unsigned, EicOpenCascadeShape> &rh);
30 
31  public:
32  EicOpenCascadeShape(): object(0), dimension(0), solid(0) {};
33  ~EicOpenCascadeShape() {};
34 
35  enum ShapeType {_OCC_PLANE_, _OCC_CYLINDER_, _OCC_CONE_, _OCC_SPHERE_, _OCC_TORUS_};
36 
37  private:
38  ShapeType sType;
39  void *object;
40  double dimension;
41 
42  TopoDS_Shape *solid;
43 };
44 #endif
45 
46 #ifdef _ELMER_
47 class mesh_t;
48 #endif
49 
50 #define _COLOR_DEFAULT_ (kBlue)
51 
52 // Main class for CAD file import;
54  public:
61  EicCadFile(const char *Name, char *geometryName, char *mediaName = 0, int color = _COLOR_DEFAULT_);
62  // Dummy constructor;
64  // Destructor;
65  ~EicCadFile() { if (mConfig) delete mConfig; };
66 
67  EicCadFileConfig *GetConfig( void ) { return mConfig; };
68  // Sorry, I like short C-style names too;
69  EicCadFileConfig *config( void ) { return mConfig; };
70 
71  void AllowRootSolidCreation(bool what = true) { mRootSolidCreationAllowed = what; };
72  void AllowStlSolidCreation(bool what = true) { mStlSolidCreationAllowed = what; };
73  void AllowStepSolidDecomposition(bool what = true) { mStepSolidDecompositionAllowed = what; };
74 
75  void SetExtraStlTranslation(double dx, double dy, double dz) {
76  mExtraStlTranslation = TVector3(dx, dy, dz);
77  };
78  void SetKillerFlag( void ) { mKillerFlag = true; };
79  void SwapXY( void ) { mSwapXY = true; };
80  //void SetWireframeMode( void ) { mWireframeMode = true; };
81  // FIXME: assume reflection about XZ- or XY-plane; what a crap!;
84 
85  void WizardTestbed( void );
86 
87  private:
90 
92  TGeoVolume *mCave;
93 
95 
97  // If 'false' EicCadFile::HandleThisSolid() will always call DumpAsStlSolid() rather
98  // than DumpAsRootSolid() at the end; NB: one can also consider to perform STL-ization
99  // right from the imported STEP solid, without making attempts to decompose it;
101 
102  // If 'false', STEP shape goes directly to STL factory;
104 
106 
107  void ResetVariables( void );
108 
111  void ConstructGeometry();
112 
113 #ifdef _OPENCASCADE_
114  // Well, it is convenient to have these "global" working variables here rather
115  // than pass them to handleThisSolid() and all the other functions it calls;
116  // NB: these variables are marked as "//!", so seemingly ROOT sreamer should
117  // never become confused by handling .root files created with and without
118  // OpenCascade support instances of this class;
119  gp_Pnt *boundarySphereCenter;
120  double boundarySphereRadius;
121 
122  void ConstructDummyStepGeometry();
123  void ConstructStepGeometry();
124  void ConstructIgesGeometry();
125 
126  enum FaceType {FaceTypeAny, FaceTypeFlat, FaceTypeCurved};
127 
128  void HandleThisSolid(const TopoDS_Shape &solid, TGeoMedium *medium, double *color);
129  void HandleThisSolidWrapper(const TopoDS_Shape &solid, TGeoMedium *medium, double *color);
130 
131  void DumpAsStlSolid(const TopoDS_Shape &solid, TGeoMedium *medium);
132  TGeoCombiTrans *Ax3ToCombiTrans(char *name, const gp_Ax3 &ax3, double offset = 0.0);
133 
134  void DumpAsRootSolid(const TopoDS_Shape &solid,
135  std::vector< std::pair<unsigned, EicOpenCascadeShape> > &facets,
136  TGeoMedium *medium, double *color);
137  Bool_t elementaryFaceType(TopoDS_Face &face, FaceType fType = FaceTypeAny);
138  Bool_t splitSolidByInfiniteFace(const TopoDS_Shape &solid, const TopoDS_Face &face,
139  EicOpenCascadeShape &cuttingShape,
140  std::vector<TopoDS_Shape> &commonSolids,
141  std::vector<TopoDS_Shape> &cutSolids);
142  //Bool_t elementaryFlatEdgeType(TopoDS_Edge &edge);
143 #endif
144 
146  bool mSwapXY /*, mWireframeMode*/;
147  // FIXME: apply to other objects later (as well as implement rotation);
150 
151 #ifdef _ELMER_
152  void ConstructElmerGeometry();
153 
154  mesh_t *mElmerMesh;
155 #endif
156 
157  ClassDef(EicCadFile,20)
158 };
159 
160 #endif