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