43 pathName = thePathName;
49 for(std::size_t i = 0; i < tree.size(); ++i)
72 G4String remainingPath = commandPath;
73 remainingPath.erase(0, pathName.length());
74 if(remainingPath.empty())
76 if(guidance ==
nullptr)
78 guidance = newCommand;
80 { broadcastCommands =
false; }
87 if(guidance !=
nullptr)
90 ifSort = dir->IfSort();
92 std::size_t i = remainingPath.find(
'/');
93 if(i == std::string::npos)
96 std::size_t n_commandEntry = command.size();
97 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
99 if(remainingPath == command[i_thCommand]->GetCommandName())
105 ed <<
"Command <" << commandPath <<
"> already exist. New command is not added.";
106 G4Exception(
"G4UIcommandTree::AddNewCommand",
"UI_ComTree_001",
114 if(!broadcastCommands)
120 auto j = command.cbegin();
121 for(; j != command.cend(); ++j) {
122 if (newCommand->
GetCommandPath() < (*j)->GetCommandPath()) {
break; }
124 command.insert(j,newCommand);
127 { command.push_back(newCommand); }
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)
140 if(!broadcastCommands)
144 tree[i_thTree]->AddNewCommand(newCommand, workerThreadOnly);
152 auto j = tree.cbegin();
153 for(; j != tree.cend(); ++j) {
154 if (newTree->GetPathName() < (*j)->GetPathName()) {
break; }
156 tree.insert(j,newTree);
159 { tree.push_back(newTree); }
160 if(!broadcastCommands)
165 newTree->AddNewCommand(newCommand, workerThreadOnly);
179 G4String remainingPath = commandPath;
180 remainingPath.erase(0, pathName.length());
181 if(remainingPath.empty())
187 std::size_t i = remainingPath.find(
'/');
188 if(i == std::string::npos)
191 std::size_t n_commandEntry = command.size();
192 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
194 if(remainingPath == command[i_thCommand]->GetCommandName())
196 command.erase(command.begin() + i_thCommand);
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)
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)
217 tree.erase(tree.begin() + i_thTree);
232 G4String remainingPath = commandPath;
233 if(remainingPath.find(pathName) == std::string::npos)
237 remainingPath.erase(0, pathName.length());
238 std::size_t i = remainingPath.find(
'/');
239 if(i == std::string::npos)
242 std::size_t n_commandEntry = command.size();
243 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
245 if(remainingPath == command[i_thCommand]->GetCommandName())
247 return command[i_thCommand];
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)
261 return tree[i_thTree]->FindPath(commandPath);
275 G4String remainingPath = commandPath;
276 if(remainingPath.find(pathName) == std::string::npos)
280 remainingPath.erase(0, pathName.length());
281 std::size_t i = remainingPath.find(
'/');
282 if(i != std::string::npos)
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)
292 return tree[i_thTree];
296 return tree[i_thTree]->FindCommandTree(commandPath);
311 G4String remainingPath = aCommandPath;
316 auto jpre = pName.rfind(
'/');
317 if(jpre != G4String::npos)
319 pName.erase(jpre + 1);
328 if(pName.find(pName) == std::string::npos)
333 std::vector<G4String> paths;
343 for(
G4int idir = 1; idir <= Ndir; ++idir)
347 if(fpdir.find(remainingPath, 0) == 0)
351 matchingPath = fpdir;
358 paths.push_back(fpdir);
362 if(paths.size() >= 2)
365 for(
const auto& path : paths)
372 std::vector<G4String> commands;
374 for(
G4int icmd = 1; icmd <= Ncmd; ++icmd)
379 if(fpcmd.find(remainingPath, 0) == 0)
383 matchingPath = fpcmd +
" ";
387 strtmp = fpcmd +
" ";
391 commands.emplace_back(fpcmd +
" ");
395 if(commands.size() >= 2)
398 for(
const auto& matched : commands)
411 std::size_t nlen1 = str1.length();
412 std::size_t nlen2 = str2.length();
414 std::size_t nmin = nlen1 < nlen2 ? nlen1 : nlen2;
419 if(str1[i] == str2[i])
421 strMatched += str1[i];
435 G4cout <<
"Command directory path : " << pathName <<
G4endl;
436 if(guidance !=
nullptr)
441 std::size_t n_treeEntry = tree.size();
442 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
444 G4cout <<
" " << tree[i_thTree]->GetPathName();
446 tree[i_thTree]->
GetGuidance()->IsWorkerThreadOnly())
457 std::size_t n_commandEntry = command.size();
458 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
460 G4cout <<
" " << command[i_thCommand]->GetCommandName();
461 if(command[i_thCommand]->IsWorkerThreadOnly())
476 G4cout <<
"Command directory path : " << pathName <<
G4endl;
477 if(guidance !=
nullptr)
483 std::size_t n_treeEntry = tree.size();
484 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
487 G4cout <<
" " << i <<
") " << tree[i_thTree]->GetPathName() <<
" "
488 << tree[i_thTree]->GetTitle() <<
G4endl;
491 std::size_t n_commandEntry = command.size();
492 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
495 G4cout <<
" " << i <<
") " << command[i_thCommand]->GetCommandName()
496 <<
" * " << command[i_thCommand]->GetTitle() <<
G4endl;
504 std::size_t n_commandEntry = command.size();
505 for(std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand)
507 command[i_thCommand]->List();
509 std::size_t n_treeEntry = tree.size();
510 for(std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree)
512 tree[i_thTree]->List();
517G4String G4UIcommandTree::CreateFileName(
const char* pName)
521 while((idxs = fn.find(
"/")) != std::string::npos)
523 fn[(
G4int)idxs] =
'_';
530G4String G4UIcommandTree::ModStr(
const char* strS)
534 for(
G4int i = 0; i <
G4int(str.length()); ++i)
558 G4String ofileName = CreateFileName(pathName);
559 std::ofstream oF(ofileName, std::ios::out);
561 oF <<
"<html><head><title>Commands in " << ModStr(pathName)
562 <<
"</title></head>" <<
G4endl;
564 table,table td,table th { \
565 border:1px solid #eee \
567 table td,table th { \
574 text-decoration:none; \
575 transition-duration:0.3s \
581 border-collapse:collapse; \
588 letter-spacing:-1px; \
589 line-height:1.15em; \
590 margin-bottom:0.5em; \
591 word-wrap:break-word \
596 letter-spacing:-1px; \
597 line-height:1.15em; \
598 margin-bottom:0.5em; \
599 word-wrap:break-word \
605 padding:15px 0 15px 0; \
606 border-bottom:2px #eee solid; \
607 word-wrap:break-word \
614 -webkit-box-sizing:border-box; \
615 -moz-box-sizing:border-box; \
616 -ms-box-sizing:border-box; \
617 box-sizing:border-box; \
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 \
632 oF <<
"<body bgcolor=\"#ffffff\">" <<
G4endl;
635 if (createHTMLTreeLevel == 0 ) {
636 oF <<
"<div class=\"sidebar\">" << sideBar <<
"</div>" <<
G4endl;
639 oF <<
"<div class=\"context\">";
640 oF <<
"<h1>" << ModStr(pathName) <<
"</h1>" <<
G4endl;
642 if(guidance !=
nullptr)
653 menu +=
"<h2>Sub-directories </h2><table>";
654 newSideBar +=
"<h2><a href=\"" + ofileName +
"\">Top level </a></h2><table>";
656 for(
auto& i_thTree : tree)
658 newSideBar +=
"<tr><td><a href=\"" +
659 CreateFileName(i_thTree->GetPathName()) +
"\">" +
660 ModStr(i_thTree->GetPathName()) +
"</a>";
663 for(
auto& i_thTree : tree)
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>";
670 newSideBar +=
"</table>";
671 for(
auto& i_thTree : tree)
673 createHTMLTreeLevel ++;
674 i_thTree->CreateHTML(newSideBar);
675 createHTMLTreeLevel --;
682 oF <<
"<h2>Commands </h2>" <<
G4endl;
685 oF <<
"<table>" <<
G4endl;
686 for(std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand)
689 oF <<
"<tr><td><a href=\"#c"<< i_thCommand <<
"\">"<< ModStr(cmd->
GetCommandName());
690 oF <<
"</a></td></tr>" <<
G4endl;
692 oF <<
"</table>" <<
G4endl;
693 for(std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand)
696 oF <<
"<h3 id=\"c" << i_thCommand <<
"\">" << ModStr(cmd->
GetCommandName());
717 std::vector<G4ApplicationState>* availabelStateList = cmd->
GetStateList();
718 if(availabelStateList->size() == 6)
720 oF <<
"<p>Available at all Geant4 states." <<
G4endl;
724 oF <<
"<p>Available Geant4 state(s) : ";
725 for(
auto& ias : *availabelStateList)
733 oF <<
"<p>Parameters<table border=1>" <<
G4endl;
743 oF <<
"Omittable : ";
746 oF <<
"current value is used as the default value." <<
G4endl;
761 oF <<
"Parameter candidates : "
765 oF <<
"</table>" <<
G4endl;
769 oF <<
"</div></body></html>" <<
G4endl;
779 if(comName == i->GetPathName())
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
std::ostringstream G4ExceptionDescription
G4GLOB_DLL std::ostream G4cout
G4String GetStateString(const G4ApplicationState &aState) const
static G4StateManager * GetStateManager()
G4bool operator!=(const G4UIcommandTree &right) const
G4int GetCommandEntry() const
G4UIcommandTree()=default
const G4UIcommand * GetGuidance() const
G4UIcommand * GetCommand(G4int i)
const G4String & GetPathName() const
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
G4bool operator==(const G4UIcommandTree &right) const
void AddNewCommand(G4UIcommand *newCommand, G4bool workerThreadOnly=false)
G4UIcommandTree * FindCommandTree(const char *commandPath)
void ListCurrentWithNum() const
G4String CompleteCommandPath(const G4String &commandPath)
G4String GetFirstMatchedString(const G4String &, const G4String &) const
void CreateHTML(const G4String &="")
G4UIcommand * FindPath(const char *commandPath) const
void RemoveCommand(G4UIcommand *aCommand, G4bool workerThreadOnly=false)
void SetToBeBroadcasted(G4bool val)
G4bool IsWorkerThreadOnly() const
std::size_t GetParameterEntries() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
G4bool ToBeBroadcasted() const
const G4String & GetCommandPath() const
std::size_t GetGuidanceEntries() const
std::vector< G4ApplicationState > * GetStateList()
void SetWorkerThreadOnly(G4bool val=true)
const G4String & GetCommandName() const
const G4String & GetRange() const
void SetDefaultSortFlag(G4bool val)
G4int GetVerboseLevel() const
static G4UImanager * GetUIpointer()
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