Geant4  10.03
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 93025 2015-09-30 16:02:12Z 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 #ifdef G4MULTITHREADED
40 #include "G4MTRunManager.hh"
41 #endif
42 #include "G4Run.hh"
43 #include "G4UIsession.hh"
44 #include "G4Trajectory.hh"
45 #include "G4TrajectoryPoint.hh"
46 #include "G4RichTrajectory.hh"
47 #include "G4RichTrajectoryPoint.hh"
48 #include "G4SmoothTrajectory.hh"
50 #include "G4PhysicalVolumeModel.hh"
51 #include "G4AttDef.hh"
52 
54 
56  G4bool omitable;
57 
58  fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
59  fpCommand -> SetGuidance("Abort review of kept events.");
60  fpCommand -> SetParameterName("abort", omitable=true);
61  fpCommand -> SetDefaultValue(true);
62 }
63 
65  delete fpCommand;
66 }
67 
69  return G4String();
70 }
71 
73  G4String newValue) {
75  G4cout << "Type \"continue\" to complete the abort." << G4endl;
76 }
77 
79 
81  G4bool omitable;
82 
83  fpCommand = new G4UIcmdWithABool("/vis/enable", this);
84  fpCommand -> SetGuidance("Enables/disables visualization system.");
85  fpCommand -> SetParameterName("enabled", omitable=true);
86  fpCommand -> SetDefaultValue(true);
87 
88  fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
89  fpCommand1 -> SetGuidance("Disables visualization system.");
90 }
91 
93  delete fpCommand;
94  delete fpCommand1;
95 }
96 
98  return G4String();
99 }
100 
102  G4String newValue) {
103  if (command == fpCommand) {
104  G4bool enable = G4UIcommand::ConvertToBool(newValue);
105  if (enable) fpVisManager->Enable(); // Printing is in vis manager.
106  else fpVisManager->Disable(); // Printing is in vis manager.
107  } else fpVisManager->Disable(); // Printing is in vis manager.
108  // Note: Printing is in vis manager.
109 }
110 
112 
114 {
115  fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
116  fpCommand -> SetGuidance("Initialise visualisation manager.");
117 }
118 
120  delete fpCommand;
121 }
122 
124  G4String) {
126 }
127 
129 
131 {
132  G4bool omitable;
133 
134  fpCommand = new G4UIcmdWithAString("/vis/list", this);
135  fpCommand -> SetGuidance("Lists visualization parameters.");
136  fpCommand -> SetParameterName("verbosity", omitable=true);
137  fpCommand -> SetDefaultValue("warnings");
138 }
139 
141 {
142  delete fpCommand;
143 }
144 
146 {
147  return "";
148 }
149 
151 {
152  G4String& verbosityString = newValue;
153  G4VisManager::Verbosity verbosity =
154  fpVisManager->GetVerbosityValue(verbosityString);
155 
157  G4cout << G4endl;
159  G4cout << G4endl;
161  G4cout << G4endl;
163  G4cout << G4endl;
164  G4UImanager* UImanager = G4UImanager::GetUIpointer();
165  UImanager->ApplyCommand("/vis/scene/list ! " + newValue);
166  UImanager->ApplyCommand("/vis/viewer/list ! " + newValue);
167 
168  G4cout <<
169  "\nAttributes available for modeling and filtering with"
170  "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
171  "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
172  "\nand by picking:"
173  << G4endl;
174  G4cout
176  G4cout
179  G4cout
182  G4cout
183  << *G4Trajectory().GetAttDefs()
185 
186  G4cout <<
187  "\nGeometry attributes available for touchables by picking:\n";
188  G4cout
190 
191  if (verbosity < G4VisManager::parameters)
192  G4cout <<
193  "\nTo get more information, \"/vis/list all\" or use individual commands"
194  "\n such as (use \"ls\" or \"help\"):"
195  "\n /vis/scene/list all all"
196  "\n /vis/viewer/list all all"
197  "\n /vis/modeling/trajectories/list"
198  "\n /vis/filtering/trajectories/list"
199  << G4endl;
200 }
201 
203 
205 {
206  G4bool omitable;
207 
208  fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
209  fpCommand -> SetGuidance("Review kept events.");
210  fpCommand -> SetGuidance
211  ("If a macro file is specified, it is executed for each event.");
212  fpCommand -> SetGuidance(
213  "If a macro file is not specified, each event is drawn to the current"
214  "\nviewer. After each event, the session is paused. The user may issue"
215  "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
216  "\nevent."
217  "\nUseful commands might be:"
218  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
219  "\n \"/vis/oglx/printEPS\" to get hard copy."
220  "\n \"/vis/open\" to get alternative viewer."
221  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
222  fpCommand -> SetParameterName("macro-file-name", omitable=true);
223  fpCommand -> SetDefaultValue("");
224 }
225 
227 {
228  delete fpCommand;
229 }
230 
232 {
233  return "";
234 }
235 
237 {
238  static bool reviewing = false;
239  if (reviewing) {
240  G4cout <<
241  "\"/vis/reviewKeptEvents\" not allowed within an already started review."
242  "\n No action taken."
243  << G4endl;
244  return;
245  }
246 
247  G4String& macroFileName = newValue;
249 
251 #ifdef G4MULTITHREADED
253  { runManager = G4MTRunManager::GetMasterRunManager(); }
254 #endif
255  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
256  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
257  size_t nKeptEvents = events? events->size(): 0;
258 
259  if (!nKeptEvents) {
260  if (verbosity >= G4VisManager::errors) {
261  G4cerr <<
262  "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
263  "\n or kept events not accessible."
264  << G4endl;
265  }
266  return;
267  }
268 
270  if (!viewer) {
271  if (verbosity >= G4VisManager::errors) {
272  G4cerr <<
273  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
274  << G4endl;
275  }
276  return;
277  }
278 
279  G4Scene* pScene = fpVisManager->GetCurrentScene();
280  if (!pScene) {
281  if (verbosity >= G4VisManager::errors) {
282  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
283  }
284  return;
285  }
286 
287  G4UImanager* UImanager = G4UImanager::GetUIpointer();
288  G4int keepVerbose = UImanager->GetVerboseLevel();
289  G4int newVerbose(0);
290  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
291  newVerbose = 2;
292  UImanager->SetVerboseLevel(newVerbose);
293 
294  G4VVisManager* keepConcreteInstance = fpVisManager->GetConcreteInstance();
295  fpVisManager->Enable();
296 
297  // Event by event refreshing...
298  reviewing = true;
299  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
300  pScene->SetRefreshAtEndOfEvent(true);
301  if (macroFileName.empty()) {
302 
303  // Draw to viewer and pause session...
304  G4UIsession* session = UImanager->GetSession();
305  for (size_t i = 0; i < nKeptEvents; ++i) {
306  const G4Event* event = (*events)[i];
307  if (verbosity >= G4VisManager::warnings) {
308  G4cout << "Drawing event : " << event->GetEventID() <<
309  ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
310  << G4endl;
311  static G4bool first = true;
312  if (first) {
313  first = false;
314  G4cout <<
315  " Useful commands might be:"
316  "\n \"/vis/scene/add/trajectories\" if not already added."
317  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
318  "\n \"/vis/oglx/printEPS\" to get hard copy."
319  "\n \"/vis/open\" to get alternative viewer."
320  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
321  << G4endl;
322  }
323  }
325  UImanager->ApplyCommand("/vis/viewer/rebuild");
326  /* The above command forces a rebuild of the scene, including
327  the detector. This is fine for "immediate" viewers - a
328  refresh requires a rebuild anyway. But for "stored mode"
329  viewers, you could, in principle, avoid a rebuild of the
330  detector with something like the following:
331  sceneHandler->ClearTransientStore();
332  viewer->DrawView();
333  sceneHandler->DrawEvent(event);
334  but this causes mayhem for "immediate" viewers because
335  ClearTransientStore issues a DrawView and some curious sort
336  of recursion takes place. For "stored" viewers, the event
337  gets drawn but not the eventID, so something odd is happening
338  there too. This needs further investigation - enhanced
339  features or a complete re-think.
340  */
341  UImanager->ApplyCommand("/vis/viewer/flush");
342  session->PauseSessionStart("EndOfEvent");
345  }
347 
348  } else {
349 
350  // Execute macro file...
351  for (size_t i = 0; i < nKeptEvents; ++i) {
352  const G4Event* event = (*events)[i];
353  if (verbosity >= G4VisManager::warnings) {
354  G4cout << "Drawing event : " << event->GetEventID()
355  << " with macro file \"" << macroFileName << G4endl;
356  }
358  UImanager->ApplyCommand("/control/execute " + macroFileName);
360  }
361  }
362  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
363  reviewing = false;
364 
365  if (keepConcreteInstance) fpVisManager->Enable();
366  else fpVisManager->Disable();
367  UImanager->SetVerboseLevel(keepVerbose);
368 }
369 
371 
373  G4bool omitable;
374 
375  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
376  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
378  }
379  fpCommand -> SetParameterName("verbosity", omitable=true);
380  fpCommand -> SetDefaultValue("warnings");
381 }
382 
384  delete fpCommand;
385 }
386 
388  return G4String();
389 }
390 
392  G4String newValue) {
393  G4VisManager::Verbosity verbosity =
394  fpVisManager->GetVerbosityValue(newValue);
395  fpVisManager->SetVerboseLevel(verbosity);
396  // Always prints whatever the verbosity...
397  G4cout << "Visualization verbosity changed to "
398  << G4VisManager::VerbosityString(verbosity) << G4endl;
399 }
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual ~G4VisCommandEnable()
G4UIsession * GetSession() const
Definition: G4UImanager.hh:208
void PrintAvailableColours(Verbosity) const
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4UIcmdWithAString * fpCommand
virtual void PauseSessionStart(const G4String &Prompt)
Definition: G4UIsession.cc:48
void PrintAvailableUserVisActions(Verbosity) const
void PrintAvailableModels(Verbosity) const
G4String GetCurrentValue(G4UIcommand *command)
static G4VVisManager * GetConcreteInstance()
virtual ~G4VisCommandList()
void PrintAvailableGraphicsSystems(Verbosity) const
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithAString * fpCommand
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
G4UIcmdWithABool * fpCommand
G4String GetCurrentValue(G4UIcommand *command)
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4GLOB_DLL std::ostream G4cout
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:425
bool G4bool
Definition: G4Types.hh:79
G4String GetCurrentValue(G4UIcommand *command)
static G4MTRunManager * GetMasterRunManager()
Definition: G4Run.hh:46
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4UIterminal * session
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:152
G4UIcmdWithoutParameter * fpCommand
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void Initialize()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
static G4String VerbosityString(Verbosity)
const std::map< G4String, G4AttDef > * GetAttDefs() const
static Verbosity GetVerbosity()
#define G4endl
Definition: G4ios.hh:61
G4UIcmdWithAString * fpCommand
G4VViewer * GetCurrentViewer() const
G4bool GetAbortReviewKeptEvents() const
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithoutParameter * fpCommand1
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:446
G4Scene * GetCurrentScene() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetRefreshAtEndOfEvent(G4bool)
G4GLOB_DLL std::ostream G4cerr
void SetAbortReviewKeptEvents(G4bool)
static G4VisManager * fpVisManager
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const