56 G4int G4UImanager::igThreadID = -1;
62 if(!fUImanagerHasBeenKilled)
65 fUImanager->CreateMessenger();
72 {
return fMasterUImanager; }
76 UImessenger(0), UnitsMessenger(0), CoutMessenger(0),
77 isMaster(false),bridges(0),
78 ignoreCmdNotFound(false), stackCommandsForBroadcast(false),
79 threadID(-1), threadCout(0)
85 savedParameters = nullString;
91 pauseAtBeginOfEvent =
false;
92 pauseAtEndOfEvent =
false;
95 commandStack =
new std::vector<G4String>;
98 void G4UImanager::CreateMessenger()
109 std::vector<G4UIbridge*>::iterator itr = bridges->begin();
110 for(;itr!=bridges->end();itr++)
116 if(saveHistory) historyFile.close();
117 delete CoutMessenger;
118 delete UnitsMessenger;
122 fUImanagerHasBeenKilled =
true;
126 commandStack->clear();
131 if(threadCout)
delete threadCout;
140 UImessenger = ui.UImessenger;
141 UnitsMessenger = ui.UnitsMessenger;
142 aliasList = ui.aliasList;
143 g4UIWindow = ui.g4UIWindow;
144 savedCommand= ui.savedCommand;
145 session = ui.session;
146 treeTop = ui.treeTop;
152 {
return (
this==&right); }
154 {
return (
this!=&right); }
159 savedCommand = treeTop->
FindPath( theCommand );
160 if( savedCommand == NULL )
171 if(reGet || savedCommand == NULL)
177 for(
G4int i_thParameter=0;i_thParameter<parameterNumber;i_thParameter++)
179 token = savedToken();
181 if( token[(
size_t)0] ==
'"' )
184 token.
append(savedToken(
"\""));
191 const char * aParameterName,
G4bool reGet)
193 if(reGet || savedCommand == NULL)
199 if( aParameterName ==
207 const char * aParameterName,
G4bool reGet)
212 const char* t = targetParameter;
213 std::istringstream is(t);
224 const char* t = targetParameter;
225 std::istringstream is(t);
231 const char * aParameterName,
G4bool reGet)
236 const char* t = targetParameter;
237 std::istringstream is(t);
248 const char* t = targetParameter;
249 std::istringstream is(t);
258 { fMasterUImanager->AddWorkerCommand(newCommand); }
261 void G4UImanager::AddWorkerCommand(
G4UIcommand * newCommand)
270 { fMasterUImanager->RemoveWorkerCommand(aCommand); }
273 void G4UImanager::RemoveWorkerCommand(
G4UIcommand * aCommand)
281 session = batchSession;
284 session = previousSession;
295 c1 += parameterToken();
297 c1 += parameterToken();
299 std::istringstream is(t1);
303 is >> d1 >> d2 >> d3;
304 Loop(mf,vn,d1,d2,d3);
312 for(
G4double d=initialValue;
d<=finalValue;
d+=stepSize)
314 std::ostringstream os;
320 for(
G4double d=initialValue;
d>=finalValue;
d+=stepSize)
322 std::ostringstream os;
328 Foreach(macroFile,variableName,cd);
339 while(!((ca=parameterToken()).isNull()))
348 const char * candidates)
350 G4String candidatesString = candidates;
353 while(!((cd=parameterToken()).isNull()))
369 while((ia !=
G4int(std::string::npos))&&((iz==
G4int(std::string::npos))||(ia<iz)))
375 if( ib ==
G4int(std::string::npos) )
380 G4cerr <<
"Unmatched alias parenthis -- command ignored" <<
G4endl;
384 G4String ps = aCommand(ia+1,aCommand.length()-(ia+1));
387 if(ic!=
G4int(std::string::npos) && ic <
id)
395 if(ia>0) subs = aCommand(0,ia);
396 G4String alis = aCommand(ia+1,ibx-ia-1);
397 G4String rems = aCommand(ibx+1,aCommand.length()-ibx);
402 G4cerr <<
"Alias <" << alis <<
"> not found -- command ignored" <<
G4endl;
406 aCommand = subs+(*alVal)+rems;
407 ia = aCommand.
index(
"{");
428 if( i !=
G4int(std::string::npos) )
430 commandString = aCommand(0,i);
431 commandParameter = aCommand(i+1,aCommand.length()-(i+1));
435 commandString = aCommand;
445 if(commandString(ll,2)==
"//")
448 { commandString.
remove(ll,1); }
451 a1 = commandString(0,ll);
452 a2 = commandString(ll+1,len-ll-1);
453 commandString = a1+a2;
461 if(isMaster&&bridges)
463 std::vector<G4UIbridge*>::iterator itr = bridges->begin();
464 for(;itr!=bridges->end();itr++)
466 G4int leng = (*itr)->DirLength();
467 if(commandString(0,leng)==(*itr)->DirName())
468 {
return (*itr)->LocalUI()->ApplyCommand(commandString+
" "+commandParameter); }
473 if( targetCommand == NULL )
475 if(ignoreCmdNotFound)
477 if(stackCommandsForBroadcast)
478 { commandStack->push_back(commandString+
" "+commandParameter); }
486 { commandStack->push_back(commandString+
" "+commandParameter); }
491 if(saveHistory) historyFile << aCommand <<
G4endl;
492 if(
G4int(histVec.size()) >= maxHistSize )
493 { histVec.erase(histVec.begin()); }
494 histVec.push_back(aCommand);
496 return targetCommand->
DoIt( commandParameter );
507 { historyFile.close(); }
508 historyFile.open((
char*)fileName);
516 saveHistory = historySwitch;
519 void G4UImanager::PauseSession(
const char* msg)
537 if( targetDir( targetDir.length()-1 ) !=
'/' )
538 { targetDir +=
"/"; }
540 if( targetDir ==
"/" )
543 while( idx <
G4int(targetDir.length())-1 )
546 G4String targetDirString = targetDir(0,i+1);
547 comTree = comTree->
GetTree(targetDirString);
548 if( comTree == NULL )
558 if(pauseAtBeginOfEvent)
562 { PauseSession(
"BeginOfEvent"); }
564 if(pauseAtEndOfEvent)
568 { PauseSession(
"EndOfEvent"); }
602 G4String aliasValue = aLine(i+1,aLine.length()-(i+1));
603 if(aliasValue(0)==
'"')
606 if(aliasValue(aliasValue.length()-1)==
'"')
607 { strippedValue = aliasValue(1,aliasValue.length()-2); }
609 { strippedValue = aliasValue(1,aliasValue.length()-1); }
610 aliasValue = strippedValue;
634 {
G4cerr <<
"Directory <" << dir <<
"> is not found." <<
G4endl; }
644 while( (idxend = searchPath.
index(
':', idxfirst)) != G4String::npos) {
645 pathstring = searchPath.substr(idxfirst, idxend-idxfirst);
646 if(pathstring.size() != 0) searchDirs.push_back(pathstring);
647 idxfirst = idxend + 1;
650 pathstring = searchPath.substr(idxfirst, searchPath.size()-idxfirst);
651 if(pathstring.size() != 0) searchDirs.push_back(pathstring);
671 for (
size_t i = 0; i < searchDirs.size(); i++) {
673 if ( FileFound(fullpath) ) {
674 macrofile = fullpath;
684 std::vector<G4String>* returnValue = commandStack;
685 commandStack =
new std::vector<G4String>;
694 "G4UIBridge cannot bridge between same object.");
697 { bridges->push_back(brg); }
711 if(threadID<0)
return;
713 if(fileN ==
"**Screen**")
717 std::stringstream fn;
718 fn<<
"G4W_"<<threadID<<
"_"<<fileN;
726 if(threadID<0)
return;
728 if(fileN ==
"**Screen**")
732 std::stringstream fn;
733 fn<<
"G4W_"<<threadID<<
"_"<<fileN;
741 if(threadID<0)
return;
748 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 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 ParseMacroSearchPath()
static G4StateManager * GetStateManager()
G4bool ToBeBroadcasted() const
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
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)
const XML_Char int const XML_Char * value
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 SetThreadIgnore(G4int tid=0)
void CreateHTML(const char *dir="/")
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)