Geant4 10.7.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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////////////// /vis/set/arrow3DLineSegmentsPerCircle ////////////////////////////////////
44
46{
47 G4bool omitable;
48 fpCommand = new G4UIcmdWithAnInteger("/vis/set/arrow3DLineSegmentsPerCircle", this);
49 fpCommand->SetGuidance
50 ("Defines number of line segments per circle for drawing 3D arrows"
51 " for future \"/vis/scene/add/\" commands.");
52 fpCommand->SetParameterName ("number", omitable = true);
53 fpCommand->SetDefaultValue (6);
54 fpCommand->SetRange("number >= 3");
55}
56
58{
59 delete fpCommand;
60}
61
63{
64 return G4String();
65}
66
68{
70
72
73 if (verbosity >= G4VisManager::confirmations) {
74 G4cout <<
75 "Number of line segments per circle for drawing 3D arrows for future"
76 "\n \"/vis/scene/add/\" commands has been set to "
78 << G4endl;
79 }
80}
81
82////////////// /vis/set/colour ////////////////////////////////////
83
85{
86 G4bool omitable;
87 fpCommand = new G4UIcommand("/vis/set/colour", this);
88 fpCommand->SetGuidance
89 ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
90 fpCommand->SetGuidance
91 ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)");
93 fpCommand->SetGuidance("Default: white and opaque.");
94 G4UIparameter* parameter;
95 parameter = new G4UIparameter ("red", 's', omitable = true);
96 parameter->SetGuidance
97 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
98 parameter->SetDefaultValue ("1.");
99 fpCommand->SetParameter (parameter);
100 parameter = new G4UIparameter ("green", 'd', omitable = true);
101 parameter->SetDefaultValue (1.);
102 fpCommand->SetParameter (parameter);
103 parameter = new G4UIparameter ("blue", 'd', omitable = true);
104 parameter->SetDefaultValue (1.);
105 fpCommand->SetParameter (parameter);
106 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
107 parameter->SetDefaultValue (1.);
108 parameter->SetGuidance ("Opacity");
109 fpCommand->SetParameter (parameter);
110}
111
113{
114 delete fpCommand;
115}
116
118{
119 return G4String();
120}
121
123{
125
126 G4String redOrString;
127 G4double green, blue, opacity;
128 std::istringstream iss(newValue);
129 iss >> redOrString >> green >> blue >> opacity;
130
131 ConvertToColour(fCurrentColour, redOrString, green, blue, opacity);
132
133 if (verbosity >= G4VisManager::confirmations) {
134 G4cout <<
135 "Colour for future \"/vis/scene/add/\" commands has been set to "
136 << fCurrentColour <<
137 ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)"
138 << G4endl;
139 }
140}
141
142////////////// /vis/set/extentForField ////////////////////////////////////
143
145{
146 G4bool omitable;
147 fpCommand = new G4UIcommand("/vis/set/extentForField", this);
148 fpCommand->SetGuidance
149 ("Sets an extent for future \"/vis/scene/add/*Field\" commands.");
150 fpCommand->SetGuidance
151 ("The default is a null extent, which is interpreted by the commands as the"
152 "\nextent of the whole scene.");
153 G4UIparameter* parameter;
154 parameter = new G4UIparameter ("xmin", 'd', omitable = true);
155 parameter->SetDefaultValue (0.);
156 fpCommand->SetParameter (parameter);
157 parameter = new G4UIparameter ("xmax", 'd', omitable = true);
158 parameter->SetDefaultValue (0.);
159 fpCommand->SetParameter (parameter);
160 parameter = new G4UIparameter ("ymin", 'd', omitable = true);
161 parameter->SetDefaultValue (0.);
162 fpCommand->SetParameter (parameter);
163 parameter = new G4UIparameter ("ymax", 'd', omitable = true);
164 parameter->SetDefaultValue (0.);
165 fpCommand->SetParameter (parameter);
166 parameter = new G4UIparameter ("zmin", 'd', omitable = true);
167 parameter->SetDefaultValue (0.);
168 fpCommand->SetParameter (parameter);
169 parameter = new G4UIparameter ("zmax", 'd', omitable = true);
170 parameter->SetDefaultValue (0.);
171 fpCommand->SetParameter (parameter);
172 parameter = new G4UIparameter ("unit", 's', omitable = true);
173 parameter->SetDefaultValue ("m");
174 fpCommand->SetParameter (parameter);
175}
176
178{
179 delete fpCommand;
180}
181
183{
184 return G4String();
185}
186
188{
190
191 G4double xmin, xmax, ymin, ymax, zmin, zmax;
192 G4String unitString;
193 std::istringstream iss(newValue);
194 iss >> xmin >> xmax >> ymin >> ymax >> zmin >> zmax >> unitString;
195 G4double unit = G4UIcommand::ValueOf(unitString);
196 xmin *= unit; xmax *= unit;
197 ymin *= unit; ymax *= unit;
198 zmin *= unit; zmax *= unit;
199
200 fCurrentExtentForField = G4VisExtent(xmin,xmax,ymin,ymax,zmin,zmax);
202
203 if (verbosity >= G4VisManager::confirmations) {
204 G4cout <<
205 "Extent for future \"/vis/scene/add/*Field\" commands has been set to "
207 << "\nVolume for field has been cleared."
208 << G4endl;
209 }
210}
211
212////////////// /vis/set/lineWidth ////////////////////////////////////
213
215{
216 G4bool omitable;
217 fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
218 fpCommand->SetGuidance
219 ("Defines line width for future \"/vis/scene/add/\" commands.");
220 fpCommand->SetParameterName ("lineWidth", omitable = true);
221 fpCommand->SetDefaultValue (1.);
222 fpCommand->SetRange("lineWidth >= 1.");
223}
224
226{
227 delete fpCommand;
228}
229
231{
232 return G4String();
233}
234
236{
238
239 fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue);
240
241 if (verbosity >= G4VisManager::confirmations) {
242 G4cout <<
243 "Line width for future \"/vis/scene/add/\" commands has been set to "
245 << G4endl;
246 }
247}
248
249////////////// /vis/set/textColour ////////////////////////////////////
250
252{
253 G4bool omitable;
254 fpCommand = new G4UIcommand("/vis/set/textColour", this);
255 fpCommand->SetGuidance
256 ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
258 fpCommand->SetGuidance("Default: blue and opaque.");
259 G4UIparameter* parameter;
260 parameter = new G4UIparameter ("red", 's', omitable = true);
261 parameter->SetGuidance
262 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
263 parameter->SetDefaultValue ("0.");
264 fpCommand->SetParameter (parameter);
265 parameter = new G4UIparameter ("green", 'd', omitable = true);
266 parameter->SetDefaultValue (0.);
267 fpCommand->SetParameter (parameter);
268 parameter = new G4UIparameter ("blue", 'd', omitable = true);
269 parameter->SetDefaultValue (1.);
270 fpCommand->SetParameter (parameter);
271 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
272 parameter->SetDefaultValue (1.);
273 parameter->SetGuidance ("Opacity");
274 fpCommand->SetParameter (parameter);
275}
276
278{
279 delete fpCommand;
280}
281
283{
284 return G4String();
285}
286
288{
290
291 G4String redOrString;
292 G4double green, blue, opacity;
293 std::istringstream iss(newValue);
294 iss >> redOrString >> green >> blue >> opacity;
295
296 ConvertToColour(fCurrentTextColour, redOrString, green, blue, opacity);
297
298 if (verbosity >= G4VisManager::confirmations) {
299 G4cout <<
300 "Colour for future \"/vis/scene/add/text\" commands has been set to "
301 << fCurrentTextColour << '.'
302 << G4endl;
303 }
304}
305
306////////////// /vis/set/textLayout ////////////////////////////////////
307
309{
310 G4bool omitable;
311 fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
312 fpCommand->SetGuidance
313 ("Defines layout future \"/vis/scene/add/text\" commands.");
314 fpCommand->SetGuidance
315 ("\"left\" (default) for left justification to provided coordinate.");
316 fpCommand->SetGuidance
317 ("\"centre\" or \"center\" for text centered on provided coordinate.");
318 fpCommand->SetGuidance
319 ("\"right\" for right justification to provided coordinate.");
320 fpCommand->SetGuidance("Default: left.");
321 fpCommand->SetParameterName("layout", omitable = true);
322 fpCommand->SetCandidates ("left centre center right");
323 fpCommand->SetDefaultValue ("left");
324}
325
327{
328 delete fpCommand;
329}
330
332{
333 return G4String();
334}
335
337{
339 if (newValue == "left") layout = G4Text::left;
340 else if (newValue == "centre" || newValue == "center")
341 layout = G4Text::centre;
342 else if (newValue == "right") layout = G4Text::right;
343
344 fCurrentTextLayout = layout;
345
347 if (verbosity >= G4VisManager::confirmations) {
348 G4cout << "Text layout (for future \"text\" commands) has been set to \""
349 << fCurrentTextLayout << "\"."
350 << G4endl;
351 }
352}
353
354////////////// /vis/set/textSize ////////////////////////////////////
355
357{
358 G4bool omitable;
359 fpCommand = new G4UIcmdWithADouble("/vis/set/textSize", this);
360 fpCommand->SetGuidance
361 ("Defines text size (pixels) for future \"/vis/scene/add/\" commands.");
362 fpCommand->SetParameterName ("textSize", omitable = true);
363 fpCommand->SetDefaultValue (12.); // pixels
364 fpCommand->SetRange("textSize >= 8.");
365}
366
368{
369 delete fpCommand;
370}
371
373{
374 return G4String();
375}
376
378{
380
381 fCurrentTextSize = fpCommand->GetNewDoubleValue(newValue);
382
383 if (verbosity >= G4VisManager::confirmations) {
384 G4cout <<
385 "Text size for future \"/vis/scene/add/\" commands has been set to "
387 << G4endl;
388 }
389}
390
391////////////// /vis/set/touchable ////////////////////////////////////
392
394{
395 G4bool omitable;
396 G4UIparameter* parameter;
397 fpCommand = new G4UIcommand("/vis/set/touchable", this);
398 fpCommand->SetGuidance
399 ("Defines touchable for future \"/vis/touchable/set/\" commands.");
400 fpCommand->SetGuidance
401 ("Please provide a list of space-separated physical volume names and"
402 "\ncopy number pairs starting at the world volume, e.g:"
403 "\n /vis/set/touchable World 0 Envelope 0 Shape1 0"
404 "\n(To get list of touchables, use \"/vis/drawTree\")"
405 "\n(To save, use \"/vis/viewer/save\")");
406 parameter = new G4UIparameter ("list", 's', omitable = true);
407 parameter->SetGuidance
408 ("List of physical volume names and copy number pairs");
409 fpCommand->SetParameter (parameter);
410}
411
413{
414 delete fpCommand;
415}
416
418{
419 return G4String();
420}
421
423{
425
426 if (newValue.isNull()) {
428 if (verbosity >= G4VisManager::confirmations) {
429 G4cout <<
430 "Current touchable reset to: " << fCurrentTouchableProperties.fTouchablePath
431 << G4endl;
432 }
433 return;
434 }
435
436 G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
437
438 // Algorithm from Josuttis p.476.
439 G4String::size_type iBegin, iEnd;
440 iBegin = newValue.find_first_not_of(' ');
441 while (iBegin != G4String::npos) {
442 iEnd = newValue.find_first_of(' ',iBegin);
443 if (iEnd == G4String::npos) {
444 iEnd = newValue.length();
445 }
446 G4String name(newValue.substr(iBegin,iEnd-iBegin));
447 iBegin = newValue.find_first_not_of(' ',iEnd);
448 if (iBegin == G4String::npos) {
449 if (verbosity >= G4VisManager::warnings) {
450 G4cout <<
451 "WARNING: G4VisCommandSetTouchable::SetNewValue"
452 "\n A pair not found. (Did you have an even number of parameters?)"
453 "\n Command ignored."
454 << G4endl;
455 return;
456 }
457 }
458 iEnd = newValue.find_first_of(' ',iBegin);
459 if (iEnd == G4String::npos) {
460 iEnd = newValue.length();
461 }
462 G4int copyNo;
463 std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
464 if (!(iss >> copyNo)) {
465 if (verbosity >= G4VisManager::warnings) {
466 G4cout <<
467 "WARNING: G4VisCommandSetTouchable::SetNewValue"
468 "\n Error reading copy number - it was not numeric?"
469 "\n Command ignored."
470 << G4endl;
471 return;
472 }
473 }
474 currentTouchablePath.push_back
476 iBegin = newValue.find_first_not_of(' ',iEnd);
477 }
478
479 // Check validity
480 G4bool successful = false;
481 G4TransportationManager* transportationManager =
483 size_t nWorlds = transportationManager->GetNoWorlds();
484 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
485 transportationManager->GetWorldsIterator();
486 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
487 G4PhysicalVolumeModel pvModel (*iterWorld); // Unlimited depth.
488 G4ModelingParameters mp; // Default - no culling.
489 pvModel.SetModelingParameters (&mp);
490 G4TouchablePropertiesScene scene (&pvModel,currentTouchablePath);
491 pvModel.DescribeYourselfTo (scene); // Initiate geometry tree traversal.
493 successful = true;
495 break; // Found, so no need to scan more worlds.
496 }
497 }
498
499 if (successful) {
500 if (verbosity >= G4VisManager::confirmations) {
501 G4cout <<
502 "Current touchable: " << fCurrentTouchableProperties.fTouchablePath
503 << G4endl;
504 return;
505 }
506 } else {
507 if (verbosity >= G4VisManager::warnings) {
508 G4cout <<
509 "WARNING: G4VisCommandSetTouchable::SetNewValue"
510 "\n Touchable not found."
511 << G4endl;
512 return;
513 }
514 }
515}
516
517////////////// /vis/set/volumeForField ////////////////////////////////////
518
520{
521 G4bool omitable;
522 G4UIparameter* parameter;
523 fpCommand = new G4UIcommand("/vis/set/volumeForField", this);
524 fpCommand->SetGuidance
525 ("Sets a volume for \"/vis/scene/add/*Field\" commands.");
526 fpCommand->SetGuidance
527 ("Takes a volume name or a /regular expression/ -- see guidance for"
528 "\n\"/vis/drawVolume\"");
529 parameter = new G4UIparameter ("physical-volume-name", 's', omitable = true);
530 parameter -> SetDefaultValue ("none");
531 fpCommand -> SetParameter (parameter);
532 parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
533 parameter -> SetGuidance ("If negative, matches any copy no.");
534 parameter -> SetDefaultValue (-1);
535 fpCommand -> SetParameter (parameter);
536 parameter = new G4UIparameter ("draw", 'b', omitable = true);
537 parameter -> SetGuidance ("If true, draw extent of found volumes.");
538 parameter -> SetDefaultValue (false);
539 fpCommand -> SetParameter (parameter);
540}
541
543{
544 delete fpCommand;
545}
546
548{
549 return G4String();
550}
551
553{
555
556 G4String name, drawString;
557 G4int copyNo;
558 std::istringstream is (newValue);
559 is >> name >> copyNo >> drawString;
560 G4bool draw = G4UIcmdWithABool::ConvertToBool(drawString);
561
562 if (name == "none") {
565 if (verbosity >= G4VisManager::warnings) {
566 G4cout << "Volume for field cleared" << G4endl;
567 }
568 return;
569 }
570
571 G4TransportationManager* transportationManager =
573 size_t nWorlds = transportationManager->GetNoWorlds();
574 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
575 transportationManager->GetWorldsIterator();
577 G4BoundingExtentScene extentScene;
578 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
579 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
580 G4ModelingParameters mp; // Default - no culling.
581 searchModel.SetModelingParameters (&mp);
582 G4PhysicalVolumesSearchScene searchScene (&searchModel, name, copyNo);
583 searchModel.DescribeYourselfTo (searchScene); // Initiate search.
584 for (const auto& findings: searchScene.GetFindings()) {
585 fCurrrentPVFindingsForField.push_back(findings);
586 G4VisExtent extent = findings.fpFoundPV->GetLogicalVolume()->GetSolid()->GetExtent();
587 extent.Transform(findings.fFoundObjectTransformation);
588 extentScene.AccrueBoundingExtent(extent);
589 }
590 }
591
592 if (fCurrrentPVFindingsForField.empty()) {
593 if (verbosity >= G4VisManager::errors) {
594 G4cerr << "ERROR: Volume \"" << name << "\"";
595 if (copyNo >= 0) {
596 G4cerr << ", copy no. " << copyNo << ",";
597 }
598 G4cerr << " not found." << G4endl;
599 }
600 return;
601 }
602
603 fCurrentExtentForField = extentScene.GetExtent();
604
606
607 if (verbosity >= G4VisManager::confirmations) {
608 for (const auto& findings: fCurrrentPVFindingsForField) {
609 G4cout
610 << "\"" << findings.fpFoundPV->GetName()
611 << "\", copy no. " << findings.fFoundPVCopyNo
612 << ", found\nin searched volume \""
613 << findings.fpSearchPV->GetName()
614 << "\" at depth " << findings.fFoundDepth
615 << ",\nbase path: \"" << findings.fFoundBasePVPath
616 << "\",\nand has been set as volume for field."
617 << G4endl;
618 }
619 }
620}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#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
G4bool isNull() 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()
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:348
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:530
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
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