Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 99418 2016-09-21 09:18:42Z gcosmo $
28 
29 // /vis/touchable/set commands - John Allison 8th October 2012
30 
32 
33 #include "G4UImanager.hh"
34 #include "G4UIcommand.hh"
35 #include "G4UIcmdWithABool.hh"
36 #include "G4UIcmdWithADouble.hh"
37 #include "G4UIcmdWithAnInteger.hh"
38 #include "G4UIcmdWithAString.hh"
39 
40 #include <sstream>
41 #include <cctype>
42 
44 
46 {
47  G4bool omitable;
48  G4UIparameter* parameter;
49 
50  fpCommandSetColour = new G4UIcommand
51  ("/vis/touchable/set/colour", this);
52  fpCommandSetColour->SetGuidance("Set colour of current touchable.");
53  fpCommandSetColour->SetGuidance
54  ("Use \"/vis/set/touchable\" to set current touchable.");
55  fpCommandSetColour->SetGuidance
56  ("If \"red\" is a string understood by the vis system it will be taken."
57  "\n Otherwise the values of \red\", \"green\", etc., are used.");
58  parameter = new G4UIparameter("red", 's', omitable = true);
59  parameter->SetDefaultValue("1.");
60  fpCommandSetColour->SetParameter(parameter);
61  parameter = new G4UIparameter("green", 'd', omitable = true);
62  parameter->SetDefaultValue(1.);
63  fpCommandSetColour->SetParameter(parameter);
64  parameter = new G4UIparameter("blue", 'd', omitable = true);
65  parameter->SetDefaultValue(1.);
66  fpCommandSetColour->SetParameter(parameter);
67  parameter = new G4UIparameter("opacity", 'd', omitable = true);
68  parameter->SetDefaultValue(1.);
69  fpCommandSetColour->SetParameter(parameter);
70 
71  fpCommandSetDaughtersInvisible = new G4UIcmdWithABool
72  ("/vis/touchable/set/daughtersInvisible", this);
73  fpCommandSetDaughtersInvisible->SetGuidance
74  ("Daughters of current touchable invisible: true/false.");
75  fpCommandSetDaughtersInvisible->SetGuidance
76  ("Use \"/vis/set/touchable\" to set current touchable.");
77  fpCommandSetDaughtersInvisible->SetParameterName("daughtersInvisible", omitable = true);
78  fpCommandSetDaughtersInvisible->SetDefaultValue(true);
79 
80  fpCommandSetForceAuxEdgeVisible = new G4UIcmdWithABool
81  ("/vis/touchable/set/forceAuxEdgeVisible", this);
82  fpCommandSetForceAuxEdgeVisible->SetGuidance
83  ("Force auxiliary (soft) edges of current touchable to be visible: true/false.");
84  fpCommandSetForceAuxEdgeVisible->SetGuidance
85  ("Use \"/vis/set/touchable\" to set current touchable.");
86  fpCommandSetForceAuxEdgeVisible->SetParameterName("forceAuxEdgeVisible", omitable = true);
87  fpCommandSetForceAuxEdgeVisible->SetDefaultValue(true);
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(0);
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(true);
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(true);
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(true);
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 {
165  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
166 
167  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
168  if (!currentViewer) {
169  if (verbosity >= G4VisManager::errors) {
170  G4cerr <<
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)) {
190  if (fpVisManager->GetVerbosity() >= G4VisManager::warnings) {
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);
203  workingVP.AddVisAttributesModifier
205  (workingVisAtts,
207  fCurrentTouchablePath));
208  }
209 
210  else if (command == fpCommandSetDaughtersInvisible) {
211  workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
212  workingVP.AddVisAttributesModifier
214  (workingVisAtts,
216  fCurrentTouchablePath));
217  }
218 
219  else if (command == fpCommandSetForceAuxEdgeVisible) {
220  workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
221  workingVP.AddVisAttributesModifier
223  (workingVisAtts,
225  fCurrentTouchablePath));
226  }
227 
228  else if (command == fpCommandSetLineSegmentsPerCircle) {
229  workingVisAtts.SetForceLineSegmentsPerCircle
230  (G4UIcommand::ConvertToInt(newValue));
231  workingVP.AddVisAttributesModifier
233  (workingVisAtts,
235  fCurrentTouchablePath));
236  }
237 
238  else if (command == fpCommandSetForceSolid) {
239  workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
240  workingVP.AddVisAttributesModifier
242  (workingVisAtts,
244  fCurrentTouchablePath));
245  }
246 
247  else if (command == fpCommandSetForceWireframe) {
248  workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
249  workingVP.AddVisAttributesModifier
251  (workingVisAtts,
253  fCurrentTouchablePath));
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);
265  workingVP.AddVisAttributesModifier
267  (workingVisAtts,
269  fCurrentTouchablePath));
270  }
271 
272  else if (command == fpCommandSetLineWidth) {
273  workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
274  workingVP.AddVisAttributesModifier
276  (workingVisAtts,
278  fCurrentTouchablePath));
279  }
280 
281  else if (command == fpCommandSetVisibility) {
282  workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
283  workingVP.AddVisAttributesModifier
285  (workingVisAtts,
287  fCurrentTouchablePath));
288  }
289 
290  else {
291  if (verbosity >= G4VisManager::errors) {
292  G4cerr <<
293  "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
294  << G4endl;
295  }
296  return;
297  }
298 
299  SetViewParameters(currentViewer,workingVP);
300 
301  // To update all views
302  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
303 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetColour(const G4Colour &)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4String GetCurrentValue(G4UIcommand *command)
void SetLineStyle(LineStyle)
void SetLineWidth(G4double)
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=true)
void SetDefaultValue(G4bool defVal)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:59
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:437
void SetVisibility(G4bool=true)
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:455
static G4int ConvertToInt(const char *st)
Definition: G4UIcommand.cc:447
void SetDaughtersInvisible(G4bool=true)
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 SetForceAuxEdgeVisible(G4bool=true)
void SetDefaultValue(G4int defVal)
double G4double
Definition: G4Types.hh:76
void SetForceWireframe(G4bool=true)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4GLOB_DLL std::ostream G4cerr
void SetForceLineSegmentsPerCircle(G4int nSegments)