20#include "BDSException.hh"
21#include "BDSGeometryWriter.hh"
22#include "BDSUtilities.hh"
28#include "G4GDMLAuxStructType.hh"
29#include "G4GDMLParser.hh"
30#include "G4VisAttributes.hh"
33#include "G4FileUtilities.hh"
35#include "G4TransportationManager.hh"
41class G4VPhysicalVolume;
46BDSGeometryWriter::~BDSGeometryWriter()
49BDSGeometryWriter::BDSGeometryWriter()
53 const G4String& geometryFileName)
55 if (geometryType ==
"gdml")
60 throw BDSException(__METHOD_NAME__,
"Unable to write out " + geometryFileName +
", as compiled without GDML support");
64 {
throw BDSException(__METHOD_NAME__,
"unknown geometry export type \"" + geometryType +
"\".");}
69 G4VPhysicalVolume* volume)
72 {volume = G4TransportationManager::GetTransportationManager()->GetNavigatorForTracking()->GetWorldVolume();}
76 G4FileUtilities fileUtilities;
77 G4cout <<
"Removing existing file: \"" << outputFileName <<
"\"" << G4endl;
78 fileUtilities.DeleteFile(outputFileName,
"");
87 {
throw BDSException(__METHOD_NAME__,
"directory \"" + dirName +
"\" does not exist - please create it first.");}
94 parser.Write(outputFileName, volume,
true);
98 const G4Colour& colour)
100 std::array<G4double, 4> numbers = {colour.GetRed(),
104 std::stringstream ss;
105 ss << visible <<
" ";
106 for (
auto cv : numbers)
107 {ss << std::setprecision(4) << cv <<
" ";}
108 G4String result = ss.str();
115 std::map<G4LogicalVolume*, G4GDMLAuxStructType> result;
116 auto lv = volume->GetLogicalVolume();
122 const std::map<G4LogicalVolume*, G4GDMLAuxStructType>& volToAuxMap)
124 for (
const auto& lvAux : volToAuxMap)
125 {parser.AddVolumeAuxiliary(lvAux.second, lvAux.first);}
130 const G4VisAttributes* visAttr = lv->GetVisAttributes();
133 G4GDMLAuxStructType c;
139 for (std::size_t i = 0; i < lv->GetNoDaughters(); i++)
141 auto dlv = lv->GetDaughter(i)->GetLogicalVolume();
General exception with possible name of object and message.
void WriteToGDML(const G4String &outputFileName, G4VPhysicalVolume *volume=nullptr)
static std::map< G4LogicalVolume *, G4GDMLAuxStructType > PrepareColourInformation(G4VPhysicalVolume *volume)
static const G4String auxType
"bds_vrgba" - short to minimise output file size: "bdsim visibility rgba"
static void AddLVColour(std::map< G4LogicalVolume *, G4GDMLAuxStructType > &, G4LogicalVolume *lv)
static G4String ColourToVRGBAString(G4bool visible, const G4Colour &colour)
static void RegisterVolumeAuxiliaryInformation(G4GDMLParser &parser, const std::map< G4LogicalVolume *, G4GDMLAuxStructType > &volToAuxMap)
Register the auxiliary information with the GDML parser (writer).
void ExportGeometry(const G4String &geometryType, const G4String &geometryFileName)
G4bool StrContains(const G4String &str, const G4String &test)
Utility function to simplify lots of syntax changes for pedantic g4 changes.
G4String GetFullPath(G4String filename, bool excludeNameFromPath=false, bool useCWDForPrefix=false)
G4bool DirectoryExists(const G4String &path)
Check if directory exists.
G4bool FileExists(const G4String &filename)
Checks if filename exists.