Geant4 Cross Reference |
1 // 1 // 2 // ******************************************* 2 // ******************************************************************** 3 // * License and Disclaimer 3 // * License and Disclaimer * 4 // * 4 // * * 5 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 6 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 7 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 8 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 9 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 10 // * 10 // * * 11 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 12 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 13 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 14 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 15 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 16 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 17 // * 17 // * * 18 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 19 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 20 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 21 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 22 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 23 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 24 // ******************************************* 24 // ******************************************************************** 25 // 25 // 26 // G4GDMLWriteSolids implementation << 27 // 26 // 28 // Author: Zoltan Torzsok, November 2007 << 27 // $Id: G4GDMLWriteSolids.cc 93151 2015-10-08 11:53:10Z gcosmo $ >> 28 // >> 29 // class G4GDMLWriteSolids Implementation >> 30 // >> 31 // Original author: Zoltan Torzsok, November 2007 >> 32 // 29 // ------------------------------------------- 33 // -------------------------------------------------------------------- 30 34 31 #include "G4GDMLWriteSolids.hh" 35 #include "G4GDMLWriteSolids.hh" 32 36 33 #include "G4SystemOfUnits.hh" 37 #include "G4SystemOfUnits.hh" 34 #include "G4BooleanSolid.hh" 38 #include "G4BooleanSolid.hh" 35 #include "G4ScaledSolid.hh" << 36 #include "G4Box.hh" 39 #include "G4Box.hh" 37 #include "G4Cons.hh" 40 #include "G4Cons.hh" 38 #include "G4Ellipsoid.hh" 41 #include "G4Ellipsoid.hh" 39 #include "G4EllipticalCone.hh" 42 #include "G4EllipticalCone.hh" 40 #include "G4EllipticalTube.hh" 43 #include "G4EllipticalTube.hh" 41 #include "G4ExtrudedSolid.hh" 44 #include "G4ExtrudedSolid.hh" 42 #include "G4Hype.hh" 45 #include "G4Hype.hh" 43 #include "G4Orb.hh" 46 #include "G4Orb.hh" 44 #include "G4Para.hh" 47 #include "G4Para.hh" 45 #include "G4Paraboloid.hh" 48 #include "G4Paraboloid.hh" 46 #include "G4IntersectionSolid.hh" 49 #include "G4IntersectionSolid.hh" 47 #include "G4Polycone.hh" 50 #include "G4Polycone.hh" 48 #include "G4GenericPolycone.hh" 51 #include "G4GenericPolycone.hh" 49 #include "G4Polyhedra.hh" 52 #include "G4Polyhedra.hh" 50 #include "G4ReflectedSolid.hh" 53 #include "G4ReflectedSolid.hh" 51 #include "G4Sphere.hh" 54 #include "G4Sphere.hh" 52 #include "G4SubtractionSolid.hh" 55 #include "G4SubtractionSolid.hh" 53 #include "G4GenericTrap.hh" 56 #include "G4GenericTrap.hh" 54 #include "G4TessellatedSolid.hh" 57 #include "G4TessellatedSolid.hh" 55 #include "G4Tet.hh" 58 #include "G4Tet.hh" 56 #include "G4Torus.hh" 59 #include "G4Torus.hh" 57 #include "G4Trap.hh" 60 #include "G4Trap.hh" 58 #include "G4Trd.hh" 61 #include "G4Trd.hh" 59 #include "G4Tubs.hh" 62 #include "G4Tubs.hh" 60 #include "G4CutTubs.hh" 63 #include "G4CutTubs.hh" 61 #include "G4TwistedBox.hh" 64 #include "G4TwistedBox.hh" 62 #include "G4TwistedTrap.hh" 65 #include "G4TwistedTrap.hh" 63 #include "G4TwistedTrd.hh" 66 #include "G4TwistedTrd.hh" 64 #include "G4TwistedTubs.hh" 67 #include "G4TwistedTubs.hh" 65 #include "G4UnionSolid.hh" 68 #include "G4UnionSolid.hh" 66 #include "G4OpticalSurface.hh" 69 #include "G4OpticalSurface.hh" 67 #include "G4SurfaceProperty.hh" 70 #include "G4SurfaceProperty.hh" 68 #include "G4MaterialPropertiesTable.hh" << 69 71 70 // ------------------------------------------- << 71 G4GDMLWriteSolids::G4GDMLWriteSolids() 72 G4GDMLWriteSolids::G4GDMLWriteSolids() 72 : G4GDMLWriteMaterials() << 73 : G4GDMLWriteMaterials(), solidsElement(0) 73 { 74 { 74 } 75 } 75 76 76 // ------------------------------------------- << 77 G4GDMLWriteSolids::~G4GDMLWriteSolids() 77 G4GDMLWriteSolids::~G4GDMLWriteSolids() 78 { 78 { 79 } 79 } 80 80 81 // ------------------------------------------- << 81 #if !defined(G4GEOM_USE_USOLIDS) 82 void G4GDMLWriteSolids::MultiUnionWrite(xerces << 82 void G4GDMLWriteSolids:: 83 const << 83 MultiUnionWrite(xercesc::DOMElement*, 84 { << 84 const G4MultiUnion* const) 85 G4int numSolids = munionSolid->GetNumberOfSo << 85 { 86 G4String tag("multiUnion"); << 86 G4Exception("G4GDMLWriteSolids::MultiUnionWrite()", 87 << 87 "InvalidSetup", FatalException, 88 G4VSolid* solid; << 88 "Installation with USolids primitives required!"); 89 G4Transform3D transform; << 89 return; 90 << 90 } 91 const G4String& name = GenerateName(munionSo << 91 #else 92 xercesc::DOMElement* multiUnionElement = New << 92 void G4GDMLWriteSolids:: 93 multiUnionElement->setAttributeNode(NewAttri << 93 MultiUnionWrite(xercesc::DOMElement* solElement, 94 << 94 const G4MultiUnion* const munionSolid) 95 for(G4int i = 0; i < numSolids; ++i) << 95 { 96 { << 96 G4int numSolids=munionSolid->GetNumberOfSolids(); 97 solid = munionSolid->GetSolid(i); << 97 G4String tag("multiUnion"); 98 transform = munionSolid->GetTransformation << 98 99 << 99 G4VSolid* solid; 100 HepGeom::Rotate3D rot3d; << 100 G4Transform3D* transform; 101 HepGeom::Translate3D transl; << 101 102 HepGeom::Scale3D scale; << 102 const G4String& name = GenerateName(munionSolid->GetName(),munionSolid); 103 transform.getDecomposition(scale, rot3d, t << 103 xercesc::DOMElement* multiUnionElement = NewElement(tag); 104 << 104 multiUnionElement->setAttributeNode(NewAttribute("name",name)); 105 G4ThreeVector pos = transl.getTranslation( << 105 106 G4RotationMatrix rotm(CLHEP::HepRep3x3(rot << 106 for (G4int i=0; i<numSolids; ++i) 107 rot << 107 { 108 rot << 108 solid = munionSolid->GetSolid(i); 109 G4ThreeVector rot = GetAngles(rotm); << 109 transform = munionSolid->GetTransformation(i); 110 << 110 111 AddSolid(solid); << 111 HepGeom::Rotate3D rot3d; 112 const G4String& solidref = GenerateName(so << 112 HepGeom::Translate3D transl ; 113 std::ostringstream os; << 113 HepGeom::Scale3D scale; 114 os << i + 1; << 114 transform->getDecomposition(scale,rot3d,transl); 115 const G4String& nodeName = "Node- << 115 116 xercesc::DOMElement* solidElement = NewEle << 116 G4ThreeVector pos = transl.getTranslation(); 117 solidElement->setAttributeNode(NewAttribut << 117 G4RotationMatrix 118 xercesc::DOMElement* multiUnionNodeElement << 118 rotm(CLHEP::HepRep3x3(rot3d.xx(), rot3d.xy(), rot3d.xz(), 119 multiUnionNodeElement->setAttributeNode(Ne << 119 rot3d.yx(), rot3d.yy(), rot3d.yz(), 120 multiUnionNodeElement->appendChild(solidEl << 120 rot3d.zx(), rot3d.zy(), rot3d.zz())); 121 if((std::fabs(pos.x()) > kLinearPrecision) << 121 G4ThreeVector rot = GetAngles(rotm); 122 (std::fabs(pos.y()) > kLinearPrecision) << 122 123 (std::fabs(pos.z()) > kLinearPrecision) << 123 AddSolid(solid); 124 { << 124 const G4String& solidref = GenerateName(solid->GetName(),solid); 125 PositionWrite(multiUnionNodeElement,name << 125 std::ostringstream os; os << i+1; 126 } << 126 const G4String& nodeName = "Node-" + G4String(os.str()); 127 if((std::fabs(rot.x()) > kAngularPrecision << 127 xercesc::DOMElement* solidElement = NewElement("solid"); 128 (std::fabs(rot.y()) > kAngularPrecision << 128 solidElement->setAttributeNode(NewAttribute("ref",solidref)); 129 (std::fabs(rot.z()) > kAngularPrecision << 129 xercesc::DOMElement* multiUnionNodeElement = NewElement("multiUnionNode"); 130 { << 130 multiUnionNodeElement->setAttributeNode(NewAttribute("name", nodeName)); 131 RotationWrite(multiUnionNodeElement,name << 131 multiUnionNodeElement->appendChild(solidElement); // Append solid to node 132 } << 132 if ( (std::fabs(pos.x()) > kLinearPrecision) 133 multiUnionElement->appendChild(multiUnionN << 133 || (std::fabs(pos.y()) > kLinearPrecision) 134 } << 134 || (std::fabs(pos.z()) > kLinearPrecision) ) >> 135 { >> 136 PositionWrite(multiUnionNodeElement,name+"_pos",pos); >> 137 } >> 138 if ( (std::fabs(rot.x()) > kAngularPrecision) >> 139 || (std::fabs(rot.y()) > kAngularPrecision) >> 140 || (std::fabs(rot.z()) > kAngularPrecision) ) >> 141 { >> 142 RotationWrite(multiUnionNodeElement,name+"_rot",rot); >> 143 } >> 144 multiUnionElement->appendChild(multiUnionNodeElement); // Append node >> 145 } 135 146 136 solElement->appendChild(multiUnionElement); << 147 solElement->appendChild(multiUnionElement); 137 // Add the multiUnion solid AFTER the consti << 148 // Add the multiUnion solid AFTER the constituent nodes! 138 } 149 } >> 150 #endif 139 151 140 // ------------------------------------------- << 152 void G4GDMLWriteSolids:: 141 void G4GDMLWriteSolids::BooleanWrite(xercesc:: << 153 BooleanWrite(xercesc::DOMElement* solElement, 142 const G4B << 154 const G4BooleanSolid* const boolean) 143 { << 155 { 144 G4int displaced = 0; << 156 G4int displaced=0; >> 157 >> 158 G4String tag("undefined"); >> 159 if (dynamic_cast<const G4IntersectionSolid*>(boolean)) >> 160 { tag = "intersection"; } else >> 161 if (dynamic_cast<const G4SubtractionSolid*>(boolean)) >> 162 { tag = "subtraction"; } else >> 163 if (dynamic_cast<const G4UnionSolid*>(boolean)) >> 164 { tag = "union"; } >> 165 >> 166 G4VSolid* firstPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(0)); >> 167 G4VSolid* secondPtr = const_cast<G4VSolid*>(boolean->GetConstituentSolid(1)); >> 168 >> 169 G4ThreeVector firstpos,firstrot,pos,rot; >> 170 >> 171 // Solve possible displacement of referenced solids! >> 172 // >> 173 while (true) >> 174 { >> 175 if ( displaced>8 ) >> 176 { >> 177 G4String ErrorMessage = "The referenced solid '" >> 178 + firstPtr->GetName() + >> 179 + "in the Boolean shape '" + >> 180 + boolean->GetName() + >> 181 + "' was displaced too many times!"; >> 182 G4Exception("G4GDMLWriteSolids::BooleanWrite()", >> 183 "InvalidSetup", FatalException, ErrorMessage); >> 184 } 145 185 146 G4String tag("undefined"); << 186 if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(firstPtr)) 147 if(dynamic_cast<const G4IntersectionSolid*>( << 187 { 148 { << 188 firstpos += disp->GetObjectTranslation(); 149 tag = "intersection"; << 189 firstrot += GetAngles(disp->GetObjectRotation()); 150 } << 190 firstPtr = disp->GetConstituentMovedSolid(); 151 else if(dynamic_cast<const G4SubtractionSoli << 191 displaced++; 152 { << 192 continue; 153 tag = "subtraction"; << 193 } 154 } << 194 break; 155 else if(dynamic_cast<const G4UnionSolid*>(bo << 195 } 156 { << 196 displaced = 0; 157 tag = "union"; << 197 while (true) 158 } << 198 { >> 199 if ( displaced>maxTransforms ) >> 200 { >> 201 G4String ErrorMessage = "The referenced solid '" >> 202 + secondPtr->GetName() + >> 203 + "in the Boolean shape '" + >> 204 + boolean->GetName() + >> 205 + "' was displaced too many times!"; >> 206 G4Exception("G4GDMLWriteSolids::BooleanWrite()", >> 207 "InvalidSetup", FatalException, ErrorMessage); >> 208 } 159 209 160 G4VSolid* firstPtr = const_cast<G4VSolid*>( << 210 if (G4DisplacedSolid* disp = dynamic_cast<G4DisplacedSolid*>(secondPtr)) 161 G4VSolid* secondPtr = const_cast<G4VSolid*>( << 211 { >> 212 pos += disp->GetObjectTranslation(); >> 213 rot += GetAngles(disp->GetObjectRotation()); >> 214 secondPtr = disp->GetConstituentMovedSolid(); >> 215 displaced++; >> 216 continue; >> 217 } >> 218 break; >> 219 } 162 220 163 G4ThreeVector firstpos, firstrot, pos, rot; << 221 AddSolid(firstPtr); // At first add the constituent solids! >> 222 AddSolid(secondPtr); 164 223 165 // Solve possible displacement of referenced << 224 const G4String& name = GenerateName(boolean->GetName(),boolean); 166 // << 225 const G4String& firstref = GenerateName(firstPtr->GetName(),firstPtr); 167 while(true) << 226 const G4String& secondref = GenerateName(secondPtr->GetName(),secondPtr); 168 { << 227 169 if(displaced > 8) << 228 xercesc::DOMElement* booleanElement = NewElement(tag); 170 { << 229 booleanElement->setAttributeNode(NewAttribute("name",name)); 171 G4String ErrorMessage = "The referenced << 230 xercesc::DOMElement* firstElement = NewElement("first"); 172 +"in the Boolean << 231 firstElement->setAttributeNode(NewAttribute("ref",firstref)); 173 +"' was displace << 232 booleanElement->appendChild(firstElement); 174 G4Exception("G4GDMLWriteSolids::BooleanW << 233 xercesc::DOMElement* secondElement = NewElement("second"); 175 FatalException, ErrorMessage << 234 secondElement->setAttributeNode(NewAttribute("ref",secondref)); 176 } << 235 booleanElement->appendChild(secondElement); >> 236 solElement->appendChild(booleanElement); >> 237 // Add the boolean solid AFTER the constituent solids! >> 238 >> 239 if ( (std::fabs(pos.x()) > kLinearPrecision) >> 240 || (std::fabs(pos.y()) > kLinearPrecision) >> 241 || (std::fabs(pos.z()) > kLinearPrecision) ) >> 242 { >> 243 PositionWrite(booleanElement,name+"_pos",pos); >> 244 } >> 245 >> 246 if ( (std::fabs(rot.x()) > kAngularPrecision) >> 247 || (std::fabs(rot.y()) > kAngularPrecision) >> 248 || (std::fabs(rot.z()) > kAngularPrecision) ) >> 249 { >> 250 RotationWrite(booleanElement,name+"_rot",rot); >> 251 } >> 252 >> 253 if ( (std::fabs(firstpos.x()) > kLinearPrecision) >> 254 || (std::fabs(firstpos.y()) > kLinearPrecision) >> 255 || (std::fabs(firstpos.z()) > kLinearPrecision) ) >> 256 { >> 257 FirstpositionWrite(booleanElement,name+"_fpos",firstpos); >> 258 } >> 259 >> 260 if ( (std::fabs(firstrot.x()) > kAngularPrecision) >> 261 || (std::fabs(firstrot.y()) > kAngularPrecision) >> 262 || (std::fabs(firstrot.z()) > kAngularPrecision) ) >> 263 { >> 264 FirstrotationWrite(booleanElement,name+"_frot",firstrot); >> 265 } >> 266 } >> 267 >> 268 void G4GDMLWriteSolids:: >> 269 BoxWrite(xercesc::DOMElement* solElement, const G4Box* const box) >> 270 { >> 271 const G4String& name = GenerateName(box->GetName(),box); >> 272 >> 273 xercesc::DOMElement* boxElement = NewElement("box"); >> 274 boxElement->setAttributeNode(NewAttribute("name",name)); >> 275 boxElement->setAttributeNode(NewAttribute("x",2.0*box->GetXHalfLength()/mm)); >> 276 boxElement->setAttributeNode(NewAttribute("y",2.0*box->GetYHalfLength()/mm)); >> 277 boxElement->setAttributeNode(NewAttribute("z",2.0*box->GetZHalfLength()/mm)); >> 278 boxElement->setAttributeNode(NewAttribute("lunit","mm")); >> 279 solElement->appendChild(boxElement); >> 280 } >> 281 >> 282 void G4GDMLWriteSolids:: >> 283 ConeWrite(xercesc::DOMElement* solElement, const G4Cons* const cone) >> 284 { >> 285 const G4String& name = GenerateName(cone->GetName(),cone); >> 286 >> 287 xercesc::DOMElement* coneElement = NewElement("cone"); >> 288 coneElement->setAttributeNode(NewAttribute("name",name)); >> 289 coneElement-> >> 290 setAttributeNode(NewAttribute("rmin1",cone->GetInnerRadiusMinusZ()/mm)); >> 291 coneElement-> >> 292 setAttributeNode(NewAttribute("rmax1",cone->GetOuterRadiusMinusZ()/mm)); >> 293 coneElement-> >> 294 setAttributeNode(NewAttribute("rmin2",cone->GetInnerRadiusPlusZ()/mm)); >> 295 coneElement-> >> 296 setAttributeNode(NewAttribute("rmax2",cone->GetOuterRadiusPlusZ()/mm)); >> 297 coneElement-> >> 298 setAttributeNode(NewAttribute("z",2.0*cone->GetZHalfLength()/mm)); >> 299 coneElement-> >> 300 setAttributeNode(NewAttribute("startphi",cone->GetStartPhiAngle()/degree)); >> 301 coneElement-> >> 302 setAttributeNode(NewAttribute("deltaphi",cone->GetDeltaPhiAngle()/degree)); >> 303 coneElement->setAttributeNode(NewAttribute("aunit","deg")); >> 304 coneElement->setAttributeNode(NewAttribute("lunit","mm")); >> 305 solElement->appendChild(coneElement); >> 306 } >> 307 >> 308 void G4GDMLWriteSolids:: >> 309 ElconeWrite(xercesc::DOMElement* solElement, >> 310 const G4EllipticalCone* const elcone) >> 311 { >> 312 const G4String& name = GenerateName(elcone->GetName(),elcone); >> 313 >> 314 xercesc::DOMElement* elconeElement = NewElement("elcone"); >> 315 elconeElement->setAttributeNode(NewAttribute("name",name)); >> 316 elconeElement->setAttributeNode(NewAttribute("dx",elcone->GetSemiAxisX()/mm)); >> 317 elconeElement->setAttributeNode(NewAttribute("dy",elcone->GetSemiAxisY()/mm)); >> 318 elconeElement->setAttributeNode(NewAttribute("zmax",elcone->GetZMax()/mm)); >> 319 elconeElement->setAttributeNode(NewAttribute("zcut",elcone->GetZTopCut()/mm)); >> 320 elconeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 321 solElement->appendChild(elconeElement); >> 322 } >> 323 >> 324 void G4GDMLWriteSolids:: >> 325 EllipsoidWrite(xercesc::DOMElement* solElement, >> 326 const G4Ellipsoid* const ellipsoid) >> 327 { >> 328 const G4String& name = GenerateName(ellipsoid->GetName(),ellipsoid); >> 329 >> 330 xercesc::DOMElement* ellipsoidElement = NewElement("ellipsoid"); >> 331 ellipsoidElement->setAttributeNode(NewAttribute("name",name)); >> 332 ellipsoidElement-> >> 333 setAttributeNode(NewAttribute("ax",ellipsoid->GetSemiAxisMax(0)/mm)); >> 334 ellipsoidElement-> >> 335 setAttributeNode(NewAttribute("by",ellipsoid->GetSemiAxisMax(1)/mm)); >> 336 ellipsoidElement-> >> 337 setAttributeNode(NewAttribute("cz",ellipsoid->GetSemiAxisMax(2)/mm)); >> 338 ellipsoidElement-> >> 339 setAttributeNode(NewAttribute("zcut1",ellipsoid->GetZBottomCut()/mm)); >> 340 ellipsoidElement-> >> 341 setAttributeNode(NewAttribute("zcut2",ellipsoid->GetZTopCut()/mm)); >> 342 ellipsoidElement-> >> 343 setAttributeNode(NewAttribute("lunit","mm")); >> 344 solElement->appendChild(ellipsoidElement); >> 345 } >> 346 >> 347 void G4GDMLWriteSolids:: >> 348 EltubeWrite(xercesc::DOMElement* solElement, >> 349 const G4EllipticalTube* const eltube) >> 350 { >> 351 const G4String& name = GenerateName(eltube->GetName(),eltube); >> 352 >> 353 xercesc::DOMElement* eltubeElement = NewElement("eltube"); >> 354 eltubeElement->setAttributeNode(NewAttribute("name",name)); >> 355 eltubeElement->setAttributeNode(NewAttribute("dx",eltube->GetDx()/mm)); >> 356 eltubeElement->setAttributeNode(NewAttribute("dy",eltube->GetDy()/mm)); >> 357 eltubeElement->setAttributeNode(NewAttribute("dz",eltube->GetDz()/mm)); >> 358 eltubeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 359 solElement->appendChild(eltubeElement); >> 360 } >> 361 >> 362 void G4GDMLWriteSolids:: >> 363 XtruWrite(xercesc::DOMElement* solElement, >> 364 const G4ExtrudedSolid* const xtru) >> 365 { >> 366 const G4String& name = GenerateName(xtru->GetName(),xtru); >> 367 >> 368 xercesc::DOMElement* xtruElement = NewElement("xtru"); >> 369 xtruElement->setAttributeNode(NewAttribute("name",name)); >> 370 xtruElement->setAttributeNode(NewAttribute("lunit","mm")); >> 371 solElement->appendChild(xtruElement); >> 372 >> 373 const G4int NumVertex = xtru->GetNofVertices(); >> 374 >> 375 for (G4int i=0;i<NumVertex;i++) >> 376 { >> 377 xercesc::DOMElement* twoDimVertexElement = NewElement("twoDimVertex"); >> 378 xtruElement->appendChild(twoDimVertexElement); >> 379 >> 380 const G4TwoVector& vertex = xtru->GetVertex(i); >> 381 >> 382 twoDimVertexElement->setAttributeNode(NewAttribute("x",vertex.x()/mm)); >> 383 twoDimVertexElement->setAttributeNode(NewAttribute("y",vertex.y()/mm)); >> 384 } >> 385 >> 386 const G4int NumSection = xtru->GetNofZSections(); >> 387 >> 388 for (G4int i=0;i<NumSection;i++) >> 389 { >> 390 xercesc::DOMElement* sectionElement = NewElement("section"); >> 391 xtruElement->appendChild(sectionElement); >> 392 >> 393 const G4ExtrudedSolid::ZSection section = xtru->GetZSection(i); >> 394 >> 395 sectionElement->setAttributeNode(NewAttribute("zOrder",i)); >> 396 sectionElement->setAttributeNode(NewAttribute("zPosition",section.fZ/mm)); >> 397 sectionElement-> >> 398 setAttributeNode(NewAttribute("xOffset",section.fOffset.x()/mm)); >> 399 sectionElement-> >> 400 setAttributeNode(NewAttribute("yOffset",section.fOffset.y()/mm)); >> 401 sectionElement-> >> 402 setAttributeNode(NewAttribute("scalingFactor",section.fScale)); >> 403 } >> 404 } >> 405 >> 406 void G4GDMLWriteSolids:: >> 407 HypeWrite(xercesc::DOMElement* solElement, const G4Hype* const hype) >> 408 { >> 409 const G4String& name = GenerateName(hype->GetName(),hype); >> 410 >> 411 xercesc::DOMElement* hypeElement = NewElement("hype"); >> 412 hypeElement->setAttributeNode(NewAttribute("name",name)); >> 413 hypeElement->setAttributeNode(NewAttribute("rmin", >> 414 hype->GetInnerRadius()/mm)); >> 415 hypeElement->setAttributeNode(NewAttribute("rmax", >> 416 hype->GetOuterRadius()/mm)); >> 417 hypeElement->setAttributeNode(NewAttribute("inst", >> 418 hype->GetInnerStereo()/degree)); >> 419 hypeElement->setAttributeNode(NewAttribute("outst", >> 420 hype->GetOuterStereo()/degree)); >> 421 hypeElement->setAttributeNode(NewAttribute("z", >> 422 2.0*hype->GetZHalfLength()/mm)); >> 423 hypeElement->setAttributeNode(NewAttribute("aunit","deg")); >> 424 hypeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 425 solElement->appendChild(hypeElement); >> 426 } >> 427 >> 428 void G4GDMLWriteSolids:: >> 429 OrbWrite(xercesc::DOMElement* solElement, const G4Orb* const orb) >> 430 { >> 431 const G4String& name = GenerateName(orb->GetName(),orb); >> 432 >> 433 xercesc::DOMElement* orbElement = NewElement("orb"); >> 434 orbElement->setAttributeNode(NewAttribute("name",name)); >> 435 orbElement->setAttributeNode(NewAttribute("r",orb->GetRadius()/mm)); >> 436 orbElement->setAttributeNode(NewAttribute("lunit","mm")); >> 437 solElement->appendChild(orbElement); >> 438 } >> 439 >> 440 void G4GDMLWriteSolids:: >> 441 ParaWrite(xercesc::DOMElement* solElement, const G4Para* const para) >> 442 { >> 443 const G4String& name = GenerateName(para->GetName(),para); >> 444 >> 445 const G4ThreeVector simaxis = para->GetSymAxis(); >> 446 const G4double alpha = std::atan(para->GetTanAlpha()); >> 447 const G4double phi = simaxis.phi(); >> 448 const G4double theta = simaxis.theta(); >> 449 >> 450 xercesc::DOMElement* paraElement = NewElement("para"); >> 451 paraElement->setAttributeNode(NewAttribute("name",name)); >> 452 paraElement->setAttributeNode(NewAttribute("x", >> 453 2.0*para->GetXHalfLength()/mm)); >> 454 paraElement->setAttributeNode(NewAttribute("y", >> 455 2.0*para->GetYHalfLength()/mm)); >> 456 paraElement->setAttributeNode(NewAttribute("z", >> 457 2.0*para->GetZHalfLength()/mm)); >> 458 paraElement->setAttributeNode(NewAttribute("alpha",alpha/degree)); >> 459 paraElement->setAttributeNode(NewAttribute("theta",theta/degree)); >> 460 paraElement->setAttributeNode(NewAttribute("phi",phi/degree)); >> 461 paraElement->setAttributeNode(NewAttribute("aunit","deg")); >> 462 paraElement->setAttributeNode(NewAttribute("lunit","mm")); >> 463 solElement->appendChild(paraElement); >> 464 } >> 465 >> 466 void G4GDMLWriteSolids:: >> 467 ParaboloidWrite(xercesc::DOMElement* solElement, >> 468 const G4Paraboloid* const paraboloid) >> 469 { >> 470 const G4String& name = GenerateName(paraboloid->GetName(),paraboloid); >> 471 >> 472 xercesc::DOMElement* paraboloidElement = NewElement("paraboloid"); >> 473 paraboloidElement->setAttributeNode(NewAttribute("name",name)); >> 474 paraboloidElement->setAttributeNode(NewAttribute("rlo", >> 475 paraboloid->GetRadiusMinusZ()/mm)); >> 476 paraboloidElement->setAttributeNode(NewAttribute("rhi", >> 477 paraboloid->GetRadiusPlusZ()/mm)); >> 478 paraboloidElement->setAttributeNode(NewAttribute("dz", >> 479 paraboloid->GetZHalfLength()/mm)); >> 480 paraboloidElement->setAttributeNode(NewAttribute("lunit","mm")); >> 481 solElement->appendChild(paraboloidElement); >> 482 } >> 483 void G4GDMLWriteSolids:: >> 484 PolyconeWrite(xercesc::DOMElement* solElement, >> 485 const G4Polycone* const polycone) >> 486 { >> 487 const G4String& name = GenerateName(polycone->GetName(),polycone); >> 488 >> 489 xercesc::DOMElement* polyconeElement = NewElement("polycone"); >> 490 polyconeElement->setAttributeNode(NewAttribute("name",name)); >> 491 polyconeElement->setAttributeNode(NewAttribute("startphi", >> 492 polycone->GetOriginalParameters()->Start_angle/degree)); >> 493 polyconeElement->setAttributeNode(NewAttribute("deltaphi", >> 494 polycone->GetOriginalParameters()->Opening_angle/degree)); >> 495 polyconeElement->setAttributeNode(NewAttribute("aunit","deg")); >> 496 polyconeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 497 solElement->appendChild(polyconeElement); >> 498 >> 499 const size_t num_zplanes = polycone->GetOriginalParameters()->Num_z_planes; >> 500 const G4double* z_array = polycone->GetOriginalParameters()->Z_values; >> 501 const G4double* rmin_array = polycone->GetOriginalParameters()->Rmin; >> 502 const G4double* rmax_array = polycone->GetOriginalParameters()->Rmax; 177 503 178 if(G4DisplacedSolid* disp = dynamic_cast<G << 504 for (size_t i=0; i<num_zplanes; i++) 179 { 505 { 180 firstpos += disp->GetObjectTranslation() << 506 ZplaneWrite(polyconeElement,z_array[i],rmin_array[i],rmax_array[i]); 181 firstrot += GetAngles(disp->GetObjectRot << 182 firstPtr = disp->GetConstituentMovedSoli << 183 ++displaced; << 184 continue; << 185 } 507 } 186 break; << 508 187 } << 509 188 displaced = 0; << 189 while(true) << 190 { << 191 if(displaced > maxTransforms) << 192 { << 193 G4String ErrorMessage = "The referenced << 194 +"in the Boolean << 195 +"' was displace << 196 G4Exception("G4GDMLWriteSolids::BooleanW << 197 FatalException, ErrorMessage << 198 } << 199 << 200 if(G4DisplacedSolid* disp = dynamic_cast<G << 201 { << 202 pos += disp->GetObjectTranslation(); << 203 rot += GetAngles(disp->GetObjectRotation << 204 secondPtr = disp->GetConstituentMovedSol << 205 ++displaced; << 206 continue; << 207 } << 208 break; << 209 } << 210 << 211 AddSolid(firstPtr); // At first add the con << 212 AddSolid(secondPtr); << 213 << 214 const G4String& name = GenerateName(boo << 215 const G4String& firstref = GenerateName(fir << 216 const G4String& secondref = GenerateName(sec << 217 << 218 xercesc::DOMElement* booleanElement = NewEle << 219 booleanElement->setAttributeNode(NewAttribut << 220 xercesc::DOMElement* firstElement = NewEleme << 221 firstElement->setAttributeNode(NewAttribute( << 222 booleanElement->appendChild(firstElement); << 223 xercesc::DOMElement* secondElement = NewElem << 224 secondElement->setAttributeNode(NewAttribute << 225 booleanElement->appendChild(secondElement); << 226 solElement->appendChild(booleanElement); << 227 // Add the boolean solid AFTER the constitue << 228 << 229 if((std::fabs(pos.x()) > kLinearPrecision) | << 230 (std::fabs(pos.y()) > kLinearPrecision) | << 231 (std::fabs(pos.z()) > kLinearPrecision)) << 232 { << 233 PositionWrite(booleanElement, name + "_pos << 234 } << 235 << 236 if((std::fabs(rot.x()) > kAngularPrecision) << 237 (std::fabs(rot.y()) > kAngularPrecision) << 238 (std::fabs(rot.z()) > kAngularPrecision)) << 239 { << 240 RotationWrite(booleanElement, name + "_rot << 241 } << 242 << 243 if((std::fabs(firstpos.x()) > kLinearPrecisi << 244 (std::fabs(firstpos.y()) > kLinearPrecisi << 245 (std::fabs(firstpos.z()) > kLinearPrecisi << 246 { << 247 FirstpositionWrite(booleanElement, name + << 248 } << 249 << 250 if((std::fabs(firstrot.x()) > kAngularPrecis << 251 (std::fabs(firstrot.y()) > kAngularPrecis << 252 (std::fabs(firstrot.z()) > kAngularPrecis << 253 { << 254 FirstrotationWrite(booleanElement, name + << 255 } << 256 } << 257 << 258 // ------------------------------------------- << 259 void G4GDMLWriteSolids::ScaledWrite(xercesc::D << 260 const G4Sc << 261 { << 262 G4String tag("scaledSolid"); << 263 << 264 G4VSolid* solid = const_cast<G4VSoli << 265 G4Scale3D scale = scaled->GetScaleTr << 266 G4ThreeVector sclVector = G4ThreeVector(scal << 267 << 268 AddSolid(solid); // Add the constituent sol << 269 << 270 const G4String& name = GenerateName(scal << 271 const G4String& solidref = GenerateName(soli << 272 << 273 xercesc::DOMElement* scaledElement = NewElem << 274 scaledElement->setAttributeNode(NewAttribute << 275 << 276 xercesc::DOMElement* solidElement = NewEleme << 277 solidElement->setAttributeNode(NewAttribute( << 278 scaledElement->appendChild(solidElement); << 279 << 280 if((std::fabs(scale.xx()) > kLinearPrecision << 281 (std::fabs(scale.yy()) > kLinearPrecision << 282 (std::fabs(scale.zz()) > kLinearPrecision << 283 { << 284 ScaleWrite(scaledElement, name + "_scl", s << 285 } << 286 << 287 solElement->appendChild(scaledElement); << 288 // Add the scaled solid AFTER its constituen << 289 } << 290 << 291 // ------------------------------------------- << 292 void G4GDMLWriteSolids::BoxWrite(xercesc::DOME << 293 const G4Box* << 294 { << 295 const G4String& name = GenerateName(box->Get << 296 << 297 xercesc::DOMElement* boxElement = NewElement << 298 boxElement->setAttributeNode(NewAttribute("n << 299 boxElement->setAttributeNode( << 300 NewAttribute("x", 2.0 * box->GetXHalfLengt << 301 boxElement->setAttributeNode( << 302 NewAttribute("y", 2.0 * box->GetYHalfLengt << 303 boxElement->setAttributeNode( << 304 NewAttribute("z", 2.0 * box->GetZHalfLengt << 305 boxElement->setAttributeNode(NewAttribute("l << 306 solElement->appendChild(boxElement); << 307 } 510 } 308 511 309 // ------------------------------------------- << 512 void G4GDMLWriteSolids:: 310 void G4GDMLWriteSolids::ConeWrite(xercesc::DOM << 513 GenericPolyconeWrite(xercesc::DOMElement* solElement, 311 const G4Cons << 514 const G4GenericPolycone* const polycone) 312 { << 515 { 313 const G4String& name = GenerateName(cone->Ge << 516 const G4String& name = GenerateName(polycone->GetName(),polycone); >> 517 xercesc::DOMElement* polyconeElement = NewElement("genericPolycone"); >> 518 const G4double startPhi=polycone->GetStartPhi(); >> 519 polyconeElement->setAttributeNode(NewAttribute("name",name)); >> 520 polyconeElement->setAttributeNode(NewAttribute("startphi", >> 521 startPhi/degree)); >> 522 polyconeElement->setAttributeNode(NewAttribute("deltaphi", >> 523 (polycone->GetEndPhi()-startPhi)/degree)); >> 524 polyconeElement->setAttributeNode(NewAttribute("aunit","deg")); >> 525 polyconeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 526 solElement->appendChild(polyconeElement); 314 527 315 xercesc::DOMElement* coneElement = NewElemen << 528 const size_t num_rzpoints = polycone->GetNumRZCorner(); 316 coneElement->setAttributeNode(NewAttribute(" << 529 for (size_t i=0; i<num_rzpoints; i++) 317 coneElement->setAttributeNode( << 530 { 318 NewAttribute("rmin1", cone->GetInnerRadius << 531 const G4double r_point=polycone->GetCorner(i).r; 319 coneElement->setAttributeNode( << 532 const G4double z_point=polycone->GetCorner(i).z; 320 NewAttribute("rmax1", cone->GetOuterRadius << 533 RZPointWrite(polyconeElement,r_point,z_point); 321 coneElement->setAttributeNode( << 534 } 322 NewAttribute("rmin2", cone->GetInnerRadius << 535 323 coneElement->setAttributeNode( << 324 NewAttribute("rmax2", cone->GetOuterRadius << 325 coneElement->setAttributeNode( << 326 NewAttribute("z", 2.0 * cone->GetZHalfLeng << 327 coneElement->setAttributeNode( << 328 NewAttribute("startphi", cone->GetStartPhi << 329 coneElement->setAttributeNode( << 330 NewAttribute("deltaphi", cone->GetDeltaPhi << 331 coneElement->setAttributeNode(NewAttribute(" << 332 coneElement->setAttributeNode(NewAttribute(" << 333 solElement->appendChild(coneElement); << 334 } << 335 << 336 // ------------------------------------------- << 337 void G4GDMLWriteSolids::ElconeWrite(xercesc::D << 338 const G4El << 339 { << 340 const G4String& name = GenerateName(elcone-> << 341 << 342 xercesc::DOMElement* elconeElement = NewElem << 343 elconeElement->setAttributeNode(NewAttribute << 344 elconeElement->setAttributeNode( << 345 NewAttribute("dx", elcone->GetSemiAxisX() << 346 elconeElement->setAttributeNode( << 347 NewAttribute("dy", elcone->GetSemiAxisY() << 348 elconeElement->setAttributeNode(NewAttribute << 349 elconeElement->setAttributeNode( << 350 NewAttribute("zcut", elcone->GetZTopCut() << 351 elconeElement->setAttributeNode(NewAttribute << 352 solElement->appendChild(elconeElement); << 353 } << 354 << 355 // ------------------------------------------- << 356 void G4GDMLWriteSolids::EllipsoidWrite(xercesc << 357 const G << 358 { << 359 const G4String& name = GenerateName(ellipsoi << 360 << 361 xercesc::DOMElement* ellipsoidElement = NewE << 362 ellipsoidElement->setAttributeNode(NewAttrib << 363 ellipsoidElement->setAttributeNode( << 364 NewAttribute("ax", ellipsoid->GetSemiAxisM << 365 ellipsoidElement->setAttributeNode( << 366 NewAttribute("by", ellipsoid->GetSemiAxisM << 367 ellipsoidElement->setAttributeNode( << 368 NewAttribute("cz", ellipsoid->GetSemiAxisM << 369 ellipsoidElement->setAttributeNode( << 370 NewAttribute("zcut1", ellipsoid->GetZBotto << 371 ellipsoidElement->setAttributeNode( << 372 NewAttribute("zcut2", ellipsoid->GetZTopCu << 373 ellipsoidElement->setAttributeNode(NewAttrib << 374 solElement->appendChild(ellipsoidElement); << 375 } << 376 << 377 // ------------------------------------------- << 378 void G4GDMLWriteSolids::EltubeWrite(xercesc::D << 379 const G4El << 380 { << 381 const G4String& name = GenerateName(eltube-> << 382 << 383 xercesc::DOMElement* eltubeElement = NewElem << 384 eltubeElement->setAttributeNode(NewAttribute << 385 eltubeElement->setAttributeNode(NewAttribute << 386 eltubeElement->setAttributeNode(NewAttribute << 387 eltubeElement->setAttributeNode(NewAttribute << 388 eltubeElement->setAttributeNode(NewAttribute << 389 solElement->appendChild(eltubeElement); << 390 } << 391 << 392 // ------------------------------------------- << 393 void G4GDMLWriteSolids::XtruWrite(xercesc::DOM << 394 const G4Extr << 395 { << 396 const G4String& name = GenerateName(xtru->Ge << 397 << 398 xercesc::DOMElement* xtruElement = NewElemen << 399 xtruElement->setAttributeNode(NewAttribute(" << 400 xtruElement->setAttributeNode(NewAttribute(" << 401 solElement->appendChild(xtruElement); << 402 << 403 const G4int NumVertex = xtru->GetNofVertices << 404 << 405 for(G4int i = 0; i < NumVertex; ++i) << 406 { << 407 xercesc::DOMElement* twoDimVertexElement = << 408 xtruElement->appendChild(twoDimVertexEleme << 409 << 410 const G4TwoVector& vertex = xtru->GetVerte << 411 << 412 twoDimVertexElement->setAttributeNode(NewA << 413 twoDimVertexElement->setAttributeNode(NewA << 414 } << 415 << 416 const G4int NumSection = xtru->GetNofZSectio << 417 << 418 for(G4int i = 0; i < NumSection; ++i) << 419 { << 420 xercesc::DOMElement* sectionElement = NewE << 421 xtruElement->appendChild(sectionElement); << 422 << 423 const G4ExtrudedSolid::ZSection section = << 424 << 425 sectionElement->setAttributeNode(NewAttrib << 426 sectionElement->setAttributeNode( << 427 NewAttribute("zPosition", section.fZ / m << 428 sectionElement->setAttributeNode( << 429 NewAttribute("xOffset", section.fOffset. << 430 sectionElement->setAttributeNode( << 431 NewAttribute("yOffset", section.fOffset. << 432 sectionElement->setAttributeNode( << 433 NewAttribute("scalingFactor", section.fS << 434 } << 435 } << 436 << 437 // ------------------------------------------- << 438 void G4GDMLWriteSolids::HypeWrite(xercesc::DOM << 439 const G4Hype << 440 { << 441 const G4String& name = GenerateName(hype->Ge << 442 << 443 xercesc::DOMElement* hypeElement = NewElemen << 444 hypeElement->setAttributeNode(NewAttribute(" << 445 hypeElement->setAttributeNode( << 446 NewAttribute("rmin", hype->GetInnerRadius( << 447 hypeElement->setAttributeNode( << 448 NewAttribute("rmax", hype->GetOuterRadius( << 449 hypeElement->setAttributeNode( << 450 NewAttribute("inst", hype->GetInnerStereo( << 451 hypeElement->setAttributeNode( << 452 NewAttribute("outst", hype->GetOuterStereo << 453 hypeElement->setAttributeNode( << 454 NewAttribute("z", 2.0 * hype->GetZHalfLeng << 455 hypeElement->setAttributeNode(NewAttribute(" << 456 hypeElement->setAttributeNode(NewAttribute(" << 457 solElement->appendChild(hypeElement); << 458 } << 459 << 460 // ------------------------------------------- << 461 void G4GDMLWriteSolids::OrbWrite(xercesc::DOME << 462 const G4Orb* << 463 { << 464 const G4String& name = GenerateName(orb->Get << 465 << 466 xercesc::DOMElement* orbElement = NewElement << 467 orbElement->setAttributeNode(NewAttribute("n << 468 orbElement->setAttributeNode(NewAttribute("r << 469 orbElement->setAttributeNode(NewAttribute("l << 470 solElement->appendChild(orbElement); << 471 } << 472 << 473 // ------------------------------------------- << 474 void G4GDMLWriteSolids::ParaWrite(xercesc::DOM << 475 const G4Para << 476 { << 477 const G4String& name = GenerateName(para->Ge << 478 << 479 const G4ThreeVector simaxis = para->GetSymAx << 480 const G4double alpha = std::atan(para << 481 const G4double phi = simaxis.phi(); << 482 const G4double theta = simaxis.theta( << 483 << 484 xercesc::DOMElement* paraElement = NewElemen << 485 paraElement->setAttributeNode(NewAttribute(" << 486 paraElement->setAttributeNode( << 487 NewAttribute("x", 2.0 * para->GetXHalfLeng << 488 paraElement->setAttributeNode( << 489 NewAttribute("y", 2.0 * para->GetYHalfLeng << 490 paraElement->setAttributeNode( << 491 NewAttribute("z", 2.0 * para->GetZHalfLeng << 492 paraElement->setAttributeNode(NewAttribute(" << 493 paraElement->setAttributeNode(NewAttribute(" << 494 paraElement->setAttributeNode(NewAttribute(" << 495 paraElement->setAttributeNode(NewAttribute(" << 496 paraElement->setAttributeNode(NewAttribute(" << 497 solElement->appendChild(paraElement); << 498 } << 499 << 500 // ------------------------------------------- << 501 void G4GDMLWriteSolids::ParaboloidWrite(xerces << 502 const << 503 { << 504 const G4String& name = GenerateName(parabolo << 505 << 506 xercesc::DOMElement* paraboloidElement = New << 507 paraboloidElement->setAttributeNode(NewAttri << 508 paraboloidElement->setAttributeNode( << 509 NewAttribute("rlo", paraboloid->GetRadiusM << 510 paraboloidElement->setAttributeNode( << 511 NewAttribute("rhi", paraboloid->GetRadiusP << 512 paraboloidElement->setAttributeNode( << 513 NewAttribute("dz", paraboloid->GetZHalfLen << 514 paraboloidElement->setAttributeNode(NewAttri << 515 solElement->appendChild(paraboloidElement); << 516 } << 517 << 518 // ------------------------------------------- << 519 void G4GDMLWriteSolids::PolyconeWrite(xercesc: << 520 const G4 << 521 { << 522 const G4String& name = GenerateName(polycone << 523 << 524 xercesc::DOMElement* polyconeElement = NewEl << 525 polyconeElement->setAttributeNode(NewAttribu << 526 polyconeElement->setAttributeNode(NewAttribu << 527 "startphi", polycone->GetOriginalParameter << 528 polyconeElement->setAttributeNode(NewAttribu << 529 "deltaphi", polycone->GetOriginalParameter << 530 polyconeElement->setAttributeNode(NewAttribu << 531 polyconeElement->setAttributeNode(NewAttribu << 532 solElement->appendChild(polyconeElement); << 533 << 534 const std::size_t num_zplanes << 535 = polycone->GetOriginalParameters()->N << 536 const G4double* z_array = polycone->GetOr << 537 const G4double* rmin_array = polycone->GetOr << 538 const G4double* rmax_array = polycone->GetOr << 539 << 540 for(std::size_t i = 0; i < num_zplanes; ++i) << 541 { << 542 ZplaneWrite(polyconeElement, z_array[i], r << 543 } << 544 } << 545 << 546 // ------------------------------------------- << 547 void G4GDMLWriteSolids::GenericPolyconeWrite( << 548 xercesc::DOMElement* solElement, const G4Gen << 549 { << 550 const G4String& name = GenerateName(polycone << 551 xercesc::DOMElement* polyconeElement = NewEl << 552 const G4double startPhi = polyc << 553 polyconeElement->setAttributeNode(NewAttribu << 554 polyconeElement->setAttributeNode( << 555 NewAttribute("startphi", startPhi / degree << 556 polyconeElement->setAttributeNode( << 557 NewAttribute("deltaphi", (polycone->GetEnd << 558 polyconeElement->setAttributeNode(NewAttribu << 559 polyconeElement->setAttributeNode(NewAttribu << 560 solElement->appendChild(polyconeElement); << 561 << 562 const G4int num_rzpoints = (G4int)polycone-> << 563 for(G4int i = 0; i < num_rzpoints; ++i) << 564 { << 565 const G4double r_point = polycone->GetCorn << 566 const G4double z_point = polycone->GetCorn << 567 RZPointWrite(polyconeElement, r_point, z_p << 568 } << 569 } 536 } 570 537 571 // ------------------------------------------- << 538 void G4GDMLWriteSolids:: 572 void G4GDMLWriteSolids::PolyhedraWrite(xercesc << 539 PolyhedraWrite(xercesc::DOMElement* solElement, 573 const G << 540 const G4Polyhedra* const polyhedra) 574 { 541 { 575 const G4String& name = GenerateName(polyhedr << 542 const G4String& name = GenerateName(polyhedra->GetName(),polyhedra); 576 if(polyhedra->IsGeneric() == false) << 543 if(polyhedra->IsGeneric() == false){ 577 { << 578 xercesc::DOMElement* polyhedraElement = Ne 544 xercesc::DOMElement* polyhedraElement = NewElement("polyhedra"); 579 polyhedraElement->setAttributeNode(NewAttr << 545 polyhedraElement->setAttributeNode(NewAttribute("name",name)); 580 polyhedraElement->setAttributeNode(NewAttr << 546 polyhedraElement->setAttributeNode(NewAttribute("startphi", 581 "startphi", polyhedra->GetOriginalParame << 547 polyhedra->GetOriginalParameters()->Start_angle/degree)); 582 polyhedraElement->setAttributeNode(NewAttr << 548 polyhedraElement->setAttributeNode(NewAttribute("deltaphi", 583 "deltaphi", polyhedra->GetOriginalParame << 549 polyhedra->GetOriginalParameters()->Opening_angle/degree)); 584 polyhedraElement->setAttributeNode( << 550 polyhedraElement->setAttributeNode(NewAttribute("numsides", 585 NewAttribute("numsides", polyhedra->GetO << 551 polyhedra->GetOriginalParameters()->numSide)); 586 polyhedraElement->setAttributeNode(NewAttr << 552 polyhedraElement->setAttributeNode(NewAttribute("aunit","deg")); 587 polyhedraElement->setAttributeNode(NewAttr << 553 polyhedraElement->setAttributeNode(NewAttribute("lunit","mm")); 588 solElement->appendChild(polyhedraElement); 554 solElement->appendChild(polyhedraElement); 589 555 590 const std::size_t num_zplanes << 556 const size_t num_zplanes = polyhedra->GetOriginalParameters()->Num_z_planes; 591 = polyhedra->GetOriginalParameters() << 557 const G4double* z_array = polyhedra->GetOriginalParameters()->Z_values; 592 const G4double* z_array = polyhedra->GetO << 593 const G4double* rmin_array = polyhedra->Ge 558 const G4double* rmin_array = polyhedra->GetOriginalParameters()->Rmin; 594 const G4double* rmax_array = polyhedra->Ge 559 const G4double* rmax_array = polyhedra->GetOriginalParameters()->Rmax; 595 560 596 const G4double convertRad = 561 const G4double convertRad = 597 std::cos(0.5 * polyhedra->GetOriginalPar << 562 std::cos(0.5*polyhedra->GetOriginalParameters()->Opening_angle 598 polyhedra->GetOriginalParameter << 563 / polyhedra->GetOriginalParameters()->numSide); 599 564 600 for(std::size_t i = 0; i < num_zplanes; ++ << 565 for (size_t i=0;i<num_zplanes;i++) 601 { 566 { 602 ZplaneWrite(polyhedraElement, z_array[i] << 567 ZplaneWrite(polyhedraElement,z_array[i], 603 rmax_array[i] * convertRad); << 568 rmin_array[i]*convertRad, rmax_array[i]*convertRad); 604 } 569 } 605 } << 570 }else{//generic polyhedra 606 else // generic polyhedra << 571 607 { << 608 xercesc::DOMElement* polyhedraElement = Ne 572 xercesc::DOMElement* polyhedraElement = NewElement("genericPolyhedra"); 609 polyhedraElement->setAttributeNode(NewAttr << 573 polyhedraElement->setAttributeNode(NewAttribute("name",name)); 610 polyhedraElement->setAttributeNode(NewAttr << 574 polyhedraElement->setAttributeNode(NewAttribute("startphi", 611 "startphi", polyhedra->GetOriginalParame << 575 polyhedra->GetOriginalParameters()->Start_angle/degree)); 612 polyhedraElement->setAttributeNode(NewAttr << 576 polyhedraElement->setAttributeNode(NewAttribute("deltaphi", 613 "deltaphi", polyhedra->GetOriginalParame << 577 polyhedra->GetOriginalParameters()->Opening_angle/degree)); 614 polyhedraElement->setAttributeNode( << 578 polyhedraElement->setAttributeNode(NewAttribute("numsides", 615 NewAttribute("numsides", polyhedra->GetO << 579 polyhedra->GetOriginalParameters()->numSide)); 616 polyhedraElement->setAttributeNode(NewAttr << 580 polyhedraElement->setAttributeNode(NewAttribute("aunit","deg")); 617 polyhedraElement->setAttributeNode(NewAttr << 581 polyhedraElement->setAttributeNode(NewAttribute("lunit","mm")); 618 solElement->appendChild(polyhedraElement); 582 solElement->appendChild(polyhedraElement); 619 583 620 const G4int num_rzpoints = (G4int)polyhedr << 584 const size_t num_rzpoints = polyhedra->GetNumRZCorner(); 621 << 585 622 for(G4int i = 0; i < num_rzpoints; ++i) << 586 for (size_t i=0;i<num_rzpoints;i++) 623 { 587 { 624 const G4double r_point = polyhedra->GetC 588 const G4double r_point = polyhedra->GetCorner(i).r; 625 const G4double z_point = polyhedra->GetC 589 const G4double z_point = polyhedra->GetCorner(i).z; 626 RZPointWrite(polyhedraElement, r_point, << 590 RZPointWrite(polyhedraElement,r_point,z_point); 627 } 591 } 628 } 592 } 629 } 593 } 630 594 631 // ------------------------------------------- << 595 void G4GDMLWriteSolids:: 632 void G4GDMLWriteSolids::SphereWrite(xercesc::D << 596 SphereWrite(xercesc::DOMElement* solElement, const G4Sphere* const sphere) 633 const G4Sp << 634 { 597 { 635 const G4String& name = GenerateName(sphere-> << 598 const G4String& name = GenerateName(sphere->GetName(),sphere); 636 << 637 xercesc::DOMElement* sphereElement = NewElem << 638 sphereElement->setAttributeNode(NewAttribute << 639 sphereElement->setAttributeNode( << 640 NewAttribute("rmin", sphere->GetInnerRadiu << 641 sphereElement->setAttributeNode( << 642 NewAttribute("rmax", sphere->GetOuterRadiu << 643 sphereElement->setAttributeNode( << 644 NewAttribute("startphi", sphere->GetStartP << 645 sphereElement->setAttributeNode( << 646 NewAttribute("deltaphi", sphere->GetDeltaP << 647 sphereElement->setAttributeNode( << 648 NewAttribute("starttheta", sphere->GetStar << 649 sphereElement->setAttributeNode( << 650 NewAttribute("deltatheta", sphere->GetDelt << 651 sphereElement->setAttributeNode(NewAttribute << 652 sphereElement->setAttributeNode(NewAttribute << 653 solElement->appendChild(sphereElement); << 654 } << 655 599 656 // ------------------------------------------- << 600 xercesc::DOMElement* sphereElement = NewElement("sphere"); 657 void G4GDMLWriteSolids::TessellatedWrite( << 601 sphereElement->setAttributeNode(NewAttribute("name",name)); 658 xercesc::DOMElement* solElement, const G4Tes << 602 sphereElement->setAttributeNode(NewAttribute("rmin", 659 { << 603 sphere->GetInnerRadius()/mm)); 660 const G4String& solid_name = tessellated->Ge << 604 sphereElement->setAttributeNode(NewAttribute("rmax", 661 const G4String& name = GenerateName(so << 605 sphere->GetOuterRadius()/mm)); 662 << 606 sphereElement->setAttributeNode(NewAttribute("startphi", 663 xercesc::DOMElement* tessellatedElement = Ne << 607 sphere->GetStartPhiAngle()/degree)); 664 tessellatedElement->setAttributeNode(NewAttr << 608 sphereElement->setAttributeNode(NewAttribute("deltaphi", 665 tessellatedElement->setAttributeNode(NewAttr << 609 sphere->GetDeltaPhiAngle()/degree)); 666 tessellatedElement->setAttributeNode(NewAttr << 610 sphereElement->setAttributeNode(NewAttribute("starttheta", 667 solElement->appendChild(tessellatedElement); << 611 sphere->GetStartThetaAngle()/degree)); 668 << 612 sphereElement->setAttributeNode(NewAttribute("deltatheta", 669 std::map<G4ThreeVector, G4String, G4ThreeVec << 613 sphere->GetDeltaThetaAngle()/degree)); 670 << 614 sphereElement->setAttributeNode(NewAttribute("aunit","deg")); 671 const std::size_t NumFacets = tessellated->G << 615 sphereElement->setAttributeNode(NewAttribute("lunit","mm")); 672 std::size_t NumVertex = 0; << 616 solElement->appendChild(sphereElement); 673 << 617 } 674 for(std::size_t i = 0; i < NumFacets; ++i) << 618 675 { << 619 void G4GDMLWriteSolids:: 676 const G4VFacet* facet = tessellat << 620 TessellatedWrite(xercesc::DOMElement* solElement, 677 const size_t NumVertexPerFacet = facet->Ge << 621 const G4TessellatedSolid* const tessellated) 678 << 622 { 679 G4String FacetTag; << 623 const G4String& solid_name = tessellated->GetName(); 680 << 624 const G4String& name = GenerateName(solid_name, tessellated); 681 if(NumVertexPerFacet == 3) << 625 682 { << 626 xercesc::DOMElement* tessellatedElement = NewElement("tessellated"); 683 FacetTag = "triangular"; << 627 tessellatedElement->setAttributeNode(NewAttribute("name",name)); 684 } << 628 tessellatedElement->setAttributeNode(NewAttribute("aunit","deg")); 685 else if(NumVertexPerFacet == 4) << 629 tessellatedElement->setAttributeNode(NewAttribute("lunit","mm")); 686 { << 630 solElement->appendChild(tessellatedElement); 687 FacetTag = "quadrangular"; << 631 688 } << 632 std::map<G4ThreeVector, G4String, G4ThreeVectorCompare> vertexMap; 689 else << 633 690 { << 634 const size_t NumFacets = tessellated->GetNumberOfFacets(); 691 G4Exception("G4GDMLWriteSolids::Tessella << 635 size_t NumVertex = 0; 692 FatalException, "Facet shoul << 636 693 } << 637 for (size_t i=0;i<NumFacets;i++) 694 << 638 { 695 xercesc::DOMElement* facetElement = NewEle << 639 const G4VFacet* facet = tessellated->GetFacet(i); 696 tessellatedElement->appendChild(facetEleme << 640 const size_t NumVertexPerFacet = facet->GetNumberOfVertices(); 697 << 641 698 for(std::size_t j = 0; j < NumVertexPerFac << 642 G4String FacetTag; 699 { << 643 700 std::stringstream name_stream; << 644 if (NumVertexPerFacet==3) { FacetTag="triangular"; } else 701 std::stringstream ref_stream; << 645 if (NumVertexPerFacet==4) { FacetTag="quadrangular"; } 702 << 646 else 703 name_stream << "vertex" << (j + 1); << 704 ref_stream << solid_name << "_v" << NumV << 705 << 706 const G4String& fname = name_stream.str( << 707 G4String ref = ref_stream.str() << 708 << 709 // Now search for the existance of the c << 710 // map of cached vertices. If existing, << 711 // position in the GDML file, so avoidin << 712 // cache it in the local map and add it << 713 // "define" section of the GDML file. << 714 << 715 const G4ThreeVector& vertex = facet->Get << 716 << 717 if(vertexMap.find(vertex) != vertexMap.c << 718 { 647 { 719 ref = vertexMap[vertex]; // Set the p << 648 G4Exception("G4GDMLWriteSolids::TessellatedWrite()", "InvalidSetup", >> 649 FatalException, "Facet should contain 3 or 4 vertices!"); 720 } 650 } 721 else // Vertex not found << 722 { << 723 if ( ! vertexMap.insert(std::make_pair << 724 { << 725 G4ExceptionDescription description; << 726 description << "Failed to insert [ve << 727 << ref << " in map."; << 728 G4Exception("G4GDMLWriteSolids::Tess << 729 JustWarning, descriptio << 730 } << 731 AddPosition(ref, vertex); // ... add << 732 ++NumVertex; << 733 } << 734 << 735 // Now create association of the vertex << 736 // << 737 facetElement->setAttributeNode(NewAttrib << 738 } << 739 } << 740 } << 741 << 742 // ------------------------------------------- << 743 void G4GDMLWriteSolids::TetWrite(xercesc::DOME << 744 const G4Tet* << 745 { << 746 const G4String& solid_name = tet->GetName(); << 747 const G4String& name = GenerateName(so << 748 << 749 std::vector<G4ThreeVector> vertexList = tet- << 750 << 751 xercesc::DOMElement* tetElement = NewElement << 752 tetElement->setAttributeNode(NewAttribute("n << 753 tetElement->setAttributeNode(NewAttribute("v << 754 tetElement->setAttributeNode(NewAttribute("v << 755 tetElement->setAttributeNode(NewAttribute("v << 756 tetElement->setAttributeNode(NewAttribute("v << 757 tetElement->setAttributeNode(NewAttribute("l << 758 solElement->appendChild(tetElement); << 759 << 760 AddPosition(solid_name + "_v1", vertexList[0 << 761 AddPosition(solid_name + "_v2", vertexList[1 << 762 AddPosition(solid_name + "_v3", vertexList[2 << 763 AddPosition(solid_name + "_v4", vertexList[3 << 764 } << 765 << 766 // ------------------------------------------- << 767 void G4GDMLWriteSolids::TorusWrite(xercesc::DO << 768 const G4Tor << 769 { << 770 const G4String& name = GenerateName(torus->G << 771 << 772 xercesc::DOMElement* torusElement = NewEleme << 773 torusElement->setAttributeNode(NewAttribute( << 774 torusElement->setAttributeNode(NewAttribute( << 775 torusElement->setAttributeNode(NewAttribute( << 776 torusElement->setAttributeNode(NewAttribute( << 777 torusElement->setAttributeNode( << 778 NewAttribute("startphi", torus->GetSPhi() << 779 torusElement->setAttributeNode( << 780 NewAttribute("deltaphi", torus->GetDPhi() << 781 torusElement->setAttributeNode(NewAttribute( << 782 torusElement->setAttributeNode(NewAttribute( << 783 solElement->appendChild(torusElement); << 784 } << 785 << 786 // ------------------------------------------- << 787 void G4GDMLWriteSolids::GenTrapWrite(xercesc:: << 788 const G4G << 789 { << 790 const G4String& name = GenerateName(gtrap->G << 791 << 792 std::vector<G4TwoVector> vertices = gtrap->G << 793 << 794 xercesc::DOMElement* gtrapElement = NewEleme << 795 gtrapElement->setAttributeNode(NewAttribute( << 796 gtrapElement->setAttributeNode( << 797 NewAttribute("dz", gtrap->GetZHalfLength() << 798 gtrapElement->setAttributeNode(NewAttribute( << 799 gtrapElement->setAttributeNode(NewAttribute( << 800 gtrapElement->setAttributeNode(NewAttribute( << 801 gtrapElement->setAttributeNode(NewAttribute( << 802 gtrapElement->setAttributeNode(NewAttribute( << 803 gtrapElement->setAttributeNode(NewAttribute( << 804 gtrapElement->setAttributeNode(NewAttribute( << 805 gtrapElement->setAttributeNode(NewAttribute( << 806 gtrapElement->setAttributeNode(NewAttribute( << 807 gtrapElement->setAttributeNode(NewAttribute( << 808 gtrapElement->setAttributeNode(NewAttribute( << 809 gtrapElement->setAttributeNode(NewAttribute( << 810 gtrapElement->setAttributeNode(NewAttribute( << 811 gtrapElement->setAttributeNode(NewAttribute( << 812 gtrapElement->setAttributeNode(NewAttribute( << 813 gtrapElement->setAttributeNode(NewAttribute( << 814 gtrapElement->setAttributeNode(NewAttribute( << 815 solElement->appendChild(gtrapElement); << 816 } << 817 << 818 // ------------------------------------------- << 819 void G4GDMLWriteSolids::TrapWrite(xercesc::DOM << 820 const G4Trap << 821 { << 822 const G4String& name = GenerateName(trap->Ge << 823 << 824 const G4ThreeVector& simaxis = trap->GetSymA << 825 const G4double phi = simaxis.phi() << 826 const G4double theta = simaxis.theta << 827 const G4double alpha1 = std::atan(tra << 828 const G4double alpha2 = std::atan(tra << 829 << 830 xercesc::DOMElement* trapElement = NewElemen << 831 trapElement->setAttributeNode(NewAttribute(" << 832 trapElement->setAttributeNode( << 833 NewAttribute("z", 2.0 * trap->GetZHalfLeng << 834 trapElement->setAttributeNode(NewAttribute(" << 835 trapElement->setAttributeNode(NewAttribute(" << 836 trapElement->setAttributeNode( << 837 NewAttribute("y1", 2.0 * trap->GetYHalfLen << 838 trapElement->setAttributeNode( << 839 NewAttribute("x1", 2.0 * trap->GetXHalfLen << 840 trapElement->setAttributeNode( << 841 NewAttribute("x2", 2.0 * trap->GetXHalfLen << 842 trapElement->setAttributeNode(NewAttribute(" << 843 trapElement->setAttributeNode( << 844 NewAttribute("y2", 2.0 * trap->GetYHalfLen << 845 trapElement->setAttributeNode( << 846 NewAttribute("x3", 2.0 * trap->GetXHalfLen << 847 trapElement->setAttributeNode( << 848 NewAttribute("x4", 2.0 * trap->GetXHalfLen << 849 trapElement->setAttributeNode(NewAttribute(" << 850 trapElement->setAttributeNode(NewAttribute(" << 851 trapElement->setAttributeNode(NewAttribute(" << 852 solElement->appendChild(trapElement); << 853 } << 854 << 855 // ------------------------------------------- << 856 void G4GDMLWriteSolids::TrdWrite(xercesc::DOME << 857 const G4Trd* << 858 { << 859 const G4String& name = GenerateName(trd->Get << 860 << 861 xercesc::DOMElement* trdElement = NewElement << 862 trdElement->setAttributeNode(NewAttribute("n << 863 trdElement->setAttributeNode( << 864 NewAttribute("x1", 2.0 * trd->GetXHalfLeng << 865 trdElement->setAttributeNode( << 866 NewAttribute("x2", 2.0 * trd->GetXHalfLeng << 867 trdElement->setAttributeNode( << 868 NewAttribute("y1", 2.0 * trd->GetYHalfLeng << 869 trdElement->setAttributeNode( << 870 NewAttribute("y2", 2.0 * trd->GetYHalfLeng << 871 trdElement->setAttributeNode( << 872 NewAttribute("z", 2.0 * trd->GetZHalfLengt << 873 trdElement->setAttributeNode(NewAttribute("l << 874 solElement->appendChild(trdElement); << 875 } << 876 << 877 // ------------------------------------------- << 878 void G4GDMLWriteSolids::TubeWrite(xercesc::DOM << 879 const G4Tubs << 880 { << 881 const G4String& name = GenerateName(tube->Ge << 882 << 883 xercesc::DOMElement* tubeElement = NewElemen << 884 tubeElement->setAttributeNode(NewAttribute(" << 885 tubeElement->setAttributeNode( << 886 NewAttribute("rmin", tube->GetInnerRadius( << 887 tubeElement->setAttributeNode( << 888 NewAttribute("rmax", tube->GetOuterRadius( << 889 tubeElement->setAttributeNode( << 890 NewAttribute("z", 2.0 * tube->GetZHalfLeng << 891 tubeElement->setAttributeNode( << 892 NewAttribute("startphi", tube->GetStartPhi << 893 tubeElement->setAttributeNode( << 894 NewAttribute("deltaphi", tube->GetDeltaPhi << 895 tubeElement->setAttributeNode(NewAttribute(" << 896 tubeElement->setAttributeNode(NewAttribute(" << 897 solElement->appendChild(tubeElement); << 898 } << 899 << 900 // ------------------------------------------- << 901 void G4GDMLWriteSolids::CutTubeWrite(xercesc:: << 902 const G4C << 903 { << 904 const G4String& name = GenerateName(cuttube- << 905 << 906 xercesc::DOMElement* cuttubeElement = NewEle << 907 cuttubeElement->setAttributeNode(NewAttribut << 908 cuttubeElement->setAttributeNode( << 909 NewAttribute("rmin", cuttube->GetInnerRadi << 910 cuttubeElement->setAttributeNode( << 911 NewAttribute("rmax", cuttube->GetOuterRadi << 912 cuttubeElement->setAttributeNode( << 913 NewAttribute("z", 2.0 * cuttube->GetZHalfL << 914 cuttubeElement->setAttributeNode( << 915 NewAttribute("startphi", cuttube->GetStart << 916 cuttubeElement->setAttributeNode( << 917 NewAttribute("deltaphi", cuttube->GetDelta << 918 cuttubeElement->setAttributeNode( << 919 NewAttribute("lowX", cuttube->GetLowNorm() << 920 cuttubeElement->setAttributeNode( << 921 NewAttribute("lowY", cuttube->GetLowNorm() << 922 cuttubeElement->setAttributeNode( << 923 NewAttribute("lowZ", cuttube->GetLowNorm() << 924 cuttubeElement->setAttributeNode( << 925 NewAttribute("highX", cuttube->GetHighNorm << 926 cuttubeElement->setAttributeNode( << 927 NewAttribute("highY", cuttube->GetHighNorm << 928 cuttubeElement->setAttributeNode( << 929 NewAttribute("highZ", cuttube->GetHighNorm << 930 cuttubeElement->setAttributeNode(NewAttribut << 931 cuttubeElement->setAttributeNode(NewAttribut << 932 solElement->appendChild(cuttubeElement); << 933 } << 934 << 935 // ------------------------------------------- << 936 void G4GDMLWriteSolids::TwistedboxWrite(xerces << 937 const << 938 { << 939 const G4String& name = GenerateName(twistedb << 940 << 941 xercesc::DOMElement* twistedboxElement = New << 942 twistedboxElement->setAttributeNode(NewAttri << 943 twistedboxElement->setAttributeNode( << 944 NewAttribute("x", 2.0 * twistedbox->GetXHa << 945 twistedboxElement->setAttributeNode( << 946 NewAttribute("y", 2.0 * twistedbox->GetYHa << 947 twistedboxElement->setAttributeNode( << 948 NewAttribute("z", 2.0 * twistedbox->GetZHa << 949 twistedboxElement->setAttributeNode( << 950 NewAttribute("PhiTwist", twistedbox->GetPh << 951 twistedboxElement->setAttributeNode(NewAttri << 952 twistedboxElement->setAttributeNode(NewAttri << 953 solElement->appendChild(twistedboxElement); << 954 } << 955 << 956 // ------------------------------------------- << 957 void G4GDMLWriteSolids::TwistedtrapWrite(xerce << 958 const << 959 { << 960 const G4String& name = GenerateName(twistedt << 961 << 962 xercesc::DOMElement* twistedtrapElement = Ne << 963 twistedtrapElement->setAttributeNode(NewAttr << 964 twistedtrapElement->setAttributeNode( << 965 NewAttribute("y1", 2.0 * twistedtrap->GetY << 966 twistedtrapElement->setAttributeNode( << 967 NewAttribute("x1", 2.0 * twistedtrap->GetX << 968 twistedtrapElement->setAttributeNode( << 969 NewAttribute("x2", 2.0 * twistedtrap->GetX << 970 twistedtrapElement->setAttributeNode( << 971 NewAttribute("y2", 2.0 * twistedtrap->GetY << 972 twistedtrapElement->setAttributeNode( << 973 NewAttribute("x3", 2.0 * twistedtrap->GetX << 974 twistedtrapElement->setAttributeNode( << 975 NewAttribute("x4", 2.0 * twistedtrap->GetX << 976 twistedtrapElement->setAttributeNode( << 977 NewAttribute("z", 2.0 * twistedtrap->GetZH << 978 twistedtrapElement->setAttributeNode( << 979 NewAttribute("Alph", twistedtrap->GetTiltA << 980 twistedtrapElement->setAttributeNode( << 981 NewAttribute("Theta", twistedtrap->GetPola << 982 twistedtrapElement->setAttributeNode( << 983 NewAttribute("Phi", twistedtrap->GetAzimut << 984 twistedtrapElement->setAttributeNode( << 985 NewAttribute("PhiTwist", twistedtrap->GetP << 986 twistedtrapElement->setAttributeNode(NewAttr << 987 twistedtrapElement->setAttributeNode(NewAttr << 988 651 989 solElement->appendChild(twistedtrapElement); << 652 xercesc::DOMElement* facetElement = NewElement(FacetTag); 990 } << 653 tessellatedElement->appendChild(facetElement); 991 << 992 // ------------------------------------------- << 993 void G4GDMLWriteSolids::TwistedtrdWrite(xerces << 994 const << 995 { << 996 const G4String& name = GenerateName(twistedt << 997 654 998 xercesc::DOMElement* twistedtrdElement = New << 655 for (size_t j=0; j<NumVertexPerFacet; j++) 999 twistedtrdElement->setAttributeNode(NewAttri << 656 { 1000 twistedtrdElement->setAttributeNode( << 657 std::stringstream name_stream; 1001 NewAttribute("x1", 2.0 * twistedtrd->GetX << 658 std::stringstream ref_stream; 1002 twistedtrdElement->setAttributeNode( << 1003 NewAttribute("x2", 2.0 * twistedtrd->GetX << 1004 twistedtrdElement->setAttributeNode( << 1005 NewAttribute("y1", 2.0 * twistedtrd->GetY << 1006 twistedtrdElement->setAttributeNode( << 1007 NewAttribute("y2", 2.0 * twistedtrd->GetY << 1008 twistedtrdElement->setAttributeNode( << 1009 NewAttribute("z", 2.0 * twistedtrd->GetZH << 1010 twistedtrdElement->setAttributeNode( << 1011 NewAttribute("PhiTwist", twistedtrd->GetP << 1012 twistedtrdElement->setAttributeNode(NewAttr << 1013 twistedtrdElement->setAttributeNode(NewAttr << 1014 solElement->appendChild(twistedtrdElement); << 1015 } << 1016 << 1017 // ------------------------------------------ << 1018 void G4GDMLWriteSolids::TwistedtubsWrite(xerc << 1019 cons << 1020 { << 1021 const G4String& name = GenerateName(twisted << 1022 659 1023 xercesc::DOMElement* twistedtubsElement = N << 660 name_stream << "vertex" << (j+1); 1024 twistedtubsElement->setAttributeNode(NewAtt << 661 ref_stream << solid_name << "_v" << NumVertex; 1025 twistedtubsElement->setAttributeNode( << 1026 NewAttribute("twistedangle", twistedtubs- << 1027 twistedtubsElement->setAttributeNode( << 1028 NewAttribute("midinnerrad", twistedtubs-> << 1029 twistedtubsElement->setAttributeNode( << 1030 NewAttribute("midouterrad", twistedtubs-> << 1031 twistedtubsElement->setAttributeNode( << 1032 NewAttribute("negativeEndz", twistedtubs- << 1033 twistedtubsElement->setAttributeNode( << 1034 NewAttribute("positiveEndz", twistedtubs- << 1035 twistedtubsElement->setAttributeNode( << 1036 NewAttribute("phi", twistedtubs->GetDPhi( << 1037 twistedtubsElement->setAttributeNode(NewAtt << 1038 twistedtubsElement->setAttributeNode(NewAtt << 1039 solElement->appendChild(twistedtubsElement) << 1040 } << 1041 662 1042 // ------------------------------------------ << 663 const G4String& fname = name_stream.str(); // facet's tag variable 1043 void G4GDMLWriteSolids::ZplaneWrite(xercesc:: << 664 G4String ref = ref_stream.str(); // vertex tag to be associated 1044 const G4d << 1045 const G4d << 1046 { << 1047 xercesc::DOMElement* zplaneElement = NewEle << 1048 zplaneElement->setAttributeNode(NewAttribut << 1049 zplaneElement->setAttributeNode(NewAttribut << 1050 zplaneElement->setAttributeNode(NewAttribut << 1051 element->appendChild(zplaneElement); << 1052 } << 1053 665 1054 // ------------------------------------------ << 666 // Now search for the existance of the current vertex in the 1055 void G4GDMLWriteSolids::RZPointWrite(xercesc: << 667 // map of cached vertices. If existing, do NOT store it as 1056 const G4 << 668 // position in the GDML file, so avoiding duplication; otherwise 1057 { << 669 // cache it in the local map and add it as position in the 1058 xercesc::DOMElement* rzpointElement = NewEl << 670 // "define" section of the GDML file. 1059 rzpointElement->setAttributeNode(NewAttribu << 671 1060 rzpointElement->setAttributeNode(NewAttribu << 672 const G4ThreeVector& vertex = facet->GetVertex(j); 1061 element->appendChild(rzpointElement); << 673 >> 674 if(vertexMap.find(vertex) != vertexMap.end()) // Vertex is cached >> 675 { >> 676 ref = vertexMap[vertex]; // Set the proper tag for it >> 677 } >> 678 else // Vertex not found >> 679 { >> 680 vertexMap.insert(std::make_pair(vertex,ref)); // Cache vertex and ... >> 681 AddPosition(ref, vertex); // ... add it to define section! >> 682 NumVertex++; >> 683 } >> 684 >> 685 // Now create association of the vertex with its facet >> 686 // >> 687 facetElement->setAttributeNode(NewAttribute(fname,ref)); >> 688 } >> 689 } 1062 } 690 } 1063 691 1064 // ------------------------------------------ << 692 void G4GDMLWriteSolids:: 1065 void G4GDMLWriteSolids::OpticalSurfaceWrite(x << 693 TetWrite(xercesc::DOMElement* solElement, const G4Tet* const tet) 1066 c << 1067 { 694 { 1068 xercesc::DOMElement* optElement = NewElemen << 695 const G4String& solid_name = tet->GetName(); 1069 G4OpticalSurfaceModel smodel = surf->Get << 696 const G4String& name = GenerateName(solid_name, tet); 1070 G4double sval = << 1071 (smodel == glisur) ? surf->GetPolish() : << 1072 const G4String& name = GenerateName(surf->G << 1073 << 1074 optElement->setAttributeNode(NewAttribute(" << 1075 optElement->setAttributeNode(NewAttribute(" << 1076 optElement->setAttributeNode(NewAttribute(" << 1077 optElement->setAttributeNode(NewAttribute(" << 1078 optElement->setAttributeNode(NewAttribute(" << 1079 << 1080 // Write any property attached to the optic << 1081 // << 1082 if(surf->GetMaterialPropertiesTable()) << 1083 { << 1084 PropertyWrite(optElement, surf); << 1085 } << 1086 697 1087 solElement->appendChild(optElement); << 698 std::vector<G4ThreeVector> vertexList = tet->GetVertices(); 1088 } << 699 >> 700 xercesc::DOMElement* tetElement = NewElement("tet"); >> 701 tetElement->setAttributeNode(NewAttribute("name",name)); >> 702 tetElement->setAttributeNode(NewAttribute("vertex1",solid_name+"_v1")); >> 703 tetElement->setAttributeNode(NewAttribute("vertex2",solid_name+"_v2")); >> 704 tetElement->setAttributeNode(NewAttribute("vertex3",solid_name+"_v3")); >> 705 tetElement->setAttributeNode(NewAttribute("vertex4",solid_name+"_v4")); >> 706 tetElement->setAttributeNode(NewAttribute("lunit","mm")); >> 707 solElement->appendChild(tetElement); >> 708 >> 709 AddPosition(solid_name+"_v1",vertexList[0]); >> 710 AddPosition(solid_name+"_v2",vertexList[1]); >> 711 AddPosition(solid_name+"_v3",vertexList[2]); >> 712 AddPosition(solid_name+"_v4",vertexList[3]); >> 713 } >> 714 >> 715 void G4GDMLWriteSolids:: >> 716 TorusWrite(xercesc::DOMElement* solElement, const G4Torus* const torus) >> 717 { >> 718 const G4String& name = GenerateName(torus->GetName(),torus); >> 719 >> 720 xercesc::DOMElement* torusElement = NewElement("torus"); >> 721 torusElement->setAttributeNode(NewAttribute("name",name)); >> 722 torusElement->setAttributeNode(NewAttribute("rmin",torus->GetRmin()/mm)); >> 723 torusElement->setAttributeNode(NewAttribute("rmax",torus->GetRmax()/mm)); >> 724 torusElement->setAttributeNode(NewAttribute("rtor",torus->GetRtor()/mm)); >> 725 torusElement-> >> 726 setAttributeNode(NewAttribute("startphi",torus->GetSPhi()/degree)); >> 727 torusElement-> >> 728 setAttributeNode(NewAttribute("deltaphi",torus->GetDPhi()/degree)); >> 729 torusElement->setAttributeNode(NewAttribute("aunit","deg")); >> 730 torusElement->setAttributeNode(NewAttribute("lunit","mm")); >> 731 solElement->appendChild(torusElement); >> 732 } >> 733 >> 734 void G4GDMLWriteSolids:: >> 735 GenTrapWrite(xercesc::DOMElement* solElement, >> 736 const G4GenericTrap* const gtrap) >> 737 { >> 738 const G4String& name = GenerateName(gtrap->GetName(),gtrap); >> 739 >> 740 std::vector<G4TwoVector> vertices = gtrap->GetVertices(); >> 741 >> 742 xercesc::DOMElement* gtrapElement = NewElement("arb8"); >> 743 gtrapElement->setAttributeNode(NewAttribute("name",name)); >> 744 gtrapElement->setAttributeNode(NewAttribute("dz", >> 745 gtrap->GetZHalfLength()/mm)); >> 746 gtrapElement->setAttributeNode(NewAttribute("v1x", vertices[0].x())); >> 747 gtrapElement->setAttributeNode(NewAttribute("v1y", vertices[0].y())); >> 748 gtrapElement->setAttributeNode(NewAttribute("v2x", vertices[1].x())); >> 749 gtrapElement->setAttributeNode(NewAttribute("v2y", vertices[1].y())); >> 750 gtrapElement->setAttributeNode(NewAttribute("v3x", vertices[2].x())); >> 751 gtrapElement->setAttributeNode(NewAttribute("v3y", vertices[2].y())); >> 752 gtrapElement->setAttributeNode(NewAttribute("v4x", vertices[3].x())); >> 753 gtrapElement->setAttributeNode(NewAttribute("v4y", vertices[3].y())); >> 754 gtrapElement->setAttributeNode(NewAttribute("v5x", vertices[4].x())); >> 755 gtrapElement->setAttributeNode(NewAttribute("v5y", vertices[4].y())); >> 756 gtrapElement->setAttributeNode(NewAttribute("v6x", vertices[5].x())); >> 757 gtrapElement->setAttributeNode(NewAttribute("v6y", vertices[5].y())); >> 758 gtrapElement->setAttributeNode(NewAttribute("v7x", vertices[6].x())); >> 759 gtrapElement->setAttributeNode(NewAttribute("v7y", vertices[6].y())); >> 760 gtrapElement->setAttributeNode(NewAttribute("v8x", vertices[7].x())); >> 761 gtrapElement->setAttributeNode(NewAttribute("v8y", vertices[7].y())); >> 762 gtrapElement->setAttributeNode(NewAttribute("lunit","mm")); >> 763 solElement->appendChild(gtrapElement); >> 764 } >> 765 >> 766 void G4GDMLWriteSolids:: >> 767 TrapWrite(xercesc::DOMElement* solElement, const G4Trap* const trap) >> 768 { >> 769 const G4String& name = GenerateName(trap->GetName(),trap); >> 770 >> 771 const G4ThreeVector& simaxis = trap->GetSymAxis(); >> 772 const G4double phi = simaxis.phi(); >> 773 const G4double theta = simaxis.theta(); >> 774 const G4double alpha1 = std::atan(trap->GetTanAlpha1()); >> 775 const G4double alpha2 = std::atan(trap->GetTanAlpha2()); >> 776 >> 777 xercesc::DOMElement* trapElement = NewElement("trap"); >> 778 trapElement->setAttributeNode(NewAttribute("name",name)); >> 779 trapElement->setAttributeNode(NewAttribute("z", >> 780 2.0*trap->GetZHalfLength()/mm)); >> 781 trapElement->setAttributeNode(NewAttribute("theta",theta/degree)); >> 782 trapElement->setAttributeNode(NewAttribute("phi",phi/degree)); >> 783 trapElement->setAttributeNode(NewAttribute("y1", >> 784 2.0*trap->GetYHalfLength1()/mm)); >> 785 trapElement->setAttributeNode(NewAttribute("x1", >> 786 2.0*trap->GetXHalfLength1()/mm)); >> 787 trapElement->setAttributeNode(NewAttribute("x2", >> 788 2.0*trap->GetXHalfLength2()/mm)); >> 789 trapElement->setAttributeNode(NewAttribute("alpha1",alpha1/degree)); >> 790 trapElement->setAttributeNode(NewAttribute("y2", >> 791 2.0*trap->GetYHalfLength2()/mm)); >> 792 trapElement->setAttributeNode(NewAttribute("x3", >> 793 2.0*trap->GetXHalfLength3()/mm)); >> 794 trapElement->setAttributeNode(NewAttribute("x4", >> 795 2.0*trap->GetXHalfLength4()/mm)); >> 796 trapElement->setAttributeNode(NewAttribute("alpha2",alpha2/degree)); >> 797 trapElement->setAttributeNode(NewAttribute("aunit","deg")); >> 798 trapElement->setAttributeNode(NewAttribute("lunit","mm")); >> 799 solElement->appendChild(trapElement); >> 800 } >> 801 >> 802 void G4GDMLWriteSolids:: >> 803 TrdWrite(xercesc::DOMElement* solElement, const G4Trd* const trd) >> 804 { >> 805 const G4String& name = GenerateName(trd->GetName(),trd); >> 806 >> 807 xercesc::DOMElement* trdElement = NewElement("trd"); >> 808 trdElement->setAttributeNode(NewAttribute("name",name)); >> 809 trdElement->setAttributeNode(NewAttribute("x1", >> 810 2.0*trd->GetXHalfLength1()/mm)); >> 811 trdElement->setAttributeNode(NewAttribute("x2", >> 812 2.0*trd->GetXHalfLength2()/mm)); >> 813 trdElement->setAttributeNode(NewAttribute("y1", >> 814 2.0*trd->GetYHalfLength1()/mm)); >> 815 trdElement->setAttributeNode(NewAttribute("y2", >> 816 2.0*trd->GetYHalfLength2()/mm)); >> 817 trdElement->setAttributeNode(NewAttribute("z", >> 818 2.0*trd->GetZHalfLength()/mm)); >> 819 trdElement->setAttributeNode(NewAttribute("lunit","mm")); >> 820 solElement->appendChild(trdElement); >> 821 } >> 822 >> 823 void G4GDMLWriteSolids:: >> 824 TubeWrite(xercesc::DOMElement* solElement, const G4Tubs* const tube) >> 825 { >> 826 const G4String& name = GenerateName(tube->GetName(),tube); >> 827 >> 828 xercesc::DOMElement* tubeElement = NewElement("tube"); >> 829 tubeElement->setAttributeNode(NewAttribute("name",name)); >> 830 tubeElement->setAttributeNode(NewAttribute("rmin", >> 831 tube->GetInnerRadius()/mm)); >> 832 tubeElement->setAttributeNode(NewAttribute("rmax", >> 833 tube->GetOuterRadius()/mm)); >> 834 tubeElement->setAttributeNode(NewAttribute("z", >> 835 2.0*tube->GetZHalfLength()/mm)); >> 836 tubeElement->setAttributeNode(NewAttribute("startphi", >> 837 tube->GetStartPhiAngle()/degree)); >> 838 tubeElement->setAttributeNode(NewAttribute("deltaphi", >> 839 tube->GetDeltaPhiAngle()/degree)); >> 840 tubeElement->setAttributeNode(NewAttribute("aunit","deg")); >> 841 tubeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 842 solElement->appendChild(tubeElement); >> 843 } >> 844 >> 845 void G4GDMLWriteSolids:: >> 846 CutTubeWrite(xercesc::DOMElement* solElement, const G4CutTubs* const cuttube) >> 847 { >> 848 const G4String& name = GenerateName(cuttube->GetName(),cuttube); >> 849 >> 850 xercesc::DOMElement* cuttubeElement = NewElement("cutTube"); >> 851 cuttubeElement->setAttributeNode(NewAttribute("name",name)); >> 852 cuttubeElement->setAttributeNode(NewAttribute("rmin", >> 853 cuttube->GetInnerRadius()/mm)); >> 854 cuttubeElement->setAttributeNode(NewAttribute("rmax", >> 855 cuttube->GetOuterRadius()/mm)); >> 856 cuttubeElement->setAttributeNode(NewAttribute("z", >> 857 2.0*cuttube->GetZHalfLength()/mm)); >> 858 cuttubeElement->setAttributeNode(NewAttribute("startphi", >> 859 cuttube->GetStartPhiAngle()/degree)); >> 860 cuttubeElement->setAttributeNode(NewAttribute("deltaphi", >> 861 cuttube->GetDeltaPhiAngle()/degree)); >> 862 cuttubeElement->setAttributeNode(NewAttribute("lowX", >> 863 cuttube->GetLowNorm().getX()/mm)); >> 864 cuttubeElement->setAttributeNode(NewAttribute("lowY", >> 865 cuttube->GetLowNorm().getY()/mm)); >> 866 cuttubeElement->setAttributeNode(NewAttribute("lowZ", >> 867 cuttube->GetLowNorm().getZ()/mm)); >> 868 cuttubeElement->setAttributeNode(NewAttribute("highX", >> 869 cuttube->GetHighNorm().getX()/mm)); >> 870 cuttubeElement->setAttributeNode(NewAttribute("highY", >> 871 cuttube->GetHighNorm().getY()/mm)); >> 872 cuttubeElement->setAttributeNode(NewAttribute("highZ", >> 873 cuttube->GetHighNorm().getZ()/mm)); >> 874 cuttubeElement->setAttributeNode(NewAttribute("aunit","deg")); >> 875 cuttubeElement->setAttributeNode(NewAttribute("lunit","mm")); >> 876 solElement->appendChild(cuttubeElement); >> 877 } >> 878 >> 879 void G4GDMLWriteSolids:: >> 880 TwistedboxWrite(xercesc::DOMElement* solElement, >> 881 const G4TwistedBox* const twistedbox) >> 882 { >> 883 const G4String& name = GenerateName(twistedbox->GetName(),twistedbox); >> 884 >> 885 xercesc::DOMElement* twistedboxElement = NewElement("twistedbox"); >> 886 twistedboxElement->setAttributeNode(NewAttribute("name",name)); >> 887 twistedboxElement->setAttributeNode(NewAttribute("x", >> 888 2.0*twistedbox->GetXHalfLength()/mm)); >> 889 twistedboxElement->setAttributeNode(NewAttribute("y", >> 890 2.0*twistedbox->GetYHalfLength()/mm)); >> 891 twistedboxElement->setAttributeNode(NewAttribute("z", >> 892 2.0*twistedbox->GetZHalfLength()/mm)); >> 893 twistedboxElement->setAttributeNode(NewAttribute("PhiTwist", >> 894 twistedbox->GetPhiTwist()/degree)); >> 895 twistedboxElement->setAttributeNode(NewAttribute("aunit","deg")); >> 896 twistedboxElement->setAttributeNode(NewAttribute("lunit","mm")); >> 897 solElement->appendChild(twistedboxElement); >> 898 } >> 899 >> 900 void G4GDMLWriteSolids:: >> 901 TwistedtrapWrite(xercesc::DOMElement* solElement, >> 902 const G4TwistedTrap* const twistedtrap) >> 903 { >> 904 const G4String& name = GenerateName(twistedtrap->GetName(),twistedtrap); >> 905 >> 906 xercesc::DOMElement* twistedtrapElement = NewElement("twistedtrap"); >> 907 twistedtrapElement->setAttributeNode(NewAttribute("name",name)); >> 908 twistedtrapElement->setAttributeNode(NewAttribute("y1", >> 909 2.0*twistedtrap->GetY1HalfLength()/mm)); >> 910 twistedtrapElement->setAttributeNode(NewAttribute("x1", >> 911 2.0*twistedtrap->GetX1HalfLength()/mm)); >> 912 twistedtrapElement->setAttributeNode(NewAttribute("x2", >> 913 2.0*twistedtrap->GetX2HalfLength()/mm)); >> 914 twistedtrapElement->setAttributeNode(NewAttribute("y2", >> 915 2.0*twistedtrap->GetY2HalfLength()/mm)); >> 916 twistedtrapElement->setAttributeNode(NewAttribute("x3", >> 917 2.0*twistedtrap->GetX3HalfLength()/mm)); >> 918 twistedtrapElement->setAttributeNode(NewAttribute("x4", >> 919 2.0*twistedtrap->GetX4HalfLength()/mm)); >> 920 twistedtrapElement->setAttributeNode(NewAttribute("z", >> 921 2.0*twistedtrap->GetZHalfLength()/mm)); >> 922 twistedtrapElement->setAttributeNode(NewAttribute("Alph", >> 923 twistedtrap->GetTiltAngleAlpha()/degree)); >> 924 twistedtrapElement->setAttributeNode(NewAttribute("Theta", >> 925 twistedtrap->GetPolarAngleTheta()/degree)); >> 926 twistedtrapElement->setAttributeNode(NewAttribute("Phi", >> 927 twistedtrap->GetAzimuthalAnglePhi()/degree)); >> 928 twistedtrapElement->setAttributeNode(NewAttribute("PhiTwist", >> 929 twistedtrap->GetPhiTwist()/degree)); >> 930 twistedtrapElement->setAttributeNode(NewAttribute("aunit","deg")); >> 931 twistedtrapElement->setAttributeNode(NewAttribute("lunit","mm")); >> 932 >> 933 solElement->appendChild(twistedtrapElement); >> 934 } >> 935 >> 936 void G4GDMLWriteSolids:: >> 937 TwistedtrdWrite(xercesc::DOMElement* solElement, >> 938 const G4TwistedTrd* const twistedtrd) >> 939 { >> 940 const G4String& name = GenerateName(twistedtrd->GetName(),twistedtrd); >> 941 >> 942 xercesc::DOMElement* twistedtrdElement = NewElement("twistedtrd"); >> 943 twistedtrdElement->setAttributeNode(NewAttribute("name",name)); >> 944 twistedtrdElement->setAttributeNode(NewAttribute("x1", >> 945 2.0*twistedtrd->GetX1HalfLength()/mm)); >> 946 twistedtrdElement->setAttributeNode(NewAttribute("x2", >> 947 2.0*twistedtrd->GetX2HalfLength()/mm)); >> 948 twistedtrdElement->setAttributeNode(NewAttribute("y1", >> 949 2.0*twistedtrd->GetY1HalfLength()/mm)); >> 950 twistedtrdElement->setAttributeNode(NewAttribute("y2", >> 951 2.0*twistedtrd->GetY2HalfLength()/mm)); >> 952 twistedtrdElement->setAttributeNode(NewAttribute("z", >> 953 2.0*twistedtrd->GetZHalfLength()/mm)); >> 954 twistedtrdElement->setAttributeNode(NewAttribute("PhiTwist", >> 955 twistedtrd->GetPhiTwist()/degree)); >> 956 twistedtrdElement->setAttributeNode(NewAttribute("aunit","deg")); >> 957 twistedtrdElement->setAttributeNode(NewAttribute("lunit","mm")); >> 958 solElement->appendChild(twistedtrdElement); >> 959 } >> 960 >> 961 void G4GDMLWriteSolids:: >> 962 TwistedtubsWrite(xercesc::DOMElement* solElement, >> 963 const G4TwistedTubs* const twistedtubs) >> 964 { >> 965 const G4String& name = GenerateName(twistedtubs->GetName(),twistedtubs); >> 966 >> 967 xercesc::DOMElement* twistedtubsElement = NewElement("twistedtubs"); >> 968 twistedtubsElement->setAttributeNode(NewAttribute("name",name)); >> 969 twistedtubsElement->setAttributeNode(NewAttribute("twistedangle", >> 970 twistedtubs->GetPhiTwist()/degree)); >> 971 twistedtubsElement->setAttributeNode(NewAttribute("endinnerrad", >> 972 twistedtubs->GetInnerRadius()/mm)); >> 973 twistedtubsElement->setAttributeNode(NewAttribute("endouterrad", >> 974 twistedtubs->GetOuterRadius()/mm)); >> 975 twistedtubsElement->setAttributeNode(NewAttribute("zlen", >> 976 2.0*twistedtubs->GetZHalfLength()/mm)); >> 977 twistedtubsElement->setAttributeNode(NewAttribute("phi", >> 978 twistedtubs->GetDPhi()/degree)); >> 979 twistedtubsElement->setAttributeNode(NewAttribute("aunit","deg")); >> 980 twistedtubsElement->setAttributeNode(NewAttribute("lunit","mm")); >> 981 solElement->appendChild(twistedtubsElement); >> 982 } >> 983 >> 984 void G4GDMLWriteSolids:: >> 985 ZplaneWrite(xercesc::DOMElement* element, const G4double& z, >> 986 const G4double& rmin, const G4double& rmax) >> 987 { >> 988 xercesc::DOMElement* zplaneElement = NewElement("zplane"); >> 989 zplaneElement->setAttributeNode(NewAttribute("z",z/mm)); >> 990 zplaneElement->setAttributeNode(NewAttribute("rmin",rmin/mm)); >> 991 zplaneElement->setAttributeNode(NewAttribute("rmax",rmax/mm)); >> 992 element->appendChild(zplaneElement); >> 993 } >> 994 >> 995 void G4GDMLWriteSolids:: >> 996 RZPointWrite(xercesc::DOMElement* element, const G4double& r, >> 997 const G4double& z) >> 998 { >> 999 xercesc::DOMElement* rzpointElement = NewElement("rzpoint"); >> 1000 rzpointElement->setAttributeNode(NewAttribute("r",r/mm)); >> 1001 rzpointElement->setAttributeNode(NewAttribute("z",z/mm)); >> 1002 element->appendChild(rzpointElement); >> 1003 } >> 1004 >> 1005 void G4GDMLWriteSolids:: >> 1006 OpticalSurfaceWrite(xercesc::DOMElement* solElement, >> 1007 const G4OpticalSurface* const surf) >> 1008 { >> 1009 xercesc::DOMElement* optElement = NewElement("opticalsurface"); >> 1010 G4OpticalSurfaceModel smodel = surf->GetModel(); >> 1011 G4double sval = (smodel==glisur) ? surf->GetPolish() : surf->GetSigmaAlpha(); >> 1012 >> 1013 optElement->setAttributeNode(NewAttribute("name", surf->GetName())); >> 1014 optElement->setAttributeNode(NewAttribute("model", smodel)); >> 1015 optElement->setAttributeNode(NewAttribute("finish", surf->GetFinish())); >> 1016 optElement->setAttributeNode(NewAttribute("type", surf->GetType())); >> 1017 optElement->setAttributeNode(NewAttribute("value", sval)); 1089 1018 1090 // ------------------------------------------ << 1019 solElement->appendChild(optElement); 1091 void G4GDMLWriteSolids::PropertyWrite(xercesc << 1092 const G << 1093 { << 1094 xercesc::DOMElement* propElement; << 1095 G4MaterialPropertiesTable* ptable = surf->G << 1096 auto pvec = ptable->GetProperties(); << 1097 auto cvec = ptable->GetConstProperties(); << 1098 << 1099 for(size_t i = 0; i < pvec.size(); ++i) << 1100 { << 1101 if(pvec[i] != nullptr) { << 1102 propElement = NewElement("property"); << 1103 propElement->setAttributeNode( << 1104 NewAttribute("name", ptable->GetMater << 1105 propElement->setAttributeNode(NewAttrib << 1106 "ref", GenerateName(ptable->GetMateri << 1107 pvec[i]))); << 1108 PropertyVectorWrite(ptable->GetMaterial << 1109 pvec[i]); << 1110 optElement->appendChild(propElement); << 1111 } << 1112 } << 1113 for(size_t i = 0; i < cvec.size(); ++i) << 1114 { << 1115 if (cvec[i].second == true) { << 1116 propElement = NewElement("property"); << 1117 propElement->setAttributeNode(NewAttrib << 1118 "name", ptable->GetMaterialConstPrope << 1119 propElement->setAttributeNode(NewAttrib << 1120 "ref", ptable->GetMaterialConstProper << 1121 xercesc::DOMElement* constElement = New << 1122 constElement->setAttributeNode(NewAttri << 1123 "name", ptable->GetMaterialConstPrope << 1124 constElement->setAttributeNode(NewAttri << 1125 defineElement->appendChild(constElement << 1126 optElement->appendChild(propElement); << 1127 } << 1128 } << 1129 } 1020 } 1130 1021 1131 // ------------------------------------------ << 1132 void G4GDMLWriteSolids::SolidsWrite(xercesc:: 1022 void G4GDMLWriteSolids::SolidsWrite(xercesc::DOMElement* gdmlElement) 1133 { 1023 { 1134 #ifdef G4VERBOSE << 1024 G4cout << "G4GDML: Writing solids..." << G4endl; 1135 G4cout << "G4GDML: Writing solids..." << G4 << 1025 1136 #endif << 1026 solidsElement = NewElement("solids"); 1137 solidsElement = NewElement("solids"); << 1027 gdmlElement->appendChild(solidsElement); 1138 gdmlElement->appendChild(solidsElement); << 1139 1028 1140 solidList.clear(); << 1029 solidList.clear(); 1141 } 1030 } 1142 1031 1143 // ------------------------------------------ << 1144 void G4GDMLWriteSolids::AddSolid(const G4VSol 1032 void G4GDMLWriteSolids::AddSolid(const G4VSolid* const solidPtr) 1145 { 1033 { 1146 for(std::size_t i = 0; i < solidList.size() << 1034 for (size_t i=0; i<solidList.size(); i++) // Check if solid is 1147 { << 1035 { // already in the list! 1148 if(solidList[i] == solidPtr) << 1036 if (solidList[i] == solidPtr) { return; } 1149 { << 1037 } 1150 return; << 1038 1151 } << 1039 solidList.push_back(solidPtr); 1152 } << 1040 1153 << 1041 if (const G4BooleanSolid* const booleanPtr 1154 solidList.push_back(solidPtr); << 1042 = dynamic_cast<const G4BooleanSolid*>(solidPtr)) 1155 << 1043 { BooleanWrite(solidsElement,booleanPtr); } else 1156 if(const G4BooleanSolid* const booleanPtr = << 1044 if (solidPtr->GetEntityType()=="G4MultiUnion") 1157 dynamic_cast<const G4BooleanSolid*>(so << 1045 { const G4MultiUnion* const munionPtr 1158 { << 1046 = static_cast<const G4MultiUnion*>(solidPtr); 1159 BooleanWrite(solidsElement, booleanPtr); << 1047 MultiUnionWrite(solidsElement,munionPtr); } else 1160 } << 1048 if (solidPtr->GetEntityType()=="G4Box") 1161 else if(const G4ScaledSolid* const scaledPt << 1049 { const G4Box* const boxPtr 1162 dynamic_cast<const G4ScaledSolid* << 1050 = static_cast<const G4Box*>(solidPtr); 1163 { << 1051 BoxWrite(solidsElement,boxPtr); } else 1164 ScaledWrite(solidsElement, scaledPtr); << 1052 if (solidPtr->GetEntityType()=="G4Cons") 1165 } << 1053 { const G4Cons* const conePtr 1166 else if(solidPtr->GetEntityType() == "G4Mul << 1054 = static_cast<const G4Cons*>(solidPtr); 1167 { << 1055 ConeWrite(solidsElement,conePtr); } else 1168 const G4MultiUnion* const munionPtr = << 1056 if (solidPtr->GetEntityType()=="G4EllipticalCone") 1169 static_cast<const G4MultiUnion*>(solidP << 1057 { const G4EllipticalCone* const elconePtr 1170 MultiUnionWrite(solidsElement, munionPtr) << 1058 = static_cast<const G4EllipticalCone*>(solidPtr); 1171 } << 1059 ElconeWrite(solidsElement,elconePtr); } else 1172 else if(solidPtr->GetEntityType() == "G4Box << 1060 if (solidPtr->GetEntityType()=="G4Ellipsoid") 1173 { << 1061 { const G4Ellipsoid* const ellipsoidPtr 1174 const G4Box* const boxPtr = static_cast<c << 1062 = static_cast<const G4Ellipsoid*>(solidPtr); 1175 BoxWrite(solidsElement, boxPtr); << 1063 EllipsoidWrite(solidsElement,ellipsoidPtr); } else 1176 } << 1064 if (solidPtr->GetEntityType()=="G4EllipticalTube") 1177 else if(solidPtr->GetEntityType() == "G4Con << 1065 { const G4EllipticalTube* const eltubePtr 1178 { << 1066 = static_cast<const G4EllipticalTube*>(solidPtr); 1179 const G4Cons* const conePtr = static_cast << 1067 EltubeWrite(solidsElement,eltubePtr); } else 1180 ConeWrite(solidsElement, conePtr); << 1068 if (solidPtr->GetEntityType()=="G4ExtrudedSolid") 1181 } << 1069 { const G4ExtrudedSolid* const xtruPtr 1182 else if(solidPtr->GetEntityType() == "G4Ell << 1070 = static_cast<const G4ExtrudedSolid*>(solidPtr); 1183 { << 1071 XtruWrite(solidsElement,xtruPtr); } else 1184 const G4EllipticalCone* const elconePtr = << 1072 if (solidPtr->GetEntityType()=="G4Hype") 1185 static_cast<const G4EllipticalCone*>(so << 1073 { const G4Hype* const hypePtr 1186 ElconeWrite(solidsElement, elconePtr); << 1074 = static_cast<const G4Hype*>(solidPtr); 1187 } << 1075 HypeWrite(solidsElement,hypePtr); } else 1188 else if(solidPtr->GetEntityType() == "G4Ell << 1076 if (solidPtr->GetEntityType()=="G4Orb") 1189 { << 1077 { const G4Orb* const orbPtr 1190 const G4Ellipsoid* const ellipsoidPtr = << 1078 = static_cast<const G4Orb*>(solidPtr); 1191 static_cast<const G4Ellipsoid*>(solidPt << 1079 OrbWrite(solidsElement,orbPtr); } else 1192 EllipsoidWrite(solidsElement, ellipsoidPt << 1080 if (solidPtr->GetEntityType()=="G4Para") 1193 } << 1081 { const G4Para* const paraPtr 1194 else if(solidPtr->GetEntityType() == "G4Ell << 1082 = static_cast<const G4Para*>(solidPtr); 1195 { << 1083 ParaWrite(solidsElement,paraPtr); } else 1196 const G4EllipticalTube* const eltubePtr = << 1084 if (solidPtr->GetEntityType()=="G4Paraboloid") 1197 static_cast<const G4EllipticalTube*>(so << 1085 { const G4Paraboloid* const paraboloidPtr 1198 EltubeWrite(solidsElement, eltubePtr); << 1086 = static_cast<const G4Paraboloid*>(solidPtr); 1199 } << 1087 ParaboloidWrite(solidsElement,paraboloidPtr); } else 1200 else if(solidPtr->GetEntityType() == "G4Ext << 1088 if (solidPtr->GetEntityType()=="G4Polycone") 1201 { << 1089 { const G4Polycone* const polyconePtr 1202 const G4ExtrudedSolid* const xtruPtr = << 1090 = static_cast<const G4Polycone*>(solidPtr); 1203 static_cast<const G4ExtrudedSolid*>(sol << 1091 PolyconeWrite(solidsElement,polyconePtr); } else 1204 XtruWrite(solidsElement, xtruPtr); << 1092 if (solidPtr->GetEntityType()=="G4GenericPolycone") 1205 } << 1093 { const G4GenericPolycone* const genpolyconePtr 1206 else if(solidPtr->GetEntityType() == "G4Hyp << 1094 = static_cast<const G4GenericPolycone*>(solidPtr); 1207 { << 1095 GenericPolyconeWrite(solidsElement,genpolyconePtr); } else 1208 const G4Hype* const hypePtr = static_cast << 1096 if (solidPtr->GetEntityType()=="G4Polyhedra") 1209 HypeWrite(solidsElement, hypePtr); << 1097 { const G4Polyhedra* const polyhedraPtr 1210 } << 1098 = static_cast<const G4Polyhedra*>(solidPtr); 1211 else if(solidPtr->GetEntityType() == "G4Orb << 1099 PolyhedraWrite(solidsElement,polyhedraPtr); } else 1212 { << 1100 if (solidPtr->GetEntityType()=="G4Sphere") 1213 const G4Orb* const orbPtr = static_cast<c << 1101 { const G4Sphere* const spherePtr 1214 OrbWrite(solidsElement, orbPtr); << 1102 = static_cast<const G4Sphere*>(solidPtr); 1215 } << 1103 SphereWrite(solidsElement,spherePtr); } else 1216 else if(solidPtr->GetEntityType() == "G4Par << 1104 if (solidPtr->GetEntityType()=="G4TessellatedSolid") 1217 { << 1105 { const G4TessellatedSolid* const tessellatedPtr 1218 const G4Para* const paraPtr = static_cast << 1106 = static_cast<const G4TessellatedSolid*>(solidPtr); 1219 ParaWrite(solidsElement, paraPtr); << 1107 TessellatedWrite(solidsElement,tessellatedPtr); } else 1220 } << 1108 if (solidPtr->GetEntityType()=="G4Tet") 1221 else if(solidPtr->GetEntityType() == "G4Par << 1109 { const G4Tet* const tetPtr 1222 { << 1110 = static_cast<const G4Tet*>(solidPtr); 1223 const G4Paraboloid* const paraboloidPtr = << 1111 TetWrite(solidsElement,tetPtr); } else 1224 static_cast<const G4Paraboloid*>(solidP << 1112 if (solidPtr->GetEntityType()=="G4Torus") 1225 ParaboloidWrite(solidsElement, paraboloid << 1113 { const G4Torus* const torusPtr 1226 } << 1114 = static_cast<const G4Torus*>(solidPtr); 1227 else if(solidPtr->GetEntityType() == "G4Pol << 1115 TorusWrite(solidsElement,torusPtr); } else 1228 { << 1116 if (solidPtr->GetEntityType()=="G4GenericTrap") 1229 const G4Polycone* const polyconePtr = << 1117 { const G4GenericTrap* const gtrapPtr 1230 static_cast<const G4Polycone*>(solidPtr << 1118 = static_cast<const G4GenericTrap*>(solidPtr); 1231 PolyconeWrite(solidsElement, polyconePtr) << 1119 GenTrapWrite(solidsElement,gtrapPtr); } else 1232 } << 1120 if (solidPtr->GetEntityType()=="G4Trap") 1233 else if(solidPtr->GetEntityType() == "G4Gen << 1121 { const G4Trap* const trapPtr 1234 { << 1122 = static_cast<const G4Trap*>(solidPtr); 1235 const G4GenericPolycone* const genpolycon << 1123 TrapWrite(solidsElement,trapPtr); } else 1236 static_cast<const G4GenericPolycone*>(s << 1124 if (solidPtr->GetEntityType()=="G4Trd") 1237 GenericPolyconeWrite(solidsElement, genpo << 1125 { const G4Trd* const trdPtr 1238 } << 1126 = static_cast<const G4Trd*>(solidPtr); 1239 else if(solidPtr->GetEntityType() == "G4Pol << 1127 TrdWrite(solidsElement,trdPtr); } else 1240 { << 1128 if (solidPtr->GetEntityType()=="G4Tubs") 1241 const G4Polyhedra* const polyhedraPtr = << 1129 { const G4Tubs* const tubePtr 1242 static_cast<const G4Polyhedra*>(solidPt << 1130 = static_cast<const G4Tubs*>(solidPtr); 1243 PolyhedraWrite(solidsElement, polyhedraPt << 1131 TubeWrite(solidsElement,tubePtr); } else 1244 } << 1132 if (solidPtr->GetEntityType()=="G4CutTubs") 1245 else if(solidPtr->GetEntityType() == "G4Sph << 1133 { const G4CutTubs* const cuttubePtr 1246 { << 1134 = static_cast<const G4CutTubs*>(solidPtr); 1247 const G4Sphere* const spherePtr = static_ << 1135 CutTubeWrite(solidsElement,cuttubePtr); } else 1248 SphereWrite(solidsElement, spherePtr); << 1136 if (solidPtr->GetEntityType()=="G4TwistedBox") 1249 } << 1137 { const G4TwistedBox* const twistedboxPtr 1250 else if(solidPtr->GetEntityType() == "G4Tes << 1138 = static_cast<const G4TwistedBox*>(solidPtr); 1251 { << 1139 TwistedboxWrite(solidsElement,twistedboxPtr); } else 1252 const G4TessellatedSolid* const tessellat << 1140 if (solidPtr->GetEntityType()=="G4TwistedTrap") 1253 static_cast<const G4TessellatedSolid*>( << 1141 { const G4TwistedTrap* const twistedtrapPtr 1254 TessellatedWrite(solidsElement, tessellat << 1142 = static_cast<const G4TwistedTrap*>(solidPtr); 1255 } << 1143 TwistedtrapWrite(solidsElement,twistedtrapPtr); } else 1256 else if(solidPtr->GetEntityType() == "G4Tet << 1144 if (solidPtr->GetEntityType()=="G4TwistedTrd") 1257 { << 1145 { const G4TwistedTrd* const twistedtrdPtr 1258 const G4Tet* const tetPtr = static_cast<c << 1146 = static_cast<const G4TwistedTrd*>(solidPtr); 1259 TetWrite(solidsElement, tetPtr); << 1147 TwistedtrdWrite(solidsElement,twistedtrdPtr); } else 1260 } << 1148 if (solidPtr->GetEntityType()=="G4TwistedTubs") 1261 else if(solidPtr->GetEntityType() == "G4Tor << 1149 { const G4TwistedTubs* const twistedtubsPtr 1262 { << 1150 = static_cast<const G4TwistedTubs*>(solidPtr); 1263 const G4Torus* const torusPtr = static_ca << 1151 TwistedtubsWrite(solidsElement,twistedtubsPtr); } 1264 TorusWrite(solidsElement, torusPtr); << 1152 else 1265 } << 1153 { 1266 else if(solidPtr->GetEntityType() == "G4Gen << 1154 G4String error_msg = "Unknown solid: " + solidPtr->GetName() 1267 { << 1155 + "; Type: " + solidPtr->GetEntityType(); 1268 const G4GenericTrap* const gtrapPtr = << 1156 G4Exception("G4GDMLWriteSolids::AddSolid()", "WriteError", 1269 static_cast<const G4GenericTrap*>(solid << 1157 FatalException, error_msg); 1270 GenTrapWrite(solidsElement, gtrapPtr); << 1158 } 1271 } << 1272 else if(solidPtr->GetEntityType() == "G4Tra << 1273 { << 1274 const G4Trap* const trapPtr = static_cast << 1275 TrapWrite(solidsElement, trapPtr); << 1276 } << 1277 else if(solidPtr->GetEntityType() == "G4Trd << 1278 { << 1279 const G4Trd* const trdPtr = static_cast<c << 1280 TrdWrite(solidsElement, trdPtr); << 1281 } << 1282 else if(solidPtr->GetEntityType() == "G4Tub << 1283 { << 1284 const G4Tubs* const tubePtr = static_cast << 1285 TubeWrite(solidsElement, tubePtr); << 1286 } << 1287 else if(solidPtr->GetEntityType() == "G4Cut << 1288 { << 1289 const G4CutTubs* const cuttubePtr = stati << 1290 CutTubeWrite(solidsElement, cuttubePtr); << 1291 } << 1292 else if(solidPtr->GetEntityType() == "G4Twi << 1293 { << 1294 const G4TwistedBox* const twistedboxPtr = << 1295 static_cast<const G4TwistedBox*>(solidP << 1296 TwistedboxWrite(solidsElement, twistedbox << 1297 } << 1298 else if(solidPtr->GetEntityType() == "G4Twi << 1299 { << 1300 const G4TwistedTrap* const twistedtrapPtr << 1301 static_cast<const G4TwistedTrap*>(solid << 1302 TwistedtrapWrite(solidsElement, twistedtr << 1303 } << 1304 else if(solidPtr->GetEntityType() == "G4Twi << 1305 { << 1306 const G4TwistedTrd* const twistedtrdPtr = << 1307 static_cast<const G4TwistedTrd*>(solidP << 1308 TwistedtrdWrite(solidsElement, twistedtrd << 1309 } << 1310 else if(solidPtr->GetEntityType() == "G4Twi << 1311 { << 1312 const G4TwistedTubs* const twistedtubsPtr << 1313 static_cast<const G4TwistedTubs*>(solid << 1314 TwistedtubsWrite(solidsElement, twistedtu << 1315 } << 1316 else << 1317 { << 1318 G4String error_msg = "Unknown solid: " + << 1319 "; Type: " + solidPt << 1320 G4Exception("G4GDMLWriteSolids::AddSolid( << 1321 error_msg); << 1322 } << 1323 } 1159 } 1324 1160