00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include "G4UIGAG.hh"
00034 #include "G4StateManager.hh"
00035 #include "G4UIcommandTree.hh"
00036 #include "G4UIcommand.hh"
00037 #include "G4UIcommandStatus.hh"
00038 #include <sstream>
00039
00040 G4UIGAG::G4UIGAG()
00041 {
00042 TVersion="T1.0a"; JVersion="J1.0a";
00043
00044 prefix = "/";
00045 UI = G4UImanager::GetUIpointer();
00046 UI->SetSession(this);
00047 UI->SetCoutDestination(this);
00048 G4StateManager * statM = G4StateManager::GetStateManager();
00049 promptCharacter = statM->GetStateString(statM->GetCurrentState());
00050 uiMode = terminal_mode;
00051 iExit = false;
00052 iCont = false;
00053
00054 G4UIcommandTree * tree = UI->GetTree();
00055 GetNewTreeStructure(tree,0);
00056 GetNewTreeValues(tree,0);
00057 previousTreeCommands = newTreeCommands;
00058 previousTreeParams = newTreeParams;
00059 previousTreePCP = newTreePCP;
00060
00061 }
00062
00063 G4UIGAG::~G4UIGAG()
00064 {
00065 if( G4UImanager::GetUIpointer() != 0)
00066 {
00067 UI->SetSession(NULL);
00068 UI->SetCoutDestination(NULL);
00069
00070 }
00071 }
00072
00073 G4UIsession * G4UIGAG::SessionStart()
00074 {
00075 iExit = true;
00076 G4StateManager * statM = G4StateManager::GetStateManager();
00077 promptCharacter = statM->GetStateString(statM->GetCurrentState());
00078 G4String newCommand = GetCommand();
00079 while( iExit )
00080 {
00081 ExecuteCommand(newCommand);
00082 promptCharacter = statM->GetStateString(statM->GetCurrentState());
00083 newCommand = GetCommand();
00084 }
00085 return NULL;
00086 }
00087
00088 void G4UIGAG::PauseSessionStart(G4String msg)
00089 {
00090 promptCharacter = msg;
00091 G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
00092 iCont = true;
00093 G4String newCommand = GetCommand();
00094 while( iCont )
00095 {
00096 ExecuteCommand(newCommand);
00097 newCommand = GetCommand();
00098 }
00099 }
00100
00101 void G4UIGAG::ExecuteCommand(G4String aCommand)
00102 {
00103 G4UIcommandTree * tree = UI->GetTree();
00104 if(aCommand.length()<2) return;
00105 G4int returnVal = UI->ApplyCommand(aCommand);
00106 G4int paramIndex = returnVal % 100;
00107 G4int commandStatus = returnVal - paramIndex;
00108
00109 UpdateState();
00110 if ( uiMode == terminal_mode){
00111 switch(commandStatus) {
00112 case fCommandSucceeded:
00113 break;
00114 case fCommandNotFound:
00115
00116 G4cerr << "command <" << UI->SolveAlias(aCommand) << "> not found" << G4endl;
00117 break;
00118 case fIllegalApplicationState:
00119 G4cerr << "illegal application state -- command refused" << G4endl;
00120 break;
00121 case fParameterOutOfRange:
00122 case fParameterUnreadable:
00123 G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl;
00124 break;
00125 case fParameterOutOfCandidates:
00126 G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl;
00127
00128 break;
00129 case fAliasNotFound:
00130 default:
00131 G4cerr << "command refused (" << commandStatus << ")" << G4endl;
00132 }
00133 }else{
00134 switch(commandStatus) {
00135 case fCommandSucceeded:
00136 {
00137 GetNewTreeStructure(tree,0);
00138 GetNewTreeValues(tree,0);
00139 if (CommandUpdated()) {
00140 NotifyCommandUpdate();
00141 } else {
00142 UpdateParamVal();
00143 }
00144 previousTreeCommands = newTreeCommands;
00145 previousTreeParams = newTreeParams;
00146 previousTreePCP = newTreePCP;
00147 }
00148 break;
00149 case fCommandNotFound:
00150 G4cout << "@@ErrResult \" <" << UI->SolveAlias(aCommand) << "> command not found.\"" << G4endl;
00151 break;
00152 case fIllegalApplicationState:
00153 G4cout << "@@ErrResult \"Illegal application state -- command refused\"" << G4endl;
00154 break;
00155 case fParameterOutOfRange:
00156 G4cout << "@@ErrResult \"Parameter Out of Range.\"" << G4endl;
00157 break;
00158 case fParameterUnreadable:
00159 G4cout << "@@ErrResult \"Parameter is wrong type and/or is not omittable.\"" << G4endl;
00160 break;
00161 case fParameterOutOfCandidates:
00162
00163 G4cout << "@@ErrResult \"Parameter Out of Candidates.\"" << G4endl;
00164 break;
00165 case fAliasNotFound:
00166 default:
00167 G4cout << "@@ErrResult \"command refused (" << commandStatus << ")\"" << G4endl;
00168 }
00169 }
00170 }
00171
00172
00173 G4int G4UIGAG::ReceiveG4cout(G4String coutString)
00174 {
00175 std::cout << coutString << std::flush;
00176 return 0;
00177 }
00178
00179 G4int G4UIGAG::ReceiveG4cerr(G4String cerrString)
00180 {
00181 std::cerr << cerrString << std::flush;
00182 return 0;
00183 }
00184
00185 void G4UIGAG::Prompt(G4String aPrompt)
00186 {
00187 promptCharacter = aPrompt;
00188 }
00189
00190 G4String G4UIGAG::GetCommand()
00191 {
00192 G4String newCommand;
00193 G4String nullString;
00194 while( 1 )
00195 {
00196 G4UIcommandTree* tree = UI->GetTree();
00197 if ( uiMode != terminal_mode ){
00198 G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
00199 }
00200 if ( uiMode != java_mode ){
00201 G4cout << promptCharacter << "> " << std::flush;
00202 }else{
00203 G4cout << "@@Ready" << G4endl;
00204 }
00205 newCommand.readLine( G4cin, FALSE );
00206 if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
00207
00208 newCommand = newCommand.strip(G4String::leading);
00209 if( newCommand.length() < 1) { break; }
00210
00211 while( newCommand(newCommand.length()-1) == '_' )
00212 {
00213 G4String newLine;
00214 newCommand.remove(newCommand.length()-1);
00215 newLine.readLine( G4cin );
00216 if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
00217 newCommand.append(newLine);
00218 }
00219
00220 G4String nC = newCommand.strip(G4String::leading);
00221 if( nC.length() < 1) { break; }
00222
00223
00224 if( nC == "@@GAGmodeJAVA" ) {
00225 uiMode = java_mode;
00226 G4cout << G4endl << "@@Version " << JVersion << G4endl;
00227 SendCommandProperties(tree);
00228 NotifyStateChange();
00229 }
00230 else if( nC == "@@GAGmodeTcl" ) {
00231 uiMode = tcl_mode;
00232 G4cout << G4endl << "@@Version " << TVersion << G4endl;
00233 SendCommandProperties(tree);
00234 NotifyStateChange();
00235 }
00236 else if( nC(0) == '#' )
00237 { G4cout << nC << G4endl; }
00238
00239 else if( nC == "ls" || nC(0,3) == "ls " )
00240 { ListDirectory( nC ); }
00241 else if( nC == "pwd" )
00242 { G4cout << "Current Working Directory : " << prefix << G4endl; }
00243 else if( nC(0,2) == "cd" || nC(0,3) == "cd " )
00244 { ChangeDirectory( nC ); }
00245 else if( nC == "help" || nC(0,5) == "help ")
00246 { TerminalHelp( nC ); }
00247 else if( nC(0) == '?' )
00248 { ShowCurrent( nC ); }
00249 else if( nC(0,4) == "hist" || nC == "history")
00250 {
00251 G4int nh = UI->GetNumberOfHistory();
00252 for(int i=0;i<nh;i++)
00253 { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; }
00254 }
00255 else if( nC(0) == '!' )
00256 {
00257 G4String ss = nC(1,nC.length()-1);
00258 G4int vl;
00259 const char* tt = ss;
00260 std::istringstream is((char*)tt);
00261 is >> vl;
00262 G4int nh = UI->GetNumberOfHistory();
00263 if(vl>=0 && vl<nh)
00264 {
00265 newCommand = UI->GetPreviousCommand(vl);
00266 G4cout << newCommand << G4endl;
00267 break;
00268 }
00269 else
00270 { G4cerr << "history " << vl << " is not found." << G4endl; }
00271 }
00272 else if( nC(0,4) == "exit" )
00273 {
00274 if( iCont )
00275 {
00276 if ( uiMode == terminal_mode){
00277 G4cerr << "You are now processing RUN." << G4endl;
00278 G4cerr << "Please abrot it using \"/run/abort\" command first" << G4endl;
00279 G4cerr << " and use \"continue\" command until the application" << G4endl;
00280 G4cerr << " becomes to Idle." << G4endl;
00281 }else{
00282 G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl;
00283 }
00284 }
00285 else
00286 {
00287 iExit = false;
00288 newCommand = nullString;
00289 break;
00290 }
00291 }
00292 else if( nC == "cont" || nC == "continue" )
00293 {
00294 iCont = false;
00295 newCommand = nullString;
00296 break;
00297 }
00298 else
00299 { break; }
00300 }
00301 return GetFullPath(newCommand);
00302 }
00303
00304 G4String G4UIGAG::GetFullPath( G4String aNewCommand )
00305 {
00306 G4String newCommand = aNewCommand.strip(G4String::both);
00307 G4String tmpString;
00308 if( newCommand(0) == '/' )
00309 { tmpString = newCommand; }
00310 else if( newCommand(0,3) == "../" )
00311 {
00312 G4String tmpPrefix = prefix;
00313 unsigned i_direc = 0;
00314 while( i_direc < newCommand.length() )
00315 {
00316 if( newCommand(i_direc,3) == "../" )
00317 {
00318 i_direc += 3;
00319 prefix = ModifyPrefix( G4String("../") );
00320 }
00321 else
00322 { break; }
00323 }
00324 tmpString = prefix;
00325 tmpString.append( newCommand( i_direc, newCommand.length()-i_direc ) );
00326 prefix = tmpPrefix;
00327 }
00328 else
00329 {
00330 tmpString = prefix;
00331 tmpString.append( newCommand );
00332 }
00333 return tmpString;
00334 }
00335
00336 void G4UIGAG::SessionTerminate()
00337 {
00338 G4cout << "***** Terminal session end *****" << G4endl;
00339 }
00340
00341 void G4UIGAG::ShowCurrent( G4String newCommand )
00342 {
00343 G4String theCommand = GetFullPath(newCommand(1,newCommand.length()-1));
00344 G4String curV = UI->GetCurrentValues(theCommand);
00345 if( ! (curV.isNull()||curV(0)=='\0' ) ) {
00346 if (uiMode == terminal_mode){
00347 G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
00348 }else{
00349 G4cout << "@@CurrentValue " << curV << G4endl;
00350 }
00351 } else if (uiMode == terminal_mode){
00352 G4cout << "Current value is not available." << G4endl;
00353 } else {
00354 G4cout << "@@ErrResult \"Current value is not available.\"" << G4endl;
00355 }
00356 }
00357
00358 void G4UIGAG::ChangeDirectory( G4String newCommand )
00359 {
00360 G4String savedPrefix = prefix;
00361 if( newCommand.length() <= 3 )
00362 { prefix = "/"; }
00363 else
00364 {
00365 G4String aNewPrefix = newCommand(3,newCommand.length()-3);
00366 G4String newPrefix = aNewPrefix.strip(G4String::both);
00367 if( newPrefix(0) == '/' )
00368 { prefix = newPrefix; }
00369 else if( newPrefix(0) != '.' )
00370 {
00371 prefix += newPrefix;
00372 }
00373 else
00374 { prefix = ModifyPrefix( newPrefix ); }
00375 }
00376 if( prefix( prefix.length() - 1 ) != '/' )
00377 { prefix += "/"; }
00378 if( FindDirPath( prefix ) == NULL )
00379 {
00380 G4cout << "Directory <" << prefix << "> is not found." << G4endl;
00381 prefix = savedPrefix;
00382 }
00383 }
00384
00385 void G4UIGAG::ListDirectory( G4String newCommand )
00386 {
00387 G4String targetDir('\0');
00388 if( newCommand.length() <= 3 )
00389 { targetDir = prefix; }
00390 else
00391 {
00392 G4String newPrefix = newCommand(3,newCommand.length()-3);
00393 newPrefix.strip(G4String::both);
00394 if( newPrefix(0) == '/' )
00395 { targetDir = newPrefix; }
00396 else if( newPrefix(0) != '.' )
00397 {
00398 targetDir = prefix;
00399 targetDir += newPrefix;
00400 }
00401 else
00402 { targetDir = ModifyPrefix( newPrefix ); }
00403 }
00404 if( targetDir( targetDir.length() - 1 ) != '/' )
00405 { targetDir += "/"; }
00406 G4UIcommandTree * commandTree = FindDirPath( targetDir );
00407 if( commandTree == NULL )
00408 { G4cout << "Directory <" << targetDir << "> is not found." << G4endl; }
00409 else
00410 { commandTree->ListCurrent(); }
00411 }
00412
00413 void G4UIGAG::TerminalHelp(G4String newCommand)
00414 {
00415 G4UIcommandTree * treeTop = UI->GetTree();
00416 unsigned i = newCommand.index(" ");
00417 if( i != std::string::npos )
00418 {
00419 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
00420 newValue.strip(G4String::both);
00421 if( newValue(0) != '/' )
00422 { newValue.prepend( prefix ); }
00423 G4UIcommand * theCommand = treeTop->FindPath( newValue );
00424 if( theCommand != NULL )
00425 {
00426 theCommand->List();
00427 return;
00428 }
00429 else
00430 {
00431 G4cout << "Command <" << newValue << " is not found." << G4endl;
00432 return;
00433 }
00434 }
00435
00436 G4UIcommandTree * floor[10];
00437 floor[0] = treeTop;
00438 int iFloor = 0;
00439 unsigned prefixIndex = 1;
00440 while( prefixIndex < prefix.length()-1 )
00441 {
00442 int ii = prefix.index("/",prefixIndex);
00443 floor[iFloor+1] =
00444 floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
00445 prefixIndex = ii+1;
00446 iFloor++;
00447 }
00448 floor[iFloor]->ListCurrentWithNum();
00449
00450 while(1){
00451 int i;
00452 G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
00453 G4cin >> i;
00454 if(!G4cin.good()){
00455 G4cin.clear();
00456 G4cin.ignore(30,'\n');
00457 G4cout << G4endl << "Not a number, once more" << G4endl; continue;}
00458 else if( i < 0 ){
00459 iFloor += i;
00460 if( iFloor < 0 ) iFloor = 0;
00461 floor[iFloor]->ListCurrentWithNum(); continue;}
00462 else if(i == 0) { break;}
00463 else if( i > 0 ) {
00464 int n_tree = floor[iFloor]->GetTreeEntry();
00465 if( i > n_tree )
00466 {
00467 if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
00468 {
00469 floor[iFloor]->GetCommand(i-n_tree)->List();
00470
00471 }
00472 }
00473 else
00474 {
00475 floor[iFloor+1] = floor[iFloor]->GetTree(i);
00476 iFloor++;
00477 floor[iFloor]->ListCurrentWithNum();
00478 }
00479 }
00480
00481 }
00482 G4cout << "Exit from HELP." << G4endl << G4endl;
00483 G4cout << G4endl;
00484
00485 char temp[100];
00486 G4cin.getline( temp, 100 );
00487 }
00488
00489
00490
00491
00492
00493
00494
00495 G4String G4UIGAG::ModifyPrefix(G4String newCommand)
00496 {
00497 G4String newPrefix = prefix;
00498 while( 1 )
00499 {
00500 if( newCommand(0,2) == ".." )
00501 {
00502 if( newPrefix != "/" )
00503 {
00504 G4String tmpString = newPrefix(0,newPrefix.length()-1);
00505 newPrefix = newPrefix(0,tmpString.last('/')+1);
00506 }
00507 }
00508 else
00509 {
00510 newPrefix += newCommand;
00511 break;
00512 }
00513 if( newCommand == ".." || newCommand == "../" )
00514 { break; }
00515 newCommand = newCommand(3,newCommand.length()-3);
00516 }
00517 return newPrefix;
00518 }
00519
00520 G4UIcommandTree * G4UIGAG::FindDirPath(G4String newCommand)
00521 {
00522 G4UIcommandTree * comTree = UI->GetTree();
00523 unsigned idx = 1;
00524 while( idx < newCommand.length()-1 )
00525 {
00526 int i = newCommand.index("/",idx);
00527 comTree = comTree->GetTree(G4String(newCommand(0,i+1)));
00528 if( comTree == NULL )
00529 { return NULL; }
00530 idx = i+1;
00531 }
00532 return comTree;
00533 }
00534
00535
00536
00537 void G4UIGAG::SendCommandProperties(G4UIcommandTree * tree)
00538 {
00539 if( tree == NULL ) {
00540 G4cerr << "GetTree() returnes null." << G4endl;
00541 return;
00542 }
00543 if (uiMode == java_mode){
00544 G4cout << "@@JTreeBegin" << G4endl;
00545 CodeGenJavaTree(tree, 0);
00546 G4cout << "@@JTreeEnd" << G4endl;
00547 CodeGenJavaParams(tree, 0);
00548 }else{
00549 G4cout << G4endl << "@@maketree_start" << G4endl;
00550 CodeGenTclTree(tree,0);
00551 G4cout << "@@maketree_end" << G4endl;
00552 CodeGenTclParams(tree, 0);
00553 }
00554 }
00555 void G4UIGAG::SendParameterProperties(G4UIcommandTree * tree)
00556 {
00557 if( tree == NULL ) {
00558 G4cerr << "GetTree() returnes null." << G4endl;
00559 return;
00560 }
00561 if (uiMode == java_mode){
00562 CodeGenJavaParams(tree, 0);
00563 }else{
00564 CodeGenTclParams(tree, 0);
00565 }
00566 }
00567
00568 void G4UIGAG::CodeGenJavaTree(G4UIcommandTree * tree, int level)
00569 {
00570 int treeEntry, commandEntry;
00571 treeEntry = tree->GetTreeEntry();
00572 commandEntry = tree->GetCommandEntry();
00573
00574 if(level!=0) {
00575 for(int i=0; i<commandEntry; i++){
00576 G4cout << tree->GetCommand(i+1)->GetCommandPath() << G4endl;
00577 }
00578 }
00579 if(treeEntry == 0) return;
00580
00581 for(int j=0; j<treeEntry; j++){
00582 CodeGenJavaTree(tree->GetTree(j+1), level+1);
00583 }
00584 }
00585
00586 void G4UIGAG::CodeGenJavaParams(G4UIcommandTree * tree, int level)
00587 {
00588 int treeEntry, commandEntry, i;
00589
00590 G4UIcommandTree * treeLink;
00591
00592 treeEntry = tree->GetTreeEntry();
00593 commandEntry = tree->GetCommandEntry();
00594
00595 for(i=0; i<commandEntry; i++) {
00596 SendAParamProperty(tree->GetCommand(i+1));
00597 }
00598 if( treeEntry == 0 ) return;
00599
00600 for(i=0; i< treeEntry; i++) {
00601 treeLink = tree->GetTree(i+1);
00602 G4cout << "@@JDirGuideBegin" << G4endl;
00603 G4cout << treeLink->GetPathName() << G4endl << treeLink->GetTitle() << G4endl;
00604 G4cout << "@@JDirGuideEnd" << G4endl;
00605 CodeGenJavaParams(treeLink, level+1);
00606 }
00607 }
00608
00609 void G4UIGAG::SendAParamProperty(G4UIcommand * Comp)
00610 {
00611 int guidanceEntry, parameterEntry;
00612 G4String title, title2;
00613 G4UIparameter * prp;
00614 char c[2];
00615 guidanceEntry = Comp->GetGuidanceEntries();
00616 parameterEntry = Comp->GetParameterEntries();
00617 G4cout << "@@JParamBegin" << G4endl;
00618 G4cout << Comp->GetCommandPath() << G4endl;
00619 G4cout << guidanceEntry << G4endl;
00620 for (int j=0; j<guidanceEntry; j++){
00621 title = Comp->GetGuidanceLine(j);
00622 title2 = "";
00623 if (title != ""){
00624 for(int i=0; i< (int)title.length(); i++){
00625 c[0]=title(i);
00626 c[1]= '\0';
00627 if ( c[0] == '\n' || c[0] == '\r') {
00628 c[0]= ' ';
00629 }
00630 title2.append(c);
00631 }
00632 }
00633 G4cout << title2 << G4endl;
00634 }
00635 G4cout << Comp->GetRange() << G4endl;
00636 G4cout << parameterEntry << G4endl;
00637 for( int par=0; par<parameterEntry; par++) {
00638 prp = (G4UIparameter *)Comp->GetParameter(par);
00639 G4cout << prp->GetParameterName() << G4endl;
00640 G4cout << prp->GetParameterGuidance() << G4endl;
00641 G4cout << prp->GetParameterType() << G4endl;
00642 G4cout << prp->IsOmittable() << G4endl;
00643 G4cout << prp->GetDefaultValue() << G4endl;
00644 G4cout << prp->GetParameterRange() << G4endl;
00645 G4cout << prp->GetParameterCandidates() << G4endl;
00646 }
00647 G4cout << "@@JParamEnd" << G4endl;
00648 }
00649
00650 void G4UIGAG::SendDisableList(G4UIcommandTree * tree, int level)
00651 {
00652 int treeEntry, commandEntry;
00653 G4UIcommand * Comp;
00654 treeEntry = tree->GetTreeEntry();
00655 commandEntry = tree->GetCommandEntry();
00656
00657 for(int com=0; com<commandEntry; com++) {
00658 Comp = tree->GetCommand(com+1);
00659 if( Comp->IsAvailable()==false ) {
00660 G4cout << Comp->GetCommandPath()<<G4endl;
00661 }
00662 }
00663 if( treeEntry == 0 ) return;
00664
00665 for( int i=0; i<treeEntry; i++) {
00666 SendDisableList(tree->GetTree(i+1), level+1);
00667
00668 }
00669 }
00670
00671
00672
00673 void G4UIGAG::CodeGenTclTree(G4UIcommandTree * tree, int level)
00674 {
00675 int i, j;
00676 int treeEntry, commandEntry, guidanceEntry;
00677 treeEntry = tree->GetTreeEntry();
00678 commandEntry = tree->GetCommandEntry();
00679 G4String commandPath, pathName, title1, title2;
00680 G4UIcommandTree * t;
00681 G4UIcommand * Comp;
00682
00683 for(int com=0; com<commandEntry; com++){
00684 Comp = tree->GetCommand(com+1);
00685 commandPath = Comp->GetCommandPath();
00686 G4cout << commandPath << " @@command" << G4endl;
00687 guidanceEntry = Comp->GetGuidanceEntries();
00688 if (guidanceEntry == 0){
00689 title2 = "...Title not available...";
00690 } else {
00691 title2 = "";
00692 j = 0;
00693 while(1){
00694 title1 = Comp->GetGuidanceLine(j);
00695 for(i=0; i< (int)title1.length(); i++){
00696 char c[2];
00697 c[0]=title1(i);
00698 c[1]= '\0';
00699 if( c[0] == '\"') {
00700 title2.append("\\\"");
00701 } else if ( c[0] == '\n' || c[0] == '\r') {
00702 title2.append("\\n");
00703 } else title2.append(c);
00704 }
00705 j++;
00706 if (j >= guidanceEntry) break;
00707 title2.append("\\n");
00708 }
00709 }
00710 G4cout << commandPath << " @@title \""<< title2 <<"\""<< G4endl;
00711 }
00712
00713 if(treeEntry == 0) return;
00714
00715 for(i=0; i< treeEntry; i++){
00716 t = tree->GetTree(i+1);
00717 pathName = t->GetPathName();
00718 title1 = t->GetTitle();
00719 title2 = "";
00720 for(int i=0; i<(int)title1.length(); i++){
00721 char c[2];
00722 c[0]=title1(i);
00723 c[1]= '\0';
00724 if( c[0] == '\"')
00725 title2.append("\\\"");
00726 else title2.append(c);
00727 }
00728 if(level==0) G4cout << pathName<< G4endl;
00729 else G4cout << pathName<< " @@cascade"<<G4endl;
00730 G4cout << pathName << " @@title \"" << title1 << "\""<<G4endl;
00731 CodeGenTclTree(t, level+1);
00732 }
00733 }
00734
00735 void G4UIGAG::CodeGenTclParams( G4UIcommandTree * tree, int level)
00736 {
00737 int treeEntry, commandEntry;
00738 G4UIcommand * Comp;
00739 treeEntry = tree->GetTreeEntry();
00740 commandEntry = tree->GetCommandEntry();
00741
00742 for(int com=0; com<commandEntry; com++) {
00743 Comp = tree->GetCommand(com+1);
00744 SendATclParamProperty(Comp);
00745 }
00746 if( treeEntry == 0 ) return;
00747
00748 for( int i=0; i<treeEntry; i++) {
00749 CodeGenTclParams(tree->GetTree(i+1), level+1);
00750
00751 }
00752 }
00753
00754 void G4UIGAG::SendATclParamProperty(G4UIcommand * Comp)
00755 {
00756 G4UIparameter * prp;
00757 int parameterEntry = Comp->GetParameterEntries();
00758 G4String commandPath = Comp->GetCommandPath();
00759 G4String commandRange = Comp->GetRange();
00760 G4cout << "@@parameter_start" << G4endl;
00761 G4cout << commandPath << " @@param " << parameterEntry << G4endl;
00762 G4cout << "@@command_range \"" << commandRange << "\"" << G4endl;
00763 for( int par=0; par<parameterEntry; par++) {
00764 prp = (G4UIparameter *)Comp->GetParameter(par);
00765 G4cout << "{" ;
00766 G4cout << "@@param_name : \"" << prp->GetParameterName() <<"\""<<G4endl;
00767 G4String guide1,guide2;
00768 guide1 = prp->GetParameterGuidance();
00769 guide2 = "";
00770 for(int i=0; i<(int)guide1.length(); i++){
00771 char c[2];
00772 c[0]=guide1(i);
00773 c[1]= '\0';
00774 if( c[0] == '\"')
00775 guide2.append("\\\"");
00776 else guide2.append(c);
00777 }
00778 G4cout << " @@param_guide : \"" << guide2 << "\""<<G4endl;
00779 G4cout << " @@param_type : \"" << prp->GetParameterType()<<"\""<<G4endl;
00780 G4cout << " @@param_omit : \"" << prp->IsOmittable()<<"\""<<G4endl;
00781 G4cout << " @@param_default : \""<< prp->GetDefaultValue()<<"\""<<G4endl;
00782 G4cout << " @@param_range : \""<< prp->GetParameterRange()<<"\""<<G4endl;
00783 G4cout << " @@param_candidate : \"" << prp->GetParameterCandidates()<< "\""<<G4endl;
00784 G4cout << "}" << G4endl;
00785 }
00786 G4cout << "@@parameter_end" << G4endl;
00787 }
00788
00789 void G4UIGAG::NotifyStateChange(void)
00790 {
00791 G4String stateString;
00792 G4StateManager * statM = G4StateManager::GetStateManager();
00793 G4UIcommandTree * tree = UI->GetTree();
00794 stateString = statM->GetStateString(statM->GetCurrentState());
00795 if ( uiMode != terminal_mode ){
00796 G4cout << "@@State \"" << stateString << "\"" << G4endl;
00797 G4cout << "@@DisableListBegin"<<G4endl;
00798 SendDisableList(tree, 0);
00799 G4cout << "@@DisableListEnd" <<G4endl;
00800 }
00801 }
00802
00803 void G4UIGAG::NotifyCommandUpdate(void)
00804 {
00805 G4UIcommandTree * tree = UI->GetTree();
00806 SendCommandProperties(tree);
00807 }
00808
00809 void G4UIGAG::NotifyParameterUpdate(G4UIcommand* com)
00810 {
00811 if (uiMode == java_mode)
00812 SendAParamProperty(com);
00813 else
00814 SendATclParamProperty(com);
00815 }
00816
00817
00818 void G4UIGAG::UpdateState(void)
00819 {
00820 static G4ApplicationState previousState= G4State_PreInit;
00821 G4ApplicationState newState;
00822 G4StateManager *statM = G4StateManager::GetStateManager();
00823 newState = statM->GetCurrentState();
00824 if( newState != previousState )
00825 {
00826 NotifyStateChange();
00827 previousState = newState;
00828 }
00829 }
00830
00831 int G4UIGAG::CommandUpdated(void)
00832 {
00833 int added=0, deleted=0;
00834 int pEntry= previousTreeCommands.size();
00835 int nEntry= newTreeCommands.size();
00836 int i,j;
00837 for( i=0; i<pEntry; i++) {
00838 for( j=0; j<nEntry; j++) {
00839 if( previousTreeCommands[i] == newTreeCommands[j]) break;
00840 }
00841 if( j==nEntry ) {
00842 deleted = 1;
00843
00844 }
00845 }
00846 for( i=0; i<nEntry; i++) {
00847 for( j=0; j<pEntry; j++) {
00848 if( newTreeCommands[i] == previousTreeCommands[j]) break;
00849 }
00850 if( j==pEntry ) {
00851 added = 1;
00852
00853 }
00854 }
00855 if( added && deleted==0 ) {G4cout<<"c added"<<G4endl;return added;}
00856 if( added==0 && deleted ) {G4cout<<"c deleted"<<G4endl;return deleted;}
00857 if( added && deleted ) {G4cout<<"c add/deleted"<<G4endl;return addedAndDeleted;}
00858 return notChanged;
00859 }
00860
00861 void G4UIGAG::GetNewTreeStructure(G4UIcommandTree * tree, int level)
00862 {
00863 G4String commandPath;
00864 G4String title;
00865 G4String pathName;
00866 G4UIcommandTree * t;
00867 int treeEntry = tree->GetTreeEntry();
00868 int commandEntry = tree->GetCommandEntry();
00869
00870 if( level==0 ) { newTreeCommands.clear();}
00871 for(int com=0; com<commandEntry; com++){
00872 commandPath = tree->GetCommand(com+1)->GetCommandPath();
00873 title = tree->GetCommand(com+1)->GetTitle();
00874 newTreeCommands.push_back( commandPath + " " + title );
00875 }
00876
00877 if(treeEntry == 0) return;
00878
00879 for(int i=0; i< treeEntry; i++){
00880 t = tree->GetTree(i+1);
00881 pathName = t->GetPathName();
00882 title = t->GetTitle();
00883 newTreeCommands.push_back( pathName + " " + title );
00884 GetNewTreeStructure(t, level+1);
00885 }
00886 }
00887
00888 void G4UIGAG::UpdateParamVal(void)
00889 {
00890
00891
00892
00893 int pEntry= previousTreeParams.size();
00894 int nEntry= newTreeParams.size();
00895 int i;
00896 G4UIcommand* Comp;
00897 if (pEntry != nEntry) return;
00898 for( i=0; i<nEntry; i++) {
00899 if( previousTreeParams[i] != newTreeParams[i]){
00900 Comp = newTreePCP[i];
00901 G4cout << Comp->GetCommandPath()
00902 << " command is updated." <<G4endl;
00903 NotifyParameterUpdate(Comp);
00904 }
00905 }
00906 }
00907
00908
00909
00910
00911
00912
00913
00914
00915
00916
00917
00918
00919
00920
00921
00922
00923
00924
00925
00926
00927
00928
00929
00930
00931
00932
00933
00934
00935
00936
00937
00938
00939
00940 void G4UIGAG::GetNewTreeValues( G4UIcommandTree * tree, int level)
00941 {
00942 G4String commandPath;
00943 G4String pathName;
00944 G4UIcommandTree * t;
00945 int parameterEntry;
00946 int treeEntry = tree->GetTreeEntry();
00947 int commandEntry = tree->GetCommandEntry();
00948 G4UIcommand * Comp;
00949 G4UIparameter * prp;
00950 G4String param, str(" ");
00951
00952 if( level==0 ) { newTreeParams.clear(); }
00953 for(int com=0; com<commandEntry; com++) {
00954 Comp = tree->GetCommand(com+1);
00955 commandPath = Comp->GetCommandPath();
00956 parameterEntry = Comp->GetParameterEntries();
00957 param = commandPath +" ";
00958 for( int par=0; par< parameterEntry; par++) {
00959 prp = (G4UIparameter *)Comp->GetParameter(par);
00960 param += prp->GetParameterName() +" ";
00961 str(0) = prp->GetParameterType();
00962 param += str + " ";
00963 param += prp->GetDefaultValue() +" ";
00964 param += prp->GetParameterRange() +" ";
00965 param += prp->GetParameterCandidates();
00966 }
00967 newTreeParams.push_back( param + "\n");
00968 newTreePCP.push_back( Comp );
00969 }
00970 if( treeEntry == 0 ) return;
00971 for( int i=0; i< treeEntry; i++) {
00972 t = tree->GetTree(i+1);
00973 GetNewTreeValues(t, level+1);
00974 }
00975 }
00976