Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIcommandTree Class Reference

#include <G4UIcommandTree.hh>

Public Member Functions

 G4UIcommandTree ()
 
 G4UIcommandTree (const char *thePathName)
 
 ~G4UIcommandTree ()
 
G4int operator== (const G4UIcommandTree &right) const
 
G4int operator!= (const G4UIcommandTree &right) const
 
void AddNewCommand (G4UIcommand *newCommand)
 
void RemoveCommand (G4UIcommand *aCommand)
 
G4UIcommandFindPath (const char *commandPath) const
 
G4UIcommandTreeFindCommandTree (const char *commandPath)
 
G4String CompleteCommandPath (const G4String &commandPath)
 
void List () const
 
void ListCurrent () const
 
void ListCurrentWithNum () const
 
void CreateHTML ()
 
const G4UIcommandGetGuidance () const
 
const G4String GetPathName () const
 
G4int GetTreeEntry () const
 
G4int GetCommandEntry () const
 
G4UIcommandTreeGetTree (G4int i)
 
G4UIcommandTreeGetTree (const char *comNameC)
 
G4UIcommandGetCommand (G4int i)
 
const G4String GetTitle () const
 

Detailed Description

Definition at line 44 of file G4UIcommandTree.hh.

Constructor & Destructor Documentation

◆ G4UIcommandTree() [1/2]

G4UIcommandTree::G4UIcommandTree ( )

Definition at line 35 of file G4UIcommandTree.cc.

36:guidance(NULL)
37{ }

Referenced by AddNewCommand().

◆ G4UIcommandTree() [2/2]

G4UIcommandTree::G4UIcommandTree ( const char *  thePathName)

Definition at line 39 of file G4UIcommandTree.cc.

40:guidance(NULL)
41{
42 pathName = thePathName;
43}

◆ ~G4UIcommandTree()

G4UIcommandTree::~G4UIcommandTree ( )

Definition at line 45 of file G4UIcommandTree.cc.

46{
47 G4int i;
48 G4int n_treeEntry = tree.size();
49 for( i=0; i < n_treeEntry; i++ )
50 { delete tree[i]; }
51}
int G4int
Definition: G4Types.hh:66

Member Function Documentation

◆ AddNewCommand()

void G4UIcommandTree::AddNewCommand ( G4UIcommand newCommand)

Definition at line 63 of file G4UIcommandTree.cc.

64{
65 G4String commandPath = newCommand->GetCommandPath();
66 G4String remainingPath = commandPath;
67 remainingPath.remove(0,pathName.length());
68 if( remainingPath.isNull() )
69 {
70 guidance = newCommand;
71 return;
72 }
73 G4int i = remainingPath.first('/');
74 if( i == G4int(std::string::npos) )
75 {
76 // Find command
77 G4int n_commandEntry = command.size();
78 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
79 {
80 if( remainingPath == command[i_thCommand]->GetCommandName() )
81 { return; }
82 }
83 command.push_back( newCommand );
84 return;
85 }
86 else
87 {
88 // Find path
89 G4String nextPath = pathName;
90 nextPath.append(remainingPath(0,i+1));
91 G4int n_treeEntry = tree.size();
92 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
93 {
94 if( nextPath == tree[i_thTree]->GetPathName() )
95 {
96 tree[i_thTree]->AddNewCommand( newCommand );
97 return;
98 }
99 }
100 G4UIcommandTree * newTree = new G4UIcommandTree( nextPath );
101 tree.push_back( newTree );
102 newTree->AddNewCommand( newCommand );
103 return;
104 }
105}
G4String & remove(str_size)
G4String & append(const G4String &)
G4bool isNull() const
G4int first(char) const
const G4String GetPathName() const
void AddNewCommand(G4UIcommand *newCommand)
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:134

Referenced by AddNewCommand(), and G4UImanager::AddNewCommand().

◆ CompleteCommandPath()

G4String G4UIcommandTree::CompleteCommandPath ( const G4String commandPath)

Definition at line 227 of file G4UIcommandTree.cc.

228{
229 G4String pName = aCommandPath;
230 G4String remainingPath = aCommandPath;
231 G4String empty = "";
232 G4String matchingPath = empty;
233
234 // find the tree
235 G4int jpre= pName.last('/');
236 if(jpre != G4int(G4String::npos)) pName.remove(jpre+1);
237 G4UIcommandTree* aTree = FindCommandTree(pName);
238
239 if (!aTree) {
240 return empty;
241 }
242
243 if( pName.index( pName ) == std::string::npos ) return empty;
244
245 std::vector<G4String> paths;
246
247 // list matched directories/commands
248 G4String strtmp;
249 G4int nMatch= 0;
250
251 int Ndir= aTree-> GetTreeEntry();
252 int Ncmd= aTree-> GetCommandEntry();
253
254 // directory ...
255 for(G4int idir=1; idir<=Ndir; idir++) {
256 G4String fpdir= aTree-> GetTree(idir)-> GetPathName();
257 // matching test
258 if( fpdir.index(remainingPath, 0) == 0) {
259 if(nMatch==0) {
260 matchingPath = fpdir;
261 } else {
262 matchingPath = GetFirstMatchedString(fpdir,matchingPath);
263 }
264 nMatch++;
265 paths.push_back(fpdir);
266 }
267 }
268
269 if (paths.size()>=2) {
270 G4cout << "Matching directories :" << G4endl;
271 for( unsigned int i_thCommand = 0; i_thCommand < paths.size(); i_thCommand++ ) {
272 G4cout << paths[i_thCommand] << G4endl;
273 }
274 }
275
276 // command ...
277 std::vector<G4String> commands;
278
279 for(G4int icmd=1; icmd<=Ncmd; icmd++){
280 G4String fpcmd= aTree-> GetPathName() +
281 aTree-> GetCommand(icmd) -> GetCommandName();
282 // matching test
283 if( fpcmd.index(remainingPath, 0) ==0) {
284 if(nMatch==0) {
285 matchingPath= fpcmd + " ";
286 } else {
287 strtmp= fpcmd + " ";
288 matchingPath= GetFirstMatchedString(matchingPath, strtmp);
289 }
290 nMatch++;
291 commands.push_back(fpcmd+" ");
292 }
293 }
294
295 if (commands.size()>=2) {
296 G4cout << "Matching commands :" << G4endl;
297 for( unsigned int i_thCommand = 0; i_thCommand < commands.size(); i_thCommand++ ) {
298 G4cout << commands[i_thCommand] << G4endl;
299 }
300 }
301
302 return matchingPath;
303}
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4int last(char) const
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)

◆ CreateHTML()

void G4UIcommandTree::CreateHTML ( )

Definition at line 418 of file G4UIcommandTree.cc.

419{
420 G4String ofileName = CreateFileName(pathName);
421 std::ofstream oF(ofileName, std::ios::out);
422
423 oF << "<html><head><title>Commands in " << ModStr(pathName) << "</title></head>" << G4endl;
424 oF << "<body bgcolor=\"#ffffff\"><h2>" << ModStr(pathName) << "</h2><p>" << G4endl;
425
426 if( guidance != NULL )
427 {
428 for(G4int i=0;i<guidance->GetGuidanceEntries();i++)
429 { oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl; }
430 }
431
432 oF << "<p><hr><p>" << G4endl;
433
434 oF << "<h2>Sub-directories : </h2><dl>" << G4endl;
435 for( G4int i_thTree = 0; i_thTree < G4int(tree.size()); i_thTree++ )
436 {
437 oF << "<p><br><p><dt><a href=\"" << CreateFileName(tree[i_thTree]->GetPathName())
438 << "\">" << ModStr(tree[i_thTree]->GetPathName()) << "</a>" << G4endl;
439 oF << "<p><dd>" << ModStr(tree[i_thTree]->GetTitle()) << G4endl;
440 tree[i_thTree]->CreateHTML();
441 }
442
443 oF << "</dl><p><hr><p>" << G4endl;
444
445 oF << "<h2>Commands : </h2><dl>" << G4endl;
446 for( G4int i_thCommand = 0; i_thCommand < G4int(command.size()); i_thCommand++ )
447 {
448 G4UIcommand* cmd = command[i_thCommand];
449 oF << "<p><br><p><dt><b>" << ModStr(cmd->GetCommandName());
450 if(cmd->GetParameterEntries()>0)
451 {
452 for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
453 { oF << " [<i>" << ModStr(cmd->GetParameter(i_thParam)->GetParameterName()) << "</i>]"; }
454 }
455 oF << "</b>" << G4endl;
456 oF << "<p><dd>" << G4endl;
457 for(G4int i=0;i<cmd->GetGuidanceEntries();i++)
458 { oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl; }
459 if(!(cmd->GetRange()).isNull())
460 { oF << "<p><dd>Range : " << ModStr(cmd->GetRange()) << G4endl; }
461 std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList();
462 if(availabelStateList->size()==6)
463 { oF << "<p><dd>Available at all Geant4 states." << G4endl; }
464 else
465 {
466 oF << "<p><dd>Available Geant4 state(s) : ";
467 for(G4int ias=0;ias<G4int(availabelStateList->size());ias++)
468 { oF << G4StateManager::GetStateManager()->GetStateString((*availabelStateList)[ias]) << " " << G4endl; }
469 }
470 if(cmd->GetParameterEntries()>0)
471 {
472 oF << "<p><dd>Parameters<table border=1>" << G4endl;
473 for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
474 {
475 G4UIparameter* prm = cmd->GetParameter(i_thParam);
476 oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl;
477 oF << "<td>type " << prm->GetParameterType() << G4endl;
478 oF << "<td>";
479 if(prm->IsOmittable())
480 {
481 oF << "Omittable : ";
482 if(prm->GetCurrentAsDefault())
483 { oF << "current value is used as the default value." << G4endl; }
484 else
485 { oF << "default value = " << prm->GetDefaultValue() << G4endl; }
486 }
487 oF << "<td>";
488 if(!(prm->GetParameterRange()).isNull())
489 { oF << "Parameter range : " << ModStr(prm->GetParameterRange()) << G4endl; }
490 else if(!(prm->GetParameterCandidates()).isNull())
491 { oF << "Parameter candidates : " << ModStr(prm->GetParameterCandidates()) << G4endl; }
492 }
493 oF << "</table>" << G4endl;
494 }
495
496 }
497
498 oF << "</dl></body></html>" << G4endl;
499 oF.close();
500}
static G4StateManager * GetStateManager()
G4String GetStateString(G4ApplicationState aState) const
const G4String GetTitle() 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
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:138
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:142
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:136
const G4String & GetRange() const
Definition: G4UIcommand.hh:128
G4String GetParameterRange() const
G4String GetDefaultValue() const
G4bool IsOmittable() const
G4String GetParameterCandidates() const
G4bool GetCurrentAsDefault() const
char GetParameterType() const
G4String GetParameterName() const

Referenced by G4UImanager::CreateHTML().

◆ FindCommandTree()

G4UIcommandTree * G4UIcommandTree::FindCommandTree ( const char *  commandPath)

Try to match a command or a path with the one given. @commandPath : command or path to match

Returns
the commandTree found or NULL if not

Definition at line 199 of file G4UIcommandTree.cc.

200{
201 G4String remainingPath = commandPath;
202 if( remainingPath.index( pathName ) == std::string::npos )
203 { return NULL; }
204 remainingPath.remove(0,pathName.length());
205 G4int i = remainingPath.first('/');
206 if( i != G4int(std::string::npos) )
207 {
208 // Find path
209 G4String nextPath = pathName;
210 nextPath.append(remainingPath(0,i+1));
211 G4int n_treeEntry = tree.size();
212 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
213 {
214 if (tree[i_thTree]->GetPathName() == commandPath) {
215 return tree[i_thTree];
216 }
217 else if( nextPath == tree[i_thTree]->GetPathName() ) {
218 return tree[i_thTree]->FindCommandTree( commandPath );
219 }
220 }
221 } else {
222 return this;
223 }
224 return NULL;
225}

Referenced by CompleteCommandPath().

◆ FindPath()

G4UIcommand * G4UIcommandTree::FindPath ( const char *  commandPath) const

Definition at line 161 of file G4UIcommandTree.cc.

162{
163 G4String remainingPath = commandPath;
164 if( remainingPath.index( pathName ) == std::string::npos )
165 { return NULL; }
166 remainingPath.remove(0,pathName.length());
167 G4int i = remainingPath.first('/');
168 if( i == G4int(std::string::npos) )
169 {
170 // Find command
171 G4int n_commandEntry = command.size();
172 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
173 {
174 if( remainingPath == command[i_thCommand]->GetCommandName() )
175 { return command[i_thCommand]; }
176 }
177 }
178 else
179 {
180 // Find path
181 G4String nextPath = pathName;
182 nextPath.append(remainingPath(0,i+1));
183 G4int n_treeEntry = tree.size();
184 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
185 {
186 if( nextPath == tree[i_thTree]->GetPathName() )
187 { return tree[i_thTree]->FindPath( commandPath ); }
188 }
189 }
190 return NULL;
191}

Referenced by G4UImanager::ApplyCommand(), G4CascadeParamMessenger::CreateDirectory(), G4VBasicShell::FindCommand(), G4UImanager::GetCurrentValues(), and G4VBasicShell::TerminalHelp().

◆ GetCommand()

G4UIcommand * G4UIcommandTree::GetCommand ( G4int  i)
inline

Definition at line 98 of file G4UIcommandTree.hh.

99 { return command[i-1]; };

Referenced by CompleteCommandPath(), and G4VBasicShell::TerminalHelp().

◆ GetCommandEntry()

G4int G4UIcommandTree::GetCommandEntry ( ) const
inline

Definition at line 84 of file G4UIcommandTree.hh.

85 { return command.size(); };

Referenced by CompleteCommandPath().

◆ GetGuidance()

const G4UIcommand * G4UIcommandTree::GetGuidance ( ) const
inline

Definition at line 78 of file G4UIcommandTree.hh.

79 { return guidance; };

◆ GetPathName()

const G4String G4UIcommandTree::GetPathName ( ) const
inline

◆ GetTitle()

const G4String G4UIcommandTree::GetTitle ( ) const
inline

Definition at line 100 of file G4UIcommandTree.hh.

101 {
102 if(guidance==NULL)
103 { return G4String("...Title not available..."); }
104 else
105 { return guidance->GetTitle(); }
106 };
const G4String GetTitle() const
Definition: G4UIcommand.hh:165

Referenced by CreateHTML().

◆ GetTree() [1/2]

G4UIcommandTree * G4UIcommandTree::GetTree ( const char *  comNameC)
inline

Definition at line 88 of file G4UIcommandTree.hh.

89 {
90 G4String comName = comNameC;
91 for( size_t i=0; i < tree.size(); i++)
92 {
93 if( comName == tree[i]->GetPathName() )
94 { return tree[i]; }
95 }
96 return NULL;
97 };

◆ GetTree() [2/2]

G4UIcommandTree * G4UIcommandTree::GetTree ( G4int  i)
inline

Definition at line 86 of file G4UIcommandTree.hh.

87 { return tree[i-1]; };

Referenced by CompleteCommandPath(), G4VBasicShell::FindDirectory(), and G4VBasicShell::TerminalHelp().

◆ GetTreeEntry()

G4int G4UIcommandTree::GetTreeEntry ( ) const
inline

Definition at line 82 of file G4UIcommandTree.hh.

83 { return tree.size(); };

Referenced by CompleteCommandPath(), RemoveCommand(), and G4VBasicShell::TerminalHelp().

◆ List()

void G4UIcommandTree::List ( ) const

Definition at line 371 of file G4UIcommandTree.cc.

372{
373 ListCurrent();
374 G4int n_commandEntry = command.size();
375 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
376 {
377 command[i_thCommand]->List();
378 }
379 G4int n_treeEntry = tree.size();
380 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
381 {
382 tree[i_thTree]->List();
383 }
384}
void ListCurrent() const

Referenced by G4UImanager::ListCommands().

◆ ListCurrent()

void G4UIcommandTree::ListCurrent ( ) const

Definition at line 328 of file G4UIcommandTree.cc.

329{
330 G4cout << "Command directory path : " << pathName << G4endl;
331 if( guidance != NULL ) guidance->List();
332 G4cout << " Sub-directories : " << G4endl;
333 G4int n_treeEntry = tree.size();
334 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
335 {
336 G4cout << " " << tree[i_thTree]->GetPathName()
337 << " " << tree[i_thTree]->GetTitle() << G4endl;
338 }
339 G4cout << " Commands : " << G4endl;
340 G4int n_commandEntry = command.size();
341 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
342 {
343 G4cout << " " << command[i_thCommand]->GetCommandName()
344 << " * " << command[i_thCommand]->GetTitle() << G4endl;
345 }
346}
virtual void List()
Definition: G4UIcommand.cc:328

Referenced by List(), and G4VBasicShell::ListDirectory().

◆ ListCurrentWithNum()

void G4UIcommandTree::ListCurrentWithNum ( ) const

Definition at line 348 of file G4UIcommandTree.cc.

349{
350 G4cout << "Command directory path : " << pathName << G4endl;
351 if( guidance != NULL ) guidance->List();
352 G4int i = 0;
353 G4cout << " Sub-directories : " << G4endl;
354 G4int n_treeEntry = tree.size();
355 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
356 {
357 i++;
358 G4cout << " " << i << ") " << tree[i_thTree]->GetPathName()
359 << " " << tree[i_thTree]->GetTitle() << G4endl;
360 }
361 G4cout << " Commands : " << G4endl;
362 G4int n_commandEntry = command.size();
363 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
364 {
365 i++;
366 G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName()
367 << " * " << command[i_thCommand]->GetTitle() << G4endl;
368 }
369}

Referenced by G4VBasicShell::TerminalHelp().

◆ operator!=()

G4int G4UIcommandTree::operator!= ( const G4UIcommandTree right) const

Definition at line 58 of file G4UIcommandTree.cc.

59{
60 return ( pathName != right.GetPathName() );
61}

◆ operator==()

G4int G4UIcommandTree::operator== ( const G4UIcommandTree right) const

Definition at line 53 of file G4UIcommandTree.cc.

54{
55 return ( pathName == right.GetPathName() );
56}

◆ RemoveCommand()

void G4UIcommandTree::RemoveCommand ( G4UIcommand aCommand)

Definition at line 107 of file G4UIcommandTree.cc.

108{
109 G4String commandPath = aCommand->GetCommandPath();
110 G4String remainingPath = commandPath;
111 remainingPath.remove(0,pathName.length());
112 if( remainingPath.isNull() )
113 {
114 guidance = NULL;
115 }
116 else
117 {
118 G4int i = remainingPath.first('/');
119 if( i == G4int(std::string::npos) )
120 {
121 // Find command
122 G4int n_commandEntry = command.size();
123 for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
124 {
125 if( remainingPath == command[i_thCommand]->GetCommandName() )
126 {
127 command.erase(command.begin()+i_thCommand);
128 break;
129 }
130 }
131 }
132 else
133 {
134 // Find path
135 G4String nextPath = pathName;
136 nextPath.append(remainingPath(0,i+1));
137 G4int n_treeEntry = tree.size();
138 for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
139 {
140 if( nextPath == tree[i_thTree]->GetPathName() )
141 {
142 tree[i_thTree]->RemoveCommand( aCommand );
143 G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
144 G4int n_treeRemain = tree[i_thTree]-> GetTreeEntry();
145 if(n_commandRemain == 0 && n_treeRemain == 0)
146 {
147 G4UIcommandTree * emptyTree = tree[i_thTree];
148 tree.erase(tree.begin()+i_thTree);
149 delete emptyTree;
150 }
151 break;
152 }
153 }
154 }
155 }
156}

Referenced by G4UImanager::RemoveCommand().


The documentation for this class was generated from the following files: