BLCMDg4ui Class Reference

Inheritance diagram for BLCMDg4ui:

BLCommand BLCallback

List of all members.


Detailed Description

class BLCMDg4ui arranges to present the user with the standard Geant4 user interface session.

Public Member Functions

 BLCMDg4ui ()
 Constructor.
virtual G4String commandName ()
 commandName() returns "g4ui".
virtual int command (BLArgumentVector &argv, BLArgumentMap &namedArgs)
 command() implements the g4ui command.
virtual void defineNamedArgs ()
 defineNamedArgs() defines the named arguments for this command.
void callback (int type)
 callback() from BLCallback.

Private Attributes

bool alreadyRegistered
std::vector< G4String > cmds [N_TYPE]
int when

Constructor & Destructor Documentation

BLCMDg4ui::BLCMDg4ui (  ) 

Constructor.

References alreadyRegistered, BLCMDTYPE_CONTROL, BLCommand::registerCommand(), BLCommand::setDescription(), BLCommand::setSynopsis(), and when.

00057 {
00058         registerCommand(BLCMDTYPE_CONTROL);
00059         setSynopsis("Accesses the Geant4 user interface");
00060         setDescription("Each positional argument is executed as a Geant4 UI\n"
00061                 "command, according to the when parameter. No positional\n"
00062                 "arguments means open a UI session on stdout/stdin.\n"
00063                 "For a given value of when, the UI commands from all g4ui "
00064                 "commands are executed in order.");
00065 
00066         alreadyRegistered = false;
00067         when = 0;
00068 }


Member Function Documentation

virtual G4String BLCMDg4ui::commandName (  )  [inline, virtual]

commandName() returns "g4ui".

Implements BLCommand.

00042 { return "g4ui"; }

int BLCMDg4ui::command ( BLArgumentVector argv,
BLArgumentMap namedArgs 
) [virtual]

command() implements the g4ui command.

Implements BLCommand.

References alreadyRegistered, cmds, BLManager::getObject(), BLCommand::handleNamedArgs(), N_TYPE, BLCommand::print(), BLCommand::printError(), BLManager::registerCallback(), and when.

00071 {
00072         when = 0;
00073         int retval = handleNamedArgs(namedArgs);
00074 
00075         if(when < 0 || when == 3 || when >= N_TYPE) {
00076                 printError("g4ui: invalid when value -- command ignored");
00077                 return -1;
00078         }
00079 
00080         if(argv.size() == 0) {
00081                 cmds[when].push_back("--interactive--");
00082         } else {
00083                 for(unsigned i=0; i<argv.size(); ++i)
00084                         cmds[when].push_back(argv[i]);
00085         }
00086 
00087         if(!alreadyRegistered) {
00088                 BLManager::getObject()->registerCallback(this, 0);
00089                 BLManager::getObject()->registerCallback(this, 1);
00090                 BLManager::getObject()->registerCallback(this, 2);
00091                 BLManager::getObject()->registerCallback(this, 4);
00092                 alreadyRegistered = true;
00093         }
00094 
00095         print("");
00096 
00097         return retval;
00098 }

void BLCMDg4ui::defineNamedArgs (  )  [virtual]

defineNamedArgs() defines the named arguments for this command.

Reimplemented from BLCommand.

References BLCommand::argInt(), and when.

00101 {
00102         argInt(when,"when","0=before reference, 1=before beam, 2=after beam, "
00103                                 "3=cannot be used, 4=visualization.");
00104 }

void BLCMDg4ui::callback ( int  type  )  [virtual]

callback() from BLCallback.

Reimplemented from BLCallback.

References cmds, and N_TYPE.

00107 {
00108         if(type < 0 || type >= N_TYPE || cmds[type].size() == 0) return;
00109 
00110         static const char *where[N_TYPE] = {"before reference",
00111                                                 "before beam", "after beam"};
00112         printf("\n");
00113         printf("Geant4 User Interface %s\n", where[type]);
00114         fflush(stdout);
00115 
00116         G4UImanager *UI = G4UImanager::GetUIpointer();
00117         for(unsigned i=0; i<cmds[type].size(); ++i) {
00118                 if(cmds[type][i] == "--interactive--") {
00119                         printf("Type exit<CR> to exit the geant4 UI and resume G4beamline\n");
00120                         fflush(stdout);
00121                         G4UIterminal *terminal = new G4UIterminal(0,false);
00122                         terminal->SessionStart();
00123                         delete terminal;
00124                 } else {
00125                         printf("    %s\n",cmds[type][i].c_str());
00126                         fflush(stdout);
00127                         int code = UI->ApplyCommand(cmds[type][i]);
00128                         if(code > 0)
00129                                 printf("Command Failed code=%d\n",code);
00130                 }
00131         }
00132 }


Member Data Documentation

Referenced by BLCMDg4ui(), and command().

std::vector<G4String> BLCMDg4ui::cmds[N_TYPE] [private]

Referenced by callback(), and command().

int BLCMDg4ui::when [private]

Referenced by BLCMDg4ui(), command(), and defineNamedArgs().


The documentation for this class was generated from the following file:
g4beamline