Geant4  10.03
G4UIGainServer.cc
Go to the documentation of this file.
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 // 12/06/2002 G4UIGainServer H. MInamimoto and H. Yoshida created
28 // $Id: G4UIGainServer.cc 66892 2013-01-17 10:57:59Z gunter $
29 //
30 #ifndef WIN32
31 
32 #include "G4UIGainServer.hh"
33 #include <netdb.h>
34 
35 #include <sstream>
36 #include "G4StateManager.hh"
37 #include "G4UIcommandTree.hh"
38 #include "G4UIcommand.hh"
39 #include "G4UIcommandStatus.hh"
40 
41 
45 {
46  TVersion ="T1.0a"; JVersion="J1.0a";
47  prefix = "/";
48 
50  while(SetUPServer() == false){
51  G4cout<<"can't get the port no. "<<port<<" Now, try to get the next port "<<port+1<<G4endl;
52  port++;
53  }
54 
55 
57  UI-> SetSession(this);
58  UI-> SetCoutDestination(this);
59 
63 
64  iExit= FALSE;
65  iCont= FALSE;
66 
67  G4UIcommandTree* tree = UI->GetTree();
68  GetNewTreeStructure(tree,0);
69  GetNewTreeValues(tree,0);
73 
74 }
75 
78 {
80 
82  UI-> SetSession(NULL);
83  UI-> SetCoutDestination(NULL);
84  }
85 
87  UI->SetSession(NULL);
88  UI->SetCoutDestination(NULL);
89  }
90 }
91 
92 
96 {
97  G4String newCommand;
98 
101 
102  iExit= TRUE;
103 
105  while(iExit){
106  newCommand= GetCommand();
107  ExecuteCommand(newCommand);
108  }
109  return NULL;
110 }
111 
115 {
116  promptCharacter = msg;
117  G4cout<<"@@PROMPT \""<<promptCharacter<<"\""<<G4endl;
118 
119  iCont= TRUE;
120 
121  G4String newCommand= GetCommand();
122  while(iCont){
123  ExecuteCommand(newCommand);
124  newCommand= GetCommand();
125  strcpy(buf,"nowIdle");
126  write(socketD[1],buf,strlen(buf));
127  }
128 }
129 
133 {
134  if(aCommand.length()<2) return;
135 
136  G4UIcommandTree* tree = UI->GetTree();
137  if(aCommand.length()<2) return;
138  G4int returnVal = UI->ApplyCommand(aCommand);
139  G4int paramIndex = returnVal % 100;
140  // 0 - 98 : paramIndex-th parameter is invalid
141  // 99 : convination of parameters is invalid
142  G4int commandStatus = returnVal - paramIndex;
143 
144  UpdateState();
145 
146  if(uiMode != terminal_mode){
147  switch(commandStatus) {
148  case fCommandSucceeded:
149  GetNewTreeStructure(tree,0);
150  GetNewTreeValues(tree,0);
151  if(CommandUpdated()){
153  } else{
154  UpdateParamVal();
155  }
159  break;
160  case fCommandNotFound:
161  G4cerr << "@@ErrResult \" <" << UI->SolveAlias(aCommand) << "> not found.\"" << G4endl;
162  break;
164  G4cerr << "@@ErrResult \"illegal application state -- command refused.\"" << G4endl;
165  break;
167  G4cout << "@@ErrResult \"Parameter Out of Range.\"" << G4endl;
168  break;
170  G4cout << "@@ErrResult \"Parameter is wrong type and/or is not omittable.\""<<G4endl;
171  break;
173  G4cerr << "@@ErrResult \"Parameter is out of candidate.\"" << G4endl;
174  break;
175  case fAliasNotFound:
176  default:
177  G4cerr << "command refused (" << commandStatus << ")" << G4endl;
178  }
179  }
180 }
181 
185 {
186  G4String newCommand;
187  G4String nullString;
188 
189  while( 1 )
190  {
191  G4UIcommandTree* tree = UI->GetTree();
192  if ( uiMode != terminal_mode ){
193  G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl;
194  }
195  if ( uiMode != java_mode ){
196  G4cout << promptCharacter << "> " << G4endl;
197  }else{
198  G4cout << "@@Ready" << G4endl;
199  }
200 
201 
204  read(socketD[1],buf,1024);
205  newCommand=buf;
206  //DEBUG cout<<"->"<<newCommand<<"<-"<<newCommand.length()<<G4endl;
207  //newCommand.readLine( G4cin, FALSE );
210 
211 
212 
213  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
214 
215  newCommand = newCommand.strip(G4String::leading);
216  if( newCommand.length() < 1) { break; }
217 
218  while( newCommand(newCommand.length()-1) == '_' )
219  {
220  G4String newLine;
221  newCommand.remove(newCommand.length()-1);
222  newLine.readLine( G4cin );
223  if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;}
224  newCommand.append(newLine);
225  }
226 
227  G4String nC = newCommand.strip(G4String::leading);
228  if( nC.length() < 1) { break; }
229 
230  // -------------------- nC.toUpper();
231  if( nC == "@@GainmodeJAVA" ) {
232  uiMode = java_mode;
233  G4cout << G4endl << "@@Version " << JVersion << G4endl;
234  SendCommandProperties(tree);
236  }
237  else if( nC == "@@GainmodeTcl" ) {
238  uiMode = tcl_mode;
239  G4cout << G4endl << "@@Version " << TVersion << G4endl;
240  SendCommandProperties(tree);
242  }
243  else if( nC(0) == '#' )
244  { G4cout << nC << G4endl; }
245 
246  else if( nC == "ls" || nC(0,3) == "ls " )
247  { ListDirectory( nC ); }
248  else if( nC == "pwd" )
249  { G4cout << "Current Working Directory : " << prefix << G4endl; }
250  else if( nC(0,2) == "cd" || nC(0,3) == "cd " )
251  { ChangeDirectory( nC ); }
252  else if( nC == "help" || nC(0,5) == "help ")
253  { TerminalHelp( nC ); }
254  else if( nC(0) == '?' )
255  { ShowCurrent( nC ); }
256  else if( nC(0,4) == "hist" || nC == "history")
257  {
258  G4int nh = UI->GetNumberOfHistory();
259  for(int i=0;i<nh;i++)
260  { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; }
261  }
262  else if( nC(0) == '!' )
263  {
264  G4String ss = nC(1,nC.length()-1);
265  G4int vl;
266  const char* tt = ss;
267  std::istringstream is((char*)tt);
268  is >> vl;
269  G4int nh = UI->GetNumberOfHistory();
270  if(vl>=0 && vl<nh)
271  {
272  newCommand = UI->GetPreviousCommand(vl);
273  G4cout << newCommand << G4endl;
274  break;
275  }
276  else
277  { G4cerr << "history " << vl << " is not found." << G4endl; }
278  }
279  else if( nC(0,4) == "exit" )
280  {
281  if( iCont )
282  {
283  if ( uiMode == terminal_mode){
284  G4cerr << "You are now processing RUN." << G4endl;
285  G4cerr << "Please abrot it using \"/run/abort\" command first" << G4endl;
286  G4cerr << " and use \"continue\" command until the application" << G4endl;
287  G4cerr << " becomes to Idle." << G4endl;
288  }else{
289  G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl;
290  }
291  }
292  else
293  {
294  close(socketD[1]);
295  close(socketD[2]);
296  iExit = false;
297  newCommand = nullString;
298  break;
299  }
300  }
301  else if( nC == "cont" || nC == "continue" )
302  {
303  iCont = false;
304  newCommand = nullString;
305  break;
306  }
307  else
308  { break; }
309  }
310  return GetFullPath(newCommand);
311 }
312 
316 {
317  if(socketD[1]>0){
318  write(socketD[1],coutString,coutString.length());
319  }
320  return 0;
321 
322  //std::cout << coutString << std::flush;
323  //return 0;
324 }
325 
329 {
330  if(socketD[2]>0){
331  write(socketD[2],cerrString,cerrString.length());
332  }
333  return 0;
334 
335  //std::cerr << cerrString << std::flush;
336  //return 0;
337 }
338 
342 {
343  G4cin >> aInt;
344  if(!G4cin.good()){
345  G4cin.clear();
346  G4cin.ignore(30,'\n');
347  return FALSE;
348  }
349  return TRUE;
350 }
351 
355 {
356  char temp[100];
357  G4cin.getline(temp, 100);
358 }
359 
363 
364  socketD[0] = socket(AF_INET,SOCK_STREAM,0);
365 
366  if(socketD[0]<0){
367  perror("server:socket");
368  return (false);
369  //exit(1);
370  }
371 
372  memset( (char *)&saddr,'\0',sizeof(saddr)) ;
373 
374  saddr.sin_family = AF_INET;
375  saddr.sin_addr.s_addr = INADDR_ANY;
376  saddr.sin_port = htons(port);
377  unlink(SOCK_NAME);
378 
379  if(bind(socketD[0] , (struct sockaddr *)&saddr , sizeof(saddr))<0){
380  perror("bind");
381  return (false);
382  //exit(1);
383  }
384  else{ G4cout<<"G4GainServer waiting at "<<port<<G4endl; }
385 
386  if(listen(socketD[0],1)<0){
387  perror("listen");
388  return (false);
389  //exit(1);
390  }
391 
392  return (true);
393 }
394 
398  len = sizeof(caddr);
399 
400  for(int i=1;i<=2;i++){
401 #if defined __APPLE__ && (__GNUC__<4)
402  if((socketD[i] = accept(socketD[0], (struct sockaddr *)&caddr,(int *)&len))<0){
403 #else
404  if((socketD[i] = accept(socketD[0], (struct sockaddr *)&caddr,(socklen_t *)&len))<0){
405 #endif
406  G4cerr<<"accept:"<<i<<G4endl;
407  //exit(1);
408  G4Exception("G4UIGainServer::WaitingConnection()",
409  "UI0004",
411  "Invalid Socket. Cannot establish connection");
412  }
413  }
414  close(socketD[0]);
415 }
416 
420  G4String newCommand = aNewCommand.strip(G4String::both);
421  G4String tmpString;
422  if( newCommand(0) == '/' )
423  { tmpString = newCommand; }
424  else if( newCommand(0,3) == "../" )
425  {
426  G4String tmpPrefix = prefix;
427  /*G4int*/ unsigned i_direc = 0;
428  while( i_direc < newCommand.length() )
429  {
430  if( newCommand(i_direc,3) == "../" )
431  {
432  i_direc += 3;
433  prefix = ModifyPrefix( G4String("../") );
434  }
435  else
436  { break; }
437  }
438  tmpString = prefix;
439  tmpString.append( newCommand( i_direc, newCommand.length()-i_direc ) );
440  prefix = tmpPrefix;
441  }
442  else
443  {
444  tmpString = prefix;
445  tmpString.append( newCommand );
446  }
447  return tmpString;
448 }
449 
453  G4cout<<"***** Terminal session end *****"<<G4endl;
454 }
455 
456 
460  G4String theCommand = GetFullPath(newCommand(1,newCommand.length()-1));
461  G4String curV = UI->GetCurrentValues(theCommand);
462  if( ! (curV.isNull()||curV(0)=='\0' ) ) {
463  if (uiMode == terminal_mode){
464  G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl;
465  }else{
466  G4cout << "@@CurrentValue " << curV << G4endl;
467  }
468  } else if (uiMode == terminal_mode){
469  G4cout << "Current value is not available." << G4endl;
470  } else {
471  G4cout << "@@ErrResult \"Current value is not available.\"" << G4endl;
472  }
473 }
474 
478  G4String savedPrefix = prefix;
479  if( newCommand.length() <= 3 )
480  { prefix = "/"; }
481  else
482  {
483  G4String aNewPrefix = newCommand(3,newCommand.length()-3);
484  G4String newPrefix = aNewPrefix.strip(G4String::both);
485  if( newPrefix(0) == '/' )
486  { prefix = newPrefix; }
487  else if( newPrefix(0) != '.' )
488  {
489  prefix += newPrefix;
490  }
491  else
492  { prefix = ModifyPrefix( newPrefix ); }
493  }
494  if( prefix( prefix.length() - 1 ) != '/' )
495  { prefix += "/"; }
496  if( FindDirPath( prefix ) == NULL )
497  {
498  G4cout << "Directory <" << prefix << "> is not found." << G4endl;
499  prefix = savedPrefix;
500  }
501 }
505  G4String targetDir('\0');
506  if( newCommand.length() <= 3 )
507  { targetDir = prefix; }
508  else
509  {
510  G4String newPrefix = newCommand(3,newCommand.length()-3);
511  newPrefix.strip(G4String::both);
512  if( newPrefix(0) == '/' )
513  { targetDir = newPrefix; }
514  else if( newPrefix(0) != '.' )
515  {
516  targetDir = prefix;
517  targetDir += newPrefix;
518  }
519  else
520  { targetDir = ModifyPrefix( newPrefix ); }
521  }
522  if( targetDir( targetDir.length() - 1 ) != '/' )
523  { targetDir += "/"; }
524  G4UIcommandTree * commandTree = FindDirPath( targetDir );
525  if( commandTree == NULL )
526  { G4cout << "Directory <" << targetDir << "> is not found." << G4endl; }
527  else
528  { commandTree->ListCurrent(); }
529 }
530 
534  G4UIcommandTree* treeTop = UI->GetTree();
535  str_size i = newCommand.index(" ");
536 
537  if(i!=std::string::npos){
538  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
539  newValue.strip(G4String::both);
540  if(newValue(0)!='/'){
541  newValue.prepend(prefix);
542  }
543  G4UIcommand* theCommand = treeTop->FindPath(newValue);
544  if(theCommand !=NULL){
545  theCommand->List();
546  return;
547  }
548  else{
549  G4cout<<"Command<" << newValue << "is not found."<<G4endl;
550  return;
551  }
552  }
553 
554  G4UIcommandTree* floor[10];
555  floor[0] = treeTop;
556  int iFloor = 0;
557  unsigned prefixIndex = 1;
558  while(prefixIndex<prefix.length()-1){
559  int ii = prefix.index("/",prefixIndex);
560  floor[iFloor+1]=
561  floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
562  prefixIndex = ii+1;
563  iFloor++;
564  }
565  floor[iFloor]->ListCurrentWithNum();
566  while(1){
567  int j;
568  G4cout<<G4endl <<"Type the number (0:end, -n:n level back) :"<<std::flush;
569  G4cin >> j;
570  if(!G4cin.good()){
571  G4cin.clear();
572  G4cin.ignore(30,'\n');
573  G4cout<<G4endl <<"Not a number,once more"<<G4endl; continue;
574  }
575  else if(j<0){
576  iFloor += j;
577  if(iFloor <0) iFloor =0;
578  floor[iFloor]->ListCurrentWithNum(); continue;
579  }
580  else if(j==0){break;}
581  else if(j>0){
582  int n_tree = floor[iFloor]->GetTreeEntry();
583  if(j>n_tree){
584  if(j<=n_tree+floor[iFloor]->GetCommandEntry()){
585  floor[iFloor]->GetCommand(j-n_tree)->List();
586  }
587  }
588  else{
589  floor[iFloor+1] = floor[iFloor]->GetTree(j);
590  iFloor++;
591  floor[iFloor]->ListCurrentWithNum();
592  }
593  }
594  }
595  G4cout<<"Exit from Help."<<G4endl <<G4endl;
596  G4cout<<G4endl;
597  char temp[100];
598  G4cin.getline(temp,100);
599 }
600 
601 
605  G4String newPrefix = prefix;
606  while(1){
607  if(newCommand(0,2) ==".."){
608  if(newPrefix !="/"){
609  G4String tmpString = newPrefix(0,newPrefix.length()-1);
610  newPrefix = newPrefix(0,tmpString.last('/')+1);
611  }
612  }
613  else{
614  newPrefix += newCommand;
615  break;
616  }
617  if(newCommand == ".." || newCommand == "../"){
618  break;
619  }
620  newCommand=newCommand(3,newCommand.length()-3);
621  }
622  return newPrefix;
623 }
624 
628  G4UIcommandTree * comTree = UI->GetTree();
629  /*int*/ unsigned idx = 1;
630  while( idx < newCommand.length()-1 )
631  {
632  int i = newCommand.index("/",idx);
633  comTree = comTree->GetTree(G4String(newCommand(0,i+1)));
634  if( comTree == NULL )
635  { return NULL; }
636  idx = i+1;
637  }
638  return comTree;
639 }
640 
642 
646  if( tree == NULL ) {
647  G4cerr << "GetTree() returnes null." << G4endl;
648  return;
649  }
650  if (uiMode == java_mode){
651  G4cout << "@@JTreeBegin" << G4endl;
652  CodeGenJavaTree(tree, 0);
653  G4cout << "@@JTreeEnd" << G4endl;
654  CodeGenJavaParams(tree, 0);
655  }else{}
656 }
657 
661  if( tree == NULL ) {
662  G4cerr << "GetTree() returnes null." << G4endl;
663  return;
664  }
665  if (uiMode == java_mode){
666  CodeGenJavaParams(tree, 0);
667  }else{ }
668 }
669 
673  int treeEntry, commandEntry;
674  treeEntry = tree->GetTreeEntry();
675  commandEntry = tree->GetCommandEntry();
676 
677  if(level!=0) {
678  for(int i=0; i<commandEntry; i++){
679  G4cout << tree->GetCommand(i+1)->GetCommandPath() << G4endl;
680  }
681  }
682  if(treeEntry == 0) return; //end recursion
683 
684  for(int j=0; j<treeEntry; j++){
685  CodeGenJavaTree(tree->GetTree(j+1), level+1);
686  }
687 }
688 
692  int treeEntry,commandEntry,i;
693  G4UIcommandTree* treeLink;
694 
695  treeEntry = tree->GetTreeEntry();
696  commandEntry = tree->GetCommandEntry();
697 
698  for(i=0;i<commandEntry; i++){
699  SendAParamProperty(tree->GetCommand(i+1));
700  }
701  if(treeEntry ==0) return;
702 
703  for(i=0;i<treeEntry; i++){
704  treeLink = tree->GetTree(i+1);
705  G4cout<<"@@JDirGuieBegin"<<G4endl;
706  G4cout<<treeLink->GetPathName()<<G4endl <<treeLink->GetTitle()<<G4endl;
707  G4cout<<"@@JDirGuideEnd"<<G4endl;
708  CodeGenJavaParams(treeLink,level+1);
709  }
710 }
711 
715  int guidanceEntry, parameterEntry;
716  G4String title, title2;
717  G4UIparameter * prp;
718  char c[2];
719  guidanceEntry = Comp->GetGuidanceEntries();
720  parameterEntry = Comp->GetParameterEntries();
721  G4cout << "@@JParamBegin" << G4endl;
722  G4cout << Comp->GetCommandPath() << G4endl;
723  G4cout << guidanceEntry << G4endl;
724  for (int j=0; j<guidanceEntry; j++){
725  title = Comp->GetGuidanceLine(j);
726  title2 = "";
727  if (title != ""){
728  for(int i=0; i< (int)title.length(); i++){
729  c[0]=title(i);
730  c[1]= '\0';
731  if ( c[0] == '\n' || c[0] == '\r') {
732  c[0]= ' ';
733  }
734  title2.append(c);
735  }
736  }
737  G4cout << title2 << G4endl;
738  }
739  G4cout << Comp->GetRange() << G4endl;
740  G4cout << parameterEntry << G4endl;
741  for( int par=0; par<parameterEntry; par++) {
742  prp = (G4UIparameter *)Comp->GetParameter(par);
743  G4cout << prp->GetParameterName() << G4endl;
744  G4cout << prp->GetParameterGuidance() << G4endl;
745  G4cout << prp->GetParameterType() << G4endl;
746  G4cout << prp->IsOmittable() << G4endl;
747  G4cout << prp->GetDefaultValue() << G4endl;
748  G4cout << prp->GetParameterRange() << G4endl;
749  G4cout << prp->GetParameterCandidates() << G4endl;
750  }
751  G4cout << "@@JParamEnd" << G4endl;
752 }
753 
757  int treeEntry, commandEntry;
758  G4UIcommand * Comp;
759  treeEntry = tree->GetTreeEntry();
760  commandEntry = tree->GetCommandEntry();
761 
762  for(int com=0; com<commandEntry; com++) {
763  Comp = tree->GetCommand(com+1);
764  if( Comp->IsAvailable()==false ) {
765  G4cout << Comp->GetCommandPath()<<G4endl;
766  }
767  }
768  if( treeEntry == 0 ) return; // end recursion
769 
770  for( int i=0; i<treeEntry; i++) {
771  SendDisableList(tree->GetTree(i+1), level+1);
772  // be sure the function name is the same
773  }
774 }
775 
776 
777 
778 //####### update check routines ####################################
779 
783 {
784  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_;
785  G4ApplicationState newState;
787  newState = statM->GetCurrentState();
788  if( newState != previousState )
789  {
791  previousState = newState;
792  }
793 }
794 
798 {
799  G4String stateString;
801  G4UIcommandTree * tree = UI->GetTree();
802  stateString = statM->GetStateString(statM->GetCurrentState());
803  if ( uiMode != terminal_mode ){
804  G4cout << "@@State \"" << stateString << "\"" << G4endl;
805  G4cout << "@@DisableListBegin"<<G4endl;
806  SendDisableList(tree, 0);
807  G4cout << "@@DisableListEnd" <<G4endl;
808  }
809 }
810 
814 {
815  G4UIcommandTree * tree = UI->GetTree();
816  SendCommandProperties(tree);
817 }
818 
822 {
823  SendAParamProperty(com);
824 }
825 
829  int added=0, deleted=0;
830  int pEntry= previousTreeCommands.size();
831  int nEntry= newTreeCommands.size();
832  int i,j;
833  for( i=0; i<pEntry; i++) { // check deleted command(s)
834  for( j=0; j<nEntry; j++) {
835  if( previousTreeCommands[i] == newTreeCommands[j]) break;
836  }
837  if( j==nEntry ) {
838  deleted = 1;
839  //G4cout <<"deleted: "<< previousTreeCommands(i) << G4endl;
840  }
841  }
842  for( i=0; i<nEntry; i++) { // check added command(s)
843  for( j=0; j<pEntry; j++) {
844  if( newTreeCommands[i] == previousTreeCommands[j]) break;
845  }
846  if( j==pEntry ) {
847  added = 1;
848  // G4cout <<"added: "<< newTreeCommands(i) << G4endl;
849  }
850  }
851  if( added && deleted==0 ) {G4cout<<"c added"<<G4endl;return added;}
852  if( added==0 && deleted ) {G4cout<<"c deleted"<<G4endl;return deleted;}
853  if( added && deleted ) {G4cout<<"c add/deleted"<<G4endl;return addedAndDeleted;}
854  return notChanged;
855 }
856 
860  G4String commandPath;
861  G4String title;
862  G4String pathName; //tree name
863  G4UIcommandTree * t;
864  int treeEntry = tree->GetTreeEntry();
865  int commandEntry = tree->GetCommandEntry();
866 
867  if( level==0 ) { newTreeCommands.clear();}
868  for(int com=0; com<commandEntry; com++){
869  commandPath = tree->GetCommand(com+1)->GetCommandPath();
870  title = tree->GetCommand(com+1)->GetTitle();
871  newTreeCommands.push_back( commandPath + " " + title );
872  }
873 
874  if(treeEntry == 0) return; //end recursion
875 
876  for(int i=0; i< treeEntry; i++){
877  t = tree->GetTree(i+1);
878  pathName = t->GetPathName();
879  title = t->GetTitle();
880  newTreeCommands.push_back( pathName + " " + title );
881  GetNewTreeStructure(t, level+1);
882  }
883 }
884 
888  // call NotifyParameterUpdate() if the value of each
889  // command/parameter is updated.
890  // assuming the command structure is not changed.
891  int pEntry= previousTreeParams.size();
892  int nEntry= newTreeParams.size();
893  int i;
894  G4UIcommand* Comp;
895  if (pEntry != nEntry) return;
896  for( i=0; i<nEntry; i++) {
897  if( previousTreeParams[i] != newTreeParams[i]){
898  Comp = newTreePCP[i];
899  G4cout << Comp->GetCommandPath()
900  << " command is updated." <<G4endl;
901  NotifyParameterUpdate(Comp);
902  }
903  }
904 }
905 
907 void G4UIGainServer::GetNewTreeValues( G4UIcommandTree * tree, int level){ // recursive
909  G4String commandPath;
910  G4String pathName; //tree name
911  G4UIcommandTree * t;
912  int parameterEntry;
913  int treeEntry = tree->GetTreeEntry();
914  int commandEntry = tree->GetCommandEntry();
915  G4UIcommand * Comp;
916  G4UIparameter * prp;
917  G4String param, str(" ");
918 
919  if( level==0 ) { newTreeParams.clear(); }
920  for(int com=0; com<commandEntry; com++) {
921  Comp = tree->GetCommand(com+1);
922  commandPath = Comp->GetCommandPath();
923  parameterEntry = Comp->GetParameterEntries();
924  param = commandPath +" ";
925  for( int par=0; par< parameterEntry; par++) {
926  prp = (G4UIparameter *)Comp->GetParameter(par);
927  param += prp->GetParameterName() +" ";
928  str(0) = prp->GetParameterType();
929  param += str + " ";
930  param += prp->GetDefaultValue() +" ";
931  param += prp->GetParameterRange() +" ";
932  param += prp->GetParameterCandidates();
933  }
934  newTreeParams.push_back( param + "\n");
935  newTreePCP.push_back( Comp );
936  }
937  if( treeEntry == 0 ) return; // end recursion
938  for( int i=0; i< treeEntry; i++) {
939  t = tree->GetTree(i+1);
940  GetNewTreeValues(t, level+1);
941  }
942 }
943 
944 
945 #endif
946 
947 
948 
949 
950 
951 
952 
953 
954 
955 
956 
957 
std::vector< G4UIcommand * > newTreePCP
void CodeGenJavaTree(G4UIcommandTree *, int recursiveLevel)
G4UIcommandTree * FindDirPath(G4String)
G4int GetNumberOfHistory() const
Definition: G4UImanager.hh:229
G4String GetParameterCandidates() const
G4bool IsAvailable()
Definition: G4UIcommand.cc:289
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
G4String GetPreviousCommand(G4int i) const
Definition: G4UImanager.hh:231
G4String & remove(str_size)
void TerminalHelp(G4String)
G4UIcommand * FindPath(const char *commandPath) const
std::vector< G4String > previousTreeCommands
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
Definition: G4UIGAG.hh:45
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
void CodeGenJavaParams(G4UIcommandTree *, int recursiveLevel)
G4int GetTreeEntry() const
std::string::size_type str_size
Definition: G4String.hh:57
const G4String GetTitle() const
Definition: G4UIcommand.hh:170
#define G4ThreadLocal
Definition: tls.hh:89
void WaitingConnection()
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
std::istream & readLine(std::istream &, G4bool skipWhite=true)
int G4int
Definition: G4Types.hh:78
virtual void PauseSessionStart(const G4String &msg)
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
void ListCurrent() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
struct sockaddr_in saddr
G4UImanager * UI
G4bool IsOmittable() const
void NotifyParameterUpdate(G4UIcommand *)
G4String & prepend(const char *)
virtual void ExecuteCommand(const G4String &aCommand)
void GetNewTreeStructure(G4UIcommandTree *, int recursiveLevel)
static G4StateManager * GetStateManager()
#define G4cin
Definition: G4ios.hh:60
std::vector< G4UIcommand * > previousTreePCP
void SendAParamProperty(G4UIcommand *)
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
virtual G4int ReceiveG4cerr(const G4String &cerrString)
void SendCommandProperties(G4UIcommandTree *)
bool G4bool
Definition: G4Types.hh:79
virtual G4int ReceiveG4cout(const G4String &coutString)
#define FALSE
Definition: globals.hh:52
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
void ListCurrentWithNum() const
#define TRUE
Definition: globals.hh:55
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
G4ApplicationState GetCurrentState() const
virtual void ExitHelp() const
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void ShowCurrent(G4String)
std::vector< G4String > previousTreeParams
G4String GetCurrentValues(const char *aCommand)
Definition: G4UImanager.cc:170
const G4String GetPathName() const
std::vector< G4String > newTreeCommands
const G4String GetTitle() const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String ModifyPrefix(G4String)
char buf[1024]
G4int last(char) const
G4String GetCommand()
G4String & append(const G4String &)
#define DEFAULT_PORT
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:618
int CommandUpdated(void)
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:391
char GetParameterType() const
void SendParameterProperties(G4UIcommandTree *)
#define G4endl
Definition: G4ios.hh:61
void NotifyCommandUpdate(void)
G4String GetFullPath(G4String)
G4UIsession * SessionStart()
void NotifyStateChange(void)
const G4String GetParameterGuidance() const
void GetNewTreeValues(G4UIcommandTree *, int recursiveLevel)
std::vector< G4String > newTreeParams
virtual void List()
Definition: G4UIcommand.cc:348
G4String GetParameterRange() const
#define SOCK_NAME
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
void UpdateParamVal(void)
void SendDisableList(G4UIcommandTree *, int recursiveLevel)
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
struct sockaddr_in caddr
G4bool isNull() const
void UpdateState(void)
G4ApplicationState
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
void ChangeDirectory(G4String)
G4String promptCharacter
G4GLOB_DLL std::ostream G4cerr
void ListDirectory(G4String)
G4String GetStateString(G4ApplicationState aState) const
virtual G4bool GetHelpChoice(G4int &aInt)