55 G4bool G4UImanager::doublePrecisionStr =
false;
57 G4int G4UImanager::igThreadID = -1;
63 if(!fUImanagerHasBeenKilled)
66 fUImanager->CreateMessenger();
73 {
return fMasterUImanager; }
77 UImessenger(0), UnitsMessenger(0), CoutMessenger(0),
78 isMaster(false),bridges(0),
79 ignoreCmdNotFound(false), stackCommandsForBroadcast(false),
80 threadID(-1), threadCout(0)
86 savedParameters = nullString;
92 pauseAtBeginOfEvent =
false;
93 pauseAtEndOfEvent =
false;
96 commandStack =
new std::vector<G4String>;
99 void G4UImanager::CreateMessenger()
110 std::vector<G4UIbridge*>::iterator itr = bridges->begin();
111 for(;itr!=bridges->end();itr++)
117 if(saveHistory) historyFile.close();
118 delete CoutMessenger;
119 delete UnitsMessenger;
123 fUImanagerHasBeenKilled =
true;
127 commandStack->clear();
132 if(threadCout)
delete threadCout;
141 UImessenger = ui.UImessenger;
142 UnitsMessenger = ui.UnitsMessenger;
143 aliasList = ui.aliasList;
144 g4UIWindow = ui.g4UIWindow;
145 savedCommand= ui.savedCommand;
146 session = ui.session;
147 treeTop = ui.treeTop;
148 verboseLevel = ui.verboseLevel;
149 saveHistory = ui.saveHistory;
151 maxHistSize = ui.maxHistSize;
152 pauseAtBeginOfEvent = ui.pauseAtBeginOfEvent;
153 pauseAtEndOfEvent = ui.pauseAtEndOfEvent;
154 isMaster = ui.isMaster;
155 bridges = ui.bridges;
156 ignoreCmdNotFound = ui.ignoreCmdNotFound;
157 stackCommandsForBroadcast = ui.stackCommandsForBroadcast;
158 commandStack = ui.commandStack;
159 threadID = ui.threadID;
160 threadCout = ui.threadCout;
167 {
return (
this==&right); }
169 {
return (
this!=&right); }
174 savedCommand = treeTop->
FindPath( theCommand );
175 if( savedCommand == NULL )
186 if(reGet || savedCommand == NULL)
192 for(
G4int i_thParameter=0;i_thParameter<parameterNumber;i_thParameter++)
194 token = savedToken();
196 if( token[(
size_t)0] ==
'"' )
199 token.
append(savedToken(
"\""));
206 const char * aParameterName,
G4bool reGet)
208 if(reGet || savedCommand == NULL)
214 if( aParameterName ==
222 const char * aParameterName,
G4bool reGet)
227 const char* t = targetParameter;
228 std::istringstream is(t);
239 const char* t = targetParameter;
240 std::istringstream is(t);
246 const char * aParameterName,
G4bool reGet)
251 const char* t = targetParameter;
252 std::istringstream is(t);
263 const char* t = targetParameter;
264 std::istringstream is(t);
273 { fMasterUImanager->AddWorkerCommand(newCommand); }
276 void G4UImanager::AddWorkerCommand(
G4UIcommand * newCommand)
285 { fMasterUImanager->RemoveWorkerCommand(aCommand); }
288 void G4UImanager::RemoveWorkerCommand(
G4UIcommand * aCommand)
296 session = batchSession;
299 session = previousSession;
310 c1 += parameterToken();
312 c1 += parameterToken();
314 std::istringstream is(t1);
318 is >> d1 >> d2 >> d3;
319 Loop(mf,vn,d1,d2,d3);
327 for(
G4double d=initialValue;d<=finalValue;d+=stepSize)
329 std::ostringstream os;
335 for(
G4double d=initialValue;d>=finalValue;d+=stepSize)
337 std::ostringstream os;
343 Foreach(macroFile,variableName,cd);
354 while(!((ca=parameterToken()).isNull()))
361 if(aliasValue(0)==
'"')
364 if(aliasValue(aliasValue.length()-1)==
'"')
365 { strippedValue = aliasValue(1,aliasValue.length()-2); }
367 { strippedValue = aliasValue(1,aliasValue.length()-1); }
368 aliasValue = strippedValue;
376 const char * candidates)
378 G4String candidatesString = candidates;
381 while(!((cd=parameterToken()).isNull()))
397 while((ia !=
G4int(std::string::npos))&&((iz==
G4int(std::string::npos))||(ia<iz)))
403 if( ib ==
G4int(std::string::npos) )
408 G4cerr <<
"Unmatched alias parenthis -- command ignored" <<
G4endl;
412 G4String ps = aCommand(ia+1,aCommand.length()-(ia+1));
415 if(ic!=
G4int(std::string::npos) && ic <
id)
423 if(ia>0) subs = aCommand(0,ia);
424 G4String alis = aCommand(ia+1,ibx-ia-1);
425 G4String rems = aCommand(ibx+1,aCommand.length()-ibx);
430 G4cerr <<
"Alias <" << alis <<
"> not found -- command ignored" <<
G4endl;
434 aCommand = subs+(*alVal)+rems;
435 ia = aCommand.
index(
"{");
456 if( i !=
G4int(std::string::npos) )
458 commandString = aCommand(0,i);
459 commandParameter = aCommand(i+1,aCommand.length()-(i+1));
463 commandString = aCommand;
473 if(commandString(ll,2)==
"//")
476 { commandString.
remove(ll,1); }
479 a1 = commandString(0,ll);
480 a2 = commandString(ll+1,len-ll-1);
481 commandString = a1+a2;
489 if(isMaster&&bridges)
491 std::vector<G4UIbridge*>::iterator itr = bridges->begin();
492 for(;itr!=bridges->end();itr++)
494 G4int leng = (*itr)->DirLength();
495 if(commandString(0,leng)==(*itr)->DirName())
496 {
return (*itr)->LocalUI()->ApplyCommand(commandString+
" "+commandParameter); }
501 if( targetCommand == NULL )
503 if(ignoreCmdNotFound)
505 if(stackCommandsForBroadcast)
506 { commandStack->push_back(commandString+
" "+commandParameter); }
514 { commandStack->push_back(commandString+
" "+commandParameter); }
519 if(saveHistory) historyFile << aCommand <<
G4endl;
520 if(
G4int(histVec.size()) >= maxHistSize )
521 { histVec.erase(histVec.begin()); }
522 histVec.push_back(aCommand);
524 return targetCommand->
DoIt( commandParameter );
535 { historyFile.close(); }
536 historyFile.open((
char*)fileName);
544 saveHistory = historySwitch;
547 void G4UImanager::PauseSession(
const char* msg)
565 if( targetDir( targetDir.length()-1 ) !=
'/' )
566 { targetDir +=
"/"; }
568 if( targetDir ==
"/" )
571 while( idx <
G4int(targetDir.length())-1 )
574 G4String targetDirString = targetDir(0,i+1);
575 comTree = comTree->
GetTree(targetDirString);
576 if( comTree == NULL )
586 if(pauseAtBeginOfEvent)
590 { PauseSession(
"BeginOfEvent"); }
592 if(pauseAtEndOfEvent)
596 { PauseSession(
"EndOfEvent"); }
630 G4String aliasValue = aLine(i+1,aLine.length()-(i+1));
631 if(aliasValue(0)==
'"')
634 if(aliasValue(aliasValue.length()-1)==
'"')
635 { strippedValue = aliasValue(1,aliasValue.length()-2); }
637 { strippedValue = aliasValue(1,aliasValue.length()-1); }
638 aliasValue = strippedValue;
662 {
G4cerr <<
"Directory <" << dir <<
"> is not found." <<
G4endl; }
672 while( (idxend = searchPath.
index(
':', idxfirst)) != G4String::npos) {
673 pathstring = searchPath.substr(idxfirst, idxend-idxfirst);
674 if(pathstring.size() != 0) searchDirs.push_back(pathstring);
675 idxfirst = idxend + 1;
678 pathstring = searchPath.substr(idxfirst, searchPath.size()-idxfirst);
679 if(pathstring.size() != 0) searchDirs.push_back(pathstring);
687 fs.open(fname.c_str(), std::ios::in);
699 for (
size_t i = 0; i < searchDirs.size(); i++) {
702 macrofile = fullpath;
712 std::vector<G4String>* returnValue = commandStack;
713 commandStack =
new std::vector<G4String>;
722 "G4UIBridge cannot bridge between same object.");
725 { bridges->push_back(brg); }
749 if(threadID<0)
return;
751 if(fileN ==
"**Screen**")
755 std::stringstream fn;
756 fn<<
"G4W_"<<threadID<<
"_"<<fileN;
764 if(threadID<0)
return;
766 if(fileN ==
"**Screen**")
770 std::stringstream fn;
771 fn<<
"G4W_"<<threadID<<
"_"<<fileN;
779 if(threadID<0)
return;
786 if(threadID<0)
return;
804 if(threadID<0) {
return; }
void ForeachS(const char *valueList)
void ExecuteMacroFile(const char *fileName)
void Foreach(const char *macroFile, const char *variableName, const char *candidates)
void RemoveAlias(const char *aliasName)
void SetThreadPrefixString(const G4String &s="W")
void SetAlias(const char *aliasLine)
void SetUpForAThread(G4int tId)
virtual void PauseSessionStart(const G4String &Prompt)
G4String GetCurrentStringValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
static G4UImanager * GetMasterUIpointer()
G4String & remove(str_size)
void RegisterBridge(G4UIbridge *brg)
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4String GetParameterName() const
void G4SetThreadId(G4int aNewValue)
static G4bool FileFound(const G4String &fname)
void SetThreadUseBuffer(G4bool flg=true)
virtual G4UIsession * SessionStart()
std::vector< G4String > * GetCommandStack()
void SetCerrFileName(const G4String &fileN="G4cerr.txt", G4bool ifAppend=true)
void SetPrefixString(const G4String &wd="G4WT")
void SetCoutFileName(const G4String &fileN="G4cout.txt", G4bool ifAppend=true)
static G4UImanager * GetUIpointer()
void SetIgnoreInit(G4bool val=true)
void ParseMacroSearchPath()
static G4StateManager * GetStateManager()
void SetThreadIgnoreInit(G4bool flg=true)
G4bool ToBeBroadcasted() const
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
const XML_Char int const XML_Char * value
G4UIcommandTree * GetTree(G4int i)
void ChangeAlias(const char *aliasName, const char *aliasValue)
void Loop(const char *macroFile, const char *variableName, G4double initialValue, G4double finalValue, G4double stepSize=1.0)
G4UIparameter * GetParameter(G4int i) const
void EnableBuffering(G4bool flag=true)
void RemoveCommand(G4UIcommand *aCommand)
void RemoveCommand(G4UIcommand *aCommand, G4bool workerThreadOnly=false)
G4int GetCurrentIntValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
G4String * FindAlias(const char *aliasName)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void SetIgnoreCout(G4int tid=0)
G4String GetCurrentValues(const char *aCommand)
const char * data() const
void ListCommands(const char *direc)
void SetDestination(G4coutDestination *dest)
void AddNewCommand(G4UIcommand *newCommand, G4bool workerThreadOnly=false)
void AddNewCommand(G4UIcommand *newCommand)
G4String & append(const G4String &)
void SetCoutDestination(G4UIsession *const value)
void G4iosInitialization()
G4String SolveAlias(const char *aCmd)
void LoopS(const char *valueList)
virtual G4bool Notify(G4ApplicationState requestedState)
G4double GetCurrentDoubleValue(const char *aCommand, G4int parameterNumber=1, G4bool reGet=true)
G4UImanager * LocalUI() const
void SetUpForSpecialThread(G4String aPrefix)
void SetThreadIgnore(G4int tid=0)
void CreateHTML(const char *dir="/")
static constexpr double ps
void StoreHistory(const char *fileName="G4history.macro")
G4int GetParameterEntries() const
G4String FindMacroPath(const G4String &fname) const
virtual G4int DoIt(G4String parameterList)
G4int ApplyCommand(const char *aCommand)
G4String GetCurrentValue()
G4GLOB_DLL std::ostream G4cerr
void RemoveAlias(const char *aliasName)