30#if defined(G4UI_BUILD_QT_SESSION)
35#if defined(G4UI_BUILD_WT_SESSION)
40#if defined(G4UI_BUILD_XM_SESSION)
44#if defined(G4UI_BUILD_WIN32_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();
150#if defined(G4UI_BUILD_WT_SESSION)
151 session =
new G4UIWt(argc, argv);
179 if ( session == NULL ) {
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.");
200 if ( selected != kWt )
delete session;
204void G4UIExecutive::SelectSessionByArg(
const G4String& stype)
206 if ( qt_build && stype ==
"qt" ) selected = kQt;
207 else if ( xm_build && stype ==
"xm" ) selected = kXm;
208 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
209 else if ( wt_build && stype ==
"wt" ) selected = kWt;
210 else if ( stype ==
"gag" ) selected = kGag;
211 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
212 else if ( stype ==
"csh" ) selected = kCsh;
216void G4UIExecutive::SelectSessionByEnv()
218 if ( qt_build && std::getenv(
"G4UI_USE_QT") ) selected = kQt;
219 else if ( xm_build && std::getenv(
"G4UI_USE_XM") ) selected = kXm;
220 else if ( win32_build && std::getenv(
"G4UI_USE_WIN32") ) selected = kWin32;
221 else if ( wt_build && std::getenv(
"G4UI_USE_WT") ) selected = kWt;
222 else if ( std::getenv(
"G4UI_USE_GAG") ) selected = kGag;
223 else if ( tcsh_build && std::getenv(
"G4UI_USE_TCSH") ) selected = kTcsh;
227void G4UIExecutive::SelectSessionByFile(
const G4String& appname)
229 const char* path = std::getenv(
"HOME");
230 if( path == NULL )
return;
234 G4String fname= homedir +
"/.g4session";
236 G4String fname= homedir +
"\\.g4session";
239 std::ifstream fsession;
240 enum { BUFSIZE= 1024 };
char linebuf[BUFSIZE];
242 fsession.open(fname, std::ios::in);
247 while( fsession.good() ) {
248 if( fsession.eof())
break;
249 fsession.getline(linebuf, BUFSIZE);
252 if ( aline(0) ==
'#' )
continue;
253 if ( aline ==
"" )
continue;
255 default_session = aline;
257 size_t idx = aline.find_first_of(
" ");
258 if ( idx == G4String::npos )
break;
259 G4String aname = aline.substr(0, idx);
260 idx = aline.find_first_not_of(
" ", idx);
261 if (idx == G4String::npos )
break;
262 G4String sname = aline.substr(idx, aline.size()-idx);
263 sessionMap[aname] = sname;
270 std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
271 if ( it != sessionMap.end() ) stype = sessionMap[appname];
272 else stype = default_session;
276 if ( qt_build && stype ==
"qt" ) selected = kQt;
277 else if ( xm_build && stype ==
"xm" ) selected = kXm;
278 else if ( win32_build && stype ==
"win32" ) selected = kWin32;
280 else if ( stype ==
"gag" ) selected = kGag;
281 else if ( tcsh_build && stype ==
"tcsh" ) selected = kTcsh;
282 else if ( stype ==
"csh" ) selected = kCsh;
286void G4UIExecutive::SelectSessionByBestGuess()
288 if ( qt_build ) selected = kQt;
289 else if ( tcsh_build ) selected = kTcsh;
290 else if ( xm_build ) selected = kXm;
303 if(shell) shell->
SetLsColor(dirColor, cmdColor);
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
#define TIMEMORY_INIT(...)
#define DISCARD_PARAMETER(p)
G4GLOB_DLL 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)