ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommandsCompound.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisCommandsCompound.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 // Compound /vis/ commands - John Allison 15th May 2000
29 
30 #include "G4VisCommandsCompound.hh"
31 
32 #include "G4VisManager.hh"
33 #include "G4UImanager.hh"
34 #include "G4UIcommandTree.hh"
35 #include "G4UIcmdWithAString.hh"
36 
37 #include <sstream>
38 #include <set>
39 
41 
43  G4bool omitable;
44  fpCommand = new G4UIcommand("/vis/drawTree", this);
46  ("Produces a representation of the geometry hierarchy. Further"
47  "\nguidance is given on running the command. Or look at the guidance"
48  "\nfor \"/vis/ASCIITree/verbose\".");
49  fpCommand->SetGuidance("The pre-existing scene and view are preserved.");
50  G4UIparameter* parameter;
51  parameter = new G4UIparameter("physical-volume-name", 's', omitable = true);
52  parameter -> SetDefaultValue("world");
53  fpCommand -> SetParameter (parameter);
54  parameter = new G4UIparameter("system", 's', omitable = true);
55  parameter -> SetDefaultValue("ATree");
56  fpCommand -> SetParameter (parameter);
57 }
58 
60  delete fpCommand;
61 }
62 
64 
65  G4String pvname, system;
66  std::istringstream is(newValue);
67  is >> pvname >> system;
68 
69  // Note: The second parameter, "system", is intended to allow the user
70  // a choice of dedicated tree printing/displaying systems but at present
71  // the only such dedicated system is ASCIITree. It doesn't make sense to
72  // specify OGLSX, for example. So to avoid confusion we restrict this
73  // feature to systems that have "Tree" in the name or nickname.
74 
75  // Of course, some other systems, such as OGLSQt, have a tree browser
76  // built-in. The HepRApp offline browser also has a tree browser
77  // built in.
78 
79  if (!system.contains("Tree")) {
80  system = "ATree";
81  }
82 
84  G4Scene* keepScene = fpVisManager->GetCurrentScene();
86  G4VViewer* keepViewer = fpVisManager->GetCurrentViewer();
88 
90  G4int keepUIVerbose = UImanager->GetVerboseLevel();
91  G4int newVerbose(0);
92  if (keepUIVerbose >= 2 ||
94  newVerbose = 2;
95  UImanager->SetVerboseLevel(newVerbose);
96 
97  G4bool keepAbleness = fpVisManager->GetConcreteInstance()? true: false;
98 
99  UImanager->ApplyCommand(G4String("/vis/open " + system));
100  if (fErrorCode == 0) {
101  if (!keepAbleness) { // Enable temporarily
102  fpVisManager->SetVerboseLevel("Quiet");
103  UImanager->ApplyCommand("/vis/enable");
104  fpVisManager->SetVerboseLevel(keepVisVerbosity);
105  }
106  UImanager->ApplyCommand(G4String("/vis/drawVolume " + pvname));
107  UImanager->ApplyCommand("/vis/viewer/flush");
108  if (!keepAbleness) { // Disable again
109  fpVisManager->SetVerboseLevel("Quiet");
110  UImanager->ApplyCommand("/vis/disable");
111  fpVisManager->SetVerboseLevel(keepVisVerbosity);
112  }
113  if (keepViewer) {
115  G4cout << "Reverting to " << keepViewer->GetName() << G4endl;
116  }
118  fpVisManager->SetCurrentScene(keepScene);
119  fpVisManager->SetCurrentSceneHandler(keepSceneHandler);
120  fpVisManager->SetCurrentViewer(keepViewer);
121  }
122  }
123  UImanager->SetVerboseLevel(keepUIVerbose);
124 }
125 
127 
129  G4bool omitable;
130  fpCommand = new G4UIcommand("/vis/drawView", this);
132  ("Draw view from this angle, etc.");
133  G4UIparameter* parameter;
134  parameter = new G4UIparameter("theta-degrees", 'd', omitable = true);
135  parameter -> SetDefaultValue(0.);
136  fpCommand -> SetParameter (parameter);
137  parameter = new G4UIparameter("phi-degrees", 'd', omitable = true);
138  parameter -> SetDefaultValue(0.);
139  fpCommand -> SetParameter (parameter);
140  parameter = new G4UIparameter("pan-right", 'd', omitable = true);
141  parameter -> SetDefaultValue(0.);
142  fpCommand -> SetParameter (parameter);
143  parameter = new G4UIparameter("pan-up", 'd', omitable = true);
144  parameter -> SetDefaultValue(0.);
145  fpCommand -> SetParameter (parameter);
146  parameter = new G4UIparameter("pan-unit", 's', omitable = true);
147  parameter -> SetDefaultValue("cm");
148  fpCommand -> SetParameter (parameter);
149  parameter = new G4UIparameter("zoom-factor", 'd', omitable = true);
150  parameter -> SetDefaultValue(1.);
151  fpCommand -> SetParameter (parameter);
152  parameter = new G4UIparameter("dolly", 'd', omitable = true);
153  parameter -> SetDefaultValue(0.);
154  fpCommand -> SetParameter (parameter);
155  parameter = new G4UIparameter("dolly-unit", 's', omitable = true);
156  parameter -> SetDefaultValue("cm");
157  fpCommand -> SetParameter (parameter);
158 }
159 
161  delete fpCommand;
162 }
163 
165 
167 
168  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
169  if (!currentViewer) {
170  if (verbosity >= G4VisManager::warnings) {
171  G4cout <<
172  "WARNING: G4VisCommandsDrawView::SetNewValue: no current viewer."
173  << G4endl;
174  }
175  return;
176  }
177 
178  G4String thetaDeg;
179  G4String phiDeg;
180  G4String panRight;
181  G4String panUp;
182  G4String panUnit;
183  G4String zoomFactor;
184  G4String dolly;
185  G4String dollyUnit;
186  std::istringstream is(newValue);
187  is >> thetaDeg >> phiDeg >> panRight >> panUp >> panUnit
188  >> zoomFactor >> dolly >> dollyUnit;
189 
190  G4UImanager* UImanager = G4UImanager::GetUIpointer();
191  G4int keepVerbose = UImanager->GetVerboseLevel();
192  G4int newVerbose(0);
193  if (keepVerbose >= 2 ||
195  newVerbose = 2;
196  UImanager->SetVerboseLevel(newVerbose);
197  G4ViewParameters vp = currentViewer->GetViewParameters();
198  G4bool keepAutoRefresh = vp.IsAutoRefresh();
199  vp.SetAutoRefresh(false);
200  currentViewer->SetViewParameters(vp);
201  UImanager->ApplyCommand(
202  G4String("/vis/viewer/set/viewpointThetaPhi " + thetaDeg + " " + phiDeg + " deg"));
203  UImanager->ApplyCommand(
204  G4String("/vis/viewer/panTo " + panRight + " " + panUp + " " + panUnit));
205  UImanager->ApplyCommand(
206  G4String("/vis/viewer/zoomTo " + zoomFactor));
207  vp = currentViewer->GetViewParameters();
208  vp.SetAutoRefresh(keepAutoRefresh);
209  currentViewer->SetViewParameters(vp);
210  UImanager->ApplyCommand(
211  G4String("/vis/viewer/dollyTo " + dolly + " " + dollyUnit));
212  UImanager->SetVerboseLevel(keepVerbose);
213 }
214 
216 
218  fpCommand = new G4UIcommand("/vis/drawLogicalVolume", this);
220  ("Draws logical volume with additional components.");
222  ("Synonymous with \"/vis/specify\".");
224  ("Creates a scene consisting of this logical volume and asks the"
225  "\n current viewer to draw it. The scene becomes current.");
227  const G4UIcommand* addLogVolCmd = tree->FindPath("/vis/scene/add/logicalVolume");
228  // Pick up guidance from /vis/scene/add/logicalVolume
229  CopyGuidanceFrom(addLogVolCmd,fpCommand);
230  // Pick up parameters from /vis/scene/add/logicalVolume
231  CopyParametersFrom(addLogVolCmd,fpCommand);
232 }
233 
235  delete fpCommand;
236 }
237 
240  G4UImanager* UImanager = G4UImanager::GetUIpointer();
241  G4int keepVerbose = UImanager->GetVerboseLevel();
242  G4int newVerbose(0);
243  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
244  newVerbose = 2;
245  UImanager->SetVerboseLevel(newVerbose);
246  G4VViewer* currentViewer = fpVisManager->GetCurrentViewer();
247  const G4ViewParameters& currentViewParams = currentViewer->GetViewParameters();
248  G4bool keepAutoRefresh = currentViewParams.IsAutoRefresh();
249  if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh false");
250  UImanager->ApplyCommand("/vis/scene/create");
251  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
252  UImanager->ApplyCommand("/vis/sceneHandler/attach");
253  G4ViewParameters::DrawingStyle keepDrawingStyle = currentViewParams.GetDrawingStyle();
254  if(keepDrawingStyle != G4ViewParameters::wireframe)
255  UImanager->ApplyCommand("/vis/viewer/set/style wireframe");
256  G4bool keepMarkerNotHidden = currentViewParams.IsMarkerNotHidden();
257  if (!keepMarkerNotHidden) UImanager->ApplyCommand("/vis/viewer/set/hiddenMarker false");
258  if (keepAutoRefresh) UImanager->ApplyCommand("/vis/viewer/set/autoRefresh true");
259  UImanager->SetVerboseLevel(keepVerbose);
260  if (verbosity >= G4VisManager::warnings) {
261  if (keepDrawingStyle != currentViewParams.GetDrawingStyle()) {
262  G4cout
263  << "Drawing style changed to wireframe. To restore previous style:";
264  G4String style, edge;
265  switch (keepDrawingStyle) {
267  style = "wireframe"; edge = "false"; break;
269  style = "wireframe"; edge = "true"; break;
271  style = "surface"; edge = "false"; break;
273  style = "surface"; edge = "true"; break;
275  style = "cloud"; edge = ""; break;
276  }
277  G4cout << "\n /vis/viewer/set/style " + style;
278  if (!edge.empty()) G4cout << "\n /vis/viewer/set/hiddenEdge " + edge;
279  G4cout << G4endl;
280  }
281  if (keepMarkerNotHidden != currentViewParams.IsMarkerNotHidden()) {
282  G4cout
283  << "Markers changed to \"not hidden\". To restore previous condition:"
284  << "\n /vis/viewer/set/hiddenmarker true"
285  << G4endl;
286  }
287  }
288  static G4bool warned = false;
289  if (verbosity >= G4VisManager::confirmations && !warned) {
290  G4cout <<
291  "NOTE: For systems which are not \"auto-refresh\" you will need to"
292  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
293  << G4endl;
294  warned = true;
295  }
296 }
297 
299 
301  fpCommand = new G4UIcommand("/vis/drawVolume", this);
303  ("Creates a scene containing this physical volume and asks the"
304  "\ncurrent viewer to draw it. The scene becomes current.");
306  const G4UIcommand* addVolCmd = tree->FindPath("/vis/scene/add/volume");
307  // Pick up guidance from /vis/scene/add/volume
308  CopyGuidanceFrom(addVolCmd,fpCommand);
309  // Pick up parameters from /vis/scene/add/volume
310  CopyParametersFrom(addVolCmd,fpCommand);
311 }
312 
314  delete fpCommand;
315 }
316 
319  G4UImanager* UImanager = G4UImanager::GetUIpointer();
320  G4int keepVerbose = UImanager->GetVerboseLevel();
321  G4int newVerbose(0);
322  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
323  newVerbose = 2;
324  UImanager->SetVerboseLevel(newVerbose);
325  UImanager->ApplyCommand("/vis/scene/create");
326  UImanager->ApplyCommand(G4String("/vis/scene/add/volume " + newValue));
327  UImanager->ApplyCommand("/vis/sceneHandler/attach");
328  UImanager->SetVerboseLevel(keepVerbose);
329  static G4bool warned = false;
330  if (verbosity >= G4VisManager::confirmations && !warned) {
331  G4cout <<
332  "NOTE: For systems which are not \"auto-refresh\" you will need to"
333  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
334  << G4endl;
335  warned = true;
336  }
337 }
338 
340 
342  G4bool omitable;
343  fpCommand = new G4UIcommand("/vis/open", this);
345  ("Creates a scene handler ready for drawing.");
347  ("The scene handler becomes current (the name is auto-generated).");
348  G4UIparameter* parameter;
349  parameter = new G4UIparameter("graphics-system-name", 's', omitable = false);
350  fpCommand->SetParameter(parameter);
351  parameter = new G4UIparameter("window-size-hint", 's', omitable = true);
352  parameter->SetGuidance
353  ("integer (pixels) for square window placed by window manager or"
354  " X-Windows-type geometry string, e.g. 600x600-100+100");
355  parameter->SetDefaultValue("600");
356  fpCommand->SetParameter(parameter);
357 }
358 
360  delete fpCommand;
361 }
362 
364  G4String systemName, windowSizeHint;
365  std::istringstream is(newValue);
366  is >> systemName >> windowSizeHint;
367  G4UImanager* UImanager = G4UImanager::GetUIpointer();
368  G4int keepVerbose = UImanager->GetVerboseLevel();
369  G4int newVerbose(0);
370  if (keepVerbose >= 2 ||
372  newVerbose = 2;
373  UImanager->SetVerboseLevel(newVerbose);
374  fErrorCode = UImanager->ApplyCommand(G4String("/vis/sceneHandler/create " + systemName));
375  if (fErrorCode == 0) {
376  UImanager->ApplyCommand(G4String("/vis/viewer/create ! ! " + windowSizeHint));
377  } else {
378  // Use set to get alphabetical order
379  std::set<G4String> candidates;
380  for (const auto gs: fpVisManager -> GetAvailableGraphicsSystems()) {
381  // Just list nicknames, but exclude FALLBACK nicknames
382  for (const auto& nickname: gs->GetNicknames()) {
383  if (!nickname.contains("FALLBACK")) {
384  candidates.insert(nickname);
385  }
386  }
387  }
388  G4cerr << "Candidates are:";
389  for (const auto& candidate: candidates) {
390  G4cerr << ' ' << candidate;
391  }
392  G4cerr << G4endl;
393  }
394  UImanager->SetVerboseLevel(keepVerbose);
395 }
396 
398 
400  G4bool omitable;
401  fpCommand = new G4UIcommand("/vis/specify", this);
403  ("Draws logical volume with Boolean components, voxels and readout geometry.");
405  ("Synonymous with \"/vis/drawLogicalVolume\".");
407  ("Creates a scene consisting of this logical volume and asks the"
408  "\n current viewer to draw it to the specified depth of descent"
409  "\n showing boolean components (if any), voxels (if any),"
410  "\n readout geometry (if any), local axes and overlaps (if any),"
411  "\n under control of the appropriate flag.");
413  ("Note: voxels are not constructed until start of run - /run/beamOn."
414  "\n (For voxels without a run, \"/run/beamOn 0\".)");
415  fpCommand->SetGuidance("The scene becomes current.");
416  G4UIparameter* parameter;
417  parameter = new G4UIparameter("logical-volume-name", 's', omitable = false);
418  fpCommand->SetParameter(parameter);
419  parameter = new G4UIparameter("depth-of-descent", 'i', omitable = true);
420  parameter->SetDefaultValue(1);
421  fpCommand->SetParameter(parameter);
422  parameter = new G4UIparameter("booleans-flag", 'b', omitable = true);
423  parameter->SetDefaultValue(true);
424  fpCommand->SetParameter(parameter);
425  parameter = new G4UIparameter("voxels-flag", 'b', omitable = true);
426  parameter->SetDefaultValue(true);
427  fpCommand->SetParameter(parameter);
428  parameter = new G4UIparameter("readout-flag", 'b', omitable = true);
429  parameter->SetDefaultValue(true);
430  fpCommand->SetParameter(parameter);
431  parameter = new G4UIparameter("axes-flag", 'b', omitable = true);
432  parameter->SetDefaultValue(true);
433  parameter -> SetGuidance ("Set \"false\" to suppress axes.");
434  fpCommand->SetParameter(parameter);
435  parameter = new G4UIparameter("check-overlap-flag", 'b', omitable = true);
436  parameter->SetDefaultValue(true);
437  parameter -> SetGuidance ("Set \"false\" to suppress overlap check.");
438  fpCommand->SetParameter(parameter);
439 }
440 
442  delete fpCommand;
443 }
444 
447  G4UImanager* UImanager = G4UImanager::GetUIpointer();
448  G4int keepVerbose = UImanager->GetVerboseLevel();
449  G4int newVerbose(0);
450  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
451  newVerbose = 2;
452  UImanager->SetVerboseLevel(newVerbose);
453  // UImanager->ApplyCommand(G4String("/geometry/print " + newValue));
454  UImanager->ApplyCommand("/vis/scene/create");
455  UImanager->ApplyCommand(G4String("/vis/scene/add/logicalVolume " + newValue));
456  UImanager->ApplyCommand("/vis/sceneHandler/attach");
457  UImanager->SetVerboseLevel(keepVerbose);
458  static G4bool warned = false;
459  if (verbosity >= G4VisManager::confirmations && !warned) {
460  G4cout <<
461  "NOTE: For systems which are not \"auto-refresh\" you will need to"
462  "\n issue \"/vis/viewer/refresh\" or \"/vis/viewer/flush\"."
463  << G4endl;
464  warned = true;
465  }
466 }