Geant4 11.1.1
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 ()=default
 
 G4UIcommandTree (const char *thePathName)
 
 ~G4UIcommandTree ()
 
G4bool operator== (const G4UIcommandTree &right) const
 
G4bool operator!= (const G4UIcommandTree &right) const
 
void AddNewCommand (G4UIcommand *newCommand, G4bool workerThreadOnly=false)
 
void RemoveCommand (G4UIcommand *aCommand, G4bool workerThreadOnly=false)
 
G4UIcommandFindPath (const char *commandPath) const
 
G4UIcommandTreeFindCommandTree (const char *commandPath)
 
G4String GetFirstMatchedString (const G4String &, const G4String &) const
 
G4String CompleteCommandPath (const G4String &commandPath)
 
void List () const
 
void ListCurrent () const
 
void ListCurrentWithNum () const
 
void CreateHTML (const G4String &="")
 
const G4UIcommandGetGuidance () const
 
const G4StringGetPathName () 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 ( )
default

Referenced by AddNewCommand().

◆ G4UIcommandTree() [2/2]

G4UIcommandTree::G4UIcommandTree ( const char *  thePathName)

Definition at line 41 of file G4UIcommandTree.cc.

42{
43 pathName = thePathName;
44}

◆ ~G4UIcommandTree()

G4UIcommandTree::~G4UIcommandTree ( )

Definition at line 47 of file G4UIcommandTree.cc.

48{
49 for(std::size_t i = 0; i < tree.size(); ++i)
50 {
51 delete tree[i];
52 }
53}

Member Function Documentation

◆ AddNewCommand()

void G4UIcommandTree::AddNewCommand ( G4UIcommand newCommand,
G4bool  workerThreadOnly = false 
)

Definition at line 68 of file G4UIcommandTree.cc.

70{
71 G4String commandPath = newCommand->GetCommandPath();
72 G4String remainingPath = commandPath;
73 remainingPath.erase(0, pathName.length());
74 if(remainingPath.empty())
75 {
76 if(guidance == nullptr)
77 {
78 guidance = newCommand;
79 if(!(newCommand->ToBeBroadcasted()))
80 { broadcastCommands = false; }
81 if(workerThreadOnly)
82 { newCommand->SetWorkerThreadOnly(); }
83 }
84 return;
85 }
86
87 if(guidance != nullptr)
88 {
89 auto* dir = static_cast<G4UIdirectory*>(guidance);
90 ifSort = dir->IfSort();
91 }
92 std::size_t i = remainingPath.find('/');
93 if(i == std::string::npos)
94 {
95 // Adding a new command to this directory
96 std::size_t n_commandEntry = command.size();
97 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
98 {
99 if(remainingPath == command[i_thCommand]->GetCommandName())
100 {
101 // a command of same name has already defined. do nothing and return.
103 {
105 ed << "Command <" << commandPath << "> already exist. New command is not added.";
106 G4Exception("G4UIcommandTree::AddNewCommand","UI_ComTree_001",
107 //FatalException,
109 ed);
110 }
111 return;
112 }
113 }
114 if(!broadcastCommands)
115 { newCommand->SetToBeBroadcasted(false); }
116 if(workerThreadOnly)
117 { newCommand->SetWorkerThreadOnly(); }
118 if(ifSort)
119 {
120 auto j = command.cbegin();
121 for(; j != command.cend(); ++j) {
122 if (newCommand->GetCommandPath() < (*j)->GetCommandPath()) { break; }
123 }
124 command.insert(j,newCommand);
125 }
126 else
127 { command.push_back(newCommand); }
128 return;
129 }
130 else
131 {
132 // Adding a new command to a sub-directory
133 G4String nextPath = pathName;
134 nextPath.append(remainingPath.substr(0, i + 1));
135 std::size_t n_treeEntry = tree.size();
136 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
137 {
138 if(nextPath == tree[i_thTree]->GetPathName())
139 {
140 if(!broadcastCommands)
141 {
142 newCommand->SetToBeBroadcasted(false);
143 }
144 tree[i_thTree]->AddNewCommand(newCommand, workerThreadOnly);
145 return;
146 }
147 }
148 // Creating a new sub-directory
149 auto* newTree = new G4UIcommandTree(nextPath);
150 if(ifSort)
151 {
152 auto j = tree.cbegin();
153 for(; j != tree.cend(); ++j) {
154 if (newTree->GetPathName() < (*j)->GetPathName()) { break; }
155 }
156 tree.insert(j,newTree);
157 }
158 else
159 { tree.push_back(newTree); }
160 if(!broadcastCommands)
161 { newCommand->SetToBeBroadcasted(false); }
162 // In case a new sub-directry is created with a new G4UIdirectory
163 // (most-likely this is the case), inherit the sort flag
164 newCommand->SetDefaultSortFlag(ifSort);
165 newTree->AddNewCommand(newCommand, workerThreadOnly);
166 return;
167 }
168}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:59
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
G4UIcommandTree()=default
const G4String & GetPathName() const
void SetToBeBroadcasted(G4bool val)
Definition: G4UIcommand.hh:172
G4bool ToBeBroadcasted() const
Definition: G4UIcommand.hh:173
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:137
void SetWorkerThreadOnly(G4bool val=true)
Definition: G4UIcommand.hh:176
void SetDefaultSortFlag(G4bool val)
Definition: G4UIcommand.hh:208
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:200
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77

Referenced by G4UImanager::AddNewCommand().

◆ CompleteCommandPath()

G4String G4UIcommandTree::CompleteCommandPath ( const G4String commandPath)

Definition at line 308 of file G4UIcommandTree.cc.

309{
310 G4String pName = aCommandPath;
311 G4String remainingPath = aCommandPath;
312 G4String empty = "";
313 G4String matchingPath = empty;
314
315 // find the tree
316 auto jpre = pName.rfind('/');
317 if(jpre != G4String::npos)
318 {
319 pName.erase(jpre + 1);
320 }
321 G4UIcommandTree* aTree = FindCommandTree(pName);
322
323 if(aTree == nullptr)
324 {
325 return empty;
326 }
327
328 if(pName.find(pName) == std::string::npos)
329 {
330 return empty;
331 }
332
333 std::vector<G4String> paths;
334
335 // list matched directories/commands
336 G4String strtmp;
337 G4int nMatch = 0;
338
339 G4int Ndir = aTree->GetTreeEntry();
340 G4int Ncmd = aTree->GetCommandEntry();
341
342 // directory ...
343 for(G4int idir = 1; idir <= Ndir; ++idir)
344 {
345 G4String fpdir = aTree->GetTree(idir)->GetPathName();
346 // matching test
347 if(fpdir.find(remainingPath, 0) == 0)
348 {
349 if(nMatch == 0)
350 {
351 matchingPath = fpdir;
352 }
353 else
354 {
355 matchingPath = GetFirstMatchedString(fpdir, matchingPath);
356 }
357 ++nMatch;
358 paths.push_back(fpdir);
359 }
360 }
361
362 if(paths.size() >= 2)
363 {
364 G4cout << "Matching directories :" << G4endl;
365 for(const auto& path : paths)
366 {
367 G4cout << path << G4endl;
368 }
369 }
370
371 // command ...
372 std::vector<G4String> commands;
373
374 for(G4int icmd = 1; icmd <= Ncmd; ++icmd)
375 {
376 G4String fpcmd =
377 aTree->GetPathName() + aTree->GetCommand(icmd)->GetCommandName();
378 // matching test
379 if(fpcmd.find(remainingPath, 0) == 0)
380 {
381 if(nMatch == 0)
382 {
383 matchingPath = fpcmd + " ";
384 }
385 else
386 {
387 strtmp = fpcmd + " ";
388 matchingPath = GetFirstMatchedString(matchingPath, strtmp);
389 }
390 nMatch++;
391 commands.emplace_back(fpcmd + " ");
392 }
393 }
394
395 if(commands.size() >= 2)
396 {
397 G4cout << "Matching commands :" << G4endl;
398 for(const auto& matched : commands)
399 {
400 G4cout << matched << G4endl;
401 }
402 }
403
404 return matchingPath;
405}
int G4int
Definition: G4Types.hh:85
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)
G4String GetFirstMatchedString(const G4String &, const G4String &) const
const G4String & GetCommandName() const
Definition: G4UIcommand.hh:138

◆ CreateHTML()

void G4UIcommandTree::CreateHTML ( const G4String sideBar = "")

Definition at line 556 of file G4UIcommandTree.cc.

557{
558 G4String ofileName = CreateFileName(pathName);
559 std::ofstream oF(ofileName, std::ios::out);
560
561 oF << "<html><head><title>Commands in " << ModStr(pathName)
562 << "</title></head>" << G4endl;
563 oF << "<style> \
564 table,table td,table th { \
565 border:1px solid #eee \
566 } \
567 table td,table th { \
568 padding:5px 20px; \
569 line-height:1.3; \
570 text-align:inherit \
571 } \
572 a { \
573 color:#17a81a; \
574 text-decoration:none; \
575 transition-duration:0.3s \
576 } \
577 a:hover { \
578 color:#17a81a \
579 } \
580 table { \
581 border-collapse:collapse; \
582 border-spacing:0; \
583 margin-bottom:5px; \
584 } \
585 h1 { \
586 font-size:2.25em; \
587 font-weight:300; \
588 letter-spacing:-1px; \
589 line-height:1.15em; \
590 margin-bottom:0.5em; \
591 word-wrap:break-word \
592 } \
593 h2 { \
594 font-size:1.5em; \
595 font-weight:300; \
596 letter-spacing:-1px; \
597 line-height:1.15em; \
598 margin-bottom:0.5em; \
599 word-wrap:break-word \
600 } \
601 h3 { \
602 color:#26282a; \
603 font-weight:300; \
604 font-size:1.3em; \
605 padding:15px 0 15px 0; \
606 border-bottom:2px #eee solid; \
607 word-wrap:break-word \
608 } \
609 .sidebar { \
610 display:block; \
611 position:relative; \
612 position:sticky; \
613 float:left; \
614 -webkit-box-sizing:border-box; \
615 -moz-box-sizing:border-box; \
616 -ms-box-sizing:border-box; \
617 box-sizing:border-box; \
618 width:20%; \
619 padding-right:20px \
620 } \
621 .context { \
622 width:80%; \
623 display:inline-block; \
624 background-color:#fff; \
625 padding: 25px 35px 20px 30px; \
626 -webkit-box-sizing:border-box; \
627 -moz-box-sizing:border-box; \
628 -ms-box-sizing:border-box; \
629 box-sizing:border-box \
630 } \
631 </style>"<< G4endl;
632 oF << "<body bgcolor=\"#ffffff\">" << G4endl;
633
634 // Left Panel
635 if (createHTMLTreeLevel == 0 ) {
636 oF << "<div class=\"sidebar\">" << sideBar << "</div>" << G4endl;
637 }
638 // Right Panel
639 oF << "<div class=\"context\">";
640 oF << "<h1>" << ModStr(pathName) << "</h1>" << G4endl;
641
642 if(guidance != nullptr)
643 {
644 for(G4int i = 0; i < (G4int)guidance->GetGuidanceEntries(); ++i)
645 {
646 oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl;
647 }
648 }
649 if(!tree.empty())
650 {
651 G4String menu = "";
652 G4String newSideBar = "";
653 menu += "<h2>Sub-directories </h2><table>";
654 newSideBar += "<h2><a href=\"" + ofileName + "\">Top level </a></h2><table>";
655 // Build menu short version
656 for(auto& i_thTree : tree)
657 {
658 newSideBar += "<tr><td><a href=\"" +
659 CreateFileName(i_thTree->GetPathName()) + "\">" +
660 ModStr(i_thTree->GetPathName()) + "</a>";
661 }
662 // Build menu
663 for(auto& i_thTree : tree)
664 {
665 menu += "<tr><td><a href=\"" + CreateFileName(i_thTree->GetPathName()) +
666 "\">" + ModStr(i_thTree->GetPathName()) + "</a>";
667 menu += "</td><td>" + ModStr(i_thTree->GetTitle()) + "</tr>";
668 }
669 menu += "</table>";
670 newSideBar += "</table>";
671 for(auto& i_thTree : tree)
672 {
673 createHTMLTreeLevel ++;
674 i_thTree->CreateHTML(newSideBar);
675 createHTMLTreeLevel --;
676 }
677 oF << menu << G4endl;
678 }
679
680 if(!command.empty())
681 {
682 oF << "<h2>Commands </h2>" << G4endl;
683
684 // resume
685 oF << "<table>" << G4endl;
686 for(std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand)
687 {
688 G4UIcommand* cmd = command[i_thCommand];
689 oF << "<tr><td><a href=\"#c"<< i_thCommand << "\">"<< ModStr(cmd->GetCommandName());
690 oF << "</a></td></tr>" << G4endl;
691 }
692 oF << "</table>" << G4endl;
693 for(std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand)
694 {
695 G4UIcommand* cmd = command[i_thCommand];
696 oF << "<h3 id=\"c" << i_thCommand << "\">" << ModStr(cmd->GetCommandName());
697 if(cmd->GetParameterEntries() > 0)
698 {
699 for(G4int i_thParam = 0; i_thParam < (G4int)cmd->GetParameterEntries();
700 ++i_thParam)
701 {
702 oF << " [<i>"
703 << ModStr(cmd->GetParameter(i_thParam)->GetParameterName())
704 << "</i>]";
705 }
706 }
707 oF << "</h3>" << G4endl;
708 oF << "<p>" << G4endl;
709 for(G4int i = 0; i < (G4int)cmd->GetGuidanceEntries(); ++i)
710 {
711 oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl;
712 }
713 if(!(cmd->GetRange()).empty())
714 {
715 oF << "<p>Range : " << ModStr(cmd->GetRange()) << G4endl;
716 }
717 std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList();
718 if(availabelStateList->size() == 6)
719 {
720 oF << "<p>Available at all Geant4 states." << G4endl;
721 }
722 else
723 {
724 oF << "<p>Available Geant4 state(s) : ";
725 for(auto& ias : *availabelStateList)
726 {
728 << G4endl;
729 }
730 }
731 if(cmd->GetParameterEntries() > 0)
732 {
733 oF << "<p>Parameters<table border=1>" << G4endl;
734 for(G4int i_thParam = 0; i_thParam < (G4int)cmd->GetParameterEntries();
735 ++i_thParam)
736 {
737 G4UIparameter* prm = cmd->GetParameter(i_thParam);
738 oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl;
739 oF << "<td>type " << prm->GetParameterType() << G4endl;
740 oF << "<td>";
741 if(prm->IsOmittable())
742 {
743 oF << "Omittable : ";
744 if(prm->GetCurrentAsDefault())
745 {
746 oF << "current value is used as the default value." << G4endl;
747 }
748 else
749 {
750 oF << "default value = " << prm->GetDefaultValue() << G4endl;
751 }
752 }
753 oF << "<td>";
754 if(!(prm->GetParameterRange()).empty())
755 {
756 oF << "Parameter range : " << ModStr(prm->GetParameterRange())
757 << G4endl;
758 }
759 else if(!(prm->GetParameterCandidates()).empty())
760 {
761 oF << "Parameter candidates : "
762 << ModStr(prm->GetParameterCandidates()) << G4endl;
763 }
764 }
765 oF << "</table>" << G4endl;
766 }
767 }
768 }
769 oF << "</div></body></html>" << G4endl;
770 oF.close();
771}
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:139
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:133
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:140
std::size_t GetGuidanceEntries() const
Definition: G4UIcommand.hh:129
std::vector< G4ApplicationState > * GetStateList()
Definition: G4UIcommand.hh:141
const G4String & GetRange() const
Definition: G4UIcommand.hh:128
const G4String & GetParameterCandidates() const
G4bool IsOmittable() const
const G4String & GetParameterRange() const
G4bool GetCurrentAsDefault() const
char GetParameterType() const
const G4String & GetParameterName() const
const G4String & GetDefaultValue() const

Referenced by G4UImanager::CreateHTML().

◆ FindCommandTree()

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

Definition at line 269 of file G4UIcommandTree.cc.

270{
271 // Try to match a command or a path with the one given.
272 // @commandPath : command or path to match
273 // @return the commandTree found or nullptr if not
274
275 G4String remainingPath = commandPath;
276 if(remainingPath.find(pathName) == std::string::npos)
277 {
278 return nullptr;
279 }
280 remainingPath.erase(0, pathName.length());
281 std::size_t i = remainingPath.find('/');
282 if(i != std::string::npos)
283 {
284 // Find path
285 G4String nextPath = pathName;
286 nextPath.append(remainingPath.substr(0, i + 1));
287 std::size_t n_treeEntry = tree.size();
288 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
289 {
290 if(tree[i_thTree]->GetPathName() == commandPath)
291 {
292 return tree[i_thTree];
293 }
294 else if(nextPath == tree[i_thTree]->GetPathName())
295 {
296 return tree[i_thTree]->FindCommandTree(commandPath);
297 }
298 }
299 }
300 else
301 {
302 return this;
303 }
304 return nullptr;
305}

Referenced by CompleteCommandPath(), G4UImessenger::CreateDirectory(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ FindPath()

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

Definition at line 228 of file G4UIcommandTree.cc.

229{
230 // This function tries to match a command name
231
232 G4String remainingPath = commandPath;
233 if(remainingPath.find(pathName) == std::string::npos)
234 {
235 return nullptr;
236 }
237 remainingPath.erase(0, pathName.length());
238 std::size_t i = remainingPath.find('/');
239 if(i == std::string::npos)
240 {
241 // Find command
242 std::size_t n_commandEntry = command.size();
243 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
244 {
245 if(remainingPath == command[i_thCommand]->GetCommandName())
246 {
247 return command[i_thCommand];
248 }
249 }
250 }
251 else
252 {
253 // Find path
254 G4String nextPath = pathName;
255 nextPath.append(remainingPath.substr(0, i + 1));
256 std::size_t n_treeEntry = tree.size();
257 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
258 {
259 if(nextPath == tree[i_thTree]->GetPathName())
260 {
261 return tree[i_thTree]->FindPath(commandPath);
262 }
263 }
264 }
265 return nullptr;
266}

Referenced by G4UIQt::AddButton(), G4UIQt::AddIcon(), G4UImanager::ApplyCommand(), G4CascadeParamMessenger::CreateDirectory(), G4UImanager::FindCommand(), G4VBasicShell::FindCommand(), G4VisCommandDrawLogicalVolume::G4VisCommandDrawLogicalVolume(), G4VisCommandDrawVolume::G4VisCommandDrawVolume(), G4VisCommandOpen::G4VisCommandOpen(), G4VisCommandSceneAddMagneticField::G4VisCommandSceneAddMagneticField(), G4UImanager::GetCurrentValues(), and G4VBasicShell::TerminalHelp().

◆ GetCommand()

G4UIcommand * G4UIcommandTree::GetCommand ( G4int  i)
inline

Definition at line 77 of file G4UIcommandTree.hh.

77{ return command[i - 1]; }

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

◆ GetCommandEntry()

G4int G4UIcommandTree::GetCommandEntry ( ) const
inline

Definition at line 74 of file G4UIcommandTree.hh.

74{ return G4int(command.size()); }

Referenced by CompleteCommandPath(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ GetFirstMatchedString()

G4String G4UIcommandTree::GetFirstMatchedString ( const G4String str1,
const G4String str2 
) const

Definition at line 408 of file G4UIcommandTree.cc.

410{
411 std::size_t nlen1 = str1.length();
412 std::size_t nlen2 = str2.length();
413
414 std::size_t nmin = nlen1 < nlen2 ? nlen1 : nlen2;
415
416 G4String strMatched;
417 for(G4int i = 0; i < (G4int)nmin; ++i)
418 {
419 if(str1[i] == str2[i])
420 {
421 strMatched += str1[i];
422 }
423 else
424 {
425 break;
426 }
427 }
428
429 return strMatched;
430}

Referenced by CompleteCommandPath().

◆ GetGuidance()

const G4UIcommand * G4UIcommandTree::GetGuidance ( ) const
inline

Definition at line 71 of file G4UIcommandTree.hh.

71{ return guidance; }

Referenced by ListCurrent().

◆ GetPathName()

const G4String & G4UIcommandTree::GetPathName ( ) const
inline

◆ GetTitle()

const G4String G4UIcommandTree::GetTitle ( ) const
inline

Definition at line 78 of file G4UIcommandTree.hh.

79 {
80 return (guidance == nullptr) ? G4String("...Title not available...")
81 : guidance->GetTitle();
82 }
const G4String GetTitle() const

◆ GetTree() [1/2]

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

Definition at line 774 of file G4UIcommandTree.cc.

775{
776 G4String comName = comNameC;
777 for(auto& i : tree)
778 {
779 if(comName == i->GetPathName())
780 {
781 return i;
782 }
783 }
784 return nullptr;
785}

◆ GetTree() [2/2]

G4UIcommandTree * G4UIcommandTree::GetTree ( G4int  i)
inline

Definition at line 75 of file G4UIcommandTree.hh.

75{ return tree[i - 1]; }

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

◆ GetTreeEntry()

G4int G4UIcommandTree::GetTreeEntry ( ) const
inline

Definition at line 73 of file G4UIcommandTree.hh.

73{ return G4int(tree.size()); }

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

◆ List()

void G4UIcommandTree::List ( ) const

Definition at line 501 of file G4UIcommandTree.cc.

502{
503 ListCurrent();
504 std::size_t n_commandEntry = command.size();
505 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
506 {
507 command[i_thCommand]->List();
508 }
509 std::size_t n_treeEntry = tree.size();
510 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
511 {
512 tree[i_thTree]->List();
513 }
514}
void ListCurrent() const

Referenced by G4UImanager::ListCommands().

◆ ListCurrent()

void G4UIcommandTree::ListCurrent ( ) const

Definition at line 433 of file G4UIcommandTree.cc.

434{
435 G4cout << "Command directory path : " << pathName << G4endl;
436 if(guidance != nullptr)
437 {
438 guidance->List();
439 }
440 G4cout << " Sub-directories : " << G4endl;
441 std::size_t n_treeEntry = tree.size();
442 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
443 {
444 G4cout << " " << tree[i_thTree]->GetPathName();
445 if((tree[i_thTree]->GetGuidance() != nullptr) &&
446 tree[i_thTree]->GetGuidance()->IsWorkerThreadOnly())
447 {
448 G4cout << " @ ";
449 }
450 else
451 {
452 G4cout << " ";
453 }
454 G4cout << tree[i_thTree]->GetTitle() << G4endl;
455 }
456 G4cout << " Commands : " << G4endl;
457 std::size_t n_commandEntry = command.size();
458 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
459 {
460 G4cout << " " << command[i_thCommand]->GetCommandName();
461 if(command[i_thCommand]->IsWorkerThreadOnly())
462 {
463 G4cout << " @ ";
464 }
465 else
466 {
467 G4cout << " * ";
468 }
469 G4cout << command[i_thCommand]->GetTitle() << G4endl;
470 }
471}
const G4UIcommand * GetGuidance() const
virtual void List()
Definition: G4UIcommand.cc:411

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

◆ ListCurrentWithNum()

void G4UIcommandTree::ListCurrentWithNum ( ) const

Definition at line 474 of file G4UIcommandTree.cc.

475{
476 G4cout << "Command directory path : " << pathName << G4endl;
477 if(guidance != nullptr)
478 {
479 guidance->List();
480 }
481 G4int i = 0;
482 G4cout << " Sub-directories : " << G4endl;
483 std::size_t n_treeEntry = tree.size();
484 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
485 {
486 ++i;
487 G4cout << " " << i << ") " << tree[i_thTree]->GetPathName() << " "
488 << tree[i_thTree]->GetTitle() << G4endl;
489 }
490 G4cout << " Commands : " << G4endl;
491 std::size_t n_commandEntry = command.size();
492 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
493 {
494 ++i;
495 G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName()
496 << " * " << command[i_thCommand]->GetTitle() << G4endl;
497 }
498}

Referenced by G4VBasicShell::TerminalHelp().

◆ operator!=()

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

Definition at line 62 of file G4UIcommandTree.cc.

63{
64 return (pathName != right.GetPathName());
65}

◆ operator==()

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

Definition at line 56 of file G4UIcommandTree.cc.

57{
58 return (pathName == right.GetPathName());
59}

◆ RemoveCommand()

void G4UIcommandTree::RemoveCommand ( G4UIcommand aCommand,
G4bool  workerThreadOnly = false 
)

Definition at line 171 of file G4UIcommandTree.cc.

173{
174 if(workerThreadOnly && !(aCommand->IsWorkerThreadOnly()))
175 {
176 return;
177 }
178 G4String commandPath = aCommand->GetCommandPath();
179 G4String remainingPath = commandPath;
180 remainingPath.erase(0, pathName.length());
181 if(remainingPath.empty())
182 {
183 guidance = nullptr;
184 }
185 else
186 {
187 std::size_t i = remainingPath.find('/');
188 if(i == std::string::npos)
189 {
190 // Find command
191 std::size_t n_commandEntry = command.size();
192 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
193 {
194 if(remainingPath == command[i_thCommand]->GetCommandName())
195 {
196 command.erase(command.begin() + i_thCommand);
197 break;
198 }
199 }
200 }
201 else
202 {
203 // Find path
204 G4String nextPath = pathName;
205 nextPath.append(remainingPath.substr(0, i + 1));
206 std::size_t n_treeEntry = tree.size();
207 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
208 {
209 if(nextPath == tree[i_thTree]->GetPathName())
210 {
211 tree[i_thTree]->RemoveCommand(aCommand);
212 G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
213 G4int n_treeRemain = tree[i_thTree]->GetTreeEntry();
214 if(n_commandRemain == 0 && n_treeRemain == 0)
215 {
216 G4UIcommandTree* emptyTree = tree[i_thTree];
217 tree.erase(tree.begin() + i_thTree);
218 delete emptyTree;
219 }
220 break;
221 }
222 }
223 }
224 }
225}
G4bool IsWorkerThreadOnly() const
Definition: G4UIcommand.hh:177

Referenced by G4UImanager::RemoveCommand().


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