VGM Version 5.3
Loading...
Searching...
No Matches
GDMLWriter.h
Go to the documentation of this file.
1// $Id$
2
3// -----------------------------------------------------------------------
4// The XmlVGM package of the Virtual Geometry Model
5// Copyright (C) 2007, Ivana Hrivnacova
6// All rights reserved.
7//
8// For the licensing terms see vgm/LICENSE.
9// Contact: ivana@ipno.in2p3.fr
10// -----------------------------------------------------------------------
11
13//
20
21#ifndef XML_VGM_GDML_WRITER_H
22#define XML_VGM_GDML_WRITER_H
23
24#include "XmlVGM/IWriter.h"
25
26#include <fstream>
27#include <set>
28#include <vector>
29
30namespace VGM {
31class ISolid;
32class IBooleanSolid;
33class IArb8;
34class IBox;
35class IBox;
36class ICons;
37class ICtubs;
38class IEllipsoid;
39class IEllipticalTube;
40class IExtrudedSolid;
41class IHype;
42class IMultiUnion;
43class IPara;
44class IParaboloid;
45class IPolycone;
46class IPolyhedra;
47class ISphere;
48class ITessellatedSolid;
49class ITorus;
50class ITrap;
51class ITrd;
52class ITubs;
53class IMaterial;
54class IElement;
55class IVolume;
56class IPlacement;
57} // namespace VGM
58
59namespace XmlVGM {
60
61class Maps;
62
63class GDMLWriter : public virtual IWriter
64{
65 public:
67 const std::string& unitName = "unit1", const std::string& version = "1.0");
68 virtual ~GDMLWriter();
69
70 // methods
71
72 // XML elements
73 //
74 virtual void OpenFile(std::string filePath);
75 virtual void OpenDocument();
76 virtual void OpenSection(const std::string& topVolume);
77 virtual void OpenPositions();
78 virtual void OpenRotations();
79 virtual void OpenMaterials();
80 virtual void OpenMedia() {}
81 virtual void OpenSolids();
82 virtual void OpenStructure();
83 virtual void OpenComposition(
84 const std::string& name, const std::string& materialName);
85
86 virtual void CloseFile();
87 virtual void CloseDocument();
88 virtual void CloseSection(const std::string& topVolume);
89 virtual void ClosePositions();
90 virtual void CloseRotations();
91 virtual void CloseMaterials();
92 virtual void CloseMedia() {}
93 virtual void CloseSolids();
94 virtual void CloseStructure();
95 virtual void CloseComposition();
96
97 // Geometry elements
98 //
99 virtual void WriteIsotope(const VGM::IIsotope* isotope);
100
101 virtual void WriteElement(const VGM::IElement* element);
102
103 virtual void WriteMaterial(const VGM::IMaterial* material);
104
105 virtual void WriteMedium(const VGM::IMedium* /*medium*/) {}
106 virtual void WriteMedium(const VGM::IMaterial* /*material*/) {}
107
108 virtual void WriteSolid(
109 std::string lvName, const VGM::ISolid* solid, std::string /*mediumName*/);
110
111 virtual void WritePosition(
112 const std::string& name, const VGM::Transform& transform);
113
114 virtual void WriteRotation(
115 const std::string& name, const VGM::Transform& transform);
116
117 virtual void WriteScale(const std::string& name);
118
119 virtual void WritePlacement(const VGM::IPlacement& placement);
120
121 // Formatting utilities
122 //
123 virtual void WriteEmptyLine();
124 virtual void IncreaseIndention();
125 virtual void DecreaseIndention();
126
127 // Units
128 //
129 virtual double LengthUnit() const;
130 virtual double AngleUnit() const;
131 virtual double AtomicWeightUnit() const;
132 virtual double MassDensityUnit() const;
133 virtual double TemperatureUnit() const;
134 virtual double PressureUnit() const;
135
136 // Set methods
137 //
138 virtual void SetMaps(Maps* maps);
139 virtual void SetNumWidth(int width);
140 virtual void SetNumPrecision(int precision);
141
142 // Get methods
143 //
144 virtual double GetNumWidth() const;
145 virtual double GetNumPrecision() const;
146
147 protected:
148 GDMLWriter(const GDMLWriter& rhs);
149
150 private:
151 // types
152 //
153 typedef std::set<std::string, std::less<std::string> > StringSet;
154
155 // Utility methods
156 //
157 double UpdateAngle(double angle) const;
158 void RegisterName(const std::string& name, bool warning = true);
159
160 // Writing solids
161 //
162 void WriteBooleanSolid(std::string name, const VGM::IBooleanSolid* solid);
163 void WriteBox(std::string lvName, double hx, double hy, double hz);
164 void WriteArb8(std::string name, const VGM::IArb8* arb8);
165 void WriteBox(std::string name, const VGM::IBox* box);
166 void WriteCons(std::string name, const VGM::ICons* cons);
167 void WriteCtubs(std::string name, const VGM::ICtubs* ctubs);
168 void WriteEllipsoid(std::string name, const VGM::IEllipsoid* ellipsoid);
169 void WriteEllipticalTube(std::string name, const VGM::IEllipticalTube* eltu);
170 void WriteExtrudedSolid(
171 std::string name, const VGM::IExtrudedSolid* extruded);
172 void WriteHype(std::string name, const VGM::IHype* hype);
173 void WriteMultiUnion(std::string name, const VGM::IMultiUnion* multiUnion);
174 void WritePara(std::string name, const VGM::IPara* para);
175 void WriteParaboloid(std::string name, const VGM::IParaboloid* paraboloid);
176 void WritePolycone(std::string name, const VGM::IPolycone* polycone);
177 void WritePolyhedra(std::string name, const VGM::IPolyhedra* polyhedra);
178 void WriteSphere(std::string name, const VGM::ISphere* sphere);
179 void WriteTessellatedSolid(
180 std::string name, const VGM::ITessellatedSolid* tessellated);
181 void WriteTorus(std::string name, const VGM::ITorus* torus);
182 void WriteTrap(std::string name, const VGM::ITrap* trap);
183 void WriteTrd(std::string name, const VGM::ITrd* trd);
184 void WriteTubs(std::string name, const VGM::ITubs* tubs);
185 void WriteNotSupportedSolid(std::string name);
186
187 // Writing placements
188 //
189 virtual void WriteSimplePlacement(const std::string& lvName,
190 const std::string& positionRef, const std::string& rotationRef,
191 bool isReflection);
192
193 virtual void WriteMultiplePlacement(const std::string& lvName, VGM::Axis axis,
194 int nofReplicas, double width, double offset);
195
196 // static data members
197 //
198 static const int fgkDefaultNumWidth; // default output numbers width
199 static const int fgkDefaultNumPrecision; // default output numbers precision
200 static const std::string fgkSolidNameExtension; // solid names extension
201 static const std::string fgkIsotopeNameExtension; // isotope names extension
202 static const std::string fgkElementNameExtension; // element names extension
203 static const char fgkCharReplacement; // replacement for ' ' in names
204 static const std::string fgkNotAllowedChars; // not allowed characters in XML
205 static const std::string fgkNotAllowedChars1; // not allowed first characters
206 // in XML names
207 static const double fgkSTPTemperature;
208 static const double fgkSTPPressure;
209 static const double fgkCarTolerance;
210 static const double fgkAngTolerance;
211
212 // data members
213 //
214 std::ofstream fOutFile; // output file
215 std::string fUnitName; // unit name
216 std::string fVersion; // geometry version
217 const std::string fkBasicIndention; // basic indention
218 std::string fIndention; // indention string
219 int fNW; // output numbers width
220 int fNP; // output numbers precision
221 StringSet fGDMLNames; // names in GDML
222 Maps* fMaps; // name maps
223 bool fFullLengths; // full lengths in solids
224};
225
226} // namespace XmlVGM
227
228inline double XmlVGM::GDMLWriter::LengthUnit() const { return 10.; } // cm
229
230inline double XmlVGM::GDMLWriter::AngleUnit() const { return 1.; } // deg
231
233{
234 return 1.;
235} // g/mole
236
238{
239 return 1.;
240} // g/cm3
241
243{
244 return 1.;
245} // kelvin
246
248{
249 return 1. / 101325.0;
250} // pascal
251
253{
254 fMaps = maps;
255}
256
257inline void XmlVGM::GDMLWriter::SetNumWidth(int width) { fNW = width; }
258
259inline void XmlVGM::GDMLWriter::SetNumPrecision(int precision)
260{
261 fNP = precision;
262}
263
264inline double XmlVGM::GDMLWriter::GetNumWidth() const { return fNW; }
265
266inline double XmlVGM::GDMLWriter::GetNumPrecision() const { return fNP; }
267
268#endif // XML_VGM_GDML_WRITER_H
VGM Axis enumeration.
The VGM interface to Arb8 solids.
Definition IArb8.h:31
The VGM interface to Boolean solids.
The VGM interface to box solids.
Definition IBox.h:30
The VGM interface to cons solids.
Definition ICons.h:30
The VGM interface to cut tubs solids.
Definition ICtubs.h:30
The VGM interface to elements.
Definition IElement.h:34
The VGM interface to ellipsoid solids.
Definition IEllipsoid.h:30
The VGM interface to elliptical tube solids.
The VGM interface to extruded solids.
The VGM interface to hyperboloid solids.
Definition IHype.h:30
The VGM interface to elements.
Definition IIsotope.h:28
The VGM interface to materials.
Definition IMaterial.h:44
The VGM interface to tracking medium.
Definition IMedium.h:31
The VGM interface to Boolean solids.
Definition IMultiUnion.h:31
The VGM interface to para solids.
Definition IPara.h:30
The VGM interface to paraboloid solids.
Definition IParaboloid.h:30
The VGM interface to positions of volumes.
Definition IPlacement.h:44
The VGM interface to polycone solids.
Definition IPolycone.h:30
The VGM interface to polyhedra solids.
Definition IPolyhedra.h:30
The VGM interface to solids.
Definition ISolid.h:58
The VGM interface to sphere solids.
Definition ISphere.h:30
The VGM interface to extruded solids.
The VGM interface to torus solids.
Definition ITorus.h:30
The VGM interface to trap solids.
Definition ITrap.h:30
The VGM interface to trd solids.
Definition ITrd.h:30
The VGM interface to tubs solids.
Definition ITubs.h:30
The implementation of the interface for the XML writer that writes VGM geometry objects to XML define...
Definition GDMLWriter.h:64
virtual void CloseMaterials()
Write materials definitions closing.
virtual double MassDensityUnit() const
Return the default mass density unit.
Definition GDMLWriter.h:237
virtual void WriteRotation(const std::string &name, const VGM::Transform &transform)
Write rotation (from VGM transformation)
virtual void CloseStructure()
Write structure definition closing (if present)
virtual void SetNumWidth(int width)
Set fixed format number width.
Definition GDMLWriter.h:257
virtual void OpenSolids()
Write solids definitions opening.
virtual void OpenPositions()
Write positions definitions opening.
virtual double GetNumPrecision() const
Return fixed format number precision.
Definition GDMLWriter.h:266
virtual void WriteEmptyLine()
Write empty line.
virtual void CloseSolids()
Write materials definitions closing.
virtual void CloseFile()
Close output file.
virtual double LengthUnit() const
Return the default length unit.
Definition GDMLWriter.h:228
virtual void OpenStructure()
Write structure definition opening (if present)
virtual void SetNumPrecision(int precision)
Set fixed format number precision.
Definition GDMLWriter.h:259
GDMLWriter(const std::string &unitName="unit1", const std::string &version="1.0")
virtual void CloseMedia()
Write media definitions closing.
Definition GDMLWriter.h:92
virtual double GetNumWidth() const
Return fixed format number width.
Definition GDMLWriter.h:264
virtual void SetMaps(Maps *maps)
Definition GDMLWriter.h:252
virtual void WriteMaterial(const VGM::IMaterial *material)
Write VGM material.
virtual double TemperatureUnit() const
Definition GDMLWriter.h:242
virtual void WritePosition(const std::string &name, const VGM::Transform &transform)
Write position (from VGM transformation)
virtual void OpenMaterials()
Write materials definitions opening.
virtual double PressureUnit() const
Definition GDMLWriter.h:247
virtual void OpenComposition(const std::string &name, const std::string &materialName)
Write composition definition opening (if present)
virtual void IncreaseIndention()
Increase indention.
virtual void OpenRotations()
Write rotations definitions opening.
virtual void WritePlacement(const VGM::IPlacement &placement)
Write VGM placement.
virtual void OpenMedia()
Write media definitions opening.
Definition GDMLWriter.h:80
virtual void WriteMedium(const VGM::IMaterial *)
Write medium element from material.
Definition GDMLWriter.h:106
virtual void DecreaseIndention()
Decrease indention.
virtual void WriteMedium(const VGM::IMedium *)
Write VGM medium.
Definition GDMLWriter.h:105
virtual void CloseComposition()
Write composition definition closing (if present)
virtual double AtomicWeightUnit() const
Return the default atomic weight unit.
Definition GDMLWriter.h:232
virtual void OpenSection(const std::string &topVolume)
Write the section opening (if present)
virtual void ClosePositions()
Write positions definitions closing.
virtual void OpenFile(std::string filePath)
Open output file.
virtual void WriteSolid(std::string lvName, const VGM::ISolid *solid, std::string)
Write VGM solid.
virtual void WriteScale(const std::string &name)
Write scale (from VGM transformation)
virtual void CloseDocument()
Write XML document closing.
virtual void OpenDocument()
Write XML document opening.
virtual void WriteElement(const VGM::IElement *element)
Write VGM element.
virtual double AngleUnit() const
Return the default angle unit.
Definition GDMLWriter.h:230
virtual void CloseSection(const std::string &topVolume)
Write the section closing (if present)
virtual void CloseRotations()
Write rotations definitions closing.
virtual void WriteIsotope(const VGM::IIsotope *isotope)
Write VGM isotope.
The interface for the XML writer that writes VGM geometry objects to XML:
Definition IWriter.h:43
Utility class for mapping XML element values to their names within the XML exporter precision.
Definition Maps.h:42
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40
XmlVGM utilities.