Geant4_10
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 66870 2013-01-14 23:38:59Z adotti $
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);
44  fpCommand->SetGuidance
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);
100  fpCommand->SetGuidance
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);
189  fpCommand->SetGuidance
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);
235  fpCommand->SetGuidance
236  ("Creates a scene handler ready for drawing.");
237  fpCommand->SetGuidance
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  const G4GraphicsSystemList& gslist =
243  G4String candidates;
244  for (size_t igslist = 0; igslist < gslist.size(); igslist++) {
245  const G4String& name = gslist[igslist]->GetName();
246  const G4String& nickname = gslist[igslist]->GetNickname();
247  if (nickname.isNull()) {
248  candidates += name;
249  }
250  else {
251  candidates += nickname;
252  }
253  candidates += " ";
254  }
255  candidates = candidates.strip();
256  parameter->SetParameterCandidates(candidates);
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  UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
282  UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
283  UImanager->SetVerboseLevel(keepVerbose);
284 }
285 
287 
289  G4bool omitable;
290  fpCommand = new G4UIcommand("/vis/specify", this);
291  fpCommand->SetGuidance
292  ("Draws logical volume with Boolean components, voxels and readout geometry.");
293  fpCommand->SetGuidance
294  ("Creates a scene consisting of this logical volume and asks the"
295  "\n current viewer to draw it to the specified depth of descent"
296  "\n showing boolean components (if any), voxels (if any)"
297  "\n and readout geometry (if any), under control of the appropriate flag.");
298  fpCommand->SetGuidance
299  ("Note: voxels are not constructed until start of run - /run/beamOn.");
300  fpCommand->SetGuidance("The scene becomes current.");
301  G4UIparameter* parameter;
302  parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
303  fpCommand->SetParameter(parameter);
304  parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
305  parameter->SetDefaultValue(1);
306  fpCommand->SetParameter(parameter);
307  parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
308  parameter->SetDefaultValue(true);
309  fpCommand->SetParameter(parameter);
310  parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
311  parameter->SetDefaultValue(true);
312  fpCommand->SetParameter(parameter);
313  parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
314  parameter->SetDefaultValue(true);
315  fpCommand->SetParameter(parameter);
316 }
317 
319  delete fpCommand;
320 }
321 
324  G4UImanager* UImanager = G4UImanager::GetUIpointer();
325  G4int keepVerbose = UImanager->GetVerboseLevel();
326  G4int newVerbose(0);
327  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
328  newVerbose = 2;
329  UImanager->SetVerboseLevel(newVerbose);
330  // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
331  UImanager->ApplyCommand("/vis/scene/create");
332  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
333  UImanager->ApplyCommand("/vis/sceneHandler/attach");
334  UImanager->SetVerboseLevel(keepVerbose);
335  static G4bool warned = false;
336  if (verbosity >= G4VisManager::confirmations && !warned) {
337  G4cout <<
338  "NOTE: For systems which are not \"auto-refresh\" you will need to"
339  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
340  << G4endl;
341  warned = true;
342  }
343 }
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 *)
G4String strip(G4int strip_Type=trailing, char c=' ')
void SetParameterCandidates(const char *theString)
const G4ViewParameters & GetViewParameters() const
void SetDefaultValue(const char *theDefaultValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
const XML_Char * name
Definition: expat.h:151
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)
system("rm -rf dna.root")
G4VSceneHandler * GetCurrentSceneHandler() const
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
void SetGuidance(const char *theGuidance)
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
G4bool isNull() const
G4bool IsAutoRefresh() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
G4Scene * GetCurrentScene() const
static G4VisManager * fpVisManager