Geant4_10
G4VisCommands.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: G4VisCommands.cc 75567 2013-11-04 11:35:11Z gcosmo $
28 
29 // /vis/ top level commands - John Allison 5th February 2001
30 
31 #include "G4VisCommands.hh"
32 
33 #include "G4VisManager.hh"
34 #include "G4UImanager.hh"
35 #include "G4UIcmdWithABool.hh"
36 #include "G4UIcmdWithAString.hh"
38 #include "G4RunManager.hh"
39 #include "G4Run.hh"
40 #include "G4UIsession.hh"
41 #include "G4Trajectory.hh"
42 #include "G4TrajectoryPoint.hh"
43 #include "G4RichTrajectory.hh"
44 #include "G4RichTrajectoryPoint.hh"
45 #include "G4SmoothTrajectory.hh"
47 #include "G4PhysicalVolumeModel.hh"
48 #include "G4AttDef.hh"
49 
51 
53  G4bool omitable;
54 
55  fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
56  fpCommand -> SetGuidance("Abort review of kept events.");
57  fpCommand -> SetParameterName("abort", omitable=true);
58  fpCommand -> SetDefaultValue(true);
59 }
60 
62  delete fpCommand;
63 }
64 
66  return G4String();
67 }
68 
70  G4String newValue) {
72  G4cout << "Type \"continue\" to complete the abort." << G4endl;
73 }
74 
76 
78  G4bool omitable;
79 
80  fpCommand = new G4UIcmdWithABool("/vis/enable", this);
81  fpCommand -> SetGuidance("Enables/disables visualization system.");
82  fpCommand -> SetParameterName("enabled", omitable=true);
83  fpCommand -> SetDefaultValue(true);
84 
85  fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
86  fpCommand1 -> SetGuidance("Disables visualization system.");
87 }
88 
90  delete fpCommand;
91  delete fpCommand1;
92 }
93 
95  return G4String();
96 }
97 
99  G4String newValue) {
100  if (command == fpCommand) {
101  G4bool enable = G4UIcommand::ConvertToBool(newValue);
102  if (enable) fpVisManager->Enable(); // Printing is in vis manager.
103  else fpVisManager->Disable(); // Printing is in vis manager.
104  } else fpVisManager->Disable(); // Printing is in vis manager.
105  // Note: Printing is in vis manager.
106 }
107 
109 
111 {
112  fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
113  fpCommand -> SetGuidance("Initialise visualisation manager.");
114 }
115 
117  delete fpCommand;
118 }
119 
121  G4String) {
123 }
124 
126 
128 {
129  G4bool omitable;
130 
131  fpCommand = new G4UIcmdWithAString("/vis/list", this);
132  fpCommand -> SetGuidance("Lists visualization parameters.");
133  fpCommand -> SetParameterName("verbosity", omitable=true);
134  fpCommand -> SetDefaultValue("warnings");
135 }
136 
138 {
139  delete fpCommand;
140 }
141 
143 {
144  return "";
145 }
146 
148 {
149  G4String& verbosityString = newValue;
150  G4VisManager::Verbosity verbosity =
151  fpVisManager->GetVerbosityValue(verbosityString);
152 
154  G4cout << G4endl;
155  fpVisManager->PrintAvailableModels(verbosity);
156  G4cout << G4endl;
157  fpVisManager->PrintAvailableUserVisActions(verbosity);
158  G4cout << G4endl;
159  fpVisManager->PrintAvailableColours(verbosity);
160  G4cout << G4endl;
161  G4UImanager* UImanager = G4UImanager::GetUIpointer();
162  UImanager->ApplyCommand("/vis/scene/list ! c");
163  UImanager->ApplyCommand("/vis/viewer/list ! c");
164 
165  G4cout <<
166  "\nAttributes available for modeling and filtering with"
167  "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
168  "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
169  "\nand by picking:"
170  << G4endl;
178 
179  G4cout <<
180  "\nAttributes available for touchables by picking:"
181  << G4endl;
183 
184  if (verbosity < G4VisManager::parameters)
185  G4cout <<
186  "\nTo get more information, \"/vis/list all all\" or use individual commands"
187  "\n such as (use \"ls\" or \"help\"):"
188  "\n /vis/scene/list all all"
189  "\n /vis/viewer/list all all"
190  "\n /vis/modeling/trajectories/list"
191  "\n /vis/filtering/trajectories/list"
192  << G4endl;
193 }
194 
196 
198 {
199  G4bool omitable;
200 
201  fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
202  fpCommand -> SetGuidance("Review kept events.");
203  fpCommand -> SetGuidance
204  ("If a macro file is specified, it is executed for each event.");
205  fpCommand -> SetGuidance(
206  "If a macro file is not specified, each event is drawn to the current"
207  "\nviewer. After each event, the session is paused. The user may issue"
208  "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
209  "\nevent."
210  "\nUseful commands might be:"
211  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
212  "\n \"/vis/oglx/printEPS\" to get hard copy."
213  "\n \"/vis/open\" to get alternative viewer."
214  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
215  fpCommand -> SetParameterName("macro-file-name", omitable=true);
216  fpCommand -> SetDefaultValue("");
217 }
218 
220 {
221  delete fpCommand;
222 }
223 
225 {
226  return "";
227 }
228 
230 {
231  static bool reviewing = false;
232  if (reviewing) {
233  G4cout <<
234  "\"/vis/reviewKeptEvents\" not allowed within an already started review."
235  "\n No action taken."
236  << G4endl;
237  return;
238  }
239 
240  G4String& macroFileName = newValue;
242 
244  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
245  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
246  size_t nKeptEvents = events? events->size(): 0;
247 
248  if (!nKeptEvents) {
249  if (verbosity >= G4VisManager::errors) {
250  G4cout <<
251  "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
252  "\n or kept events not accessible."
253  << G4endl;
254  }
255  return;
256  }
257 
259  if (!viewer) {
260  if (verbosity >= G4VisManager::errors) {
261  G4cout <<
262  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
263  << G4endl;
264  }
265  return;
266  }
267 
268  G4Scene* pScene = fpVisManager->GetCurrentScene();
269  if (!pScene) {
270  if (verbosity >= G4VisManager::errors) {
271  G4cout << "ERROR: No current scene. Please create one." << G4endl;
272  }
273  return;
274  }
275 
276  G4UImanager* UImanager = G4UImanager::GetUIpointer();
277  G4int keepVerbose = UImanager->GetVerboseLevel();
278  G4int newVerbose(0);
279  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
280  newVerbose = 2;
281  UImanager->SetVerboseLevel(newVerbose);
282 
283  G4VVisManager* keepConcreteInstance = fpVisManager->GetConcreteInstance();
284  fpVisManager->Enable();
285 
286  // Event by event refreshing...
287  reviewing = true;
288  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
289  pScene->SetRefreshAtEndOfEvent(true);
290  if (macroFileName.empty()) {
291 
292  // Draw to viewer and pause session...
293  G4UIsession* session = UImanager->GetSession();
294  for (size_t i = 0; i < nKeptEvents; ++i) {
295  const G4Event* event = (*events)[i];
296  if (verbosity >= G4VisManager::warnings) {
297  G4cout << "Drawing event : " << event->GetEventID() <<
298  ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
299  << G4endl;
300  static G4bool first = true;
301  if (first) {
302  first = false;
303  G4cout <<
304  " Useful commands might be:"
305  "\n \"/vis/scene/add/trajectories\" if not already added."
306  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
307  "\n \"/vis/oglx/printEPS\" to get hard copy."
308  "\n \"/vis/open\" to get alternative viewer."
309  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
310  << G4endl;
311  }
312  }
314  UImanager->ApplyCommand("/vis/viewer/rebuild");
315  /* The above command forces a rebuild of the scene, including
316  the detector. This is fine for "immediate" viewers - a
317  refresh requires a rebuild anyway. But for "stored mode"
318  viewers, you could, in principle, avoid a rebuild of the
319  detector with something like the following:
320  sceneHandler->ClearTransientStore();
321  viewer->DrawView();
322  sceneHandler->DrawEvent(event);
323  but this causes mayhem for "immediate" viewers because
324  ClearTransientStore issues a DrawView and some curious sort
325  of recursion takes place. For "stored" viewers, the event
326  gets drawn but not the eventID, so something odd is happening
327  there too. This needs further investigation - enhanced
328  features or a complete re-think.
329  */
330  UImanager->ApplyCommand("/vis/viewer/flush");
331  session->PauseSessionStart("EndOfEvent");
334  }
336 
337  } else {
338 
339  // Execute macro file...
340  for (size_t i = 0; i < nKeptEvents; ++i) {
341  const G4Event* event = (*events)[i];
342  if (verbosity >= G4VisManager::warnings) {
343  G4cout << "Drawing event : " << event->GetEventID()
344  << " with macro file \"" << macroFileName << G4endl;
345  }
347  UImanager->ApplyCommand("/control/execute " + macroFileName);
349  }
350  }
351  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
352  reviewing = false;
353 
354  if (keepConcreteInstance) fpVisManager->Enable();
355  else fpVisManager->Disable();
356  UImanager->SetVerboseLevel(keepVerbose);
357 }
358 
360 
362  G4bool omitable;
363 
364  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
365  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
366  fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
367  }
368  fpCommand -> SetParameterName("verbosity", omitable=true);
369  fpCommand -> SetDefaultValue("warnings");
370 }
371 
373  delete fpCommand;
374 }
375 
377  return G4String();
378 }
379 
381  G4String newValue) {
382  G4VisManager::Verbosity verbosity =
383  fpVisManager->GetVerbosityValue(newValue);
384  fpVisManager->SetVerboseLevel(verbosity);
385  // Always prints whatever the verbosity...
386  G4cout << "Visualization verbosity changed to "
387  << G4VisManager::VerbosityString(verbosity) << G4endl;
388 }
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual ~G4VisCommandEnable()
G4UIsession * GetSession() const
Definition: G4UImanager.hh:208
const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual void PauseSessionStart(const G4String &Prompt)
Definition: G4UIsession.cc:40
G4String GetCurrentValue(G4UIcommand *command)
static G4VVisManager * GetConcreteInstance()
virtual ~G4VisCommandList()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetVerboseLevel(G4int)
virtual ~G4VisCommandVerbose()
void SetRequestedEvent(const G4Event *)
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
virtual ~G4VisCommandInitialize()
G4bool GetRefreshAtEndOfEvent() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
static std::vector< G4String > VerbosityGuidanceStrings
void SetNewValue(G4UIcommand *command, G4String newValue)
int G4int
Definition: G4Types.hh:78
static Verbosity GetVerbosityValue(const G4String &)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
const G4Run * GetCurrentRun() const
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:225
G4String GetCurrentValue(G4UIcommand *command)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void PrintAvailableGraphicsSystems() const
G4GLOB_DLL std::ostream G4cout
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:411
bool G4bool
Definition: G4Types.hh:79
G4String GetCurrentValue(G4UIcommand *command)
Definition: G4Run.hh:46
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void Initialize()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
static G4String VerbosityString(Verbosity)
G4int first
const std::map< G4String, G4AttDef > * GetAttDefs() const
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61
G4VViewer * GetCurrentViewer() const
G4bool GetAbortReviewKeptEvents() const
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419
G4Scene * GetCurrentScene() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetRefreshAtEndOfEvent(G4bool)
void SetAbortReviewKeptEvents(G4bool)
static G4VisManager * fpVisManager
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const