45 pathName = thePathName;
51 for (
auto& i : tree) {
72 G4String remainingPath = commandPath;
73 remainingPath.erase(0, pathName.length());
74 if (remainingPath.empty()) {
75 if (guidance ==
nullptr) {
76 guidance = newCommand;
78 broadcastCommands =
false;
80 if (workerThreadOnly) {
87 if (guidance !=
nullptr) {
89 ifSort = dir->IfSort();
91 std::size_t i = remainingPath.find(
'/');
92 if (i == std::string::npos) {
94 std::size_t n_commandEntry = command.size();
95 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
96 if (remainingPath == command[i_thCommand]->GetCommandName()) {
100 ed <<
"Command <" << commandPath <<
"> already exist. New command is not added.";
101 G4Exception(
"G4UIcommandTree::AddNewCommand",
"UI_ComTree_001",
108 if (!broadcastCommands) {
111 if (workerThreadOnly) {
115 auto j = command.cbegin();
116 for (; j != command.cend(); ++j) {
121 command.insert(j, newCommand);
124 command.push_back(newCommand);
131 nextPath.append(remainingPath.substr(0, i + 1));
132 std::size_t n_treeEntry = tree.size();
133 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
135 if (!broadcastCommands) {
138 tree[i_thTree]->AddNewCommand(newCommand, workerThreadOnly);
145 auto j = tree.cbegin();
146 for (; j != tree.cend(); ++j) {
147 if (newTree->GetPathName() < (*j)->GetPathName()) {
151 tree.insert(j, newTree);
154 tree.push_back(newTree);
156 if (!broadcastCommands) {
162 newTree->AddNewCommand(newCommand, workerThreadOnly);
173 G4String remainingPath = commandPath;
174 remainingPath.erase(0, pathName.length());
175 if (remainingPath.empty()) {
179 std::size_t i = remainingPath.find(
'/');
180 if (i == std::string::npos) {
182 std::size_t n_commandEntry = command.size();
183 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
184 if (remainingPath == command[i_thCommand]->GetCommandName()) {
185 command.erase(command.begin() + i_thCommand);
193 nextPath.append(remainingPath.substr(0, i + 1));
194 std::size_t n_treeEntry = tree.size();
195 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
197 tree[i_thTree]->RemoveCommand(aCommand);
198 G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
199 G4int n_treeRemain = tree[i_thTree]->GetTreeEntry();
200 if (n_commandRemain == 0 && n_treeRemain == 0) {
202 tree.erase(tree.begin() + i_thTree);
217 G4String remainingPath = commandPath;
218 if (remainingPath.find(pathName) == std::string::npos) {
221 remainingPath.erase(0, pathName.length());
222 std::size_t i = remainingPath.find(
'/');
223 if (i == std::string::npos) {
225 std::size_t n_commandEntry = command.size();
226 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
227 if (remainingPath == command[i_thCommand]->GetCommandName()) {
228 return command[i_thCommand];
235 nextPath.append(remainingPath.substr(0, i + 1));
236 std::size_t n_treeEntry = tree.size();
237 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
239 return tree[i_thTree]->FindPath(commandPath);
253 G4String remainingPath = commandPath;
254 if (remainingPath.find(pathName) == std::string::npos) {
257 remainingPath.erase(0, pathName.length());
258 std::size_t i = remainingPath.find(
'/');
259 if (i != std::string::npos) {
262 nextPath.append(remainingPath.substr(0, i + 1));
263 std::size_t n_treeEntry = tree.size();
264 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
265 if (tree[i_thTree]->
GetPathName() == commandPath) {
266 return tree[i_thTree];
269 return tree[i_thTree]->FindCommandTree(commandPath);
283 G4String remainingPath = aCommandPath;
288 auto jpre = pName.rfind(
'/');
289 if (jpre != G4String::npos) {
290 pName.erase(jpre + 1);
294 if (aTree ==
nullptr) {
298 if (pName.find(pName) == std::string::npos) {
302 std::vector<G4String> paths;
312 for (
G4int idir = 1; idir <= Ndir; ++idir) {
315 if (fpdir.find(remainingPath, 0) == 0) {
317 matchingPath = fpdir;
323 paths.push_back(fpdir);
327 if (paths.size() >= 2) {
329 for (
const auto& path : paths) {
335 std::vector<G4String> commands;
337 for (
G4int icmd = 1; icmd <= Ncmd; ++icmd) {
340 if (fpcmd.find(remainingPath, 0) == 0) {
342 matchingPath = fpcmd +
" ";
345 strtmp = fpcmd +
" ";
349 commands.emplace_back(fpcmd +
" ");
353 if (commands.size() >= 2) {
355 for (
const auto& matched : commands) {
366 std::size_t nlen1 = str1.length();
367 std::size_t nlen2 = str2.length();
369 std::size_t nmin = nlen1 < nlen2 ? nlen1 : nlen2;
373 if (str1[i] == str2[i]) {
374 strMatched += str1[i];
387 G4cout <<
"Command directory path : " << pathName <<
G4endl;
388 if (guidance !=
nullptr) {
392 std::size_t n_treeEntry = tree.size();
393 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
394 G4cout <<
" " << tree[i_thTree]->GetPathName();
396 && tree[i_thTree]->
GetGuidance()->IsWorkerThreadOnly())
406 std::size_t n_commandEntry = command.size();
407 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
408 G4cout <<
" " << command[i_thCommand]->GetCommandName();
409 if (command[i_thCommand]->IsWorkerThreadOnly()) {
422 G4cout <<
"Command directory path : " << pathName <<
G4endl;
423 if (guidance !=
nullptr) {
428 std::size_t n_treeEntry = tree.size();
429 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
431 G4cout <<
" " << i <<
") " << tree[i_thTree]->GetPathName() <<
" "
432 << tree[i_thTree]->GetTitle() <<
G4endl;
435 std::size_t n_commandEntry = command.size();
436 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
438 G4cout <<
" " << i <<
") " << command[i_thCommand]->GetCommandName() <<
" * "
439 << command[i_thCommand]->GetTitle() <<
G4endl;
447 std::size_t n_commandEntry = command.size();
448 for (std::size_t i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) {
449 command[i_thCommand]->List();
451 std::size_t n_treeEntry = tree.size();
452 for (std::size_t i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) {
453 tree[i_thTree]->List();
458G4String G4UIcommandTree::CreateFileName(
const char* pName)
462 while ((idxs = fn.find(
'/')) != std::string::npos) {
463 fn[(
G4int)idxs] =
'_';
470G4String G4UIcommandTree::ModStr(
const char* strS)
474 for (
G4int i = 0; i <
G4int(str.length()); ++i) {
496 G4String ofileName = CreateFileName(pathName);
497 std::ofstream oF(ofileName, std::ios::out);
499 oF <<
"<html><head><title>Commands in " << ModStr(pathName) <<
"</title></head>" <<
G4endl;
501 table,table td,table th { \
502 border:1px solid #eee \
504 table td,table th { \
511 text-decoration:none; \
512 transition-duration:0.3s \
518 border-collapse:collapse; \
525 letter-spacing:-1px; \
526 line-height:1.15em; \
527 margin-bottom:0.5em; \
528 word-wrap:break-word \
533 letter-spacing:-1px; \
534 line-height:1.15em; \
535 margin-bottom:0.5em; \
536 word-wrap:break-word \
542 padding:15px 0 15px 0; \
543 border-bottom:2px #eee solid; \
544 word-wrap:break-word \
551 -webkit-box-sizing:border-box; \
552 -moz-box-sizing:border-box; \
553 -ms-box-sizing:border-box; \
554 box-sizing:border-box; \
560 display:inline-block; \
561 background-color:#fff; \
562 padding: 25px 35px 20px 30px; \
563 -webkit-box-sizing:border-box; \
564 -moz-box-sizing:border-box; \
565 -ms-box-sizing:border-box; \
566 box-sizing:border-box \
570 oF <<
"<body bgcolor=\"#ffffff\">" <<
G4endl;
573 if (createHTMLTreeLevel == 0) {
574 oF <<
"<div class=\"sidebar\">" << sideBar <<
"</div>" <<
G4endl;
577 oF <<
"<div class=\"context\">";
578 oF <<
"<h1>" << ModStr(pathName) <<
"</h1>" <<
G4endl;
580 if (guidance !=
nullptr) {
588 menu +=
"<h2>Sub-directories </h2><table>";
589 newSideBar +=
"<h2><a href=\"" + ofileName +
"\">Top level </a></h2><table>";
591 for (
auto& i_thTree : tree) {
592 newSideBar +=
"<tr><td><a href=\"" + CreateFileName(i_thTree->GetPathName()) +
"\">"
593 + ModStr(i_thTree->GetPathName()) +
"</a>";
596 for (
auto& i_thTree : tree) {
597 menu +=
"<tr><td><a href=\"" + CreateFileName(i_thTree->GetPathName()) +
"\">"
598 + ModStr(i_thTree->GetPathName()) +
"</a>";
599 menu +=
"</td><td>" + ModStr(i_thTree->GetTitle()) +
"</tr>";
602 newSideBar +=
"</table>";
603 for (
auto& i_thTree : tree) {
604 createHTMLTreeLevel++;
605 i_thTree->CreateHTML(newSideBar);
606 createHTMLTreeLevel--;
611 if (!command.empty()) {
612 oF <<
"<h2>Commands </h2>" <<
G4endl;
615 oF <<
"<table>" <<
G4endl;
616 for (std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand) {
618 oF <<
"<tr><td><a href=\"#c" << i_thCommand <<
"\">" << ModStr(cmd->
GetCommandName());
619 oF <<
"</a></td></tr>" <<
G4endl;
621 oF <<
"</table>" <<
G4endl;
622 for (std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand) {
624 oF <<
"<h3 id=\"c" << i_thCommand <<
"\">" << ModStr(cmd->
GetCommandName());
638 std::vector<G4ApplicationState>* availabelStateList = cmd->
GetStateList();
639 if (availabelStateList->size() == 6) {
640 oF <<
"<p>Available at all Geant4 states." <<
G4endl;
643 oF <<
"<p>Available Geant4 state(s) : ";
644 for (
auto& ias : *availabelStateList) {
649 oF <<
"<p>Parameters<table border=1>" <<
G4endl;
656 oF <<
"Omittable : ";
658 oF <<
"current value is used as the default value." <<
G4endl;
672 oF <<
"</table>" <<
G4endl;
676 oF <<
"</div></body></html>" <<
G4endl;
684 for (
auto& i : tree) {
685 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)
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