Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4GDMLMessenger.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4GDMLMessenger.cc 96673 2016-04-29 12:08:20Z gcosmo $
28 //
29 //
30 // class G4GDMLMessenger Implementation
31 //
32 // -------------------------------------------------------------------------
33 
34 #include "G4GDMLMessenger.hh"
35 #include "G4GDMLParser.hh"
36 
37 #include "globals.hh"
38 #include "G4RunManager.hh"
39 #include "G4UIdirectory.hh"
40 #include "G4UIcmdWithAString.hh"
41 #include "G4UIcmdWithABool.hh"
43 #include "G4GeometryManager.hh"
44 #include "G4LogicalVolumeStore.hh"
45 #include "G4PhysicalVolumeStore.hh"
46 #include "G4SolidStore.hh"
47 
49  : myParser(myPars), topvol(0)
50 {
51  persistencyDir = new G4UIdirectory("/persistency/");
52  persistencyDir->SetGuidance("UI commands specific to persistency.");
53 
54  gdmlDir = new G4UIdirectory("/persistency/gdml/");
55  gdmlDir->SetGuidance("GDML parser and writer.");
56 
57  ReaderCmd = new G4UIcmdWithAString("/persistency/gdml/read",this);
58  ReaderCmd->SetGuidance("Read GDML file.");
59  ReaderCmd->SetParameterName("filename",false);
61 
62  TopVolCmd = new G4UIcmdWithAString("/persistency/gdml/topvol",this);
63  TopVolCmd->SetGuidance("Set the top volume for writing the GDML file.");
64  TopVolCmd->SetParameterName("topvol",false);
65 
66  WriterCmd = new G4UIcmdWithAString("/persistency/gdml/write",this);
67  WriterCmd->SetGuidance("Write GDML file.");
68  WriterCmd->SetParameterName("filename",false);
69  WriterCmd->AvailableForStates(G4State_Idle);
70 
71  RegionCmd = new G4UIcmdWithABool("/persistency/gdml/export_regions",this);
72  RegionCmd->SetGuidance("Enable export of geometrical regions");
73  RegionCmd->SetGuidance("for storing production cuts.");
74  RegionCmd->SetParameterName("export_regions",false);
75  RegionCmd->SetDefaultValue(false);
76  RegionCmd->AvailableForStates(G4State_Idle);
77 
78  EcutsCmd = new G4UIcmdWithABool("/persistency/gdml/export_Ecuts",this);
79  EcutsCmd->SetGuidance("Enable export of energy cuts associated");
80  EcutsCmd->SetGuidance("to logical volumes.");
81  EcutsCmd->SetGuidance("NOTE: may increase considerably the size of the");
82  EcutsCmd->SetGuidance(" GDML file! Information is anyhow not used");
83  EcutsCmd->SetGuidance(" for import.");
84  EcutsCmd->SetParameterName("export_Ecuts",false);
85  EcutsCmd->SetDefaultValue(false);
87 
88  SDCmd = new G4UIcmdWithABool("/persistency/gdml/export_SD",this);
89  SDCmd->SetGuidance("Enable export of SD associated");
90  SDCmd->SetGuidance("to logical volumes.");
91  SDCmd->SetParameterName("export_SD",false);
92  SDCmd->SetDefaultValue(false);
94 
95  ClearCmd = new G4UIcmdWithoutParameter("/persistency/gdml/clear",this);
96  ClearCmd->SetGuidance("Clear geometry (before reading a new one from GDML).");
98 }
99 
101 {
102  delete ReaderCmd;
103  delete WriterCmd;
104  delete ClearCmd;
105  delete TopVolCmd;
106  delete RegionCmd;
107  delete EcutsCmd;
108  delete SDCmd;
109  delete persistencyDir;
110  delete gdmlDir;
111 }
112 
114 {
115  if( command == ReaderCmd )
116  {
118  myParser->Read(newValue);
120  }
121 
122  if( command == RegionCmd )
123  {
124  G4bool mode = RegionCmd->GetNewBoolValue(newValue);
125  myParser->SetRegionExport(mode);
126  }
127 
128  if( command == EcutsCmd )
129  {
130  G4bool mode = EcutsCmd->GetNewBoolValue(newValue);
131  myParser->SetEnergyCutsExport(mode);
132  }
133 
134  if( command == SDCmd )
135  {
136  G4bool mode = SDCmd->GetNewBoolValue(newValue);
137  myParser->SetSDExport(mode);
138  }
139 
140  if( command == TopVolCmd )
141  {
142  topvol = G4LogicalVolumeStore::GetInstance()->GetVolume(newValue);
143  }
144 
145  if( command == WriterCmd )
146  {
147  myParser->Write(newValue, topvol);
148  }
149 
150  if( command == ClearCmd )
151  {
152  myParser->Clear();
154  }
155 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetNewValue(G4UIcommand *, G4String)
G4VPhysicalVolume * GetWorldVolume(const G4String &setupName="Default") const
void SetRegionExport(G4bool)
static G4bool GetNewBoolValue(const char *paramString)
G4LogicalVolume * GetVolume(const G4String &name, G4bool verbose=true) const
virtual void DefineWorldVolume(G4VPhysicalVolume *worldVol, G4bool topologyIsChanged=true)
void SetDefaultValue(G4bool defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4GDMLMessenger(G4GDMLParser *)
bool G4bool
Definition: G4Types.hh:79
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static G4LogicalVolumeStore * GetInstance()
void Write(const G4String &filename, const G4VPhysicalVolume *pvol=0, G4bool storeReferences=true, const G4String &SchemaLocation=G4GDML_DEFAULT_SCHEMALOCATION)
void AvailableForStates(G4ApplicationState s1)
Definition: G4UIcommand.cc:240
void SetSDExport(G4bool)
static G4GeometryManager * GetInstance()
void ReinitializeGeometry(G4bool destroyFirst=false, G4bool prop=true)
void SetEnergyCutsExport(G4bool)
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
void Read(const G4String &filename, G4bool Validate=true)
void OpenGeometry(G4VPhysicalVolume *vol=0)