G4UImanager.hh

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 //
00027 // $Id$
00028 //
00029 
00030 #ifndef G4UImanager_h
00031 #define G4UImanager_h 1
00032 
00033 #include "globals.hh"
00034 
00035 #include <vector>
00036 #include <fstream>
00037 #include "G4VStateDependent.hh"
00038 #include "G4UIcommandStatus.hh"
00039 class G4UIcommandTree;
00040 class G4UIcommand;
00041 class G4UIsession;
00042 class G4UIcontrolMessenger;
00043 class G4UnitsMessenger;
00044 class G4UIaliasList;
00045 
00046 // class description:
00047 //
00048 //  This is a singlton class which controls the command manipulation
00049 // and the user interface(s). The constructor of this class MUST NOT
00050 // invoked by the user.
00051 //
00052 
00053 class G4UImanager : public G4VStateDependent
00054 {
00055   public: // with description
00056       static G4UImanager * GetUIpointer();
00057       //  A static method to get the pointer to the only existing object
00058       // of this class.
00059 
00060   protected:
00061       G4UImanager();
00062   public:
00063       ~G4UImanager();
00064   private:
00065       G4UImanager(const G4UImanager &right);
00066       const G4UImanager & operator=(const G4UImanager &right);
00067       G4int operator==(const G4UImanager &right) const;
00068       G4int operator!=(const G4UImanager &right) const;
00069 
00070   public: // with description
00071       G4String GetCurrentValues(const char * aCommand);
00072       //  This method returns a string which represents the current value(s)
00073       // of the parameter(s) of the specified command. Null string will be
00074       // returned if the given command is not defined or the command does
00075       // not support the GetCurrentValues() method.
00076       void AddNewCommand(G4UIcommand * newCommand);
00077       //  This method register a new command.
00078       void RemoveCommand(G4UIcommand * aCommand);
00079       //  This command remove the registered command. After invokation of this
00080       // command, that particular command cannot be applied.
00081       void ExecuteMacroFile(const char * fileName);
00082       //  A macro file defined by the argument will be read by G4UIbatch object.
00083       void Loop(const char * macroFile,const char * variableName,
00084                    G4double initialValue,G4double finalValue,G4double stepSize=1.0);
00085       // Execute a macro file more than once with a loop counter.
00086       void Foreach(const char * macroFile,const char * variableName,
00087                                                         const char * candidates);
00088       // Execute a macro file more than once with an aliased variable which takes
00089       // a value in the candidate list.
00090       G4int ApplyCommand(const char * aCommand);
00091       G4int ApplyCommand(const G4String& aCommand);
00092       //  A command (and parameter(s)) given
00093       // by the method's argument will be applied. Zero will be returned in
00094       // case the command is successfully executed. Positive non-zero value
00095       // will be returned if the command couldn't be executed. The meaning of
00096       // this non-zero value is the following.
00097       //   The returned number : xyy
00098       //        x00 : G4CommandStatus.hh enumeration
00099       //         yy : the problematic parameter (first found)
00100       void StoreHistory(const char* fileName = "G4history.macro");
00101       void StoreHistory(G4bool historySwitch,
00102                         const char* fileName = "G4history.macro");
00103       //  The executed commands will be stored in the defined file. If
00104       // "historySwitch" is false, saving will be suspended.
00105       void ListCommands(const char* direc);
00106       //  All commands registored under the given directory will be listed to
00107       // G4cout.
00108       void SetAlias(const char * aliasLine);
00109       //  Define an alias. The first word of "aliasLine" string is the
00110       // alias name and the remaining word(s) is(are) string value
00111       // to be aliased.
00112       void RemoveAlias(const char * aliasName);
00113       //  Remove the defined alias.
00114       void ListAlias();
00115       //  Print all aliases.
00116       G4String SolveAlias(const char* aCmd);
00117       //  Convert a command string which contains alias(es).
00118       void CreateHTML(const char* dir = "/");
00119       //  Generate HTML files for defined UI commands
00120 
00121 
00122   public:
00123       void LoopS(const char* valueList);
00124       void ForeachS(const char* valueList);
00125       //  These methods are used by G4UIcontrolMessenger to use Loop() and Foreach() methods.
00126       virtual G4bool Notify(G4ApplicationState requestedState);
00127       //  This method is exclusively invoked by G4StateManager and the user
00128       // must not use this method.
00129 
00130   private:
00131       void PauseSession(const char* msg);
00132       void CreateMessenger();
00133       G4UIcommandTree* FindDirectory(const char* dirName);
00134 
00135   //public:
00136   // following three methods will be removed quite soon.
00137   //    void Interact();
00138   //    void Interact(const char * promptCharacters);
00139 
00140   private:
00141       static G4UImanager * fUImanager;
00142       static G4bool fUImanagerHasBeenKilled;
00143       G4UIcommandTree * treeTop;
00144       G4UIsession * session;
00145       G4UIsession * g4UIWindow;
00146       G4UIcontrolMessenger * UImessenger;
00147       G4UnitsMessenger * UnitsMessenger;
00148       G4String savedParameters;
00149       G4UIcommand * savedCommand;
00150       G4int verboseLevel;
00151       std::ofstream historyFile;
00152       G4bool saveHistory;
00153       std::vector<G4String> histVec;
00154       G4UIaliasList* aliasList;
00155       G4int maxHistSize;
00156       G4bool pauseAtBeginOfEvent;
00157       G4bool pauseAtEndOfEvent;
00158       G4String searchPath;
00159       std::vector<G4String> searchDirs;
00160 
00161   public: // with description
00162       G4String GetCurrentStringValue(const char * aCommand,
00163       G4int parameterNumber=1, G4bool reGet=true);
00164       G4int GetCurrentIntValue(const char * aCommand,
00165       G4int parameterNumber=1, G4bool reGet=true);
00166       G4double GetCurrentDoubleValue(const char * aCommand,
00167       G4int parameterNumber=1, G4bool reGet=true);
00168       G4String GetCurrentStringValue(const char * aCommand,
00169       const char * aParameterName, G4bool reGet=true);
00170       G4int GetCurrentIntValue(const char * aCommand,
00171       const char * aParameterName, G4bool reGet=true);
00172       G4double GetCurrentDoubleValue(const char * aCommand,
00173       const char * aParameterName, G4bool reGet=true);
00174       //  These six methods returns the current value of a parameter of the
00175       // given command. For the first three methods, the ordering number of
00176       // the parameter (1 is the first parameter) can be given, whereas,
00177       // other three methods can give the parameter name.
00178       //  If "reGet" is true, actual request of returning the current value
00179       // will be sent to the corresponding messenger, while, if it is false,
00180       // the value stored in G4Umanager will be used. The later case is valid
00181       // for the sequential invokation for the same command.
00182 
00183       inline void SetPauseAtBeginOfEvent(G4bool vl)
00184       { pauseAtBeginOfEvent = vl; }
00185       inline G4bool GetPauseAtBeginOfEvent() const
00186       { return pauseAtBeginOfEvent; }
00187       inline void SetPauseAtEndOfEvent(G4bool vl)
00188       { pauseAtEndOfEvent = vl; }
00189       inline G4bool GetPauseAtEndOfEvent() const
00190       { return pauseAtEndOfEvent; }
00191       //  If the boolean flags are true, Pause() method of G4StateManager is invoked
00192       // at the very begining (before generating a G4Event object) or at the end of
00193       // each event. So that, in case a (G)UI session is defined, the user can interact.
00194 
00195 
00196   public:
00197       inline G4UIcommandTree * GetTree() const
00198       { return treeTop; }
00199       inline G4UIsession * GetSession() const
00200       { return session; }
00201       inline G4UIsession * GetG4UIWindow() const
00202       { return g4UIWindow; }
00203   public: // with description
00204       inline void SetSession(G4UIsession *const value)
00205       { session = value; }
00206       inline void SetG4UIWindow(G4UIsession *const value)
00207       { g4UIWindow = value; }
00208       //  This method defines the active (G)UI session.
00209      void SetCoutDestination(G4UIsession *const value);
00210      //  This method defines the destination of G4cout/G4cerr stream.
00211      // For usual cases, this method will be invoked by a concrete
00212      // (G)UI session class object and thus the user needs not to invoke
00213      // this method by him(her)self.
00214 
00215   public:
00216       inline void SetVerboseLevel(G4int val)
00217       { verboseLevel = val; }
00218       inline G4int GetVerboseLevel() const
00219       { return verboseLevel; }
00220       inline G4int GetNumberOfHistory() const
00221       { return histVec.size(); }
00222       inline G4String GetPreviousCommand(G4int i) const
00223       {
00224         G4String st;
00225         if(i>=0 && i<G4int(histVec.size()))
00226         { st = histVec[i]; }
00227         return st;
00228       }
00229       inline void SetMaxHistSize(G4int mx)
00230       { maxHistSize = mx; }
00231       inline G4int GetMaxHistSize() const
00232       { return maxHistSize; }
00233 
00234       inline void SetMacroSearchPath(const G4String& path)
00235       { searchPath = path; }
00236       inline const G4String& GetMacroSearchPath() const
00237       { return searchPath; }
00238       void ParseMacroSearchPath();
00239       G4String FindMacroPath(const G4String& fname) const;
00240 
00241   // Old methods kept for backward compatibility
00242   //    inline G4UIcommandTree * GetTree() const
00243   //    { return treeTop; };
00244   //    inline G4UIsession * GetSession() const
00245   //    { return session; };
00246   //    inline void SetSession(G4UIsession *const  value)
00247   //    { session = value; };
00248 
00249 };
00250 
00251 #endif

Generated on Mon May 27 17:50:06 2013 for Geant4 by  doxygen 1.4.7