[476] | 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 | // |
---|
[609] | 27 | // $Id: G4UIGAG.cc,v 1.19 2007/10/30 10:14:34 kmura Exp $ |
---|
| 28 | // GEANT4 tag $Name: $ |
---|
[476] | 29 | // |
---|
| 30 | // G4UIGAG.cc |
---|
| 31 | // 18.Feb.98 M.Nagamatu and T.Kodama created G4UIGAG from G4UIterminal |
---|
| 32 | |
---|
| 33 | #include "G4UIGAG.hh" |
---|
| 34 | #include "G4StateManager.hh" |
---|
| 35 | #include "G4UIcommandTree.hh" |
---|
| 36 | #include "G4UIcommand.hh" |
---|
| 37 | #include "G4UIcommandStatus.hh" |
---|
| 38 | #include <sstream> |
---|
| 39 | |
---|
| 40 | G4UIGAG::G4UIGAG()//: TVersion("T1.0a"), JVersion("J1.0a") |
---|
| 41 | { |
---|
| 42 | TVersion="T1.0a"; JVersion="J1.0a"; |
---|
| 43 | //G4cout << "G4UIGAG: Apr15,98." << G4endl; |
---|
| 44 | prefix = "/"; |
---|
| 45 | UI = G4UImanager::GetUIpointer(); |
---|
| 46 | UI->SetSession(this); |
---|
| 47 | UI->SetCoutDestination(this); |
---|
| 48 | G4StateManager * statM = G4StateManager::GetStateManager(); |
---|
| 49 | promptCharacter = statM->GetStateString(statM->GetCurrentState()); |
---|
| 50 | uiMode = terminal_mode; // GAG |
---|
| 51 | iExit = false; |
---|
| 52 | iCont = false; |
---|
| 53 | // -- Initialize Notify routines begin |
---|
| 54 | G4UIcommandTree * tree = UI->GetTree(); |
---|
| 55 | GetNewTreeStructure(tree,0); |
---|
| 56 | GetNewTreeValues(tree,0); |
---|
| 57 | previousTreeCommands = newTreeCommands; |
---|
| 58 | previousTreeParams = newTreeParams; |
---|
| 59 | previousTreePCP = newTreePCP; |
---|
| 60 | // -- end |
---|
| 61 | } |
---|
| 62 | |
---|
| 63 | G4UIGAG::~G4UIGAG() |
---|
| 64 | { |
---|
| 65 | if( G4UImanager::GetUIpointer() != 0) |
---|
| 66 | { |
---|
| 67 | UI->SetSession(NULL); |
---|
| 68 | UI->SetCoutDestination(NULL); |
---|
| 69 | // G4cout << "GAG session deleted" << G4endl; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | G4UIsession * G4UIGAG::SessionStart() |
---|
| 74 | { |
---|
| 75 | iExit = true; |
---|
| 76 | G4StateManager * statM = G4StateManager::GetStateManager(); |
---|
| 77 | promptCharacter = statM->GetStateString(statM->GetCurrentState()); |
---|
| 78 | G4String newCommand = GetCommand(); |
---|
| 79 | while( iExit ) |
---|
| 80 | { |
---|
| 81 | ExecuteCommand(newCommand); |
---|
| 82 | promptCharacter = statM->GetStateString(statM->GetCurrentState()); |
---|
| 83 | newCommand = GetCommand(); |
---|
| 84 | } |
---|
| 85 | return NULL; |
---|
| 86 | } |
---|
| 87 | |
---|
| 88 | void G4UIGAG::PauseSessionStart(G4String msg) |
---|
| 89 | { |
---|
| 90 | promptCharacter = msg; |
---|
| 91 | G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl; |
---|
| 92 | iCont = true; |
---|
| 93 | G4String newCommand = GetCommand(); |
---|
| 94 | while( iCont ) |
---|
| 95 | { |
---|
| 96 | ExecuteCommand(newCommand); |
---|
| 97 | newCommand = GetCommand(); |
---|
| 98 | } |
---|
| 99 | } |
---|
| 100 | |
---|
| 101 | void G4UIGAG::ExecuteCommand(G4String aCommand) |
---|
| 102 | { |
---|
| 103 | G4UIcommandTree * tree = UI->GetTree(); |
---|
| 104 | if(aCommand.length()<2) return; |
---|
| 105 | G4int returnVal = UI->ApplyCommand(aCommand); |
---|
| 106 | G4int paramIndex = returnVal % 100; |
---|
| 107 | G4int commandStatus = returnVal - paramIndex; |
---|
| 108 | |
---|
| 109 | UpdateState(); |
---|
| 110 | if ( uiMode == terminal_mode){ |
---|
| 111 | switch(commandStatus) { |
---|
| 112 | case fCommandSucceeded: |
---|
| 113 | break; |
---|
| 114 | case fCommandNotFound: |
---|
| 115 | // G4cerr << "command not found" << G4endl; |
---|
| 116 | G4cerr << "command <" << UI->SolveAlias(aCommand) << "> not found" << G4endl; |
---|
| 117 | break; |
---|
| 118 | case fIllegalApplicationState: |
---|
| 119 | G4cerr << "illegal application state -- command refused" << G4endl; |
---|
| 120 | break; |
---|
| 121 | case fParameterOutOfRange: |
---|
| 122 | case fParameterUnreadable: |
---|
| 123 | G4cerr << "Parameter is wrong type and/or is not omittable (index " << paramIndex << ")" << G4endl; |
---|
| 124 | break; |
---|
| 125 | case fParameterOutOfCandidates: |
---|
| 126 | G4cerr << "Parameter is out of candidate list (index " << paramIndex << ")" << G4endl; |
---|
| 127 | // G4cerr << "Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates() << G4endl; |
---|
| 128 | break; |
---|
| 129 | case fAliasNotFound: |
---|
| 130 | default: |
---|
| 131 | G4cerr << "command refused (" << commandStatus << ")" << G4endl; |
---|
| 132 | } |
---|
| 133 | }else{ |
---|
| 134 | switch(commandStatus) { |
---|
| 135 | case fCommandSucceeded: |
---|
| 136 | { |
---|
| 137 | GetNewTreeStructure(tree,0); |
---|
| 138 | GetNewTreeValues(tree,0); |
---|
| 139 | if (CommandUpdated()) { |
---|
| 140 | NotifyCommandUpdate(); |
---|
| 141 | } else { |
---|
| 142 | UpdateParamVal(); // if param is updated, call notifyPara... |
---|
| 143 | } |
---|
| 144 | previousTreeCommands = newTreeCommands; |
---|
| 145 | previousTreeParams = newTreeParams; |
---|
| 146 | previousTreePCP = newTreePCP; |
---|
| 147 | } |
---|
| 148 | break; |
---|
| 149 | case fCommandNotFound: |
---|
| 150 | G4cout << "@@ErrResult \" <" << UI->SolveAlias(aCommand) << "> command not found.\"" << G4endl; |
---|
| 151 | break; |
---|
| 152 | case fIllegalApplicationState: |
---|
| 153 | G4cout << "@@ErrResult \"Illegal application state -- command refused\"" << G4endl; |
---|
| 154 | break; |
---|
| 155 | case fParameterOutOfRange: |
---|
| 156 | G4cout << "@@ErrResult \"Parameter Out of Range.\"" << G4endl; |
---|
| 157 | break; |
---|
| 158 | case fParameterUnreadable: |
---|
| 159 | G4cout << "@@ErrResult \"Parameter is wrong type and/or is not omittable.\"" << G4endl; |
---|
| 160 | break; |
---|
| 161 | case fParameterOutOfCandidates: |
---|
| 162 | // G4cout << "@@ErrResult \"Parameter Out of Candidates. Candidates : " << cmd->GetParameter(paramIndex)->GetParameterCandidates()<< "\"" << G4endl; |
---|
| 163 | G4cout << "@@ErrResult \"Parameter Out of Candidates.\"" << G4endl; |
---|
| 164 | break; |
---|
| 165 | case fAliasNotFound: |
---|
| 166 | default: |
---|
| 167 | G4cout << "@@ErrResult \"command refused (" << commandStatus << ")\"" << G4endl; |
---|
| 168 | } |
---|
| 169 | } |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | |
---|
| 173 | G4int G4UIGAG::ReceiveG4cout(G4String coutString) |
---|
| 174 | { |
---|
| 175 | std::cout << coutString << std::flush; |
---|
| 176 | return 0; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | G4int G4UIGAG::ReceiveG4cerr(G4String cerrString) |
---|
| 180 | { |
---|
| 181 | std::cerr << cerrString << std::flush; |
---|
| 182 | return 0; |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | void G4UIGAG::Prompt(G4String aPrompt) |
---|
| 186 | { |
---|
| 187 | promptCharacter = aPrompt; |
---|
| 188 | } |
---|
| 189 | |
---|
| 190 | G4String G4UIGAG::GetCommand() |
---|
| 191 | { |
---|
| 192 | G4String newCommand; |
---|
| 193 | G4String nullString; |
---|
| 194 | while( 1 ) |
---|
| 195 | { |
---|
| 196 | G4UIcommandTree* tree = UI->GetTree(); |
---|
| 197 | if ( uiMode != terminal_mode ){ |
---|
| 198 | G4cout << "@@PROMPT \"" << promptCharacter << "\"" << G4endl; |
---|
| 199 | } |
---|
| 200 | if ( uiMode != java_mode ){ |
---|
| 201 | G4cout << promptCharacter << "> " << std::flush; |
---|
| 202 | }else{ |
---|
| 203 | G4cout << "@@Ready" << G4endl; |
---|
| 204 | } |
---|
| 205 | newCommand.readLine( G4cin, FALSE ); |
---|
| 206 | if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;} |
---|
| 207 | |
---|
| 208 | newCommand = newCommand.strip(G4String::leading); |
---|
| 209 | if( newCommand.length() < 1) { break; } |
---|
| 210 | |
---|
| 211 | while( newCommand(newCommand.length()-1) == '_' ) |
---|
| 212 | { |
---|
| 213 | G4String newLine; |
---|
| 214 | newCommand.remove(newCommand.length()-1); |
---|
| 215 | newLine.readLine( G4cin ); |
---|
| 216 | if (!G4cin.good()) { G4cin.clear(); newCommand = nullString; iExit=false;break;} |
---|
| 217 | newCommand.append(newLine); |
---|
| 218 | } |
---|
| 219 | |
---|
| 220 | G4String nC = newCommand.strip(G4String::leading); |
---|
| 221 | if( nC.length() < 1) { break; } |
---|
| 222 | |
---|
| 223 | // -------------------- nC.toUpper(); |
---|
| 224 | if( nC == "@@GAGmodeJAVA" ) { |
---|
| 225 | uiMode = java_mode; |
---|
| 226 | G4cout << G4endl << "@@Version " << JVersion << G4endl; |
---|
| 227 | SendCommandProperties(tree); |
---|
| 228 | NotifyStateChange(); |
---|
| 229 | } |
---|
| 230 | else if( nC == "@@GAGmodeTcl" ) { |
---|
| 231 | uiMode = tcl_mode; |
---|
| 232 | G4cout << G4endl << "@@Version " << TVersion << G4endl; |
---|
| 233 | SendCommandProperties(tree); |
---|
| 234 | NotifyStateChange(); |
---|
| 235 | } |
---|
| 236 | else if( nC(0) == '#' ) |
---|
| 237 | { G4cout << nC << G4endl; } |
---|
| 238 | |
---|
| 239 | else if( nC == "ls" || nC(0,3) == "ls " ) |
---|
| 240 | { ListDirectory( nC ); } |
---|
| 241 | else if( nC == "pwd" ) |
---|
| 242 | { G4cout << "Current Working Directory : " << prefix << G4endl; } |
---|
| 243 | else if( nC(0,2) == "cd" || nC(0,3) == "cd " ) |
---|
| 244 | { ChangeDirectory( nC ); } |
---|
| 245 | else if( nC == "help" || nC(0,5) == "help ") |
---|
| 246 | { TerminalHelp( nC ); } |
---|
| 247 | else if( nC(0) == '?' ) |
---|
| 248 | { ShowCurrent( nC ); } |
---|
| 249 | else if( nC(0,4) == "hist" || nC == "history") |
---|
| 250 | { |
---|
| 251 | G4int nh = UI->GetNumberOfHistory(); |
---|
| 252 | for(int i=0;i<nh;i++) |
---|
| 253 | { G4cout << i << ": " << UI->GetPreviousCommand(i) << G4endl; } |
---|
| 254 | } |
---|
| 255 | else if( nC(0) == '!' ) |
---|
| 256 | { |
---|
| 257 | G4String ss = nC(1,nC.length()-1); |
---|
| 258 | G4int vl; |
---|
| 259 | const char* tt = ss; |
---|
| 260 | std::istringstream is((char*)tt); |
---|
| 261 | is >> vl; |
---|
| 262 | G4int nh = UI->GetNumberOfHistory(); |
---|
| 263 | if(vl>=0 && vl<nh) |
---|
| 264 | { |
---|
| 265 | newCommand = UI->GetPreviousCommand(vl); |
---|
| 266 | G4cout << newCommand << G4endl; |
---|
| 267 | break; |
---|
| 268 | } |
---|
| 269 | else |
---|
| 270 | { G4cerr << "history " << vl << " is not found." << G4endl; } |
---|
| 271 | } |
---|
| 272 | else if( nC(0,4) == "exit" ) |
---|
| 273 | { |
---|
| 274 | if( iCont ) |
---|
| 275 | { |
---|
| 276 | if ( uiMode == terminal_mode){ |
---|
| 277 | G4cerr << "You are now processing RUN." << G4endl; |
---|
| 278 | G4cerr << "Please abrot it using \"/run/abort\" command first" << G4endl; |
---|
| 279 | G4cerr << " and use \"continue\" command until the application" << G4endl; |
---|
| 280 | G4cerr << " becomes to Idle." << G4endl; |
---|
| 281 | }else{ |
---|
| 282 | G4cout << "@@ErrResult \"You are now processing RUN.\"" << G4endl; |
---|
| 283 | } |
---|
| 284 | } |
---|
| 285 | else |
---|
| 286 | { |
---|
| 287 | iExit = false; |
---|
| 288 | newCommand = nullString; |
---|
| 289 | break; |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | else if( nC == "cont" || nC == "continue" ) |
---|
| 293 | { |
---|
| 294 | iCont = false; |
---|
| 295 | newCommand = nullString; |
---|
| 296 | break; |
---|
| 297 | } |
---|
| 298 | else |
---|
| 299 | { break; } |
---|
| 300 | } |
---|
| 301 | return GetFullPath(newCommand); |
---|
| 302 | } |
---|
| 303 | |
---|
| 304 | G4String G4UIGAG::GetFullPath( G4String aNewCommand ) |
---|
| 305 | { |
---|
| 306 | G4String newCommand = aNewCommand.strip(G4String::both); |
---|
| 307 | G4String tmpString; |
---|
| 308 | if( newCommand(0) == '/' ) |
---|
| 309 | { tmpString = newCommand; } |
---|
| 310 | else if( newCommand(0,3) == "../" ) |
---|
| 311 | { |
---|
| 312 | G4String tmpPrefix = prefix; |
---|
| 313 | /*G4int*/ unsigned i_direc = 0; |
---|
| 314 | while( i_direc < newCommand.length() ) |
---|
| 315 | { |
---|
| 316 | if( newCommand(i_direc,3) == "../" ) |
---|
| 317 | { |
---|
| 318 | i_direc += 3; |
---|
| 319 | prefix = ModifyPrefix( G4String("../") ); |
---|
| 320 | } |
---|
| 321 | else |
---|
| 322 | { break; } |
---|
| 323 | } |
---|
| 324 | tmpString = prefix; |
---|
| 325 | tmpString.append( newCommand( i_direc, newCommand.length()-i_direc ) ); |
---|
| 326 | prefix = tmpPrefix; |
---|
| 327 | } |
---|
| 328 | else |
---|
| 329 | { |
---|
| 330 | tmpString = prefix; |
---|
| 331 | tmpString.append( newCommand ); |
---|
| 332 | } |
---|
| 333 | return tmpString; |
---|
| 334 | } |
---|
| 335 | |
---|
| 336 | void G4UIGAG::SessionTerminate() |
---|
| 337 | { |
---|
| 338 | G4cout << "***** Terminal session end *****" << G4endl; |
---|
| 339 | } |
---|
| 340 | |
---|
| 341 | void G4UIGAG::ShowCurrent( G4String newCommand ) |
---|
| 342 | { |
---|
| 343 | G4String theCommand = GetFullPath(newCommand(1,newCommand.length()-1)); |
---|
| 344 | G4String curV = UI->GetCurrentValues(theCommand); |
---|
| 345 | if( ! (curV.isNull()||curV(0)=='\0' ) ) { |
---|
| 346 | if (uiMode == terminal_mode){ |
---|
| 347 | G4cout << "Current value(s) of the parameter(s) : " << curV << G4endl; |
---|
| 348 | }else{ |
---|
| 349 | G4cout << "@@CurrentValue " << curV << G4endl; |
---|
| 350 | } |
---|
| 351 | } else if (uiMode == terminal_mode){ |
---|
| 352 | G4cout << "Current value is not available." << G4endl; |
---|
| 353 | } else { |
---|
| 354 | G4cout << "@@ErrResult \"Current value is not available.\"" << G4endl; |
---|
| 355 | } |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | void G4UIGAG::ChangeDirectory( G4String newCommand ) |
---|
| 359 | { |
---|
| 360 | G4String savedPrefix = prefix; |
---|
| 361 | if( newCommand.length() <= 3 ) |
---|
| 362 | { prefix = "/"; } |
---|
| 363 | else |
---|
| 364 | { |
---|
| 365 | G4String aNewPrefix = newCommand(3,newCommand.length()-3); |
---|
| 366 | G4String newPrefix = aNewPrefix.strip(G4String::both); |
---|
| 367 | if( newPrefix(0) == '/' ) |
---|
| 368 | { prefix = newPrefix; } |
---|
| 369 | else if( newPrefix(0) != '.' ) |
---|
| 370 | { |
---|
| 371 | prefix += newPrefix; |
---|
| 372 | } |
---|
| 373 | else |
---|
| 374 | { prefix = ModifyPrefix( newPrefix ); } |
---|
| 375 | } |
---|
| 376 | if( prefix( prefix.length() - 1 ) != '/' ) |
---|
| 377 | { prefix += "/"; } |
---|
| 378 | if( FindDirPath( prefix ) == NULL ) |
---|
| 379 | { |
---|
| 380 | G4cout << "Directory <" << prefix << "> is not found." << G4endl; |
---|
| 381 | prefix = savedPrefix; |
---|
| 382 | } |
---|
| 383 | } |
---|
| 384 | |
---|
| 385 | void G4UIGAG::ListDirectory( G4String newCommand ) |
---|
| 386 | { |
---|
| 387 | G4String targetDir('\0'); |
---|
| 388 | if( newCommand.length() <= 3 ) |
---|
| 389 | { targetDir = prefix; } |
---|
| 390 | else |
---|
| 391 | { |
---|
| 392 | G4String newPrefix = newCommand(3,newCommand.length()-3); |
---|
| 393 | newPrefix.strip(G4String::both); |
---|
| 394 | if( newPrefix(0) == '/' ) |
---|
| 395 | { targetDir = newPrefix; } |
---|
| 396 | else if( newPrefix(0) != '.' ) |
---|
| 397 | { |
---|
| 398 | targetDir = prefix; |
---|
| 399 | targetDir += newPrefix; |
---|
| 400 | } |
---|
| 401 | else |
---|
| 402 | { targetDir = ModifyPrefix( newPrefix ); } |
---|
| 403 | } |
---|
| 404 | if( targetDir( targetDir.length() - 1 ) != '/' ) |
---|
| 405 | { targetDir += "/"; } |
---|
| 406 | G4UIcommandTree * commandTree = FindDirPath( targetDir ); |
---|
| 407 | if( commandTree == NULL ) |
---|
| 408 | { G4cout << "Directory <" << targetDir << "> is not found." << G4endl; } |
---|
| 409 | else |
---|
| 410 | { commandTree->ListCurrent(); } |
---|
| 411 | } |
---|
| 412 | |
---|
| 413 | void G4UIGAG::TerminalHelp(G4String newCommand) |
---|
| 414 | { |
---|
| 415 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
[609] | 416 | /*int*/str_size i = newCommand.index(" "); |
---|
[476] | 417 | if( i != std::string::npos ) |
---|
| 418 | { |
---|
| 419 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
| 420 | newValue.strip(G4String::both); |
---|
| 421 | if( newValue(0) != '/' ) |
---|
| 422 | { newValue.prepend( prefix ); } |
---|
| 423 | G4UIcommand * theCommand = treeTop->FindPath( newValue ); |
---|
| 424 | if( theCommand != NULL ) |
---|
| 425 | { |
---|
| 426 | theCommand->List(); |
---|
| 427 | return; |
---|
| 428 | } |
---|
| 429 | else |
---|
| 430 | { |
---|
| 431 | G4cout << "Command <" << newValue << " is not found." << G4endl; |
---|
| 432 | return; |
---|
| 433 | } |
---|
| 434 | } |
---|
| 435 | |
---|
| 436 | G4UIcommandTree * floor[10]; |
---|
| 437 | floor[0] = treeTop; |
---|
| 438 | int iFloor = 0; |
---|
| 439 | /*int*/ unsigned prefixIndex = 1; |
---|
| 440 | while( prefixIndex < prefix.length()-1 ) |
---|
| 441 | { |
---|
| 442 | int ii = prefix.index("/",prefixIndex); |
---|
| 443 | floor[iFloor+1] = |
---|
| 444 | floor[iFloor]->GetTree(G4String(prefix(0,ii+1))); |
---|
| 445 | prefixIndex = ii+1; |
---|
| 446 | iFloor++; |
---|
| 447 | } |
---|
| 448 | floor[iFloor]->ListCurrentWithNum(); |
---|
| 449 | // 1998 Oct 2 non-number input |
---|
| 450 | while(1){ |
---|
| 451 | int i; |
---|
| 452 | G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush; |
---|
| 453 | G4cin >> i; |
---|
| 454 | if(!G4cin.good()){ |
---|
| 455 | G4cin.clear(); |
---|
| 456 | G4cin.ignore(30,'\n'); |
---|
| 457 | G4cout << G4endl << "Not a number, once more" << G4endl; continue;} |
---|
| 458 | else if( i < 0 ){ |
---|
| 459 | iFloor += i; |
---|
| 460 | if( iFloor < 0 ) iFloor = 0; |
---|
| 461 | floor[iFloor]->ListCurrentWithNum(); continue;} |
---|
| 462 | else if(i == 0) { break;} |
---|
| 463 | else if( i > 0 ) { |
---|
| 464 | int n_tree = floor[iFloor]->GetTreeEntry(); |
---|
| 465 | if( i > n_tree ) |
---|
| 466 | { |
---|
| 467 | if( i <= n_tree + floor[iFloor]->GetCommandEntry() ) |
---|
| 468 | { |
---|
| 469 | floor[iFloor]->GetCommand(i-n_tree)->List(); |
---|
| 470 | //iFloor++; |
---|
| 471 | } |
---|
| 472 | } |
---|
| 473 | else |
---|
| 474 | { |
---|
| 475 | floor[iFloor+1] = floor[iFloor]->GetTree(i); |
---|
| 476 | iFloor++; |
---|
| 477 | floor[iFloor]->ListCurrentWithNum(); |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | } |
---|
| 482 | G4cout << "Exit from HELP." << G4endl << G4endl; |
---|
| 483 | G4cout << G4endl; |
---|
| 484 | // G4cin.flush(); |
---|
| 485 | char temp[100]; |
---|
| 486 | G4cin.getline( temp, 100 ); |
---|
| 487 | } |
---|
| 488 | |
---|
| 489 | |
---|
| 490 | |
---|
| 491 | |
---|
| 492 | |
---|
| 493 | |
---|
| 494 | |
---|
| 495 | G4String G4UIGAG::ModifyPrefix(G4String newCommand) |
---|
| 496 | { |
---|
| 497 | G4String newPrefix = prefix; |
---|
| 498 | while( 1 ) |
---|
| 499 | { |
---|
| 500 | if( newCommand(0,2) == ".." ) |
---|
| 501 | { |
---|
| 502 | if( newPrefix != "/" ) |
---|
| 503 | { |
---|
| 504 | G4String tmpString = newPrefix(0,newPrefix.length()-1); |
---|
| 505 | newPrefix = newPrefix(0,tmpString.last('/')+1); |
---|
| 506 | } |
---|
| 507 | } |
---|
| 508 | else |
---|
| 509 | { |
---|
| 510 | newPrefix += newCommand; |
---|
| 511 | break; |
---|
| 512 | } |
---|
| 513 | if( newCommand == ".." || newCommand == "../" ) |
---|
| 514 | { break; } |
---|
| 515 | newCommand = newCommand(3,newCommand.length()-3); |
---|
| 516 | } |
---|
| 517 | return newPrefix; |
---|
| 518 | } |
---|
| 519 | |
---|
| 520 | G4UIcommandTree * G4UIGAG::FindDirPath(G4String newCommand) |
---|
| 521 | { |
---|
| 522 | G4UIcommandTree * comTree = UI->GetTree(); |
---|
| 523 | /*int*/ unsigned idx = 1; |
---|
| 524 | while( idx < newCommand.length()-1 ) |
---|
| 525 | { |
---|
| 526 | int i = newCommand.index("/",idx); |
---|
| 527 | comTree = comTree->GetTree(G4String(newCommand(0,i+1))); |
---|
| 528 | if( comTree == NULL ) |
---|
| 529 | { return NULL; } |
---|
| 530 | idx = i+1; |
---|
| 531 | } |
---|
| 532 | return comTree; |
---|
| 533 | } |
---|
| 534 | |
---|
| 535 | // ----- for JAVA GAG (by T.Kodama) |
---|
| 536 | |
---|
| 537 | void G4UIGAG::SendCommandProperties(G4UIcommandTree * tree) |
---|
| 538 | { |
---|
| 539 | if( tree == NULL ) { |
---|
| 540 | G4cerr << "GetTree() returnes null." << G4endl; |
---|
| 541 | return; |
---|
| 542 | } |
---|
| 543 | if (uiMode == java_mode){ |
---|
| 544 | G4cout << "@@JTreeBegin" << G4endl; |
---|
| 545 | CodeGenJavaTree(tree, 0); |
---|
| 546 | G4cout << "@@JTreeEnd" << G4endl; |
---|
| 547 | CodeGenJavaParams(tree, 0); |
---|
| 548 | }else{ |
---|
| 549 | G4cout << G4endl << "@@maketree_start" << G4endl; |
---|
| 550 | CodeGenTclTree(tree,0); |
---|
| 551 | G4cout << "@@maketree_end" << G4endl; |
---|
| 552 | CodeGenTclParams(tree, 0); |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | void G4UIGAG::SendParameterProperties(G4UIcommandTree * tree) |
---|
| 556 | { |
---|
| 557 | if( tree == NULL ) { |
---|
| 558 | G4cerr << "GetTree() returnes null." << G4endl; |
---|
| 559 | return; |
---|
| 560 | } |
---|
| 561 | if (uiMode == java_mode){ |
---|
| 562 | CodeGenJavaParams(tree, 0); |
---|
| 563 | }else{ |
---|
| 564 | CodeGenTclParams(tree, 0); |
---|
| 565 | } |
---|
| 566 | } |
---|
| 567 | |
---|
| 568 | void G4UIGAG::CodeGenJavaTree(G4UIcommandTree * tree, int level) |
---|
| 569 | { |
---|
| 570 | int treeEntry, commandEntry; |
---|
| 571 | treeEntry = tree->GetTreeEntry(); |
---|
| 572 | commandEntry = tree->GetCommandEntry(); |
---|
| 573 | |
---|
| 574 | if(level!=0) { |
---|
| 575 | for(int i=0; i<commandEntry; i++){ |
---|
| 576 | G4cout << tree->GetCommand(i+1)->GetCommandPath() << G4endl; |
---|
| 577 | } |
---|
| 578 | } |
---|
| 579 | if(treeEntry == 0) return; //end recursion |
---|
| 580 | |
---|
| 581 | for(int j=0; j<treeEntry; j++){ |
---|
| 582 | CodeGenJavaTree(tree->GetTree(j+1), level+1); |
---|
| 583 | } |
---|
| 584 | } |
---|
| 585 | |
---|
| 586 | void G4UIGAG::CodeGenJavaParams(G4UIcommandTree * tree, int level) //recursive |
---|
| 587 | { |
---|
| 588 | int treeEntry, commandEntry, i; |
---|
| 589 | //G4UIcommand * Comp; |
---|
| 590 | G4UIcommandTree * treeLink; |
---|
| 591 | |
---|
| 592 | treeEntry = tree->GetTreeEntry(); |
---|
| 593 | commandEntry = tree->GetCommandEntry(); |
---|
| 594 | |
---|
| 595 | for(i=0; i<commandEntry; i++) { |
---|
| 596 | SendAParamProperty(tree->GetCommand(i+1)); |
---|
| 597 | } |
---|
| 598 | if( treeEntry == 0 ) return; // end recursion |
---|
| 599 | |
---|
| 600 | for(i=0; i< treeEntry; i++) { |
---|
| 601 | treeLink = tree->GetTree(i+1); |
---|
| 602 | G4cout << "@@JDirGuideBegin" << G4endl; |
---|
| 603 | G4cout << treeLink->GetPathName() << G4endl << treeLink->GetTitle() << G4endl; |
---|
| 604 | G4cout << "@@JDirGuideEnd" << G4endl; |
---|
| 605 | CodeGenJavaParams(treeLink, level+1); |
---|
| 606 | } |
---|
| 607 | } |
---|
| 608 | |
---|
| 609 | void G4UIGAG::SendAParamProperty(G4UIcommand * Comp) |
---|
| 610 | { |
---|
| 611 | int guidanceEntry, parameterEntry; |
---|
| 612 | G4String title, title2; |
---|
| 613 | G4UIparameter * prp; |
---|
| 614 | char c[2]; |
---|
| 615 | guidanceEntry = Comp->GetGuidanceEntries(); |
---|
| 616 | parameterEntry = Comp->GetParameterEntries(); |
---|
| 617 | G4cout << "@@JParamBegin" << G4endl; |
---|
| 618 | G4cout << Comp->GetCommandPath() << G4endl; |
---|
| 619 | G4cout << guidanceEntry << G4endl; |
---|
| 620 | for (int j=0; j<guidanceEntry; j++){ |
---|
| 621 | title = Comp->GetGuidanceLine(j); |
---|
| 622 | title2 = ""; |
---|
| 623 | if (title != ""){ |
---|
| 624 | for(int i=0; i< (int)title.length(); i++){ |
---|
| 625 | c[0]=title(i); |
---|
| 626 | c[1]= '\0'; |
---|
| 627 | if ( c[0] == '\n' || c[0] == '\r') { |
---|
| 628 | c[0]= ' '; |
---|
| 629 | } |
---|
| 630 | title2.append(c); |
---|
| 631 | } |
---|
| 632 | } |
---|
| 633 | G4cout << title2 << G4endl; |
---|
| 634 | } |
---|
| 635 | G4cout << Comp->GetRange() << G4endl; |
---|
| 636 | G4cout << parameterEntry << G4endl; |
---|
| 637 | for( int par=0; par<parameterEntry; par++) { |
---|
| 638 | prp = (G4UIparameter *)Comp->GetParameter(par); |
---|
| 639 | G4cout << prp->GetParameterName() << G4endl; |
---|
| 640 | G4cout << prp->GetParameterGuidance() << G4endl; |
---|
| 641 | G4cout << prp->GetParameterType() << G4endl; |
---|
| 642 | G4cout << prp->IsOmittable() << G4endl; |
---|
| 643 | G4cout << prp->GetDefaultValue() << G4endl; |
---|
| 644 | G4cout << prp->GetParameterRange() << G4endl; |
---|
| 645 | G4cout << prp->GetParameterCandidates() << G4endl; |
---|
| 646 | } |
---|
| 647 | G4cout << "@@JParamEnd" << G4endl; |
---|
| 648 | } |
---|
| 649 | |
---|
| 650 | void G4UIGAG::SendDisableList(G4UIcommandTree * tree, int level) |
---|
| 651 | { |
---|
| 652 | int treeEntry, commandEntry; |
---|
| 653 | G4UIcommand * Comp; |
---|
| 654 | treeEntry = tree->GetTreeEntry(); |
---|
| 655 | commandEntry = tree->GetCommandEntry(); |
---|
| 656 | |
---|
| 657 | for(int com=0; com<commandEntry; com++) { |
---|
| 658 | Comp = tree->GetCommand(com+1); |
---|
| 659 | if( Comp->IsAvailable()==false ) { |
---|
| 660 | G4cout << Comp->GetCommandPath()<<G4endl; |
---|
| 661 | } |
---|
| 662 | } |
---|
| 663 | if( treeEntry == 0 ) return; // end recursion |
---|
| 664 | |
---|
| 665 | for( int i=0; i<treeEntry; i++) { |
---|
| 666 | SendDisableList(tree->GetTree(i+1), level+1); |
---|
| 667 | // be sure the function name is the same |
---|
| 668 | } |
---|
| 669 | } |
---|
| 670 | |
---|
| 671 | // ----- for Tcl GAG |
---|
| 672 | |
---|
| 673 | void G4UIGAG::CodeGenTclTree(G4UIcommandTree * tree, int level) |
---|
| 674 | { |
---|
| 675 | int i, j; |
---|
| 676 | int treeEntry, commandEntry, guidanceEntry; |
---|
| 677 | treeEntry = tree->GetTreeEntry(); |
---|
| 678 | commandEntry = tree->GetCommandEntry(); |
---|
| 679 | G4String commandPath, pathName, title1, title2; |
---|
| 680 | G4UIcommandTree * t; |
---|
| 681 | G4UIcommand * Comp; |
---|
| 682 | |
---|
| 683 | for(int com=0; com<commandEntry; com++){ |
---|
| 684 | Comp = tree->GetCommand(com+1); |
---|
| 685 | commandPath = Comp->GetCommandPath(); |
---|
| 686 | G4cout << commandPath << " @@command" << G4endl; |
---|
| 687 | guidanceEntry = Comp->GetGuidanceEntries(); |
---|
| 688 | if (guidanceEntry == 0){ |
---|
| 689 | title2 = "...Title not available..."; |
---|
| 690 | } else { |
---|
| 691 | title2 = ""; |
---|
| 692 | j = 0; |
---|
| 693 | while(1){ |
---|
| 694 | title1 = Comp->GetGuidanceLine(j); |
---|
| 695 | for(i=0; i< (int)title1.length(); i++){ |
---|
| 696 | char c[2]; |
---|
| 697 | c[0]=title1(i); |
---|
| 698 | c[1]= '\0'; |
---|
| 699 | if( c[0] == '\"') { |
---|
| 700 | title2.append("\\\""); // a Backslash and a double quote |
---|
| 701 | } else if ( c[0] == '\n' || c[0] == '\r') { |
---|
| 702 | title2.append("\\n"); |
---|
| 703 | } else title2.append(c); |
---|
| 704 | } |
---|
| 705 | j++; |
---|
| 706 | if (j >= guidanceEntry) break; |
---|
| 707 | title2.append("\\n"); |
---|
| 708 | } |
---|
| 709 | } |
---|
| 710 | G4cout << commandPath << " @@title \""<< title2 <<"\""<< G4endl; |
---|
| 711 | } |
---|
| 712 | |
---|
| 713 | if(treeEntry == 0) return; //end recursion |
---|
| 714 | |
---|
| 715 | for(i=0; i< treeEntry; i++){ |
---|
| 716 | t = tree->GetTree(i+1); |
---|
| 717 | pathName = t->GetPathName(); |
---|
| 718 | title1 = t->GetTitle(); |
---|
| 719 | title2 = ""; |
---|
| 720 | for(int i=0; i<(int)title1.length(); i++){ |
---|
| 721 | char c[2]; |
---|
| 722 | c[0]=title1(i); |
---|
| 723 | c[1]= '\0'; |
---|
| 724 | if( c[0] == '\"') |
---|
| 725 | title2.append("\\\""); // a Backslash and a double quote |
---|
| 726 | else title2.append(c); |
---|
| 727 | } |
---|
| 728 | if(level==0) G4cout << pathName<< G4endl; |
---|
| 729 | else G4cout << pathName<< " @@cascade"<<G4endl; |
---|
| 730 | G4cout << pathName << " @@title \"" << title1 << "\""<<G4endl; |
---|
| 731 | CodeGenTclTree(t, level+1); |
---|
| 732 | } |
---|
| 733 | } |
---|
| 734 | |
---|
| 735 | void G4UIGAG::CodeGenTclParams( G4UIcommandTree * tree, int level) // recursive |
---|
| 736 | { |
---|
| 737 | int treeEntry, commandEntry; |
---|
| 738 | G4UIcommand * Comp; |
---|
| 739 | treeEntry = tree->GetTreeEntry(); |
---|
| 740 | commandEntry = tree->GetCommandEntry(); |
---|
| 741 | |
---|
| 742 | for(int com=0; com<commandEntry; com++) { |
---|
| 743 | Comp = tree->GetCommand(com+1); |
---|
| 744 | SendATclParamProperty(Comp); |
---|
| 745 | } |
---|
| 746 | if( treeEntry == 0 ) return; // end recursion |
---|
| 747 | |
---|
| 748 | for( int i=0; i<treeEntry; i++) { |
---|
| 749 | CodeGenTclParams(tree->GetTree(i+1), level+1); |
---|
| 750 | // be sure the function name is the same |
---|
| 751 | } |
---|
| 752 | } |
---|
| 753 | |
---|
| 754 | void G4UIGAG::SendATclParamProperty(G4UIcommand * Comp) |
---|
| 755 | { |
---|
| 756 | G4UIparameter * prp; |
---|
| 757 | int parameterEntry = Comp->GetParameterEntries(); |
---|
| 758 | G4String commandPath = Comp->GetCommandPath(); |
---|
| 759 | G4String commandRange = Comp->GetRange(); |
---|
| 760 | G4cout << "@@parameter_start" << G4endl; |
---|
| 761 | G4cout << commandPath << " @@param " << parameterEntry << G4endl; |
---|
| 762 | G4cout << "@@command_range \"" << commandRange << "\"" << G4endl; |
---|
| 763 | for( int par=0; par<parameterEntry; par++) { |
---|
| 764 | prp = (G4UIparameter *)Comp->GetParameter(par); |
---|
| 765 | G4cout << "{" ; |
---|
| 766 | G4cout << "@@param_name : \"" << prp->GetParameterName() <<"\""<<G4endl; |
---|
| 767 | G4String guide1,guide2; |
---|
| 768 | guide1 = prp->GetParameterGuidance(); |
---|
| 769 | guide2 = ""; |
---|
| 770 | for(int i=0; i<(int)guide1.length(); i++){ |
---|
| 771 | char c[2]; |
---|
| 772 | c[0]=guide1(i); |
---|
| 773 | c[1]= '\0'; |
---|
| 774 | if( c[0] == '\"') |
---|
| 775 | guide2.append("\\\""); // a Backslash and a double quote |
---|
| 776 | else guide2.append(c); |
---|
| 777 | } |
---|
| 778 | G4cout << " @@param_guide : \"" << guide2 << "\""<<G4endl; |
---|
| 779 | G4cout << " @@param_type : \"" << prp->GetParameterType()<<"\""<<G4endl; |
---|
| 780 | G4cout << " @@param_omit : \"" << prp->IsOmittable()<<"\""<<G4endl; |
---|
| 781 | G4cout << " @@param_default : \""<< prp->GetDefaultValue()<<"\""<<G4endl; |
---|
| 782 | G4cout << " @@param_range : \""<< prp->GetParameterRange()<<"\""<<G4endl; |
---|
| 783 | G4cout << " @@param_candidate : \"" << prp->GetParameterCandidates()<< "\""<<G4endl; |
---|
| 784 | G4cout << "}" << G4endl; |
---|
| 785 | } |
---|
| 786 | G4cout << "@@parameter_end" << G4endl; |
---|
| 787 | } |
---|
| 788 | |
---|
| 789 | void G4UIGAG::NotifyStateChange(void) |
---|
| 790 | { |
---|
| 791 | G4String stateString; |
---|
| 792 | G4StateManager * statM = G4StateManager::GetStateManager(); |
---|
| 793 | G4UIcommandTree * tree = UI->GetTree(); |
---|
| 794 | stateString = statM->GetStateString(statM->GetCurrentState()); |
---|
| 795 | if ( uiMode != terminal_mode ){ |
---|
| 796 | G4cout << "@@State \"" << stateString << "\"" << G4endl; |
---|
| 797 | G4cout << "@@DisableListBegin"<<G4endl; |
---|
| 798 | SendDisableList(tree, 0); |
---|
| 799 | G4cout << "@@DisableListEnd" <<G4endl; |
---|
| 800 | } |
---|
| 801 | } |
---|
| 802 | |
---|
| 803 | void G4UIGAG::NotifyCommandUpdate(void) |
---|
| 804 | { |
---|
| 805 | G4UIcommandTree * tree = UI->GetTree(); |
---|
| 806 | SendCommandProperties(tree); |
---|
| 807 | } |
---|
| 808 | |
---|
| 809 | void G4UIGAG::NotifyParameterUpdate(G4UIcommand* com) |
---|
| 810 | { |
---|
| 811 | if (uiMode == java_mode) |
---|
| 812 | SendAParamProperty(com); |
---|
| 813 | else |
---|
| 814 | SendATclParamProperty(com); |
---|
| 815 | } |
---|
| 816 | |
---|
| 817 | //####### update check routines #################################### |
---|
| 818 | void G4UIGAG::UpdateState(void) |
---|
| 819 | { |
---|
| 820 | static G4ApplicationState previousState= G4State_PreInit; |
---|
| 821 | G4ApplicationState newState; |
---|
| 822 | G4StateManager *statM = G4StateManager::GetStateManager(); |
---|
| 823 | newState = statM->GetCurrentState(); |
---|
| 824 | if( newState != previousState ) |
---|
| 825 | { |
---|
| 826 | NotifyStateChange(); |
---|
| 827 | previousState = newState; |
---|
| 828 | } |
---|
| 829 | } |
---|
| 830 | |
---|
| 831 | int G4UIGAG::CommandUpdated(void) |
---|
| 832 | { |
---|
| 833 | int added=0, deleted=0; |
---|
| 834 | int pEntry= previousTreeCommands.size(); |
---|
| 835 | int nEntry= newTreeCommands.size(); |
---|
| 836 | int i,j; |
---|
| 837 | for( i=0; i<pEntry; i++) { // check deleted command(s) |
---|
| 838 | for( j=0; j<nEntry; j++) { |
---|
| 839 | if( previousTreeCommands[i] == newTreeCommands[j]) break; |
---|
| 840 | } |
---|
| 841 | if( j==nEntry ) { |
---|
| 842 | deleted = 1; |
---|
| 843 | //G4cout <<"deleted: "<< previousTreeCommands(i) << G4endl; |
---|
| 844 | } |
---|
| 845 | } |
---|
| 846 | for( i=0; i<nEntry; i++) { // check added command(s) |
---|
| 847 | for( j=0; j<pEntry; j++) { |
---|
| 848 | if( newTreeCommands[i] == previousTreeCommands[j]) break; |
---|
| 849 | } |
---|
| 850 | if( j==pEntry ) { |
---|
| 851 | added = 1; |
---|
| 852 | // G4cout <<"added: "<< newTreeCommands(i) << G4endl; |
---|
| 853 | } |
---|
| 854 | } |
---|
| 855 | if( added && deleted==0 ) {G4cout<<"c added"<<G4endl;return added;} |
---|
| 856 | if( added==0 && deleted ) {G4cout<<"c deleted"<<G4endl;return deleted;} |
---|
| 857 | if( added && deleted ) {G4cout<<"c add/deleted"<<G4endl;return addedAndDeleted;} |
---|
| 858 | return notChanged; |
---|
| 859 | } |
---|
| 860 | |
---|
| 861 | void G4UIGAG::GetNewTreeStructure(G4UIcommandTree * tree, int level) |
---|
| 862 | { |
---|
| 863 | G4String commandPath; |
---|
| 864 | G4String title; |
---|
| 865 | G4String pathName; //tree name |
---|
| 866 | G4UIcommandTree * t; |
---|
| 867 | int treeEntry = tree->GetTreeEntry(); |
---|
| 868 | int commandEntry = tree->GetCommandEntry(); |
---|
| 869 | |
---|
| 870 | if( level==0 ) { newTreeCommands.clear();} |
---|
| 871 | for(int com=0; com<commandEntry; com++){ |
---|
| 872 | commandPath = tree->GetCommand(com+1)->GetCommandPath(); |
---|
| 873 | title = tree->GetCommand(com+1)->GetTitle(); |
---|
| 874 | newTreeCommands.push_back( commandPath + " " + title ); |
---|
| 875 | } |
---|
| 876 | |
---|
| 877 | if(treeEntry == 0) return; //end recursion |
---|
| 878 | |
---|
| 879 | for(int i=0; i< treeEntry; i++){ |
---|
| 880 | t = tree->GetTree(i+1); |
---|
| 881 | pathName = t->GetPathName(); |
---|
| 882 | title = t->GetTitle(); |
---|
| 883 | newTreeCommands.push_back( pathName + " " + title ); |
---|
| 884 | GetNewTreeStructure(t, level+1); |
---|
| 885 | } |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | void G4UIGAG::UpdateParamVal(void) |
---|
| 889 | { |
---|
| 890 | // call NotifyParameterUpdate() if the value of each |
---|
| 891 | // command/parameter is updated. |
---|
| 892 | // assuming the command structure is not changed. |
---|
| 893 | int pEntry= previousTreeParams.size(); |
---|
| 894 | int nEntry= newTreeParams.size(); |
---|
| 895 | int i; |
---|
| 896 | G4UIcommand* Comp; |
---|
| 897 | if (pEntry != nEntry) return; |
---|
| 898 | for( i=0; i<nEntry; i++) { |
---|
| 899 | if( previousTreeParams[i] != newTreeParams[i]){ |
---|
| 900 | Comp = newTreePCP[i]; |
---|
| 901 | G4cout << Comp->GetCommandPath() |
---|
| 902 | << " command is updated." <<G4endl; |
---|
| 903 | NotifyParameterUpdate(Comp); |
---|
| 904 | } |
---|
| 905 | } |
---|
| 906 | } |
---|
| 907 | |
---|
| 908 | //void G4UIGAG::paramUpdate(void) |
---|
| 909 | //{ |
---|
| 910 | // int added=0, deleted=0; |
---|
| 911 | // int pEntry= previousTreeParams.entries(); |
---|
| 912 | // int nEntry= newTreeParams.entries(); |
---|
| 913 | // int i,j; |
---|
| 914 | // |
---|
| 915 | // if (pEntry != nEntry) return NULL; |
---|
| 916 | // for( i=0; i<pEntry; i++) { // check deleted param(s) |
---|
| 917 | // for( j=0; j<nEntry; j++) { |
---|
| 918 | // if( previousTreeParams(i) == newTreeParams(j)) break; |
---|
| 919 | // } |
---|
| 920 | // if( j==nEntry ) { |
---|
| 921 | // deleted = 1; |
---|
| 922 | // //G4cout <<"para deleted: "<< previousTreeParams(i) << G4endl; |
---|
| 923 | // } |
---|
| 924 | // } |
---|
| 925 | // for( i=0; i<nEntry; i++) { // check added param(s) |
---|
| 926 | // for( j=0; j<pEntry; j++) { |
---|
| 927 | // if( newTreeParams(i) == previousTreeParams(j)) break; |
---|
| 928 | // } |
---|
| 929 | // if( j==pEntry ) { |
---|
| 930 | // added = 1; |
---|
| 931 | // //G4cout <<"para added: "<< newTreeParams(i) << G4endl; |
---|
| 932 | // } |
---|
| 933 | // } |
---|
| 934 | // if( added && deleted==0 ) {G4cout<<"p added"<<G4endl;return added;} |
---|
| 935 | // if( added==0 && deleted ) {G4cout<<"p deleted"<<G4endl;return deleted;} |
---|
| 936 | // if( added && deleted ) {G4cout<<"p add/deleted"<<G4endl; return addedAndDeleted;} |
---|
| 937 | // return notChanged; |
---|
| 938 | //} |
---|
| 939 | |
---|
| 940 | void G4UIGAG::GetNewTreeValues( G4UIcommandTree * tree, int level) // recursive |
---|
| 941 | { |
---|
| 942 | G4String commandPath; |
---|
| 943 | G4String pathName; //tree name |
---|
| 944 | G4UIcommandTree * t; |
---|
| 945 | int parameterEntry; |
---|
| 946 | int treeEntry = tree->GetTreeEntry(); |
---|
| 947 | int commandEntry = tree->GetCommandEntry(); |
---|
| 948 | G4UIcommand * Comp; |
---|
| 949 | G4UIparameter * prp; |
---|
| 950 | G4String param, str(" "); |
---|
| 951 | |
---|
| 952 | if( level==0 ) { newTreeParams.clear(); } |
---|
| 953 | for(int com=0; com<commandEntry; com++) { |
---|
| 954 | Comp = tree->GetCommand(com+1); |
---|
| 955 | commandPath = Comp->GetCommandPath(); |
---|
| 956 | parameterEntry = Comp->GetParameterEntries(); |
---|
| 957 | param = commandPath +" "; |
---|
| 958 | for( int par=0; par< parameterEntry; par++) { |
---|
| 959 | prp = (G4UIparameter *)Comp->GetParameter(par); |
---|
| 960 | param += prp->GetParameterName() +" "; |
---|
| 961 | str(0) = prp->GetParameterType(); |
---|
| 962 | param += str + " "; |
---|
| 963 | param += prp->GetDefaultValue() +" "; |
---|
| 964 | param += prp->GetParameterRange() +" "; |
---|
| 965 | param += prp->GetParameterCandidates(); |
---|
| 966 | } |
---|
| 967 | newTreeParams.push_back( param + "\n"); |
---|
| 968 | newTreePCP.push_back( Comp ); |
---|
| 969 | } |
---|
| 970 | if( treeEntry == 0 ) return; // end recursion |
---|
| 971 | for( int i=0; i< treeEntry; i++) { |
---|
| 972 | t = tree->GetTree(i+1); |
---|
| 973 | GetNewTreeValues(t, level+1); |
---|
| 974 | } |
---|
| 975 | } |
---|
| 976 | //###################################################### |
---|