VGM Version 5.3
Loading...
Searching...
No Matches
AGDDWriter.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//
21
22#ifndef XML_VGM_AGDD_WRITER_H
23#define XML_VGM_AGDD_WRITER_H
24
26
27#include "XmlVGM/IWriter.h"
28
29#include <fstream>
30#include <set>
31#include <string>
32#include <vector>
33
34namespace VGM {
35class ISolid;
36class IBooleanSolid;
37class IBox;
38class IBox;
39class ITubs;
40class ICons;
41class ITrd;
42class ITrap;
43class IPara;
44class IPolycone;
45class IPolyhedra;
46class IMaterial;
47class IElement;
48class IVolume;
49class IPlacement;
50} // namespace VGM
51
52namespace XmlVGM {
53
54class Maps;
55
56class AGDDWriter : public virtual IWriter
57{
58 public:
59 AGDDWriter(const std::string& version = "Undefined",
60 const std::string& author = "VGM AGGD Writer",
61 const std::string dtdVersion = "v7");
62 virtual ~AGDDWriter();
63
64 // methods
65
66 // XML elements
67 //
68 virtual void OpenFile(std::string filePath);
69 virtual void OpenDocument();
70 virtual void OpenSection(const std::string& topVolume);
71 virtual void OpenPositions() {}
72 virtual void OpenRotations() {}
73 virtual void OpenMaterials();
74 virtual void OpenMedia();
75 virtual void OpenSolids() {}
76 virtual void OpenStructure() {}
77 virtual void OpenComposition(
78 const std::string& name, const std::string& /*materialName*/);
79
80 virtual void CloseFile();
81 virtual void CloseDocument();
82 virtual void CloseSection(const std::string& /*topVolume*/);
83 virtual void ClosePositions() {}
84 virtual void CloseRotations() {}
85 virtual void CloseMaterials();
86 virtual void CloseMedia();
87 virtual void CloseSolids() {}
88 virtual void CloseStructure() {}
89 virtual void CloseComposition();
90
91 // Geometry elements
92 //
93 virtual void WriteIsotope(const VGM::IIsotope* isotope);
94
95 virtual void WriteElement(const VGM::IElement* element);
96
97 virtual void WriteMaterial(const VGM::IMaterial* material);
98
99 virtual void WriteMedium(const VGM::IMedium* medium);
100 virtual void WriteMedium(const VGM::IMaterial* material);
101
102 virtual void WriteSolid(
103 std::string lvName, const VGM::ISolid* solid, std::string mediumName);
104
105 virtual void WritePosition(
106 const std::string& /*name*/, const VGM::Transform& /*position*/)
107 {}
108 virtual void WriteRotation(
109 const std::string& /*name*/, const VGM::Transform& /*rotation*/)
110 {}
111 virtual void WriteScale(const std::string& /*name*/) {}
112
113 void WritePlacement(
114 const std::string& lvName, const VGM::ThreeVector& position);
115 virtual void WritePlacement(const VGM::IPlacement& placement);
116
117 // Formatting utilities
118 //
119 virtual void WriteEmptyLine();
120 virtual void IncreaseIndention();
121 virtual void DecreaseIndention();
122
123 // Units
124 //
125 virtual double LengthUnit() const;
126 virtual double AngleUnit() const;
127 virtual double AtomicWeightUnit() const;
128 virtual double MassDensityUnit() const;
129
130 // Set methods
131 //
132 virtual void SetNumWidth(int width);
133 virtual void SetNumPrecision(int precision);
134
135 // Get methods
136 //
137 virtual double GetNumWidth() const;
138 virtual double GetNumPrecision() const;
139
140 protected:
141 AGDDWriter(const AGDDWriter& rhs);
142
143 private:
144 // types
145 //
146 typedef std::set<std::string, std::less<std::string> > StringSet;
147
148 // Utility methods
149 //
150 std::string ElementSymbol(const VGM::IElement* element) const;
151 void RegisterName(const std::string& name, bool warning = true);
152 double Round2(double number) const;
153 bool IsIdentity(const VGM::ThreeVector& rotation) const;
154
155 // Writing solids
156 //
157 void WriteBooleanSolid(std::string lvName,
158 const VGM::IBooleanSolid* booleanSolid, std::string mediumName);
159
160 void WriteBox(std::string lvName, double hx, double hy, double hz,
161 std::string mediumName);
162
163 void WriteBox(
164 std::string lvName, const VGM::IBox* box, std::string mediumName);
165
166 void WriteCons(
167 std::string lvName, const VGM::ICons* cons, std::string mediumName);
168
169 void WritePara(
170 std::string lvName, const VGM::IPara* para, std::string mediumName);
171
172 void WritePolycone(
173 std::string lvName, const VGM::IPolycone* polycone, std::string mediumName);
174
175 void WritePolyhedra(std::string lvName, const VGM::IPolyhedra* polyhedra,
176 std::string mediumName);
177
178 void WriteTrap(
179 std::string lvName, const VGM::ITrap* trap, std::string mediumName);
180
181 void WriteTrd(
182 std::string lvName, const VGM::ITrd* trd, std::string mediumName);
183
184 void WriteTubs(
185 std::string lvName, const VGM::ITubs* tubs, std::string mediumName);
186
187 void WriteNotSupportedSolid(std::string name, std::string mediumName);
188
189 // Writing placements
190 //
191 virtual void WritePlacementWithRotation(std::string lvName,
192 const VGM::ThreeVector& position, const VGM::ThreeVector& rotation);
193
194 virtual void WritePlacementWithRotationAndReflection(std::string lvName,
195 const VGM::ThreeVector& position, const VGM::ThreeVector& rotation);
196
197 virtual void WriteMultiplePlacement(const std::string& lvName, VGM::Axis axis,
198 int nofReplicas, double width, double offset);
199
200 // static data members
201 //
202 static const int fgkDefaultNumWidth; // default output numbers width
203 static const int fgkDefaultNumPrecision; // default output numbers precision
204 static const std::string
205 fgkCompNameExtension; // name extension for composition
206 static const std::string fgkElementNameExtension; // element name extension
207 static const std::string fgkMaterialNameExtension; // material name extension
208 static const double fgkCarTolerance;
209 static const double fgkAngTolerance;
210
211 // data members
212 //
213 std::ofstream fOutFile; // output file
214 std::string fVersion; // geometry version
215 std::string fAuthor; // geometry author
216 std::string fDtdVersion; // DTD 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 fAGDDNames; // names in GDML
222};
223
224} // namespace XmlVGM
225
226// inline functions
227
228inline double XmlVGM::AGDDWriter::LengthUnit() const { return 10.; } // cm
229
230inline double XmlVGM::AGDDWriter::AngleUnit() const { return 1.; } // deg
231
233{
234 return 1.;
235} // g/mole
236
238{
239 return 1.;
240} // g/cm3
241
242inline void XmlVGM::AGDDWriter::SetNumWidth(int width) { fNW = width; }
243
244inline void XmlVGM::AGDDWriter::SetNumPrecision(int precision)
245{
246 fNP = precision;
247}
248
249inline double XmlVGM::AGDDWriter::GetNumWidth() const { return fNW; }
250
251inline double XmlVGM::AGDDWriter::GetNumPrecision() const { return fNP; }
252
253#endif // XML_VGM_AGDD_WRITER_H
VGM Axis enumeration.
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 elements.
Definition IElement.h:34
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 para solids.
Definition IPara.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 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 AGDDWriter.h:57
virtual double LengthUnit() const
Return the default length unit.
Definition AGDDWriter.h:228
virtual void ClosePositions()
Write positions definitions closing.
Definition AGDDWriter.h:83
virtual void CloseMedia()
Write media definitions closing.
virtual void OpenSolids()
Write solids definitions opening.
Definition AGDDWriter.h:75
virtual void WriteMaterial(const VGM::IMaterial *material)
Write VGM material.
virtual void CloseSection(const std::string &)
Write the section closing (if present)
virtual void CloseStructure()
Write structure definition closing (if present)
Definition AGDDWriter.h:88
virtual void WriteMedium(const VGM::IMedium *medium)
Write VGM medium.
virtual ~AGDDWriter()
virtual double AtomicWeightUnit() const
Return the default atomic weight unit.
Definition AGDDWriter.h:232
virtual void IncreaseIndention()
Increase indention.
virtual double MassDensityUnit() const
Return the default mass density unit.
Definition AGDDWriter.h:237
virtual void OpenMaterials()
Write materials definitions opening.
virtual void OpenStructure()
Write structure definition opening (if present)
Definition AGDDWriter.h:76
virtual void CloseSolids()
Write materials definitions closing.
Definition AGDDWriter.h:87
virtual void CloseRotations()
Write rotations definitions closing.
Definition AGDDWriter.h:84
virtual void CloseFile()
Close output file.
virtual void WriteSolid(std::string lvName, const VGM::ISolid *solid, std::string mediumName)
Write VGM solid.
virtual void WritePosition(const std::string &, const VGM::Transform &)
Write position (from VGM transformation)
Definition AGDDWriter.h:105
virtual void CloseDocument()
Write XML document closing.
virtual void SetNumPrecision(int precision)
Set fixed format number precision.
Definition AGDDWriter.h:244
virtual void WriteElement(const VGM::IElement *element)
Write VGM element.
virtual void DecreaseIndention()
Decrease indention.
virtual void WriteEmptyLine()
Write empty line.
virtual void WriteScale(const std::string &)
Write scale (from VGM transformation)
Definition AGDDWriter.h:111
virtual void OpenMedia()
Write media definitions opening.
void WritePlacement(const std::string &lvName, const VGM::ThreeVector &position)
virtual double AngleUnit() const
Return the default angle unit.
Definition AGDDWriter.h:230
virtual double GetNumPrecision() const
Return fixed format number precision.
Definition AGDDWriter.h:251
virtual void CloseComposition()
Write composition definition closing (if present)
AGDDWriter(const std::string &version="Undefined", const std::string &author="VGM AGGD Writer", const std::string dtdVersion="v7")
virtual void CloseMaterials()
Write materials definitions closing.
virtual void OpenDocument()
Write XML document opening.
virtual double GetNumWidth() const
Return fixed format number width.
Definition AGDDWriter.h:249
virtual void WriteRotation(const std::string &, const VGM::Transform &)
Write rotation (from VGM transformation)
Definition AGDDWriter.h:108
virtual void SetNumWidth(int width)
Set fixed format number width.
Definition AGDDWriter.h:242
virtual void OpenSection(const std::string &topVolume)
Write the section opening (if present)
virtual void OpenPositions()
Write positions definitions opening.
Definition AGDDWriter.h:71
virtual void WriteIsotope(const VGM::IIsotope *isotope)
Write VGM isotope.
virtual void OpenComposition(const std::string &name, const std::string &)
Write composition definition opening (if present)
virtual void OpenFile(std::string filePath)
Open output file.
virtual void OpenRotations()
Write rotations definitions opening.
Definition AGDDWriter.h:72
The interface for the XML writer that writes VGM geometry objects to XML:
Definition IWriter.h:43
VGM interfaces.
Definition VMedium.h:28
std::vector< double > Transform
Definition Transform.h:40
std::vector< double > ThreeVector
Definition ThreeVector.h:27
XmlVGM utilities.