Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 98766 2016-08-09 14:17:17Z 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 #include <set>
39 
41 
43  G4bool omitable;
44  fpCommand = new G4UIcommand("/vis/drawTree", this);
45  fpCommand->SetGuidance
46  ("(DTREE) Creates a scene consisting of this physical volume and"
47  "\n produces a representation of the geometry hieracrhy.");
48  fpCommand->SetGuidance("The scene becomes current.");
49  G4UIparameter* parameter;
50  parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
51  parameter -> SetDefaultValue("world");
52  fpCommand -> SetParameter (parameter);
53  parameter = new G4UIparameter("system", 's', omitable = true);
54  parameter -> SetDefaultValue("ATree");
55  fpCommand -> SetParameter (parameter);
56 }
57 
59  delete fpCommand;
60 }
61 
63 
64  G4String pvname, system;
65  std::istringstream is(newValue);
66  is >> pvname >> system;
67 
68  // Note: The second parameter, "system", is intended to allow the user
69  // a choice of dedicated tree printing/displaying systems but at present
70  // the only such dedicated system is ASCIITree. It doesn't make sense to
71  // specify OGLSX, for example. So to avoid confusion we restrict this
72  // feature to systems that have "Tree" in the name or nickname.
73 
74  // Of course, some other systems, such as OGLSQt, have a tree browser
75  // built-in. The HepRApp offline browser also has a tree browser
76  // built in.
77 
78  if (!system.contains("Tree")) {
79  system = "ATree";
80  }
81 
83  G4Scene* keepScene = fpVisManager->GetCurrentScene();
85  G4VViewer* keepViewer = fpVisManager->GetCurrentViewer();
86 
88  G4int keepVerbose = UImanager->GetVerboseLevel();
89  G4int newVerbose(0);
90  if (keepVerbose >= 2 ||
92  newVerbose = 2;
93  UImanager->SetVerboseLevel(newVerbose);
94  UImanager->ApplyCommand(G4String("/vis/open " + system));
95  if (fErrorCode == 0) {
96  UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
97  UImanager->ApplyCommand("/vis/viewer/flush");
98  if (keepViewer) {
100  G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
101  }
103  fpVisManager->SetCurrentScene(keepScene);
104  fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
105  fpVisManager->SetCurrentViewer(keepViewer);
106  }
107  }
108  UImanager->SetVerboseLevel(keepVerbose);
109 }
110 
112 
114  G4bool omitable;
115  fpCommand = new G4UIcommand("/vis/drawView", this);
116  fpCommand->SetGuidance
117  ("Draw view from this angle, etc.");
118  G4UIparameter* parameter;
119  parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
120  parameter -> SetDefaultValue(0.);
121  fpCommand -> SetParameter (parameter);
122  parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
123  parameter -> SetDefaultValue(0.);
124  fpCommand -> SetParameter (parameter);
125  parameter = new G4UIparameter("pan-right", 'd', omitable = true);
126  parameter -> SetDefaultValue(0.);
127  fpCommand -> SetParameter (parameter);
128  parameter = new G4UIparameter("pan-up", 'd', omitable = true);
129  parameter -> SetDefaultValue(0.);
130  fpCommand -> SetParameter (parameter);
131  parameter = new G4UIparameter("pan-unit", 's', omitable = true);
132  parameter -> SetDefaultValue("cm");
133  fpCommand -> SetParameter (parameter);
134  parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
135  parameter -> SetDefaultValue(1.);
136  fpCommand -> SetParameter (parameter);
137  parameter = new G4UIparameter("dolly", 'd', omitable = true);
138  parameter -> SetDefaultValue(0.);
139  fpCommand -> SetParameter (parameter);
140  parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
141  parameter -> SetDefaultValue("cm");
142  fpCommand -> SetParameter (parameter);
143 }
144 
146  delete fpCommand;
147 }
148 
150 
152 
153  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
154  if (!currentViewer) {
155  if (verbosity >= G4VisManager::warnings) {
156  G4cout <<
157  "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
158  << G4endl;
159  }
160  return;
161  }
162 
163  G4String thetaDeg;
164  G4String phiDeg;
165  G4String panRight;
166  G4String panUp;
167  G4String panUnit;
168  G4String zoomFactor;
169  G4String dolly;
170  G4String dollyUnit;
171  std::istringstream is(newValue);
172  is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
173  >> zoomFactor >> dolly >> dollyUnit;
174 
175  G4UImanager* UImanager = G4UImanager::GetUIpointer();
176  G4int keepVerbose = UImanager->GetVerboseLevel();
177  G4int newVerbose(0);
178  if (keepVerbose >= 2 ||
180  newVerbose = 2;
181  UImanager->SetVerboseLevel(newVerbose);
182  G4ViewParameters vp = currentViewer->GetViewParameters();
183  G4bool keepAutoRefresh = vp.IsAutoRefresh();
184  vp.SetAutoRefresh(false);
185  currentViewer->SetViewParameters(vp);
186  UImanager->ApplyCommand(
187  G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
188  UImanager->ApplyCommand(
189  G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
190  UImanager->ApplyCommand(
191  G4String("/vis/viewer/zoomTo " + zoomFactor));
192  vp = currentViewer->GetViewParameters();
193  vp.SetAutoRefresh(keepAutoRefresh);
194  currentViewer->SetViewParameters(vp);
195  UImanager->ApplyCommand(
196  G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
197  UImanager->SetVerboseLevel(keepVerbose);
198 }
199 
201 
203  G4bool omitable;
204  fpCommand = new G4UIcmdWithAString("/vis/drawVolume", this);
205  fpCommand->SetGuidance
206  ("Creates a scene containing this physical volume and asks the"
207  "\ncurrent viewer to draw it. The scene becomes current.");
208  fpCommand -> SetGuidance
209  ("If physical-volume-name is \"world\" (the default), the main geometry"
210  "\ntree (material world) is drawn. If \"worlds\", all worlds - material"
211  "\nworld and parallel worlds, if any - are drawn. Otherwise a search of"
212  "\nall worlds is made, taking the first matching occurence only. To see"
213  "\na representation of the geometry hierarchy of the worlds, try"
214  "\n\"/vis/drawTree worlds\" or one of the driver/browser combinations"
215  "\nthat have the required functionality, e.g., HepRepFile/HepRApp.");
216  fpCommand->SetParameterName("physical-volume-name", omitable = true);
217  fpCommand->SetDefaultValue("world");
218 }
219 
221  delete fpCommand;
222 }
223 
226  G4UImanager* UImanager = G4UImanager::GetUIpointer();
227  G4int keepVerbose = UImanager->GetVerboseLevel();
228  G4int newVerbose(0);
229  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
230  newVerbose = 2;
231  UImanager->SetVerboseLevel(newVerbose);
232  UImanager->ApplyCommand("/vis/scene/create");
233  UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
234  UImanager->ApplyCommand("/vis/sceneHandler/attach");
235  UImanager->SetVerboseLevel(keepVerbose);
236  static G4bool warned = false;
237  if (verbosity >= G4VisManager::confirmations && !warned) {
238  G4cout <<
239  "NOTE: For systems which are not \"auto-refresh\" you will need to"
240  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
241  << G4endl;
242  warned = true;
243  }
244 }
245 
247 
249  G4bool omitable;
250  fpCommand = new G4UIcommand("/vis/open", this);
251  fpCommand->SetGuidance
252  ("Creates a scene handler ready for drawing.");
253  fpCommand->SetGuidance
254  ("The scene handler becomes current (the name is auto-generated).");
255  G4UIparameter* parameter;
256  parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
257  fpCommand->SetParameter(parameter);
258  parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
259  parameter->SetGuidance
260  ("integer (pixels) for square window placed by window manager or"
261  " X-Windows-type geometry string, e.g. 600x600-100+100");
262  parameter->SetDefaultValue("600");
263  fpCommand->SetParameter(parameter);
264 }
265 
267  delete fpCommand;
268 }
269 
271  G4String systemName, windowSizeHint;
272  std::istringstream is(newValue);
273  is >> systemName >> windowSizeHint;
274  G4UImanager* UImanager = G4UImanager::GetUIpointer();
275  G4int keepVerbose = UImanager->GetVerboseLevel();
276  G4int newVerbose(0);
277  if (keepVerbose >= 2 ||
279  newVerbose = 2;
280  UImanager->SetVerboseLevel(newVerbose);
281  fErrorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
282  if (fErrorCode == 0) {
283  UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
284  } else {
285  // Use set to get alphabetical order
286  std::set<G4String> candidates;
287  for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) {
288  // Just list nicknames, but exclude FALLBACK nicknames
289  for (const auto& nickname: gs->GetNicknames()) {
290  if (!nickname.contains("FALLBACK")) {
291  candidates.insert(nickname);
292  }
293  }
294  }
295  G4cerr << "Candidates are:";
296  for (const auto& candidate: candidates) {
297  G4cerr << ' ' << candidate;
298  }
299  G4cerr << G4endl;
300  }
301  UImanager->SetVerboseLevel(keepVerbose);
302 }
303 
305 
307  G4bool omitable;
308  fpCommand = new G4UIcommand("/vis/specify", this);
309  fpCommand->SetGuidance
310  ("Draws logical volume with Boolean components, voxels and readout geometry.");
311  fpCommand->SetGuidance
312  ("Creates a scene consisting of this logical volume and asks the"
313  "\n current viewer to draw it to the specified depth of descent"
314  "\n showing boolean components (if any), voxels (if any),"
315  "\n readout geometry (if any) and local axes, under control of the"
316  "\n appropriate flag.");
317  fpCommand->SetGuidance
318  ("Note: voxels are not constructed until start of run - /run/beamOn."
319  "\n (For voxels without a run, \"/run/beamOn 0\".)");
320  fpCommand->SetGuidance("The scene becomes current.");
321  G4UIparameter* parameter;
322  parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
323  fpCommand->SetParameter(parameter);
324  parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
325  parameter->SetDefaultValue(1);
326  fpCommand->SetParameter(parameter);
327  parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
328  parameter->SetDefaultValue(true);
329  fpCommand->SetParameter(parameter);
330  parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
331  parameter->SetDefaultValue(true);
332  fpCommand->SetParameter(parameter);
333  parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
334  parameter->SetDefaultValue(true);
335  fpCommand->SetParameter(parameter);
336  parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
337  parameter->SetDefaultValue(true);
338  parameter -> SetGuidance ("Set \"false\" to suppress axes.");
339  fpCommand->SetParameter(parameter);
340 }
341 
343  delete fpCommand;
344 }
345 
348  G4UImanager* UImanager = G4UImanager::GetUIpointer();
349  G4int keepVerbose = UImanager->GetVerboseLevel();
350  G4int newVerbose(0);
351  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
352  newVerbose = 2;
353  UImanager->SetVerboseLevel(newVerbose);
354  // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
355  UImanager->ApplyCommand("/vis/scene/create");
356  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
357  UImanager->ApplyCommand("/vis/sceneHandler/attach");
358  UImanager->SetVerboseLevel(keepVerbose);
359  static G4bool warned = false;
360  if (verbosity >= G4VisManager::confirmations && !warned) {
361  G4cout <<
362  "NOTE: For systems which are not \"auto-refresh\" you will need to"
363  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
364  << G4endl;
365  warned = true;
366  }
367 }
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:120
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:59
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
static G4int fErrorCode
G4VViewer * GetCurrentViewer() const
void SetGuidance(const char *theGuidance)
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:447
G4Scene * GetCurrentScene() const
G4GLOB_DLL std::ostream G4cerr
static G4VisManager * fpVisManager