Geant4  10.02.p03
G4UIExecutive Class Reference

#include <G4UIExecutive.hh>

Collaboration diagram for G4UIExecutive:

Public Member Functions

 G4UIExecutive (G4int argc, char **argv, const G4String &type="")
 
 ~G4UIExecutive ()
 
G4UIsessionGetSession () const
 
G4bool IsGUI () const
 
void SetPrompt (const G4String &prompt)
 
void SetLsColor (TermColorIndex dirColor, TermColorIndex cmdColor)
 
void SessionStart ()
 

Private Types

enum  SessionType {
  kNone, kQt, kXm, kWin32,
  kWt, kGag, kTcsh, kCsh
}
 

Private Member Functions

void SelectSessionByArg (const G4String &stype)
 
void SelectSessionByEnv ()
 
void SelectSessionByFile (const G4String &appname)
 
void SelectSessionByBestGuess ()
 

Private Attributes

SessionType selected
 
G4UIsessionsession
 
G4VUIshellshell
 
G4bool isGUI
 
std::map< G4String, G4StringsessionMap
 

Detailed Description

Definition at line 60 of file G4UIExecutive.hh.

Member Enumeration Documentation

◆ SessionType

Constructor & Destructor Documentation

◆ G4UIExecutive()

G4UIExecutive::G4UIExecutive ( G4int  argc,
char **  argv,
const G4String type = "" 
)

Definition at line 91 of file G4UIExecutive.cc.

92  : selected(kNone), session(NULL), shell(NULL), isGUI(false)
93 {
94  G4cout << "Available UI session types: [ ";
95  if ( qt_build ) G4cout << "Qt, ";
96  if ( xm_build ) G4cout << "Xm, ";
97  if ( win32_build) G4cout << "Win32, ";
98  if ( wt_build ) G4cout << "Wt, ";
99  G4cout << "GAG, ";
100  if (tcsh_build ) G4cout << "tcsh, ";
101  G4cout << "csh ]" << G4endl;
102 
103  // selecting session type...
104  // 1st priority : in case argumant specified
105  G4String stype = type;
106  stype.toLower(); // session type is case-insensitive.
107  if (type != "") SelectSessionByArg(stype);
108 
109  // 2nd priority : refer environment variables (as backword compatibility)
110  if ( selected == kNone ) SelectSessionByEnv();
111 
112  // 3rd priority : refer $HOME/.g4session
113  if ( selected == kNone ) {
114  G4String appinput = argv[0];
115  G4String appname = "";
116  size_t islash = appinput.find_last_of("/\\");
117  if (islash == G4String::npos)
118  appname = appinput;
119  else
120  appname = appinput(islash+1, appinput.size()-islash-1);
121 
122  SelectSessionByFile(appname);
123  }
124 
125  // 4th, best guess of session type
127 
128  // instantiate a session...
129  switch ( selected ) {
130  case kQt:
131 #if defined(G4UI_BUILD_QT_SESSION)
132  session = new G4UIQt(argc, argv);
133  isGUI = true;
134 #endif
135  break;
136  case kXm:
137 #if defined(G4UI_BUILD_XM_SESSION)
138  session = new G4UIXm(argc, argv);
139  isGUI = true;
140 #endif
141  break;
142  case kWin32:
143 #if defined(G4UI_BUILD_WIN32_SESSION)
144  DISCARD_PARAMETER(argc);
145  DISCARD_PARAMETER(argv);
146  session = new G4UIWin32();
147 #endif
148  break;
149  case kWt:
150 #if defined(G4UI_BUILD_WT_SESSION)
151  session = new G4UIWt(argc, argv);
152  isGUI = true;
153 #endif
154  break;
155  case kGag:
156  DISCARD_PARAMETER(argc);
157  DISCARD_PARAMETER(argv);
158  session = new G4UIGAG();
159  isGUI = true;
160  break;
161  case kTcsh:
162 #ifndef WIN32
163  DISCARD_PARAMETER(argc);
164  DISCARD_PARAMETER(argv);
165  shell = new G4UItcsh;
166  session = new G4UIterminal(shell);
167 #endif
168  break;
169  case kCsh:
170  DISCARD_PARAMETER(argc);
171  DISCARD_PARAMETER(argv);
172  shell = new G4UIcsh;
173  session = new G4UIterminal(shell);
174  default:
175  break;
176  }
177 
178  // fallback (csh)
179  if ( session == NULL ) {
180  G4Exception("G4UIExecutive::G4UIExecutive()",
181  "UI0002",
182  JustWarning,
183  "Specified session type is not build in your system,\n"
184  "or no session type is specified.\n"
185  "A fallback session type is used.");
186 
187  selected = kCsh;
188  DISCARD_PARAMETER(argc);
189  DISCARD_PARAMETER(argv);
190  shell = new G4UIcsh;
191  session = new G4UIterminal(shell);
192  }
193 }
static const G4bool wt_build
static const G4bool win32_build
SessionType selected
static const G4bool qt_build
#define DISCARD_PARAMETER(p)
void SelectSessionByBestGuess()
void SelectSessionByArg(const G4String &stype)
G4GLOB_DLL std::ostream G4cout
G4UIsession * session
static const G4bool xm_build
void toLower()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SelectSessionByEnv()
static const G4bool tcsh_build
G4VUIshell * shell
void SelectSessionByFile(const G4String &appname)
#define G4endl
Definition: G4ios.hh:61
Here is the call graph for this function:

◆ ~G4UIExecutive()

G4UIExecutive::~G4UIExecutive ( )

Definition at line 196 of file G4UIExecutive.cc.

197 {
198  if ( selected != kWt ) delete session;
199 }
SessionType selected
G4UIsession * session

Member Function Documentation

◆ GetSession()

G4UIsession * G4UIExecutive::GetSession ( ) const
inline

Definition at line 92 of file G4UIExecutive.hh.

93 {
94  return session;
95 }
G4UIsession * session

◆ IsGUI()

G4bool G4UIExecutive::IsGUI ( ) const
inline

Definition at line 97 of file G4UIExecutive.hh.

98 {
99  return isGUI;
100 }
Here is the caller graph for this function:

◆ SelectSessionByArg()

void G4UIExecutive::SelectSessionByArg ( const G4String stype)
private

Definition at line 202 of file G4UIExecutive.cc.

203 {
204  if ( qt_build && stype == "qt" ) selected = kQt;
205  else if ( xm_build && stype == "xm" ) selected = kXm;
206  else if ( win32_build && stype == "win32" ) selected = kWin32;
207  else if ( wt_build && stype == "wt" ) selected = kWt;
208  else if ( stype == "gag" ) selected = kGag;
209  else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
210  else if ( stype == "csh" ) selected = kCsh;
211 }
static const G4bool wt_build
static const G4bool win32_build
SessionType selected
static const G4bool qt_build
static const G4bool xm_build
static const G4bool tcsh_build
Here is the caller graph for this function:

◆ SelectSessionByBestGuess()

void G4UIExecutive::SelectSessionByBestGuess ( )
private

Definition at line 283 of file G4UIExecutive.cc.

284 {
285  if ( qt_build ) selected = kQt;
286  else if ( tcsh_build ) selected = kTcsh;
287  else if ( xm_build ) selected = kXm;
288 }
SessionType selected
static const G4bool qt_build
static const G4bool xm_build
static const G4bool tcsh_build
Here is the caller graph for this function:

◆ SelectSessionByEnv()

void G4UIExecutive::SelectSessionByEnv ( )
private

Definition at line 214 of file G4UIExecutive.cc.

215 {
216  if ( qt_build && getenv("G4UI_USE_QT") ) selected = kQt;
217  else if ( xm_build && getenv("G4UI_USE_XM") ) selected = kXm;
218  else if ( win32_build && getenv("G4UI_USE_WIN32") ) selected = kWin32;
219  else if ( wt_build && getenv("G4UI_USE_WT") ) selected = kWt;
220  else if ( getenv("G4UI_USE_GAG") ) selected = kGag;
221  else if ( tcsh_build && getenv("G4UI_USE_TCSH") ) selected = kTcsh;
222 }
static const G4bool wt_build
static const G4bool win32_build
SessionType selected
static const G4bool qt_build
static const G4bool xm_build
static const G4bool tcsh_build
Here is the caller graph for this function:

◆ SelectSessionByFile()

void G4UIExecutive::SelectSessionByFile ( const G4String appname)
private

Definition at line 225 of file G4UIExecutive.cc.

226 {
227  const char* path = getenv("HOME");
228  if( path == NULL ) return;
229  G4String homedir = path;
230 
231 #ifndef WIN32
232  G4String fname= homedir + "/.g4session";
233 #else
234  G4String fname= homedir + "\\.g4session";
235 #endif
236 
237  std::ifstream fsession;
238  enum { BUFSIZE= 1024 }; char linebuf[BUFSIZE];
239 
240  fsession.open(fname, std::ios::in);
241 
242  G4String default_session = "";
243  G4int iline = 1;
244  sessionMap.clear();
245  while( fsession.good() ) {
246  if( fsession.eof()) break;
247  fsession.getline(linebuf, BUFSIZE);
248  G4String aline = linebuf;
249  aline.strip(G4String::both);
250  if ( aline(0) == '#' ) continue;
251  if ( iline == 1 )
252  default_session = aline;
253  else {
254  size_t idx = aline.find_first_of(" ");
255  if ( idx == G4String::npos ) break;
256  G4String aname = aline.substr(0, idx);
257  idx = aline.find_first_not_of(" ", idx);
258  if (idx == G4String::npos ) break;
259  G4String sname = aline.substr(idx, aline.size()-idx);
260  sessionMap[aname] = sname;
261  }
262  iline++;
263  }
264  fsession.close();
265 
266  G4String stype = "";
267  std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
268  if ( it != sessionMap.end() ) stype = sessionMap[appname];
269  else stype = default_session;
270  stype.toLower();
271 
272  // select session...
273  if ( qt_build && stype == "qt" ) selected = kQt;
274  else if ( xm_build && stype == "xm" ) selected = kXm;
275  else if ( win32_build && stype == "win32" ) selected = kWin32;
276  //else if ( wt_build && stype == "wt" ) selected = kWt;
277  else if ( stype == "gag" ) selected = kGag;
278  else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
279  else if ( stype == "csh" ) selected = kCsh;
280 }
static const G4bool win32_build
SessionType selected
G4String strip(G4int strip_Type=trailing, char c=' ')
ifstream in
Definition: comparison.C:7
static const G4bool qt_build
int G4int
Definition: G4Types.hh:78
std::map< G4String, G4String > sessionMap
static const G4bool xm_build
void toLower()
static const G4bool tcsh_build
#define BUFSIZE
Definition: liblist.c:41
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SessionStart()

void G4UIExecutive::SessionStart ( )

Definition at line 304 of file G4UIExecutive.cc.

305 {
306  session-> SessionStart();
307 }
G4UIsession * session
Here is the caller graph for this function:

◆ SetLsColor()

void G4UIExecutive::SetLsColor ( TermColorIndex  dirColor,
TermColorIndex  cmdColor 
)

Definition at line 297 of file G4UIExecutive.cc.

299 {
300  if(shell) shell-> SetLsColor(dirColor, cmdColor);
301 }
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
G4VUIshell * shell

◆ SetPrompt()

void G4UIExecutive::SetPrompt ( const G4String prompt)

Definition at line 291 of file G4UIExecutive.cc.

292 {
293  if(shell) shell-> SetPrompt(prompt);
294 }
void SetPrompt(const G4String &prompt)
G4VUIshell * shell

Member Data Documentation

◆ isGUI

G4bool G4UIExecutive::isGUI
private

Definition at line 81 of file G4UIExecutive.hh.

◆ selected

SessionType G4UIExecutive::selected
private

Definition at line 76 of file G4UIExecutive.hh.

◆ session

G4UIsession* G4UIExecutive::session
private

Definition at line 78 of file G4UIExecutive.hh.

◆ sessionMap

std::map<G4String, G4String> G4UIExecutive::sessionMap
private

Definition at line 83 of file G4UIExecutive.hh.

◆ shell

G4VUIshell* G4UIExecutive::shell
private

Definition at line 79 of file G4UIExecutive.hh.


The documentation for this class was generated from the following files: