| [821] | 1 | //
|
|---|
| 2 | // ********************************************************************
|
|---|
| 3 | // * License and Disclaimer *
|
|---|
| 4 | // * *
|
|---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of *
|
|---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and *
|
|---|
| 7 | // * conditions of the Geant4 Software License, included in the file *
|
|---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These *
|
|---|
| 9 | // * include a list of copyright holders. *
|
|---|
| 10 | // * *
|
|---|
| 11 | // * Neither the authors of this software system, nor their employing *
|
|---|
| 12 | // * institutes,nor the agencies providing financial support for this *
|
|---|
| 13 | // * work make any representation or warranty, express or implied, *
|
|---|
| 14 | // * regarding this software system or assume any liability for its *
|
|---|
| 15 | // * use. Please see the license in the file LICENSE and URL above *
|
|---|
| 16 | // * for the full disclaimer and the limitation of liability. *
|
|---|
| 17 | // * *
|
|---|
| 18 | // * This code implementation is the result of the scientific and *
|
|---|
| 19 | // * technical work of the GEANT4 collaboration. *
|
|---|
| 20 | // * By using, copying, modifying or distributing the software (or *
|
|---|
| 21 | // * any work based on the software) you agree to acknowledge its *
|
|---|
| 22 | // * use in resulting scientific publications, and indicate your *
|
|---|
| 23 | // * acceptance of all terms of the Geant4 Software license. *
|
|---|
| 24 | // ********************************************************************
|
|---|
| 25 | //
|
|---|
| 26 | //
|
|---|
| 27 | // $Id: G4UIcommandTree.cc,v 1.13 2006/06/29 19:08:58 gunter Exp $
|
|---|
| 28 | // GEANT4 tag $Name: geant4-09-01-patch-02 $
|
|---|
| 29 | //
|
|---|
| 30 |
|
|---|
| 31 | #include "G4UIcommandTree.hh"
|
|---|
| 32 | #include "G4StateManager.hh"
|
|---|
| 33 | #include <fstream>
|
|---|
| 34 | #include "G4ios.hh"
|
|---|
| 35 |
|
|---|
| 36 | G4UIcommandTree::G4UIcommandTree()
|
|---|
| 37 | :guidance(NULL)
|
|---|
| 38 | { }
|
|---|
| 39 |
|
|---|
| 40 | G4UIcommandTree::G4UIcommandTree(const char * thePathName)
|
|---|
| 41 | :guidance(NULL)
|
|---|
| 42 | {
|
|---|
| 43 | pathName = thePathName;
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | G4UIcommandTree::~G4UIcommandTree()
|
|---|
| 47 | {
|
|---|
| 48 | G4int i;
|
|---|
| 49 | G4int n_treeEntry = tree.size();
|
|---|
| 50 | for( i=0; i < n_treeEntry; i++ )
|
|---|
| 51 | { delete tree[i]; }
|
|---|
| 52 | }
|
|---|
| 53 |
|
|---|
| 54 | G4int G4UIcommandTree::operator==(const G4UIcommandTree &right) const
|
|---|
| 55 | {
|
|---|
| 56 | return ( pathName == right.GetPathName() );
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | G4int G4UIcommandTree::operator!=(const G4UIcommandTree &right) const
|
|---|
| 60 | {
|
|---|
| 61 | return ( pathName != right.GetPathName() );
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | void G4UIcommandTree::AddNewCommand(G4UIcommand *newCommand)
|
|---|
| 65 | {
|
|---|
| 66 | G4String commandPath = newCommand->GetCommandPath();
|
|---|
| 67 | G4String remainingPath = commandPath;
|
|---|
| 68 | remainingPath.remove(0,pathName.length());
|
|---|
| 69 | if( remainingPath.isNull() )
|
|---|
| 70 | {
|
|---|
| 71 | guidance = newCommand;
|
|---|
| 72 | return;
|
|---|
| 73 | }
|
|---|
| 74 | G4int i = remainingPath.first('/');
|
|---|
| 75 | if( i == G4int(std::string::npos) )
|
|---|
| 76 | {
|
|---|
| 77 | // Find command
|
|---|
| 78 | G4int n_commandEntry = command.size();
|
|---|
| 79 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 80 | {
|
|---|
| 81 | if( remainingPath == command[i_thCommand]->GetCommandName() )
|
|---|
| 82 | { return; }
|
|---|
| 83 | }
|
|---|
| 84 | command.push_back( newCommand );
|
|---|
| 85 | return;
|
|---|
| 86 | }
|
|---|
| 87 | else
|
|---|
| 88 | {
|
|---|
| 89 | // Find path
|
|---|
| 90 | G4String nextPath = pathName;
|
|---|
| 91 | nextPath.append(remainingPath(0,i+1));
|
|---|
| 92 | G4int n_treeEntry = tree.size();
|
|---|
| 93 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 94 | {
|
|---|
| 95 | if( nextPath == tree[i_thTree]->GetPathName() )
|
|---|
| 96 | {
|
|---|
| 97 | tree[i_thTree]->AddNewCommand( newCommand );
|
|---|
| 98 | return;
|
|---|
| 99 | }
|
|---|
| 100 | }
|
|---|
| 101 | G4UIcommandTree * newTree = new G4UIcommandTree( nextPath );
|
|---|
| 102 | tree.push_back( newTree );
|
|---|
| 103 | newTree->AddNewCommand( newCommand );
|
|---|
| 104 | return;
|
|---|
| 105 | }
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | void G4UIcommandTree::RemoveCommand(G4UIcommand *aCommand)
|
|---|
| 109 | {
|
|---|
| 110 | G4String commandPath = aCommand->GetCommandPath();
|
|---|
| 111 | G4String remainingPath = commandPath;
|
|---|
| 112 | remainingPath.remove(0,pathName.length());
|
|---|
| 113 | if( remainingPath.isNull() )
|
|---|
| 114 | {
|
|---|
| 115 | guidance = NULL;
|
|---|
| 116 | }
|
|---|
| 117 | else
|
|---|
| 118 | {
|
|---|
| 119 | G4int i = remainingPath.first('/');
|
|---|
| 120 | if( i == G4int(std::string::npos) )
|
|---|
| 121 | {
|
|---|
| 122 | // Find command
|
|---|
| 123 | G4int n_commandEntry = command.size();
|
|---|
| 124 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 125 | {
|
|---|
| 126 | if( remainingPath == command[i_thCommand]->GetCommandName() )
|
|---|
| 127 | {
|
|---|
| 128 | command.erase(command.begin()+i_thCommand);
|
|---|
| 129 | break;
|
|---|
| 130 | }
|
|---|
| 131 | }
|
|---|
| 132 | }
|
|---|
| 133 | else
|
|---|
| 134 | {
|
|---|
| 135 | // Find path
|
|---|
| 136 | G4String nextPath = pathName;
|
|---|
| 137 | nextPath.append(remainingPath(0,i+1));
|
|---|
| 138 | G4int n_treeEntry = tree.size();
|
|---|
| 139 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 140 | {
|
|---|
| 141 | if( nextPath == tree[i_thTree]->GetPathName() )
|
|---|
| 142 | {
|
|---|
| 143 | tree[i_thTree]->RemoveCommand( aCommand );
|
|---|
| 144 | G4int n_commandRemain = tree[i_thTree]->GetCommandEntry();
|
|---|
| 145 | if(n_commandRemain==0)
|
|---|
| 146 | {
|
|---|
| 147 | G4UIcommandTree * emptyTree = tree[i_thTree];
|
|---|
| 148 | tree.erase(tree.begin()+i_thTree);
|
|---|
| 149 | delete emptyTree;
|
|---|
| 150 | }
|
|---|
| 151 | break;
|
|---|
| 152 | }
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | }
|
|---|
| 156 | }
|
|---|
| 157 |
|
|---|
| 158 | G4UIcommand * G4UIcommandTree::FindPath(const char* commandPath)
|
|---|
| 159 | {
|
|---|
| 160 | G4String remainingPath = commandPath;
|
|---|
| 161 | if( remainingPath.index( pathName ) == std::string::npos )
|
|---|
| 162 | { return NULL; }
|
|---|
| 163 | remainingPath.remove(0,pathName.length());
|
|---|
| 164 | G4int i = remainingPath.first('/');
|
|---|
| 165 | if( i == G4int(std::string::npos) )
|
|---|
| 166 | {
|
|---|
| 167 | // Find command
|
|---|
| 168 | G4int n_commandEntry = command.size();
|
|---|
| 169 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 170 | {
|
|---|
| 171 | if( remainingPath == command[i_thCommand]->GetCommandName() )
|
|---|
| 172 | { return command[i_thCommand]; }
|
|---|
| 173 | }
|
|---|
| 174 | }
|
|---|
| 175 | else
|
|---|
| 176 | {
|
|---|
| 177 | // Find path
|
|---|
| 178 | G4String nextPath = pathName;
|
|---|
| 179 | nextPath.append(remainingPath(0,i+1));
|
|---|
| 180 | G4int n_treeEntry = tree.size();
|
|---|
| 181 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 182 | {
|
|---|
| 183 | if( nextPath == tree[i_thTree]->GetPathName() )
|
|---|
| 184 | { return tree[i_thTree]->FindPath( commandPath ); }
|
|---|
| 185 | }
|
|---|
| 186 | }
|
|---|
| 187 | return NULL;
|
|---|
| 188 | }
|
|---|
| 189 |
|
|---|
| 190 | void G4UIcommandTree::ListCurrent()
|
|---|
| 191 | {
|
|---|
| 192 | G4cout << "Command directory path : " << pathName << G4endl;
|
|---|
| 193 | if( guidance != NULL ) guidance->List();
|
|---|
| 194 | G4cout << " Sub-directories : " << G4endl;
|
|---|
| 195 | G4int n_treeEntry = tree.size();
|
|---|
| 196 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 197 | {
|
|---|
| 198 | G4cout << " " << tree[i_thTree]->GetPathName()
|
|---|
| 199 | << " " << tree[i_thTree]->GetTitle() << G4endl;
|
|---|
| 200 | }
|
|---|
| 201 | G4cout << " Commands : " << G4endl;
|
|---|
| 202 | G4int n_commandEntry = command.size();
|
|---|
| 203 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 204 | {
|
|---|
| 205 | G4cout << " " << command[i_thCommand]->GetCommandName()
|
|---|
| 206 | << " * " << command[i_thCommand]->GetTitle() << G4endl;
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 |
|
|---|
| 210 | void G4UIcommandTree::ListCurrentWithNum()
|
|---|
| 211 | {
|
|---|
| 212 | G4cout << "Command directory path : " << pathName << G4endl;
|
|---|
| 213 | if( guidance != NULL ) guidance->List();
|
|---|
| 214 | G4int i = 0;
|
|---|
| 215 | G4cout << " Sub-directories : " << G4endl;
|
|---|
| 216 | G4int n_treeEntry = tree.size();
|
|---|
| 217 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 218 | {
|
|---|
| 219 | i++;
|
|---|
| 220 | G4cout << " " << i << ") " << tree[i_thTree]->GetPathName()
|
|---|
| 221 | << " " << tree[i_thTree]->GetTitle() << G4endl;
|
|---|
| 222 | }
|
|---|
| 223 | G4cout << " Commands : " << G4endl;
|
|---|
| 224 | G4int n_commandEntry = command.size();
|
|---|
| 225 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 226 | {
|
|---|
| 227 | i++;
|
|---|
| 228 | G4cout << " " << i << ") " << command[i_thCommand]->GetCommandName()
|
|---|
| 229 | << " * " << command[i_thCommand]->GetTitle() << G4endl;
|
|---|
| 230 | }
|
|---|
| 231 | }
|
|---|
| 232 |
|
|---|
| 233 | void G4UIcommandTree::List()
|
|---|
| 234 | {
|
|---|
| 235 | ListCurrent();
|
|---|
| 236 | G4int n_commandEntry = command.size();
|
|---|
| 237 | for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
|
|---|
| 238 | {
|
|---|
| 239 | command[i_thCommand]->List();
|
|---|
| 240 | }
|
|---|
| 241 | G4int n_treeEntry = tree.size();
|
|---|
| 242 | for( G4int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ )
|
|---|
| 243 | {
|
|---|
| 244 | tree[i_thTree]->List();
|
|---|
| 245 | }
|
|---|
| 246 | }
|
|---|
| 247 |
|
|---|
| 248 | G4String G4UIcommandTree::CreateFileName(const char* pName)
|
|---|
| 249 | {
|
|---|
| 250 | G4String fn = pName;
|
|---|
| 251 | G4int idxs;
|
|---|
| 252 | while((idxs=fn.index("/"))!=G4int(std::string::npos))
|
|---|
| 253 | { fn(idxs) = '_'; }
|
|---|
| 254 | fn += ".html";
|
|---|
| 255 | return fn;
|
|---|
| 256 | }
|
|---|
| 257 |
|
|---|
| 258 | G4String G4UIcommandTree::ModStr(const char* strS)
|
|---|
| 259 | {
|
|---|
| 260 | G4String sx;
|
|---|
| 261 | G4String str = strS;
|
|---|
| 262 | for(G4int i=0;i<G4int(str.length());i++)
|
|---|
| 263 | {
|
|---|
| 264 | char c = str(i);
|
|---|
| 265 | switch(c)
|
|---|
| 266 | {
|
|---|
| 267 | case '<':
|
|---|
| 268 | sx += "<"; break;
|
|---|
| 269 | case '>':
|
|---|
| 270 | sx += ">"; break;
|
|---|
| 271 | case '&':
|
|---|
| 272 | sx += "&"; break;
|
|---|
| 273 | default:
|
|---|
| 274 | sx += c;
|
|---|
| 275 | }
|
|---|
| 276 | }
|
|---|
| 277 | return sx;
|
|---|
| 278 | }
|
|---|
| 279 |
|
|---|
| 280 | void G4UIcommandTree::CreateHTML()
|
|---|
| 281 | {
|
|---|
| 282 | G4String ofileName = CreateFileName(pathName);
|
|---|
| 283 | std::ofstream oF(ofileName, std::ios::out);
|
|---|
| 284 |
|
|---|
| 285 | oF << "<html><head><title>Commands in " << ModStr(pathName) << "</title></head>" << G4endl;
|
|---|
| 286 | oF << "<body bgcolor=\"#ffffff\"><h2>" << ModStr(pathName) << "</h2><p>" << G4endl;
|
|---|
| 287 |
|
|---|
| 288 | if( guidance != NULL )
|
|---|
| 289 | {
|
|---|
| 290 | for(G4int i=0;i<guidance->GetGuidanceEntries();i++)
|
|---|
| 291 | { oF << ModStr(guidance->GetGuidanceLine(i)) << "<br>" << G4endl; }
|
|---|
| 292 | }
|
|---|
| 293 |
|
|---|
| 294 | oF << "<p><hr><p>" << G4endl;
|
|---|
| 295 |
|
|---|
| 296 | oF << "<h2>Sub-directories : </h2><dl>" << G4endl;
|
|---|
| 297 | for( G4int i_thTree = 0; i_thTree < G4int(tree.size()); i_thTree++ )
|
|---|
| 298 | {
|
|---|
| 299 | oF << "<p><br><p><dt><a href=\"" << CreateFileName(tree[i_thTree]->GetPathName())
|
|---|
| 300 | << "\">" << ModStr(tree[i_thTree]->GetPathName()) << "</a>" << G4endl;
|
|---|
| 301 | oF << "<p><dd>" << ModStr(tree[i_thTree]->GetTitle()) << G4endl;
|
|---|
| 302 | tree[i_thTree]->CreateHTML();
|
|---|
| 303 | }
|
|---|
| 304 |
|
|---|
| 305 | oF << "</dl><p><hr><p>" << G4endl;
|
|---|
| 306 |
|
|---|
| 307 | oF << "<h2>Commands : </h2><dl>" << G4endl;
|
|---|
| 308 | for( G4int i_thCommand = 0; i_thCommand < G4int(command.size()); i_thCommand++ )
|
|---|
| 309 | {
|
|---|
| 310 | G4UIcommand* cmd = command[i_thCommand];
|
|---|
| 311 | oF << "<p><br><p><dt><b>" << ModStr(cmd->GetCommandName());
|
|---|
| 312 | if(cmd->GetParameterEntries()>0)
|
|---|
| 313 | {
|
|---|
| 314 | for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
|
|---|
| 315 | { oF << " [<i>" << ModStr(cmd->GetParameter(i_thParam)->GetParameterName()) << "</i>]"; }
|
|---|
| 316 | }
|
|---|
| 317 | oF << "</b>" << G4endl;
|
|---|
| 318 | oF << "<p><dd>" << G4endl;
|
|---|
| 319 | for(G4int i=0;i<cmd->GetGuidanceEntries();i++)
|
|---|
| 320 | { oF << ModStr(cmd->GetGuidanceLine(i)) << "<br>" << G4endl; }
|
|---|
| 321 | if(!(cmd->GetRange()).isNull())
|
|---|
| 322 | { oF << "<p><dd>Range : " << ModStr(cmd->GetRange()) << G4endl; }
|
|---|
| 323 | std::vector<G4ApplicationState>* availabelStateList = cmd->GetStateList();
|
|---|
| 324 | if(availabelStateList->size()==6)
|
|---|
| 325 | { oF << "<p><dd>Available at all Geant4 states." << G4endl; }
|
|---|
| 326 | else
|
|---|
| 327 | {
|
|---|
| 328 | oF << "<p><dd>Available Geant4 state(s) : ";
|
|---|
| 329 | for(G4int ias=0;ias<G4int(availabelStateList->size());ias++)
|
|---|
| 330 | { oF << G4StateManager::GetStateManager()->GetStateString((*availabelStateList)[ias]) << " " << G4endl; }
|
|---|
| 331 | }
|
|---|
| 332 | if(cmd->GetParameterEntries()>0)
|
|---|
| 333 | {
|
|---|
| 334 | oF << "<p><dd>Parameters<table border=1>" << G4endl;
|
|---|
| 335 | for(G4int i_thParam=0;i_thParam<cmd->GetParameterEntries();i_thParam++)
|
|---|
| 336 | {
|
|---|
| 337 | G4UIparameter* prm = cmd->GetParameter(i_thParam);
|
|---|
| 338 | oF << "<tr><td>" << ModStr(prm->GetParameterName()) << G4endl;
|
|---|
| 339 | oF << "<td>type " << prm->GetParameterType() << G4endl;
|
|---|
| 340 | oF << "<td>";
|
|---|
| 341 | if(prm->IsOmittable())
|
|---|
| 342 | {
|
|---|
| 343 | oF << "Omittable : ";
|
|---|
| 344 | if(prm->GetCurrentAsDefault())
|
|---|
| 345 | { oF << "current value is used as the default value." << G4endl; }
|
|---|
| 346 | else
|
|---|
| 347 | { oF << "default value = " << prm->GetDefaultValue() << G4endl; }
|
|---|
| 348 | }
|
|---|
| 349 | oF << "<td>";
|
|---|
| 350 | if(!(prm->GetParameterRange()).isNull())
|
|---|
| 351 | { oF << "Parameter range : " << ModStr(prm->GetParameterRange()) << G4endl; }
|
|---|
| 352 | else if(!(prm->GetParameterCandidates()).isNull())
|
|---|
| 353 | { oF << "Parameter candidates : " << ModStr(prm->GetParameterCandidates()) << G4endl; }
|
|---|
| 354 | }
|
|---|
| 355 | oF << "</table>" << G4endl;
|
|---|
| 356 | }
|
|---|
| 357 |
|
|---|
| 358 | }
|
|---|
| 359 |
|
|---|
| 360 | oF << "</dl></body></html>" << G4endl;
|
|---|
| 361 | oF.close();
|
|---|
| 362 | }
|
|---|
| 363 |
|
|---|