ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandsTouchableSet.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisCommandsTouchableSet.cc
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"
36 #include "G4UIcmdWithAnInteger.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.");
56  fpCommandSetColour->SetParameter(parameter);
57  parameter = new G4UIparameter("green", 'd', omitable = true);
58  parameter->SetDefaultValue(1.);
59  fpCommandSetColour->SetParameter(parameter);
60  parameter = new G4UIparameter("blue", 'd', omitable = true);
61  parameter->SetDefaultValue(1.);
62  fpCommandSetColour->SetParameter(parameter);
63  parameter = new G4UIparameter("opacity", 'd', omitable = true);
64  parameter->SetDefaultValue(1.);
65  fpCommandSetColour->SetParameter(parameter);
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/lineSegmentsPerCircle", this);
88  ("For current touchable, set number of line segments per circle, the"
89  "\nprecision with which a curved line or surface is represented by a"
90  "\npolygon or polyhedron, regardless of the view parameters."
91  "\nNegative to pick up G4Polyhedron default value.");
93  ("Use \"/vis/set/touchable\" to set current touchable.");
94  fpCommandSetLineSegmentsPerCircle->SetParameterName("lineSegmentsPerCircle", omitable = true);
96 
98  ("/vis/touchable/set/forceCloud", this);
100  ("Force current touchable always to be drawn as a cloud.");
102  ("Use \"/vis/set/touchable\" to set current touchable.");
103  fpCommandSetForceCloud->SetParameterName("force", omitable = true);
105 
107  ("/vis/touchable/set/forceSolid", this);
109  ("Force current touchable always to be drawn solid (surface drawing).");
111  ("Use \"/vis/set/touchable\" to set current touchable.");
112  fpCommandSetForceSolid->SetParameterName("force", omitable = true);
114 
116  ("/vis/touchable/set/forceWireframe", this);
118  ("Force current touchable always to be drawn as wireframe.");
120  ("Use \"/vis/set/touchable\" to set current touchable.");
121  fpCommandSetForceWireframe->SetParameterName("forceWireframe", 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 line segments per circle, the"
145  "\nprecision with which a curved line or surface is represented by a"
146  "\npolygon or polyhedron, regardless of the view parameters."
147  "\nNegative to pick up G4Polyhedron default value.");
149  ("Use \"/vis/set/touchable\" to set current touchable.");
150  fpCommandSetNumberOfCloudPoints->SetParameterName("lineSegmentsPerCircle", omitable = true);
152 
154  ("/vis/touchable/set/visibility", this);
156  ("Set visibility of current touchable: true/false.");
158  ("Use \"/vis/set/touchable\" to set current touchable.");
159  fpCommandSetVisibility->SetParameterName("visibility", omitable = true);
161 }
162 
164  delete fpCommandSetVisibility;
166  delete fpCommandSetLineWidth;
167  delete fpCommandSetLineStyle;
169  delete fpCommandSetForceSolid;
170  delete fpCommandSetForceCloud;
174  delete fpCommandSetColour;
175 }
176 
178  return "";
179 }
180 
182 (G4UIcommand* command,G4String newValue)
183 {
184  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
185 
186  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
187  if (!currentViewer) {
188  if (verbosity >= G4VisManager::errors) {
189  G4cerr <<
190  "ERROR: G4VisCommandsTouchableSet::SetNewValue: no current viewer."
191  << G4endl;
192  }
193  return;
194  }
195 
196  G4ViewParameters workingVP = currentViewer->GetViewParameters();
197  G4VisAttributes workingVisAtts;
198 
199  if (command == fpCommandSetColour)
200  {
201  G4String redOrString;
202  G4double green, blue, opacity;
203  std::istringstream iss(newValue);
204  iss >> redOrString >> green >> blue >> opacity;
205  G4Colour colour(1,1,1,1); // Default white and opaque.
206  ConvertToColour(colour, redOrString, green, blue, opacity);
207  workingVisAtts.SetColour(colour);
208  workingVP.AddVisAttributesModifier
210  (workingVisAtts,
212  fCurrentTouchableProperties.fTouchablePath));
213  }
214 
215  else if (command == fpCommandSetDaughtersInvisible) {
216  workingVisAtts.SetDaughtersInvisible(G4UIcommand::ConvertToBool(newValue));
217  workingVP.AddVisAttributesModifier
219  (workingVisAtts,
221  fCurrentTouchableProperties.fTouchablePath));
222  }
223 
224  else if (command == fpCommandSetForceAuxEdgeVisible) {
225  workingVisAtts.SetForceAuxEdgeVisible(G4UIcommand::ConvertToBool(newValue));
226  workingVP.AddVisAttributesModifier
228  (workingVisAtts,
230  fCurrentTouchableProperties.fTouchablePath));
231  }
232 
233  else if (command == fpCommandSetLineSegmentsPerCircle) {
234  workingVisAtts.SetForceLineSegmentsPerCircle
235  (G4UIcommand::ConvertToInt(newValue));
236  workingVP.AddVisAttributesModifier
238  (workingVisAtts,
240  fCurrentTouchableProperties.fTouchablePath));
241  }
242 
243  else if (command == fpCommandSetForceCloud) {
244  workingVisAtts.SetForceCloud(G4UIcommand::ConvertToBool(newValue));
245  workingVP.AddVisAttributesModifier
247  (workingVisAtts,
249  fCurrentTouchableProperties.fTouchablePath));
250  }
251 
252  else if (command == fpCommandSetForceSolid) {
253  workingVisAtts.SetForceSolid(G4UIcommand::ConvertToBool(newValue));
254  workingVP.AddVisAttributesModifier
256  (workingVisAtts,
258  fCurrentTouchableProperties.fTouchablePath));
259  }
260 
261  else if (command == fpCommandSetForceWireframe) {
262  workingVisAtts.SetForceWireframe(G4UIcommand::ConvertToBool(newValue));
263  workingVP.AddVisAttributesModifier
265  (workingVisAtts,
267  fCurrentTouchableProperties.fTouchablePath));
268  }
269 
270  else if (command == fpCommandSetLineStyle) {
272  if (newValue == "dashed") {
273  lineStyle = G4VisAttributes::dashed;
274  } else if (newValue == "dotted") {
275  lineStyle = G4VisAttributes::dotted;
276  }
277  // All other values are "unbroken".
278  workingVisAtts.SetLineStyle(lineStyle);
279  workingVP.AddVisAttributesModifier
281  (workingVisAtts,
283  fCurrentTouchableProperties.fTouchablePath));
284  }
285 
286  else if (command == fpCommandSetLineWidth) {
287  workingVisAtts.SetLineWidth(G4UIcommand::ConvertToDouble(newValue));
288  workingVP.AddVisAttributesModifier
290  (workingVisAtts,
292  fCurrentTouchableProperties.fTouchablePath));
293  }
294 
295  else if (command == fpCommandSetNumberOfCloudPoints) {
296  workingVisAtts.SetForceNumberOfCloudPoints
297  (G4UIcommand::ConvertToInt(newValue));
298  workingVP.AddVisAttributesModifier
300  (workingVisAtts,
302  fCurrentTouchableProperties.fTouchablePath));
303  }
304 
305  else if (command == fpCommandSetVisibility) {
306  workingVisAtts.SetVisibility(G4UIcommand::ConvertToBool(newValue));
307  workingVP.AddVisAttributesModifier
309  (workingVisAtts,
311  fCurrentTouchableProperties.fTouchablePath));
312  }
313 
314  else {
315  if (verbosity >= G4VisManager::errors) {
316  G4cerr <<
317  "ERROR: G4VisCommandsTouchableSet::SetNewValue: unrecognised command."
318  << G4endl;
319  }
320  return;
321  }
322 
323  SetViewParameters(currentViewer,workingVP);
324 
325  // To update all views
326  G4UImanager::GetUIpointer()->ApplyCommand("/vis/scene/notifyHandlers");
327 }