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,v 1.21 2006/06/29 19:08:17 gunter Exp $ |
---|
28 | // GEANT4 tag $Name: geant4-09-02 $ |
---|
29 | // |
---|
30 | |
---|
31 | #ifndef G4UImanager_h |
---|
32 | #define G4UImanager_h 1 |
---|
33 | |
---|
34 | #include "globals.hh" |
---|
35 | |
---|
36 | #include <vector> |
---|
37 | #include <fstream> |
---|
38 | #include "G4VStateDependent.hh" |
---|
39 | #include "G4UIcommandStatus.hh" |
---|
40 | class G4UIcommandTree; |
---|
41 | class G4UIcommand; |
---|
42 | class G4UIsession; |
---|
43 | class G4UIcontrolMessenger; |
---|
44 | class G4UnitsMessenger; |
---|
45 | class G4UIaliasList; |
---|
46 | |
---|
47 | // class description: |
---|
48 | // |
---|
49 | // This is a singlton class which controls the command manipulation |
---|
50 | // and the user interface(s). The constructor of this class MUST NOT |
---|
51 | // invoked by the user. |
---|
52 | // |
---|
53 | |
---|
54 | class G4UImanager : public G4VStateDependent |
---|
55 | { |
---|
56 | public: // with description |
---|
57 | static G4UImanager * GetUIpointer(); |
---|
58 | // A static method to get the pointer to the only existing object |
---|
59 | // of this class. |
---|
60 | |
---|
61 | protected: |
---|
62 | G4UImanager(); |
---|
63 | public: |
---|
64 | ~G4UImanager(); |
---|
65 | private: |
---|
66 | G4UImanager(const G4UImanager &right); |
---|
67 | const G4UImanager & operator=(const G4UImanager &right); |
---|
68 | G4int operator==(const G4UImanager &right) const; |
---|
69 | G4int operator!=(const G4UImanager &right) const; |
---|
70 | |
---|
71 | public: // with description |
---|
72 | G4String GetCurrentValues(const char * aCommand); |
---|
73 | // This method returns a string which represents the current value(s) |
---|
74 | // of the parameter(s) of the specified command. Null string will be |
---|
75 | // returned if the given command is not defined or the command does |
---|
76 | // not support the GetCurrentValues() method. |
---|
77 | void AddNewCommand(G4UIcommand * newCommand); |
---|
78 | // This method register a new command. |
---|
79 | void RemoveCommand(G4UIcommand * aCommand); |
---|
80 | // This command remove the registered command. After invokation of this |
---|
81 | // command, that particular command cannot be applied. |
---|
82 | void ExecuteMacroFile(const char * fileName); |
---|
83 | // A macro file defined by the argument will be read by G4UIbatch object. |
---|
84 | void Loop(const char * macroFile,const char * variableName, |
---|
85 | G4double initialValue,G4double finalValue,G4double stepSize=1.0); |
---|
86 | // Execute a macro file more than once with a loop counter. |
---|
87 | void Foreach(const char * macroFile,const char * variableName, |
---|
88 | const char * candidates); |
---|
89 | // Execute a macro file more than once with an aliased variable which takes |
---|
90 | // a value in the candidate list. |
---|
91 | G4int ApplyCommand(const char * aCommand); |
---|
92 | G4int ApplyCommand(G4String aCommand); |
---|
93 | // A command (and parameter(s)) given |
---|
94 | // by the method's argument will be applied. Zero will be returned in |
---|
95 | // case the command is successfully executed. Positive non-zero value |
---|
96 | // will be returned if the command couldn't be executed. The meaning of |
---|
97 | // this non-zero value is the following. |
---|
98 | // The returned number : xyy |
---|
99 | // x00 : G4CommandStatus.hh enumeration |
---|
100 | // yy : the problematic parameter (first found) |
---|
101 | void StoreHistory(const char* fileName = "G4history.macro"); |
---|
102 | void StoreHistory(G4bool historySwitch, |
---|
103 | const char* fileName = "G4history.macro"); |
---|
104 | // The executed commands will be stored in the defined file. If |
---|
105 | // "historySwitch" is false, saving will be suspended. |
---|
106 | void ListCommands(const char* direc); |
---|
107 | // All commands registored under the given directory will be listed to |
---|
108 | // G4cout. |
---|
109 | void SetAlias(const char * aliasLine); |
---|
110 | // Define an alias. The first word of "aliasLine" string is the |
---|
111 | // alias name and the remaining word(s) is(are) string value |
---|
112 | // to be aliased. |
---|
113 | void RemoveAlias(const char * aliasName); |
---|
114 | // Remove the defined alias. |
---|
115 | void ListAlias(); |
---|
116 | // Print all aliases. |
---|
117 | G4String SolveAlias(const char* aCmd); |
---|
118 | // Convert a command string which contains alias(es). |
---|
119 | void CreateHTML(const char* dir = "/"); |
---|
120 | // Generate HTML files for defined UI commands |
---|
121 | |
---|
122 | |
---|
123 | public: |
---|
124 | void LoopS(const char* valueList); |
---|
125 | void ForeachS(const char* valueList); |
---|
126 | // These methods are used by G4UIcontrolMessenger to use Loop() and Foreach() methods. |
---|
127 | virtual G4bool Notify(G4ApplicationState requestedState); |
---|
128 | // This method is exclusively invoked by G4StateManager and the user |
---|
129 | // must not use this method. |
---|
130 | |
---|
131 | private: |
---|
132 | void PauseSession(const char* msg); |
---|
133 | void CreateMessenger(); |
---|
134 | G4UIcommandTree* FindDirectory(const char* dirName); |
---|
135 | |
---|
136 | //public: |
---|
137 | // following three methods will be removed quite soon. |
---|
138 | // void Interact(); |
---|
139 | // void Interact(const char * promptCharacters); |
---|
140 | |
---|
141 | private: |
---|
142 | static G4UImanager * fUImanager; |
---|
143 | static G4bool fUImanagerHasBeenKilled; |
---|
144 | G4UIcommandTree * treeTop; |
---|
145 | G4UIsession * session; |
---|
146 | G4UIcontrolMessenger * UImessenger; |
---|
147 | G4UnitsMessenger * UnitsMessenger; |
---|
148 | G4String savedParameters; |
---|
149 | G4UIcommand * savedCommand; |
---|
150 | G4int verboseLevel; |
---|
151 | std::ofstream historyFile; |
---|
152 | G4bool saveHistory; |
---|
153 | std::vector<G4String> histVec; |
---|
154 | G4UIaliasList* aliasList; |
---|
155 | G4int maxHistSize; |
---|
156 | G4bool pauseAtBeginOfEvent; |
---|
157 | G4bool pauseAtEndOfEvent; |
---|
158 | |
---|
159 | |
---|
160 | public: // with description |
---|
161 | G4String GetCurrentStringValue(const char * aCommand, |
---|
162 | G4int parameterNumber=1, G4bool reGet=true); |
---|
163 | G4int GetCurrentIntValue(const char * aCommand, |
---|
164 | G4int parameterNumber=1, G4bool reGet=true); |
---|
165 | G4double GetCurrentDoubleValue(const char * aCommand, |
---|
166 | G4int parameterNumber=1, G4bool reGet=true); |
---|
167 | G4String GetCurrentStringValue(const char * aCommand, |
---|
168 | const char * aParameterName, G4bool reGet=true); |
---|
169 | G4int GetCurrentIntValue(const char * aCommand, |
---|
170 | const char * aParameterName, G4bool reGet=true); |
---|
171 | G4double GetCurrentDoubleValue(const char * aCommand, |
---|
172 | const char * aParameterName, G4bool reGet=true); |
---|
173 | // These six methods returns the current value of a parameter of the |
---|
174 | // given command. For the first three methods, the ordering number of |
---|
175 | // the parameter (1 is the first parameter) can be given, whereas, |
---|
176 | // other three methods can give the parameter name. |
---|
177 | // If "reGet" is true, actual request of returning the current value |
---|
178 | // will be sent to the corresponding messenger, while, if it is false, |
---|
179 | // the value stored in G4Umanager will be used. The later case is valid |
---|
180 | // for the sequential invokation for the same command. |
---|
181 | |
---|
182 | inline void SetPauseAtBeginOfEvent(G4bool vl) |
---|
183 | { pauseAtBeginOfEvent = vl; } |
---|
184 | inline G4bool GetPauseAtBeginOfEvent() const |
---|
185 | { return pauseAtBeginOfEvent; } |
---|
186 | inline void SetPauseAtEndOfEvent(G4bool vl) |
---|
187 | { pauseAtEndOfEvent = vl; } |
---|
188 | inline G4bool GetPauseAtEndOfEvent() const |
---|
189 | { return pauseAtEndOfEvent; } |
---|
190 | // If the boolean flags are true, Pause() method of G4StateManager is invoked |
---|
191 | // at the very begining (before generating a G4Event object) or at the end of |
---|
192 | // each event. So that, in case a (G)UI session is defined, the user can interact. |
---|
193 | |
---|
194 | |
---|
195 | public: |
---|
196 | inline G4UIcommandTree * GetTree() const |
---|
197 | { return treeTop; } |
---|
198 | inline G4UIsession * GetSession() const |
---|
199 | { return session; } |
---|
200 | public: // with description |
---|
201 | inline void SetSession(G4UIsession *const value) |
---|
202 | { session = value; } |
---|
203 | // This method defines the active (G)UI session. |
---|
204 | void SetCoutDestination(G4UIsession *const value); |
---|
205 | // This method defines the destination of G4cout/G4cerr stream. |
---|
206 | // For usual cases, this method will be invoked by a concrete |
---|
207 | // (G)UI session class object and thus the user needs not to invoke |
---|
208 | // this method by him(her)self. |
---|
209 | |
---|
210 | public: |
---|
211 | inline void SetVerboseLevel(G4int val) |
---|
212 | { verboseLevel = val; } |
---|
213 | inline G4int GetVerboseLevel() const |
---|
214 | { return verboseLevel; } |
---|
215 | inline G4int GetNumberOfHistory() const |
---|
216 | { return histVec.size(); } |
---|
217 | inline G4String GetPreviousCommand(G4int i) const |
---|
218 | { |
---|
219 | G4String st; |
---|
220 | if(i>=0 && i<G4int(histVec.size())) |
---|
221 | { st = histVec[i]; } |
---|
222 | return st; |
---|
223 | } |
---|
224 | inline void SetMaxHistSize(G4int mx) |
---|
225 | { maxHistSize = mx; } |
---|
226 | inline G4int GetMaxHistSize() const |
---|
227 | { return maxHistSize; } |
---|
228 | |
---|
229 | // Old methods kept for backward compatibility |
---|
230 | // inline G4UIcommandTree * GetTree() const |
---|
231 | // { return treeTop; }; |
---|
232 | // inline G4UIsession * GetSession() const |
---|
233 | // { return session; }; |
---|
234 | // inline void SetSession(G4UIsession *const value) |
---|
235 | // { session = value; }; |
---|
236 | |
---|
237 | }; |
---|
238 | |
---|
239 | #endif |
---|
240 | |
---|