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