G4HepRepMessenger.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 #include "G4HepRepMessenger.hh"
00029 
00030 G4HepRepMessenger*
00031 G4HepRepMessenger::fpInstance = 0;
00032 
00033 G4HepRepMessenger*
00034 G4HepRepMessenger::GetInstance()
00035 {
00036         if (!fpInstance) fpInstance = new G4HepRepMessenger;
00037         return fpInstance;
00038 }
00039 
00040 G4HepRepMessenger::G4HepRepMessenger() :
00041     fileDir(""),
00042         fileName("G4Data"),
00043         overwrite(false),
00044         cullInvisibles(false),
00045         cylAsPolygons(false),
00046         scale(1.),
00047     suffix (""),
00048     geometry(true),
00049     solids(true),
00050     invisibles(true) {
00051 
00052     heprepDirectory = new G4UIdirectory("/vis/heprep/");
00053     heprepDirectory->SetGuidance("HepRep commands.");
00054                 
00055         setFileDirCommand = new G4UIcmdWithAString("/vis/heprep/setFileDir", this);
00056         setFileDirCommand->SetGuidance("Set directory for output.");
00057         setFileDirCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML.");
00058         setFileDirCommand->SetParameterName("directory",false);
00059         if ( getenv( "G4HEPREPFILE_DIR" ) == NULL ) {
00060                 setFileDirCommand->SetDefaultValue("");
00061         } else {
00062                 setFileDirCommand->SetDefaultValue(getenv("G4HEPREPFILE_DIR"));
00063                 fileDir = getenv("G4HEPREPFILE_DIR");
00064         }
00065         setFileDirCommand->AvailableForStates(G4State_Idle);
00066                 
00067         setFileNameCommand = new G4UIcmdWithAString("/vis/heprep/setFileName", this);
00068         setFileNameCommand->SetGuidance("Set file name for output.");
00069         setFileNameCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML.");
00070         setFileNameCommand->SetParameterName("directory",false);
00071         if ( getenv( "G4HEPREPFILE_NAME" ) == NULL ) {
00072                 setFileNameCommand->SetDefaultValue("G4Data");
00073         } else {
00074                 setFileNameCommand->SetDefaultValue(getenv("G4HEPREPFILE_NAME"));
00075                 fileName = getenv("G4HEPREPFILE_NAME");
00076         }
00077         setFileNameCommand->AvailableForStates(G4State_Idle);
00078 
00079         setOverwriteCommand = new G4UIcmdWithABool("/vis/heprep/setOverwrite", this);
00080         setOverwriteCommand->SetGuidance("Set true to write all output to exact same file name.");
00081         setOverwriteCommand->SetGuidance("Set false to increment the file name for each new output.");
00082         setOverwriteCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML.");
00083         setOverwriteCommand->SetParameterName("flag",false);
00084         if ( getenv( "G4HEPREPFILE_OVERWRITE" ) == NULL ) {
00085                 setOverwriteCommand->SetDefaultValue(false);
00086         } else {
00087                 setOverwriteCommand->SetDefaultValue(getenv("G4HEPREPFILE_OVERWRITE"));
00088                 overwrite = setOverwriteCommand->ConvertToBool(getenv("G4HEPREPFILE_OVERWRITE"));
00089         }
00090         setOverwriteCommand->AvailableForStates(G4State_Idle);
00091                 
00092         setCullInvisiblesCommand = new G4UIcmdWithABool("/vis/heprep/setCullInvisibles", this);
00093         setCullInvisiblesCommand->SetGuidance("Remove invisible objects from output file.");
00094         setCullInvisiblesCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML.");
00095         setCullInvisiblesCommand->SetParameterName("flag",false);
00096         if ( getenv( "G4HEPREPFILE_CULL" ) == NULL ) {
00097                 setCullInvisiblesCommand->SetDefaultValue(false);
00098         } else {
00099                 setCullInvisiblesCommand->SetDefaultValue(getenv("G4HEPREPFILE_CULL"));
00100                 cullInvisibles = setCullInvisiblesCommand->ConvertToBool(getenv("G4HEPREPFILE_CULL"));
00101         }
00102         setCullInvisiblesCommand->AvailableForStates(G4State_Idle);
00103                 
00104         renderCylAsPolygonsCommand = new G4UIcmdWithABool("/vis/heprep/renderCylAsPolygons", this);
00105         renderCylAsPolygonsCommand->SetGuidance("Render cylinders and cones as polygons.");
00106         renderCylAsPolygonsCommand->SetGuidance("This command is used by HepRepFile, not by HepRepXML.");
00107         renderCylAsPolygonsCommand->SetParameterName("flag",false);
00108         renderCylAsPolygonsCommand->SetDefaultValue(false);
00109         renderCylAsPolygonsCommand->AvailableForStates(G4State_Idle);
00110                 
00111         setScaleCommand = new G4UIcmdWithADouble("/vis/heprep/scale",this);
00112         setScaleCommand->SetGuidance("Re-Scale coordinates.");
00113         setScaleCommand->SetParameterName("Scale",true);
00114         setScaleCommand->SetDefaultValue(1.);
00115         setScaleCommand->SetRange("Scale > 0");
00116         
00117         setCenterCommand = new G4UIcmdWith3VectorAndUnit("/vis/heprep/center",this);
00118         setCenterCommand->SetGuidance("Re-Center coordinates.");
00119         setCenterCommand->SetParameterName("CenterX","CenterY","CenterZ",true);
00120         setCenterCommand->SetDefaultValue(G4ThreeVector(0.,0.,0.));
00121         setCenterCommand->SetDefaultUnit("m");
00122                 
00123     setEventNumberSuffixCommand = new G4UIcmdWithAString("/vis/heprep/setEventNumberSuffix", this);
00124     setEventNumberSuffixCommand->SetGuidance("Write separate event files, appended with given suffix.");
00125     setEventNumberSuffixCommand->SetGuidance("Define the suffix with a pattern such as '-0000'.");
00126         setEventNumberSuffixCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile.");
00127     setEventNumberSuffixCommand->SetParameterName("suffix",false);
00128     setEventNumberSuffixCommand->SetDefaultValue("");
00129     setEventNumberSuffixCommand->AvailableForStates(G4State_Idle);
00130     
00131     appendGeometryCommand = new G4UIcmdWithABool("/vis/heprep/appendGeometry", this);
00132     appendGeometryCommand->SetGuidance("Appends copy of geometry to every event.");
00133         appendGeometryCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile.");
00134     appendGeometryCommand->SetParameterName("flag",false);
00135     appendGeometryCommand->SetDefaultValue(true);
00136     appendGeometryCommand->AvailableForStates(G4State_Idle);
00137 
00138     addPointAttributesCommand = new G4UIcmdWithABool("/vis/heprep/addPointAttributes", this);
00139     addPointAttributesCommand->SetGuidance("Adds point attributes to the points of trajectories.");
00140         addPointAttributesCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile.");
00141     addPointAttributesCommand->SetParameterName("flag",false);
00142     addPointAttributesCommand->SetDefaultValue(false);
00143     addPointAttributesCommand->AvailableForStates(G4State_Idle);
00144                 
00145         useSolidsCommand = new G4UIcmdWithABool("/vis/heprep/useSolids", this);
00146         useSolidsCommand->SetGuidance("Use HepRep Solids, rather than Geant4 Primitives.");
00147         useSolidsCommand->SetGuidance("This command is used by HepRepXML, not by HepRepFile..");
00148         useSolidsCommand->SetParameterName("flag",false);
00149         useSolidsCommand->SetDefaultValue(true);
00150         useSolidsCommand->AvailableForStates(G4State_Idle);
00151 }
00152 
00153 G4HepRepMessenger::~G4HepRepMessenger() {
00154         delete setFileDirCommand;
00155         delete setFileNameCommand;
00156         delete setOverwriteCommand;
00157         delete setCullInvisiblesCommand;
00158     delete renderCylAsPolygonsCommand;
00159         delete setScaleCommand;
00160         delete setCenterCommand;
00161     delete setEventNumberSuffixCommand;
00162     delete appendGeometryCommand;
00163     delete addPointAttributesCommand;
00164     delete useSolidsCommand;
00165     delete heprepDirectory;
00166 }
00167 
00168 G4String G4HepRepMessenger::GetCurrentValue(G4UIcommand * command) {
00169     if (command==setFileDirCommand) {
00170         return fileDir;
00171     } else if (command==setFileNameCommand) {
00172         return fileName; 
00173     } else if (command==setOverwriteCommand) {
00174         return overwrite; 
00175     } else if (command==setCullInvisiblesCommand) {
00176         return cullInvisibles; 
00177     } else if (command==renderCylAsPolygonsCommand) {
00178         return renderCylAsPolygonsCommand->ConvertToString(cylAsPolygons);
00179     } else if (command==setScaleCommand) {
00180         return setScaleCommand->ConvertToString(scale);
00181     } else if (command==setCenterCommand) {
00182         return setCenterCommand->ConvertToString(center,"m");
00183     } else if (command==setEventNumberSuffixCommand) {
00184         return suffix; 
00185     } else if (command==appendGeometryCommand) {
00186         return appendGeometryCommand->ConvertToString(geometry); 
00187     } else if (command==addPointAttributesCommand) {
00188         return addPointAttributesCommand->ConvertToString(pointAttributes); 
00189     } else if (command==useSolidsCommand) {
00190         return useSolidsCommand->ConvertToString(solids);
00191     } else {
00192         return "";
00193     }
00194 }
00195 
00196 void G4HepRepMessenger::SetNewValue(G4UIcommand * command, G4String newValue) {
00197     if (command==setFileDirCommand) {
00198         fileDir = newValue;
00199     } else if (command==setFileNameCommand) {
00200         fileName = newValue;
00201     } else if (command==setOverwriteCommand) {
00202         overwrite = setOverwriteCommand->GetNewBoolValue(newValue);
00203     } else if (command==setCullInvisiblesCommand) {
00204                 cullInvisibles = setCullInvisiblesCommand->GetNewBoolValue(newValue);
00205     } else if (command==renderCylAsPolygonsCommand) {
00206         cylAsPolygons = renderCylAsPolygonsCommand->GetNewBoolValue(newValue);
00207     } else if (command==setScaleCommand) {
00208         scale = setScaleCommand->GetNewDoubleValue(newValue);
00209     } else if (command==setCenterCommand) {
00210         center = setCenterCommand->GetNew3VectorValue(newValue);
00211     } else if (command==setEventNumberSuffixCommand) {
00212         suffix = newValue;
00213     } else if (command==appendGeometryCommand) {
00214         geometry = appendGeometryCommand->GetNewBoolValue(newValue);
00215     } else if (command==addPointAttributesCommand) {
00216         pointAttributes = addPointAttributesCommand->GetNewBoolValue(newValue);
00217     } else if (command==useSolidsCommand) {
00218         solids = useSolidsCommand->GetNewBoolValue(newValue);
00219     } 
00220 }
00221 
00222 G4String G4HepRepMessenger::getFileDir() {
00223     return fileDir;
00224 }
00225 
00226 G4String G4HepRepMessenger::getFileName() {
00227     return fileName;
00228 }
00229 
00230 G4bool G4HepRepMessenger::getOverwrite() {
00231     return overwrite;
00232 }
00233 
00234 G4bool G4HepRepMessenger::getCullInvisibles() {
00235     return cullInvisibles;
00236 }
00237 
00238 G4bool G4HepRepMessenger::renderCylAsPolygons() {
00239     return cylAsPolygons;
00240 }
00241 
00242 G4double G4HepRepMessenger::getScale() {
00243     return scale;
00244 }
00245 
00246 G4ThreeVector G4HepRepMessenger::getCenter() {
00247     return center;
00248 }
00249 
00250 G4String G4HepRepMessenger::getEventNumberSuffix() {
00251     return suffix;
00252 }
00253 
00254 G4bool G4HepRepMessenger::appendGeometry() {
00255     return geometry;
00256 }
00257 
00258 G4bool G4HepRepMessenger::addPointAttributes() {
00259     return pointAttributes;
00260 }
00261 
00262 G4bool G4HepRepMessenger::useSolids() {
00263     return solids;
00264 }
00265 
00266 G4bool G4HepRepMessenger::writeInvisibles() {
00267     return invisibles;
00268 }
00269 

Generated on Mon May 27 17:48:30 2013 for Geant4 by  doxygen 1.4.7