32#if defined(G4UI_BUILD_QT_SESSION)
37#if defined(G4UI_BUILD_XM_SESSION)
41#if defined(G4UI_BUILD_WIN32_SESSION)
45#if defined(G4UI_BUILD_WT_SESSION)
57#if defined(G4UI_BUILD_QT_SESSION)
58static const G4bool qt_build =
true;
60static const G4bool qt_build =
false;
63#if defined(G4UI_BUILD_XM_SESSION)
64static const G4bool xm_build =
true;
66static const G4bool xm_build =
false;
69#if defined(G4UI_BUILD_WIN32_SESSION)
70static const G4bool win32_build =
true;
72static const G4bool win32_build =
false;
75#if defined(G4UI_BUILD_WT_SESSION)
76static const G4bool wt_build =
true;
78static const G4bool wt_build =
false;
82static const G4bool tcsh_build =
true;
84static const G4bool tcsh_build =
false;
87#define DISCARD_PARAMETER(p) (void)p
91 : selected(kNone), session(NULL), shell(NULL), isGUI(false)
93 G4cout <<
"Available UI session types: [ ";
94 if ( qt_build )
G4cout <<
"Qt, ";
95 if ( xm_build )
G4cout <<
"Xm, ";
96 if ( win32_build)
G4cout <<
"Win32, ";
97 if ( wt_build )
G4cout <<
"Wt, ";
99 if (tcsh_build )
G4cout <<
"tcsh, ";
106 if (type !=
"") SelectSessionByArg(stype);
109 if ( selected == kNone ) SelectSessionByEnv();
112 if ( selected == kNone ) {
115 size_t islash = appinput.find_last_of(
"/\\");
116 if (islash == G4String::npos)
119 appname = appinput(islash+1, appinput.size()-islash-1);
121 SelectSessionByFile(appname);
125 if ( selected == kNone) SelectSessionByBestGuess();
128 switch ( selected ) {
130#if defined(G4UI_BUILD_QT_SESSION)
131 session =
new G4UIQt(argc, argv);
136#if defined(G4UI_BUILD_XM_SESSION)
137 session =
new G4UIXm(argc, argv);
142#if defined(G4UI_BUILD_WIN32_SESSION)
145 session =
new G4UIWin32();
149#if defined(G4UI_BUILD_WT_SESSION)
178 if ( session == NULL ) {
182 "Specified session type is not build in your system,\n"
183 "or no session type is specified.\n"
184 "A fallback session type is used.");
197 if ( selected != kWt )
delete session;
201void G4UIExecutive::SelectSessionByArg(
const G4String& stype)
203 if ( qt_build && stype ==
"qt" ) selected = kQt;
204 else if ( xm_build && stype ==
"xm" ) selected = kXm;
205 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
207 else if ( stype ==
"gag" ) selected = kGag;
208 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
209 else if ( stype ==
"csh" ) selected = kCsh;
213void G4UIExecutive::SelectSessionByEnv()
215 if ( qt_build && getenv(
"G4UI_USE_QT") ) selected = kQt;
216 else if ( xm_build && getenv(
"G4UI_USE_XM") ) selected = kXm;
217 else if ( win32_build && getenv(
"G4UI_USE_WIN32") ) selected = kWin32;
219 else if ( getenv(
"G4UI_USE_GAG") ) selected = kGag;
220 else if ( tcsh_build && getenv(
"G4UI_USE_TCSH") ) selected = kTcsh;
224void G4UIExecutive::SelectSessionByFile(
const G4String& appname)
226 const char* path = getenv(
"HOME");
227 if( path == NULL )
return;
231 G4String fname= homedir +
"/.g4session";
233 G4String fname= homedir +
"\\.g4session";
236 std::ifstream fsession;
237 enum { BUFSIZE= 1024 };
char linebuf[BUFSIZE];
239 fsession.open(fname, std::ios::in);
244 while( fsession.good() ) {
245 if( fsession.eof())
break;
246 fsession.getline(linebuf, BUFSIZE);
249 if ( aline(0) ==
'#' )
continue;
251 default_session = aline;
253 size_t idx = aline.find_first_of(
" ");
254 if ( idx == G4String::npos )
break;
255 G4String aname = aline.substr(0, idx);
256 idx = aline.find_first_not_of(
" ", idx);
257 if (idx == G4String::npos )
break;
258 G4String sname = aline.substr(idx, aline.size()-idx);
259 sessionMap[aname] = sname;
266 std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
267 if ( it != sessionMap.end() ) stype = sessionMap[appname];
268 else stype = default_session;
272 if ( qt_build && stype ==
"qt" ) selected = kQt;
273 else if ( xm_build && stype ==
"xm" ) selected = kXm;
274 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
276 else if ( stype ==
"gag" ) selected = kGag;
277 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
278 else if ( stype ==
"csh" ) selected = kCsh;
282void G4UIExecutive::SelectSessionByBestGuess()
284 if ( qt_build ) selected = kQt;
285 else if ( tcsh_build ) selected = kTcsh;
286 else if ( xm_build ) selected = kXm;
299 if(shell) shell->
SetLsColor(dirColor, cmdColor);
#define DISCARD_PARAMETER(p)
G4DLLIMPORT std::ostream G4cout
G4String strip(G4int strip_Type=trailing, char c=' ')
void SetPrompt(const G4String &prompt)
G4UIExecutive(G4int argc, char **argv, const G4String &type="")
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)