Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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$
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 
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 {
165  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
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)) {
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  G4cout <<
293  "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
294  << G4endl;
295  }
296  return;
297  }
298 
299  SetViewParameters(currentViewer,workingVP);
300 }