Geant4-11
Public Member Functions | Private Member Functions | Private Attributes
G4UIcommandTree Class Reference

#include <G4UIcommandTree.hh>

Public Member Functions

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

Private Member Functions

G4String CreateFileName (const char *pName)
 
G4String ModStr (const char *strS)
 

Private Attributes

G4bool broadcastCommands = true
 
std::vector< G4UIcommand * > command
 
G4int createHTMLTreeLevel = 0
 
G4UIcommandguidance = nullptr
 
G4bool ifSort = false
 
G4String pathName
 
std::vector< G4UIcommandTree * > tree
 

Detailed Description

Definition at line 44 of file G4UIcommandTree.hh.

Constructor & Destructor Documentation

◆ G4UIcommandTree() [1/2]

G4UIcommandTree::G4UIcommandTree ( )

Definition at line 41 of file G4UIcommandTree.cc.

42{
43}

Referenced by AddNewCommand().

◆ G4UIcommandTree() [2/2]

G4UIcommandTree::G4UIcommandTree ( const char *  thePathName)

Definition at line 46 of file G4UIcommandTree.cc.

47{
48 pathName = thePathName;
49}

References pathName.

◆ ~G4UIcommandTree()

G4UIcommandTree::~G4UIcommandTree ( )

Definition at line 52 of file G4UIcommandTree.cc.

53{
54 G4int i;
55 G4int n_treeEntry = tree.size();
56 for(i = 0; i < n_treeEntry; ++i)
57 {
58 delete tree[i];
59 }
60}
int G4int
Definition: G4Types.hh:85
std::vector< G4UIcommandTree * > tree

References tree.

Member Function Documentation

◆ AddNewCommand()

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

Definition at line 75 of file G4UIcommandTree.cc.

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

References AddNewCommand(), broadcastCommands, command, G4Exception(), G4UIcommandTree(), G4UIcommand::GetCommandPath(), GetPathName(), G4UImanager::GetUIpointer(), G4UImanager::GetVerboseLevel(), guidance, ifSort, G4UIdirectory::IfSort(), JustWarning, pathName, G4UIcommand::SetDefaultSortFlag(), G4UIcommand::SetToBeBroadcasted(), G4UIcommand::SetWorkerThreadOnly(), G4UIcommand::ToBeBroadcasted(), and tree.

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

◆ CompleteCommandPath()

G4String G4UIcommandTree::CompleteCommandPath ( const G4String commandPath)

Definition at line 311 of file G4UIcommandTree.cc.

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

References anonymous_namespace{G4MTcoutDestination.cc}::empty, FindCommandTree(), G4cout, G4endl, GetCommand(), GetCommandEntry(), G4UIcommand::GetCommandName(), GetFirstMatchedString(), GetPathName(), GetTree(), and GetTreeEntry().

◆ CreateFileName()

G4String G4UIcommandTree::CreateFileName ( const char *  pName)
private

Definition at line 513 of file G4UIcommandTree.cc.

514{
515 G4String fn = pName;
516 G4int idxs;
517 while((idxs = fn.find("/")) != G4int(std::string::npos))
518 {
519 fn[idxs] = '_';
520 }
521 fn += ".html";
522 return fn;
523}

Referenced by CreateHTML().

◆ CreateHTML()

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

Definition at line 552 of file G4UIcommandTree.cc.

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

References command, CreateFileName(), createHTMLTreeLevel, G4endl, G4UIcommand::GetCommandName(), G4UIparameter::GetCurrentAsDefault(), G4UIparameter::GetDefaultValue(), G4UIcommand::GetGuidanceEntries(), G4UIcommand::GetGuidanceLine(), G4UIcommand::GetParameter(), G4UIparameter::GetParameterCandidates(), G4UIcommand::GetParameterEntries(), G4UIparameter::GetParameterName(), G4UIparameter::GetParameterRange(), G4UIparameter::GetParameterType(), GetPathName(), G4UIcommand::GetRange(), G4UIcommand::GetStateList(), G4StateManager::GetStateManager(), G4StateManager::GetStateString(), GetTitle(), guidance, G4UIparameter::IsOmittable(), ModStr(), pathName, and tree.

Referenced by G4UImanager::CreateHTML(), and export_G4UIcommandTree().

◆ FindCommandTree()

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

Definition at line 272 of file G4UIcommandTree.cc.

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

References GetPathName(), pathName, and tree.

Referenced by CompleteCommandPath(), G4UIQt::CreateCompleterModel(), G4UImessenger::CreateDirectory(), G4UIWin32::GetHelpTreeToolTips(), G4UIQt::HelpTreeClicCallback(), G4UIQt::UpdateCommandCompleter(), and G4OpenGLQtViewer::updateViewerPropertiesTableWidget().

◆ FindPath()

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

Definition at line 231 of file G4UIcommandTree.cc.

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

References command, GetPathName(), pathName, and tree.

Referenced by G4UIQt::AddButton(), G4UIQt::AddIcon(), G4UImanager::ApplyCommand(), G4UIQt::ButtonCallback(), G4CascadeParamMessenger::CreateDirectory(), export_G4UIcommandTree(), G4UImanager::FindCommand(), G4VBasicShell::FindCommand(), G4VisCommandDrawLogicalVolume::G4VisCommandDrawLogicalVolume(), G4VisCommandDrawVolume::G4VisCommandDrawVolume(), G4VisCommandSceneAddMagneticField::G4VisCommandSceneAddMagneticField(), G4UImanager::GetCurrentValues(), G4UIWin32::GetHelpTreeToolTips(), G4UIQt::HelpTreeClicCallback(), G4UIQt::OpenHelpTreeOnCommand(), and G4VBasicShell::TerminalHelp().

◆ GetCommand()

G4UIcommand * G4UIcommandTree::GetCommand ( G4int  i)
inline

◆ GetCommandEntry()

G4int G4UIcommandTree::GetCommandEntry ( ) const
inline

◆ GetFirstMatchedString()

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

Definition at line 408 of file G4UIcommandTree.cc.

410{
411 G4int nlen1 = str1.length();
412 G4int nlen2 = str2.length();
413
414 G4int nmin = nlen1 < nlen2 ? nlen1 : nlen2;
415
416 G4String strMatched;
417 for(size_t i = 0; G4int(i) < 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(), and G4UIQt::CreateCompleterModel().

◆ GetGuidance()

const G4UIcommand * G4UIcommandTree::GetGuidance ( ) const
inline

Definition at line 71 of file G4UIcommandTree.hh.

71{ return guidance; }

References guidance.

Referenced by export_G4UIcommandTree(), ListCurrent(), and G4UIQt::LookForHelpStringInChildTree().

◆ 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 }

References G4UIcommand::GetTitle(), and guidance.

Referenced by CreateHTML(), export_G4UIcommandTree(), G4UIWin32::GetHelpTreeToolTips(), and G4UIQt::HelpTreeClicCallback().

◆ GetTree() [1/2]

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

Definition at line 770 of file G4UIcommandTree.cc.

771{
772 G4String comName = comNameC;
773 for(std::size_t i = 0; i < tree.size(); ++i)
774 {
775 if(comName == tree[i]->GetPathName())
776 {
777 return tree[i];
778 }
779 }
780 return nullptr;
781}

References GetPathName(), and tree.

◆ GetTree() [2/2]

G4UIcommandTree * G4UIcommandTree::GetTree ( G4int  i)
inline

◆ GetTreeEntry()

G4int G4UIcommandTree::GetTreeEntry ( ) const
inline

◆ List()

void G4UIcommandTree::List ( ) const

Definition at line 497 of file G4UIcommandTree.cc.

498{
499 ListCurrent();
500 G4int n_commandEntry = command.size();
501 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
502 {
503 command[i_thCommand]->List();
504 }
505 G4int n_treeEntry = tree.size();
506 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
507 {
508 tree[i_thTree]->List();
509 }
510}
void ListCurrent() const

References command, ListCurrent(), and tree.

Referenced by export_G4UIcommandTree(), and 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 guidance->List();
438 G4cout << " Sub-directories : " << G4endl;
439 G4int n_treeEntry = tree.size();
440 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
441 {
442 G4cout << " " << tree[i_thTree]->GetPathName();
443 if(tree[i_thTree]->GetGuidance() &&
444 tree[i_thTree]->GetGuidance()->IsWorkerThreadOnly())
445 {
446 G4cout << " @ ";
447 }
448 else
449 {
450 G4cout << " ";
451 }
452 G4cout << tree[i_thTree]->GetTitle() << G4endl;
453 }
454 G4cout << " Commands : " << G4endl;
455 G4int n_commandEntry = command.size();
456 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
457 {
458 G4cout << " " << command[i_thCommand]->GetCommandName();
459 if(command[i_thCommand]->IsWorkerThreadOnly())
460 {
461 G4cout << " @ ";
462 }
463 else
464 {
465 G4cout << " * ";
466 }
467 G4cout << command[i_thCommand]->GetTitle() << G4endl;
468 }
469}
const G4UIcommand * GetGuidance() const
virtual void List()
Definition: G4UIcommand.cc:410

References command, G4cout, G4endl, GetGuidance(), guidance, G4UIcommand::List(), pathName, and tree.

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

◆ ListCurrentWithNum()

void G4UIcommandTree::ListCurrentWithNum ( ) const

Definition at line 472 of file G4UIcommandTree.cc.

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

References command, G4cout, G4endl, guidance, G4UIcommand::List(), pathName, and tree.

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

◆ ModStr()

G4String G4UIcommandTree::ModStr ( const char *  strS)
private

Definition at line 526 of file G4UIcommandTree.cc.

527{
528 G4String sx;
529 G4String str = strS;
530 for(G4int i = 0; i < G4int(str.length()); ++i)
531 {
532 char c = str[i];
533 switch(c)
534 {
535 case '<':
536 sx += "&lt;";
537 break;
538 case '>':
539 sx += "&gt;";
540 break;
541 case '&':
542 sx += "&amp;";
543 break;
544 default:
545 sx += c;
546 }
547 }
548 return sx;
549}

Referenced by CreateHTML().

◆ operator!=()

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

Definition at line 69 of file G4UIcommandTree.cc.

70{
71 return (pathName != right.GetPathName());
72}

References GetPathName(), and pathName.

◆ operator==()

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

Definition at line 63 of file G4UIcommandTree.cc.

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

References GetPathName(), and pathName.

◆ RemoveCommand()

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

Definition at line 176 of file G4UIcommandTree.cc.

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

References command, G4UIcommand::GetCommandPath(), GetPathName(), guidance, G4UIcommand::IsWorkerThreadOnly(), pathName, and tree.

Referenced by G4UImanager::RemoveCommand(), and G4UImanager::RemoveWorkerCommand().

Field Documentation

◆ broadcastCommands

G4bool G4UIcommandTree::broadcastCommands = true
private

Definition at line 93 of file G4UIcommandTree.hh.

Referenced by AddNewCommand().

◆ command

std::vector<G4UIcommand*> G4UIcommandTree::command
private

◆ createHTMLTreeLevel

G4int G4UIcommandTree::createHTMLTreeLevel = 0
private

Definition at line 95 of file G4UIcommandTree.hh.

Referenced by CreateHTML().

◆ guidance

G4UIcommand* G4UIcommandTree::guidance = nullptr
private

◆ ifSort

G4bool G4UIcommandTree::ifSort = false
private

Definition at line 94 of file G4UIcommandTree.hh.

Referenced by AddNewCommand().

◆ pathName

G4String G4UIcommandTree::pathName
private

◆ tree

std::vector<G4UIcommandTree*> G4UIcommandTree::tree
private

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