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