Geant4 Cross Reference |
>> 1 // 1 // ******************************************* 2 // ******************************************************************** 2 // * License and Disclaimer 3 // * License and Disclaimer * 3 // * 4 // * * 4 // * The Geant4 software is copyright of th 5 // * The Geant4 software is copyright of the Copyright Holders of * 5 // * the Geant4 Collaboration. It is provided 6 // * the Geant4 Collaboration. It is provided under the terms and * 6 // * conditions of the Geant4 Software License 7 // * conditions of the Geant4 Software License, included in the file * 7 // * LICENSE and available at http://cern.ch/ 8 // * LICENSE and available at http://cern.ch/geant4/license . These * 8 // * include a list of copyright holders. 9 // * include a list of copyright holders. * 9 // * 10 // * * 10 // * Neither the authors of this software syst 11 // * Neither the authors of this software system, nor their employing * 11 // * institutes,nor the agencies providing fin 12 // * institutes,nor the agencies providing financial support for this * 12 // * work make any representation or warran 13 // * work make any representation or warranty, express or implied, * 13 // * regarding this software system or assum 14 // * regarding this software system or assume any liability for its * 14 // * use. Please see the license in the file 15 // * use. Please see the license in the file LICENSE and URL above * 15 // * for the full disclaimer and the limitatio 16 // * for the full disclaimer and the limitation of liability. * 16 // * 17 // * * 17 // * This code implementation is the result 18 // * This code implementation is the result of the scientific and * 18 // * technical work of the GEANT4 collaboratio 19 // * technical work of the GEANT4 collaboration. * 19 // * By using, copying, modifying or distri 20 // * By using, copying, modifying or distributing the software (or * 20 // * any work based on the software) you ag 21 // * any work based on the software) you agree to acknowledge its * 21 // * use in resulting scientific publicati 22 // * use in resulting scientific publications, and indicate your * 22 // * acceptance of all terms of the Geant4 Sof 23 // * acceptance of all terms of the Geant4 Software license. * 23 // ******************************************* 24 // ******************************************************************** 24 // 25 // 25 // G4UIcommandTree 26 // G4UIcommandTree 26 // 27 // 27 // Author: Makoto Asai (SLAC), 1998 28 // Author: Makoto Asai (SLAC), 1998 28 // Midified: Makoto Asai (SLAC), 2021 << 29 // Improve output HTML file layout and add o << 30 // command/directory names in alphabetic ord << 31 // ------------------------------------------- 29 // -------------------------------------------------------------------- 32 30 33 #include "G4UIcommandTree.hh" 31 #include "G4UIcommandTree.hh" 34 << 35 #include "G4StateManager.hh" 32 #include "G4StateManager.hh" 36 #include "G4UIdirectory.hh" << 33 #include <fstream> 37 #include "G4UImanager.hh" << 38 #include "G4ios.hh" 34 #include "G4ios.hh" 39 35 40 #include <fstream> << 36 // -------------------------------------------------------------------- >> 37 G4UIcommandTree::G4UIcommandTree() >> 38 { >> 39 } 41 40 42 // ------------------------------------------- 41 // -------------------------------------------------------------------- 43 G4UIcommandTree::G4UIcommandTree(const char* t 42 G4UIcommandTree::G4UIcommandTree(const char* thePathName) 44 { 43 { 45 pathName = thePathName; 44 pathName = thePathName; 46 } 45 } 47 46 48 // ------------------------------------------- 47 // -------------------------------------------------------------------- 49 G4UIcommandTree::~G4UIcommandTree() 48 G4UIcommandTree::~G4UIcommandTree() 50 { 49 { 51 for (auto& i : tree) { << 50 G4int i; 52 delete i; << 51 G4int n_treeEntry = tree.size(); >> 52 for(i = 0; i < n_treeEntry; ++i) >> 53 { >> 54 delete tree[i]; 53 } 55 } 54 } 56 } 55 57 56 // ------------------------------------------- 58 // -------------------------------------------------------------------- 57 G4bool G4UIcommandTree::operator==(const G4UIc 59 G4bool G4UIcommandTree::operator==(const G4UIcommandTree& right) const 58 { 60 { 59 return (pathName == right.GetPathName()); 61 return (pathName == right.GetPathName()); 60 } 62 } 61 63 62 // ------------------------------------------- 64 // -------------------------------------------------------------------- 63 G4bool G4UIcommandTree::operator!=(const G4UIc 65 G4bool G4UIcommandTree::operator!=(const G4UIcommandTree& right) const 64 { 66 { 65 return (pathName != right.GetPathName()); 67 return (pathName != right.GetPathName()); 66 } 68 } 67 69 68 // ------------------------------------------- 70 // -------------------------------------------------------------------- 69 void G4UIcommandTree::AddNewCommand(G4UIcomman << 71 void G4UIcommandTree::AddNewCommand(G4UIcommand* newCommand, >> 72 G4bool workerThreadOnly) 70 { 73 { 71 G4String commandPath = newCommand->GetComman << 74 G4String commandPath = newCommand->GetCommandPath(); 72 G4String remainingPath = commandPath; 75 G4String remainingPath = commandPath; 73 remainingPath.erase(0, pathName.length()); << 76 remainingPath.remove(0, pathName.length()); 74 if (remainingPath.empty()) { << 77 if(remainingPath.isNull()) 75 if (guidance == nullptr) { << 78 { >> 79 if(!guidance) >> 80 { 76 guidance = newCommand; 81 guidance = newCommand; 77 if (!(newCommand->ToBeBroadcasted())) { << 82 if(!(newCommand->ToBeBroadcasted())) 78 broadcastCommands = false; 83 broadcastCommands = false; 79 } << 84 if(workerThreadOnly) 80 if (workerThreadOnly) { << 81 newCommand->SetWorkerThreadOnly(); 85 newCommand->SetWorkerThreadOnly(); 82 } << 83 } 86 } 84 return; 87 return; 85 } 88 } 86 << 89 G4int i = remainingPath.first('/'); 87 if (guidance != nullptr) { << 90 if(i == G4int(std::string::npos)) 88 auto* dir = static_cast<G4UIdirectory*>(gu << 91 { 89 ifSort = dir->IfSort(); << 92 // Find command 90 } << 93 G4int n_commandEntry = command.size(); 91 std::size_t i = remainingPath.find('/'); << 94 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) 92 if (i == std::string::npos) { << 95 { 93 // Adding a new command to this directory << 96 if(remainingPath == command[i_thCommand]->GetCommandName()) 94 std::size_t n_commandEntry = command.size( << 97 { 95 for (std::size_t i_thCommand = 0; i_thComm << 96 if (remainingPath == command[i_thCommand << 97 // a command of same name has already << 98 if (G4UImanager::GetUIpointer()->GetVe << 99 G4ExceptionDescription ed; << 100 ed << "Command <" << commandPath << << 101 G4Exception("G4UIcommandTree::AddNew << 102 // FatalException, << 103 JustWarning, ed); << 104 } << 105 return; 98 return; 106 } 99 } 107 } 100 } 108 if (!broadcastCommands) { << 101 if(!broadcastCommands) 109 newCommand->SetToBeBroadcasted(false); 102 newCommand->SetToBeBroadcasted(false); 110 } << 103 if(workerThreadOnly) 111 if (workerThreadOnly) { << 112 newCommand->SetWorkerThreadOnly(); 104 newCommand->SetWorkerThreadOnly(); 113 } << 105 command.push_back(newCommand); 114 if (ifSort) { << 115 auto j = command.cbegin(); << 116 for (; j != command.cend(); ++j) { << 117 if (newCommand->GetCommandPath() < (*j << 118 break; << 119 } << 120 } << 121 command.insert(j, newCommand); << 122 } << 123 else { << 124 command.push_back(newCommand); << 125 } << 126 return; 106 return; 127 } 107 } 128 << 108 else 129 // Adding a new command to a sub-directory << 109 { 130 G4String nextPath = pathName; << 110 // Find path 131 nextPath.append(remainingPath.substr(0, i + << 111 G4String nextPath = pathName; 132 std::size_t n_treeEntry = tree.size(); << 112 nextPath.append(remainingPath(0, i + 1)); 133 for (std::size_t i_thTree = 0; i_thTree < n_ << 113 G4int n_treeEntry = tree.size(); 134 if (nextPath == tree[i_thTree]->GetPathNam << 114 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) 135 if (!broadcastCommands) { << 115 { 136 newCommand->SetToBeBroadcasted(false); << 116 if(nextPath == tree[i_thTree]->GetPathName()) 137 } << 117 { 138 tree[i_thTree]->AddNewCommand(newCommand << 118 if(!broadcastCommands) 139 return; << 119 newCommand->SetToBeBroadcasted(false); 140 } << 120 tree[i_thTree]->AddNewCommand(newCommand, workerThreadOnly); 141 } << 121 return; 142 // Creating a new sub-directory << 143 auto* newTree = new G4UIcommandTree(nextPath << 144 if (ifSort) { << 145 auto j = tree.cbegin(); << 146 for (; j != tree.cend(); ++j) { << 147 if (newTree->GetPathName() < (*j)->GetPa << 148 break; << 149 } 122 } 150 } 123 } 151 tree.insert(j, newTree); << 124 G4UIcommandTree* newTree = new G4UIcommandTree(nextPath); 152 } << 153 else { << 154 tree.push_back(newTree); 125 tree.push_back(newTree); >> 126 if(!broadcastCommands) >> 127 newCommand->SetToBeBroadcasted(false); >> 128 newTree->AddNewCommand(newCommand, workerThreadOnly); >> 129 return; 155 } 130 } 156 if (!broadcastCommands) { << 157 newCommand->SetToBeBroadcasted(false); << 158 } << 159 // In case a new sub-directry is created wit << 160 // (most-likely this is the case), inherit t << 161 newCommand->SetDefaultSortFlag(ifSort); << 162 newTree->AddNewCommand(newCommand, workerThr << 163 return; << 164 } 131 } 165 132 166 // ------------------------------------------- 133 // -------------------------------------------------------------------- 167 void G4UIcommandTree::RemoveCommand(G4UIcomman << 134 void G4UIcommandTree::RemoveCommand(G4UIcommand* aCommand, >> 135 G4bool workerThreadOnly) 168 { 136 { 169 if (workerThreadOnly && !(aCommand->IsWorker << 137 if(workerThreadOnly && !(aCommand->IsWorkerThreadOnly())) 170 return; 138 return; 171 } << 139 G4String commandPath = aCommand->GetCommandPath(); 172 G4String commandPath = aCommand->GetCommandP << 140 G4String remainingPath = commandPath; 173 commandPath.erase(0, pathName.length()); << 141 remainingPath.remove(0, pathName.length()); 174 if (commandPath.empty()) { << 142 if(remainingPath.isNull()) >> 143 { 175 guidance = nullptr; 144 guidance = nullptr; 176 } 145 } 177 else { << 146 else 178 std::size_t i = commandPath.find('/'); << 147 { 179 if (i == std::string::npos) { << 148 G4int i = remainingPath.first('/'); >> 149 if(i == G4int(std::string::npos)) >> 150 { 180 // Find command 151 // Find command 181 std::size_t n_commandEntry = command.siz << 152 G4int n_commandEntry = command.size(); 182 for (std::size_t i_thCommand = 0; i_thCo << 153 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) 183 if (commandPath == command[i_thCommand << 154 { >> 155 if(remainingPath == command[i_thCommand]->GetCommandName()) >> 156 { 184 command.erase(command.begin() + i_th 157 command.erase(command.begin() + i_thCommand); 185 break; 158 break; 186 } 159 } 187 } 160 } 188 } 161 } 189 else { << 162 else >> 163 { 190 // Find path 164 // Find path 191 G4String nextPath = pathName; 165 G4String nextPath = pathName; 192 nextPath.append(commandPath.substr(0, i << 166 nextPath.append(remainingPath(0, i + 1)); 193 std::size_t n_treeEntry = tree.size(); << 167 G4int n_treeEntry = tree.size(); 194 for (std::size_t i_thTree = 0; i_thTree << 168 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) 195 if (nextPath == tree[i_thTree]->GetPat << 169 { >> 170 if(nextPath == tree[i_thTree]->GetPathName()) >> 171 { 196 tree[i_thTree]->RemoveCommand(aComma 172 tree[i_thTree]->RemoveCommand(aCommand); 197 G4int n_commandRemain = tree[i_thTre 173 G4int n_commandRemain = tree[i_thTree]->GetCommandEntry(); 198 G4int n_treeRemain = tree[i_thTree]- << 174 G4int n_treeRemain = tree[i_thTree]->GetTreeEntry(); 199 if (n_commandRemain == 0 && n_treeRe << 175 if(n_commandRemain == 0 && n_treeRemain == 0) >> 176 { 200 G4UIcommandTree* emptyTree = tree[ 177 G4UIcommandTree* emptyTree = tree[i_thTree]; 201 tree.erase(tree.begin() + i_thTree 178 tree.erase(tree.begin() + i_thTree); 202 delete emptyTree; 179 delete emptyTree; 203 } 180 } 204 break; 181 break; 205 } 182 } 206 } 183 } 207 } 184 } 208 } 185 } 209 } 186 } 210 187 211 // ------------------------------------------- 188 // -------------------------------------------------------------------- 212 G4UIcommand* G4UIcommandTree::FindPath(const c 189 G4UIcommand* G4UIcommandTree::FindPath(const char* commandPath) const 213 { 190 { 214 // This function tries to match a command na 191 // This function tries to match a command name 215 192 216 G4String remainingPath = commandPath; 193 G4String remainingPath = commandPath; 217 if (remainingPath.find(pathName) == std::str << 194 if(remainingPath.index(pathName) == std::string::npos) >> 195 { 218 return nullptr; 196 return nullptr; 219 } 197 } 220 remainingPath.erase(0, pathName.length()); << 198 remainingPath.remove(0, pathName.length()); 221 std::size_t i = remainingPath.find('/'); << 199 G4int i = remainingPath.first('/'); 222 if (i == std::string::npos) { << 200 if(i == G4int(std::string::npos)) >> 201 { 223 // Find command 202 // Find command 224 std::size_t n_commandEntry = command.size( << 203 G4int n_commandEntry = command.size(); 225 for (std::size_t i_thCommand = 0; i_thComm << 204 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) 226 if (remainingPath == command[i_thCommand << 205 { >> 206 if(remainingPath == command[i_thCommand]->GetCommandName()) >> 207 { 227 return command[i_thCommand]; 208 return command[i_thCommand]; 228 } 209 } 229 } 210 } 230 } 211 } 231 else { << 212 else >> 213 { 232 // Find path 214 // Find path 233 G4String nextPath = pathName; 215 G4String nextPath = pathName; 234 nextPath.append(remainingPath.substr(0, i << 216 nextPath.append(remainingPath(0, i + 1)); 235 std::size_t n_treeEntry = tree.size(); << 217 G4int n_treeEntry = tree.size(); 236 for (std::size_t i_thTree = 0; i_thTree < << 218 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) 237 if (nextPath == tree[i_thTree]->GetPathN << 219 { >> 220 if(nextPath == tree[i_thTree]->GetPathName()) >> 221 { 238 return tree[i_thTree]->FindPath(comman 222 return tree[i_thTree]->FindPath(commandPath); 239 } 223 } 240 } 224 } 241 } 225 } 242 return nullptr; 226 return nullptr; 243 } 227 } 244 228 245 // ------------------------------------------- 229 // -------------------------------------------------------------------- 246 G4UIcommandTree* G4UIcommandTree::FindCommandT 230 G4UIcommandTree* G4UIcommandTree::FindCommandTree(const char* commandPath) 247 { 231 { 248 // Try to match a command or a path with the 232 // Try to match a command or a path with the one given. 249 // @commandPath : command or path to match 233 // @commandPath : command or path to match 250 // @return the commandTree found or nullptr 234 // @return the commandTree found or nullptr if not 251 235 252 G4String remainingPath = commandPath; 236 G4String remainingPath = commandPath; 253 if (remainingPath.find(pathName) == std::str << 237 if(remainingPath.index(pathName) == std::string::npos) >> 238 { 254 return nullptr; 239 return nullptr; 255 } 240 } 256 remainingPath.erase(0, pathName.length()); << 241 remainingPath.remove(0, pathName.length()); 257 std::size_t i = remainingPath.find('/'); << 242 G4int i = remainingPath.first('/'); 258 if (i != std::string::npos) { << 243 if(i != G4int(std::string::npos)) >> 244 { 259 // Find path 245 // Find path 260 G4String nextPath = pathName; 246 G4String nextPath = pathName; 261 nextPath.append(remainingPath.substr(0, i << 247 nextPath.append(remainingPath(0, i + 1)); 262 std::size_t n_treeEntry = tree.size(); << 248 G4int n_treeEntry = tree.size(); 263 for (std::size_t i_thTree = 0; i_thTree < << 249 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) 264 if (tree[i_thTree]->GetPathName() == com << 250 { >> 251 if(tree[i_thTree]->GetPathName() == commandPath) >> 252 { 265 return tree[i_thTree]; 253 return tree[i_thTree]; 266 } 254 } 267 if (nextPath == tree[i_thTree]->GetPathN << 255 else if(nextPath == tree[i_thTree]->GetPathName()) >> 256 { 268 return tree[i_thTree]->FindCommandTree 257 return tree[i_thTree]->FindCommandTree(commandPath); 269 } 258 } 270 } 259 } 271 } 260 } 272 else { << 261 else >> 262 { 273 return this; 263 return this; 274 } 264 } 275 return nullptr; 265 return nullptr; 276 } 266 } 277 267 278 // ------------------------------------------- 268 // -------------------------------------------------------------------- 279 G4String G4UIcommandTree::CompleteCommandPath( 269 G4String G4UIcommandTree::CompleteCommandPath(const G4String& aCommandPath) 280 { 270 { 281 G4String pName = aCommandPath; << 271 G4String pName = aCommandPath; 282 G4String remainingPath = aCommandPath; 272 G4String remainingPath = aCommandPath; 283 G4String empty = ""; << 273 G4String empty = ""; 284 G4String matchingPath = empty; << 274 G4String matchingPath = empty; 285 275 286 // find the tree 276 // find the tree 287 auto jpre = pName.rfind('/'); << 277 G4int jpre = pName.last('/'); 288 if (jpre != G4String::npos) { << 278 if(jpre != G4int(G4String::npos)) 289 pName.erase(jpre + 1); << 279 pName.remove(jpre + 1); 290 } << 291 G4UIcommandTree* aTree = FindCommandTree(pNa 280 G4UIcommandTree* aTree = FindCommandTree(pName); 292 281 293 if (aTree == nullptr) { << 282 if(!aTree) >> 283 { 294 return empty; 284 return empty; 295 } 285 } 296 286 297 if (pName.find(pName) == std::string::npos) << 287 if(pName.index(pName) == std::string::npos) 298 return empty; 288 return empty; 299 } << 300 289 301 std::vector<G4String> paths; 290 std::vector<G4String> paths; 302 291 303 // list matched directories/commands 292 // list matched directories/commands 304 G4String strtmp; 293 G4String strtmp; 305 G4int nMatch = 0; 294 G4int nMatch = 0; 306 295 307 G4int Ndir = aTree->GetTreeEntry(); 296 G4int Ndir = aTree->GetTreeEntry(); 308 G4int Ncmd = aTree->GetCommandEntry(); 297 G4int Ncmd = aTree->GetCommandEntry(); 309 298 310 // directory ... 299 // directory ... 311 for (G4int idir = 1; idir <= Ndir; ++idir) { << 300 for(G4int idir = 1; idir <= Ndir; ++idir) 312 const G4String& fpdir = aTree->GetTree(idi << 301 { >> 302 G4String fpdir = aTree->GetTree(idir)->GetPathName(); 313 // matching test 303 // matching test 314 if (fpdir.find(remainingPath, 0) == 0) { << 304 if(fpdir.index(remainingPath, 0) == 0) 315 if (nMatch == 0) { << 305 { >> 306 if(nMatch == 0) >> 307 { 316 matchingPath = fpdir; 308 matchingPath = fpdir; 317 } 309 } 318 else { << 310 else >> 311 { 319 matchingPath = GetFirstMatchedString(f 312 matchingPath = GetFirstMatchedString(fpdir, matchingPath); 320 } 313 } 321 ++nMatch; 314 ++nMatch; 322 paths.push_back(fpdir); 315 paths.push_back(fpdir); 323 } 316 } 324 } 317 } 325 318 326 if (paths.size() >= 2) { << 319 if(paths.size() >= 2) >> 320 { 327 G4cout << "Matching directories :" << G4en 321 G4cout << "Matching directories :" << G4endl; 328 for (const auto& path : paths) { << 322 for(unsigned int i_thCommand = 0; i_thCommand < paths.size(); ++i_thCommand) 329 G4cout << path << G4endl; << 323 { >> 324 G4cout << paths[i_thCommand] << G4endl; 330 } 325 } 331 } 326 } 332 327 333 // command ... 328 // command ... 334 std::vector<G4String> commands; 329 std::vector<G4String> commands; 335 330 336 for (G4int icmd = 1; icmd <= Ncmd; ++icmd) { << 331 for(G4int icmd = 1; icmd <= Ncmd; ++icmd) 337 G4String fpcmd = aTree->GetPathName() + aT << 332 { >> 333 G4String fpcmd = >> 334 aTree->GetPathName() + aTree->GetCommand(icmd)->GetCommandName(); 338 // matching test 335 // matching test 339 if (fpcmd.find(remainingPath, 0) == 0) { << 336 if(fpcmd.index(remainingPath, 0) == 0) 340 if (nMatch == 0) { << 337 { >> 338 if(nMatch == 0) >> 339 { 341 matchingPath = fpcmd + " "; 340 matchingPath = fpcmd + " "; 342 } 341 } 343 else { << 342 else 344 strtmp = fpcmd + " "; << 343 { >> 344 strtmp = fpcmd + " "; 345 matchingPath = GetFirstMatchedString(m 345 matchingPath = GetFirstMatchedString(matchingPath, strtmp); 346 } 346 } 347 nMatch++; 347 nMatch++; 348 commands.emplace_back(fpcmd + " "); << 348 commands.push_back(fpcmd + " "); 349 } 349 } 350 } 350 } 351 351 352 if (commands.size() >= 2) { << 352 if(commands.size() >= 2) >> 353 { 353 G4cout << "Matching commands :" << G4endl; 354 G4cout << "Matching commands :" << G4endl; 354 for (const auto& matched : commands) { << 355 for(unsigned int i_thCommand = 0; i_thCommand < commands.size(); 355 G4cout << matched << G4endl; << 356 ++i_thCommand) >> 357 { >> 358 G4cout << commands[i_thCommand] << G4endl; 356 } 359 } 357 } 360 } 358 361 359 return matchingPath; 362 return matchingPath; 360 } 363 } 361 364 362 // ------------------------------------------- 365 // -------------------------------------------------------------------- 363 G4String G4UIcommandTree::GetFirstMatchedStrin << 366 G4String G4UIcommandTree::GetFirstMatchedString(const G4String& str1, >> 367 const G4String& str2) const 364 { 368 { 365 std::size_t nlen1 = str1.length(); << 369 G4int nlen1 = str1.length(); 366 std::size_t nlen2 = str2.length(); << 370 G4int nlen2 = str2.length(); 367 371 368 std::size_t nmin = nlen1 < nlen2 ? nlen1 : n << 372 G4int nmin = nlen1 < nlen2 ? nlen1 : nlen2; 369 373 370 G4String strMatched; 374 G4String strMatched; 371 for (G4int i = 0; i < (G4int)nmin; ++i) { << 375 for(size_t i = 0; G4int(i) < nmin; ++i) 372 if (str1[i] == str2[i]) { << 376 { >> 377 if(str1[i] == str2[i]) >> 378 { 373 strMatched += str1[i]; 379 strMatched += str1[i]; 374 } 380 } 375 else { << 381 else >> 382 { 376 break; 383 break; 377 } 384 } 378 } 385 } 379 386 380 return strMatched; 387 return strMatched; 381 } 388 } 382 389 383 // ------------------------------------------- 390 // -------------------------------------------------------------------- 384 void G4UIcommandTree::ListCurrent() const 391 void G4UIcommandTree::ListCurrent() const 385 { 392 { 386 G4cout << "Command directory path : " << pat 393 G4cout << "Command directory path : " << pathName << G4endl; 387 if (guidance != nullptr) { << 394 if(guidance != nullptr) 388 guidance->List(); 395 guidance->List(); 389 } << 390 G4cout << " Sub-directories : " << G4endl; 396 G4cout << " Sub-directories : " << G4endl; 391 std::size_t n_treeEntry = tree.size(); << 397 G4int n_treeEntry = tree.size(); 392 for (std::size_t i_thTree = 0; i_thTree < n_ << 398 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) >> 399 { 393 G4cout << " " << tree[i_thTree]->GetPath 400 G4cout << " " << tree[i_thTree]->GetPathName(); 394 if ((tree[i_thTree]->GetGuidance() != null << 401 if(tree[i_thTree]->GetGuidance() && 395 && tree[i_thTree]->GetGuidance()->IsWo << 402 tree[i_thTree]->GetGuidance()->IsWorkerThreadOnly()) 396 { 403 { 397 G4cout << " @ "; 404 G4cout << " @ "; 398 } 405 } 399 else { << 406 else >> 407 { 400 G4cout << " "; 408 G4cout << " "; 401 } 409 } 402 G4cout << tree[i_thTree]->GetTitle() << G4 410 G4cout << tree[i_thTree]->GetTitle() << G4endl; 403 } 411 } 404 G4cout << " Commands : " << G4endl; 412 G4cout << " Commands : " << G4endl; 405 std::size_t n_commandEntry = command.size(); << 413 G4int n_commandEntry = command.size(); 406 for (std::size_t i_thCommand = 0; i_thComman << 414 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) >> 415 { 407 G4cout << " " << command[i_thCommand]->G 416 G4cout << " " << command[i_thCommand]->GetCommandName(); 408 if (command[i_thCommand]->IsWorkerThreadOn << 417 if(command[i_thCommand]->IsWorkerThreadOnly()) >> 418 { 409 G4cout << " @ "; 419 G4cout << " @ "; 410 } 420 } 411 else { << 421 else >> 422 { 412 G4cout << " * "; 423 G4cout << " * "; 413 } 424 } 414 G4cout << command[i_thCommand]->GetTitle() 425 G4cout << command[i_thCommand]->GetTitle() << G4endl; 415 } 426 } 416 } 427 } 417 428 418 // ------------------------------------------- 429 // -------------------------------------------------------------------- 419 void G4UIcommandTree::ListCurrentWithNum() con 430 void G4UIcommandTree::ListCurrentWithNum() const 420 { 431 { 421 G4cout << "Command directory path : " << pat 432 G4cout << "Command directory path : " << pathName << G4endl; 422 if (guidance != nullptr) { << 433 if(guidance != nullptr) 423 guidance->List(); 434 guidance->List(); 424 } << 425 G4int i = 0; 435 G4int i = 0; 426 G4cout << " Sub-directories : " << G4endl; 436 G4cout << " Sub-directories : " << G4endl; 427 std::size_t n_treeEntry = tree.size(); << 437 G4int n_treeEntry = tree.size(); 428 for (std::size_t i_thTree = 0; i_thTree < n_ << 438 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) >> 439 { 429 ++i; 440 ++i; 430 G4cout << " " << i << ") " << tree[i_thTre 441 G4cout << " " << i << ") " << tree[i_thTree]->GetPathName() << " " 431 << tree[i_thTree]->GetTitle() << G4 442 << tree[i_thTree]->GetTitle() << G4endl; 432 } 443 } 433 G4cout << " Commands : " << G4endl; 444 G4cout << " Commands : " << G4endl; 434 std::size_t n_commandEntry = command.size(); << 445 G4int n_commandEntry = command.size(); 435 for (std::size_t i_thCommand = 0; i_thComman << 446 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) >> 447 { 436 ++i; 448 ++i; 437 G4cout << " " << i << ") " << command[i_th << 449 G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName() 438 << command[i_thCommand]->GetTitle() << 450 << " * " << command[i_thCommand]->GetTitle() << G4endl; 439 } 451 } 440 } 452 } 441 453 442 // ------------------------------------------- 454 // -------------------------------------------------------------------- 443 void G4UIcommandTree::List() const 455 void G4UIcommandTree::List() const 444 { 456 { 445 ListCurrent(); 457 ListCurrent(); 446 std::size_t n_commandEntry = command.size(); << 458 G4int n_commandEntry = command.size(); 447 for (std::size_t i_thCommand = 0; i_thComman << 459 for(G4int i_thCommand = 0; i_thCommand < n_commandEntry; ++i_thCommand) >> 460 { 448 command[i_thCommand]->List(); 461 command[i_thCommand]->List(); 449 } 462 } 450 std::size_t n_treeEntry = tree.size(); << 463 G4int n_treeEntry = tree.size(); 451 for (std::size_t i_thTree = 0; i_thTree < n_ << 464 for(G4int i_thTree = 0; i_thTree < n_treeEntry; ++i_thTree) >> 465 { 452 tree[i_thTree]->List(); 466 tree[i_thTree]->List(); 453 } 467 } 454 } 468 } 455 469 456 // ------------------------------------------- 470 // -------------------------------------------------------------------- 457 G4String G4UIcommandTree::CreateFileName(const 471 G4String G4UIcommandTree::CreateFileName(const char* pName) 458 { 472 { 459 G4String fn = pName; 473 G4String fn = pName; 460 std::size_t idxs; << 474 G4int idxs; 461 while ((idxs = fn.find('/')) != std::string: << 475 while((idxs = fn.index("/")) != G4int(std::string::npos)) 462 fn[(G4int)idxs] = '_'; << 476 { >> 477 fn(idxs) = '_'; 463 } 478 } 464 fn += ".html"; 479 fn += ".html"; 465 return fn; 480 return fn; 466 } 481 } 467 482 468 // ------------------------------------------- 483 // -------------------------------------------------------------------- 469 G4String G4UIcommandTree::ModStr(const char* s 484 G4String G4UIcommandTree::ModStr(const char* strS) 470 { 485 { 471 G4String sx; 486 G4String sx; 472 G4String str = strS; 487 G4String str = strS; 473 for (G4int i = 0; i < G4int(str.length()); + << 488 for(G4int i = 0; i < G4int(str.length()); ++i) 474 char c = str[i]; << 489 { 475 switch (c) { << 490 char c = str(i); >> 491 switch(c) >> 492 { 476 case '<': 493 case '<': 477 sx += "<"; 494 sx += "<"; 478 break; 495 break; 479 case '>': 496 case '>': 480 sx += ">"; 497 sx += ">"; 481 break; 498 break; 482 case '&': 499 case '&': 483 sx += "&"; 500 sx += "&"; 484 break; 501 break; 485 default: 502 default: 486 sx += c; 503 sx += c; 487 } 504 } 488 } 505 } 489 return sx; 506 return sx; 490 } 507 } 491 508 492 // ------------------------------------------- 509 // -------------------------------------------------------------------- 493 void G4UIcommandTree::CreateHTML(const G4Strin << 510 void G4UIcommandTree::CreateHTML() 494 { 511 { 495 G4String ofileName = CreateFileName(pathName 512 G4String ofileName = CreateFileName(pathName); 496 std::ofstream oF(ofileName, std::ios::out); 513 std::ofstream oF(ofileName, std::ios::out); 497 514 498 oF << "<html><head><title>Commands in " << M << 515 oF << "<html><head><title>Commands in " << ModStr(pathName) 499 oF << "<style> \ << 516 << "</title></head>" << G4endl; 500 table,table td,table th { \ << 517 oF << "<body bgcolor=\"#ffffff\"><h2>" << ModStr(pathName) << "</h2><p>" 501 border:1px solid #eee \ << 502 } \ << 503 table td,table th { \ << 504 padding:5px 20px; \ << 505 line-height:1.3; \ << 506 text-align:inherit \ << 507 } \ << 508 a { \ << 509 color:#17a81a; \ << 510 text-decoration:none; \ << 511 transition-duration:0.3s \ << 512 } \ << 513 a:hover { \ << 514 color:#17a81a \ << 515 } \ << 516 table { \ << 517 border-collapse:collapse; \ << 518 border-spacing:0; \ << 519 margin-bottom:5px; \ << 520 } \ << 521 h1 { \ << 522 font-size:2.25em; \ << 523 font-weight:300; \ << 524 letter-spacing:-1px; \ << 525 line-height:1.15em; \ << 526 margin-bottom:0.5em; \ << 527 word-wrap:break-word \ << 528 } \ << 529 h2 { \ << 530 font-size:1.5em; \ << 531 font-weight:300; \ << 532 letter-spacing:-1px; \ << 533 line-height:1.15em; \ << 534 margin-bottom:0.5em; \ << 535 word-wrap:break-word \ << 536 } \ << 537 h3 { \ << 538 color:#26282a; \ << 539 font-weight:300; \ << 540 font-size:1.3em; \ << 541 padding:15px 0 15px 0; \ << 542 border-bottom:2px #eee solid; \ << 543 word-wrap:break-word \ << 544 } \ << 545 .sidebar { \ << 546 display:block; \ << 547 position:relative; \ << 548 position:sticky; \ << 549 float:left; \ << 550 -webkit-box-sizing:border-box; \ << 551 -moz-box-sizing:border-box; \ << 552 -ms-box-sizing:border-box; \ << 553 box-sizing:border-box; \ << 554 width:20%; \ << 555 padding-right:20px \ << 556 } \ << 557 .context { \ << 558 width:80%; \ << 559 display:inline-block; \ << 560 background-color:#fff; \ << 561 padding: 25px 35px 20px 30px; \ << 562 -webkit-box-sizing:border-box; \ << 563 -moz-box-sizing:border-box; \ << 564 -ms-box-sizing:border-box; \ << 565 box-sizing:border-box \ << 566 } \ << 567 </style>" << 568 << G4endl; 518 << G4endl; 569 oF << "<body bgcolor=\"#ffffff\">" << G4endl << 570 519 571 // Left Panel << 520 if(guidance != nullptr) 572 if (createHTMLTreeLevel == 0) { << 521 { 573 oF << "<div class=\"sidebar\">" << sideBar << 522 for(std::size_t i = 0; i < guidance->GetGuidanceEntries(); ++i) 574 } << 523 { 575 // Right Panel << 576 oF << "<div class=\"context\">"; << 577 oF << "<h1>" << ModStr(pathName) << "</h1>" << 578 << 579 if (guidance != nullptr) { << 580 for (G4int i = 0; i < (G4int)guidance->Get << 581 oF << ModStr(guidance->GetGuidanceLine(i 524 oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl; 582 } 525 } 583 } 526 } 584 if (!tree.empty()) { << 527 585 G4String menu = ""; << 528 oF << "<p><hr><p>" << G4endl; 586 G4String newSideBar = ""; << 529 587 menu += "<h2>Sub-directories </h2><table>" << 530 oF << "<h2>Sub-directories : </h2><dl>" << G4endl; 588 newSideBar += "<h2><a href=\"" + ofileName << 531 for(std::size_t i_thTree = 0; i_thTree < tree.size(); ++i_thTree) 589 // Build menu short version << 532 { 590 for (auto& i_thTree : tree) { << 533 oF << "<p><br><p><dt><a href=\"" 591 newSideBar += "<tr><td><a href=\"" + Cre << 534 << CreateFileName(tree[i_thTree]->GetPathName()) << "\">" 592 + ModStr(i_thTree->GetPath << 535 << ModStr(tree[i_thTree]->GetPathName()) << "</a>" << G4endl; 593 } << 536 oF << "<p><dd>" << ModStr(tree[i_thTree]->GetTitle()) << G4endl; 594 // Build menu << 537 tree[i_thTree]->CreateHTML(); 595 for (auto& i_thTree : tree) { << 538 } 596 menu += "<tr><td><a href=\"" + CreateFil << 539 597 + ModStr(i_thTree->GetPathName() << 540 oF << "</dl><p><hr><p>" << G4endl; 598 menu += "</td><td>" + ModStr(i_thTree->G << 541 599 } << 542 oF << "<h2>Commands : </h2><dl>" << G4endl; 600 menu += "</table>"; << 543 for(std::size_t i_thCommand = 0; i_thCommand < command.size(); ++i_thCommand) 601 newSideBar += "</table>"; << 544 { 602 for (auto& i_thTree : tree) { << 545 G4UIcommand* cmd = command[i_thCommand]; 603 createHTMLTreeLevel++; << 546 oF << "<p><br><p><dt><b>" << ModStr(cmd->GetCommandName()); 604 i_thTree->CreateHTML(newSideBar); << 547 if(cmd->GetParameterEntries() > 0) 605 createHTMLTreeLevel--; << 548 { 606 } << 549 for(std::size_t i_thParam = 0; i_thParam < cmd->GetParameterEntries(); 607 oF << menu << G4endl; << 550 ++i_thParam) 608 } << 551 { 609 << 552 oF << " [<i>" 610 if (!command.empty()) { << 553 << ModStr(cmd->GetParameter(i_thParam)->GetParameterName()) 611 oF << "<h2>Commands </h2>" << G4endl; << 554 << "</i>]"; 612 << 613 // resume << 614 oF << "<table>" << G4endl; << 615 for (std::size_t i_thCommand = 0; i_thComm << 616 G4UIcommand* cmd = command[i_thCommand]; << 617 oF << "<tr><td><a href=\"#c" << i_thComm << 618 oF << "</a></td></tr>" << G4endl; << 619 } << 620 oF << "</table>" << G4endl; << 621 for (std::size_t i_thCommand = 0; i_thComm << 622 G4UIcommand* cmd = command[i_thCommand]; << 623 oF << "<h3 id=\"c" << i_thCommand << "\" << 624 if (cmd->GetParameterEntries() > 0) { << 625 for (G4int i_thParam = 0; i_thParam < << 626 oF << " [<i>" << ModStr(cmd->GetPara << 627 } << 628 } 555 } 629 oF << "</h3>" << G4endl; << 556 } 630 oF << "<p>" << G4endl; << 557 oF << "</b>" << G4endl; 631 for (G4int i = 0; i < (G4int)cmd->GetGui << 558 oF << "<p><dd>" << G4endl; 632 oF << ModStr(cmd->GetGuidanceLine(i)) << 559 for(std::size_t i = 0; i < cmd->GetGuidanceEntries(); ++i) 633 } << 560 { 634 if (!(cmd->GetRange()).empty()) { << 561 oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl; 635 oF << "<p>Range : " << ModStr(cmd->Get << 562 } 636 } << 563 if(!(cmd->GetRange()).isNull()) 637 std::vector<G4ApplicationState>* availab << 564 { 638 if (availabelStateList->size() == 6) { << 565 oF << "<p><dd>Range : " << ModStr(cmd->GetRange()) << G4endl; 639 oF << "<p>Available at all Geant4 stat << 566 } 640 } << 567 std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList(); 641 else { << 568 if(availabelStateList->size() == 6) 642 oF << "<p>Available Geant4 state(s) : << 569 { 643 for (auto& ias : *availabelStateList) << 570 oF << "<p><dd>Available at all Geant4 states." << G4endl; 644 oF << G4StateManager::GetStateManage << 571 } 645 } << 572 else >> 573 { >> 574 oF << "<p><dd>Available Geant4 state(s) : "; >> 575 for(std::size_t ias = 0; ias < availabelStateList->size(); ++ias) >> 576 { >> 577 oF << G4StateManager::GetStateManager()->GetStateString( >> 578 (*availabelStateList)[ias]) >> 579 << " " << G4endl; 646 } 580 } 647 if (cmd->GetParameterEntries() > 0) { << 581 } 648 oF << "<p>Parameters<table border=1>" << 582 if(cmd->GetParameterEntries() > 0) 649 for (G4int i_thParam = 0; i_thParam < << 583 { 650 G4UIparameter* prm = cmd->GetParamet << 584 oF << "<p><dd>Parameters<table border=1>" << G4endl; 651 oF << "<tr><td>" << ModStr(prm->GetP << 585 for(std::size_t i_thParam = 0; i_thParam < cmd->GetParameterEntries(); 652 oF << "<td>type " << prm->GetParamet << 586 ++i_thParam) 653 oF << "<td>"; << 587 { 654 if (prm->IsOmittable()) { << 588 G4UIparameter* prm = cmd->GetParameter(i_thParam); 655 oF << "Omittable : "; << 589 oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl; 656 if (prm->GetCurrentAsDefault()) { << 590 oF << "<td>type " << prm->GetParameterType() << G4endl; 657 oF << "current value is used as << 591 oF << "<td>"; 658 } << 592 if(prm->IsOmittable()) 659 else { << 593 { 660 oF << "default value = " << prm- << 594 oF << "Omittable : "; 661 } << 595 if(prm->GetCurrentAsDefault()) 662 } << 596 { 663 oF << "<td>"; << 597 oF << "current value is used as the default value." << G4endl; 664 if (!(prm->GetParameterRange()).empt << 665 oF << "Parameter range : " << ModS << 666 } 598 } 667 else if (!(prm->GetParameterCandidat << 599 else 668 oF << "Parameter candidates : " << << 600 { >> 601 oF << "default value = " << prm->GetDefaultValue() << G4endl; 669 } 602 } 670 } 603 } 671 oF << "</table>" << G4endl; << 604 oF << "<td>"; >> 605 if(!(prm->GetParameterRange()).isNull()) >> 606 { >> 607 oF << "Parameter range : " << ModStr(prm->GetParameterRange()) >> 608 << G4endl; >> 609 } >> 610 else if(!(prm->GetParameterCandidates()).isNull()) >> 611 { >> 612 oF << "Parameter candidates : " >> 613 << ModStr(prm->GetParameterCandidates()) << G4endl; >> 614 } 672 } 615 } >> 616 oF << "</table>" << G4endl; 673 } 617 } 674 } 618 } 675 oF << "</div></body></html>" << G4endl; << 619 >> 620 oF << "</dl></body></html>" << G4endl; 676 oF.close(); 621 oF.close(); 677 } 622 } 678 623 679 // ------------------------------------------- 624 // -------------------------------------------------------------------- 680 G4UIcommandTree* G4UIcommandTree::GetTree(cons 625 G4UIcommandTree* G4UIcommandTree::GetTree(const char* comNameC) 681 { 626 { 682 G4String comName = comNameC; 627 G4String comName = comNameC; 683 for (auto& i : tree) { << 628 for(std::size_t i = 0; i < tree.size(); ++i) 684 if (comName == i->GetPathName()) { << 629 { 685 return i; << 630 if(comName == tree[i]->GetPathName()) >> 631 { >> 632 return tree[i]; 686 } 633 } 687 } 634 } 688 return nullptr; 635 return nullptr; 689 } 636 } 690 637