Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4UIcontrolMessenger.cc
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26//
27// $Id$
28//
29
30#include <stdlib.h>
32#include "G4UImanager.hh"
33#include "G4UIdirectory.hh"
34#include "G4UIcommand.hh"
35#include "G4UIparameter.hh"
36#include "G4UIcmdWithAString.hh"
39#include "G4UIaliasList.hh"
40#include "G4StateManager.hh"
41#include "G4Tokenizer.hh"
42
43#include "G4ios.hh"
44
46{
47 controlDirectory = new G4UIdirectory("/control/");
48 controlDirectory->SetGuidance("UI control commands.");
49
50 macroPathCommand = new G4UIcmdWithAString("/control/macroPath",this);
51 macroPathCommand->SetGuidance("Set macro search path"
52 "with colon-separated list.");
53 macroPathCommand->SetParameterName("path",false);
54
55 ExecuteCommand = new G4UIcmdWithAString("/control/execute",this);
56 ExecuteCommand->SetGuidance("Execute a macro file.");
57 ExecuteCommand->SetParameterName("fileName",false);
58
59 loopCommand = new G4UIcommand("/control/loop",this);
60 loopCommand->SetGuidance("Execute a macro file more than once.");
61 loopCommand->SetGuidance("Loop counter can be used as an aliased variable.");
62 G4UIparameter* param1 = new G4UIparameter("macroFile",'s',false);
63 loopCommand->SetParameter(param1);
64 G4UIparameter* param2 = new G4UIparameter("counterName",'s',false);
65 loopCommand->SetParameter(param2);
66 G4UIparameter* param3 = new G4UIparameter("initialValue",'d',false);
67 loopCommand->SetParameter(param3);
68 G4UIparameter* param4 = new G4UIparameter("finalValue",'d',false);
69 loopCommand->SetParameter(param4);
70 G4UIparameter* param5 = new G4UIparameter("stepSize",'d',true);
71 param5->SetDefaultValue(1.0);
72 loopCommand->SetParameter(param5);
73
74 foreachCommand = new G4UIcommand("/control/foreach",this);
75 foreachCommand->SetGuidance("Execute a macro file more than once.");
76 foreachCommand->SetGuidance("Loop counter can be used as an aliased variable.");
77 foreachCommand->SetGuidance("Values must be separated by a space.");
78 G4UIparameter* param6 = new G4UIparameter("macroFile",'s',false);
79 foreachCommand->SetParameter(param6);
80 G4UIparameter* param7 = new G4UIparameter("counterName",'s',false);
81 foreachCommand->SetParameter(param7);
82 G4UIparameter* param8 = new G4UIparameter("valueList",'s',false);
83 foreachCommand->SetParameter(param8);
84
85 suppressAbortionCommand = new G4UIcmdWithAnInteger("/control/suppressAbortion",this);
86 suppressAbortionCommand->SetGuidance("Suppress the program abortion caused by G4Exception.");
87 suppressAbortionCommand->SetGuidance("Suppression level = 0 : no suppression");
88 suppressAbortionCommand->SetGuidance(" = 1 : suppress during EventProc state");
89 suppressAbortionCommand->SetGuidance(" = 2 : full suppression, i.e. no abortion by G4Exception");
90 suppressAbortionCommand->SetGuidance("When abortion is suppressed, you will get error messages issued by G4Exception,");
91 suppressAbortionCommand->SetGuidance("and there is NO guarantee for the correct result after the G4Exception error message.");
92 suppressAbortionCommand->SetParameterName("level",true);
93 suppressAbortionCommand->SetRange("level >= 0 && level <= 2");
94 suppressAbortionCommand->SetDefaultValue(0);
95
96 verboseCommand = new G4UIcmdWithAnInteger("/control/verbose",this);
97 verboseCommand->SetGuidance("Applied command will also be shown on screen.");
98 verboseCommand->SetGuidance("This command is useful with MACRO file.");
99 verboseCommand->SetGuidance(" 0 : silent");
100 verboseCommand->SetGuidance(" 1 : only the valid commands are shown.");
101 verboseCommand->SetGuidance(" 2 : comment lines are also shown (default).");
102 verboseCommand->SetParameterName("switch",true);
103 verboseCommand->SetRange("switch >= 0 && switch <=2");
104 verboseCommand->SetDefaultValue(2);
105
106 historyCommand = new G4UIcmdWithAString("/control/saveHistory",this);
107 historyCommand->SetGuidance("Store command history to a file.");
108 historyCommand->SetGuidance("Defaul file name is G4history.macro.");
109 historyCommand->SetParameterName("fileName",true);
110 historyCommand->SetDefaultValue("G4History.macro");
111
112 stopStoreHistoryCommand
113 = new G4UIcmdWithoutParameter("/control/stopSavingHistory",this);
114 stopStoreHistoryCommand->SetGuidance("Stop saving history file.");
115
116 aliasCommand = new G4UIcommand("/control/alias",this);
117 aliasCommand->SetGuidance("Set an alias.");
118 aliasCommand->SetGuidance("String can be aliased by this command.");
119 aliasCommand->SetGuidance("The string may contain one or more spaces,");
120 aliasCommand->SetGuidance("the string must be enclosed by double quotes (\").");
121 aliasCommand->SetGuidance("To use an alias, enclose the alias name with");
122 aliasCommand->SetGuidance("parenthis \"{\" and \"}\".");
123 G4UIparameter* aliasNameParam = new G4UIparameter("aliasName",'s',false);
124 aliasCommand->SetParameter(aliasNameParam);
125 G4UIparameter* aliasValueParam = new G4UIparameter("aliasValue",'s',false);
126 aliasCommand->SetParameter(aliasValueParam);
127
128 unaliasCommand = new G4UIcmdWithAString("/control/unalias",this);
129 unaliasCommand->SetGuidance("Remove an alias.");
130 unaliasCommand->SetParameterName("aliasName",false);
131
132 listAliasCommand = new G4UIcmdWithoutParameter("/control/listAlias",this);
133 listAliasCommand->SetGuidance("List aliases.");
134
135 getEnvCmd = new G4UIcmdWithAString("/control/getEnv",this);
136 getEnvCmd->SetGuidance("Get a shell environment variable and define it as an alias.");
137
138 echoCmd = new G4UIcmdWithAString("/control/echo",this);
139 echoCmd->SetGuidance("Display the aliased value.");
140
141 shellCommand = new G4UIcmdWithAString("/control/shell",this);
142 shellCommand->SetGuidance("Execute a (Unix) SHELL command.");
143
144 ManualCommand = new G4UIcmdWithAString("/control/manual",this);
145 ManualCommand->SetGuidance("Display all of sub-directories and commands.");
146 ManualCommand->SetGuidance("Directory path should be given by FULL-PATH.");
147 ManualCommand->SetParameterName("dirPath",true);
148 ManualCommand->SetDefaultValue("/");
149
150 HTMLCommand = new G4UIcmdWithAString("/control/createHTML",this);
151 HTMLCommand->SetGuidance("Generate HTML files for all of sub-directories and commands.");
152 HTMLCommand->SetGuidance("Directory path should be given by FULL-PATH.");
153 HTMLCommand->SetParameterName("dirPath",true);
154 HTMLCommand->SetDefaultValue("/");
155
156 maxStoredHistCommand = new G4UIcmdWithAnInteger("/control/maximumStoredHistory",this);
157 maxStoredHistCommand->SetGuidance("Set maximum number of stored UI commands.");
158 maxStoredHistCommand->SetParameterName("max",true);
159 maxStoredHistCommand->SetDefaultValue(20);
160
161 ifCommand = new G4UIcommand("/control/if",this);
162 ifCommand->SetGuidance("Execute a macro file if the expression is true.");
163 ifCommand->SetGuidance(" Syntax : <double> <comp> <double> <macro_file>");
164 G4UIparameter* leftParam = new G4UIparameter("left",'d',false);
165 ifCommand->SetParameter(leftParam);
166 G4UIparameter* compParam = new G4UIparameter("comp",'s',false);
167 compParam->SetParameterCandidates("> >= < <= == !=");
168 ifCommand->SetParameter(compParam);
169 G4UIparameter* rightParam = new G4UIparameter("right",'d',false);
170 ifCommand->SetParameter(rightParam);
171 G4UIparameter* macroFileParam = new G4UIparameter("aliasValue",'s',false);
172 ifCommand->SetParameter(macroFileParam);
173
174 addCommand = new G4UIcommand("/control/add",this);
175 addCommand->SetGuidance("Define a new alias as the sum of two values.");
176 addCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
177 addCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
178 addCommand->SetGuidance(" aliased value is alternated.");
179 G4UIparameter* newAlias1 = new G4UIparameter("new_alias",'s',false);
180 addCommand->SetParameter(newAlias1);
181 G4UIparameter* val1a = new G4UIparameter("value1",'d',false);
182 addCommand->SetParameter(val1a);
183 G4UIparameter* val1b = new G4UIparameter("value2",'d',false);
184 addCommand->SetParameter(val1b);
185
186 subtractCommand = new G4UIcommand("/control/subtract",this);
187 subtractCommand->SetGuidance("Define a new alias as the subtraction of two values.");
188 subtractCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
189 subtractCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
190 subtractCommand->SetGuidance(" aliased value is alternated.");
191 G4UIparameter* newAlias2 = new G4UIparameter("new_alias",'s',false);
192 subtractCommand->SetParameter(newAlias2);
193 G4UIparameter* val2a = new G4UIparameter("value1",'d',false);
194 subtractCommand->SetParameter(val2a);
195 G4UIparameter* val2b = new G4UIparameter("value2",'d',false);
196 subtractCommand->SetParameter(val2b);
197
198 multiplyCommand = new G4UIcommand("/control/multiply",this);
199 multiplyCommand->SetGuidance("Define a new alias as the multiplification of two values.");
200 multiplyCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
201 multiplyCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
202 multiplyCommand->SetGuidance(" aliased value is alternated.");
203 G4UIparameter* newAlias3 = new G4UIparameter("new_alias",'s',false);
204 multiplyCommand->SetParameter(newAlias3);
205 G4UIparameter* val3a = new G4UIparameter("value1",'d',false);
206 multiplyCommand->SetParameter(val3a);
207 G4UIparameter* val3b = new G4UIparameter("value2",'d',false);
208 multiplyCommand->SetParameter(val3b);
209
210 divideCommand = new G4UIcommand("/control/divide",this);
211 divideCommand->SetGuidance("Define a new alias as the division of two values.");
212 divideCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
213 divideCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
214 divideCommand->SetGuidance(" aliased value is alternated.");
215 G4UIparameter* newAlias4 = new G4UIparameter("new_alias",'s',false);
216 divideCommand->SetParameter(newAlias4);
217 G4UIparameter* val4a = new G4UIparameter("value1",'d',false);
218 divideCommand->SetParameter(val4a);
219 G4UIparameter* val4b = new G4UIparameter("value2",'d',false);
220 val4b->SetParameterRange("value2 != 0.");
221 divideCommand->SetParameter(val4b);
222
223 remainderCommand = new G4UIcommand("/control/remainder",this);
224 remainderCommand->SetGuidance("Define a new alias as the remainder of two values.");
225 remainderCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
226 remainderCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
227 remainderCommand->SetGuidance(" aliased value is alternated.");
228 G4UIparameter* newAlias5 = new G4UIparameter("new_alias",'s',false);
229 remainderCommand->SetParameter(newAlias5);
230 G4UIparameter* val5a = new G4UIparameter("value1",'i',false);
231 remainderCommand->SetParameter(val5a);
232 G4UIparameter* val5b = new G4UIparameter("value2",'i',false);
233 val4b->SetParameterRange("value2 != 0");
234 remainderCommand->SetParameter(val5b);
235
236}
237
239{
240 delete macroPathCommand;
241 delete ExecuteCommand;
242 delete suppressAbortionCommand;
243 delete verboseCommand;
244 delete historyCommand;
245 delete stopStoreHistoryCommand;
246 delete ManualCommand;
247 delete aliasCommand;
248 delete unaliasCommand;
249 delete listAliasCommand;
250 delete getEnvCmd;
251 delete echoCmd;
252 delete shellCommand;
253 delete loopCommand;
254 delete foreachCommand;
255 delete HTMLCommand;
256 delete maxStoredHistCommand;
257 delete ifCommand;
258 delete addCommand;
259 delete subtractCommand;
260 delete multiplyCommand;
261 delete divideCommand;
262 delete remainderCommand;
263
264 delete controlDirectory;
265}
266
268{
270
271 if( command == macroPathCommand) {
272 UI-> SetMacroSearchPath(newValue);
273 UI-> ParseMacroSearchPath();
274 }
275 if(command==ExecuteCommand)
276 {
277 UI-> ExecuteMacroFile(UI-> FindMacroPath(newValue));
278 }
279 if(command==suppressAbortionCommand)
280 {
281 G4StateManager::GetStateManager()->SetSuppressAbortion(suppressAbortionCommand->GetNewIntValue(newValue));
282 }
283 if(command==verboseCommand)
284 {
285 UI->SetVerboseLevel(verboseCommand->GetNewIntValue(newValue));
286 }
287 if(command==historyCommand)
288 {
289 UI->StoreHistory(newValue);
290 }
291 if(command==stopStoreHistoryCommand)
292 {
293 UI->StoreHistory(false);
294 }
295 if(command==ManualCommand)
296 {
297 UI->ListCommands(newValue);
298 }
299 if(command==aliasCommand)
300 {
301 UI->SetAlias(newValue);
302 }
303 if(command==unaliasCommand)
304 {
305 UI->RemoveAlias(newValue);
306 }
307 if(command==listAliasCommand)
308 {
309 UI->ListAlias();
310 }
311 if(command==getEnvCmd)
312 {
313 if(getenv(newValue))
314 {
315 G4String st = "/control/alias ";
316 st += newValue;
317 st += " ";
318 st += getenv(newValue);
319 UI->ApplyCommand(st);
320 }
321 else
322 { G4cerr << "<" << newValue << "> is not defined as a shell variable. Command ignored." << G4endl; }
323 }
324 if(command==echoCmd)
325 { G4cout << UI->SolveAlias(newValue) << G4endl; }
326 if(command==shellCommand)
327 {
328 system(newValue);
329 }
330 if(command==loopCommand)
331 {
332 UI->LoopS(newValue);
333 }
334 if(command==foreachCommand)
335 {
336 UI->ForeachS(newValue);
337 }
338 if(command==HTMLCommand)
339 {
340 UI->CreateHTML(newValue);
341 }
342 if(command==maxStoredHistCommand)
343 {
344 UI->SetMaxHistSize(maxStoredHistCommand->GetNewIntValue(newValue));
345 }
346 if(command==ifCommand)
347 {
348 G4Tokenizer next(newValue);
349 G4double l = StoD(next());
350 G4String comp = next();
351 G4double r = StoD(next());
352 G4String mac = next();
353 G4bool x = false;
354 if(comp==">") x = (l>r);
355 else if(comp==">=") x = (l>=r);
356 else if(comp=="<") x = (l<r);
357 else if(comp=="<=") x = (l<=r);
358 else if(comp=="==") x = (l==r);
359 else if(comp=="!=") x = (l!=r);
360 if(x) UI->ExecuteMacroFile(mac);
361 }
362 if(command==addCommand)
363 {
364 G4Tokenizer next(newValue);
365 G4String newA = next();
366 G4double l = StoD(next());
367 G4double r = StoD(next());
368 G4String st = "/control/alias ";
369 st += newA;
370 st += " ";
371 st += DtoS(l+r);
372 UI->ApplyCommand(st);
373 }
374 if(command==subtractCommand)
375 {
376 G4Tokenizer next(newValue);
377 G4String newA = next();
378 G4double l = StoD(next());
379 G4double r = StoD(next());
380 G4String st = "/control/alias ";
381 st += newA;
382 st += " ";
383 st += DtoS(l-r);
384 UI->ApplyCommand(st);
385 }
386 if(command==multiplyCommand)
387 {
388 G4Tokenizer next(newValue);
389 G4String newA = next();
390 G4double l = StoD(next());
391 G4double r = StoD(next());
392 G4String st = "/control/alias ";
393 st += newA;
394 st += " ";
395 st += DtoS(l*r);
396 UI->ApplyCommand(st);
397 }
398 if(command==divideCommand)
399 {
400 G4Tokenizer next(newValue);
401 G4String newA = next();
402 G4double l = StoD(next());
403 G4double r = StoD(next());
404 G4String st = "/control/alias ";
405 st += newA;
406 st += " ";
407 st += DtoS(l/r);
408 UI->ApplyCommand(st);
409 }
410 if(command==remainderCommand)
411 {
412 G4Tokenizer next(newValue);
413 G4String newA = next();
414 G4int l = StoI(next());
415 G4int r = StoI(next());
416 G4String st = "/control/alias ";
417 st += newA;
418 st += " ";
419 st += DtoS(l%r);
420 UI->ApplyCommand(st);
421 }
422}
423
425{
427 G4String currentValue;
428
429 if( command == macroPathCommand ) {
430 currentValue = UI-> GetMacroSearchPath();
431 }
432 if(command==verboseCommand)
433 {
434 currentValue = verboseCommand->ConvertToString(UI->GetVerboseLevel());
435 }
436 if(command==suppressAbortionCommand)
437 {
438 currentValue = suppressAbortionCommand->ConvertToString(G4StateManager::GetStateManager()->GetSuppressAbortion());
439 }
440 if(command==maxStoredHistCommand)
441 {
442 currentValue = maxStoredHistCommand->ConvertToString(UI->GetMaxHistSize());
443 }
444
445 return currentValue;
446}
447
448
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cerr
G4DLLIMPORT std::ostream G4cout
void SetSuppressAbortion(G4int i)
static G4StateManager * GetStateManager()
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4int GetNewIntValue(const char *paramString)
void SetDefaultValue(G4int defVal)
static G4String ConvertToString(G4bool boolVal)
Definition: G4UIcommand.cc:349
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void ForeachS(const char *valueList)
Definition: G4UImanager.cc:283
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:369
void CreateHTML(const char *dir="/")
Definition: G4UImanager.cc:554
void LoopS(const char *valueList)
Definition: G4UImanager.cc:239
void StoreHistory(const char *fileName="G4history.macro")
Definition: G4UImanager.cc:425
void ListCommands(const char *direc)
Definition: G4UImanager.cc:450
void ExecuteMacroFile(const char *fileName)
Definition: G4UImanager.cc:230
void SetMaxHistSize(G4int mx)
Definition: G4UImanager.hh:229
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:218
void SetAlias(const char *aliasLine)
Definition: G4UImanager.cc:523
void RemoveAlias(const char *aliasName)
Definition: G4UImanager.cc:542
G4String SolveAlias(const char *aCmd)
Definition: G4UImanager.cc:316
void ListAlias()
Definition: G4UImanager.cc:549
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
G4int GetMaxHistSize() const
Definition: G4UImanager.hh:231
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:216
G4int StoI(G4String s)
G4String DtoS(G4double a)
G4double StoD(G4String s)
void SetDefaultValue(const char *theDefaultValue)
void SetParameterRange(const char *theRange)
void SetParameterCandidates(const char *theString)