Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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$
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#include "G4Run.hh"
40#include "G4UIsession.hh"
41#include "G4Trajectory.hh"
42#include "G4TrajectoryPoint.hh"
43#include "G4RichTrajectory.hh"
45#include "G4SmoothTrajectory.hh"
48#include "G4AttDef.hh"
49
50////////////// /vis/abortReviewKeptEvents /////////////////////////////
51
53 G4bool omitable;
54
55 fpCommand = new G4UIcmdWithABool("/vis/abortReviewKeptEvents", this);
56 fpCommand -> SetGuidance("Abort review of kept events.");
57 fpCommand -> SetParameterName("abort", omitable=true);
58 fpCommand -> SetDefaultValue(true);
59}
60
62 delete fpCommand;
63}
64
66 return G4String();
67}
68
70 G4String newValue) {
72 G4cout << "Type \"continue\" to complete the abort." << G4endl;
73}
74
75////////////// /vis/enable ///////////////////////////////////////
76
78 G4bool omitable;
79
80 fpCommand = new G4UIcmdWithABool("/vis/enable", this);
81 fpCommand -> SetGuidance("Enables/disables visualization system.");
82 fpCommand -> SetParameterName("enabled", omitable=true);
83 fpCommand -> SetDefaultValue(true);
84
85 fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
86 fpCommand1 -> SetGuidance("Disables visualization system.");
87}
88
90 delete fpCommand;
91 delete fpCommand1;
92}
93
95 return G4String();
96}
97
99 G4String newValue) {
100 if (command == fpCommand) {
101 G4bool enable = G4UIcommand::ConvertToBool(newValue);
102 if (enable) fpVisManager->Enable(); // Printing is in vis manager.
103 else fpVisManager->Disable(); // Printing is in vis manager.
104 } else fpVisManager->Disable(); // Printing is in vis manager.
105 // Note: Printing is in vis manager.
106}
107
108////////////// /vis/initialize ///////////////////////////////////////
109
111{
112 fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
113 fpCommand -> SetGuidance("Initialise visualisation manager.");
114}
115
117 delete fpCommand;
118}
119
121 G4String) {
123}
124
125////////////// /vis/list ///////////////////////////////////////
126
128{
129 G4bool omitable;
130
131 fpCommand = new G4UIcmdWithAString("/vis/list", this);
132 fpCommand -> SetGuidance("Lists visualization parameters.");
133 fpCommand -> SetParameterName("verbosity", omitable=true);
134 fpCommand -> SetDefaultValue("warnings");
135}
136
138{
139 delete fpCommand;
140}
141
143{
144 return "";
145}
146
148{
149 G4String& verbosityString = newValue;
150 G4VisManager::Verbosity verbosity =
151 fpVisManager->GetVerbosityValue(verbosityString);
152
154 G4cout << G4endl;
155 fpVisManager->PrintAvailableModels(verbosity);
156 G4cout << G4endl;
157 fpVisManager->PrintAvailableUserVisActions(verbosity);
158 G4cout << G4endl;
159 fpVisManager->PrintAvailableColours(verbosity);
160 G4cout << G4endl;
162 UImanager->ApplyCommand("/vis/scene/list ! c");
163 UImanager->ApplyCommand("/vis/viewer/list ! c");
164
165 G4cout <<
166 "\nAttributes available for modeling and filtering with"
167 "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
168 "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
169 "\nand by picking:"
170 << G4endl;
178
179 G4cout <<
180 "\nAttributes available for touchables by picking:"
181 << G4endl;
183
184 if (verbosity < G4VisManager::parameters)
185 G4cout <<
186 "\nTo get more information, \"/vis/list all all\" or use individual commands"
187 "\n such as (use \"ls\" or \"help\"):"
188 "\n /vis/scene/list all all"
189 "\n /vis/viewer/list all all"
190 "\n /vis/modeling/trajectories/list"
191 "\n /vis/filtering/trajectories/list"
192 << G4endl;
193}
194
195////////////// /vis/reviewKeptEvents ///////////////////////////////////////
196
198{
199 G4bool omitable;
200
201 fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
202 fpCommand -> SetGuidance("Review kept events.");
203 fpCommand -> SetGuidance
204 ("If a macro file is specified, it is executed for each event.");
205 fpCommand -> SetGuidance(
206 "If a macro file is not specified, each event is drawn to the current"
207 "\nviewer. After each event, the session is paused. The user may issue"
208 "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
209 "\nevent."
210 "\nUseful commands might be:"
211 "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
212 "\n \"/vis/oglx/printEPS\" to get hard copy."
213 "\n \"/vis/open\" to get alternative viewer."
214 "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
215 fpCommand -> SetParameterName("macro-file-name", omitable=true);
216 fpCommand -> SetDefaultValue("");
217}
218
220{
221 delete fpCommand;
222}
223
225{
226 return "";
227}
228
230{
231 static bool reviewing = false;
232 if (reviewing) {
233 G4cout <<
234 "\"/vis/reviewKeptEvents\" not allowed within an already started review."
235 "\n No action taken."
236 << G4endl;
237 return;
238 }
239
240 G4String& macroFileName = newValue;
242
244 const G4Run* run = runManager? runManager->GetCurrentRun(): 0;
245 const std::vector<const G4Event*>* events = run? run->GetEventVector(): 0;
246 size_t nKeptEvents = events? events->size(): 0;
247
248 if (!nKeptEvents) {
249 if (verbosity >= G4VisManager::errors) {
250 G4cout <<
251 "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
252 "\n or kept events not accessible."
253 << G4endl;
254 }
255 return;
256 }
257
259 if (!viewer) {
260 if (verbosity >= G4VisManager::errors) {
261 G4cout <<
262 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
263 << G4endl;
264 }
265 return;
266 }
267
269 if (!pScene) {
270 if (verbosity >= G4VisManager::errors) {
271 G4cout << "ERROR: No current scene. Please create one." << G4endl;
272 }
273 return;
274 }
275
277 G4int keepVerbose = UImanager->GetVerboseLevel();
278 G4int newVerbose(0);
279 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
280 newVerbose = 2;
281 UImanager->SetVerboseLevel(newVerbose);
282
283 // Event by event refreshing...
284 reviewing = true;
285 G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
286 pScene->SetRefreshAtEndOfEvent(true);
287 if (macroFileName.empty()) {
288
289 // Draw to viewer and pause session...
290 G4UIsession* session = UImanager->GetSession();
291 for (size_t i = 0; i < nKeptEvents; ++i) {
292 const G4Event* event = (*events)[i];
293 if (verbosity >= G4VisManager::warnings) {
294 G4cout << "Drawing event : " << event->GetEventID() <<
295 ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
296 << G4endl;
297 static G4bool first = true;
298 if (first) {
299 first = false;
300 G4cout <<
301 " Useful commands might be:"
302 "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
303 "\n \"/vis/oglx/printEPS\" to get hard copy."
304 "\n \"/vis/open\" to get alternative viewer."
305 "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
306 << G4endl;
307 }
308 }
310 UImanager->ApplyCommand("/vis/viewer/rebuild");
311 /* The above command forces a rebuild of the scene, including
312 the detector. This is fine for "immediate" viewers - a
313 refresh requires a rebuild anyway. But for "stored mode"
314 viewers, you could, in principle, avoid a rebuild of the
315 detector with something like the following:
316 sceneHandler->ClearTransientStore();
317 viewer->DrawView();
318 sceneHandler->DrawEvent(event);
319 but this causes mayhem for "immediate" viewers because
320 ClearTransientStore issues a DrawView and some curious sort
321 of recursion takes place. For "stored" viewers, the event
322 gets drawn but not the eventID, so something odd is happening
323 there too. This needs further investigation - enhanced
324 features or a complete re-think.
325 */
326 UImanager->ApplyCommand("/vis/viewer/flush");
327 session->PauseSessionStart("EndOfEvent");
330 }
332
333 } else {
334
335 // Execute macro file...
336 for (size_t i = 0; i < nKeptEvents; ++i) {
337 const G4Event* event = (*events)[i];
338 if (verbosity >= G4VisManager::warnings) {
339 G4cout << "Drawing event : " << event->GetEventID()
340 << " with macro file \"" << macroFileName << G4endl;
341 }
343 UImanager->ApplyCommand("/control/execute " + macroFileName);
345 }
346 }
347 pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
348 reviewing = false;
349
350 UImanager->SetVerboseLevel(keepVerbose);
351}
352
353////////////// /vis/verbose ///////////////////////////////////////
354
356 G4bool omitable;
357
358 fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
359 for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
360 fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
361 }
362 fpCommand -> SetParameterName("verbosity", omitable=true);
363 fpCommand -> SetDefaultValue("warnings");
364}
365
367 delete fpCommand;
368}
369
371 return G4String();
372}
373
375 G4String newValue) {
376 G4VisManager::Verbosity verbosity =
378 fpVisManager->SetVerboseLevel(verbosity);
379 // Always prints whatever the verbosity...
380 G4cout << "Visualization verbosity changed to "
381 << G4VisManager::VerbosityString(verbosity) << G4endl;
382}
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:62
const G4Run * GetCurrentRun() const
Definition: G4Run.hh:47
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:112
G4bool GetRefreshAtEndOfEvent() const
void SetRefreshAtEndOfEvent(G4bool)
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
virtual const std::map< G4String, G4AttDef > * GetAttDefs() const
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:403
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:369
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:218
G4UIsession * GetSession() const
Definition: G4UImanager.hh:199
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:51
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:216
virtual void PauseSessionStart(const G4String &Prompt)
Definition: G4UIsession.cc:40
static G4VisManager * fpVisManager
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
virtual ~G4VisCommandEnable()
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual ~G4VisCommandInitialize()
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
virtual ~G4VisCommandList()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
virtual ~G4VisCommandVerbose()
void Initialize()
G4Scene * GetCurrentScene() const
static std::vector< G4String > VerbosityGuidanceStrings
static G4String VerbosityString(Verbosity)
G4bool GetAbortReviewKeptEvents() const
void SetAbortReviewKeptEvents(G4bool)
G4VViewer * GetCurrentViewer() const
void SetRequestedEvent(const G4Event *)
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)
static Verbosity GetVerbosityValue(const G4String &)
void PrintAvailableGraphicsSystems() const