ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4UIGAG.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4UIGAG.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 //
28 // G4UIGAG.cc
29 // 18.Feb.98 M.Nagamatu and T.Kodama created G4UIGAG from G4UIterminal
30 
31 #include "G4UIGAG.hh"
32 #include "G4StateManager.hh"
33 #include "G4UIcommandTree.hh"
34 #include "G4UIcommand.hh"
35 #include "G4UIcommandStatus.hh"
36 #include <sstream>
37 
38 G4UIGAG::G4UIGAG()//: TVersion("T1.0a"), JVersion("J1.0a")
39 {
40  TVersion="T1.0a"; JVersion="J1.0a";
41  //G4cout << "G4UIGAG: Apr15,98." << G4endl;
42  prefix = "/";
44  UI->SetSession(this);
45  UI->SetCoutDestination(this);
48  uiMode = terminal_mode; // GAG
49  iExit = false;
50  iCont = false;
51  // -- Initialize Notify routines begin
53  GetNewTreeStructure(tree,0);
54  GetNewTreeValues(tree,0);
58  // -- end
59 }
60 
62 {
63  if( G4UImanager::GetUIpointer() != 0)
64  {
65  UI->SetSession(NULL);
66  UI->SetCoutDestination(NULL);
67  // G4cout << "GAG session deleted" << G4endl;
68  }
69 }
70 
72 {
73  iExit = true;
76  G4String newCommand = GetCommand();
77  while( iExit )
78  {
79  ExecuteCommand(newCommand);
81  newCommand = GetCommand();
82  }
83  return NULL;
84 }
85 
87 {
88  promptCharacter = msg;
89  G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
90  iCont = true;
91  G4String newCommand = GetCommand();
92  while( iCont )
93  {
94  ExecuteCommand(newCommand);
95  newCommand = GetCommand();
96  }
97 }
98 
99 void G4UIGAG::ExecuteCommand(const G4String& aCommand)
100 {
102  if(aCommand.length()<2) return;
103  G4int returnVal = UI->ApplyCommand(aCommand);
104  G4int paramIndex = returnVal % 100;
105  G4int commandStatus = returnVal - paramIndex;
106 
107  UpdateState();
108  if ( uiMode == terminal_mode){
109  switch(commandStatus) {
110  case fCommandSucceeded:
111  break;
112  case fCommandNotFound:
113  // G4cerr << "command not found" << G4endl;
114  G4cerr << "command <" << UI->SolveAlias(aCommand) << "> not found" << G4endl;
115  break;
117  G4cerr << "illegal application state -- command refused" << G4endl;
118  break;
121  G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl;
122  break;
124  G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl;
125  // G4cerr << "Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates() << G4endl;
126  break;
127  case fAliasNotFound:
128  default:
129  G4cerr << "command refused (" << commandStatus << ")" << G4endl;
130  }
131  }else{
132  switch(commandStatus) {
133  case fCommandSucceeded:
134  {
135  GetNewTreeStructure(tree,0);
136  GetNewTreeValues(tree,0);
137  if (CommandUpdated()) {
139  } else {
140  UpdateParamVal(); // if param is updated, call notifyPara...
141  }
145  }
146  break;
147  case fCommandNotFound:
148  G4cout << "@@ErrResult \" <" << UI->SolveAlias(aCommand) << "> command not found.\"" << G4endl;
149  break;
151  G4cout << "@@ErrResult \"Illegal application state -- command refused\"" << G4endl;
152  break;
154  G4cout << "@@ErrResult \"Parameter Out of Range.\"" << G4endl;
155  break;
157  G4cout << "@@ErrResult \"Parameter is wrong type and/or is not omittable.\"" << G4endl;
158  break;
160 // G4cout << "@@ErrResult \"Parameter Out of Candidates. Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates()<< "\"" << G4endl;
161  G4cout << "@@ErrResult \"Parameter Out of Candidates.\"" << G4endl;
162  break;
163  case fAliasNotFound:
164  default:
165  G4cout << "@@ErrResult \"command refused (" << commandStatus << ")\"" << G4endl;
166  }
167  }
168 }
169 
170 
172 {
173  std::cout << coutString << std::flush;
174  return 0;
175 }
176 
178 {
179  std::cerr << cerrString << std::flush;
180  return 0;
181 }
182 
183 void G4UIGAG::Prompt(const G4String& aPrompt)
184 {
185  promptCharacter = aPrompt;
186 }
187 
189 {
190  G4String newCommand;
191  G4String nullString;
192  while( 1 )
193  {
195  if ( uiMode != terminal_mode ){
196  G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
197  }
198  if ( uiMode != java_mode ){
199  G4cout << promptCharacter << "> " << std::flush;
200  }else{
201  G4cout << "@@Ready" << G4endl;
202  }
203  newCommand.readLine( G4cin, FALSE );
204  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
205 
206  newCommand = newCommand.strip(G4String::leading);
207  if( newCommand.length() < 1) { break; }
208 
209  while( newCommand(newCommand.length()-1) == '_' )
210  {
211  G4String newLine;
212  newCommand.remove(newCommand.length()-1);
213  newLine.readLine( G4cin );
214  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
215  newCommand.append(newLine);
216  }
217 
218  G4String nC = newCommand.strip(G4String::leading);
219  if( nC.length() < 1) { break; }
220 
221  // -------------------- nC.toUpper();
222  if( nC == "@@GAGmodeJAVA" ) {
223  uiMode = java_mode;
224  G4cout << G4endl << "@@Version " << JVersion << G4endl;
225  SendCommandProperties(tree);
227  }
228  else if( nC == "@@GAGmodeTcl" ) {
229  uiMode = tcl_mode;
230  G4cout << G4endl << "@@Version " << TVersion << G4endl;
231  SendCommandProperties(tree);
233  }
234  else if( nC(0) == '#' )
235  { G4cout << nC << G4endl; }
236 
237  else if( nC == "ls" || nC(0,3) == "ls " )
238  { ListDirectory( nC ); }
239  else if( nC == "pwd" )
240  { G4cout << "Current Working Directory : " << prefix << G4endl; }
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")
248  {
249  G4int nh = UI->GetNumberOfHistory();
250  for(int i=0;i<nh;i++)
251  { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; }
252  }
253  else if( nC(0) == '!' )
254  {
255  G4String ss = nC(1,nC.length()-1);
256  G4int vl;
257  const char* tt = ss;
258  std::istringstream is((char*)tt);
259  is >> vl;
260  G4int nh = UI->GetNumberOfHistory();
261  if(vl>=0 && vl<nh)
262  {
263  newCommand = UI->GetPreviousCommand(vl);
264  G4cout << newCommand << G4endl;
265  break;
266  }
267  else
268  { G4cerr << "history " << vl << " is not found." << G4endl; }
269  }
270  else if( nC(0,4) == "exit" )
271  {
272  if( iCont )
273  {
274  if ( uiMode == terminal_mode){
275  G4cerr << "You are now processing RUN." << G4endl;
276  G4cerr << "Please abort it using \"/run/abort\" command first" << G4endl;
277  G4cerr << " and use \"continue\" command until the application" << G4endl;
278  G4cerr << " gets to Idle." << G4endl;
279  }else{
280  G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl;
281  }
282  }
283  else
284  {
285  iExit = false;
286  newCommand = nullString;
287  break;
288  }
289  }
290  else if( nC == "cont" || nC == "continue" )
291  {
292  iCont = false;
293  newCommand = nullString;
294  break;
295  }
296  else
297  { break; }
298  }
299  return GetFullPath(newCommand);
300 }
301 
303 {
304  G4String newCommand = aNewCommand;
305  newCommand.strip(G4String::both);
306 
307  G4String tmpString;
308  if( newCommand(0) == '/' )
309  { tmpString = newCommand; }
310  else if( newCommand(0,3) == "../" )
311  {
312  G4String tmpPrefix = prefix;
313  /*G4int*/ unsigned i_direc = 0;
314  while( i_direc < newCommand.length() )
315  {
316  if( newCommand(i_direc,3) == "../" )
317  {
318  i_direc += 3;
319  prefix = ModifyPrefix( G4String("../") );
320  }
321  else
322  { break; }
323  }
324  tmpString = prefix;
325  tmpString.append( newCommand( i_direc, newCommand.length()-i_direc ) );
326  prefix = tmpPrefix;
327  }
328  else
329  {
330  tmpString = prefix;
331  tmpString.append( newCommand );
332  }
333  return tmpString;
334 }
335 
337 {
338  G4cout << "***** Terminal session end *****" << G4endl;
339 }
340 
341 void G4UIGAG::ShowCurrent(const G4String& newCommand )
342 {
343  G4String theCommand = GetFullPath(newCommand.substr(1,newCommand.length()-1));
344  G4String curV = UI->GetCurrentValues(theCommand);
345  if( ! (curV.isNull()||curV(0)=='\0' ) ) {
346  if (uiMode == terminal_mode){
347  G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
348  }else{
349  G4cout << "@@CurrentValue " << curV << G4endl;
350  }
351  } else if (uiMode == terminal_mode){
352  G4cout << "Current value is not available." << G4endl;
353  } else {
354  G4cout << "@@ErrResult \"Current value is not available.\"" << G4endl;
355  }
356 }
357 
358 void G4UIGAG::ChangeDirectory(const G4String& newCommand )
359 {
360  G4String savedPrefix = prefix;
361  if( newCommand.length() <= 3 )
362  { prefix = "/"; }
363  else
364  {
365  G4String aNewPrefix = newCommand.substr(3,newCommand.length()-3);
366  G4String newPrefix = aNewPrefix.strip(G4String::both);
367  if( newPrefix(0) == '/' )
368  { prefix = newPrefix; }
369  else if( newPrefix(0) != '.' )
370  {
371  prefix += newPrefix;
372  }
373  else
374  { prefix = ModifyPrefix( newPrefix ); }
375  }
376  if( prefix( prefix.length() - 1 ) != '/' )
377  { prefix += "/"; }
378  if( FindDirPath( prefix ) == NULL )
379  {
380  G4cout << "Directory <" << prefix << "> is not found." << G4endl;
381  prefix = savedPrefix;
382  }
383 }
384 
385 void G4UIGAG::ListDirectory(const G4String& newCommand )
386 {
387  G4String targetDir('\0');
388  if( newCommand.length() <= 3 )
389  { targetDir = prefix; }
390  else
391  {
392  G4String newPrefix = newCommand.substr(3,newCommand.length()-3);
393  newPrefix.strip(G4String::both);
394  if( newPrefix(0) == '/' )
395  { targetDir = newPrefix; }
396  else if( newPrefix(0) != '.' )
397  {
398  targetDir = prefix;
399  targetDir += newPrefix;
400  }
401  else
402  { targetDir = ModifyPrefix(newPrefix); }
403  }
404  if( targetDir( targetDir.length() - 1 ) != '/' )
405  { targetDir += "/"; }
406  G4UIcommandTree * commandTree = FindDirPath( targetDir );
407  if( commandTree == NULL )
408  { G4cout << "Directory <" << targetDir << "> is not found." << G4endl; }
409  else
410  { commandTree->ListCurrent(); }
411 }
412 
413 void G4UIGAG::TerminalHelp(const G4String& newCommand)
414 {
415  G4UIcommandTree * treeTop = UI->GetTree();
416  /*int*/str_size i = newCommand.index(" ");
417  if( i != std::string::npos )
418  {
419  G4String newValue = newCommand.substr(i+1,newCommand.length()-(i+1));
420  newValue.strip(G4String::both);
421  if( newValue(0) != '/' )
422  { newValue.prepend( prefix ); }
423  G4UIcommand * theCommand = treeTop->FindPath( newValue );
424  if( theCommand != NULL )
425  {
426  theCommand->List();
427  return;
428  }
429  else
430  {
431  G4cout << "Command <" << newValue << " is not found." << G4endl;
432  return;
433  }
434  }
435 
436  G4UIcommandTree * floor[10];
437  floor[0] = treeTop;
438  int iFloor = 0;
439  /*int*/ unsigned prefixIndex = 1;
440  while( prefixIndex < prefix.length()-1 )
441  {
442  int ii = prefix.index("/",prefixIndex);
443  floor[iFloor+1] =
444  floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
445  prefixIndex = ii+1;
446  iFloor++;
447  }
448  floor[iFloor]->ListCurrentWithNum();
449  // 1998 Oct 2 non-number input
450  while(1){
451  int j;
452  G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
453  G4cin >> j;
454  if(!G4cin.good()){
455  G4cin.clear();
456  G4cin.ignore(30,'\n');
457  G4cout << G4endl << "Not a number, once more" << G4endl; continue;}
458  else if( j < 0 ){
459  iFloor += j;
460  if( iFloor < 0 ) iFloor = 0;
461  floor[iFloor]->ListCurrentWithNum(); continue;}
462  else if(j == 0) { break;}
463  else if( j > 0 ) {
464  int n_tree = floor[iFloor]->GetTreeEntry();
465  if( j > n_tree )
466  {
467  if( j <= n_tree + floor[iFloor]->GetCommandEntry() )
468  {
469  floor[iFloor]->GetCommand(i-n_tree)->List();
470  //iFloor++;
471  }
472  }
473  else
474  {
475  floor[iFloor+1] = floor[iFloor]->GetTree(i);
476  iFloor++;
477  floor[iFloor]->ListCurrentWithNum();
478  }
479  }
480 
481  }
482  G4cout << "Exit from HELP." << G4endl << G4endl;
483  G4cout << G4endl;
484  // G4cin.flush();
485  char temp[100];
486  G4cin.getline( temp, 100 );
487 }
488 
490 {
491  G4String newPrefix = prefix;
492  while( 1 )
493  {
494  if( newCommand.substr(0,2) == ".." )
495  {
496  if( newPrefix != "/" )
497  {
498  G4String tmpString = newPrefix(0,newPrefix.length()-1);
499  newPrefix = newPrefix(0,tmpString.last('/')+1);
500  }
501  }
502  else
503  {
504  newPrefix += newCommand;
505  break;
506  }
507  if( newCommand == ".." || newCommand == "../" )
508  { break; }
509  newCommand = newCommand.substr(3,newCommand.length()-3);
510  }
511  return newPrefix;
512 }
513 
515 {
516  G4UIcommandTree * comTree = UI->GetTree();
517  /*int*/ unsigned idx = 1;
518  while( idx < newCommand.length()-1 )
519  {
520  int i = newCommand.index("/",idx);
521  comTree = comTree->GetTree(G4String(newCommand.substr(0,i+1)));
522  if( comTree == NULL )
523  { return NULL; }
524  idx = i+1;
525  }
526  return comTree;
527 }
528 
529 // ----- for JAVA GAG (by T.Kodama)
530 
532 {
533  if( tree == NULL ) {
534  G4cerr << "GetTree() returnes null." << G4endl;
535  return;
536  }
537  if (uiMode == java_mode){
538  G4cout << "@@JTreeBegin" << G4endl;
539  CodeGenJavaTree(tree, 0);
540  G4cout << "@@JTreeEnd" << G4endl;
541  CodeGenJavaParams(tree, 0);
542  }else{
543  G4cout << G4endl << "@@maketree_start" << G4endl;
544  CodeGenTclTree(tree,0);
545  G4cout << "@@maketree_end" << G4endl;
546  CodeGenTclParams(tree, 0);
547  }
548 }
550 {
551  if( tree == NULL ) {
552  G4cerr << "GetTree() returnes null." << G4endl;
553  return;
554  }
555  if (uiMode == java_mode){
556  CodeGenJavaParams(tree, 0);
557  }else{
558  CodeGenTclParams(tree, 0);
559  }
560 }
561 
563 {
564  int treeEntry, commandEntry;
565  treeEntry = tree->GetTreeEntry();
566  commandEntry = tree->GetCommandEntry();
567 
568  if(level!=0) {
569  for(int i=0; i<commandEntry; i++){
570  G4cout << tree->GetCommand(i+1)->GetCommandPath() << G4endl;
571  }
572  }
573  if(treeEntry == 0) return; //end recursion
574 
575  for(int j=0; j<treeEntry; j++){
576  CodeGenJavaTree(tree->GetTree(j+1), level+1);
577  }
578 }
579 
580 void G4UIGAG::CodeGenJavaParams(G4UIcommandTree * tree, int level) //recursive
581 {
582  int treeEntry, commandEntry, i;
583  //G4UIcommand * Comp;
584  G4UIcommandTree * treeLink;
585 
586  treeEntry = tree->GetTreeEntry();
587  commandEntry = tree->GetCommandEntry();
588 
589  for(i=0; i<commandEntry; i++) {
590  SendAParamProperty(tree->GetCommand(i+1));
591  }
592  if( treeEntry == 0 ) return; // end recursion
593 
594  for(i=0; i< treeEntry; i++) {
595  treeLink = tree->GetTree(i+1);
596  G4cout << "@@JDirGuideBegin" << G4endl;
597  G4cout << treeLink->GetPathName() << G4endl << treeLink->GetTitle() << G4endl;
598  G4cout << "@@JDirGuideEnd" << G4endl;
599  CodeGenJavaParams(treeLink, level+1);
600  }
601 }
602 
604 {
605  int guidanceEntry, parameterEntry;
606  G4String title, title2;
607  G4UIparameter * prp;
608  char c[2];
609  guidanceEntry = Comp->GetGuidanceEntries();
610  parameterEntry = Comp->GetParameterEntries();
611  G4cout << "@@JParamBegin" << G4endl;
612  G4cout << Comp->GetCommandPath() << G4endl;
613  G4cout << guidanceEntry << G4endl;
614  for (int j=0; j<guidanceEntry; j++){
615  title = Comp->GetGuidanceLine(j);
616  title2 = "";
617  if (title != ""){
618  for(int i=0; i< (int)title.length(); i++){
619  c[0]=title(i);
620  c[1]= '\0';
621  if ( c[0] == '\n' || c[0] == '\r') {
622  c[0]= ' ';
623  }
624  title2.append(c);
625  }
626  }
627  G4cout << title2 << G4endl;
628  }
629  G4cout << Comp->GetRange() << G4endl;
630  G4cout << parameterEntry << G4endl;
631  for( int par=0; par<parameterEntry; par++) {
632  prp = (G4UIparameter *)Comp->GetParameter(par);
633  G4cout << prp->GetParameterName() << G4endl;
634  G4cout << prp->GetParameterGuidance() << G4endl;
635  G4cout << prp->GetParameterType() << G4endl;
636  G4cout << prp->IsOmittable() << G4endl;
637  G4cout << prp->GetDefaultValue() << G4endl;
638  G4cout << prp->GetParameterRange() << G4endl;
639  G4cout << prp->GetParameterCandidates() << G4endl;
640  }
641  G4cout << "@@JParamEnd" << G4endl;
642 }
643 
645 {
646  int treeEntry, commandEntry;
647  G4UIcommand * Comp;
648  treeEntry = tree->GetTreeEntry();
649  commandEntry = tree->GetCommandEntry();
650 
651  for(int com=0; com<commandEntry; com++) {
652  Comp = tree->GetCommand(com+1);
653  if( Comp->IsAvailable()==false ) {
654  G4cout << Comp->GetCommandPath()<<G4endl;
655  }
656  }
657  if( treeEntry == 0 ) return; // end recursion
658 
659  for( int i=0; i<treeEntry; i++) {
660  SendDisableList(tree->GetTree(i+1), level+1);
661  // be sure the function name is the same
662  }
663 }
664 
665 // ----- for Tcl GAG
666 
668 {
669  int i, j;
670  int treeEntry, commandEntry, guidanceEntry;
671  treeEntry = tree->GetTreeEntry();
672  commandEntry = tree->GetCommandEntry();
673  G4String commandPath, pathName, title1, title2;
674  G4UIcommandTree * t;
675  G4UIcommand * Comp;
676 
677  for(int com=0; com<commandEntry; com++){
678  Comp = tree->GetCommand(com+1);
679  commandPath = Comp->GetCommandPath();
680  G4cout << commandPath << " @@command" << G4endl;
681  guidanceEntry = Comp->GetGuidanceEntries();
682  if (guidanceEntry == 0){
683  title2 = "...Title not available...";
684  } else {
685  title2 = "";
686  j = 0;
687  while(1){
688  title1 = Comp->GetGuidanceLine(j);
689  for(i=0; i< (int)title1.length(); i++){
690  char c[2];
691  c[0]=title1(i);
692  c[1]= '\0';
693  if( c[0] == '\"') {
694  title2.append("\\\""); // a Backslash and a double quote
695  } else if ( c[0] == '\n' || c[0] == '\r') {
696  title2.append("\\n");
697  } else title2.append(c);
698  }
699  j++;
700  if (j >= guidanceEntry) break;
701  title2.append("\\n");
702  }
703  }
704  G4cout << commandPath << " @@title \""<< title2 <<"\""<< G4endl;
705  }
706 
707  if(treeEntry == 0) return; //end recursion
708 
709  for(i=0; i< treeEntry; i++){
710  t = tree->GetTree(i+1);
711  pathName = t->GetPathName();
712  title1 = t->GetTitle();
713  title2 = "";
714  for(int k=0; k<(int)title1.length(); k++){
715  char c[2];
716  c[0]=title1(k);
717  c[1]= '\0';
718  if( c[0] == '\"')
719  title2.append("\\\""); // a Backslash and a double quote
720  else title2.append(c);
721  }
722  if(level==0) G4cout << pathName<< G4endl;
723  else G4cout << pathName<< " @@cascade"<<G4endl;
724  G4cout << pathName << " @@title \"" << title1 << "\""<<G4endl;
725  CodeGenTclTree(t, level+1);
726  }
727 }
728 
729 void G4UIGAG::CodeGenTclParams( G4UIcommandTree * tree, int level) // recursive
730 {
731  int treeEntry, commandEntry;
732  G4UIcommand * Comp;
733  treeEntry = tree->GetTreeEntry();
734  commandEntry = tree->GetCommandEntry();
735 
736  for(int com=0; com<commandEntry; com++) {
737  Comp = tree->GetCommand(com+1);
738  SendATclParamProperty(Comp);
739  }
740  if( treeEntry == 0 ) return; // end recursion
741 
742  for( int i=0; i<treeEntry; i++) {
743  CodeGenTclParams(tree->GetTree(i+1), level+1);
744  // be sure the function name is the same
745  }
746 }
747 
749 {
750  G4UIparameter * prp;
751  int parameterEntry = Comp->GetParameterEntries();
752  G4String commandPath = Comp->GetCommandPath();
753  G4String commandRange = Comp->GetRange();
754  G4cout << "@@parameter_start" << G4endl;
755  G4cout << commandPath << " @@param " << parameterEntry << G4endl;
756  G4cout << "@@command_range \"" << commandRange << "\"" << G4endl;
757  for( int par=0; par<parameterEntry; par++) {
758  prp = (G4UIparameter *)Comp->GetParameter(par);
759  G4cout << "{" ;
760  G4cout << "@@param_name : \"" << prp->GetParameterName() <<"\""<<G4endl;
761  G4String guide1,guide2;
762  guide1 = prp->GetParameterGuidance();
763  guide2 = "";
764  for(int i=0; i<(int)guide1.length(); i++){
765  char c[2];
766  c[0]=guide1(i);
767  c[1]= '\0';
768  if( c[0] == '\"')
769  guide2.append("\\\""); // a Backslash and a double quote
770  else guide2.append(c);
771  }
772  G4cout << " @@param_guide : \"" << guide2 << "\""<<G4endl;
773  G4cout << " @@param_type : \"" << prp->GetParameterType()<<"\""<<G4endl;
774  G4cout << " @@param_omit : \"" << prp->IsOmittable()<<"\""<<G4endl;
775  G4cout << " @@param_default : \""<< prp->GetDefaultValue()<<"\""<<G4endl;
776  G4cout << " @@param_range : \""<< prp->GetParameterRange()<<"\""<<G4endl;
777  G4cout << " @@param_candidate : \"" << prp->GetParameterCandidates()<< "\""<<G4endl;
778  G4cout << "}" << G4endl;
779  }
780  G4cout << "@@parameter_end" << G4endl;
781 }
782 
784 {
785  G4String stateString;
788  stateString = statM->GetStateString(statM->GetCurrentState());
789  if ( uiMode != terminal_mode ){
790  G4cout << "@@State \"" << stateString << "\"" << G4endl;
791  G4cout << "@@DisableListBegin"<<G4endl;
792  SendDisableList(tree, 0);
793  G4cout << "@@DisableListEnd" <<G4endl;
794  }
795 }
796 
798 {
800  SendCommandProperties(tree);
801 }
802 
804 {
805  if (uiMode == java_mode)
806  SendAParamProperty(com);
807  else
809 }
810 
811 //####### update check routines ####################################
813 {
814  static G4ThreadLocal G4ApplicationState *previousState_G4MT_TLS_ = 0 ; if (!previousState_G4MT_TLS_) {previousState_G4MT_TLS_ = new G4ApplicationState ; *previousState_G4MT_TLS_= G4State_PreInit ; } G4ApplicationState &previousState = *previousState_G4MT_TLS_;
815  G4ApplicationState newState;
817  newState = statM->GetCurrentState();
818  if( newState != previousState )
819  {
821  previousState = newState;
822  }
823 }
824 
826 {
827  int added=0, deleted=0;
828  int pEntry= previousTreeCommands.size();
829  int nEntry= newTreeCommands.size();
830  int i,j;
831  for( i=0; i<pEntry; i++) { // check deleted command(s)
832  for( j=0; j<nEntry; j++) {
833  if( previousTreeCommands[i] == newTreeCommands[j]) break;
834  }
835  if( j==nEntry ) {
836  deleted = 1;
837  //G4cout <<"deleted: "<< previousTreeCommands(i) << G4endl;
838  }
839  }
840  for( i=0; i<nEntry; i++) { // check added command(s)
841  for( j=0; j<pEntry; j++) {
842  if( newTreeCommands[i] == previousTreeCommands[j]) break;
843  }
844  if( j==pEntry ) {
845  added = 1;
846  // G4cout <<"added: "<< newTreeCommands(i) << G4endl;
847  }
848  }
849  if( added && deleted==0 ) {G4cout<<"c added"<<G4endl;return added;}
850  if( added==0 && deleted ) {G4cout<<"c deleted"<<G4endl;return deleted;}
851  if( added && deleted ) {G4cout<<"c add/deleted"<<G4endl;return addedAndDeleted;}
852  return notChanged;
853 }
854 
856 {
857  G4String commandPath;
858  G4String title;
859  G4String pathName; //tree name
860  G4UIcommandTree * t;
861  int treeEntry = tree->GetTreeEntry();
862  int commandEntry = tree->GetCommandEntry();
863 
864  if( level==0 ) { newTreeCommands.clear();}
865  for(int com=0; com<commandEntry; com++){
866  commandPath = tree->GetCommand(com+1)->GetCommandPath();
867  title = tree->GetCommand(com+1)->GetTitle();
868  newTreeCommands.push_back( commandPath + " " + title );
869  }
870 
871  if(treeEntry == 0) return; //end recursion
872 
873  for(int i=0; i< treeEntry; i++){
874  t = tree->GetTree(i+1);
875  pathName = t->GetPathName();
876  title = t->GetTitle();
877  newTreeCommands.push_back( pathName + " " + title );
878  GetNewTreeStructure(t, level+1);
879  }
880 }
881 
883 {
884  // call NotifyParameterUpdate() if the value of each
885  // command/parameter is updated.
886  // assuming the command structure is not changed.
887  int pEntry= previousTreeParams.size();
888  int nEntry= newTreeParams.size();
889  int i;
890  G4UIcommand* Comp;
891  if (pEntry != nEntry) return;
892  for( i=0; i<nEntry; i++) {
893  if( previousTreeParams[i] != newTreeParams[i]){
894  Comp = newTreePCP[i];
895  G4cout << Comp->GetCommandPath()
896  << " command is updated." <<G4endl;
897  NotifyParameterUpdate(Comp);
898  }
899  }
900 }
901 
902 //void G4UIGAG::paramUpdate(void)
903 //{
904 // int added=0, deleted=0;
905 // int pEntry= previousTreeParams.entries();
906 // int nEntry= newTreeParams.entries();
907 // int i,j;
908 //
909 // if (pEntry != nEntry) return NULL;
910 // for( i=0; i<pEntry; i++) { // check deleted param(s)
911 // for( j=0; j<nEntry; j++) {
912 // if( previousTreeParams(i) == newTreeParams(j)) break;
913 // }
914 // if( j==nEntry ) {
915 // deleted = 1;
916 // //G4cout <<"para deleted: "<< previousTreeParams(i) << G4endl;
917 // }
918 // }
919 // for( i=0; i<nEntry; i++) { // check added param(s)
920 // for( j=0; j<pEntry; j++) {
921 // if( newTreeParams(i) == previousTreeParams(j)) break;
922 // }
923 // if( j==pEntry ) {
924 // added = 1;
925 // //G4cout <<"para added: "<< newTreeParams(i) << G4endl;
926 // }
927 // }
928 // if( added && deleted==0 ) {G4cout<<"p added"<<G4endl;return added;}
929 // if( added==0 && deleted ) {G4cout<<"p deleted"<<G4endl;return deleted;}
930 // if( added && deleted ) {G4cout<<"p add/deleted"<<G4endl; return addedAndDeleted;}
931 // return notChanged;
932 //}
933 
934 void G4UIGAG::GetNewTreeValues( G4UIcommandTree * tree, int level) // recursive
935 {
936  G4String commandPath;
937  G4String pathName; //tree name
938  G4UIcommandTree * t;
939  int parameterEntry;
940  int treeEntry = tree->GetTreeEntry();
941  int commandEntry = tree->GetCommandEntry();
942  G4UIcommand * Comp;
943  G4UIparameter * prp;
944  G4String param, str(" ");
945 
946  if( level==0 ) { newTreeParams.clear(); }
947  for(int com=0; com<commandEntry; com++) {
948  Comp = tree->GetCommand(com+1);
949  commandPath = Comp->GetCommandPath();
950  parameterEntry = Comp->GetParameterEntries();
951  param = commandPath +" ";
952  for( int par=0; par< parameterEntry; par++) {
953  prp = (G4UIparameter *)Comp->GetParameter(par);
954  param += prp->GetParameterName() +" ";
955  str(0) = prp->GetParameterType();
956  param += str + " ";
957  param += prp->GetDefaultValue() +" ";
958  param += prp->GetParameterRange() +" ";
959  param += prp->GetParameterCandidates();
960  }
961  newTreeParams.push_back( param + "\n");
962  newTreePCP.push_back( Comp );
963  }
964  if( treeEntry == 0 ) return; // end recursion
965  for( int i=0; i< treeEntry; i++) {
966  t = tree->GetTree(i+1);
967  GetNewTreeValues(t, level+1);
968  }
969 }
970 //######################################################