File indexing completed on 2025-01-18 09:59:16
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifndef G4UImanager_hh
0036 #define G4UImanager_hh 1
0037
0038 #include "G4UIcommandStatus.hh"
0039 #include "G4VStateDependent.hh"
0040 #include "globals.hh"
0041
0042 #include "icomsdefs.hh"
0043
0044 #include <fstream>
0045 #include <vector>
0046
0047 class G4UIcommandTree;
0048 class G4UIcommand;
0049 class G4UIsession;
0050 class G4UIcontrolMessenger;
0051 class G4UnitsMessenger;
0052 class G4LocalThreadCoutMessenger;
0053 class G4UIaliasList;
0054 class G4MTcoutDestination;
0055 class G4UIbridge;
0056 class G4ProfilerMessenger;
0057
0058 class G4UImanager : public G4VStateDependent
0059 {
0060 public:
0061
0062
0063 static G4UImanager* GetUIpointer();
0064 static G4UImanager* GetMasterUIpointer();
0065
0066 ~G4UImanager() override;
0067
0068 G4UImanager(const G4UImanager&) = delete;
0069 const G4UImanager& operator=(const G4UImanager&) = delete;
0070 G4bool operator==(const G4UImanager&) const = delete;
0071 G4bool operator!=(const G4UImanager&) const = delete;
0072
0073
0074
0075
0076
0077 G4String GetCurrentValues(const char* aCommand);
0078
0079
0080 void AddNewCommand(G4UIcommand* newCommand);
0081
0082
0083
0084 void RemoveCommand(G4UIcommand* aCommand);
0085
0086
0087 void ExecuteMacroFile(const char* fileName);
0088
0089
0090 void Loop(const char* macroFile, const char* variableName, G4double initialValue,
0091 G4double finalValue, G4double stepSize = 1.0);
0092
0093
0094
0095 void Foreach(const char* macroFile, const char* variableName, const char* candidates);
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105 G4int ApplyCommand(const char* aCommand);
0106 G4int ApplyCommand(const G4String& aCommand);
0107
0108
0109
0110
0111
0112 G4UIcommand* FindCommand(const char* aCommand);
0113 G4UIcommand* FindCommand(const G4String& aCommand);
0114
0115
0116
0117 void StoreHistory(const char* fileName = "G4history.macro");
0118 void StoreHistory(G4bool historySwitch, const char* fileName = "G4history.macro");
0119
0120
0121
0122 void ListCommands(const char* direc);
0123
0124
0125
0126
0127 void SetAlias(const char* aliasLine);
0128
0129
0130 void RemoveAlias(const char* aliasName);
0131
0132
0133 void ListAlias();
0134
0135
0136 G4String SolveAlias(const char* aCmd);
0137
0138
0139 void CreateHTML(const char* dir = "/");
0140
0141
0142
0143 void LoopS(const char* valueList);
0144 void ForeachS(const char* valueList);
0145
0146
0147 G4bool Notify(G4ApplicationState requestedState) override;
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 G4String GetCurrentStringValue(const char* aCommand, G4int parameterNumber = 1,
0158 G4bool reGet = true);
0159 G4int GetCurrentIntValue(const char* aCommand, G4int parameterNumber = 1, G4bool reGet = true);
0160 G4double GetCurrentDoubleValue(const char* aCommand, G4int parameterNumber = 1,
0161 G4bool reGet = true);
0162 G4String GetCurrentStringValue(const char* aCommand, const char* aParameterName,
0163 G4bool reGet = true);
0164 G4int GetCurrentIntValue(const char* aCommand, const char* aParameterName, G4bool reGet = true);
0165 G4double GetCurrentDoubleValue(const char* aCommand, const char* aParameterName,
0166 G4bool reGet = true);
0167
0168
0169
0170
0171
0172 inline void SetPauseAtBeginOfEvent(G4bool vl) { pauseAtBeginOfEvent = vl; }
0173 inline G4bool GetPauseAtBeginOfEvent() const { return pauseAtBeginOfEvent; }
0174 inline void SetPauseAtEndOfEvent(G4bool vl) { pauseAtEndOfEvent = vl; }
0175 inline G4bool GetPauseAtEndOfEvent() const { return pauseAtEndOfEvent; }
0176
0177 inline G4UIcommandTree* GetTree() const { return treeTop; }
0178 inline G4UIsession* GetSession() const { return session; }
0179 inline G4UIsession* GetG4UIWindow() const { return g4UIWindow; }
0180
0181 G4UIsession* GetBaseSession() const;
0182
0183
0184 inline void SetSession(G4UIsession* const value) { session = value; }
0185 inline void SetG4UIWindow(G4UIsession* const value) { g4UIWindow = value; }
0186
0187
0188
0189
0190 void SetCoutDestination(G4UIsession* const value);
0191
0192 inline void SetVerboseLevel(G4int val) { verboseLevel = val; }
0193 inline G4int GetVerboseLevel() const { return verboseLevel; }
0194 inline G4int GetNumberOfHistory() const { return G4int(histVec.size()); }
0195 inline G4String GetPreviousCommand(G4int i) const
0196 {
0197 G4String st;
0198 if (i >= 0 && i < G4int(histVec.size())) {
0199 st = histVec[i];
0200 }
0201 return st;
0202 }
0203 inline void SetMaxHistSize(G4int mx) { maxHistSize = mx; }
0204 inline G4int GetMaxHistSize() const { return maxHistSize; }
0205
0206 inline void SetMacroSearchPath(const G4String& path) { searchPath = path; }
0207 inline const G4String& GetMacroSearchPath() const { return searchPath; }
0208 void ParseMacroSearchPath();
0209 G4String FindMacroPath(const G4String& fname) const;
0210
0211 inline void SetMasterUIManager(G4bool val)
0212 {
0213 isMaster = val;
0214 stackCommandsForBroadcast = val;
0215 if (val && (bridges == nullptr)) {
0216 bridges = new std::vector<G4UIbridge*>;
0217 fMasterUImanager() = this;
0218 }
0219 }
0220 inline void SetIgnoreCmdNotFound(G4bool val) { ignoreCmdNotFound = val; }
0221
0222 std::vector<G4String>* GetCommandStack();
0223 void RegisterBridge(G4UIbridge* brg);
0224
0225
0226 void SetUpForAThread(G4int tId);
0227
0228 void SetUpForSpecialThread(const G4String& aPrefix);
0229
0230 inline G4int GetThreadID() const { return threadID; }
0231
0232 void SetCoutFileName(const G4String& fileN = "G4cout.txt", G4bool ifAppend = true);
0233 void SetCerrFileName(const G4String& fileN = "G4cerr.txt", G4bool ifAppend = true);
0234 void SetThreadPrefixString(const G4String& prefix = "W");
0235 void SetThreadUseBuffer(G4bool flg = true);
0236 void SetThreadIgnore(G4int tid = 0);
0237 void SetThreadIgnoreInit(G4bool flg = true);
0238 inline G4MTcoutDestination* GetThreadCout() { return threadCout; }
0239
0240 static void UseDoublePrecisionStr(G4bool val);
0241 static G4bool DoublePrecisionStr();
0242
0243 inline G4int GetLastReturnCode() const { return lastRC; }
0244
0245 inline bool IsLastCommandOutputTreated() { return fLastCommandOutputTreated; }
0246 inline void SetLastCommandOutputTreated() { fLastCommandOutputTreated = true; }
0247
0248 protected:
0249 G4UImanager();
0250
0251 private:
0252 void AddWorkerCommand(G4UIcommand* newCommand);
0253 void RemoveWorkerCommand(G4UIcommand* aCommand);
0254
0255 void PauseSession(const char* msg);
0256 void CreateMessenger();
0257 G4UIcommandTree* FindDirectory(const char* dirName);
0258
0259 private:
0260 G4ICOMS_DLL static G4UImanager*& fUImanager();
0261 G4ICOMS_DLL static G4bool& fUImanagerHasBeenKilled();
0262 G4ICOMS_DLL static G4UImanager*& fMasterUImanager();
0263 G4UIcommandTree* treeTop = nullptr;
0264 G4UIsession* session = nullptr;
0265 G4UIsession* g4UIWindow = nullptr;
0266 G4UIcontrolMessenger* UImessenger = nullptr;
0267 G4UnitsMessenger* UnitsMessenger = nullptr;
0268 G4LocalThreadCoutMessenger* CoutMessenger = nullptr;
0269 G4ProfilerMessenger* ProfileMessenger = nullptr;
0270 G4String savedParameters;
0271 G4UIcommand* savedCommand = nullptr;
0272 G4int verboseLevel = 0;
0273 std::ofstream historyFile;
0274 G4bool saveHistory = false;
0275 std::vector<G4String> histVec;
0276 G4UIaliasList* aliasList = nullptr;
0277 G4int maxHistSize = 20;
0278 G4bool pauseAtBeginOfEvent = false;
0279 G4bool pauseAtEndOfEvent = false;
0280 G4String searchPath = "";
0281 std::vector<G4String> searchDirs;
0282
0283 G4bool isMaster = false;
0284 std::vector<G4UIbridge*>* bridges = nullptr;
0285 G4bool ignoreCmdNotFound = false;
0286 G4bool stackCommandsForBroadcast = false;
0287 std::vector<G4String>* commandStack = nullptr;
0288
0289 G4int threadID = -1;
0290 G4MTcoutDestination* threadCout = nullptr;
0291 G4ICOMS_DLL static G4int igThreadID;
0292
0293 G4ICOMS_DLL static G4bool doublePrecisionStr;
0294
0295 G4int lastRC = 0;
0296
0297 G4bool fLastCommandOutputTreated = true;
0298 };
0299
0300 #endif