Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4VisCommandsSet.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
28// /vis/set - John Allison 21st March 2012
29// Set quantities for use in appropriate future commands.
30
31#include "G4VisCommandsSet.hh"
32
33#include "G4UIcommand.hh"
35#include "G4UIcmdWithADouble.hh"
36#include "G4UIcmdWithAString.hh"
37#include "G4UIcmdWithABool.hh"
41#include <sstream>
42
43#define G4warn G4cout
44
45////////////// /vis/set/arrow3DLineSegmentsPerCircle ////////////////////////////////////
46
48{
49 G4bool omitable;
50 fpCommand = new G4UIcmdWithAnInteger("/vis/set/arrow3DLineSegmentsPerCircle", this);
51 fpCommand->SetGuidance
52 ("Defines number of line segments per circle for drawing 3D arrows"
53 " for future \"/vis/scene/add/\" commands.");
54 fpCommand->SetParameterName ("number", omitable = true);
55 fpCommand->SetDefaultValue (6);
56 fpCommand->SetRange("number >= 3");
57}
58
60{
61 delete fpCommand;
62}
63
65{
66 return G4String();
67}
68
70{
72
74
75 if (verbosity >= G4VisManager::confirmations) {
76 G4cout <<
77 "Number of line segments per circle for drawing 3D arrows for future"
78 "\n \"/vis/scene/add/\" commands has been set to "
80 << G4endl;
81 }
82}
83
84////////////// /vis/set/colour ////////////////////////////////////
85
87{
88 G4bool omitable;
89 fpCommand = new G4UIcommand("/vis/set/colour", this);
90 fpCommand->SetGuidance
91 ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
92 fpCommand->SetGuidance
93 ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)");
95 fpCommand->SetGuidance("Default: white and opaque.");
96 G4UIparameter* parameter;
97 parameter = new G4UIparameter ("red", 's', omitable = true);
98 parameter->SetGuidance
99 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
100 parameter->SetDefaultValue ("1.");
101 fpCommand->SetParameter (parameter);
102 parameter = new G4UIparameter ("green", 'd', omitable = true);
103 parameter->SetDefaultValue (1.);
104 fpCommand->SetParameter (parameter);
105 parameter = new G4UIparameter ("blue", 'd', omitable = true);
106 parameter->SetDefaultValue (1.);
107 fpCommand->SetParameter (parameter);
108 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
109 parameter->SetDefaultValue (1.);
110 parameter->SetGuidance ("Opacity");
111 fpCommand->SetParameter (parameter);
112}
113
115{
116 delete fpCommand;
117}
118
120{
121 return G4String();
122}
123
125{
127
128 G4String redOrString;
129 G4double green, blue, opacity;
130 std::istringstream iss(newValue);
131 iss >> redOrString >> green >> blue >> opacity;
132
133 ConvertToColour(fCurrentColour, redOrString, green, blue, opacity);
134
135 if (verbosity >= G4VisManager::confirmations) {
136 G4cout <<
137 "Colour for future \"/vis/scene/add/\" commands has been set to "
138 << fCurrentColour <<
139 ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)"
140 << G4endl;
141 }
142}
143
144////////////// /vis/set/extentForField ////////////////////////////////////
145
147{
148 G4bool omitable;
149 fpCommand = new G4UIcommand("/vis/set/extentForField", this);
150 fpCommand->SetGuidance
151 ("Sets an extent for future \"/vis/scene/add/*Field\" commands.");
152 fpCommand->SetGuidance
153 ("The default is a null extent, which is interpreted by the commands as the"
154 "\nextent of the whole scene.");
155 G4UIparameter* parameter;
156 parameter = new G4UIparameter ("xmin", 'd', omitable = false);
157 fpCommand->SetParameter (parameter);
158 parameter = new G4UIparameter ("xmax", 'd', omitable = false);
159 fpCommand->SetParameter (parameter);
160 parameter = new G4UIparameter ("ymin", 'd', omitable = false);
161 fpCommand->SetParameter (parameter);
162 parameter = new G4UIparameter ("ymax", 'd', omitable = false);
163 fpCommand->SetParameter (parameter);
164 parameter = new G4UIparameter ("zmin", 'd', omitable = false);
165 fpCommand->SetParameter (parameter);
166 parameter = new G4UIparameter ("zmax", 'd', omitable = false);
167 fpCommand->SetParameter (parameter);
168 parameter = new G4UIparameter ("unit", 's', omitable = false);
169 fpCommand->SetParameter (parameter);
170}
171
173{
174 delete fpCommand;
175}
176
178{
179 return G4String();
180}
181
183{
185
186 G4double xmin, xmax, ymin, ymax, zmin, zmax;
187 G4String unitString;
188 std::istringstream iss(newValue);
189 iss >> xmin >> xmax >> ymin >> ymax >> zmin >> zmax >> unitString;
190 G4double unit = G4UIcommand::ValueOf(unitString);
191 xmin *= unit; xmax *= unit;
192 ymin *= unit; ymax *= unit;
193 zmin *= unit; zmax *= unit;
194
195 fCurrentExtentForField = G4VisExtent(xmin,xmax,ymin,ymax,zmin,zmax);
197
198 if (verbosity >= G4VisManager::confirmations) {
199 G4cout <<
200 "Extent for future \"/vis/scene/add/*Field\" commands has been set to "
202 << "\nVolume for field has been cleared."
203 << G4endl;
204 }
205}
206
207////////////// /vis/set/lineWidth ////////////////////////////////////
208
210{
211 G4bool omitable;
212 fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
213 fpCommand->SetGuidance
214 ("Defines line width for future \"/vis/scene/add/\" commands."
215 "\nSee \"/vis/viewer/set/lineWidth\" for more information.");
216 fpCommand->SetParameterName ("lineWidth", omitable = true);
217 fpCommand->SetDefaultValue (1.);
218 fpCommand->SetRange("lineWidth >= 1.");
219}
220
222{
223 delete fpCommand;
224}
225
227{
228 return G4String();
229}
230
232{
234
235 fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue);
236
237 if (verbosity >= G4VisManager::warnings) {
238 G4warn <<
239 "Line width for *future* \"/vis/scene/add/\" commands has been set to "
241 "\nSee \"/vis/viewer/set/lineWidth\" for more information."
242 << G4endl;
243 }
244}
245
246////////////// /vis/set/textColour ////////////////////////////////////
247
249{
250 G4bool omitable;
251 fpCommand = new G4UIcommand("/vis/set/textColour", this);
252 fpCommand->SetGuidance
253 ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
255 fpCommand->SetGuidance("Default: blue and opaque.");
256 G4UIparameter* parameter;
257 parameter = new G4UIparameter ("red", 's', omitable = true);
258 parameter->SetGuidance
259 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
260 parameter->SetDefaultValue ("0.");
261 fpCommand->SetParameter (parameter);
262 parameter = new G4UIparameter ("green", 'd', omitable = true);
263 parameter->SetDefaultValue (0.);
264 fpCommand->SetParameter (parameter);
265 parameter = new G4UIparameter ("blue", 'd', omitable = true);
266 parameter->SetDefaultValue (1.);
267 fpCommand->SetParameter (parameter);
268 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
269 parameter->SetDefaultValue (1.);
270 parameter->SetGuidance ("Opacity");
271 fpCommand->SetParameter (parameter);
272}
273
275{
276 delete fpCommand;
277}
278
280{
281 return G4String();
282}
283
285{
287
288 G4String redOrString;
289 G4double green, blue, opacity;
290 std::istringstream iss(newValue);
291 iss >> redOrString >> green >> blue >> opacity;
292
293 ConvertToColour(fCurrentTextColour, redOrString, green, blue, opacity);
294
295 if (verbosity >= G4VisManager::confirmations) {
296 G4cout <<
297 "Colour for future \"/vis/scene/add/text\" commands has been set to "
298 << fCurrentTextColour << '.'
299 << G4endl;
300 }
301}
302
303////////////// /vis/set/textLayout ////////////////////////////////////
304
306{
307 G4bool omitable;
308 fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
309 fpCommand->SetGuidance
310 ("Defines layout future \"/vis/scene/add/text\" commands.");
311 fpCommand->SetGuidance
312 ("\"left\" (default) for left justification to provided coordinate.");
313 fpCommand->SetGuidance
314 ("\"centre\" or \"center\" for text centered on provided coordinate.");
315 fpCommand->SetGuidance
316 ("\"right\" for right justification to provided coordinate.");
317 fpCommand->SetGuidance("Default: left.");
318 fpCommand->SetParameterName("layout", omitable = true);
319 fpCommand->SetCandidates ("left centre center right");
320 fpCommand->SetDefaultValue ("left");
321}
322
324{
325 delete fpCommand;
326}
327
329{
330 return G4String();
331}
332
334{
336 if (newValue == "left") layout = G4Text::left;
337 else if (newValue == "centre" || newValue == "center")
338 layout = G4Text::centre;
339 else if (newValue == "right") layout = G4Text::right;
340
341 fCurrentTextLayout = layout;
342
344 if (verbosity >= G4VisManager::confirmations) {
345 G4cout << "Text layout (for future \"text\" commands) has been set to \""
346 << fCurrentTextLayout << "\"."
347 << G4endl;
348 }
349}
350
351////////////// /vis/set/textSize ////////////////////////////////////
352
354{
355 G4bool omitable;
356 fpCommand = new G4UIcmdWithADouble("/vis/set/textSize", this);
357 fpCommand->SetGuidance
358 ("Defines text size (pixels) for future \"/vis/scene/add/\" commands.");
359 fpCommand->SetParameterName ("textSize", omitable = true);
360 fpCommand->SetDefaultValue (12.); // pixels
361 fpCommand->SetRange("textSize >= 8.");
362}
363
365{
366 delete fpCommand;
367}
368
370{
371 return G4String();
372}
373
375{
377
378 fCurrentTextSize = fpCommand->GetNewDoubleValue(newValue);
379
380 if (verbosity >= G4VisManager::confirmations) {
381 G4cout <<
382 "Text size for future \"/vis/scene/add/\" commands has been set to "
384 << G4endl;
385 }
386}
387
388////////////// /vis/set/touchable ////////////////////////////////////
389
391{
392 G4bool omitable;
393 G4UIparameter* parameter;
394 fpCommand = new G4UIcommand("/vis/set/touchable", this);
395 fpCommand->SetGuidance
396 ("Defines touchable for future \"/vis/touchable/set/\" commands.");
397 fpCommand->SetGuidance
398 ("Please provide a list of space-separated physical volume names and"
399 "\ncopy number pairs starting at the world volume, e.g:"
400 "\n /vis/set/touchable World 0 Envelope 0 Shape1 0"
401 "\n(To get list of touchables, use \"/vis/drawTree\")"
402 "\n(To save, use \"/vis/viewer/save\")");
403 parameter = new G4UIparameter ("list", 's', omitable = true);
404 parameter->SetGuidance
405 ("List of physical volume names and copy number pairs");
406 fpCommand->SetParameter (parameter);
407}
408
410{
411 delete fpCommand;
412}
413
415{
416 return G4String();
417}
418
420{
422
423 if (newValue.empty()) {
425 if (verbosity >= G4VisManager::confirmations) {
426 G4cout <<
427 "Current touchable reset to: " << fCurrentTouchableProperties.fTouchablePath
428 << G4endl;
429 }
430 return;
431 }
432
433 G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
434
435 // Algorithm from Josuttis p.476.
436 G4String::size_type iBegin, iEnd;
437 iBegin = newValue.find_first_not_of(' ');
438 while (iBegin != G4String::npos) {
439 iEnd = newValue.find_first_of(' ',iBegin);
440 if (iEnd == G4String::npos) {
441 iEnd = newValue.length();
442 }
443 G4String name(newValue.substr(iBegin,iEnd-iBegin));
444 iBegin = newValue.find_first_not_of(' ',iEnd);
445 if (iBegin == G4String::npos) {
446 if (verbosity >= G4VisManager::warnings) {
447 G4warn <<
448 "WARNING: G4VisCommandSetTouchable::SetNewValue"
449 "\n A pair not found. (There should be an even number of parameters.)"
450 "\n Command ignored."
451 << G4endl;
452 return;
453 }
454 }
455 iEnd = newValue.find_first_of(' ',iBegin);
456 if (iEnd == G4String::npos) {
457 iEnd = newValue.length();
458 }
459 G4int copyNo;
460 std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
461 if (!(iss >> copyNo)) {
462 if (verbosity >= G4VisManager::warnings) {
463 G4warn <<
464 "WARNING: G4VisCommandSetTouchable::SetNewValue"
465 "\n Error reading copy number - it was not numeric?"
466 "\n Command ignored."
467 << G4endl;
468 return;
469 }
470 }
471 currentTouchablePath.push_back
473 iBegin = newValue.find_first_not_of(' ',iEnd);
474 }
475
476 // Check validity
477 G4bool successful = false;
478 G4TransportationManager* transportationManager =
480 size_t nWorlds = transportationManager->GetNoWorlds();
481 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
482 transportationManager->GetWorldsIterator();
483 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
484 G4PhysicalVolumeModel pvModel (*iterWorld); // Unlimited depth.
485 G4ModelingParameters mp; // Default - no culling.
486 pvModel.SetModelingParameters (&mp);
487 G4TouchablePropertiesScene scene (&pvModel,currentTouchablePath);
488 pvModel.DescribeYourselfTo (scene); // Initiate geometry tree traversal.
490 successful = true;
492 break; // Found, so no need to scan more worlds.
493 }
494 }
495
496 if (successful) {
497 if (verbosity >= G4VisManager::confirmations) {
498 G4cout <<
499 "Current touchable: " << fCurrentTouchableProperties.fTouchablePath
500 << G4endl;
501 return;
502 }
503 } else {
504 if (verbosity >= G4VisManager::warnings) {
505 G4warn <<
506 "WARNING: G4VisCommandSetTouchable::SetNewValue"
507 "\n Touchable not found."
508 << G4endl;
509 return;
510 }
511 }
512}
513
514////////////// /vis/set/volumeForField ////////////////////////////////////
515
517{
518 G4bool omitable;
519 G4UIparameter* parameter;
520 fpCommand = new G4UIcommand("/vis/set/volumeForField", this);
521 fpCommand->SetGuidance
522 ("Sets a volume for \"/vis/scene/add/*Field\" commands.");
523 fpCommand->SetGuidance
524 ("Takes a volume name or a /regular expression/ -- see guidance for"
525 "\n\"/vis/drawVolume\"");
526 parameter = new G4UIparameter ("physical-volume-name", 's', omitable = false);
527 fpCommand -> SetParameter (parameter);
528 parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
529 parameter -> SetGuidance ("If negative, matches any copy no.");
530 parameter -> SetDefaultValue (-1);
531 fpCommand -> SetParameter (parameter);
532 parameter = new G4UIparameter ("draw", 'b', omitable = true);
533 parameter -> SetGuidance ("If true, draw extent of found volumes.");
534 parameter -> SetDefaultValue (false);
535 fpCommand -> SetParameter (parameter);
536}
537
539{
540 delete fpCommand;
541}
542
544{
545 return G4String();
546}
547
549{
551
552 G4String name, drawString;
553 G4int copyNo;
554 std::istringstream is (newValue);
555 is >> name >> copyNo >> drawString;
556 G4bool draw = G4UIcmdWithABool::ConvertToBool(drawString);
557
558 G4TransportationManager* transportationManager =
560 size_t nWorlds = transportationManager->GetNoWorlds();
561 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
562 transportationManager->GetWorldsIterator();
564 G4BoundingExtentScene extentScene;
565 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
566 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
567 G4ModelingParameters mp; // Default - no culling.
568 searchModel.SetModelingParameters (&mp);
569 // Find all instances at any position in the tree
570 G4PhysicalVolumesSearchScene searchScene (&searchModel, name, copyNo);
571 searchModel.DescribeYourselfTo (searchScene); // Initiate search.
572 for (const auto& findings: searchScene.GetFindings()) {
573 fCurrrentPVFindingsForField.push_back(findings);
574 G4VisExtent extent = findings.fpFoundPV->GetLogicalVolume()->GetSolid()->GetExtent();
575 extent.Transform(findings.fFoundObjectTransformation);
576 extentScene.AccrueBoundingExtent(extent);
577 }
578 }
579
580 if (fCurrrentPVFindingsForField.empty()) {
581 if (verbosity >= G4VisManager::errors) {
582 G4warn << "ERROR: Volume \"" << name << "\"";
583 if (copyNo >= 0) {
584 G4warn << ", copy no. " << copyNo << ",";
585 }
586 G4warn << " not found." << G4endl;
587 }
588 return;
589 }
590
591 fCurrentExtentForField = extentScene.GetExtent();
592
594
595 if (verbosity >= G4VisManager::confirmations) {
596 for (const auto& findings: fCurrrentPVFindingsForField) {
597 G4cout
598 << "\"" << findings.fpFoundPV->GetName()
599 << "\", copy no. " << findings.fFoundPVCopyNo
600 << ", found\nin searched volume \""
601 << findings.fpSearchPV->GetName()
602 << "\" at depth " << findings.fFoundDepth
603 << ",\nbase path: \"" << findings.fFoundBasePVPath
604 << "\",\nand has been set as volume for field."
605 << G4endl;
606 }
607 }
608}
#define G4warn
Definition: G4Scene.cc:41
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 AccrueBoundingExtent(const G4VisExtent &)
const G4VisExtent & GetExtent() const
std::vector< PVNameCopyNo > PVNameCopyNoPath
void DescribeYourselfTo(G4VGraphicsScene &)
const std::vector< Findings > & GetFindings() const
Layout
Definition: G4Text.hh:76
@ centre
Definition: G4Text.hh:76
@ right
Definition: G4Text.hh:76
@ left
Definition: G4Text.hh:76
const G4PhysicalVolumeModel::TouchableProperties & GetFoundTouchableProperties() const
static G4TransportationManager * GetTransportationManager()
std::vector< G4VPhysicalVolume * >::iterator GetWorldsIterator()
std::size_t GetNoWorlds() const
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4double GetNewDoubleValue(const char *paramString)
void SetDefaultValue(G4double defVal)
void SetCandidates(const char *candidateList)
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 G4double ValueOf(const char *unitName)
Definition: G4UIcommand.cc:362
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:157
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:549
void SetRange(const char *rs)
Definition: G4UIcommand.hh:121
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
void SetModelingParameters(const G4ModelingParameters *)
static G4double fCurrentTextSize
static G4Colour fCurrentTextColour
static std::vector< G4PhysicalVolumesSearchScene::Findings > fCurrrentPVFindingsForField
void ConvertToColour(G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
static G4VisManager * fpVisManager
static G4VisExtent fCurrentExtentForField
void DrawExtent(const G4VisExtent &)
const G4String & ConvertToColourGuidance()
static G4int fCurrentArrow3DLineSegmentsPerCircle
static G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
static G4Text::Layout fCurrentTextLayout
static G4double fCurrentLineWidth
static G4Colour fCurrentColour
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4VisExtent & Transform(const G4Transform3D &)
Definition: G4VisExtent.cc:102
static Verbosity GetVerbosity()
G4ModelingParameters::PVNameCopyNoPath fTouchablePath