Geant4 Cross Reference |
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 #include "G4HepRepMessenger.hh" 28 29 G4HepRepMessenger* G4HepRepMessenger::fpInstance = 0; 30 31 G4HepRepMessenger* G4HepRepMessenger::GetInstance() 32 { 33 if(!fpInstance) 34 fpInstance = new G4HepRepMessenger; 35 return fpInstance; 36 } 37 38 G4HepRepMessenger::G4HepRepMessenger() 39 : fileDir("") 40 , fileName("G4Data") 41 , overwrite(false) 42 , cullInvisibles(false) 43 , cylAsPolygons(false) 44 , scale(1.) 45 , suffix("") 46 , geometry(true) 47 , pointAttributes(false) 48 , solids(true) 49 , invisibles(true) 50 { 51 heprepDirectory = new G4UIdirectory("/vis/heprep/"); 52 heprepDirectory->SetGuidance("HepRep commands."); 53 54 setFileDirCommand = new G4UIcmdWithAString("/vis/heprep/setFileDir", this); 55 setFileDirCommand->SetGuidance("Set directory for output."); 56 setFileDirCommand->SetGuidance( 57 "This command is used by HepRepFile, not by HepRepXML."); 58 setFileDirCommand->SetParameterName("directory", false); 59 if(std::getenv("G4HEPREPFILE_DIR") == NULL) 60 { 61 setFileDirCommand->SetDefaultValue(""); 62 } 63 else 64 { 65 setFileDirCommand->SetDefaultValue(std::getenv("G4HEPREPFILE_DIR")); 66 fileDir = std::getenv("G4HEPREPFILE_DIR"); 67 } 68 setFileDirCommand->AvailableForStates(G4State_Idle); 69 70 setFileNameCommand = new G4UIcmdWithAString("/vis/heprep/setFileName", this); 71 setFileNameCommand->SetGuidance("Set file name for output."); 72 setFileNameCommand->SetGuidance( 73 "This command is used by HepRepFile, not by HepRepXML."); 74 setFileNameCommand->SetParameterName("directory", false); 75 if(std::getenv("G4HEPREPFILE_NAME") == NULL) 76 { 77 setFileNameCommand->SetDefaultValue("G4Data"); 78 } 79 else 80 { 81 setFileNameCommand->SetDefaultValue(std::getenv("G4HEPREPFILE_NAME")); 82 fileName = std::getenv("G4HEPREPFILE_NAME"); 83 } 84 setFileNameCommand->AvailableForStates(G4State_Idle); 85 86 setOverwriteCommand = new G4UIcmdWithABool("/vis/heprep/setOverwrite", this); 87 setOverwriteCommand->SetGuidance( 88 "Set true to write all output to exact same file name."); 89 setOverwriteCommand->SetGuidance( 90 "Set false to increment the file name for each new output."); 91 setOverwriteCommand->SetGuidance( 92 "This command is used by HepRepFile, not by HepRepXML."); 93 setOverwriteCommand->SetParameterName("flag", false); 94 if(std::getenv("G4HEPREPFILE_OVERWRITE") == NULL) 95 { 96 setOverwriteCommand->SetDefaultValue(false); 97 } 98 else 99 { 100 setOverwriteCommand->SetDefaultValue(std::getenv("G4HEPREPFILE_OVERWRITE")); 101 overwrite = 102 setOverwriteCommand->ConvertToBool(std::getenv("G4HEPREPFILE_OVERWRITE")); 103 } 104 setOverwriteCommand->AvailableForStates(G4State_Idle); 105 106 setCullInvisiblesCommand = 107 new G4UIcmdWithABool("/vis/heprep/setCullInvisibles", this); 108 setCullInvisiblesCommand->SetGuidance( 109 "Remove invisible objects from output file."); 110 setCullInvisiblesCommand->SetGuidance( 111 "This command is used by HepRepFile, not by HepRepXML."); 112 setCullInvisiblesCommand->SetParameterName("flag", false); 113 if(std::getenv("G4HEPREPFILE_CULL") == NULL) 114 { 115 setCullInvisiblesCommand->SetDefaultValue(false); 116 } 117 else 118 { 119 setCullInvisiblesCommand->SetDefaultValue(std::getenv("G4HEPREPFILE_CULL")); 120 cullInvisibles = 121 setCullInvisiblesCommand->ConvertToBool(std::getenv("G4HEPREPFILE_CULL")); 122 } 123 setCullInvisiblesCommand->AvailableForStates(G4State_Idle); 124 125 renderCylAsPolygonsCommand = 126 new G4UIcmdWithABool("/vis/heprep/renderCylAsPolygons", this); 127 renderCylAsPolygonsCommand->SetGuidance( 128 "Render cylinders and cones as polygons."); 129 renderCylAsPolygonsCommand->SetGuidance( 130 "This command is used by HepRepFile, not by HepRepXML."); 131 renderCylAsPolygonsCommand->SetParameterName("flag", false); 132 renderCylAsPolygonsCommand->SetDefaultValue(false); 133 renderCylAsPolygonsCommand->AvailableForStates(G4State_Idle); 134 135 setScaleCommand = new G4UIcmdWithADouble("/vis/heprep/scale", this); 136 setScaleCommand->SetGuidance("Re-Scale coordinates."); 137 setScaleCommand->SetParameterName("Scale", true); 138 setScaleCommand->SetDefaultValue(1.); 139 setScaleCommand->SetRange("Scale > 0"); 140 141 setCenterCommand = new G4UIcmdWith3VectorAndUnit("/vis/heprep/center", this); 142 setCenterCommand->SetGuidance("Re-Center coordinates."); 143 setCenterCommand->SetParameterName("CenterX", "CenterY", "CenterZ", true); 144 setCenterCommand->SetDefaultValue(G4ThreeVector(0., 0., 0.)); 145 setCenterCommand->SetDefaultUnit("m"); 146 147 setEventNumberSuffixCommand = 148 new G4UIcmdWithAString("/vis/heprep/setEventNumberSuffix", this); 149 setEventNumberSuffixCommand->SetGuidance( 150 "Write separate event files, appended with given suffix."); 151 setEventNumberSuffixCommand->SetGuidance( 152 "Define the suffix with a pattern such as '-0000'."); 153 setEventNumberSuffixCommand->SetGuidance( 154 "This command is used by HepRepXML, not by HepRepFile."); 155 setEventNumberSuffixCommand->SetParameterName("suffix", false); 156 setEventNumberSuffixCommand->SetDefaultValue(""); 157 setEventNumberSuffixCommand->AvailableForStates(G4State_Idle); 158 159 appendGeometryCommand = 160 new G4UIcmdWithABool("/vis/heprep/appendGeometry", this); 161 appendGeometryCommand->SetGuidance( 162 "Appends copy of geometry to every event."); 163 appendGeometryCommand->SetGuidance( 164 "This command is used by HepRepXML, not by HepRepFile."); 165 appendGeometryCommand->SetParameterName("flag", false); 166 appendGeometryCommand->SetDefaultValue(true); 167 appendGeometryCommand->AvailableForStates(G4State_Idle); 168 169 addPointAttributesCommand = 170 new G4UIcmdWithABool("/vis/heprep/addPointAttributes", this); 171 addPointAttributesCommand->SetGuidance( 172 "Adds point attributes to the points of trajectories."); 173 addPointAttributesCommand->SetGuidance( 174 "This command is used by HepRepXML, not by HepRepFile."); 175 addPointAttributesCommand->SetParameterName("flag", false); 176 addPointAttributesCommand->SetDefaultValue(false); 177 addPointAttributesCommand->AvailableForStates(G4State_Idle); 178 179 useSolidsCommand = new G4UIcmdWithABool("/vis/heprep/useSolids", this); 180 useSolidsCommand->SetGuidance( 181 "Use HepRep Solids, rather than Geant4 Primitives."); 182 useSolidsCommand->SetGuidance( 183 "This command is used by HepRepXML, not by HepRepFile.."); 184 useSolidsCommand->SetParameterName("flag", false); 185 useSolidsCommand->SetDefaultValue(true); 186 useSolidsCommand->AvailableForStates(G4State_Idle); 187 } 188 189 G4HepRepMessenger::~G4HepRepMessenger() 190 { 191 delete setFileDirCommand; 192 delete setFileNameCommand; 193 delete setOverwriteCommand; 194 delete setCullInvisiblesCommand; 195 delete renderCylAsPolygonsCommand; 196 delete setScaleCommand; 197 delete setCenterCommand; 198 delete setEventNumberSuffixCommand; 199 delete appendGeometryCommand; 200 delete addPointAttributesCommand; 201 delete useSolidsCommand; 202 delete heprepDirectory; 203 } 204 205 G4String G4HepRepMessenger::GetCurrentValue(G4UIcommand* command) 206 { 207 if(command == setFileDirCommand) 208 { 209 return fileDir; 210 } 211 else if(command == setFileNameCommand) 212 { 213 return fileName; 214 } 215 else if(command == setOverwriteCommand) 216 { 217 return G4UIcommand::ConvertToString(overwrite); 218 } 219 else if(command == setCullInvisiblesCommand) 220 { 221 return G4UIcommand::ConvertToString(cullInvisibles); 222 } 223 else if(command == renderCylAsPolygonsCommand) 224 { 225 return renderCylAsPolygonsCommand->ConvertToString(cylAsPolygons); 226 } 227 else if(command == setScaleCommand) 228 { 229 return setScaleCommand->ConvertToString(scale); 230 } 231 else if(command == setCenterCommand) 232 { 233 return setCenterCommand->ConvertToString(center, "m"); 234 } 235 else if(command == setEventNumberSuffixCommand) 236 { 237 return suffix; 238 } 239 else if(command == appendGeometryCommand) 240 { 241 return appendGeometryCommand->ConvertToString(geometry); 242 } 243 else if(command == addPointAttributesCommand) 244 { 245 return addPointAttributesCommand->ConvertToString(pointAttributes); 246 } 247 else if(command == useSolidsCommand) 248 { 249 return useSolidsCommand->ConvertToString(solids); 250 } 251 else 252 { 253 return ""; 254 } 255 } 256 257 void G4HepRepMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 258 { 259 if(command == setFileDirCommand) 260 { 261 fileDir = newValue; 262 } 263 else if(command == setFileNameCommand) 264 { 265 fileName = newValue; 266 } 267 else if(command == setOverwriteCommand) 268 { 269 overwrite = setOverwriteCommand->GetNewBoolValue(newValue); 270 } 271 else if(command == setCullInvisiblesCommand) 272 { 273 cullInvisibles = setCullInvisiblesCommand->GetNewBoolValue(newValue); 274 } 275 else if(command == renderCylAsPolygonsCommand) 276 { 277 cylAsPolygons = renderCylAsPolygonsCommand->GetNewBoolValue(newValue); 278 } 279 else if(command == setScaleCommand) 280 { 281 scale = setScaleCommand->GetNewDoubleValue(newValue); 282 } 283 else if(command == setCenterCommand) 284 { 285 center = setCenterCommand->GetNew3VectorValue(newValue); 286 } 287 else if(command == setEventNumberSuffixCommand) 288 { 289 suffix = newValue; 290 } 291 else if(command == appendGeometryCommand) 292 { 293 geometry = appendGeometryCommand->GetNewBoolValue(newValue); 294 } 295 else if(command == addPointAttributesCommand) 296 { 297 pointAttributes = addPointAttributesCommand->GetNewBoolValue(newValue); 298 } 299 else if(command == useSolidsCommand) 300 { 301 solids = useSolidsCommand->GetNewBoolValue(newValue); 302 } 303 } 304 305 G4String G4HepRepMessenger::getFileDir() { return fileDir; } 306 307 G4String G4HepRepMessenger::getFileName() { return fileName; } 308 309 G4bool G4HepRepMessenger::getOverwrite() { return overwrite; } 310 311 G4bool G4HepRepMessenger::getCullInvisibles() { return cullInvisibles; } 312 313 G4bool G4HepRepMessenger::renderCylAsPolygons() { return cylAsPolygons; } 314 315 G4double G4HepRepMessenger::getScale() { return scale; } 316 317 G4ThreeVector G4HepRepMessenger::getCenter() { return center; } 318 319 G4String G4HepRepMessenger::getEventNumberSuffix() { return suffix; } 320 321 G4bool G4HepRepMessenger::appendGeometry() { return geometry; } 322 323 G4bool G4HepRepMessenger::addPointAttributes() { return pointAttributes; } 324 325 G4bool G4HepRepMessenger::useSolids() { return solids; } 326 327 G4bool G4HepRepMessenger::writeInvisibles() { return invisibles; } 328