Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
G4VisCommandsTouchableSet.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// $Id$
28
29// /vis/touchable/set commands - John Allison 8th October 2012
30
32
33#include "G4UIcommand.hh"
34#include "G4UIcmdWithABool.hh"
35#include "G4UIcmdWithADouble.hh"
37#include "G4UIcmdWithAString.hh"
38
39#include <sstream>
40#include <cctype>
41
42////////////// /vis/touchable/set/colour ///////////////////////////////////////
43
45{
46 G4bool omitable;
47 G4UIparameter* parameter;
48
49 fpCommandSetColour = new G4UIcommand
50 ("/vis/touchable/set/colour", this);
51 fpCommandSetColour->SetGuidance("Set colour of current touchable.");
52 fpCommandSetColour->SetGuidance
53 ("Use \"/vis/set/touchable\" to set current touchable.");
54 parameter = new G4UIparameter("red", 's', omitable = true);
55 parameter->SetDefaultValue("1.");
56 parameter->SetGuidance
57 ("Red component or a string, e.g., \"blue\", in which case succeeding colour"
58 "\ncomponents are ignored.");
59 fpCommandSetColour->SetParameter(parameter);
60 parameter = new G4UIparameter("green", 'd', omitable = true);
61 parameter->SetDefaultValue(1.);
62 fpCommandSetColour->SetParameter(parameter);
63 parameter = new G4UIparameter("blue", 'd', omitable = true);
64 parameter->SetDefaultValue(1.);
65 fpCommandSetColour->SetParameter(parameter);
66 parameter = new G4UIparameter("opacity", 'd', omitable = true);
67 parameter->SetDefaultValue(1.);
68 fpCommandSetColour->SetParameter(parameter);
69
70 fpCommandSetDaughtersInvisible = new G4UIcmdWithABool
71 ("/vis/touchable/set/daughtersInvisible", this);
72 fpCommandSetDaughtersInvisible->SetGuidance
73 ("Daughters of current touchable invisible: true/false.");
74 fpCommandSetDaughtersInvisible->SetGuidance
75 ("Use \"/vis/set/touchable\" to set current touchable.");
76 fpCommandSetDaughtersInvisible->SetParameterName("daughtersInvisible", omitable = true);
77 fpCommandSetDaughtersInvisible->SetDefaultValue(false);
78
79 fpCommandSetForceAuxEdgeVisible = new G4UIcmdWithABool
80 ("/vis/touchable/set/forceAuxEdgeVisible", this);
81 fpCommandSetForceAuxEdgeVisible->SetGuidance
82 ("Force auxiliary (soft) edges of current touchable to be visible:"
83 " true/false.");
84 fpCommandSetForceAuxEdgeVisible->SetGuidance
85 ("Use \"/vis/set/touchable\" to set current touchable.");
86 fpCommandSetForceAuxEdgeVisible->SetParameterName("forceAuxEdgeVisible", omitable = true);
87 fpCommandSetForceAuxEdgeVisible->SetDefaultValue(false);
88
89 fpCommandSetLineSegmentsPerCircle = new G4UIcmdWithAnInteger
90 ("/vis/touchable/set/lineSegmentsPerCircle", this);
91 fpCommandSetLineSegmentsPerCircle->SetGuidance
92 ("For current touchable, set number of line segments per circle, the"
93 "\nprecision with which a curved line or surface is represented by a"
94 "\npolygon or polyhedron, regardless of the view parameters."
95 "\nNegative to pick up G4Polyhedron default value.");
96 fpCommandSetLineSegmentsPerCircle->SetGuidance
97 ("Use \"/vis/set/touchable\" to set current touchable.");
98 fpCommandSetLineSegmentsPerCircle->SetParameterName("lineSegmentsPerCircle", omitable = true);
99 fpCommandSetLineSegmentsPerCircle->SetDefaultValue(-1);
100
101 fpCommandSetForceSolid = new G4UIcmdWithABool
102 ("/vis/touchable/set/forceSolid", this);
103 fpCommandSetForceSolid->SetGuidance
104 ("Force current touchable always to be drawn solid (surface drawing).");
105 fpCommandSetForceSolid->SetGuidance
106 ("Use \"/vis/set/touchable\" to set current touchable.");
107 fpCommandSetForceSolid->SetParameterName("forceSolid", omitable = true);
108 fpCommandSetForceSolid->SetDefaultValue(false);
109
110 fpCommandSetForceWireframe = new G4UIcmdWithABool
111 ("/vis/touchable/set/forceWireframe", this);
112 fpCommandSetForceWireframe->SetGuidance
113 ("Force current touchable always to be drawn as wireframe.");
114 fpCommandSetForceWireframe->SetGuidance
115 ("Use \"/vis/set/touchable\" to set current touchable.");
116 fpCommandSetForceWireframe->SetParameterName("forceWireframe", omitable = true);
117 fpCommandSetForceWireframe->SetDefaultValue(false);
118
119 fpCommandSetLineStyle = new G4UIcmdWithAString
120 ("/vis/touchable/set/lineStyle", this);
121 fpCommandSetLineStyle->SetGuidance("Set line style of current touchable drawing.");
122 fpCommandSetLineStyle->SetGuidance
123 ("Use \"/vis/set/touchable\" to set current touchable.");
124 fpCommandSetLineStyle->SetParameterName("lineStyle", omitable = true);
125 fpCommandSetLineStyle->SetCandidates("unbroken dashed dotted");
126 fpCommandSetLineStyle->SetDefaultValue("unbroken");
127
128 fpCommandSetLineWidth = new G4UIcmdWithADouble
129 ("/vis/touchable/set/lineWidth", this);
130 fpCommandSetLineWidth->SetGuidance("Set line width of current touchable.");
131 fpCommandSetLineWidth->SetGuidance
132 ("Use \"/vis/set/touchable\" to set current touchable.");
133 fpCommandSetLineWidth->SetParameterName("lineWidth", omitable = true);
134 fpCommandSetLineWidth->SetDefaultValue(1.);
135
136 fpCommandSetVisibility = new G4UIcmdWithABool
137 ("/vis/touchable/set/visibility", this);
138 fpCommandSetVisibility->SetGuidance
139 ("Set visibility of current touchable: true/false.");
140 fpCommandSetVisibility->SetGuidance
141 ("Use \"/vis/set/touchable\" to set current touchable.");
142 fpCommandSetVisibility->SetParameterName("visibility", omitable = true);
143 fpCommandSetVisibility->SetDefaultValue(false);
144}
145
147 delete fpCommandSetVisibility;
148 delete fpCommandSetLineWidth;
149 delete fpCommandSetLineStyle;
150 delete fpCommandSetForceWireframe;
151 delete fpCommandSetForceSolid;
152 delete fpCommandSetLineSegmentsPerCircle;
153 delete fpCommandSetForceAuxEdgeVisible;
154 delete fpCommandSetDaughtersInvisible;
155 delete fpCommandSetColour;
156}
157
159 return "";
160}
161
163(G4UIcommand* command,G4String newValue)
164{
166
167 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
168 if (!currentViewer) {
169 if (verbosity >= G4VisManager::errors) {
170 G4cout <<
171 "ERROR: G4VisCommandsTouchableSet::SetNewValue: no current viewer."
172 << G4endl;
173 }
174 return;
175 }
176
177 G4ViewParameters workingVP = currentViewer->GetViewParameters();
178 G4VisAttributes workingVisAtts;
179
180 if (command == fpCommandSetColour)
181 {
182 G4String redOrString;
183 G4double green, blue, opacity;
184 std::istringstream iss(newValue);
185 iss >> redOrString >> green >> blue >> opacity;
186 G4Colour colour(1,1,1,1); // Default white and opaque.
187 const size_t iPos0 = 0;
188 if (std::isalpha(redOrString[iPos0])) {
189 if (!G4Colour::GetColour(redOrString, colour)) {
191 G4cout << "WARNING: Colour \"" << redOrString
192 << "\" not found. Defaulting to white and opaque."
193 << G4endl;
194 }
195 }
196 } else {
197 colour = G4Colour(G4UIcommand::ConvertToDouble(redOrString), green, blue);
198 }
199 colour = G4Colour
200 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
201
202 workingVisAtts.SetColour(colour);
205 (workingVisAtts,
208 }
209
210 else if (command == fpCommandSetDaughtersInvisible) {
211 workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
214 (workingVisAtts,
217 }
218
219 else if (command == fpCommandSetForceAuxEdgeVisible) {
220 workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
223 (workingVisAtts,
226 }
227
228 else if (command == fpCommandSetLineSegmentsPerCircle) {
229 workingVisAtts.SetForceLineSegmentsPerCircle
230 (G4UIcommand::ConvertToInt(newValue));
233 (workingVisAtts,
236 }
237
238 else if (command == fpCommandSetForceSolid) {
239 workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
242 (workingVisAtts,
245 }
246
247 else if (command == fpCommandSetForceWireframe) {
248 workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
251 (workingVisAtts,
254 }
255
256 else if (command == fpCommandSetLineStyle) {
258 if (newValue == "dashed") {
259 lineStyle = G4VisAttributes::dashed;
260 } else if (newValue == "dotted") {
261 lineStyle = G4VisAttributes::dotted;
262 }
263 // All other values are "unbroken".
264 workingVisAtts.SetLineStyle(lineStyle);
267 (workingVisAtts,
270 }
271
272 else if (command == fpCommandSetLineWidth) {
273 workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
276 (workingVisAtts,
279 }
280
281 else if (command == fpCommandSetVisibility) {
282 workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
285 (workingVisAtts,
288 }
289
290 else {
291 if (verbosity >= G4VisManager::errors) {
292 G4cout <<
293 "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
294 << G4endl;
295 }
296 return;
297 }
298
299 SetViewParameters(currentViewer,workingVP);
300}
double G4double
Definition: G4Types.hh:64
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
G4double GetBlue() const
Definition: G4Colour.hh:140
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:123
G4double GetRed() const
Definition: G4Colour.hh:138
G4double GetGreen() const
Definition: G4Colour.hh:139
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(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)
void SetDefaultValue(G4int defVal)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:413
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:403
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:421
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
const G4ViewParameters & GetViewParameters() const
void SetViewParameters(G4VViewer *, const G4ViewParameters &)
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
static G4VisManager * fpVisManager
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetForceAuxEdgeVisible(G4bool)
void SetVisibility(G4bool)
void SetColour(const G4Colour &)
void SetDaughtersInvisible(G4bool)
void SetForceWireframe(G4bool)
void SetLineWidth(G4double)
void SetForceSolid(G4bool)
void SetLineStyle(LineStyle)
void SetForceLineSegmentsPerCircle(G4int nSegments)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()