Geant4  10.02
G4VisCommandsCompound.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: G4VisCommandsCompound.cc 91686 2015-07-31 09:40:08Z gcosmo $
28 
29 // Compound /vis/ commands - John Allison 15th May 2000
30 
31 #include "G4VisCommandsCompound.hh"
32 
33 #include "G4VisManager.hh"
34 #include "G4UImanager.hh"
35 #include "G4UIcmdWithAString.hh"
36 
37 #include <sstream>
38 
40 
42  G4bool omitable;
43  fpCommand = new G4UIcommand("/vis/drawTree", this);
45  ("(DTREE) Creates a scene consisting of this physical volume and"
46  "\n produces a representation of the geometry hieracrhy.");
47  fpCommand->SetGuidance("The scene becomes current.");
48  G4UIparameter* parameter;
49  parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
50  parameter -> SetDefaultValue("world");
51  fpCommand -> SetParameter (parameter);
52  parameter = new G4UIparameter("system", 's', omitable = true);
53  parameter -> SetDefaultValue("ATree");
54  fpCommand -> SetParameter (parameter);
55 }
56 
58  delete fpCommand;
59 }
60 
62 
63  G4String pvname, system;
64  std::istringstream is(newValue);
65  is >> pvname >> system;
66 
68  G4Scene* keepScene = fpVisManager->GetCurrentScene();
70  G4VViewer* keepViewer = fpVisManager->GetCurrentViewer();
71 
73  G4int keepVerbose = UImanager->GetVerboseLevel();
74  G4int newVerbose(0);
75  if (keepVerbose >= 2 ||
77  newVerbose = 2;
78  UImanager->SetVerboseLevel(newVerbose);
79  UImanager->ApplyCommand(G4String("/vis/open " + system));
80  UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
81  UImanager->ApplyCommand("/vis/viewer/flush");
82  UImanager->SetVerboseLevel(keepVerbose);
83 
84  if (keepViewer) {
86  G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
87  }
89  fpVisManager->SetCurrentScene(keepScene);
90  fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
91  fpVisManager->SetCurrentViewer(keepViewer);
92  }
93 }
94 
96 
98  G4bool omitable;
99  fpCommand = new G4UIcommand("/vis/drawView", this);
101  ("Draw view from this angle, etc.");
102  G4UIparameter* parameter;
103  parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
104  parameter -> SetDefaultValue(0.);
105  fpCommand -> SetParameter (parameter);
106  parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
107  parameter -> SetDefaultValue(0.);
108  fpCommand -> SetParameter (parameter);
109  parameter = new G4UIparameter("pan-right", 'd', omitable = true);
110  parameter -> SetDefaultValue(0.);
111  fpCommand -> SetParameter (parameter);
112  parameter = new G4UIparameter("pan-up", 'd', omitable = true);
113  parameter -> SetDefaultValue(0.);
114  fpCommand -> SetParameter (parameter);
115  parameter = new G4UIparameter("pan-unit", 's', omitable = true);
116  parameter -> SetDefaultValue("cm");
117  fpCommand -> SetParameter (parameter);
118  parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
119  parameter -> SetDefaultValue(1.);
120  fpCommand -> SetParameter (parameter);
121  parameter = new G4UIparameter("dolly", 'd', omitable = true);
122  parameter -> SetDefaultValue(0.);
123  fpCommand -> SetParameter (parameter);
124  parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
125  parameter -> SetDefaultValue("cm");
126  fpCommand -> SetParameter (parameter);
127 }
128 
130  delete fpCommand;
131 }
132 
134 
136 
137  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
138  if (!currentViewer) {
139  if (verbosity >= G4VisManager::warnings) {
140  G4cout <<
141  "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
142  << G4endl;
143  }
144  return;
145  }
146 
147  G4String thetaDeg;
148  G4String phiDeg;
149  G4String panRight;
150  G4String panUp;
151  G4String panUnit;
152  G4String zoomFactor;
153  G4String dolly;
154  G4String dollyUnit;
155  std::istringstream is(newValue);
156  is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
157  >> zoomFactor >> dolly >> dollyUnit;
158 
159  G4UImanager* UImanager = G4UImanager::GetUIpointer();
160  G4int keepVerbose = UImanager->GetVerboseLevel();
161  G4int newVerbose(0);
162  if (keepVerbose >= 2 ||
164  newVerbose = 2;
165  UImanager->SetVerboseLevel(newVerbose);
166  G4ViewParameters vp = currentViewer->GetViewParameters();
167  G4bool keepAutoRefresh = vp.IsAutoRefresh();
168  vp.SetAutoRefresh(false);
169  currentViewer->SetViewParameters(vp);
170  UImanager->ApplyCommand(
171  G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
172  UImanager->ApplyCommand(
173  G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
174  UImanager->ApplyCommand(
175  G4String("/vis/viewer/zoomTo " + zoomFactor));
176  vp = currentViewer->GetViewParameters();
177  vp.SetAutoRefresh(keepAutoRefresh);
178  currentViewer->SetViewParameters(vp);
179  UImanager->ApplyCommand(
180  G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
181  UImanager->SetVerboseLevel(keepVerbose);
182 }
183 
185 
187  G4bool omitable;
188  fpCommand = new G4UIcmdWithAString("/vis/drawVolume", this);
190  ("Creates a scene containing this physical volume and asks the"
191  "\ncurrent viewer to draw it. The scene becomes current.");
192  fpCommand -> SetGuidance
193  ("If physical-volume-name is \"world\" (the default), the main geometry"
194  "\ntree (material world) is drawn. If \"worlds\", all worlds - material"
195  "\nworld and parallel worlds, if any - are drawn. Otherwise a search of"
196  "\nall worlds is made, taking the first matching occurence only. To see"
197  "\na representation of the geometry hierarchy of the worlds, try"
198  "\n\"/vis/drawTree [worlds]\" or one of the driver/browser combinations"
199  "\nthat have the required functionality, e.g., HepRep");
200  fpCommand->SetParameterName("physical-volume-name", omitable = true);
201  fpCommand->SetDefaultValue("world");
202 }
203 
205  delete fpCommand;
206 }
207 
210  G4UImanager* UImanager = G4UImanager::GetUIpointer();
211  G4int keepVerbose = UImanager->GetVerboseLevel();
212  G4int newVerbose(0);
213  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
214  newVerbose = 2;
215  UImanager->SetVerboseLevel(newVerbose);
216  UImanager->ApplyCommand("/vis/scene/create");
217  UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
218  UImanager->ApplyCommand("/vis/sceneHandler/attach");
219  UImanager->SetVerboseLevel(keepVerbose);
220  static G4bool warned = false;
221  if (verbosity >= G4VisManager::confirmations && !warned) {
222  G4cout <<
223  "NOTE: For systems which are not \"auto-refresh\" you will need to"
224  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
225  << G4endl;
226  warned = true;
227  }
228 }
229 
231 
233  G4bool omitable;
234  fpCommand = new G4UIcommand("/vis/open", this);
236  ("Creates a scene handler ready for drawing.");
238  ("The scene handler becomes current (the name is auto-generated).");
239  G4UIparameter* parameter;
240  parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
241  fpCommand->SetParameter(parameter);
242  parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
243  parameter->SetGuidance
244  ("integer (pixels) for square window placed by window manager or"
245  " X-Windows-type geometry string, e.g. 600x600-100+100");
246  parameter->SetDefaultValue("600");
247  fpCommand->SetParameter(parameter);
248 }
249 
251  delete fpCommand;
252 }
253 
255  G4String systemName, windowSizeHint;
256  std::istringstream is(newValue);
257  is >> systemName >> windowSizeHint;
258  G4UImanager* UImanager = G4UImanager::GetUIpointer();
259  G4int keepVerbose = UImanager->GetVerboseLevel();
260  G4int newVerbose(0);
261  if (keepVerbose >= 2 ||
263  newVerbose = 2;
264  UImanager->SetVerboseLevel(newVerbose);
265  UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
266  UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
267  UImanager->SetVerboseLevel(keepVerbose);
268 }
269 
271 
273  G4bool omitable;
274  fpCommand = new G4UIcommand("/vis/specify", this);
276  ("Draws logical volume with Boolean components, voxels and readout geometry.");
278  ("Creates a scene consisting of this logical volume and asks the"
279  "\n current viewer to draw it to the specified depth of descent"
280  "\n showing boolean components (if any), voxels (if any)"
281  "\n and readout geometry (if any), under control of the appropriate flag.");
283  ("Note: voxels are not constructed until start of run - /run/beamOn.");
284  fpCommand->SetGuidance("The scene becomes current.");
285  G4UIparameter* parameter;
286  parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
287  fpCommand->SetParameter(parameter);
288  parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
289  parameter->SetDefaultValue(1);
290  fpCommand->SetParameter(parameter);
291  parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
292  parameter->SetDefaultValue(true);
293  fpCommand->SetParameter(parameter);
294  parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
295  parameter->SetDefaultValue(true);
296  fpCommand->SetParameter(parameter);
297  parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
298  parameter->SetDefaultValue(true);
299  fpCommand->SetParameter(parameter);
300  parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
301  parameter->SetDefaultValue(true);
302  parameter -> SetGuidance ("Set \"false\" to suppress axes.");
303  fpCommand->SetParameter(parameter);
304 }
305 
307  delete fpCommand;
308 }
309 
312  G4UImanager* UImanager = G4UImanager::GetUIpointer();
313  G4int keepVerbose = UImanager->GetVerboseLevel();
314  G4int newVerbose(0);
315  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
316  newVerbose = 2;
317  UImanager->SetVerboseLevel(newVerbose);
318  // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
319  UImanager->ApplyCommand("/vis/scene/create");
320  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
321  UImanager->ApplyCommand("/vis/sceneHandler/attach");
322  UImanager->SetVerboseLevel(keepVerbose);
323  static G4bool warned = false;
324  if (verbosity >= G4VisManager::confirmations && !warned) {
325  G4cout <<
326  "NOTE: For systems which are not \"auto-refresh\" you will need to"
327  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
328  << G4endl;
329  warned = true;
330  }
331 }
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
const G4String & GetName() const
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetCurrentSceneHandler(G4VSceneHandler *)
const G4ViewParameters & GetViewParameters() const
void SetDefaultValue(const char *theDefaultValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetViewParameters(const G4ViewParameters &vp)
Definition: G4VViewer.cc:130
G4VGraphicsSystem * GetCurrentGraphicsSystem() const
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetCurrentScene(G4Scene *)
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
int G4int
Definition: G4Types.hh:78
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
bool G4bool
Definition: G4Types.hh:79
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetCurrentViewer(G4VViewer *)
void SetAutoRefresh(G4bool)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetDefaultValue(const char *defVal)
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
G4UIcmdWithAString * fpCommand
void SetGuidance(const char *theGuidance)
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
G4Scene * GetCurrentScene() const
static G4VisManager * fpVisManager