MCPcopy Create free account
hub / github.com/Geant4/geant4 / AddNewCommand

Method AddNewCommand

source/intercoms/src/G4UIcommandTree.cc:69–164  ·  view source on GitHub ↗

--------------------------------------------------------------------

Source from the content-addressed store, hash-verified

67
68// --------------------------------------------------------------------
69void G4UIcommandTree::AddNewCommand(G4UIcommand* newCommand, G4bool workerThreadOnly)
70{
71 G4String commandPath = newCommand->GetCommandPath();
72 G4String remainingPath = commandPath;
73 remainingPath.erase(0, pathName.length());
74 if (remainingPath.empty()) {
75 if (guidance == nullptr) {
76 guidance = newCommand;
77 if (!(newCommand->ToBeBroadcasted())) {
78 broadcastCommands = false;
79 }
80 if (workerThreadOnly) {
81 newCommand->SetWorkerThreadOnly();
82 }
83 }
84 return;
85 }
86
87 if (guidance != nullptr) {
88 auto* dir = static_cast<G4UIdirectory*>(guidance);
89 ifSort = dir->IfSort();
90 }
91 std::size_t i = remainingPath.find('/');
92 if (i == std::string::npos) {
93 // Adding a new command to this directory
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()) {
97 // a command of same name has already defined. do nothing and return.
98 if (G4UImanager::GetUIpointer()->GetVerboseLevel() > 8) {
99 G4ExceptionDescription ed;
100 ed << "Command <" << commandPath << "> already exist. New command is not added.";
101 G4Exception("G4UIcommandTree::AddNewCommand", "UI_ComTree_001",
102 // FatalException,
103 JustWarning, ed);
104 }
105 return;
106 }
107 }
108 if (!broadcastCommands) {
109 newCommand->SetToBeBroadcasted(false);
110 }
111 if (workerThreadOnly) {
112 newCommand->SetWorkerThreadOnly();
113 }
114 if (ifSort) {
115 auto j = command.cbegin();
116 for (; j != command.cend(); ++j) {
117 if (newCommand->GetCommandPath() < (*j)->GetCommandPath()) {
118 break;
119 }
120 }
121 command.insert(j, newCommand);
122 }
123 else {
124 command.push_back(newCommand);
125 }
126 return;

Callers

nothing calls this directly

Calls 15

G4ExceptionFunction · 0.85
ToBeBroadcastedMethod · 0.80
SetWorkerThreadOnlyMethod · 0.80
IfSortMethod · 0.80
SetToBeBroadcastedMethod · 0.80
substrMethod · 0.80
SetDefaultSortFlagMethod · 0.80
lengthMethod · 0.45
emptyMethod · 0.45
findMethod · 0.45
sizeMethod · 0.45
GetVerboseLevelMethod · 0.45

Tested by

no test coverage detected