Geant4-11
Public Member Functions | Private Types | Private Member Functions | Private Attributes
G4UIExecutive Class Reference

#include <G4UIExecutive.hh>

Public Member Functions

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

Private Types

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

Private Member Functions

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

Private Attributes

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

Detailed Description

Definition at line 59 of file G4UIExecutive.hh.

Member Enumeration Documentation

◆ SessionType

Enumerator
kNone 
kQt 
kXm 
kWin32 
kTcsh 
kCsh 

Definition at line 76 of file G4UIExecutive.hh.

Constructor & Destructor Documentation

◆ G4UIExecutive()

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

Definition at line 78 of file G4UIExecutive.cc.

79 : selected(kNone), session(NULL), shell(NULL), isGUI(false), verbose(true)
80{
81 if ( verbose ) {
82 G4cout << "Available UI session types: [ ";
83 if ( qt_build ) G4cout << "Qt, ";
84 if ( xm_build ) G4cout << "Xm, ";
85 if ( win32_build) G4cout << "Win32, ";
86 if (tcsh_build ) G4cout << "tcsh, ";
87 G4cout << "csh ]" << G4endl;
88 }
89
90 // selecting session type...
91 // 1st priority : in case argumant specified
92 G4String stype = G4StrUtil::to_lower_copy(type); // session type is case-insensitive.
93 if (type != "") SelectSessionByArg(stype);
94
95 // 2nd priority : refer environment variables (as backword compatibility)
97
98 // 3rd priority : refer $HOME/.g4session
99 if ( selected == kNone ) {
100 G4String appinput = argv[0];
101 G4String appname = "";
102 size_t islash = appinput.find_last_of("/\\");
103 if (islash == G4String::npos)
104 appname = appinput;
105 else
106 appname = appinput.substr(islash+1, appinput.size()-islash-1);
107
108 SelectSessionByFile(appname);
109 }
110
111 // 4th, best guess of session type
113
114 // instantiate a session...
115 switch ( selected ) {
116 case kQt:
117#if defined(G4UI_BUILD_QT_SESSION)
118 session = new G4UIQt(argc, argv);
119 isGUI = true;
120#endif
121 break;
122 case kXm:
123#if defined(G4UI_BUILD_XM_SESSION)
124 session = new G4UIXm(argc, argv);
125 isGUI = true;
126#endif
127 break;
128 case kWin32:
129#if defined(G4UI_BUILD_WIN32_SESSION)
130 DISCARD_PARAMETER(argc);
131 DISCARD_PARAMETER(argv);
132 session = new G4UIWin32();
133 isGUI = true;
134#endif
135 break;
136 case kTcsh:
137#ifndef WIN32
138 DISCARD_PARAMETER(argc);
139 DISCARD_PARAMETER(argv);
140 shell = new G4UItcsh;
142#endif
143 break;
144 case kCsh:
145 DISCARD_PARAMETER(argc);
146 DISCARD_PARAMETER(argv);
147 shell = new G4UIcsh;
149 default:
150 break;
151 }
152
153 // fallback (csh)
154 if ( session == NULL ) {
155 G4Exception("G4UIExecutive::G4UIExecutive()",
156 "UI0002",
158 "Specified session type is not build in your system,\n"
159 "or no session type is specified.\n"
160 "A fallback session type is used.");
161
162 selected = kCsh;
163 DISCARD_PARAMETER(argc);
164 DISCARD_PARAMETER(argv);
165 shell = new G4UIcsh;
167 }
168
169 TIMEMORY_INIT(argc, argv);
170}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
#define TIMEMORY_INIT(...)
Definition: G4TiMemory.hh:108
static const G4bool win32_build
#define DISCARD_PARAMETER(p)
static const G4bool qt_build
static const G4bool tcsh_build
static const G4bool xm_build
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
void SelectSessionByFile(const G4String &appname)
SessionType selected
void SelectSessionByBestGuess()
G4UIsession * session
void SelectSessionByArg(const G4String &stype)
void SelectSessionByEnv()
G4VUIshell * shell
Definition: G4UIXm.hh:60
G4String to_lower_copy(G4String str)
Return lowercased copy of string.

References DISCARD_PARAMETER, G4cout, G4endl, G4Exception(), isGUI, JustWarning, kCsh, kNone, kNone, kQt, kTcsh, kWin32, kXm, qt_build, selected, SelectSessionByArg(), SelectSessionByBestGuess(), SelectSessionByEnv(), SelectSessionByFile(), shell, tcsh_build, TIMEMORY_INIT, G4StrUtil::to_lower_copy(), verbose, win32_build, and xm_build.

◆ ~G4UIExecutive()

G4UIExecutive::~G4UIExecutive ( )

Definition at line 173 of file G4UIExecutive.cc.

174{
175 delete session;
176}

References session.

Member Function Documentation

◆ GetSession()

G4UIsession * G4UIExecutive::GetSession ( ) const
inline

Definition at line 95 of file G4UIExecutive.hh.

96{
97 return session;
98}

References session.

◆ IsGUI()

G4bool G4UIExecutive::IsGUI ( ) const
inline

Definition at line 100 of file G4UIExecutive.hh.

101{
102 return isGUI;
103}

References isGUI.

◆ SelectSessionByArg()

void G4UIExecutive::SelectSessionByArg ( const G4String stype)
private

Definition at line 179 of file G4UIExecutive.cc.

180{
181 if ( qt_build && stype == "qt" ) selected = kQt;
182 else if ( xm_build && stype == "xm" ) selected = kXm;
183 else if ( win32_build && stype == "win32" ) selected = kWin32;
184 else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
185 else if ( stype == "csh" ) selected = kCsh;
186}

References kCsh, kQt, kTcsh, kWin32, kXm, qt_build, selected, tcsh_build, win32_build, and xm_build.

Referenced by G4UIExecutive().

◆ SelectSessionByBestGuess()

void G4UIExecutive::SelectSessionByBestGuess ( )
private

Definition at line 254 of file G4UIExecutive.cc.

255{
256 if ( qt_build ) selected = kQt;
257 else if ( win32_build ) selected = kWin32;
258 else if ( tcsh_build ) selected = kTcsh;
259 else if ( xm_build ) selected = kXm;
260}

References kQt, kTcsh, kWin32, kXm, qt_build, selected, tcsh_build, win32_build, and xm_build.

Referenced by G4UIExecutive().

◆ SelectSessionByEnv()

void G4UIExecutive::SelectSessionByEnv ( )
private

Definition at line 189 of file G4UIExecutive.cc.

190{
191 if ( qt_build && std::getenv("G4UI_USE_QT") ) selected = kQt;
192 else if ( xm_build && std::getenv("G4UI_USE_XM") ) selected = kXm;
193 else if ( win32_build && std::getenv("G4UI_USE_WIN32") ) selected = kWin32;
194 else if ( tcsh_build && std::getenv("G4UI_USE_TCSH") ) selected = kTcsh;
195}

References kQt, kTcsh, kWin32, kXm, qt_build, selected, tcsh_build, win32_build, and xm_build.

Referenced by G4UIExecutive().

◆ SelectSessionByFile()

void G4UIExecutive::SelectSessionByFile ( const G4String appname)
private

Definition at line 198 of file G4UIExecutive.cc.

199{
200 const char* path = std::getenv("HOME");
201 if( path == NULL ) return;
202 G4String homedir = path;
203
204#ifndef WIN32
205 G4String fname= homedir + "/.g4session";
206#else
207 G4String fname= homedir + "\\.g4session";
208#endif
209
210 std::ifstream fsession;
211 enum { BUFSIZE= 1024 }; char linebuf[BUFSIZE];
212
213 fsession.open(fname, std::ios::in);
214
215 G4String default_session = "";
216 G4int iline = 1;
217 sessionMap.clear();
218 while( fsession.good() ) {
219 if( fsession.eof()) break;
220 fsession.getline(linebuf, BUFSIZE);
221 G4String aline = G4StrUtil::strip_copy(linebuf);
222 if ( aline[0] == '#' ) continue;
223 if ( aline == "" ) continue;
224 if ( iline == 1 )
225 default_session = aline;
226 else {
227 size_t idx = aline.find_first_of(" ");
228 if ( idx == G4String::npos ) break;
229 G4String aname = aline.substr(0, idx);
230 idx = aline.find_first_not_of(" ", idx);
231 if (idx == G4String::npos ) break;
232 G4String sname = aline.substr(idx, aline.size()-idx);
233 sessionMap[aname] = sname;
234 }
235 iline++;
236 }
237 fsession.close();
238
239 G4String stype = "";
240 std::map<G4String, G4String>::iterator it = sessionMap.find(appname);
241 if ( it != sessionMap.end() ) stype = sessionMap[appname];
242 else stype = default_session;
243 G4StrUtil::to_lower(stype);
244
245 // select session...
246 if ( qt_build && stype == "qt" ) selected = kQt;
247 else if ( xm_build && stype == "xm" ) selected = kXm;
248 else if ( win32_build && stype == "win32" ) selected = kWin32;
249 else if ( tcsh_build && stype == "tcsh" ) selected = kTcsh;
250 else if ( stype == "csh" ) selected = kCsh;
251}
int G4int
Definition: G4Types.hh:85
std::map< G4String, G4String > sessionMap
#define BUFSIZE
Definition: liblist.c:40
G4String strip_copy(G4String str, char c=' ')
Return copy of string with leading and trailing characters removed.
void to_lower(G4String &str)
Convert string to lowercase.
string fname
Definition: test.py:308

References BUFSIZE, test::fname, kCsh, kQt, kTcsh, kWin32, kXm, qt_build, selected, sessionMap, G4StrUtil::strip_copy(), tcsh_build, G4StrUtil::to_lower(), win32_build, and xm_build.

Referenced by G4UIExecutive().

◆ SessionStart()

void G4UIExecutive::SessionStart ( )

Definition at line 276 of file G4UIExecutive.cc.

277{
279}

References SessionStart().

Referenced by SessionStart().

◆ SetLsColor()

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

Definition at line 269 of file G4UIExecutive.cc.

271{
272 if(shell) shell-> SetLsColor(dirColor, cmdColor);
273}
void SetLsColor(TermColorIndex dirColor, TermColorIndex cmdColor)

References SetLsColor(), and shell.

Referenced by SetLsColor().

◆ SetPrompt()

void G4UIExecutive::SetPrompt ( const G4String prompt)

Definition at line 263 of file G4UIExecutive.cc.

264{
265 if(shell) shell-> SetPrompt(prompt);
266}
void SetPrompt(const G4String &prompt)

References SetPrompt(), and shell.

Referenced by SetPrompt().

◆ SetVerbose()

void G4UIExecutive::SetVerbose ( G4bool  val)
inline

Definition at line 105 of file G4UIExecutive.hh.

106{
107 verbose = val;
108}

References verbose.

Field Documentation

◆ isGUI

G4bool G4UIExecutive::isGUI
private

Definition at line 82 of file G4UIExecutive.hh.

Referenced by G4UIExecutive(), and IsGUI().

◆ selected

SessionType G4UIExecutive::selected
private

◆ session

G4UIsession* G4UIExecutive::session
private

Definition at line 79 of file G4UIExecutive.hh.

Referenced by GetSession(), and ~G4UIExecutive().

◆ sessionMap

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

Definition at line 86 of file G4UIExecutive.hh.

Referenced by SelectSessionByFile().

◆ shell

G4VUIshell* G4UIExecutive::shell
private

Definition at line 80 of file G4UIExecutive.hh.

Referenced by G4UIExecutive(), SetLsColor(), and SetPrompt().

◆ verbose

G4bool G4UIExecutive::verbose
private

Definition at line 84 of file G4UIExecutive.hh.

Referenced by G4UIExecutive(), and SetVerbose().


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