Geant4 11.4.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// G4UIcontrolMessenger
27//
28// Author: Makoto Asai, SLAC - 2001
29// --------------------------------------------------------------------
30
32
33#include "G4StateManager.hh"
34#include "G4Tokenizer.hh"
35#include "G4UIaliasList.hh"
36#include "G4UIcmdWithABool.hh"
37#include "G4UIcmdWithAString.hh"
40#include "G4UIcommand.hh"
41#include "G4UIdirectory.hh"
42#include "G4UImanager.hh"
43#include "G4UIparameter.hh"
44#include "G4UIsession.hh"
45#include "G4ios.hh"
46
47#include <cstdlib>
48
49// --------------------------------------------------------------------
51{
52 controlDirectory = new G4UIdirectory("/control/");
53 controlDirectory->SetGuidance("UI control commands.");
54
55 macroPathCommand = new G4UIcmdWithAString("/control/macroPath", this);
56 macroPathCommand->SetGuidance(
57 "Set macro search path"
58 " with colon-separated list.");
59 macroPathCommand->SetParameterName("path", false);
60
61 ExecuteCommand = new G4UIcmdWithAString("/control/execute", this);
62 ExecuteCommand->SetGuidance("Execute a macro file.");
63 ExecuteCommand->SetParameterName("fileName", false);
64 ExecuteCommand->SetToBeBroadcasted(false);
65
66 loopCommand = new G4UIcommand("/control/loop", this);
67 loopCommand->SetGuidance("Execute a macro file more than once.");
68 loopCommand->SetGuidance("Loop counter can be used as an aliased variable.");
69 auto* param1 = new G4UIparameter("macroFile", 's', false);
70 loopCommand->SetParameter(param1);
71 auto* param2 = new G4UIparameter("counterName", 's', false);
72 loopCommand->SetParameter(param2);
73 auto* param3 = new G4UIparameter("initialValue", 'd', false);
74 loopCommand->SetParameter(param3);
75 auto* param4 = new G4UIparameter("finalValue", 'd', false);
76 loopCommand->SetParameter(param4);
77 auto* param5 = new G4UIparameter("stepSize", 'd', true);
78 param5->SetDefaultValue(1.0);
79 loopCommand->SetParameter(param5);
80 loopCommand->SetToBeBroadcasted(false);
81
82 foreachCommand = new G4UIcommand("/control/foreach", this);
83 foreachCommand->SetGuidance("Execute a macro file more than once.");
84 foreachCommand->SetGuidance("Loop counter can be used as an aliased variable.");
85 foreachCommand->SetGuidance("Values must be separated by a space.");
86 auto* param6 = new G4UIparameter("macroFile", 's', false);
87 foreachCommand->SetParameter(param6);
88 auto* param7 = new G4UIparameter("counterName", 's', false);
89 foreachCommand->SetParameter(param7);
90 auto* param8 = new G4UIparameter("valueList", 's', false);
91 foreachCommand->SetParameter(param8);
92 foreachCommand->SetToBeBroadcasted(false);
93
94 suppressAbortionCommand = new G4UIcmdWithAnInteger("/control/suppressAbortion", this);
95 suppressAbortionCommand->SetGuidance("Suppress the program abortion caused by G4Exception.");
96 suppressAbortionCommand->SetGuidance("Suppression level = 0 : no suppression");
97 suppressAbortionCommand->SetGuidance(" = 1 : suppress during EventProc state");
98 suppressAbortionCommand->SetGuidance(
99 " = 2 : full suppression, i.e. no abortion by "
100 "G4Exception");
101 suppressAbortionCommand->SetGuidance(
102 "When abortion is suppressed, you will get error messages issued by "
103 "G4Exception,");
104 suppressAbortionCommand->SetGuidance(
105 "and there is NO guarantee for the correct result after the G4Exception "
106 "error message.");
107 suppressAbortionCommand->SetParameterName("level", true);
108 suppressAbortionCommand->SetRange("level >= 0 && level <= 2");
109 suppressAbortionCommand->SetDefaultValue(0);
110
111 verboseCommand = new G4UIcmdWithAnInteger("/control/verbose", this);
112 verboseCommand->SetGuidance("Applied command will also be shown on screen.");
113 verboseCommand->SetGuidance("This command is useful with MACRO file.");
114 verboseCommand->SetGuidance(" 0 : silent");
115 verboseCommand->SetGuidance(" 1 : only the valid commands are shown.");
116 verboseCommand->SetGuidance(" 2 : comment lines are also shown (default).");
117 verboseCommand->SetParameterName("switch", true);
118 verboseCommand->SetRange("switch >= 0 && switch <=2");
119 verboseCommand->SetDefaultValue(2);
120
121 doublePrecCommand = new G4UIcmdWithABool("/control/useDoublePrecision", this);
122 doublePrecCommand->SetGuidance(
123 "Use double precision for printing out the current parameter value(s).");
124 doublePrecCommand->SetParameterName("useDoublePrecision", true);
125 doublePrecCommand->SetDefaultValue(true);
126
127 historyCommand = new G4UIcmdWithAString("/control/saveHistory", this);
128 historyCommand->SetGuidance("Store command history to a file.");
129 historyCommand->SetGuidance("Defaul file name is G4history.macro.");
130 historyCommand->SetParameterName("fileName", true);
131 historyCommand->SetDefaultValue("G4History.macro");
132 historyCommand->SetToBeBroadcasted(false);
133
134 stopStoreHistoryCommand = new G4UIcmdWithoutParameter("/control/stopSavingHistory", this);
135 stopStoreHistoryCommand->SetGuidance("Stop saving history file.");
136 stopStoreHistoryCommand->SetToBeBroadcasted(false);
137
138 aliasCommand = new G4UIcommand("/control/alias", this);
139 aliasCommand->SetGuidance("Set an alias.");
140 aliasCommand->SetGuidance("String can be aliased by this command.");
141 aliasCommand->SetGuidance("The string may contain one or more spaces,");
142 aliasCommand->SetGuidance("the string must be enclosed by double quotes (\").");
143 aliasCommand->SetGuidance("To use an alias, enclose the alias name with");
144 aliasCommand->SetGuidance("parenthesis \"{\" and \"}\".");
145 auto* aliasNameParam = new G4UIparameter("aliasName", 's', false);
146 aliasCommand->SetParameter(aliasNameParam);
147 auto* aliasValueParam = new G4UIparameter("aliasValue", 's', false);
148 aliasCommand->SetParameter(aliasValueParam);
149
150 unaliasCommand = new G4UIcmdWithAString("/control/unalias", this);
151 unaliasCommand->SetGuidance("Remove an alias.");
152 unaliasCommand->SetParameterName("aliasName", false);
153
154 listAliasCommand = new G4UIcmdWithoutParameter("/control/listAlias", this);
155 listAliasCommand->SetGuidance("List aliases.");
156
157 getEnvCmd = new G4UIcmdWithAString("/control/getEnv", this);
158 getEnvCmd->SetGuidance("Get a shell environment variable and define it as an alias.");
159 getEnvCmd->SetToBeBroadcasted(false);
160
161 getValCmd = new G4UIcommand("/control/getVal", this);
162 getValCmd->SetGuidance("Get the current value of the UI command and define it as an alias.");
163 getValCmd->SetGuidance(
164 "Command is ignored if the UI command does not support GetCurrentValue().");
165 getValCmd->SetGuidance(" Syntax : <alias_name> <UI_command> <iIdx>");
166 auto* aliName = new G4UIparameter("alias_name", 's', false);
167 getValCmd->SetParameter(aliName);
168 auto* comName = new G4UIparameter("UI_command", 's', false);
169 getValCmd->SetParameter(comName);
170 auto* iIdxParam = new G4UIparameter("iIdx", 'i', true);
171 iIdxParam->SetDefaultValue(0);
172 getValCmd->SetParameter(iIdxParam);
173 getValCmd->SetToBeBroadcasted(false);
174
175 echoCmd = new G4UIcmdWithAString("/control/echo", this);
176 echoCmd->SetGuidance("Display the valuerameter string.");
177 echoCmd->SetGuidance("If alias is contained, it is converted to the aliased value.");
178
179 shellCommand = new G4UIcmdWithAString("/control/shell", this);
180 shellCommand->SetGuidance("Execute a (Unix) SHELL command.");
181 shellCommand->SetToBeBroadcasted(false);
182
183 ManualCommand = new G4UIcmdWithAString("/control/manual", this);
184 ManualCommand->SetGuidance("Display all of sub-directories and commands.");
185 ManualCommand->SetGuidance("Directory path should be given by FULL-PATH.");
186 ManualCommand->SetParameterName("dirPath", true);
187 ManualCommand->SetDefaultValue("/");
188 ManualCommand->SetToBeBroadcasted(false);
189
190 HTMLCommand = new G4UIcmdWithAString("/control/createHTML", this);
191 HTMLCommand->SetGuidance("Generate HTML files for all of sub-directories and commands.");
192 HTMLCommand->SetGuidance("Directory path should be given by FULL-PATH.");
193 HTMLCommand->SetParameterName("dirPath", true);
194 HTMLCommand->SetDefaultValue("/");
195 HTMLCommand->SetToBeBroadcasted(false);
196
197 maxStoredHistCommand = new G4UIcmdWithAnInteger("/control/maximumStoredHistory", this);
198 maxStoredHistCommand->SetGuidance("Set maximum number of stored UI commands.");
199 maxStoredHistCommand->SetParameterName("max", true);
200 maxStoredHistCommand->SetDefaultValue(20);
201
202 ifCommand = new G4UIcommand("/control/if", this);
203 ifCommand->SetGuidance("Execute a macro file if the expression is true.");
204 ifCommand->SetGuidance(" Syntax : <double> <comp> <double> <macro_file>");
205 auto* leftParam = new G4UIparameter("left", 'd', false);
206 ifCommand->SetParameter(leftParam);
207 auto* compParam = new G4UIparameter("comp", 's', false);
208 compParam->SetParameterCandidates("> >= < <= == !=");
209 ifCommand->SetParameter(compParam);
210 auto* rightParam = new G4UIparameter("right", 'd', false);
211 ifCommand->SetParameter(rightParam);
212 auto* macroFileParam = new G4UIparameter("macroFile", 's', false);
213 ifCommand->SetParameter(macroFileParam);
214 ifCommand->SetToBeBroadcasted(false);
215
216 doifCommand = new G4UIcommand("/control/doif", this);
217 doifCommand->SetGuidance("Execute a UI command if the expression is true.");
218 doifCommand->SetGuidance(" Syntax : <double> <comp> <double> <UI_command>");
219 auto* doleftParam = new G4UIparameter("left", 'd', false);
220 doifCommand->SetParameter(doleftParam);
221 auto* docompParam = new G4UIparameter("comp", 's', false);
222 docompParam->SetParameterCandidates("> >= < <= == !=");
223 doifCommand->SetParameter(docompParam);
224 auto* dorightParam = new G4UIparameter("right", 'd', false);
225 doifCommand->SetParameter(dorightParam);
226 auto* comParam = new G4UIparameter("UI_command", 's', false);
227 doifCommand->SetParameter(comParam);
228 doifCommand->SetToBeBroadcasted(false);
229
230 addCommand = new G4UIcommand("/control/add", this);
231 addCommand->SetGuidance("Define a new alias as the sum of two values.");
232 addCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
233 addCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
234 addCommand->SetGuidance(" aliased value is alternated.");
235 auto* newAlias1 = new G4UIparameter("new_alias", 's', false);
236 addCommand->SetParameter(newAlias1);
237 auto* val1a = new G4UIparameter("value1", 'd', false);
238 addCommand->SetParameter(val1a);
239 auto* val1b = new G4UIparameter("value2", 'd', false);
240 addCommand->SetParameter(val1b);
241 addCommand->SetToBeBroadcasted(false);
242
243 subtractCommand = new G4UIcommand("/control/subtract", this);
244 subtractCommand->SetGuidance("Define a new alias as the subtraction of two values.");
245 subtractCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
246 subtractCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
247 subtractCommand->SetGuidance(" aliased value is alternated.");
248 auto* newAlias2 = new G4UIparameter("new_alias", 's', false);
249 subtractCommand->SetParameter(newAlias2);
250 auto* val2a = new G4UIparameter("value1", 'd', false);
251 subtractCommand->SetParameter(val2a);
252 auto* val2b = new G4UIparameter("value2", 'd', false);
253 subtractCommand->SetParameter(val2b);
254 subtractCommand->SetToBeBroadcasted(false);
255
256 multiplyCommand = new G4UIcommand("/control/multiply", this);
257 multiplyCommand->SetGuidance("Define a new alias as the multiplication of two values.");
258 multiplyCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
259 multiplyCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
260 multiplyCommand->SetGuidance(" aliased value is alternated.");
261 auto* newAlias3 = new G4UIparameter("new_alias", 's', false);
262 multiplyCommand->SetParameter(newAlias3);
263 auto* val3a = new G4UIparameter("value1", 'd', false);
264 multiplyCommand->SetParameter(val3a);
265 auto* val3b = new G4UIparameter("value2", 'd', false);
266 multiplyCommand->SetParameter(val3b);
267 multiplyCommand->SetToBeBroadcasted(false);
268
269 divideCommand = new G4UIcommand("/control/divide", this);
270 divideCommand->SetGuidance("Define a new alias as the division of two values.");
271 divideCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
272 divideCommand->SetGuidance(" <new_alias> may be an already existing alias. If it is the case,");
273 divideCommand->SetGuidance(" aliased value is alternated.");
274 auto* newAlias4 = new G4UIparameter("new_alias", 's', false);
275 divideCommand->SetParameter(newAlias4);
276 auto* val4a = new G4UIparameter("value1", 'd', false);
277 divideCommand->SetParameter(val4a);
278 auto* val4b = new G4UIparameter("value2", 'd', false);
279 val4b->SetParameterRange("value2 != 0.");
280 divideCommand->SetParameter(val4b);
281 divideCommand->SetToBeBroadcasted(false);
282
283 remainderCommand = new G4UIcommand("/control/remainder", this);
284 remainderCommand->SetGuidance("Define a new alias as the remainder of two values.");
285 remainderCommand->SetGuidance(" Syntax : <new_alias> <value1> <value2>");
286 remainderCommand->SetGuidance(
287 " <new_alias> may be an already existing alias. If it is the case,");
288 remainderCommand->SetGuidance(" aliased value is alternated.");
289 auto* newAlias5 = new G4UIparameter("new_alias", 's', false);
290 remainderCommand->SetParameter(newAlias5);
291 auto* val5a = new G4UIparameter("value1", 'i', false);
292 remainderCommand->SetParameter(val5a);
293 auto* val5b = new G4UIparameter("value2", 'i', false);
294 val4b->SetParameterRange("value2 != 0");
295 remainderCommand->SetParameter(val5b);
296 remainderCommand->SetToBeBroadcasted(false);
297
298 strifCommand = new G4UIcommand("/control/strif", this);
299 strifCommand->SetGuidance("Execute a macro file if the expression is true.");
300 strifCommand->SetGuidance(" Syntax : <string> <comp> <string> <macro_file>");
301 auto* strleftParam = new G4UIparameter("left", 's', false);
302 strifCommand->SetParameter(strleftParam);
303 auto* strcompParam = new G4UIparameter("comp", 's', false);
304 strcompParam->SetParameterCandidates("== !=");
305 strifCommand->SetParameter(strcompParam);
306 auto* strrightParam = new G4UIparameter("right", 's', false);
307 strifCommand->SetParameter(strrightParam);
308 auto* strmacroFileParam = new G4UIparameter("macroFile", 's', false);
309 strifCommand->SetParameter(strmacroFileParam);
310 strifCommand->SetToBeBroadcasted(false);
311
312 strdoifCommand = new G4UIcommand("/control/strdoif", this);
313 strdoifCommand->SetGuidance("Execute a UI command if the expression is true.");
314 strdoifCommand->SetGuidance(" Syntax : <string> <comp> <string> <UI_command>");
315 auto* strdoleftParam = new G4UIparameter("left", 's', false);
316 strdoifCommand->SetParameter(strdoleftParam);
317 auto* strdocompParam = new G4UIparameter("comp", 's', false);
318 strdocompParam->SetParameterCandidates("== !=");
319 strdoifCommand->SetParameter(strdocompParam);
320 auto* strdorightParam = new G4UIparameter("right", 's', false);
321 strdoifCommand->SetParameter(strdorightParam);
322 auto* strdomacroFileParam = new G4UIparameter("UI_command", 's', false);
323 strdoifCommand->SetParameter(strdomacroFileParam);
324 strdoifCommand->SetToBeBroadcasted(false);
325
326 ifBatchCommand = new G4UIcmdWithAString("/control/ifBatch", this);
327 ifBatchCommand->SetGuidance("Execute a macro file if program is running in batch mode.");
328 ifBatchCommand->SetParameterName("macroFile", false);
329 ifBatchCommand->SetToBeBroadcasted(false);
330
331 ifInteractiveCommand = new G4UIcmdWithAString("/control/ifInteractive", this);
332 ifInteractiveCommand->SetGuidance(
333 "Execute a macro file if program is running in interactive mode.");
334 ifInteractiveCommand->SetParameterName("macroFile", false);
335 ifInteractiveCommand->SetToBeBroadcasted(false);
336
337 doifBatchCommand = new G4UIcmdWithAString("/control/doifBatch", this);
338 doifBatchCommand->SetGuidance("Execute a UI command if program is running in batch mode.");
339 doifBatchCommand->SetParameterName("UIcommand", false);
340 doifBatchCommand->SetToBeBroadcasted(false);
341
342 doifInteractiveCommand = new G4UIcmdWithAString("/control/doifInteractive", this);
343 doifInteractiveCommand->SetGuidance(
344 "Execute a UI command if program is running in interactive mode.");
345 doifInteractiveCommand->SetParameterName("UIcommand", false);
346 doifInteractiveCommand->SetToBeBroadcasted(false);
347
348 recordToMacroCommand = new G4UIcommand("/control/recordToMacro",this);
349 recordToMacroCommand->SetGuidance(
350 "Record the following UI command(s) into a macro file instead of executing it/them.");
351 recordToMacroCommand->SetGuidance(
352 "Recording lasts until a command \"/control/endRecord\" comes.");
353 recordToMacroCommand->SetGuidance(
354 "if <ifAppend> is set to true (default false), commands are appended to the existing file.");
355 auto* recordToMacroCommandParam = new G4UIparameter("fileName",'s',false);
356 recordToMacroCommand->SetParameter(recordToMacroCommandParam);
357 recordToMacroCommandParam = new G4UIparameter("ifAppend",'b',true);
358 recordToMacroCommandParam->SetDefaultValue(false);
359 recordToMacroCommand->SetParameter(recordToMacroCommandParam);
360 recordToMacroCommand->SetToBeBroadcasted(false);
361
362 endRecordCommand = new G4UIcmdWithoutParameter("/control/endRecord", this);
363 endRecordCommand->SetGuidance("Stop recording to a macro");
364 endRecordCommand->SetToBeBroadcasted(false);
365}
366
367// --------------------------------------------------------------------
369{
370 delete macroPathCommand;
371 delete ExecuteCommand;
372 delete suppressAbortionCommand;
373 delete verboseCommand;
374 delete doublePrecCommand;
375 delete historyCommand;
376 delete stopStoreHistoryCommand;
377 delete ManualCommand;
378 delete aliasCommand;
379 delete unaliasCommand;
380 delete listAliasCommand;
381 delete getEnvCmd;
382 delete getValCmd;
383 delete echoCmd;
384 delete shellCommand;
385 delete loopCommand;
386 delete foreachCommand;
387 delete HTMLCommand;
388 delete maxStoredHistCommand;
389 delete ifCommand;
390 delete doifCommand;
391 delete addCommand;
392 delete subtractCommand;
393 delete multiplyCommand;
394 delete divideCommand;
395 delete remainderCommand;
396 delete strifCommand;
397 delete strdoifCommand;
398 delete ifBatchCommand;
399 delete ifInteractiveCommand;
400 delete doifBatchCommand;
401 delete doifInteractiveCommand;
402 delete recordToMacroCommand;
403 delete endRecordCommand;
404 delete controlDirectory;
405}
406
407// --------------------------------------------------------------------
409{
411
412 if (command == macroPathCommand) {
413 UI->SetMacroSearchPath(newValue);
415 }
416 if (command == ExecuteCommand) {
417 command->ResetFailure();
418 UI->ExecuteMacroFile(UI->FindMacroPath(newValue));
419 if (UI->GetLastReturnCode() != 0) {
421 ed << "Command aborted (" << UI->GetLastReturnCode() << ")";
422 command->CommandFailed(UI->GetLastReturnCode(), ed);
423 }
424 }
425 if (command == suppressAbortionCommand) {
427 suppressAbortionCommand->GetNewIntValue(newValue));
428 }
429 if (command == verboseCommand) {
430 UI->SetVerboseLevel(verboseCommand->GetNewIntValue(newValue));
431 }
432 if (command == doublePrecCommand) {
433 G4UImanager::UseDoublePrecisionStr(doublePrecCommand->GetNewBoolValue(newValue));
434 }
435 if (command == historyCommand) {
436 UI->StoreHistory(newValue);
437 }
438 if (command == stopStoreHistoryCommand) {
439 UI->StoreHistory(false);
440 }
441 if (command == ManualCommand) {
442 UI->ListCommands(newValue);
443 }
444 if (command == aliasCommand) {
445 UI->SetAlias(newValue);
446 }
447 if (command == unaliasCommand) {
448 UI->RemoveAlias(newValue);
449 }
450 if (command == listAliasCommand) {
451 UI->ListAlias();
452 }
453 if (command == getEnvCmd) {
454 command->ResetFailure();
455 if (std::getenv(newValue) != nullptr) {
456 G4String st = newValue;
457 st += " ";
458 st += std::getenv(newValue);
459 UI->SetAlias(st.c_str());
460 }
461 else {
463 ed << "<" << newValue << "> is not defined as a shell variable. Command ignored.";
464 command->CommandFailed(ed);
465 }
466 }
467 if (command == getValCmd) {
468 G4Tokenizer next(newValue);
469 const G4String& aliName = next();
470 const G4String& com = next();
471 const G4String& curVal = UI->GetCurrentValues(com);
472 if (!(curVal.empty())) {
473 G4String theValue = curVal;
474 G4String iIdx = next();
475 if (!(iIdx.empty())) {
476 G4int idx = StoI(iIdx);
477 G4Tokenizer nextVal(curVal);
478 for (G4int i = 0; i <= idx; i++) {
479 theValue = nextVal();
480 }
481 }
482 G4String st = "/control/alias ";
483 st += aliName + " " + theValue;
484 UI->ApplyCommand(st);
485 }
486 }
487 if (command == echoCmd) {
488 G4cout << UI->SolveAlias(newValue) << G4endl;
489 }
490 if (command == shellCommand) {
491 command->ResetFailure();
492 G4int rc = system(newValue);
493 if (rc < 0) {
495 ed << "<" << newValue << "> is not a valid shell command. Command ignored.";
496 command->CommandFailed(ed);
497 }
498 }
499 if (command == loopCommand) {
500 command->ResetFailure();
501 UI->LoopS(newValue);
502 if (UI->GetLastReturnCode() != 0) {
504 ed << "Command aborted (" << UI->GetLastReturnCode() << ")";
505 command->CommandFailed(UI->GetLastReturnCode(), ed);
506 }
507 }
508 if (command == foreachCommand) {
509 command->ResetFailure();
510 UI->ForeachS(newValue);
511 if (UI->GetLastReturnCode() != 0) {
513 ed << "Command aborted (" << UI->GetLastReturnCode() << ")";
514 command->CommandFailed(UI->GetLastReturnCode(), ed);
515 }
516 }
517 if (command == HTMLCommand) {
518 UI->CreateHTML(newValue);
519 }
520 if (command == maxStoredHistCommand) {
521 UI->SetMaxHistSize(maxStoredHistCommand->GetNewIntValue(newValue));
522 }
523 if (command == ifCommand) {
524 G4Tokenizer next(newValue);
525 G4double l = StoD(next());
526 const G4String& comp = next();
527 G4double r = StoD(next());
528 const G4String& mac = next();
529 G4bool x = false;
530 if (comp == ">") {
531 x = (l > r);
532 }
533 else if (comp == ">=") {
534 x = (l >= r);
535 }
536 else if (comp == "<") {
537 x = (l < r);
538 }
539 else if (comp == "<=") {
540 x = (l <= r);
541 }
542 else if (comp == "==") {
543 x = (l == r);
544 }
545 else if (comp == "!=") {
546 x = (l != r);
547 }
548 if (x) {
549 UI->ExecuteMacroFile(UI->FindMacroPath(mac));
550 }
551 }
552 if (command == doifCommand) {
553 G4Tokenizer next(newValue);
554 G4double l = StoD(next());
555 const G4String& comp = next();
556 G4double r = StoD(next());
557
558 G4String c1 = next();
559 G4String ca;
560 while (!((ca = next()).empty())) {
561 c1 += " ";
562 c1 += ca;
563 }
564 if (c1[0] == '"') {
565 G4String strippedValue;
566 if (c1.back() == '"') {
567 strippedValue = c1.substr(1, c1.length() - 2);
568 }
569 else {
570 strippedValue = c1.substr(1, c1.length() - 1);
571 }
572 c1 = std::move(strippedValue);
573 }
574
575 G4bool x = false;
576 if (comp == ">") {
577 x = (l > r);
578 }
579 else if (comp == ">=") {
580 x = (l >= r);
581 }
582 else if (comp == "<") {
583 x = (l < r);
584 }
585 else if (comp == "<=") {
586 x = (l <= r);
587 }
588 else if (comp == "==") {
589 x = (l == r);
590 }
591 else if (comp == "!=") {
592 x = (l != r);
593 }
594 if (x) {
595 UI->ApplyCommand(c1);
596 }
597 }
598 if (command == addCommand) {
599 G4Tokenizer next(newValue);
600 const G4String& newA = next();
601 G4double l = StoD(next());
602 G4double r = StoD(next());
603 G4String st = "/control/alias ";
604 st += newA;
605 st += " ";
606 st += DtoS(l + r);
607 UI->ApplyCommand(st);
608 }
609 if (command == subtractCommand) {
610 G4Tokenizer next(newValue);
611 const G4String& newA = next();
612 G4double l = StoD(next());
613 G4double r = StoD(next());
614 G4String st = "/control/alias ";
615 st += newA;
616 st += " ";
617 st += DtoS(l - r);
618 UI->ApplyCommand(st);
619 }
620 if (command == multiplyCommand) {
621 G4Tokenizer next(newValue);
622 const G4String& newA = next();
623 G4double l = StoD(next());
624 G4double r = StoD(next());
625 G4String st = "/control/alias ";
626 st += newA;
627 st += " ";
628 st += DtoS(l * r);
629 UI->ApplyCommand(st);
630 }
631 if (command == divideCommand) {
632 G4Tokenizer next(newValue);
633 const G4String& newA = next();
634 G4double l = StoD(next());
635 G4double r = StoD(next());
636 G4String st = "/control/alias ";
637 st += newA;
638 st += " ";
639 st += DtoS(l / r);
640 UI->ApplyCommand(st);
641 }
642 if (command == remainderCommand) {
643 G4Tokenizer next(newValue);
644 const G4String& newA = next();
645 G4int l = StoI(next());
646 G4int r = StoI(next());
647 G4String st = "/control/alias ";
648 st += newA;
649 st += " ";
650 st += DtoS(l % r);
651 UI->ApplyCommand(st);
652 }
653 if (command == strifCommand) {
654 G4Tokenizer next(newValue);
655 const G4String& l = next();
656 const G4String& comp = next();
657 const G4String& r = next();
658 const G4String& mac = next();
659 G4bool x = false;
660 if (comp == "==") {
661 x = (l == r);
662 }
663 else if (comp == "!=") {
664 x = (l != r);
665 }
666 if (x) {
667 UI->ExecuteMacroFile(UI->FindMacroPath(mac));
668 }
669 }
670 if (command == strdoifCommand) {
671 G4Tokenizer next(newValue);
672 const G4String& l = next();
673 const G4String& comp = next();
674 const G4String& r = next();
675
676 G4String c1 = next();
677 G4String ca;
678 while (!((ca = next()).empty())) {
679 c1 += " ";
680 c1 += ca;
681 }
682 if (c1[0] == '"') {
683 G4String strippedValue;
684 if (c1.back() == '"') {
685 strippedValue = c1.substr(1, c1.length() - 2);
686 }
687 else {
688 strippedValue = c1.substr(1, c1.length() - 1);
689 }
690 c1 = std::move(strippedValue);
691 }
692
693 G4bool x = false;
694 if (comp == "==") {
695 x = (l == r);
696 }
697 else if (comp == "!=") {
698 x = (l != r);
699 }
700 if (x) {
701 UI->ApplyCommand(c1);
702 }
703 }
704 if (command == ifBatchCommand) {
705 if (G4UIsession::InSession() == 0) {
706 UI->ExecuteMacroFile(UI->FindMacroPath(newValue));
707 }
708 }
709 if (command == ifInteractiveCommand) {
710 if (G4UIsession::InSession() > 0) {
711 UI->ExecuteMacroFile(UI->FindMacroPath(newValue));
712 }
713 }
714 if (command == doifBatchCommand) {
715 if (G4UIsession::InSession() == 0) {
716 UI->ApplyCommand(newValue);
717 }
718 }
719 if (command == doifInteractiveCommand) {
720 if (G4UIsession::InSession() > 0) {
721 UI->ApplyCommand(newValue);
722 }
723 }
724 if (command == recordToMacroCommand) {
725 G4Tokenizer next(newValue);
726 const G4String& fn = next();
727 G4bool ifAppend = StoB(next());
728 UI->StartRecording(fn,ifAppend);
729 }
730 if (command == endRecordCommand) {
731 UI->ApplyCommand("/control/endRecord");
732 }
733}
734
735// --------------------------------------------------------------------
737{
739 G4String currentValue;
740
741 if (command == macroPathCommand) {
742 currentValue = UI->GetMacroSearchPath();
743 }
744 if (command == verboseCommand) {
745 currentValue = verboseCommand->ConvertToString(UI->GetVerboseLevel());
746 }
747 if (command == doublePrecCommand) {
748 currentValue = doublePrecCommand->ConvertToString(G4UImanager::DoublePrecisionStr());
749 }
750 if (command == suppressAbortionCommand) {
751 currentValue = suppressAbortionCommand->ConvertToString(
752 G4StateManager::GetStateManager()->GetSuppressAbortion());
753 }
754 if (command == maxStoredHistCommand) {
755 currentValue = maxStoredHistCommand->ConvertToString(UI->GetMaxHistSize());
756 }
757
758 return currentValue;
759}
std::ostringstream G4ExceptionDescription
double G4double
Definition G4Types.hh:83
bool G4bool
Definition G4Types.hh:86
int G4int
Definition G4Types.hh:85
#define G4endl
Definition G4ios.hh:67
G4GLOB_DLL std::ostream G4cout
void SetSuppressAbortion(G4int i)
static G4StateManager * GetStateManager()
void ResetFailure()
void CommandFailed(G4int errCode, G4ExceptionDescription &ed)
void SetNewValue(G4UIcommand *command, G4String newValue) override
G4String GetCurrentValue(G4UIcommand *command) override
static G4bool DoublePrecisionStr()
static void UseDoublePrecisionStr(G4bool val)
const G4String & GetMacroSearchPath() const
void ForeachS(const char *valueList)
G4int ApplyCommand(const char *aCommand)
void CreateHTML(const char *dir="/")
void LoopS(const char *valueList)
void StoreHistory(const char *fileName="G4history.macro")
void ListCommands(const char *direc)
void ExecuteMacroFile(const char *fileName)
void SetMacroSearchPath(const G4String &path)
void SetMaxHistSize(G4int mx)
G4int GetVerboseLevel() const
G4int GetLastReturnCode() const
G4String GetCurrentValues(const char *aCommand)
void SetAlias(const char *aliasLine)
G4String FindMacroPath(const G4String &fname) const
void RemoveAlias(const char *aliasName)
G4String SolveAlias(const char *aCmd)
void ListAlias()
void ParseMacroSearchPath()
static G4UImanager * GetUIpointer()
void StartRecording(G4String fn, G4bool ifAppend, G4bool ifTemp=false, G4String assocCmd="**NOCMD**")
G4int GetMaxHistSize() const
void SetVerboseLevel(G4int val)
G4bool StoB(const G4String &s)
G4double StoD(const G4String &s)
G4String DtoS(G4double a)
G4int StoI(const G4String &s)
static G4int InSession()