Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4UImanager.hh
이 파일의 문서화 페이지로 가기
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: G4UImanager.hh 110270 2018-05-17 14:38:26Z gcosmo $
28 //
29 
30 #ifndef G4UImanager_h
31 #define G4UImanager_h 1
32 
33 #include "globals.hh"
34 
35 #include <vector>
36 #include <fstream>
37 #include "icomsdefs.hh"
38 #include "G4VStateDependent.hh"
39 #include "G4UIcommandStatus.hh"
40 
41 class G4UIcommandTree;
42 class G4UIcommand;
43 class G4UIsession;
45 class G4UnitsMessenger;
47 class G4UIaliasList;
49 class G4UIbridge;
50 
51 // class description:
52 //
53 // This is a singlton class which controls the command manipulation
54 // and the user interface(s). The constructor of this class MUST NOT
55 // invoked by the user.
56 //
57 
59 {
60  public: // with description
61  static G4UImanager * GetUIpointer();
63  // A static method to get the pointer to the only existing object
64  // of this class.
65 
66  protected:
67  G4UImanager();
68  public:
69  ~G4UImanager();
70  private:
72  const G4UImanager & operator=(const G4UImanager &right);
73  G4int operator==(const G4UImanager &right) const;
74  G4int operator!=(const G4UImanager &right) const;
75 
76  public: // with description
77  G4String GetCurrentValues(const char * aCommand);
78  // This method returns a string which represents the current value(s)
79  // of the parameter(s) of the specified command. Null string will be
80  // returned if the given command is not defined or the command does
81  // not support the GetCurrentValues() method.
82  void AddNewCommand(G4UIcommand * newCommand);
83  // This method register a new command.
84  void RemoveCommand(G4UIcommand * aCommand);
85  // This command remove the registered command. After invokation of this
86  // command, that particular command cannot be applied.
87  void ExecuteMacroFile(const char * fileName);
88  // A macro file defined by the argument will be read by G4UIbatch object.
89  void Loop(const char * macroFile,const char * variableName,
90  G4double initialValue,G4double finalValue,G4double stepSize=1.0);
91  // Execute a macro file more than once with a loop counter.
92  void Foreach(const char * macroFile,const char * variableName,
93  const char * candidates);
94  // Execute a macro file more than once with an aliased variable which takes
95  // a value in the candidate list.
96  G4int ApplyCommand(const char * aCommand);
97  G4int ApplyCommand(const G4String& aCommand);
98  // A command (and parameter(s)) given
99  // by the method's argument will be applied. Zero will be returned in
100  // case the command is successfully executed. Positive non-zero value
101  // will be returned if the command couldn't be executed. The meaning of
102  // this non-zero value is the following.
103  // The returned number : xyy
104  // x00 : G4CommandStatus.hh enumeration
105  // yy : the problematic parameter (first found)
106  void StoreHistory(const char* fileName = "G4history.macro");
107  void StoreHistory(G4bool historySwitch,
108  const char* fileName = "G4history.macro");
109  // The executed commands will be stored in the defined file. If
110  // "historySwitch" is false, saving will be suspended.
111  void ListCommands(const char* direc);
112  // All commands registored under the given directory will be listed to
113  // G4cout.
114  void SetAlias(const char * aliasLine);
115  // Define an alias. The first word of "aliasLine" string is the
116  // alias name and the remaining word(s) is(are) string value
117  // to be aliased.
118  void RemoveAlias(const char * aliasName);
119  // Remove the defined alias.
120  void ListAlias();
121  // Print all aliases.
122  G4String SolveAlias(const char* aCmd);
123  // Convert a command string which contains alias(es).
124  void CreateHTML(const char* dir = "/");
125  // Generate HTML files for defined UI commands
126 
127  private:
128  void AddWorkerCommand(G4UIcommand * newCommand);
129  void RemoveWorkerCommand(G4UIcommand * aCommand);
130 
131  public:
132  void LoopS(const char* valueList);
133  void ForeachS(const char* valueList);
134  // These methods are used by G4UIcontrolMessenger to use Loop() and Foreach() methods.
135  virtual G4bool Notify(G4ApplicationState requestedState);
136  // This method is exclusively invoked by G4StateManager and the user
137  // must not use this method.
138 
139  private:
140  void PauseSession(const char* msg);
141  void CreateMessenger();
142  G4UIcommandTree* FindDirectory(const char* dirName);
143 
144  //public:
145  // following three methods will be removed quite soon.
146  // void Interact();
147  // void Interact(const char * promptCharacters);
148 
149  private:
150  G4ICOMS_DLL static G4UImanager*& fUImanager(); // thread-local
151  G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled(); // thread-local
162  std::ofstream historyFile;
164  std::vector<G4String> histVec;
170  std::vector<G4String> searchDirs;
171 
172  public: // with description
173  G4String GetCurrentStringValue(const char * aCommand,
174  G4int parameterNumber=1, G4bool reGet=true);
175  G4int GetCurrentIntValue(const char * aCommand,
176  G4int parameterNumber=1, G4bool reGet=true);
177  G4double GetCurrentDoubleValue(const char * aCommand,
178  G4int parameterNumber=1, G4bool reGet=true);
179  G4String GetCurrentStringValue(const char * aCommand,
180  const char * aParameterName, G4bool reGet=true);
181  G4int GetCurrentIntValue(const char * aCommand,
182  const char * aParameterName, G4bool reGet=true);
183  G4double GetCurrentDoubleValue(const char * aCommand,
184  const char * aParameterName, G4bool reGet=true);
185  // These six methods returns the current value of a parameter of the
186  // given command. For the first three methods, the ordering number of
187  // the parameter (1 is the first parameter) can be given, whereas,
188  // other three methods can give the parameter name.
189  // If "reGet" is true, actual request of returning the current value
190  // will be sent to the corresponding messenger, while, if it is false,
191  // the value stored in G4Umanager will be used. The later case is valid
192  // for the sequential invokation for the same command.
193 
195  { pauseAtBeginOfEvent = vl; }
197  { return pauseAtBeginOfEvent; }
198  inline void SetPauseAtEndOfEvent(G4bool vl)
199  { pauseAtEndOfEvent = vl; }
201  { return pauseAtEndOfEvent; }
202  // If the boolean flags are true, Pause() method of G4StateManager is invoked
203  // at the very begining (before generating a G4Event object) or at the end of
204  // each event. So that, in case a (G)UI session is defined, the user can interact.
205 
206 
207  public:
208  inline G4UIcommandTree * GetTree() const
209  { return treeTop; }
210  inline G4UIsession * GetSession() const
211  { return session; }
212  inline G4UIsession * GetG4UIWindow() const
213  { return g4UIWindow; }
214  public: // with description
215  inline void SetSession(G4UIsession *const value)
216  { session = value; }
217  inline void SetG4UIWindow(G4UIsession *const value)
218  { g4UIWindow = value; }
219  // This method defines the active (G)UI session.
220  void SetCoutDestination(G4UIsession *const value);
221  // This method defines the destination of G4cout/G4cerr stream.
222  // For usual cases, this method will be invoked by a concrete
223  // (G)UI session class object and thus the user needs not to invoke
224  // this method by him(her)self.
225 
226  public:
227  inline void SetVerboseLevel(G4int val)
228  { verboseLevel = val; }
229  inline G4int GetVerboseLevel() const
230  { return verboseLevel; }
231  inline G4int GetNumberOfHistory() const
232  { return histVec.size(); }
234  {
235  G4String st;
236  if(i>=0 && i<G4int(histVec.size()))
237  { st = histVec[i]; }
238  return st;
239  }
240  inline void SetMaxHistSize(G4int mx)
241  { maxHistSize = mx; }
242  inline G4int GetMaxHistSize() const
243  { return maxHistSize; }
244 
245  inline void SetMacroSearchPath(const G4String& path)
246  { searchPath = path; }
247  inline const G4String& GetMacroSearchPath() const
248  { return searchPath; }
249  void ParseMacroSearchPath();
250  G4String FindMacroPath(const G4String& fname) const;
251 
252  private:
254  std::vector<G4UIbridge*>* bridges;
257  std::vector<G4String>* commandStack;
258 
259  public:
260  inline void SetMasterUIManager(G4bool val)
261  {
262  isMaster = val;
263  //ignoreCmdNotFound = val;
265  if(val&&!bridges)
266  {
267  bridges = new std::vector<G4UIbridge*>;
268  fMasterUImanager() = this;
269  }
270  }
271  inline void SetIgnoreCmdNotFound(G4bool val)
272  { ignoreCmdNotFound = val; }
273 
274  std::vector<G4String>* GetCommandStack();
275  void RegisterBridge(G4UIbridge* brg);
276 
277  void SetUpForAThread(G4int tId);
278  //Setups as before but for a non-worker thread (e.g. vis)
279  void SetUpForSpecialThread(G4String aPrefix);
280 
281  inline G4int GetThreadID() const
282  { return threadID; }
283 
284  private:
288 
289  public:
290  void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true);
291  void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true);
292  void SetThreadPrefixString(const G4String& s = "W");
293  void SetThreadUseBuffer(G4bool flg = true);
294  void SetThreadIgnore(G4int tid = 0);
295  void SetThreadIgnoreInit(G4bool flg = true);
297 
298  private:
300 
301  public:
302  static void UseDoublePrecisionStr(G4bool val);
303  static G4bool DoublePrecisionStr();
304 };
305 
306 #endif
G4bool pauseAtBeginOfEvent
Definition: G4UImanager.hh:167
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:208
std::vector< G4UIbridge * > * bridges
Definition: G4UImanager.hh:254
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:678
static G4bool DoublePrecisionStr()
Definition: G4UImanager.cc:187
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:690
std::vector< G4String > * GetCommandStack()
Definition: G4UImanager.cc:744
std::vector< G4String > searchDirs
Definition: G4UImanager.hh:170
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:240
G4String savedParameters
Definition: G4UImanager.hh:159
G4UIcommandTree * FindDirectory(const char *dirName)
Definition: G4UImanager.cc:595
void AddNewCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:288
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:561
G4String searchPath
Definition: G4UImanager.hh:169
G4MTcoutDestination * GetThreadCout()
Definition: G4UImanager.hh:296
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
G4int operator==(const G4UImanager &right) const
Definition: G4UImanager.cc:180
G4UIsession * GetG4UIWindow() const
Definition: G4UImanager.hh:212
G4String FindMacroPath(const G4String &fname) const
Definition: G4UImanager.cc:729
G4UIsession * g4UIWindow
Definition: G4UImanager.hh:155
void AddWorkerCommand(G4UIcommand *newCommand)
Definition: G4UImanager.cc:295
std::ofstream historyFile
Definition: G4UImanager.hh:162
void RemoveCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:300
G4bool pauseAtEndOfEvent
Definition: G4UImanager.hh:168
G4int operator!=(const G4UImanager &right) const
Definition: G4UImanager.cc:182
G4int maxHistSize
Definition: G4UImanager.hh:166
void SetMacroSearchPath(const G4String &path)
Definition: G4UImanager.hh:245
const G4UImanager & operator=(const G4UImanager &right)
Definition: G4UImanager.cc:178
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:227
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:233
static G4ICOMS_DLL G4UImanager *& fMasterUImanager()
Definition: G4UImanager.cc:64
void SetPauseAtBeginOfEvent(G4bool vl)
Definition: G4UImanager.hh:194
G4UIsession * GetSession() const
Definition: G4UImanager.hh:210
static G4UImanager * GetMasterUIpointer()
Definition: G4UImanager.cc:86
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:411
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:242
const XML_Char * s
Definition: expat.h:262
void SetThreadIgnoreInit(G4bool flg=true)
Definition: G4UImanager.cc:835
G4bool GetPauseAtEndOfEvent() const
Definition: G4UImanager.hh:200
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:190
static G4ICOMS_DLL G4int igThreadID
Definition: G4UImanager.hh:287
const XML_Char int const XML_Char * value
Definition: expat.h:331
void SetIgnoreCmdNotFound(G4bool val)
Definition: G4UImanager.hh:271
void RegisterBridge(G4UIbridge *brg)
Definition: G4UImanager.cc:751
G4MTcoutDestination * threadCout
Definition: G4UImanager.hh:286
void RemoveWorkerCommand(G4UIcommand *aCommand)
Definition: G4UImanager.cc:307
const G4String & GetMacroSearchPath() const
Definition: G4UImanager.hh:247
virtual G4bool Notify(G4ApplicationState requestedState)
Definition: G4UImanager.cc:617
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:659
G4UIcontrolMessenger * UImessenger
Definition: G4UImanager.hh:156
G4UIaliasList * aliasList
Definition: G4UImanager.hh:165
#define G4ICOMS_DLL
Definition: icomsdefs.hh:48
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:795
void SetUpForSpecialThread(G4String aPrefix)
Definition: G4UImanager.cc:770
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:217
void PauseSession(const char *msg)
Definition: G4UImanager.cc:581
G4bool GetPauseAtBeginOfEvent() const
Definition: G4UImanager.hh:196
void SetPauseAtEndOfEvent(G4bool vl)
Definition: G4UImanager.hh:198
void ListAlias()
Definition: G4UImanager.cc:685
G4int threadID
Definition: G4UImanager.hh:285
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
Definition: G4UImanager.cc:341
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
Definition: G4UImanager.cc:780
void SetThreadPrefixString(const G4String &s="W")
Definition: G4UImanager.cc:810
static G4ICOMS_DLL G4bool & fUImanagerHasBeenKilled()
Definition: G4UImanager.cc:58
void SetThreadIgnore(G4int tid=0)
Definition: G4UImanager.cc:824
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:653
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:276
static G4ICOMS_DLL G4UImanager *& fUImanager()
Definition: G4UImanager.cc:52
void ListCommands(const char *direc)
Definition: G4UImanager.cc:586
std::vector< G4String > * commandStack
Definition: G4UImanager.hh:257
G4UIcommandTree * treeTop
Definition: G4UImanager.hh:153
int G4int
Definition: G4Types.hh:78
G4bool isMaster
Definition: G4UImanager.hh:253
G4bool ignoreCmdNotFound
Definition: G4UImanager.hh:255
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:252
TDirectory * dir
G4UIcommand * savedCommand
Definition: G4UImanager.hh:160
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:229
void ParseMacroSearchPath()
Definition: G4UImanager.cc:699
static G4ICOMS_DLL G4bool doublePrecisionStr
Definition: G4UImanager.hh:296
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:365
G4int GetThreadID() const
Definition: G4UImanager.hh:281
std::vector< G4String > histVec
Definition: G4UImanager.hh:164
G4ApplicationState
G4LocalThreadCoutMessenger * CoutMessenger
Definition: G4UImanager.hh:158
void SetUpForAThread(G4int tId)
Definition: G4UImanager.cc:762
void SetThreadUseBuffer(G4bool flg=true)
Definition: G4UImanager.cc:817
G4bool saveHistory
Definition: G4UImanager.hh:163
void CreateMessenger()
Definition: G4UImanager.cc:113
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:231
G4UIsession * session
Definition: G4UImanager.hh:154
static void UseDoublePrecisionStr(G4bool val)
Definition: G4UImanager.cc:185
G4bool stackCommandsForBroadcast
Definition: G4UImanager.hh:256
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:312
G4UnitsMessenger * UnitsMessenger
Definition: G4UImanager.hh:157
void SetMasterUIManager(G4bool val)
Definition: G4UImanager.hh:260
void LoopS(const char *valueList)
Definition: G4UImanager.cc:321
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
Definition: G4UImanager.cc:394
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
Definition: G4UImanager.cc:202
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:215
G4int verboseLevel
Definition: G4UImanager.hh:161