Geant4-11
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
28// /vis/touchable/set commands - John Allison 8th October 2012
29
31
32#include "G4UImanager.hh"
33#include "G4UIcommand.hh"
34#include "G4UIcmdWithABool.hh"
35#include "G4UIcmdWithADouble.hh"
37#include "G4UIcmdWithAString.hh"
38
39#include <sstream>
40
42
44{
45 G4bool omitable;
46 G4UIparameter* parameter;
47
49 ("/vis/touchable/set/colour", this);
50 fpCommandSetColour->SetGuidance("Set colour of current touchable.");
52 ("Use \"/vis/set/touchable\" to set current touchable.");
54 parameter = new G4UIparameter("red", 's', omitable = true);
55 parameter->SetDefaultValue("1.");
57 parameter = new G4UIparameter("green", 'd', omitable = true);
58 parameter->SetDefaultValue(1.);
60 parameter = new G4UIparameter("blue", 'd', omitable = true);
61 parameter->SetDefaultValue(1.);
63 parameter = new G4UIparameter("opacity", 'd', omitable = true);
64 parameter->SetDefaultValue(1.);
66
68 ("/vis/touchable/set/daughtersInvisible", this);
70 ("Daughters of current touchable invisible: true/false.");
72 ("Use \"/vis/set/touchable\" to set current touchable.");
73 fpCommandSetDaughtersInvisible->SetParameterName("daughtersInvisible", omitable = true);
75
77 ("/vis/touchable/set/forceAuxEdgeVisible", this);
79 ("Force auxiliary (soft) edges of current touchable to be visible: true/false.");
81 ("Use \"/vis/set/touchable\" to set current touchable.");
82 fpCommandSetForceAuxEdgeVisible->SetParameterName("forceAuxEdgeVisible", omitable = true);
84
86 ("/vis/touchable/set/forceCloud", this);
88 ("Force current touchable always to be drawn as a cloud.");
90 ("Use \"/vis/set/touchable\" to set current touchable.");
91 fpCommandSetForceCloud->SetParameterName("force", omitable = true);
93
95 ("/vis/touchable/set/forceSolid", this);
97 ("Force current touchable always to be drawn solid (surface drawing).");
99 ("Use \"/vis/set/touchable\" to set current touchable.");
100 fpCommandSetForceSolid->SetParameterName("force", omitable = true);
102
104 ("/vis/touchable/set/forceWireframe", this);
106 ("Force current touchable always to be drawn as wireframe.");
108 ("Use \"/vis/set/touchable\" to set current touchable.");
109 fpCommandSetForceWireframe->SetParameterName("forceWireframe", omitable = true);
111
113 ("/vis/touchable/set/lineSegmentsPerCircle", this);
115 ("For current touchable, set number of line segments per circle, the"
116 "\nprecision with which a curved line or surface is represented by a"
117 "\npolygon or polyhedron, regardless of the view parameters."
118 "\nNegative to pick up G4Polyhedron default value.");
120 ("Use \"/vis/set/touchable\" to set current touchable.");
121 fpCommandSetLineSegmentsPerCircle->SetParameterName("lineSegmentsPerCircle", omitable = true);
123
125 ("/vis/touchable/set/lineStyle", this);
126 fpCommandSetLineStyle->SetGuidance("Set line style of current touchable drawing.");
128 ("Use \"/vis/set/touchable\" to set current touchable.");
129 fpCommandSetLineStyle->SetParameterName("lineStyle", omitable = true);
130 fpCommandSetLineStyle->SetCandidates("unbroken dashed dotted");
132
134 ("/vis/touchable/set/lineWidth", this);
135 fpCommandSetLineWidth->SetGuidance("Set line width of current touchable.");
137 ("Use \"/vis/set/touchable\" to set current touchable.");
138 fpCommandSetLineWidth->SetParameterName("lineWidth", omitable = true);
140
142 ("/vis/touchable/set/numberOfCloudPoints", this);
144 ("For current touchable, set number of cloud points for cloud drawing."
145 "\n<= 0 means under control of viewer.");
147 ("Use \"/vis/set/touchable\" to set current touchable.");
148 fpCommandSetNumberOfCloudPoints->SetParameterName("numberOfCloudPoints", omitable = true);
150
152 ("/vis/touchable/set/visibility", this);
154 ("Set visibility of current touchable: true/false.");
156 ("Use \"/vis/set/touchable\" to set current touchable.");
157 fpCommandSetVisibility->SetParameterName("visibility", omitable = true);
159}
160
172 delete fpCommandSetColour;
173}
174
176 return "";
177}
178
180(G4UIcommand* command,G4String newValue)
181{
183
184 G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
185 if (!currentViewer) {
186 if (verbosity >= G4VisManager::errors) {
187 G4cerr <<
188 "ERROR: G4VisCommandsTouchableSet::SetNewValue: no current viewer."
189 << G4endl;
190 }
191 return;
192 }
193
194 G4ViewParameters workingVP = currentViewer->GetViewParameters();
195 G4VisAttributes workingVisAtts;
196
197 if (command == fpCommandSetColour)
198 {
199 G4String redOrString;
200 G4double green, blue, opacity;
201 std::istringstream iss(newValue);
202 iss >> redOrString >> green >> blue >> opacity;
203 G4Colour colour(1,1,1,1); // Default white and opaque.
204 ConvertToColour(colour, redOrString, green, blue, opacity);
205 workingVisAtts.SetColour(colour);
208 (workingVisAtts,
211 }
212
213 else if (command == fpCommandSetDaughtersInvisible) {
214 workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
217 (workingVisAtts,
220 }
221
222 else if (command == fpCommandSetForceAuxEdgeVisible) {
223 workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
226 (workingVisAtts,
229 }
230
231 else if (command == fpCommandSetLineSegmentsPerCircle) {
232 workingVisAtts.SetForceLineSegmentsPerCircle
233 (G4UIcommand::ConvertToInt(newValue));
236 (workingVisAtts,
239 }
240
241 else if (command == fpCommandSetForceCloud) {
242 workingVisAtts.SetForceCloud(G4UIcommand::ConvertToBool(newValue));
245 (workingVisAtts,
248 }
249
250 else if (command == fpCommandSetForceSolid) {
251 workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
254 (workingVisAtts,
257 }
258
259 else if (command == fpCommandSetForceWireframe) {
260 workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
263 (workingVisAtts,
266 }
267
268 else if (command == fpCommandSetLineStyle) {
270 if (newValue == "dashed") {
271 lineStyle = G4VisAttributes::dashed;
272 } else if (newValue == "dotted") {
273 lineStyle = G4VisAttributes::dotted;
274 }
275 // All other values are "unbroken".
276 workingVisAtts.SetLineStyle(lineStyle);
279 (workingVisAtts,
282 }
283
284 else if (command == fpCommandSetLineWidth) {
285 workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
288 (workingVisAtts,
291 }
292
293 else if (command == fpCommandSetNumberOfCloudPoints) {
294 workingVisAtts.SetForceNumberOfCloudPoints
295 (G4UIcommand::ConvertToInt(newValue));
298 (workingVisAtts,
301 }
302
303 else if (command == fpCommandSetVisibility) {
304 workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
307 (workingVisAtts,
310 }
311
312 else {
313 if (verbosity >= G4VisManager::errors) {
314 G4cerr <<
315 "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
316 << G4endl;
317 }
318 return;
319 }
320
321 SetViewParameters(currentViewer,workingVP);
322
323 // To update all views
324 G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
325}
double G4double
Definition: G4Types.hh:83
bool G4bool
Definition: G4Types.hh:86
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
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:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:557
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:545
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:575
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetDefaultValue(const char *theDefaultValue)
const G4ViewParameters & GetViewParameters() const
void ConvertToColour(G4Colour &colour, const G4String &redOrString, G4double green, G4double blue, G4double opacity)
static G4VisManager * fpVisManager
void SetViewParameters(G4VViewer *viewer, const G4ViewParameters &viewParams)
const G4String & ConvertToColourGuidance()
static G4PhysicalVolumeModel::TouchableProperties fCurrentTouchableProperties
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetColour(const G4Colour &)
void SetVisibility(G4bool=true)
void SetForceAuxEdgeVisible(G4bool=true)
void SetForceCloud(G4bool=true)
void SetForceWireframe(G4bool=true)
void SetLineWidth(G4double)
void SetForceSolid(G4bool=true)
void SetLineStyle(LineStyle)
void SetForceLineSegmentsPerCircle(G4int nSegments)
void SetDaughtersInvisible(G4bool=true)
void SetForceNumberOfCloudPoints(G4int nPoints)
G4UIcmdWithAnInteger * fpCommandSetLineSegmentsPerCircle
G4UIcmdWithAString * fpCommandSetLineStyle
G4UIcmdWithAnInteger * fpCommandSetNumberOfCloudPoints
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithABool * fpCommandSetDaughtersInvisible
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithABool * fpCommandSetForceWireframe
G4UIcmdWithABool * fpCommandSetForceAuxEdgeVisible
G4UIcmdWithADouble * fpCommandSetLineWidth
G4VViewer * GetCurrentViewer() const
static Verbosity GetVerbosity()
G4ModelingParameters::PVNameCopyNoPath fTouchablePath