Geant4  10.02.p01
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: G4VisCommandsTouchableSet.cc 82799 2014-07-10 13:18:29Z gcosmo $
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"
36 #include "G4UIcmdWithAnInteger.hh"
37 #include "G4UIcmdWithAString.hh"
38 
39 #include <sstream>
40 #include <cctype>
41 
43 
45 {
46  G4bool omitable;
47  G4UIparameter* parameter;
48 
50  ("/vis/touchable/set/colour", this);
51  fpCommandSetColour->SetGuidance("Set colour of current touchable.");
53  ("Use \"/vis/set/touchable\" to set current touchable.");
55  ("If \"red\" is a string understood by the vis system it will be taken."
56  "\n Otherwise the values of \red\", \"green\", etc., are used.");
57  parameter = new G4UIparameter("red", 's', omitable = true);
58  parameter->SetDefaultValue("1.");
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 
71  ("/vis/touchable/set/daughtersInvisible", this);
73  ("Daughters of current touchable invisible: true/false.");
75  ("Use \"/vis/set/touchable\" to set current touchable.");
76  fpCommandSetDaughtersInvisible->SetParameterName("daughtersInvisible", omitable = true);
78 
80  ("/vis/touchable/set/forceAuxEdgeVisible", this);
82  ("Force auxiliary (soft) edges of current touchable to be visible: true/false.");
84  ("Use \"/vis/set/touchable\" to set current touchable.");
85  fpCommandSetForceAuxEdgeVisible->SetParameterName("forceAuxEdgeVisible", omitable = true);
87 
89  ("/vis/touchable/set/lineSegmentsPerCircle", this);
91  ("For current touchable, set number of line segments per circle, the"
92  "\nprecision with which a curved line or surface is represented by a"
93  "\npolygon or polyhedron, regardless of the view parameters."
94  "\nNegative to pick up G4Polyhedron default value.");
96  ("Use \"/vis/set/touchable\" to set current touchable.");
97  fpCommandSetLineSegmentsPerCircle->SetParameterName("lineSegmentsPerCircle", omitable = true);
99 
101  ("/vis/touchable/set/forceSolid", this);
103  ("Force current touchable always to be drawn solid (surface drawing).");
105  ("Use \"/vis/set/touchable\" to set current touchable.");
106  fpCommandSetForceSolid->SetParameterName("forceSolid", omitable = true);
108 
110  ("/vis/touchable/set/forceWireframe", this);
112  ("Force current touchable always to be drawn as wireframe.");
114  ("Use \"/vis/set/touchable\" to set current touchable.");
115  fpCommandSetForceWireframe->SetParameterName("forceWireframe", omitable = true);
117 
119  ("/vis/touchable/set/lineStyle", this);
120  fpCommandSetLineStyle->SetGuidance("Set line style of current touchable drawing.");
122  ("Use \"/vis/set/touchable\" to set current touchable.");
123  fpCommandSetLineStyle->SetParameterName("lineStyle", omitable = true);
124  fpCommandSetLineStyle->SetCandidates("unbroken dashed dotted");
126 
128  ("/vis/touchable/set/lineWidth", this);
129  fpCommandSetLineWidth->SetGuidance("Set line width of current touchable.");
131  ("Use \"/vis/set/touchable\" to set current touchable.");
132  fpCommandSetLineWidth->SetParameterName("lineWidth", omitable = true);
134 
136  ("/vis/touchable/set/visibility", this);
138  ("Set visibility of current touchable: true/false.");
140  ("Use \"/vis/set/touchable\" to set current touchable.");
141  fpCommandSetVisibility->SetParameterName("visibility", omitable = true);
143 }
144 
146  delete fpCommandSetVisibility;
147  delete fpCommandSetLineWidth;
148  delete fpCommandSetLineStyle;
150  delete fpCommandSetForceSolid;
154  delete fpCommandSetColour;
155 }
156 
158  return "";
159 }
160 
162 (G4UIcommand* command,G4String newValue)
163 {
164  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
165 
166  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
167  if (!currentViewer) {
168  if (verbosity >= G4VisManager::errors) {
169  G4cerr <<
170  "ERROR: G4VisCommandsTouchableSet::SetNewValue: no current viewer."
171  << G4endl;
172  }
173  return;
174  }
175 
176  G4ViewParameters workingVP = currentViewer->GetViewParameters();
177  G4VisAttributes workingVisAtts;
178 
179  if (command == fpCommandSetColour)
180  {
181  G4String redOrString;
182  G4double green, blue, opacity;
183  std::istringstream iss(newValue);
184  iss >> redOrString >> green >> blue >> opacity;
185  G4Colour colour(1,1,1,1); // Default white and opaque.
186  const size_t iPos0 = 0;
187  if (std::isalpha(redOrString[iPos0])) {
188  if (!G4Colour::GetColour(redOrString, colour)) {
189  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
190  G4cout << "WARNING: Colour \"" << redOrString
191  << "\" not found. Defaulting to white and opaque."
192  << G4endl;
193  }
194  }
195  } else {
196  colour = G4Colour(G4UIcommand::ConvertToDouble(redOrString), green, blue);
197  }
198  colour = G4Colour
199  (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
200 
201  workingVisAtts.SetColour(colour);
202  workingVP.AddVisAttributesModifier
204  (workingVisAtts,
206  fCurrentTouchablePath));
207  }
208 
209  else if (command == fpCommandSetDaughtersInvisible) {
210  workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
211  workingVP.AddVisAttributesModifier
213  (workingVisAtts,
215  fCurrentTouchablePath));
216  }
217 
218  else if (command == fpCommandSetForceAuxEdgeVisible) {
219  workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
220  workingVP.AddVisAttributesModifier
222  (workingVisAtts,
224  fCurrentTouchablePath));
225  }
226 
227  else if (command == fpCommandSetLineSegmentsPerCircle) {
228  workingVisAtts.SetForceLineSegmentsPerCircle
229  (G4UIcommand::ConvertToInt(newValue));
230  workingVP.AddVisAttributesModifier
232  (workingVisAtts,
234  fCurrentTouchablePath));
235  }
236 
237  else if (command == fpCommandSetForceSolid) {
238  workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
239  workingVP.AddVisAttributesModifier
241  (workingVisAtts,
243  fCurrentTouchablePath));
244  }
245 
246  else if (command == fpCommandSetForceWireframe) {
247  workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
248  workingVP.AddVisAttributesModifier
250  (workingVisAtts,
252  fCurrentTouchablePath));
253  }
254 
255  else if (command == fpCommandSetLineStyle) {
257  if (newValue == "dashed") {
258  lineStyle = G4VisAttributes::dashed;
259  } else if (newValue == "dotted") {
260  lineStyle = G4VisAttributes::dotted;
261  }
262  // All other values are "unbroken".
263  workingVisAtts.SetLineStyle(lineStyle);
264  workingVP.AddVisAttributesModifier
266  (workingVisAtts,
268  fCurrentTouchablePath));
269  }
270 
271  else if (command == fpCommandSetLineWidth) {
272  workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
273  workingVP.AddVisAttributesModifier
275  (workingVisAtts,
277  fCurrentTouchablePath));
278  }
279 
280  else if (command == fpCommandSetVisibility) {
281  workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
282  workingVP.AddVisAttributesModifier
284  (workingVisAtts,
286  fCurrentTouchablePath));
287  }
288 
289  else {
290  if (verbosity >= G4VisManager::errors) {
291  G4cerr <<
292  "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
293  << G4endl;
294  }
295  return;
296  }
297 
298  SetViewParameters(currentViewer,workingVP);
299 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetColour(const G4Colour &)
void SetForceWireframe(G4bool)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4String GetCurrentValue(G4UIcommand *command)
void SetLineStyle(LineStyle)
void SetLineWidth(G4double)
void SetVisibility(G4bool)
const G4ViewParameters & GetViewParameters() const
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
void SetDefaultValue(const char *theDefaultValue)
G4double GetBlue() const
Definition: G4Colour.hh:141
void SetForceSolid(G4bool)
G4UIcmdWithAString * fpCommandSetLineStyle
Definition: test07.cc:36
G4UIcmdWithABool * fpCommandSetForceAuxEdgeVisible
G4UIcmdWithADouble * fpCommandSetLineWidth
void SetDefaultValue(G4bool defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4GLOB_DLL std::ostream G4cout
G4double GetRed() const
Definition: G4Colour.hh:139
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:425
bool G4bool
Definition: G4Types.hh:79
G4double GetGreen() const
Definition: G4Colour.hh:140
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:443
G4UIcmdWithAnInteger * fpCommandSetLineSegmentsPerCircle
void SetForceAuxEdgeVisible(G4bool)
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:435
G4UIcmdWithABool * fpCommandSetForceWireframe
void AddVisAttributesModifier(const G4ModelingParameters::VisAttributesModifier &)
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(G4double defVal)
void SetCandidates(const char *candidateList)
#define G4endl
Definition: G4ios.hh:61
void SetDefaultValue(G4int defVal)
double G4double
Definition: G4Types.hh:76
void SetDaughtersInvisible(G4bool)
G4UIcmdWithABool * fpCommandSetDaughtersInvisible
G4GLOB_DLL std::ostream G4cerr
void SetForceLineSegmentsPerCircle(G4int nSegments)