[1274] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * DISCLAIMER * |
---|
| 4 | // * * |
---|
| 5 | // * The following disclaimer summarizes all the specific disclaimers * |
---|
| 6 | // * of contributors to this software. The specific disclaimers,which * |
---|
| 7 | // * govern, are listed with their locations in: * |
---|
| 8 | // * http://cern.ch/geant4/license * |
---|
| 9 | // * * |
---|
| 10 | // * Neither the authors of this software system, nor their employing * |
---|
| 11 | // * institutes,nor the agencies providing financial support for this * |
---|
| 12 | // * work make any representation or warranty, express or implied, * |
---|
| 13 | // * regarding this software system or assume any liability for its * |
---|
| 14 | // * use. * |
---|
| 15 | // * * |
---|
| 16 | // * This code implementation is the intellectual property of the * |
---|
| 17 | // * GEANT4 collaboration. * |
---|
| 18 | // * By copying, distributing or modifying the Program (or any work * |
---|
| 19 | // * based on the Program) you indicate your acceptance of this * |
---|
| 20 | // * statement, and all its terms. * |
---|
| 21 | // ******************************************************************** |
---|
| 22 | // |
---|
| 23 | // |
---|
| 24 | // $Id: G4UIxvt.cc,v 1.5 2002/12/04 22:03:09 asaim Exp $ |
---|
| 25 | // GEANT4 tag $Name: $ |
---|
| 26 | // |
---|
| 27 | #ifdef G4UI_BUILD_XVT_SESSION |
---|
| 28 | |
---|
| 29 | //////////////////////////////////////////////////////////////////////////// |
---|
| 30 | // XVT driver class implementation |
---|
| 31 | // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
---|
| 32 | // Written by: Simon Prior |
---|
| 33 | // Date: 23/04/97 |
---|
| 34 | // |
---|
| 35 | // Updated for state machine: 12/08/97 |
---|
| 36 | // |
---|
| 37 | // The update consisted of adding the new state methods and I also deleted |
---|
| 38 | // a lot of old redundant code (like ChangeDirectory etc which aren't |
---|
| 39 | // needed with the XVT GUI). |
---|
| 40 | // |
---|
| 41 | //////////////////////////////////////////////////////////////////////////// |
---|
| 42 | #include "G4UIxvt.hh" |
---|
| 43 | #include "G4StateManager.hh" |
---|
| 44 | #include "G4UIxvtMessenger.hh" |
---|
| 45 | |
---|
| 46 | //////////////////////////////////////////////////////////////////////////// |
---|
| 47 | // |
---|
| 48 | // G4UIxvt - Consructor |
---|
| 49 | // |
---|
| 50 | // Initalise the class variables. |
---|
| 51 | // |
---|
| 52 | // Note: number is the number of bytes transfered with each read or write. |
---|
| 53 | // |
---|
| 54 | //////////////////////////////////////////////////////////////////////////// |
---|
| 55 | G4UIxvt::G4UIxvt() |
---|
| 56 | { |
---|
| 57 | UI = G4UImanager::GetUIpointer(); |
---|
| 58 | |
---|
| 59 | iExit = false; |
---|
| 60 | iCont = false; |
---|
| 61 | |
---|
| 62 | for(int i=0;i<4;i++) |
---|
| 63 | { |
---|
| 64 | brktbl[i] = false; |
---|
| 65 | } |
---|
| 66 | |
---|
| 67 | noBreakFlag = true; |
---|
| 68 | verboseFlag = true; |
---|
| 69 | new G4UIxvtMessenger(this); |
---|
| 70 | |
---|
| 71 | number = 100; |
---|
| 72 | currentPosition = 0; |
---|
| 73 | lastPosition = 100; |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
| 77 | //////////////////////////////////////////////////////////////////////////// |
---|
| 78 | // |
---|
| 79 | // ~G4UIxvt - Destructor |
---|
| 80 | // |
---|
| 81 | //////////////////////////////////////////////////////////////////////////// |
---|
| 82 | G4UIxvt::~G4UIxvt() |
---|
| 83 | { |
---|
| 84 | |
---|
| 85 | } |
---|
| 86 | |
---|
| 87 | //////////////////////////////////////////////////////////////////////////// |
---|
| 88 | // |
---|
| 89 | // Notify |
---|
| 90 | // |
---|
| 91 | // Notifies the user of the state changes of the system. |
---|
| 92 | // |
---|
| 93 | //////////////////////////////////////////////////////////////////////////// |
---|
| 94 | //G4bool G4UIxvt::Notify(G4ApplicationState requestedState) |
---|
| 95 | //{ |
---|
| 96 | // G4StateManager * statM = G4StateManager::GetStateManager(); |
---|
| 97 | // G4ApplicationState previousState = statM->GetPreviousState(); |
---|
| 98 | // |
---|
| 99 | // if(verboseFlag) |
---|
| 100 | // { |
---|
| 101 | // writeGeantToXvt("========== STATE CHANGE ==========="); |
---|
| 102 | // writeGeantToXvt("FROM: " + statM->GetStateString(previousState)); |
---|
| 103 | // writeGeantToXvt(" TO: " + statM->GetStateString(requestedState)); |
---|
| 104 | // writeGeantToXvt("==================================="); |
---|
| 105 | // } |
---|
| 106 | // |
---|
| 107 | // if(requestedState==Pause || breakRequested(previousState,requestedState)) |
---|
| 108 | // { |
---|
| 109 | // additionalSession(); |
---|
| 110 | // } |
---|
| 111 | // |
---|
| 112 | // return true; |
---|
| 113 | //} |
---|
| 114 | |
---|
| 115 | //////////////////////////////////////////////////////////////////////////// |
---|
| 116 | // |
---|
| 117 | // breakRequested |
---|
| 118 | // |
---|
| 119 | // Notifies and puts breaks in the Geant4 run. |
---|
| 120 | // |
---|
| 121 | //////////////////////////////////////////////////////////////////////////// |
---|
| 122 | G4bool G4UIxvt::breakRequested(G4ApplicationState previousState, |
---|
| 123 | G4ApplicationState requestedState) |
---|
| 124 | { |
---|
| 125 | if(noBreakFlag) return false; |
---|
| 126 | |
---|
| 127 | G4bool ans = false; |
---|
| 128 | |
---|
| 129 | if(previousState==G4State_Idle && requestedState==G4State_GeomClosed && brktbl[0]) |
---|
| 130 | { |
---|
| 131 | writeGeantToXvt("====== BREAKPOINT NOTIFICATION ======"); |
---|
| 132 | writeGeantToXvt("BreakPoint at: BEGIN OF RUN"); |
---|
| 133 | writeGeantToXvt("Enter 'continue' command to proceed"); |
---|
| 134 | writeGeantToXvt("====================================="); |
---|
| 135 | |
---|
| 136 | ans = true; |
---|
| 137 | } |
---|
| 138 | |
---|
| 139 | if(previousState==G4State_GeomClosed && requestedState==G4State_EventProc && brktbl[1]) |
---|
| 140 | { |
---|
| 141 | writeGeantToXvt("====== BREAKPOINT NOTIFICATION ======"); |
---|
| 142 | writeGeantToXvt("BreakPoint at: BEGIN OF EVENT"); |
---|
| 143 | writeGeantToXvt("Enter 'continue' command to proceed"); |
---|
| 144 | writeGeantToXvt("====================================="); |
---|
| 145 | |
---|
| 146 | ans = true; |
---|
| 147 | } |
---|
| 148 | |
---|
| 149 | if(previousState==G4State_EventProc && requestedState==G4State_GeomClosed && brktbl[2]) |
---|
| 150 | { |
---|
| 151 | writeGeantToXvt("====== BREAKPOINT NOTIFICATION ======"); |
---|
| 152 | writeGeantToXvt("BreakPoint at: END OF EVENT"); |
---|
| 153 | writeGeantToXvt("Enter 'continue' command to proceed"); |
---|
| 154 | writeGeantToXvt("====================================="); |
---|
| 155 | |
---|
| 156 | ans = true; |
---|
| 157 | } |
---|
| 158 | |
---|
| 159 | if(previousState==G4State_GeomClosed && requestedState==G4State_Idle && brktbl[3]) |
---|
| 160 | { |
---|
| 161 | writeGeantToXvt("====== BREAKPOINT NOTIFICATION ======"); |
---|
| 162 | writeGeantToXvt("BreakPoint at: END OF RUN"); |
---|
| 163 | writeGeantToXvt("Enter 'continue' command to proceed"); |
---|
| 164 | writeGeantToXvt("====================================="); |
---|
| 165 | |
---|
| 166 | ans = true; |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | return ans; |
---|
| 170 | } |
---|
| 171 | |
---|
| 172 | //////////////////////////////////////////////////////////////////////////// |
---|
| 173 | // |
---|
| 174 | // set_verbose |
---|
| 175 | // |
---|
| 176 | // Toggles the Verbose state of the GUI concerning the state machine. |
---|
| 177 | // |
---|
| 178 | //////////////////////////////////////////////////////////////////////////// |
---|
| 179 | void G4UIxvt::set_verbose(void) |
---|
| 180 | { |
---|
| 181 | verboseFlag = !verboseFlag; |
---|
| 182 | |
---|
| 183 | if (verboseFlag) |
---|
| 184 | { |
---|
| 185 | writeGeantToXvt("Verbose mode switched ON"); |
---|
| 186 | } |
---|
| 187 | else |
---|
| 188 | { |
---|
| 189 | writeGeantToXvt("Verbose mode switched OFF"); |
---|
| 190 | } |
---|
| 191 | } |
---|
| 192 | |
---|
| 193 | |
---|
| 194 | //////////////////////////////////////////////////////////////////////////// |
---|
| 195 | // |
---|
| 196 | // SessionStart |
---|
| 197 | // |
---|
| 198 | // Informs user of Geant Kernel starting and does a 'brief' command listing. |
---|
| 199 | // Update: 12/08/97 - now used as main control of Geant (get command is |
---|
| 200 | // currently called from here NOT from the UIManager. |
---|
| 201 | // |
---|
| 202 | //////////////////////////////////////////////////////////////////////////// |
---|
| 203 | //void G4UIxvt::SessionStart(void) |
---|
| 204 | G4UIsession* G4UIxvt::SessionStart(void) |
---|
| 205 | { |
---|
| 206 | openConnections(); |
---|
| 207 | writeGeantToXvt("Connection to Geant open...\0"); |
---|
| 208 | |
---|
| 209 | G4UImanager * UI = G4UImanager::GetUIpointer(); |
---|
| 210 | G4UIcommandTree * comTree = UI->GetTree(); |
---|
| 211 | |
---|
| 212 | fillArrayEntries(comTree, 0); |
---|
| 213 | |
---|
| 214 | G4cout << " --------- List of Array Entries ---------- " << G4endl; |
---|
| 215 | |
---|
| 216 | listCommandArray(); |
---|
| 217 | briefListCommands(); |
---|
| 218 | |
---|
| 219 | // --- Enter main program control --- // |
---|
| 220 | |
---|
| 221 | iExit = true; |
---|
| 222 | |
---|
| 223 | while( iExit ) |
---|
| 224 | { |
---|
| 225 | G4String newCommand = GetCommand(); |
---|
| 226 | if(newCommand.length()>1) UI->ApplyCommand(newCommand); |
---|
| 227 | } |
---|
| 228 | return NULL; |
---|
| 229 | } |
---|
| 230 | |
---|
| 231 | |
---|
| 232 | //////////////////////////////////////////////////////////////////////////// |
---|
| 233 | // |
---|
| 234 | // additionalSession |
---|
| 235 | // |
---|
| 236 | // |
---|
| 237 | // |
---|
| 238 | //////////////////////////////////////////////////////////////////////////// |
---|
| 239 | void G4UIxvt::additionalSession(void) |
---|
| 240 | { |
---|
| 241 | writeGeantToXvt("=== Entering Addtional Session ==="); |
---|
| 242 | iCont = true; |
---|
| 243 | while( iCont ) |
---|
| 244 | { |
---|
| 245 | G4String newCommand = GetCommand(); |
---|
| 246 | if(newCommand.length()>1) UI->ApplyCommand(newCommand); |
---|
| 247 | } |
---|
| 248 | } |
---|
| 249 | |
---|
| 250 | |
---|
| 251 | //////////////////////////////////////////////////////////////////////////// |
---|
| 252 | // |
---|
| 253 | // SessionTerminate |
---|
| 254 | // |
---|
| 255 | // Informs user that Geant has terminated. |
---|
| 256 | // |
---|
| 257 | //////////////////////////////////////////////////////////////////////////// |
---|
| 258 | void G4UIxvt::SessionTerminate(void) |
---|
| 259 | { |
---|
| 260 | writeGeantToXvt("XVT <-> Geant4 terminating..."); |
---|
| 261 | } |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | //////////////////////////////////////////////////////////////////////////// |
---|
| 265 | // |
---|
| 266 | // openConnections |
---|
| 267 | // |
---|
| 268 | // This method opens the IPC connection. |
---|
| 269 | // |
---|
| 270 | // Open the named pipes in the current directory using the |
---|
| 271 | // appropriate permissions. |
---|
| 272 | // |
---|
| 273 | //////////////////////////////////////////////////////////////////////////// |
---|
| 274 | void G4UIxvt::openConnections(void) |
---|
| 275 | { |
---|
| 276 | int o_flags; |
---|
| 277 | |
---|
| 278 | o_flags = O_WRONLY | O_NONBLOCK; |
---|
| 279 | |
---|
| 280 | if((fd_GeantToXvt = open(GeantToXvt, o_flags)) == -1) |
---|
| 281 | { |
---|
| 282 | errorHandler("GeantToXvt pipe opening"); |
---|
| 283 | } |
---|
| 284 | |
---|
| 285 | o_flags = O_RDONLY | O_NONBLOCK; |
---|
| 286 | |
---|
| 287 | if((fd_XvtToGeant = open(XvtToGeant, o_flags)) == -1) |
---|
| 288 | { |
---|
| 289 | errorHandler("XvtToGeant pipe opening"); |
---|
| 290 | } |
---|
| 291 | } |
---|
| 292 | |
---|
| 293 | |
---|
| 294 | //////////////////////////////////////////////////////////////////////////// |
---|
| 295 | // |
---|
| 296 | // checkXvtToGeantPipe |
---|
| 297 | // |
---|
| 298 | // This method checks to see if the XvtToGeant pipe contains anything. |
---|
| 299 | // Thus meaning it will be readable without blocking. |
---|
| 300 | // |
---|
| 301 | // Returns 0 if nothing present, 1 otherwise. |
---|
| 302 | // |
---|
| 303 | //////////////////////////////////////////////////////////////////////////// |
---|
| 304 | int G4UIxvt::checkXvtToGeantPipe(void) |
---|
| 305 | { |
---|
| 306 | int nbytes; |
---|
| 307 | ioctl(fd_XvtToGeant, FIONREAD, &nbytes); |
---|
| 308 | |
---|
| 309 | if (nbytes > 0) |
---|
| 310 | return 1; |
---|
| 311 | else |
---|
| 312 | return 0; |
---|
| 313 | } |
---|
| 314 | |
---|
| 315 | |
---|
| 316 | //////////////////////////////////////////////////////////////////////////// |
---|
| 317 | // |
---|
| 318 | // readXvtToGeant |
---|
| 319 | // |
---|
| 320 | // This method grabs the data in the XvtToGeant named pipe, and |
---|
| 321 | // returns it to the caller. |
---|
| 322 | // |
---|
| 323 | //////////////////////////////////////////////////////////////////////////// |
---|
| 324 | G4String G4UIxvt::readXvtToGeant(void) |
---|
| 325 | { |
---|
| 326 | int bytes_read = read(fd_XvtToGeant, textDump, number); |
---|
| 327 | textDump[bytes_read] = '\0'; |
---|
| 328 | G4String newString = textDump; |
---|
| 329 | return newString; |
---|
| 330 | } |
---|
| 331 | |
---|
| 332 | |
---|
| 333 | //////////////////////////////////////////////////////////////////////////// |
---|
| 334 | // |
---|
| 335 | // writeGeantToXvt |
---|
| 336 | // |
---|
| 337 | // This method writes the passed string to the GeantToXvt named pipe. |
---|
| 338 | // |
---|
| 339 | //////////////////////////////////////////////////////////////////////////// |
---|
| 340 | void G4UIxvt::writeGeantToXvt(const G4String& theString) |
---|
| 341 | { |
---|
| 342 | int write_check = write(fd_GeantToXvt, theString, number); |
---|
| 343 | |
---|
| 344 | if(write_check == -1) |
---|
| 345 | G4cout << "ERROR WITH WRITE!!" << G4endl; |
---|
| 346 | } |
---|
| 347 | |
---|
| 348 | |
---|
| 349 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 350 | // |
---|
| 351 | // errorHandler |
---|
| 352 | // |
---|
| 353 | // A general purpose error handler. It can be called by any method. A string |
---|
| 354 | // is passed so that this method simply prints a message via G4cout that explains |
---|
| 355 | // what the error is. |
---|
| 356 | // |
---|
| 357 | /////////////////////////////////////////////////////////////////////////////// |
---|
| 358 | void G4UIxvt::errorHandler(const G4String& theError) |
---|
| 359 | { |
---|
| 360 | G4cout << "Error with " << theError << G4endl; |
---|
| 361 | } |
---|
| 362 | |
---|
| 363 | |
---|
| 364 | //////////////////////////////////////////////////////////////////////////// |
---|
| 365 | // |
---|
| 366 | // GetCommand |
---|
| 367 | // |
---|
| 368 | // This method is called by SessionStart to get a command from the user. |
---|
| 369 | // |
---|
| 370 | // It enters a loop to repeatedly check the Geant end of the named pipe. |
---|
| 371 | // When something is present in the pipe (sent by XVT GUI) it then grabs it |
---|
| 372 | // and returns the string to the caller. |
---|
| 373 | // |
---|
| 374 | //////////////////////////////////////////////////////////////////////////// |
---|
| 375 | G4String G4UIxvt::GetCommand() |
---|
| 376 | { |
---|
| 377 | G4String newCommand('\0'); |
---|
| 378 | G4UImanager * UI = G4UImanager::GetUIpointer(); |
---|
| 379 | while( 1 ) |
---|
| 380 | { |
---|
| 381 | int Done = 0; |
---|
| 382 | |
---|
| 383 | while (!Done) |
---|
| 384 | { |
---|
| 385 | if (checkXvtToGeantPipe()) |
---|
| 386 | { |
---|
| 387 | newCommand = readXvtToGeant(); |
---|
| 388 | Done = 1; |
---|
| 389 | } |
---|
| 390 | else |
---|
| 391 | ; // Pipe is empty so loop again |
---|
| 392 | } |
---|
| 393 | |
---|
| 394 | G4String nC = newCommand; |
---|
| 395 | |
---|
| 396 | if(nC == "getCommands") |
---|
| 397 | { |
---|
| 398 | sendArrayEntriesToXvt(); |
---|
| 399 | } |
---|
| 400 | else if( nC == "/control/exit" ) |
---|
| 401 | { |
---|
| 402 | if( iCont ) |
---|
| 403 | { |
---|
| 404 | writeGeantToXvt("You are now processing RUN."); |
---|
| 405 | writeGeantToXvt("Please abort it using \"/run/abort\" command first"); |
---|
| 406 | writeGeantToXvt("and use \"continue\" command until the application"); |
---|
| 407 | writeGeantToXvt("becomes Idle."); |
---|
| 408 | } |
---|
| 409 | else |
---|
| 410 | { |
---|
| 411 | iExit = false; |
---|
| 412 | newCommand = "/"; |
---|
| 413 | break; |
---|
| 414 | } |
---|
| 415 | } |
---|
| 416 | else if( nC(0,4) == "cont" ) |
---|
| 417 | { |
---|
| 418 | iCont = false; |
---|
| 419 | newCommand = "/"; |
---|
| 420 | break; |
---|
| 421 | } |
---|
| 422 | else |
---|
| 423 | { |
---|
| 424 | break; |
---|
| 425 | } |
---|
| 426 | } |
---|
| 427 | |
---|
| 428 | if( newCommand(0) != '/' ) |
---|
| 429 | G4cerr << "IT GOT THERE!!!!" << G4endl; |
---|
| 430 | // If you ever see the error message in the output something has gone |
---|
| 431 | // wrong. |
---|
| 432 | |
---|
| 433 | return newCommand; |
---|
| 434 | |
---|
| 435 | } |
---|
| 436 | |
---|
| 437 | |
---|
| 438 | //////////////////////////////////////////////////////////////////////////// |
---|
| 439 | // |
---|
| 440 | // codeGen |
---|
| 441 | // |
---|
| 442 | // Traverses the command tree and retrieves the directories and |
---|
| 443 | // subdirectories of available commands. |
---|
| 444 | // |
---|
| 445 | // This does a 'brief' listing, i.e. does not List the guidance or |
---|
| 446 | // parameters. |
---|
| 447 | // |
---|
| 448 | // I have updated this method from the TCL implementation for XVT. |
---|
| 449 | // The differences are that G4cout is not used and some string concatenation |
---|
| 450 | // is Done differently (i.e. not with G4cout). |
---|
| 451 | // |
---|
| 452 | // This is still however not really needed and might be deleted. |
---|
| 453 | // |
---|
| 454 | //////////////////////////////////////////////////////////////////////////// |
---|
| 455 | void G4UIxvt::codeGen(G4UIcommandTree * tree, int level) |
---|
| 456 | { |
---|
| 457 | int treeEntry; |
---|
| 458 | int commandEntry; |
---|
| 459 | treeEntry = tree->GetTreeEntry(); |
---|
| 460 | commandEntry = tree->GetCommandEntry(); |
---|
| 461 | G4String commandPath; |
---|
| 462 | G4String pathName; //tree name |
---|
| 463 | G4UIcommandTree * t; |
---|
| 464 | |
---|
| 465 | // --- this loop lists the current directory and its commands --- // |
---|
| 466 | |
---|
| 467 | for(int com=0; com<commandEntry; com++) |
---|
| 468 | { |
---|
| 469 | commandPath = tree->GetCommand(com+1)->GetCommandPath(); |
---|
| 470 | if(level==0) |
---|
| 471 | { |
---|
| 472 | // This is not normally executed |
---|
| 473 | writeGeantToXvt(commandPath); // Unsure as to what this does |
---|
| 474 | } |
---|
| 475 | else |
---|
| 476 | { |
---|
| 477 | writeGeantToXvt(commandPath + " command"); // this gives the commands |
---|
| 478 | } |
---|
| 479 | } |
---|
| 480 | |
---|
| 481 | if(treeEntry == 0) |
---|
| 482 | return; //end recursion |
---|
| 483 | |
---|
| 484 | for(int i=0; i< treeEntry; i++) |
---|
| 485 | { |
---|
| 486 | t = tree->GetTree(i+1); |
---|
| 487 | pathName = t->GetPathName(); |
---|
| 488 | if(level == 0) |
---|
| 489 | { |
---|
| 490 | writeGeantToXvt(pathName); // This is the directory name |
---|
| 491 | } |
---|
| 492 | else |
---|
| 493 | { |
---|
| 494 | writeGeantToXvt(pathName + " cascade"); // This is the sub dirs |
---|
| 495 | } |
---|
| 496 | |
---|
| 497 | codeGen(t, level+1); |
---|
| 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | |
---|
| 502 | //////////////////////////////////////////////////////////////////////////// |
---|
| 503 | // |
---|
| 504 | // briefListCommands |
---|
| 505 | // |
---|
| 506 | // This method uses codeGen to traverse the tree and List the commands |
---|
| 507 | // and directories - it does a brief listing, i.e. no parameters or guidance |
---|
| 508 | // accompanying the text. |
---|
| 509 | // |
---|
| 510 | //////////////////////////////////////////////////////////////////////////// |
---|
| 511 | void G4UIxvt::briefListCommands(void) |
---|
| 512 | { |
---|
| 513 | writeGeantToXvt("--- Brief List of available commands ---"); |
---|
| 514 | G4UIcommandTree * comTree = UI->GetTree(); |
---|
| 515 | codeGen(comTree, 0); |
---|
| 516 | } |
---|
| 517 | |
---|
| 518 | |
---|
| 519 | //////////////////////////////////////////////////////////////////////////// |
---|
| 520 | // |
---|
| 521 | // ListCurrentDirectory |
---|
| 522 | // |
---|
| 523 | // This is the XVT specific implementation of the 'List Current' method |
---|
| 524 | // from the G4UICommandTree class. |
---|
| 525 | // |
---|
| 526 | // It is almost the same only instead of any couts all the data is written |
---|
| 527 | // to the named pipe for XVT to process. |
---|
| 528 | // |
---|
| 529 | // Although this is entirely XVT specific it may be deleted because it is |
---|
| 530 | // not really needed. (most directory navigation methods that were so |
---|
| 531 | // important in the terminal session aren't needed in this XVT GUI |
---|
| 532 | // implementation.) |
---|
| 533 | // |
---|
| 534 | // I have left it here in case similar code is needed in the future - this |
---|
| 535 | // demonstrates how to access the command tree etc. |
---|
| 536 | // |
---|
| 537 | //////////////////////////////////////////////////////////////////////////// |
---|
| 538 | void G4UIxvt::listCurrentDirectory(void) |
---|
| 539 | { |
---|
| 540 | G4UIcommandTree * comTree = UI->GetTree(); |
---|
| 541 | G4String path = comTree->GetPathName(); |
---|
| 542 | |
---|
| 543 | writeGeantToXvt("Command Directory Path: " + path); |
---|
| 544 | |
---|
| 545 | // --- Guidance code --- // |
---|
| 546 | |
---|
| 547 | G4UIcommand * tempGuidance = (G4UIcommand *)comTree->GetGuidance(); |
---|
| 548 | |
---|
| 549 | if (tempGuidance != NULL) |
---|
| 550 | { |
---|
| 551 | writeGeantToXvt("Command: " + tempGuidance->GetCommandPath()); |
---|
| 552 | writeGeantToXvt("Guidance: "); |
---|
| 553 | |
---|
| 554 | int n_guidanceEntry = tempGuidance->GetGuidanceEntries(); |
---|
| 555 | |
---|
| 556 | for (int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) |
---|
| 557 | { |
---|
| 558 | writeGeantToXvt(tempGuidance->GetGuidanceLine(i_thGuidance)); |
---|
| 559 | } |
---|
| 560 | |
---|
| 561 | int n_parameterEntry = tempGuidance->GetParameterEntries(); |
---|
| 562 | |
---|
| 563 | if(n_parameterEntry > 0) |
---|
| 564 | { |
---|
| 565 | for( int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) |
---|
| 566 | { |
---|
| 567 | G4UIparameter * tempParameter = (G4UIparameter *)tempGuidance->GetParameter(i_thParameter); |
---|
| 568 | |
---|
| 569 | writeGeantToXvt("Parameter: " + tempParameter->GetParameterName()); |
---|
| 570 | writeGeantToXvt(tempParameter->GetParameterGuidance()); |
---|
| 571 | writeGeantToXvt("Parameter type: " + tempParameter->GetParameterType()); |
---|
| 572 | |
---|
| 573 | // --- remember to fix the below bug --- // |
---|
| 574 | |
---|
| 575 | // writeGeantToXvt("Omittable: " + tempParameter->IsOmittable()); |
---|
| 576 | |
---|
| 577 | writeGeantToXvt("Default Value: " + tempParameter->GetDefaultValue()); |
---|
| 578 | writeGeantToXvt("Parameter Range: " + tempParameter->GetParameterRange()); |
---|
| 579 | } |
---|
| 580 | } |
---|
| 581 | } |
---|
| 582 | |
---|
| 583 | // --- End of Guidance code --- // |
---|
| 584 | |
---|
| 585 | writeGeantToXvt("Sub Directories: "); |
---|
| 586 | |
---|
| 587 | int n_treeEntry = comTree->GetTreeEntry(); |
---|
| 588 | |
---|
| 589 | for( int i_thTree = 0; i_thTree < n_treeEntry; i_thTree++ ) |
---|
| 590 | { |
---|
| 591 | G4UIcommandTree * tempTree = comTree->GetTree(i_thTree + 1); |
---|
| 592 | writeGeantToXvt(tempTree->GetPathName() + tempTree->GetTitle()); |
---|
| 593 | } |
---|
| 594 | |
---|
| 595 | writeGeantToXvt("Commands : "); |
---|
| 596 | |
---|
| 597 | int n_commandEntry = comTree->GetCommandEntry(); |
---|
| 598 | |
---|
| 599 | for( int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ ) |
---|
| 600 | { |
---|
| 601 | G4UIcommand * tempCommand = comTree->GetCommand(i_thCommand + 1); |
---|
| 602 | writeGeantToXvt(tempCommand->GetCommandName() + tempCommand->GetTitle()); |
---|
| 603 | } |
---|
| 604 | } |
---|
| 605 | |
---|
| 606 | //////////////////////////////////////////////////////////////////////////// |
---|
| 607 | // Methods for handling the command information // |
---|
| 608 | //////////////////////////////////////////////////////////////////////////// |
---|
| 609 | |
---|
| 610 | //////////////////////////////////////////////////////////////////////////// |
---|
| 611 | // |
---|
| 612 | // sendArrayEntriesToXvt |
---|
| 613 | // |
---|
| 614 | // This goes through the commandArray when called and sends all the command |
---|
| 615 | // information down the named pipe to XVT. |
---|
| 616 | // |
---|
| 617 | // It must first send the control command 'comTree' to alert XVT of the |
---|
| 618 | // following commands - XVT can then take action to fill its own 'commandArray' |
---|
| 619 | // with the ensuing strings passed to it. |
---|
| 620 | // |
---|
| 621 | //////////////////////////////////////////////////////////////////////////// |
---|
| 622 | void G4UIxvt::sendArrayEntriesToXvt(void) |
---|
| 623 | { |
---|
| 624 | writeGeantToXvt("comTree"); |
---|
| 625 | |
---|
| 626 | char theInt[5]; |
---|
| 627 | sprintf(theInt, "%d", currentPosition); |
---|
| 628 | |
---|
| 629 | writeGeantToXvt(theInt); |
---|
| 630 | |
---|
| 631 | // --- Output all the Data from the array to the named pipe --- // |
---|
| 632 | |
---|
| 633 | for (int i = 0; i < currentPosition; i++) |
---|
| 634 | { |
---|
| 635 | // --- Send flag to XVT --- // |
---|
| 636 | sprintf(theInt, "%d",commandArray[i].flag); |
---|
| 637 | writeGeantToXvt(theInt); |
---|
| 638 | |
---|
| 639 | // --- Send name and guidance --- // |
---|
| 640 | writeGeantToXvt(commandArray[i].name); |
---|
| 641 | writeGeantToXvt(commandArray[i].guidance); |
---|
| 642 | |
---|
| 643 | // --- Send number of parameters --- // |
---|
| 644 | sprintf(theInt, "%d", commandArray[i].numOfParameters); |
---|
| 645 | writeGeantToXvt(theInt); |
---|
| 646 | |
---|
| 647 | // --- if there are parameters send them next --- // |
---|
| 648 | if (commandArray[i].numOfParameters > 0) |
---|
| 649 | { |
---|
| 650 | for(int x = 0; x < commandArray[i].numOfParameters; x++) |
---|
| 651 | { |
---|
| 652 | writeGeantToXvt(commandArray[i].parameters[x].name); |
---|
| 653 | writeGeantToXvt(commandArray[i].parameters[x].guidance); |
---|
| 654 | writeGeantToXvt(commandArray[i].parameters[x].defaultValue); |
---|
| 655 | writeGeantToXvt(commandArray[i].parameters[x].range); |
---|
| 656 | writeGeantToXvt(commandArray[i].parameters[x].candidate); |
---|
| 657 | writeGeantToXvt(commandArray[i].parameters[x].type); |
---|
| 658 | writeGeantToXvt(commandArray[i].parameters[x].omittable); |
---|
| 659 | } |
---|
| 660 | } |
---|
| 661 | |
---|
| 662 | // --- Send number --- // |
---|
| 663 | sprintf(theInt, "%d", commandArray[i].commandNumber); |
---|
| 664 | writeGeantToXvt(theInt); |
---|
| 665 | } |
---|
| 666 | } |
---|
| 667 | |
---|
| 668 | |
---|
| 669 | //////////////////////////////////////////////////////////////////////////// |
---|
| 670 | // |
---|
| 671 | // fillArrayEntries |
---|
| 672 | // |
---|
| 673 | // This traverses the command tree and fills in the command structures in |
---|
| 674 | // the class variable 'commandArray'. |
---|
| 675 | // |
---|
| 676 | // Note: for flag value: |
---|
| 677 | // |
---|
| 678 | // 0 = Directory |
---|
| 679 | // 1 = command |
---|
| 680 | // 2 = subdirectory |
---|
| 681 | // |
---|
| 682 | //////////////////////////////////////////////////////////////////////////// |
---|
| 683 | void G4UIxvt::fillArrayEntries(G4UIcommandTree * tree, int level) |
---|
| 684 | { |
---|
| 685 | int treeEntry; |
---|
| 686 | int commandEntry; |
---|
| 687 | |
---|
| 688 | treeEntry = tree->GetTreeEntry(); |
---|
| 689 | commandEntry = tree->GetCommandEntry(); |
---|
| 690 | |
---|
| 691 | G4String commandPath; |
---|
| 692 | G4String pathName; //tree name |
---|
| 693 | G4UIcommandTree * t; |
---|
| 694 | |
---|
| 695 | // New variables |
---|
| 696 | G4UIcommand * tempCommand; |
---|
| 697 | G4UIparameter * tempParameter; |
---|
| 698 | |
---|
| 699 | // --- this loop lists the current directory and its commands --- // |
---|
| 700 | |
---|
| 701 | for(int com=0; com<commandEntry; com++) |
---|
| 702 | { |
---|
| 703 | tempCommand = (G4UIcommand *)tree->GetCommand(com+1); |
---|
| 704 | |
---|
| 705 | commandPath = tree->GetCommand(com+1)->GetCommandPath(); |
---|
| 706 | if(level==0) |
---|
| 707 | { |
---|
| 708 | // --- This code shouldn't ever get executed --- // |
---|
| 709 | G4cout << "Printing command Path" << commandPath << G4endl; |
---|
| 710 | } |
---|
| 711 | else |
---|
| 712 | { |
---|
| 713 | commandArray[currentPosition].flag = 1; |
---|
| 714 | commandArray[currentPosition].name = commandPath; |
---|
| 715 | commandArray[currentPosition].guidance = tempCommand->GetTitle(); |
---|
| 716 | commandArray[currentPosition].numOfParameters = tempCommand->GetParameterEntries(); |
---|
| 717 | |
---|
| 718 | int numParam = tempCommand->GetParameterEntries(); |
---|
| 719 | |
---|
| 720 | if(numParam != 0) |
---|
| 721 | { |
---|
| 722 | for(int x = 0; x < numParam; x++) |
---|
| 723 | { |
---|
| 724 | tempParameter = (G4UIparameter*)tempCommand->GetParameter(x); |
---|
| 725 | |
---|
| 726 | commandArray[currentPosition].parameters[x].name = tempParameter->GetParameterName(); |
---|
| 727 | commandArray[currentPosition].parameters[x].guidance = tempParameter->GetParameterGuidance(); |
---|
| 728 | commandArray[currentPosition].parameters[x].defaultValue = tempParameter->GetDefaultValue(); |
---|
| 729 | commandArray[currentPosition].parameters[x].range = tempParameter->GetParameterRange(); |
---|
| 730 | commandArray[currentPosition].parameters[x].candidate = tempParameter->GetParameterCandidate(); |
---|
| 731 | commandArray[currentPosition].parameters[x].type = tempParameter->GetParameterType(); |
---|
| 732 | // commandArray[currentPosition].parameters[x].omittable = tempParameter->IsOmittable(); |
---|
| 733 | } |
---|
| 734 | } |
---|
| 735 | |
---|
| 736 | commandArray[currentPosition].commandNumber = currentPosition; |
---|
| 737 | |
---|
| 738 | currentPosition = currentPosition + 1; |
---|
| 739 | } |
---|
| 740 | } |
---|
| 741 | |
---|
| 742 | if(treeEntry == 0) |
---|
| 743 | return; //end recursion |
---|
| 744 | |
---|
| 745 | G4UIcommand * treeGuidance; |
---|
| 746 | |
---|
| 747 | for(int i=0; i< treeEntry; i++) |
---|
| 748 | { |
---|
| 749 | t = tree->GetTree(i+1); |
---|
| 750 | pathName = t->GetPathName(); |
---|
| 751 | |
---|
| 752 | treeGuidance = (G4UIcommand *)t->GetGuidance(); |
---|
| 753 | |
---|
| 754 | if(level == 0) |
---|
| 755 | { |
---|
| 756 | commandArray[currentPosition].flag = 0; |
---|
| 757 | commandArray[currentPosition].name = pathName; |
---|
| 758 | commandArray[currentPosition].guidance = treeGuidance->GetTitle(); |
---|
| 759 | commandArray[currentPosition].numOfParameters = 0; |
---|
| 760 | commandArray[currentPosition].commandNumber = currentPosition; |
---|
| 761 | |
---|
| 762 | currentPosition = currentPosition + 1; |
---|
| 763 | } |
---|
| 764 | else |
---|
| 765 | { |
---|
| 766 | commandArray[currentPosition].flag = 2; |
---|
| 767 | commandArray[currentPosition].name = pathName; |
---|
| 768 | commandArray[currentPosition].guidance = treeGuidance->GetTitle(); |
---|
| 769 | commandArray[currentPosition].numOfParameters = 0; |
---|
| 770 | commandArray[currentPosition].commandNumber = currentPosition; |
---|
| 771 | |
---|
| 772 | currentPosition = currentPosition + 1; |
---|
| 773 | } |
---|
| 774 | |
---|
| 775 | fillArrayEntries(t, level+1); |
---|
| 776 | } |
---|
| 777 | } |
---|
| 778 | |
---|
| 779 | |
---|
| 780 | //////////////////////////////////////////////////////////////////////////// |
---|
| 781 | // A debugging routine // |
---|
| 782 | // // |
---|
| 783 | // This method is purely used for debugging purposes - will be deleted // |
---|
| 784 | // from the final code (when we are sure it is bug free) // |
---|
| 785 | // // |
---|
| 786 | //////////////////////////////////////////////////////////////////////////// |
---|
| 787 | void G4UIxvt::listCommandArray(void) |
---|
| 788 | { |
---|
| 789 | for(int i = 0; i < currentPosition; i++) |
---|
| 790 | { |
---|
| 791 | G4cout << "CommandArray, Entry-> " << i << G4endl |
---|
| 792 | << "Flag-> " << commandArray[i].flag << G4endl |
---|
| 793 | << "Name-> " << commandArray[i].name << G4endl |
---|
| 794 | << "Guidance-> " << commandArray[i].guidance << G4endl |
---|
| 795 | << "Number of Parameters-> " << commandArray[i].numOfParameters << G4endl; |
---|
| 796 | |
---|
| 797 | int numParam = commandArray[i].numOfParameters; |
---|
| 798 | |
---|
| 799 | if (numParam != 0) |
---|
| 800 | { |
---|
| 801 | for(int x = 0; x < numParam; x++) |
---|
| 802 | { |
---|
| 803 | G4cout << "Parameters for this command: " << G4endl << G4endl |
---|
| 804 | << "Parameter Name-> " << commandArray[i].parameters[x].name << G4endl |
---|
| 805 | << "Parameter Guidance-> " << commandArray[i].parameters[x].guidance << G4endl |
---|
| 806 | << "Parameter Default Value-> " << commandArray[i].parameters[x].defaultValue << G4endl |
---|
| 807 | << "Parameter Range-> " << commandArray[i].parameters[x].range << G4endl |
---|
| 808 | << "Parameter Candidate-> " << commandArray[i].parameters[x].candidate << G4endl |
---|
| 809 | << "Parameter Type-> " << commandArray[i].parameters[x].type << G4endl |
---|
| 810 | << "Parameter Omittable-> " << commandArray[i].parameters[x].omittable << G4endl |
---|
| 811 | << G4endl << G4endl; |
---|
| 812 | } |
---|
| 813 | } |
---|
| 814 | |
---|
| 815 | G4cout << "Number-> " << commandArray[i].commandNumber << G4endl << G4endl; |
---|
| 816 | } |
---|
| 817 | } |
---|
| 818 | |
---|
| 819 | #endif |
---|