source: trunk/geant4/visualization/management/src/G4VisCommands.cc @ 593

Last change on this file since 593 was 593, checked in by garnier, 17 years ago

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

  • Property svn:mime-type set to text/cpp
File size: 11.3 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.22 2007/03/27 15:47:32 allison Exp $
28// GEANT4 tag $Name: geant4-09-00-ref-01 $
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  G4String& macroFileName = newValue;
182  G4VisManager::Verbosity verbosity = fpVisManager->GetVerbosity();
183
184  G4RunManager* runManager = G4RunManager::GetRunManager();
185  const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
186  const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
187  size_t nKeptEvents = events? events->size(): 0;
188
189  if (!nKeptEvents) {
190    if (verbosity >= G4VisManager::errors) {
191      G4cout <<
192        "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
193        "\n  or kept events not accessible."
194             << G4endl;
195    }
196    return;
197  }
198
199  G4VViewer* viewer = fpVisManager->GetCurrentViewer();
200  if (!viewer) {
201    if (verbosity >= G4VisManager::errors) {
202      G4cout <<
203  "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
204             << G4endl;
205    }
206    return;
207  }
208
209  G4Scene* pScene = fpVisManager->GetCurrentScene();
210  if (!pScene) {
211    if (verbosity >= G4VisManager::errors) {
212      G4cout << "ERROR: No current scene.  Please create one." << G4endl;
213    }
214    return;
215  }
216
217  G4UImanager* UImanager = G4UImanager::GetUIpointer();
218  G4int keepVerbose = UImanager->GetVerboseLevel();
219  G4int newVerbose(0);
220  if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
221    newVerbose = 2;
222  UImanager->SetVerboseLevel(newVerbose);
223
224  // Event by event refreshing...
225  G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
226  pScene->SetRefreshAtEndOfEvent(true);
227  if (macroFileName.empty()) {
228
229    // Draw to viewer and pause session...
230    G4UIsession* session = UImanager->GetSession();
231    for (size_t i = 0; i < nKeptEvents; ++i) {
232      const G4Event* event = (*events)[i];
233      if (verbosity >= G4VisManager::warnings) {
234        G4cout << "Drawing event : " << event->GetEventID() <<
235          ".  At EndOfEvent, enter any command, then \"cont[inue]\"..."
236               << G4endl;
237        static G4bool first = true;
238        if (first) {
239          first = false;
240          G4cout <<
241  "  Useful commands might be:"
242  "\n    \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
243  "\n    \"/vis/oglx/printEPS\" to get hard copy."
244  "\n    \"/vis/open\" to get alternative viewer."
245  "\n    \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
246                 << G4endl;
247        }
248      }
249      fpVisManager->SetRequestedEvent(event);
250      UImanager->ApplyCommand("/vis/viewer/rebuild");
251      /* The above command forces a rebuild of the scene, including
252         the detector.  This is fine for "immediate" viewers - a
253         refresh requires a rebuild anyway.  But for "stored mode"
254         viewers, you could, in principle, avoid a rebuild of the
255         detector with something like the following:
256      sceneHandler->ClearTransientStore();
257      viewer->DrawView();
258      sceneHandler->DrawEvent(event);
259         but this causes mayhem for "immediate" viewers because
260         ClearTransientStore issues a DrawView and some curious sort
261         of recursion takes place.  For "stored" viewers, the event
262         gets drawn but not the eventID, so something odd is happening
263         there too.  This needs further investigation - enhanced
264         features or a complete re-think.
265      */
266      UImanager->ApplyCommand("/vis/viewer/flush");
267      session->PauseSessionStart("EndOfEvent");
268      fpVisManager->SetRequestedEvent(0);
269      if (fpVisManager->GetAbortReviewKeptEvents()) break;
270    }
271    fpVisManager->SetAbortReviewKeptEvents(false);
272
273  } else {
274
275    // Execute macro file...
276    for (size_t i = 0; i < nKeptEvents; ++i) {
277      const G4Event* event = (*events)[i];
278      if (verbosity >= G4VisManager::warnings) {
279        G4cout << "Drawing event : " << event->GetEventID()
280               << " with macro file \"" << macroFileName << G4endl;
281      }
282      fpVisManager->SetRequestedEvent(event);
283      UImanager->ApplyCommand("/control/execute " + macroFileName);
284      fpVisManager->SetRequestedEvent(0);
285    }
286  }
287  pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
288
289  UImanager->SetVerboseLevel(keepVerbose);
290}
291
292////////////// /vis/verbose ///////////////////////////////////////
293
294G4VisCommandVerbose::G4VisCommandVerbose () {
295  G4bool omitable;
296
297  fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
298  for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
299    fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
300  }
301  fpCommand -> SetParameterName("verbosity", omitable=true);
302  fpCommand -> SetDefaultValue("warnings");
303}
304
305G4VisCommandVerbose::~G4VisCommandVerbose () {
306  delete fpCommand;
307}
308
309G4String G4VisCommandVerbose::GetCurrentValue (G4UIcommand*) {
310  return G4String();
311}
312
313void G4VisCommandVerbose::SetNewValue (G4UIcommand*,
314                                       G4String newValue) {
315  G4VisManager::Verbosity verbosity =
316    fpVisManager->GetVerbosityValue(newValue);
317  fpVisManager->SetVerboseLevel(verbosity);
318  // Always prints whatever the verbosity...
319  G4cout << "Visualization verbosity changed to "
320         << G4VisManager::VerbosityString(verbosity) << G4endl;
321}
Note: See TracBrowser for help on using the repository browser.