Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
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 // $Id: G4VisCommands.cc 106384 2017-10-09 09:34:51Z 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 {
82  G4bool omitable;
83 
84  fpCommand = new G4UIcmdWithABool("/vis/drawOnlyToBeKeptEvents", this);
85  fpCommand -> SetGuidance
86  ("DURING A RUN draw only those events that have been \"to be kept\" by the user"
87  "\nwith G4EventManager::GetEventManager()->KeepTheCurrentEvent() or"
88  "\nwith \"/event/keepCurrentEvent\".");
89  fpCommand -> SetGuidance(
90  "To draw selected events the user should set this flag, then in a user action:"
91  "\n if ( some criterion ) {"
92  "\n G4EventManager::GetEventManager()->KeepTheCurrentEvent();"
93  "\n }");
94  fpCommand -> SetParameterName("draw", omitable=true);
95  fpCommand -> SetDefaultValue(true);
96 }
97 
99  delete fpCommand;
100 }
101 
103  return G4String();
104 }
105 
107  G4String newValue) {
110  if (verbosity < G4VisManager::warnings) {
112  G4cout << "Only events that have been kept will be drawn." << G4endl;
113  } else {
114  G4cout << "All events will be drawn." << G4endl;
115  }
116  }
117 }
118 
120 
122  G4bool omitable;
123 
124  fpCommand = new G4UIcmdWithABool("/vis/enable", this);
125  fpCommand -> SetGuidance("Enables/disables visualization system.");
126  fpCommand -> SetParameterName("enabled", omitable=true);
127  fpCommand -> SetDefaultValue(true);
128 
129  fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
130  fpCommand1 -> SetGuidance("Disables visualization system.");
131 }
132 
134  delete fpCommand;
135  delete fpCommand1;
136 }
137 
139  return G4String();
140 }
141 
143  G4String newValue) {
144  if (command == fpCommand) {
145  G4bool enable = G4UIcommand::ConvertToBool(newValue);
146  if (enable) fpVisManager->Enable(); // Printing is in vis manager.
147  else fpVisManager->Disable(); // Printing is in vis manager.
148  } else fpVisManager->Disable(); // Printing is in vis manager.
149  // Note: Printing is in vis manager.
150 }
151 
153 
155 {
156  fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
157  fpCommand -> SetGuidance("Initialise visualisation manager.");
158 }
159 
161  delete fpCommand;
162 }
163 
165  G4String) {
167 }
168 
170 
172 {
173  G4bool omitable;
174 
175  fpCommand = new G4UIcmdWithAString("/vis/list", this);
176  fpCommand -> SetGuidance("Lists visualization parameters.");
177  fpCommand -> SetParameterName("verbosity", omitable=true);
178  fpCommand -> SetDefaultValue("warnings");
179 }
180 
182 {
183  delete fpCommand;
184 }
185 
187 {
188  return "";
189 }
190 
192 {
193  G4String& verbosityString = newValue;
194  G4VisManager::Verbosity verbosity =
195  fpVisManager->GetVerbosityValue(verbosityString);
196 
198  G4cout << G4endl;
200  G4cout << G4endl;
202  G4cout << G4endl;
204  G4cout << G4endl;
205  G4UImanager* UImanager = G4UImanager::GetUIpointer();
206  UImanager->ApplyCommand("/vis/scene/list ! " + newValue);
207  UImanager->ApplyCommand("/vis/viewer/list ! " + newValue);
208 
209  G4cout <<
210  "\nAttributes available for modeling and filtering with"
211  "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
212  "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
213  "\nand by picking:"
214  << G4endl;
215  G4cout
217  G4cout
220  G4cout
223  G4cout
224  << *G4Trajectory().GetAttDefs()
226 
227  G4cout <<
228  "\nGeometry attributes available for touchables by picking:\n";
229  G4cout
231 
232  if (verbosity < G4VisManager::parameters)
233  G4cout <<
234  "\nTo get more information, \"/vis/list all\" or use individual commands"
235  "\n such as (use \"ls\" or \"help\"):"
236  "\n /vis/scene/list all all"
237  "\n /vis/viewer/list all all"
238  "\n /vis/modeling/trajectories/list"
239  "\n /vis/filtering/trajectories/list"
240  << G4endl;
241 }
242 
244 
246 {
247  G4bool omitable;
248 
249  fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
250  fpCommand -> SetGuidance("Review kept events.");
251  fpCommand -> SetGuidance
252  ("If a macro file is specified, it is executed for each event.");
253  fpCommand -> SetGuidance(
254  "If a macro file is not specified, each event is drawn to the current"
255  "\nviewer. After each event, the session is paused. The user may issue"
256  "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
257  "\nevent."
258  "\nUseful commands might be:"
259  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
260  "\n \"/vis/oglx/printEPS\" to get hard copy."
261  "\n \"/vis/open\" to get alternative viewer."
262  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
263  fpCommand -> SetParameterName("macro-file-name", omitable=true);
264  fpCommand -> SetDefaultValue("");
265 }
266 
268 {
269  delete fpCommand;
270 }
271 
273 {
274  return "";
275 }
276 
278 {
279  static bool reviewing = false;
280  if (reviewing) {
281  G4cout <<
282  "\"/vis/reviewKeptEvents\" not allowed within an already started review."
283  "\n No action taken."
284  << G4endl;
285  return;
286  }
287 
288  G4String& macroFileName = newValue;
290 
292 #ifdef G4MULTITHREADED
294  { runManager = G4MTRunManager::GetMasterRunManager(); }
295 #endif
296  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
297  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
298  size_t nKeptEvents = events? events->size(): 0;
299 
300  if (!nKeptEvents) {
301  if (verbosity >= G4VisManager::errors) {
302  G4cerr <<
303  "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
304  "\n or kept events not accessible."
305  << G4endl;
306  }
307  return;
308  }
309 
311  if (!viewer) {
312  if (verbosity >= G4VisManager::errors) {
313  G4cerr <<
314  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
315  << G4endl;
316  }
317  return;
318  }
319 
320  G4Scene* pScene = fpVisManager->GetCurrentScene();
321  if (!pScene) {
322  if (verbosity >= G4VisManager::errors) {
323  G4cerr << "ERROR: No current scene. Please create one." << G4endl;
324  }
325  return;
326  }
327 
328  G4UImanager* UImanager = G4UImanager::GetUIpointer();
329  G4int keepVerbose = UImanager->GetVerboseLevel();
330  G4int newVerbose(0);
331  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
332  newVerbose = 2;
333  UImanager->SetVerboseLevel(newVerbose);
334 
335  G4VVisManager* keepConcreteInstance = fpVisManager->GetConcreteInstance();
336  fpVisManager->Enable();
337 
338  // Event by event refreshing...
339  reviewing = true;
340  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
341  pScene->SetRefreshAtEndOfEvent(true);
342  if (macroFileName.empty()) {
343 
344  // Draw to viewer and pause session...
345  G4UIsession* session = UImanager->GetSession();
346  for (size_t i = 0; i < nKeptEvents; ++i) {
347  const G4Event* event = (*events)[i];
348  if (verbosity >= G4VisManager::warnings) {
349  G4cout << "Drawing event : " << event->GetEventID() <<
350  ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
351  << G4endl;
352  static G4bool first = true;
353  if (first) {
354  first = false;
355  G4cout <<
356  " Useful commands might be:"
357  "\n \"/vis/scene/add/trajectories\" if not already added."
358  "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
359  "\n \"/vis/oglx/printEPS\" to get hard copy."
360  "\n \"/vis/open\" to get alternative viewer."
361  "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
362  << G4endl;
363  }
364  }
366  UImanager->ApplyCommand("/vis/viewer/rebuild");
367  /* The above command forces a rebuild of the scene, including
368  the detector. This is fine for "immediate" viewers - a
369  refresh requires a rebuild anyway. But for "stored mode"
370  viewers, you could, in principle, avoid a rebuild of the
371  detector with something like the following:
372  sceneHandler->ClearTransientStore();
373  viewer->DrawView();
374  sceneHandler->DrawEvent(event);
375  but this causes mayhem for "immediate" viewers because
376  ClearTransientStore issues a DrawView and some curious sort
377  of recursion takes place. For "stored" viewers, the event
378  gets drawn but not the eventID, so something odd is happening
379  there too. This needs further investigation - enhanced
380  features or a complete re-think.
381  */
382  UImanager->ApplyCommand("/vis/viewer/flush");
383  session->PauseSessionStart("EndOfEvent");
386  }
388 
389  } else {
390 
391  // Execute macro file...
392  for (size_t i = 0; i < nKeptEvents; ++i) {
393  const G4Event* event = (*events)[i];
394  if (verbosity >= G4VisManager::warnings) {
395  G4cout << "Drawing event : " << event->GetEventID()
396  << " with macro file \"" << macroFileName << G4endl;
397  }
399  UImanager->ApplyCommand("/control/execute " + macroFileName);
401  }
402  }
403  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
404  reviewing = false;
405 
406  if (keepConcreteInstance) fpVisManager->Enable();
407  else fpVisManager->Disable();
408  UImanager->SetVerboseLevel(keepVerbose);
409 }
410 
412 
414  G4bool omitable;
415 
416  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
417  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
419  }
420  fpCommand -> SetParameterName("verbosity", omitable=true);
421  fpCommand -> SetDefaultValue("warnings");
422 }
423 
425  delete fpCommand;
426 }
427 
429  return G4String();
430 }
431 
433  G4String newValue) {
434  G4VisManager::Verbosity verbosity =
435  fpVisManager->GetVerbosityValue(newValue);
436  fpVisManager->SetVerboseLevel(verbosity);
437  // Always prints whatever the verbosity...
438  G4cout << "Visualization verbosity changed to "
439  << G4VisManager::VerbosityString(verbosity) << G4endl;
440 }
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4MTRunManager * GetMasterRunManager()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:80
const G4Run * GetCurrentRun() const
virtual ~G4VisCommandVerbose()
G4String GetCurrentValue(G4UIcommand *command)
const std::map< G4String, G4AttDef > * GetAttDefs() const
G4bool GetAbortReviewKeptEvents() const
static G4UIterminal * session
G4String GetCurrentValue(G4UIcommand *command)
G4UIcmdWithAString * fpCommand
void SetDrawEventOnlyIfToBeKept(G4bool)
static Verbosity GetVerbosityValue(const G4String &)
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:466
void PrintAvailableColours(Verbosity) const
#define G4endl
Definition: G4ios.hh:61
G4String GetCurrentValue(G4UIcommand *command)
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:439
void SetNewValue(G4UIcommand *command, G4String newValue)
void PrintAvailableUserVisActions(Verbosity) const
static std::vector< G4String > VerbosityGuidanceStrings
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:227
G4Scene * GetCurrentScene() const
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:73
void SetVerboseLevel(G4int)
void SetNewValue(G4UIcommand *command, G4String newValue)
void PrintAvailableModels(Verbosity) const
static G4VVisManager * GetConcreteInstance()
G4UIsession * GetSession() const
Definition: G4UImanager.hh:210
G4String GetCurrentValue(G4UIcommand *command)
void PrintAvailableGraphicsSystems(Verbosity) const
virtual ~G4VisCommandList()
G4UIcmdWithABool * fpCommand
bool G4bool
Definition: G4Types.hh:79
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetNewValue(G4UIcommand *command, G4String newValue)
G4bool GetRefreshAtEndOfEvent() const
virtual void PauseSessionStart(const G4String &Prompt)
Definition: G4UIsession.cc:48
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4VViewer * GetCurrentViewer() const
void SetAbortReviewKeptEvents(G4bool)
virtual ~G4VisCommandInitialize()
void SetRequestedEvent(const G4Event *)
G4String GetCurrentValue(G4UIcommand *command)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
static Verbosity GetVerbosity()
G4bool GetDrawEventOnlyIfToBeKept() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void SetRefreshAtEndOfEvent(G4bool)
G4UIcmdWithoutParameter * fpCommand
G4GLOB_DLL std::ostream G4cerr
Definition: G4Run.hh:46
G4UIcmdWithAString * fpCommand
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
G4bool IsMultithreadedApplication()
Definition: G4Threading.cc:136
int G4int
Definition: G4Types.hh:78
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:229
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
G4GLOB_DLL std::ostream G4cout
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
void Initialize()
G4UIcmdWithAString * fpCommand
G4UIcmdWithoutParameter * fpCommand1
virtual ~G4VisCommandEnable()
static G4VisManager * fpVisManager
static G4String VerbosityString(Verbosity)