Geant4-11
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
44
46{
47 G4bool omitable;
48 fpCommand = new G4UIcmdWithAnInteger("/vis/set/arrow3DLineSegmentsPerCircle", this);
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);
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
83
85{
86 G4bool omitable;
87 fpCommand = new G4UIcommand("/vis/set/colour", this);
89 ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
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
143
145{
146 G4bool omitable;
147 fpCommand = new G4UIcommand("/vis/set/extentForField", this);
149 ("Sets an extent for future \"/vis/scene/add/*Field\" commands.");
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 = false);
155 fpCommand->SetParameter (parameter);
156 parameter = new G4UIparameter ("xmax", 'd', omitable = false);
157 fpCommand->SetParameter (parameter);
158 parameter = new G4UIparameter ("ymin", 'd', omitable = false);
159 fpCommand->SetParameter (parameter);
160 parameter = new G4UIparameter ("ymax", 'd', omitable = false);
161 fpCommand->SetParameter (parameter);
162 parameter = new G4UIparameter ("zmin", 'd', omitable = false);
163 fpCommand->SetParameter (parameter);
164 parameter = new G4UIparameter ("zmax", 'd', omitable = false);
165 fpCommand->SetParameter (parameter);
166 parameter = new G4UIparameter ("unit", 's', omitable = false);
167 fpCommand->SetParameter (parameter);
168}
169
171{
172 delete fpCommand;
173}
174
176{
177 return G4String();
178}
179
181{
183
184 G4double xmin, xmax, ymin, ymax, zmin, zmax;
185 G4String unitString;
186 std::istringstream iss(newValue);
187 iss >> xmin >> xmax >> ymin >> ymax >> zmin >> zmax >> unitString;
188 G4double unit = G4UIcommand::ValueOf(unitString);
189 xmin *= unit; xmax *= unit;
190 ymin *= unit; ymax *= unit;
191 zmin *= unit; zmax *= unit;
192
193 fCurrentExtentForField = G4VisExtent(xmin,xmax,ymin,ymax,zmin,zmax);
195
196 if (verbosity >= G4VisManager::confirmations) {
197 G4cout <<
198 "Extent for future \"/vis/scene/add/*Field\" commands has been set to "
200 << "\nVolume for field has been cleared."
201 << G4endl;
202 }
203}
204
206
208{
209 G4bool omitable;
210 fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
212 ("Defines line width for future \"/vis/scene/add/\" commands.");
213 fpCommand->SetParameterName ("lineWidth", omitable = true);
215 fpCommand->SetRange("lineWidth >= 1.");
216}
217
219{
220 delete fpCommand;
221}
222
224{
225 return G4String();
226}
227
229{
231
233
234 if (verbosity >= G4VisManager::confirmations) {
235 G4cout <<
236 "Line width for future \"/vis/scene/add/\" commands has been set to "
238 << G4endl;
239 }
240}
241
243
245{
246 G4bool omitable;
247 fpCommand = new G4UIcommand("/vis/set/textColour", this);
249 ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
251 fpCommand->SetGuidance("Default: blue and opaque.");
252 G4UIparameter* parameter;
253 parameter = new G4UIparameter ("red", 's', omitable = true);
254 parameter->SetGuidance
255 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
256 parameter->SetDefaultValue ("0.");
257 fpCommand->SetParameter (parameter);
258 parameter = new G4UIparameter ("green", 'd', omitable = true);
259 parameter->SetDefaultValue (0.);
260 fpCommand->SetParameter (parameter);
261 parameter = new G4UIparameter ("blue", 'd', omitable = true);
262 parameter->SetDefaultValue (1.);
263 fpCommand->SetParameter (parameter);
264 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
265 parameter->SetDefaultValue (1.);
266 parameter->SetGuidance ("Opacity");
267 fpCommand->SetParameter (parameter);
268}
269
271{
272 delete fpCommand;
273}
274
276{
277 return G4String();
278}
279
281{
283
284 G4String redOrString;
285 G4double green, blue, opacity;
286 std::istringstream iss(newValue);
287 iss >> redOrString >> green >> blue >> opacity;
288
289 ConvertToColour(fCurrentTextColour, redOrString, green, blue, opacity);
290
291 if (verbosity >= G4VisManager::confirmations) {
292 G4cout <<
293 "Colour for future \"/vis/scene/add/text\" commands has been set to "
294 << fCurrentTextColour << '.'
295 << G4endl;
296 }
297}
298
300
302{
303 G4bool omitable;
304 fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
306 ("Defines layout future \"/vis/scene/add/text\" commands.");
308 ("\"left\" (default) for left justification to provided coordinate.");
310 ("\"centre\" or \"center\" for text centered on provided coordinate.");
312 ("\"right\" for right justification to provided coordinate.");
313 fpCommand->SetGuidance("Default: left.");
314 fpCommand->SetParameterName("layout", omitable = true);
315 fpCommand->SetCandidates ("left centre center right");
316 fpCommand->SetDefaultValue ("left");
317}
318
320{
321 delete fpCommand;
322}
323
325{
326 return G4String();
327}
328
330{
332 if (newValue == "left") layout = G4Text::left;
333 else if (newValue == "centre" || newValue == "center")
334 layout = G4Text::centre;
335 else if (newValue == "right") layout = G4Text::right;
336
337 fCurrentTextLayout = layout;
338
340 if (verbosity >= G4VisManager::confirmations) {
341 G4cout << "Text layout (for future \"text\" commands) has been set to \""
342 << fCurrentTextLayout << "\"."
343 << G4endl;
344 }
345}
346
348
350{
351 G4bool omitable;
352 fpCommand = new G4UIcmdWithADouble("/vis/set/textSize", this);
354 ("Defines text size (pixels) for future \"/vis/scene/add/\" commands.");
355 fpCommand->SetParameterName ("textSize", omitable = true);
356 fpCommand->SetDefaultValue (12.); // pixels
357 fpCommand->SetRange("textSize >= 8.");
358}
359
361{
362 delete fpCommand;
363}
364
366{
367 return G4String();
368}
369
371{
373
375
376 if (verbosity >= G4VisManager::confirmations) {
377 G4cout <<
378 "Text size for future \"/vis/scene/add/\" commands has been set to "
380 << G4endl;
381 }
382}
383
385
387{
388 G4bool omitable;
389 G4UIparameter* parameter;
390 fpCommand = new G4UIcommand("/vis/set/touchable", this);
392 ("Defines touchable for future \"/vis/touchable/set/\" commands.");
394 ("Please provide a list of space-separated physical volume names and"
395 "\ncopy number pairs starting at the world volume, e.g:"
396 "\n /vis/set/touchable World 0 Envelope 0 Shape1 0"
397 "\n(To get list of touchables, use \"/vis/drawTree\")"
398 "\n(To save, use \"/vis/viewer/save\")");
399 parameter = new G4UIparameter ("list", 's', omitable = true);
400 parameter->SetGuidance
401 ("List of physical volume names and copy number pairs");
402 fpCommand->SetParameter (parameter);
403}
404
406{
407 delete fpCommand;
408}
409
411{
412 return G4String();
413}
414
416{
418
419 if (newValue.empty()) {
421 if (verbosity >= G4VisManager::confirmations) {
422 G4cout <<
423 "Current touchable reset to: " << fCurrentTouchableProperties.fTouchablePath
424 << G4endl;
425 }
426 return;
427 }
428
429 G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
430
431 // Algorithm from Josuttis p.476.
432 G4String::size_type iBegin, iEnd;
433 iBegin = newValue.find_first_not_of(' ');
434 while (iBegin != G4String::npos) {
435 iEnd = newValue.find_first_of(' ',iBegin);
436 if (iEnd == G4String::npos) {
437 iEnd = newValue.length();
438 }
439 G4String name(newValue.substr(iBegin,iEnd-iBegin));
440 iBegin = newValue.find_first_not_of(' ',iEnd);
441 if (iBegin == G4String::npos) {
442 if (verbosity >= G4VisManager::warnings) {
443 G4cout <<
444 "WARNING: G4VisCommandSetTouchable::SetNewValue"
445 "\n A pair not found. (There should be an even number of parameters.)"
446 "\n Command ignored."
447 << G4endl;
448 return;
449 }
450 }
451 iEnd = newValue.find_first_of(' ',iBegin);
452 if (iEnd == G4String::npos) {
453 iEnd = newValue.length();
454 }
455 G4int copyNo;
456 std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
457 if (!(iss >> copyNo)) {
458 if (verbosity >= G4VisManager::warnings) {
459 G4cout <<
460 "WARNING: G4VisCommandSetTouchable::SetNewValue"
461 "\n Error reading copy number - it was not numeric?"
462 "\n Command ignored."
463 << G4endl;
464 return;
465 }
466 }
467 currentTouchablePath.push_back
469 iBegin = newValue.find_first_not_of(' ',iEnd);
470 }
471
472 // Check validity
473 G4bool successful = false;
474 G4TransportationManager* transportationManager =
476 size_t nWorlds = transportationManager->GetNoWorlds();
477 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
478 transportationManager->GetWorldsIterator();
479 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
480 G4PhysicalVolumeModel pvModel (*iterWorld); // Unlimited depth.
481 G4ModelingParameters mp; // Default - no culling.
482 pvModel.SetModelingParameters (&mp);
483 G4TouchablePropertiesScene scene (&pvModel,currentTouchablePath);
484 pvModel.DescribeYourselfTo (scene); // Initiate geometry tree traversal.
486 successful = true;
488 break; // Found, so no need to scan more worlds.
489 }
490 }
491
492 if (successful) {
493 if (verbosity >= G4VisManager::confirmations) {
494 G4cout <<
495 "Current touchable: " << fCurrentTouchableProperties.fTouchablePath
496 << G4endl;
497 return;
498 }
499 } else {
500 if (verbosity >= G4VisManager::warnings) {
501 G4cout <<
502 "WARNING: G4VisCommandSetTouchable::SetNewValue"
503 "\n Touchable not found."
504 << G4endl;
505 return;
506 }
507 }
508}
509
511
513{
514 G4bool omitable;
515 G4UIparameter* parameter;
516 fpCommand = new G4UIcommand("/vis/set/volumeForField", this);
518 ("Sets a volume for \"/vis/scene/add/*Field\" commands.");
520 ("Takes a volume name or a /regular expression/ -- see guidance for"
521 "\n\"/vis/drawVolume\"");
522 parameter = new G4UIparameter ("physical-volume-name", 's', omitable = false);
523 fpCommand -> SetParameter (parameter);
524 parameter = new G4UIparameter ("copy-no", 'i', omitable = true);
525 parameter -> SetGuidance ("If negative, matches any copy no.");
526 parameter -> SetDefaultValue (-1);
527 fpCommand -> SetParameter (parameter);
528 parameter = new G4UIparameter ("draw", 'b', omitable = true);
529 parameter -> SetGuidance ("If true, draw extent of found volumes.");
530 parameter -> SetDefaultValue (false);
531 fpCommand -> SetParameter (parameter);
532}
533
535{
536 delete fpCommand;
537}
538
540{
541 return G4String();
542}
543
545{
547
548 G4String name, drawString;
549 G4int copyNo;
550 std::istringstream is (newValue);
551 is >> name >> copyNo >> drawString;
552 G4bool draw = G4UIcmdWithABool::ConvertToBool(drawString);
553
554 G4TransportationManager* transportationManager =
556 size_t nWorlds = transportationManager->GetNoWorlds();
557 std::vector<G4VPhysicalVolume*>::iterator iterWorld =
558 transportationManager->GetWorldsIterator();
560 G4BoundingExtentScene extentScene;
561 for (size_t i = 0; i < nWorlds; ++i, ++iterWorld) {
562 G4PhysicalVolumeModel searchModel (*iterWorld); // Unlimited depth.
563 G4ModelingParameters mp; // Default - no culling.
564 searchModel.SetModelingParameters (&mp);
565 // Find all instances at any position in the tree
566 G4PhysicalVolumesSearchScene searchScene (&searchModel, name, copyNo);
567 searchModel.DescribeYourselfTo (searchScene); // Initiate search.
568 for (const auto& findings: searchScene.GetFindings()) {
569 fCurrrentPVFindingsForField.push_back(findings);
570 G4VisExtent extent = findings.fpFoundPV->GetLogicalVolume()->GetSolid()->GetExtent();
571 extent.Transform(findings.fFoundObjectTransformation);
572 extentScene.AccrueBoundingExtent(extent);
573 }
574 }
575
576 if (fCurrrentPVFindingsForField.empty()) {
577 if (verbosity >= G4VisManager::errors) {
578 G4cerr << "ERROR: Volume \"" << name << "\"";
579 if (copyNo >= 0) {
580 G4cerr << ", copy no. " << copyNo << ",";
581 }
582 G4cerr << " not found." << G4endl;
583 }
584 return;
585 }
586
587 fCurrentExtentForField = extentScene.GetExtent();
588
590
591 if (verbosity >= G4VisManager::confirmations) {
592 for (const auto& findings: fCurrrentPVFindingsForField) {
593 G4cout
594 << "\"" << findings.fpFoundPV->GetName()
595 << "\", copy no. " << findings.fFoundPVCopyNo
596 << ", found\nin searched volume \""
597 << findings.fpSearchPV->GetName()
598 << "\" at depth " << findings.fFoundDepth
599 << ",\nbase path: \"" << findings.fFoundBasePVPath
600 << "\",\nand has been set as volume for field."
601 << G4endl;
602 }
603 }
604}
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
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:363
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:545
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)
G4UIcmdWithADouble * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADouble * fpCommand
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()
const char * name(G4int ptype)
G4ModelingParameters::PVNameCopyNoPath fTouchablePath