source: trunk/source/visualization/management/src/G4VisCommands.cc @ 893

Last change on this file since 893 was 850, checked in by garnier, 16 years ago

geant4.8.2 beta

  • Property svn:mime-type set to text/cpp
File size: 11.5 KB
Line 
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,v 1.23 2008/07/27 10:46:23 allison Exp $
28// GEANT4 tag $Name: HEAD $
29
30// /vis/ top level commands - John Allison  5th February 2001
31
32#include "G4VisCommands.hh"
33
34#include "G4VisManager.hh"
35#include "G4UImanager.hh"
36#include "G4UIcmdWithABool.hh"
37#include "G4UIcmdWithAString.hh"
38#include "G4UIcmdWithoutParameter.hh"
39#include "G4RunManager.hh"
40#include "G4Run.hh"
41#include "G4UIsession.hh"
42
43////////////// /vis/abortReviewKeptEvents /////////////////////////////
44
45G4VisCommandAbortReviewKeptEvents::G4VisCommandAbortReviewKeptEvents () {
46  G4bool omitable;
47
48  fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
49  fpCommand -> SetGuidance("Abort review of kept events.");
50  fpCommand -> SetParameterName("abort", omitable=true);
51  fpCommand -> SetDefaultValue(true);
52}
53
54G4VisCommandAbortReviewKeptEvents::~G4VisCommandAbortReviewKeptEvents () {
55  delete fpCommand;
56}
57
58G4String G4VisCommandAbortReviewKeptEvents::GetCurrentValue (G4UIcommand*) {
59  return G4String();
60}
61
62void G4VisCommandAbortReviewKeptEvents::SetNewValue (G4UIcommand*,
63                                                     G4String newValue) {
64  fpVisManager->SetAbortReviewKeptEvents(G4UIcommand::ConvertToBool(newValue));
65  G4cout << "Type \"continue\" to complete the abort." << G4endl;
66}
67
68////////////// /vis/enable ///////////////////////////////////////
69
70G4VisCommandEnable::G4VisCommandEnable () {
71  G4bool omitable;
72
73  fpCommand = new G4UIcmdWithABool("/vis/enable", this);
74  fpCommand -> SetGuidance("Enables/disables visualization system.");
75  fpCommand -> SetParameterName("enabled", omitable=true);
76  fpCommand -> SetDefaultValue(true);
77
78  fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
79  fpCommand1 -> SetGuidance("Disables visualization system.");
80}
81
82G4VisCommandEnable::~G4VisCommandEnable () {
83  delete fpCommand;
84  delete fpCommand1;
85}
86
87G4String G4VisCommandEnable::GetCurrentValue (G4UIcommand*) {
88  return G4String();
89}
90
91void G4VisCommandEnable::SetNewValue (G4UIcommand* command,
92                                      G4String newValue) {
93  if (command == fpCommand) {
94    G4bool enable = G4UIcommand::ConvertToBool(newValue);
95    if (enable) fpVisManager->Enable();  // Printing is in vis manager.
96    else fpVisManager->Disable();        // Printing is in vis manager.
97  } else fpVisManager->Disable();        // Printing is in vis manager.
98  // Note: Printing is in vis manager.
99}
100
101////////////// /vis/list ///////////////////////////////////////
102
103G4VisCommandList::G4VisCommandList ()
104{
105  G4bool omitable;
106
107  fpCommand = new G4UIcmdWithAString("/vis/list", this);
108  fpCommand -> SetGuidance("Lists visualization parameters.");
109  fpCommand -> SetParameterName("verbosity", omitable=true);
110  fpCommand -> SetDefaultValue("warnings");
111}
112
113G4VisCommandList::~G4VisCommandList ()
114{
115  delete fpCommand;
116}
117
118G4String G4VisCommandList::GetCurrentValue (G4UIcommand*)
119{
120  return "";
121}
122
123void G4VisCommandList::SetNewValue (G4UIcommand*, G4String newValue)
124{
125  G4String& verbosityString = newValue;
126  G4VisManager::Verbosity verbosity =
127    fpVisManager->GetVerbosityValue(verbosityString);
128
129  fpVisManager->PrintAvailableGraphicsSystems();
130  G4cout << G4endl;
131  fpVisManager->PrintAvailableModels(verbosity);
132  G4cout << G4endl;
133  G4UImanager* UImanager = G4UImanager::GetUIpointer();
134  UImanager->ApplyCommand(G4String("/vis/viewer/list ! ") + verbosityString);
135  if (verbosity < G4VisManager::parameters)
136    G4cout <<
137  "\nTo get more information, \"/vis/list all all\" or use individual commands"
138  "\n  such as (use \"ls\" or \"help\"):"
139  "\n    /vis/viewer/list"
140  "\n    /vis/modeling/trajectories/list"
141  "\n    /vis/filtering/trajectories/list"
142           << G4endl;
143}
144
145////////////// /vis/reviewKeptEvents ///////////////////////////////////////
146
147G4VisCommandReviewKeptEvents::G4VisCommandReviewKeptEvents ()
148{
149  G4bool omitable;
150
151  fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
152  fpCommand -> SetGuidance("Review kept events.");
153  fpCommand -> SetGuidance
154    ("If a macro file is specified, it is executed for each event.");
155  fpCommand -> SetGuidance(
156  "If a macro file is not specified, each event is drawn to the current"
157  "\nviewer.  After each event, the session is paused.  The user may issue"
158  "\nany allowed command.  Then enter \"cont[inue]\" to continue to the next"
159  "\nevent."
160  "\nUseful commands might be:"
161  "\n  \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
162  "\n  \"/vis/oglx/printEPS\" to get hard copy."
163  "\n  \"/vis/open\" to get alternative viewer."
164  "\n  \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
165  fpCommand -> SetParameterName("macro-file-name", omitable=true);
166  fpCommand -> SetDefaultValue("");
167}
168
169G4VisCommandReviewKeptEvents::~G4VisCommandReviewKeptEvents ()
170{
171  delete fpCommand;
172}
173
174G4String G4VisCommandReviewKeptEvents::GetCurrentValue (G4UIcommand*)
175{
176  return "";
177}
178
179void G4VisCommandReviewKeptEvents::SetNewValue (G4UIcommand*, G4String newValue)
180{
181  static bool reviewing = false;
182  if (reviewing) {
183    G4cout <<
184      "\"/vis/reviewKeptEvents\" not allowed within an already started review."
185      "\n  No action taken."
186           << G4endl;
187    return;
188  }
189
190  G4String& macroFileName = newValue;
191  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
192
193  G4RunManager* runManager = G4RunManager::GetRunManager();
194  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
195  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
196  size_t nKeptEvents = events? events->size(): 0;
197
198  if (!nKeptEvents) {
199    if (verbosity >= G4VisManager::errors) {
200      G4cout <<
201        "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
202        "\n  or kept events not accessible."
203             << G4endl;
204    }
205    return;
206  }
207
208  G4VViewer* viewer = fpVisManager->GetCurrentViewer();
209  if (!viewer) {
210    if (verbosity >= G4VisManager::errors) {
211      G4cout <<
212  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
213             << G4endl;
214    }
215    return;
216  }
217
218  G4Scene* pScene = fpVisManager->GetCurrentScene();
219  if (!pScene) {
220    if (verbosity >= G4VisManager::errors) {
221      G4cout << "ERROR: No current scene.  Please create one." << G4endl;
222    }
223    return;
224  }
225
226  G4UImanager* UImanager = G4UImanager::GetUIpointer();
227  G4int keepVerbose = UImanager->GetVerboseLevel();
228  G4int newVerbose(0);
229  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
230    newVerbose = 2;
231  UImanager->SetVerboseLevel(newVerbose);
232
233  // Event by event refreshing...
234  reviewing  = true;
235  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
236  pScene->SetRefreshAtEndOfEvent(true);
237  if (macroFileName.empty()) {
238
239    // Draw to viewer and pause session...
240    G4UIsession* session = UImanager->GetSession();
241    for (size_t i = 0; i < nKeptEvents; ++i) {
242      const G4Event* event = (*events)[i];
243      if (verbosity >= G4VisManager::warnings) {
244        G4cout << "Drawing event : " << event->GetEventID() <<
245          ".  At EndOfEvent, enter any command, then \"cont[inue]\"..."
246               << G4endl;
247        static G4bool first = true;
248        if (first) {
249          first = false;
250          G4cout <<
251  "  Useful commands might be:"
252  "\n    \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
253  "\n    \"/vis/oglx/printEPS\" to get hard copy."
254  "\n    \"/vis/open\" to get alternative viewer."
255  "\n    \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
256                 << G4endl;
257        }
258      }
259      fpVisManager->SetRequestedEvent(event);
260      UImanager->ApplyCommand("/vis/viewer/rebuild");
261      /* The above command forces a rebuild of the scene, including
262         the detector.  This is fine for "immediate" viewers - a
263         refresh requires a rebuild anyway.  But for "stored mode"
264         viewers, you could, in principle, avoid a rebuild of the
265         detector with something like the following:
266      sceneHandler->ClearTransientStore();
267      viewer->DrawView();
268      sceneHandler->DrawEvent(event);
269         but this causes mayhem for "immediate" viewers because
270         ClearTransientStore issues a DrawView and some curious sort
271         of recursion takes place.  For "stored" viewers, the event
272         gets drawn but not the eventID, so something odd is happening
273         there too.  This needs further investigation - enhanced
274         features or a complete re-think.
275      */
276      UImanager->ApplyCommand("/vis/viewer/flush");
277      session->PauseSessionStart("EndOfEvent");
278      fpVisManager->SetRequestedEvent(0);
279      if (fpVisManager->GetAbortReviewKeptEvents()) break;
280    }
281    fpVisManager->SetAbortReviewKeptEvents(false);
282
283  } else {
284
285    // Execute macro file...
286    for (size_t i = 0; i < nKeptEvents; ++i) {
287      const G4Event* event = (*events)[i];
288      if (verbosity >= G4VisManager::warnings) {
289        G4cout << "Drawing event : " << event->GetEventID()
290               << " with macro file \"" << macroFileName << G4endl;
291      }
292      fpVisManager->SetRequestedEvent(event);
293      UImanager->ApplyCommand("/control/execute " + macroFileName);
294      fpVisManager->SetRequestedEvent(0);
295    }
296  }
297  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
298  reviewing  = false;
299
300  UImanager->SetVerboseLevel(keepVerbose);
301}
302
303////////////// /vis/verbose ///////////////////////////////////////
304
305G4VisCommandVerbose::G4VisCommandVerbose () {
306  G4bool omitable;
307
308  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
309  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
310    fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
311  }
312  fpCommand -> SetParameterName("verbosity", omitable=true);
313  fpCommand -> SetDefaultValue("warnings");
314}
315
316G4VisCommandVerbose::~G4VisCommandVerbose () {
317  delete fpCommand;
318}
319
320G4String G4VisCommandVerbose::GetCurrentValue (G4UIcommand*) {
321  return G4String();
322}
323
324void G4VisCommandVerbose::SetNewValue (G4UIcommand*,
325                                       G4String newValue) {
326  G4VisManager::Verbosity verbosity =
327    fpVisManager->GetVerbosityValue(newValue);
328  fpVisManager->SetVerboseLevel(verbosity);
329  // Always prints whatever the verbosity...
330  G4cout << "Visualization verbosity changed to "
331         << G4VisManager::VerbosityString(verbosity) << G4endl;
332}
Note: See TracBrowser for help on using the repository browser.