40 TVersion=
"T1.0a"; JVersion=
"J1.0a";
53 GetNewTreeStructure(tree,0);
54 GetNewTreeValues(tree,0);
55 previousTreeCommands = newTreeCommands;
56 previousTreeParams = newTreeParams;
57 previousTreePCP = newTreePCP;
79 ExecuteCommand(newCommand);
88 promptCharacter = msg;
89 G4cout <<
"@@PROMPT \"" << promptCharacter <<
"\"" <<
G4endl;
94 ExecuteCommand(newCommand);
99void G4UIGAG::ExecuteCommand(
const G4String& aCommand)
102 if(aCommand.length()<2)
return;
104 G4int paramIndex = returnVal % 100;
105 G4int commandStatus = returnVal - paramIndex;
109 switch(commandStatus) {
117 G4cerr <<
"illegal application state -- command refused" <<
G4endl;
121 G4cerr <<
"Parameter is wrong type and/or is not omittable (index " << paramIndex <<
")" <<
G4endl;
124 G4cerr <<
"Parameter is out of candidate list (index " << paramIndex <<
")" <<
G4endl;
129 G4cerr <<
"command refused (" << commandStatus <<
")" <<
G4endl;
132 switch(commandStatus) {
135 GetNewTreeStructure(tree,0);
136 GetNewTreeValues(tree,0);
137 if (CommandUpdated()) {
138 NotifyCommandUpdate();
142 previousTreeCommands = newTreeCommands;
143 previousTreeParams = newTreeParams;
144 previousTreePCP = newTreePCP;
151 G4cout <<
"@@ErrResult \"Illegal application state -- command refused\"" <<
G4endl;
154 G4cout <<
"@@ErrResult \"Parameter Out of Range.\"" <<
G4endl;
157 G4cout <<
"@@ErrResult \"Parameter is wrong type and/or is not omittable.\"" <<
G4endl;
161 G4cout <<
"@@ErrResult \"Parameter Out of Candidates.\"" <<
G4endl;
165 G4cout <<
"@@ErrResult \"command refused (" << commandStatus <<
")\"" <<
G4endl;
173 std::cout << coutString << std::flush;
179 std::cerr << cerrString << std::flush;
185 promptCharacter = aPrompt;
196 G4cout <<
"@@PROMPT \"" << promptCharacter <<
"\"" <<
G4endl;
199 G4cout << promptCharacter <<
"> " << std::flush;
204 if (!
G4cin.good()) {
G4cin.clear(); newCommand = nullString; iExit=
false;
break;}
207 if( newCommand.length() < 1) {
break; }
209 while( newCommand(newCommand.length()-1) ==
'_' )
212 newCommand.
remove(newCommand.length()-1);
214 if (!
G4cin.good()) {
G4cin.clear(); newCommand = nullString; iExit=
false;
break;}
215 newCommand.
append(newLine);
219 if( nC.length() < 1) {
break; }
222 if( nC ==
"@@GAGmodeJAVA" ) {
225 SendCommandProperties(tree);
228 else if( nC ==
"@@GAGmodeTcl" ) {
231 SendCommandProperties(tree);
234 else if( nC(0) ==
'#' )
237 else if( nC ==
"ls" || nC(0,3) ==
"ls " )
238 { ListDirectory( nC ); }
239 else if( nC ==
"pwd" )
241 else if( nC(0,2) ==
"cd" || nC(0,3) ==
"cd " )
242 { ChangeDirectory( nC ); }
243 else if( nC ==
"help" || nC(0,5) ==
"help ")
244 { TerminalHelp( nC ); }
245 else if( nC(0) ==
'?' )
246 { ShowCurrent( nC ); }
247 else if( nC(0,4) ==
"hist" || nC ==
"history")
250 for(
int i=0;i<nh;i++)
253 else if( nC(0) ==
'!' )
258 std::istringstream is((
char*)tt);
268 {
G4cerr <<
"history " << vl <<
" is not found." <<
G4endl; }
270 else if( nC(0,4) ==
"exit" )
276 G4cerr <<
"Please abort it using \"/run/abort\" command first" <<
G4endl;
277 G4cerr <<
" and use \"continue\" command until the application" <<
G4endl;
280 G4cout <<
"@@ErrResult \"You are now processing RUN.\"" <<
G4endl;
286 newCommand = nullString;
290 else if( nC ==
"cont" || nC ==
"continue" )
293 newCommand = nullString;
299 return GetFullPath(newCommand);
308 if( newCommand(0) ==
'/' )
309 { tmpString = newCommand; }
310 else if( newCommand(0,3) ==
"../" )
313 unsigned i_direc = 0;
314 while( i_direc < newCommand.length() )
316 if( newCommand(i_direc,3) ==
"../" )
325 tmpString.
append( newCommand( i_direc, newCommand.length()-i_direc ) );
331 tmpString.
append( newCommand );
341void G4UIGAG::ShowCurrent(
const G4String& newCommand )
343 G4String theCommand = GetFullPath(newCommand.substr(1,newCommand.length()-1));
345 if( ! (curV.
isNull()||curV(0)==
'\0' ) ) {
347 G4cout <<
"Current value(s) of the parameter(s) : " << curV <<
G4endl;
354 G4cout <<
"@@ErrResult \"Current value is not available.\"" <<
G4endl;
358void G4UIGAG::ChangeDirectory(
const G4String& newCommand )
361 if( newCommand.length() <= 3 )
365 G4String aNewPrefix = newCommand.substr(3,newCommand.length()-3);
367 if( newPrefix(0) ==
'/' )
369 else if( newPrefix(0) !=
'.' )
374 {
prefix = ModifyPrefix( newPrefix ); }
378 if( FindDirPath(
prefix ) == NULL )
385void G4UIGAG::ListDirectory(
const G4String& newCommand )
388 if( newCommand.length() <= 3 )
392 G4String newPrefix = newCommand.substr(3,newCommand.length()-3);
394 if( newPrefix(0) ==
'/' )
395 { targetDir = newPrefix; }
396 else if( newPrefix(0) !=
'.' )
399 targetDir += newPrefix;
402 { targetDir = ModifyPrefix(newPrefix); }
404 if( targetDir( targetDir.length() - 1 ) !=
'/' )
405 { targetDir +=
"/"; }
407 if( commandTree == NULL )
408 {
G4cout <<
"Directory <" << targetDir <<
"> is not found." <<
G4endl; }
413void G4UIGAG::TerminalHelp(
const G4String& newCommand)
417 if( i != std::string::npos )
419 G4String newValue = newCommand.substr(i+1,newCommand.length()-(i+1));
421 if( newValue(0) !=
'/' )
424 if( theCommand != NULL )
431 G4cout <<
"Command <" << newValue <<
" is not found." <<
G4endl;
439 unsigned prefixIndex = 1;
440 while( prefixIndex <
prefix.length()-1 )
442 int ii =
prefix.index(
"/",prefixIndex);
452 G4cout <<
G4endl <<
"Type the number ( 0:end, -n:n level back ) : "<<std::flush;
456 G4cin.ignore(30,
'\n');
460 if( iFloor < 0 ) iFloor = 0;
462 else if(j == 0) {
break;}
467 if( j <= n_tree + floor[iFloor]->GetCommandEntry() )
475 floor[iFloor+1] = floor[iFloor]->
GetTree(i);
486 G4cin.getline( temp, 100 );
494 if( newCommand.substr(0,2) ==
".." )
496 if( newPrefix !=
"/" )
498 G4String tmpString = newPrefix(0,newPrefix.length()-1);
499 newPrefix = newPrefix(0,tmpString.
last(
'/')+1);
504 newPrefix += newCommand;
507 if( newCommand ==
".." || newCommand ==
"../" )
509 newCommand = newCommand.substr(3,newCommand.length()-3);
518 while( idx < newCommand.length()-1 )
520 int i = newCommand.
index(
"/",idx);
522 if( comTree == NULL )
539 CodeGenJavaTree(tree, 0);
541 CodeGenJavaParams(tree, 0);
544 CodeGenTclTree(tree,0);
546 CodeGenTclParams(tree, 0);
556 CodeGenJavaParams(tree, 0);
558 CodeGenTclParams(tree, 0);
564 int treeEntry, commandEntry;
569 for(
int i=0; i<commandEntry; i++){
573 if(treeEntry == 0)
return;
575 for(
int j=0; j<treeEntry; j++){
576 CodeGenJavaTree(tree->
GetTree(j+1), level+1);
582 int treeEntry, commandEntry, i;
589 for(i=0; i<commandEntry; i++) {
592 if( treeEntry == 0 )
return;
594 for(i=0; i< treeEntry; i++) {
599 CodeGenJavaParams(treeLink, level+1);
603void G4UIGAG::SendAParamProperty(
G4UIcommand * Comp)
605 int guidanceEntry, parameterEntry;
614 for (
int j=0; j<guidanceEntry; j++){
618 for(
int i=0; i< (int)title.length(); i++){
621 if ( c[0] ==
'\n' || c[0] ==
'\r') {
631 for(
int par=0; par<parameterEntry; par++) {
646 int treeEntry, commandEntry;
651 for(
int com=0; com<commandEntry; com++) {
657 if( treeEntry == 0 )
return;
659 for(
int i=0; i<treeEntry; i++) {
660 SendDisableList(tree->
GetTree(i+1), level+1);
670 int treeEntry, commandEntry, guidanceEntry;
673 G4String commandPath, pathName, title1, title2;
677 for(
int com=0; com<commandEntry; com++){
682 if (guidanceEntry == 0){
683 title2 =
"...Title not available...";
689 for(i=0; i< (int)title1.length(); i++){
695 }
else if ( c[0] ==
'\n' || c[0] ==
'\r') {
700 if (j >= guidanceEntry)
break;
704 G4cout << commandPath <<
" @@title \""<< title2 <<
"\""<<
G4endl;
707 if(treeEntry == 0)
return;
709 for(i=0; i< treeEntry; i++){
714 for(
int k=0; k<(int)title1.length(); k++){
724 G4cout << pathName <<
" @@title \"" << title1 <<
"\""<<
G4endl;
725 CodeGenTclTree(t, level+1);
731 int treeEntry, commandEntry;
736 for(
int com=0; com<commandEntry; com++) {
738 SendATclParamProperty(Comp);
740 if( treeEntry == 0 )
return;
742 for(
int i=0; i<treeEntry; i++) {
743 CodeGenTclParams(tree->
GetTree(i+1), level+1);
748void G4UIGAG::SendATclParamProperty(
G4UIcommand * Comp)
755 G4cout << commandPath <<
" @@param " << parameterEntry <<
G4endl;
756 G4cout <<
"@@command_range \"" << commandRange <<
"\"" <<
G4endl;
757 for(
int par=0; par<parameterEntry; par++) {
764 for(
int i=0; i<(int)guide1.length(); i++){
772 G4cout <<
" @@param_guide : \"" << guide2 <<
"\""<<
G4endl;
783void G4UIGAG::NotifyStateChange(
void)
790 G4cout <<
"@@State \"" << stateString <<
"\"" <<
G4endl;
792 SendDisableList(tree, 0);
797void G4UIGAG::NotifyCommandUpdate(
void)
800 SendCommandProperties(tree);
803void G4UIGAG::NotifyParameterUpdate(
G4UIcommand* com)
806 SendAParamProperty(com);
808 SendATclParamProperty(com);
812void G4UIGAG::UpdateState(
void)
818 if( newState != previousState )
821 previousState = newState;
825int G4UIGAG::CommandUpdated(
void)
828 int pEntry= previousTreeCommands.size();
829 int nEntry= newTreeCommands.size();
831 for( i=0; i<pEntry; i++) {
832 for( j=0; j<nEntry; j++) {
833 if( previousTreeCommands[i] == newTreeCommands[j])
break;
840 for( i=0; i<nEntry; i++) {
841 for( j=0; j<pEntry; j++) {
842 if( newTreeCommands[i] == previousTreeCommands[j])
break;
864 if( level==0 ) { newTreeCommands.clear();}
865 for(
int com=0; com<commandEntry; com++){
868 newTreeCommands.push_back( commandPath +
" " + title );
871 if(treeEntry == 0)
return;
873 for(
int i=0; i< treeEntry; i++){
877 newTreeCommands.push_back( pathName +
" " + title );
878 GetNewTreeStructure(t, level+1);
882void G4UIGAG::UpdateParamVal(
void)
887 int pEntry= previousTreeParams.size();
888 int nEntry= newTreeParams.size();
891 if (pEntry != nEntry)
return;
892 for( i=0; i<nEntry; i++) {
893 if( previousTreeParams[i] != newTreeParams[i]){
894 Comp = newTreePCP[i];
896 <<
" command is updated." <<
G4endl;
897 NotifyParameterUpdate(Comp);
946 if( level==0 ) { newTreeParams.clear(); }
947 for(
int com=0; com<commandEntry; com++) {
951 param = commandPath +
" ";
952 for(
int par=0; par< parameterEntry; par++) {
961 newTreeParams.push_back( param +
"\n");
962 newTreePCP.push_back( Comp );
964 if( treeEntry == 0 )
return;
965 for(
int i=0; i< treeEntry; i++) {
967 GetNewTreeValues(t, level+1);
std::string::size_type str_size
@ fParameterOutOfCandidates
@ fIllegalApplicationState
G4GLOB_DLL std::ostream G4cerr
G4GLOB_DLL std::ostream G4cout
const G4ApplicationState & GetCurrentState() const
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4String & remove(str_size)
G4String & append(const G4String &)
G4String & prepend(const char *)
str_size index(const char *, G4int pos=0) const
std::size_t last(char) const
G4String strip(G4int strip_Type=trailing, char c=' ')
std::istream & readLine(std::istream &, G4bool skipWhite=true)
void PauseSessionStart(const G4String &)
G4UIsession * SessionStart()
void Prompt(const G4String &)
G4int ReceiveG4cerr(const G4String &)
G4int ReceiveG4cout(const G4String &)
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
const G4String & GetPathName() const
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
void ListCurrentWithNum() const
const G4String GetTitle() const
G4UIcommand * FindPath(const char *commandPath) const
std::size_t GetParameterEntries() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
const G4String GetTitle() const
const G4String & GetCommandPath() const
std::size_t GetGuidanceEntries() const
const G4String & GetRange() const
void SetCoutDestination(G4UIsession *const value)
G4UIcommandTree * GetTree() const
G4int ApplyCommand(const char *aCommand)
G4int GetNumberOfHistory() const
G4String GetPreviousCommand(G4int i) const
G4String GetCurrentValues(const char *aCommand)
G4String SolveAlias(const char *aCmd)
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
const G4String & GetParameterCandidates() const
const G4String & GetParameterGuidance() const
G4bool IsOmittable() const
const G4String & GetParameterRange() const
char GetParameterType() const
const G4String & GetParameterName() const
const G4String & GetDefaultValue() const