ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4VisCommands.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4VisCommands.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 // /vis/ top level commands - John Allison 5th February 2001
29 
30 #include "G4VisCommands.hh"
31 
32 #include "G4VisManager.hh"
33 #include "G4UImanager.hh"
34 #include "G4UIcmdWithABool.hh"
35 #include "G4UIcmdWithAString.hh"
37 #include "G4RunManager.hh"
38 #ifdef G4MULTITHREADED
39 #include "G4MTRunManager.hh"
40 #endif
41 #include "G4Run.hh"
42 #include "G4UIsession.hh"
43 #include "G4Trajectory.hh"
44 #include "G4TrajectoryPoint.hh"
45 #include "G4RichTrajectory.hh"
46 #include "G4RichTrajectoryPoint.hh"
47 #include "G4SmoothTrajectory.hh"
49 #include "G4PhysicalVolumeModel.hh"
50 #include "G4AttDef.hh"
51 
53 
55  G4bool omitable;
56 
57  fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
58  fpCommand -> SetGuidance("Abort review of kept events.");
59  fpCommand -> SetParameterName("abort", omitable=true);
60  fpCommand -> SetDefaultValue(true);
61 }
62 
64  delete fpCommand;
65 }
66 
68  return G4String();
69 }
70 
72  G4String newValue) {
74  G4cout << "Type \"continue\" to complete the abort." << G4endl;
75 }
76 
78 
80 {
81  G4bool omitable;
82 
83  fpCommand = new G4UIcmdWithABool("/vis/drawOnlyToBeKeptEvents", this);
84  fpCommand -> SetGuidance
85  ("DURING A RUN draw only those events that have been \"to be kept\" by the user"
86  "\nwith G4EventManager::GetEventManager()->KeepTheCurrentEvent() or"
87  "\nwith \"/event/keepCurrentEvent\".");
88  fpCommand -> SetGuidance(
89  "To draw selected events the user should set this flag, then in a user action:"
90  "\n if ( some criterion ) {"
91  "\n G4EventManager::GetEventManager()->KeepTheCurrentEvent();"
92  "\n }");
93  fpCommand -> SetParameterName("draw", omitable=true);
94  fpCommand -> SetDefaultValue(true);
95 }
96 
98  delete fpCommand;
99 }
100 
102  return G4String();
103 }
104 
106  G4String newValue) {
109  if (verbosity < G4VisManager::warnings) {
111  G4cout << "Only events that have been kept will be drawn." << G4endl;
112  } else {
113  G4cout << "All events will be drawn." << G4endl;
114  }
115  }
116 }
117 
119 
121  G4bool omitable;
122 
123  fpCommand = new G4UIcmdWithABool("/vis/enable", this);
124  fpCommand -> SetGuidance("Enables/disables visualization system.");
125  fpCommand -> SetParameterName("enabled", omitable=true);
126  fpCommand -> SetDefaultValue(true);
127 
128  fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
129  fpCommand1 -> SetGuidance("Disables visualization system.");
130 }
131 
133  delete fpCommand;
134  delete fpCommand1;
135 }
136 
138  return G4String();
139 }
140 
142  G4String newValue) {
143  if (command == fpCommand) {
144  G4bool enable = G4UIcommand::ConvertToBool(newValue);
145  if (enable) fpVisManager->Enable(); // Printing is in vis manager.
146  else fpVisManager->Disable(); // Printing is in vis manager.
147  } else fpVisManager->Disable(); // Printing is in vis manager.
148  // Note: Printing is in vis manager.
149 }
150 
152 
154 {
155  fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
156  fpCommand -> SetGuidance("Initialise visualisation manager.");
157 }
158 
160  delete fpCommand;
161 }
162 
164  G4String) {
166 }
167 
169 
171 {
172  G4bool omitable;
173 
174  fpCommand = new G4UIcmdWithAString("/vis/list", this);
175  fpCommand -> SetGuidance("Lists visualization parameters.");
176  fpCommand -> SetParameterName("verbosity", omitable=true);
177  fpCommand -> SetDefaultValue("warnings");
178 }
179 
181 {
182  delete fpCommand;
183 }
184 
186 {
187  return "";
188 }
189 
191 {
192  G4String& verbosityString = newValue;
193  G4VisManager::Verbosity verbosity =
194  fpVisManager->GetVerbosityValue(verbosityString);
195 
197  G4cout << G4endl;
199  G4cout << G4endl;
201  G4cout << G4endl;
203  G4cout << G4endl;
204  G4UImanager* UImanager = G4UImanager::GetUIpointer();
205  UImanager->ApplyCommand("/vis/scene/list ! " + newValue);
206  UImanager->ApplyCommand("/vis/viewer/list ! " + newValue);
207 
208  G4cout <<
209  "\nAttributes available for modeling and filtering with"
210  "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
211  "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
212  "\nand by picking:"
213  << G4endl;
214  G4cout
216  G4cout
219  G4cout
222  G4cout
223  << *G4Trajectory().GetAttDefs()
225 
226  G4cout <<
227  "\nGeometry attributes available for touchables by picking:\n";
228  G4cout
230 
231  if (verbosity < G4VisManager::parameters)
232  G4cout <<
233  "\nTo get more information, \"/vis/list all\" or use individual commands"
234  "\n such as (use \"ls\" or \"help\"):"
235  "\n /vis/scene/list all all"
236  "\n /vis/viewer/list all all"
237  "\n /vis/modeling/trajectories/list"
238  "\n /vis/filtering/trajectories/list"
239  << G4endl;
240 }
241 
243 
245 {
246  G4bool omitable;
247 
248  fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
249  fpCommand -> SetGuidance("Review kept events.");
250  fpCommand -> SetGuidance
251  ("If a macro file is specified, it is executed for each event.");
252  fpCommand -> SetGuidance(
253  "If a macro file is not specified, each event is drawn to the current"
254  "\nviewer. After each event, the session is paused. The user may issue"
255  "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
256  "\nevent."
257  "\nUseful commands might be:"
258  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
259  "\n \"/vis/oglx/printEPS\" to get hard copy."
260  "\n \"/vis/open\" to get alternative viewer."
261  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
262  fpCommand -> SetParameterName("macro-file-name", omitable=true);
263  fpCommand -> SetDefaultValue("");
264 }
265 
267 {
268  delete fpCommand;
269 }
270 
272 {
273  return "";
274 }
275 
277 {
279  G4cout <<
280  "\"/vis/reviewKeptEvents\" not allowed within an already started review."
281  "\n No action taken."
282  << G4endl;
283  return;
284  }
285 
286  G4String& macroFileName = newValue;
288 
290 #ifdef G4MULTITHREADED
292  { runManager = G4MTRunManager::GetMasterRunManager(); }
293 #endif
294  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
295  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
296  size_t nKeptEvents = events? events->size(): 0;
297 
298  if (!nKeptEvents) {
299  if (verbosity >= G4VisManager::errors) {
300  G4cerr <<
301  "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
302  "\n or kept events not accessible."
303  << G4endl;
304  }
305  return;
306  }
307 
309  if (!viewer) {
310  if (verbosity >= G4VisManager::errors) {
311  G4cerr <<
312  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
313  << G4endl;
314  }
315  return;
316  }
317 
318  G4Scene* pScene = fpVisManager->GetCurrentScene();
319  if (!pScene) {
320  if (verbosity >= G4VisManager::errors) {
321  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
322  }
323  return;
324  }
325 
326  G4UImanager* UImanager = G4UImanager::GetUIpointer();
327  G4int keepVerbose = UImanager->GetVerboseLevel();
328  G4int newVerbose(0);
329  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
330  newVerbose = 2;
331  UImanager->SetVerboseLevel(newVerbose);
332 
333  G4VVisManager* keepConcreteInstance = fpVisManager->GetConcreteInstance();
334  fpVisManager->Enable();
335 
336  // Start on clean view
337  UImanager->ApplyCommand("/vis/viewer/rebuild");
338 
339  // Event by event refreshing...
341  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
342  pScene->SetRefreshAtEndOfEvent(true);
343  if (macroFileName.empty()) {
344 
345  // Draw to viewer and pause session...
346  G4UIsession* session = UImanager->GetSession();
347  for (size_t i = 0; i < nKeptEvents; ++i) {
348  const G4Event* event = (*events)[i];
349  if (verbosity >= G4VisManager::warnings) {
350  G4cout << "Drawing event : " << event->GetEventID() <<
351  ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
352  << G4endl;
353  static G4bool first = true;
354  if (first) {
355  first = false;
356  G4cout <<
357  " Useful commands might be:"
358  "\n \"/vis/scene/add/trajectories\" if not already added."
359  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
360  "\n \"/vis/oglx/printEPS\" to get hard copy."
361  "\n \"/vis/open\" to get alternative viewer."
362  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
363  << G4endl;
364  }
365  }
367  UImanager->ApplyCommand("/vis/viewer/rebuild");
368  /* The above command forces a rebuild of the scene, including
369  the detector. This is fine for "immediate" viewers - a
370  refresh requires a rebuild anyway. But for "stored mode"
371  viewers, you could, in principle, avoid a rebuild of the
372  detector with something like the following:
373  sceneHandler->ClearTransientStore();
374  viewer->DrawView();
375  sceneHandler->DrawEvent(event);
376  but this causes mayhem for "immediate" viewers because
377  ClearTransientStore issues a DrawView and some curious sort
378  of recursion takes place. For "stored" viewers, the event
379  gets drawn but not the eventID, so something odd is happening
380  there too. This needs further investigation - enhanced
381  features or a complete re-think.
382  */
383  UImanager->ApplyCommand("/vis/viewer/flush");
384  session->PauseSessionStart("EndOfEvent");
387  }
389 
390  } else {
391 
392  // Execute macro file...
393  for (size_t i = 0; i < nKeptEvents; ++i) {
394  const G4Event* event = (*events)[i];
395  if (verbosity >= G4VisManager::warnings) {
396  G4cout << "Drawing event : " << event->GetEventID()
397  << " with macro file \"" << macroFileName << G4endl;
398  }
400  UImanager->ApplyCommand("/control/execute " + macroFileName);
402  }
403  }
404  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
406 
407  if (keepConcreteInstance) fpVisManager->Enable();
408  else fpVisManager->Disable();
409  UImanager->SetVerboseLevel(keepVerbose);
410 }
411 
413 
415  G4bool omitable;
416 
417  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
418  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
420  }
421  fpCommand -> SetParameterName("verbosity", omitable=true);
422  fpCommand -> SetDefaultValue("warnings");
423 }
424 
426  delete fpCommand;
427 }
428 
430  return G4String();
431 }
432 
434  G4String newValue) {
435  G4VisManager::Verbosity verbosity =
436  fpVisManager->GetVerbosityValue(newValue);
437  fpVisManager->SetVerboseLevel(verbosity);
438  // Always prints whatever the verbosity...
439  G4cout << "Visualization verbosity changed to "
440  << G4VisManager::VerbosityString(verbosity) << G4endl;
441 }