Geant4 10.7.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
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"
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/drawOnlyToBeKeptEvents /////////////////////////////
76
78{
79 G4bool omitable;
80
81 fpCommand = new G4UIcmdWithABool("/vis/drawOnlyToBeKeptEvents", this);
82 fpCommand -> SetGuidance
83 ("DURING A RUN draw only those events that have been \"to be kept\" by the user"
84 "\nwith G4EventManager::GetEventManager()->KeepTheCurrentEvent() or"
85 "\nwith \"/event/keepCurrentEvent\".");
86 fpCommand -> SetGuidance(
87 "To draw selected events the user should set this flag, then in a user action:"
88 "\n if ( some criterion ) {"
89 "\n G4EventManager::GetEventManager()->KeepTheCurrentEvent();"
90 "\n }");
91 fpCommand -> SetParameterName("draw", omitable=true);
92 fpCommand -> SetDefaultValue(true);
93}
94
96 delete fpCommand;
97}
98
100 return G4String();
101}
102
104 G4String newValue) {
107 if (verbosity < G4VisManager::warnings) {
109 G4cout << "Only events that have been kept will be drawn." << G4endl;
110 } else {
111 G4cout << "All events will be drawn." << G4endl;
112 }
113 }
114}
115
116////////////// /vis/enable ///////////////////////////////////////
117
119 G4bool omitable;
120
121 fpCommand = new G4UIcmdWithABool("/vis/enable", this);
122 fpCommand -> SetGuidance("Enables/disables visualization system.");
123 fpCommand -> SetParameterName("enabled", omitable=true);
124 fpCommand -> SetDefaultValue(true);
125
126 fpCommand1 = new G4UIcmdWithoutParameter("/vis/disable", this);
127 fpCommand1 -> SetGuidance("Disables visualization system.");
128}
129
131 delete fpCommand;
132 delete fpCommand1;
133}
134
136 return G4String();
137}
138
140 G4String newValue) {
141 if (command == fpCommand) {
142 G4bool enable = G4UIcommand::ConvertToBool(newValue);
143 if (enable) fpVisManager->Enable(); // Printing is in vis manager.
144 else fpVisManager->Disable(); // Printing is in vis manager.
145 } else fpVisManager->Disable(); // Printing is in vis manager.
146 // Note: Printing is in vis manager.
147}
148
149////////////// /vis/initialize ///////////////////////////////////////
150
152{
153 fpCommand = new G4UIcmdWithoutParameter("/vis/initialize", this);
154 fpCommand -> SetGuidance("Initialise visualisation manager.");
155}
156
158 delete fpCommand;
159}
160
162 G4String) {
164}
165
166////////////// /vis/list ///////////////////////////////////////
167
169{
170 G4bool omitable;
171
172 fpCommand = new G4UIcmdWithAString("/vis/list", this);
173 fpCommand -> SetGuidance("Lists visualization parameters.");
174 fpCommand -> SetParameterName("verbosity", omitable=true);
175 fpCommand -> SetDefaultValue("warnings");
176}
177
179{
180 delete fpCommand;
181}
182
184{
185 return "";
186}
187
189{
190 G4String& verbosityString = newValue;
191 G4VisManager::Verbosity verbosity =
192 fpVisManager->GetVerbosityValue(verbosityString);
193
195 G4cout << G4endl;
196 fpVisManager->PrintAvailableModels(verbosity);
197 G4cout << G4endl;
198 fpVisManager->PrintAvailableUserVisActions(verbosity);
199 G4cout << G4endl;
200 fpVisManager->PrintAvailableColours(verbosity);
201 G4cout << G4endl;
203 UImanager->ApplyCommand("/vis/scene/list ! " + newValue);
204 UImanager->ApplyCommand("/vis/viewer/list ! " + newValue);
205
206 G4cout <<
207 "\nAttributes available for modeling and filtering with"
208 "\n \"/vis/modeling/trajectories/create/drawByAttribute\" and"
209 "\n \"/vis/filtering/trajectories/create/attributeFilter\" commands"
210 "\nand by picking:"
211 << G4endl;
212 G4cout
214 G4cout
217 G4cout
220 G4cout
223
224 G4cout <<
225 "\nGeometry attributes available for touchables by picking:\n";
226 G4cout
228
229 if (verbosity < G4VisManager::parameters)
230 G4cout <<
231 "\nTo get more information, \"/vis/list all\" or use individual commands"
232 "\n such as (use \"ls\" or \"help\"):"
233 "\n /vis/scene/list all all"
234 "\n /vis/viewer/list all all"
235 "\n /vis/modeling/trajectories/list"
236 "\n /vis/filtering/trajectories/list"
237 << G4endl;
238}
239
240////////////// /vis/reviewKeptEvents ///////////////////////////////////////
241
243{
244 G4bool omitable;
245
246 fpCommand = new G4UIcmdWithAString("/vis/reviewKeptEvents", this);
247 fpCommand -> SetGuidance("Review kept events.");
248 fpCommand -> SetGuidance
249 ("If a macro file is specified, it is executed for each event.");
250 fpCommand -> SetGuidance(
251 "If a macro file is not specified, each event is drawn to the current"
252 "\nviewer. After each event, the session is paused. The user may issue"
253 "\nany allowed command. Then enter \"cont[inue]\" to continue to the next"
254 "\nevent."
255 "\nUseful commands might be:"
256 "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
257 "\n \"/vis/oglx/printEPS\" to get hard copy."
258 "\n \"/vis/open\" to get alternative viewer."
259 "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort.");
260 fpCommand -> SetParameterName("macro-file-name", omitable=true);
261 fpCommand -> SetDefaultValue("");
262}
263
265{
266 delete fpCommand;
267}
268
270{
271 return "";
272}
273
275{
277 G4cout <<
278 "\"/vis/reviewKeptEvents\" not allowed within an already started review."
279 "\n No action taken."
280 << G4endl;
281 return;
282 }
283
284 G4String& macroFileName = newValue;
286
288 const G4Run* run = runManager ? runManager->GetCurrentRun() : nullptr;
289 const std::vector<const G4Event*>* events =
290 run ? run->GetEventVector() : nullptr;
291 size_t nKeptEvents = events ? events->size() : 0;
292
293 if (!nKeptEvents) {
294 if (verbosity >= G4VisManager::errors) {
295 G4cerr <<
296 "ERROR: G4VisCommandReviewKeptEvents::SetNewValue: No kept events,"
297 "\n or kept events not accessible."
298 << G4endl;
299 }
300 return;
301 }
302
304 if (!viewer) {
305 if (verbosity >= G4VisManager::errors) {
306 G4cerr <<
307 "ERROR: No current viewer - \"/vis/viewer/list\" to see possibilities."
308 << G4endl;
309 }
310 return;
311 }
312
314 if (!pScene) {
315 if (verbosity >= G4VisManager::errors) {
316 G4cerr << "ERROR: No current scene. Please create one." << G4endl;
317 }
318 return;
319 }
320
322 G4int keepVerbose = UImanager->GetVerboseLevel();
323 G4int newVerbose(0);
324 if (keepVerbose >= 2 || verbosity >= G4VisManager::confirmations)
325 newVerbose = 2;
326 UImanager->SetVerboseLevel(newVerbose);
327
328 G4VVisManager* keepConcreteInstance = fpVisManager->GetConcreteInstance();
330
331 // Start on clean view
332 UImanager->ApplyCommand("/vis/viewer/rebuild");
333
334 // Event by event refreshing...
336 G4bool currentRefreshAtEndOfEvent = pScene->GetRefreshAtEndOfEvent();
337 pScene->SetRefreshAtEndOfEvent(true);
338 if (macroFileName.empty()) {
339
340 // Draw to viewer and pause session...
341 G4UIsession* session = UImanager->GetSession();
342 for (size_t i = 0; i < nKeptEvents; ++i) {
343 const G4Event* event = (*events)[i];
344 if (verbosity >= G4VisManager::warnings) {
345 G4cout << "Drawing event : " << event->GetEventID() <<
346 ". At EndOfEvent, enter any command, then \"cont[inue]\"..."
347 << G4endl;
348 static G4bool first = true;
349 if (first) {
350 first = false;
351 G4cout <<
352 " Useful commands might be:"
353 "\n \"/vis/scene/add/trajectories\" if not already added."
354 "\n \"/vis/viewer/...\" to change the view (zoom, set/viewpoint,...)."
355 "\n \"/vis/oglx/printEPS\" to get hard copy."
356 "\n \"/vis/open\" to get alternative viewer."
357 "\n \"/vis/abortReviewKeptEvents\", then \"cont[inue]\", to abort."
358 << G4endl;
359 }
360 }
362 UImanager->ApplyCommand("/vis/viewer/rebuild");
363 /* The above command forces a rebuild of the scene, including
364 the detector. This is fine for "immediate" viewers - a
365 refresh requires a rebuild anyway. But for "stored mode"
366 viewers, you could, in principle, avoid a rebuild of the
367 detector with something like the following:
368 sceneHandler->ClearTransientStore();
369 viewer->DrawView();
370 sceneHandler->DrawEvent(event);
371 but this causes mayhem for "immediate" viewers because
372 ClearTransientStore issues a DrawView and some curious sort
373 of recursion takes place. For "stored" viewers, the event
374 gets drawn but not the eventID, so something odd is happening
375 there too. This needs further investigation - enhanced
376 features or a complete re-think.
377 */
378 UImanager->ApplyCommand("/vis/viewer/flush");
379 session->PauseSessionStart("EndOfEvent");
382 }
384
385 } else {
386
387 // Execute macro file...
388 for (size_t i = 0; i < nKeptEvents; ++i) {
389 const G4Event* event = (*events)[i];
390 if (verbosity >= G4VisManager::warnings) {
391 G4cout << "Drawing event : " << event->GetEventID()
392 << " with macro file \"" << macroFileName << G4endl;
393 }
395 UImanager->ApplyCommand("/control/execute " + macroFileName);
397 }
398 }
399 pScene->SetRefreshAtEndOfEvent(currentRefreshAtEndOfEvent);
401
402 if (keepConcreteInstance) fpVisManager->Enable();
403 else fpVisManager->Disable();
404 UImanager->SetVerboseLevel(keepVerbose);
405}
406
407////////////// /vis/verbose ///////////////////////////////////////
408
410 G4bool omitable;
411
412 fpCommand = new G4UIcmdWithAString("/vis/verbose", this);
413 for (size_t i = 0; i < G4VisManager::VerbosityGuidanceStrings.size(); ++i) {
414 fpCommand -> SetGuidance(G4VisManager::VerbosityGuidanceStrings[i]);
415 }
416 fpCommand -> SetParameterName("verbosity", omitable=true);
417 fpCommand -> SetDefaultValue("warnings");
418}
419
421 delete fpCommand;
422}
423
425 return G4String();
426}
427
429 G4String newValue) {
430 G4VisManager::Verbosity verbosity =
432 fpVisManager->SetVerboseLevel(verbosity);
433 // Always prints whatever the verbosity...
434 G4cout << "Visualization verbosity changed to "
435 << G4VisManager::VerbosityString(verbosity) << G4endl;
436}
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
G4GLOB_DLL std::ostream G4cerr
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL 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 * GetMasterRunManager()
const G4Run * GetCurrentRun() const
Definition: G4Run.hh:49
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:119
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:530
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:485
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:193
G4UIsession * GetSession() const
Definition: G4UImanager.hh:180
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:77
void SetVerboseLevel(G4int val)
Definition: G4UImanager.hh:192
virtual void PauseSessionStart(const G4String &Prompt)
Definition: G4UIsession.cc:63
static G4VisManager * fpVisManager
static G4VVisManager * GetConcreteInstance()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
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
void SetDrawEventOnlyIfToBeKept(G4bool)
static std::vector< G4String > VerbosityGuidanceStrings
static G4String VerbosityString(Verbosity)
G4bool GetAbortReviewKeptEvents() const
void SetAbortReviewKeptEvents(G4bool)
G4VViewer * GetCurrentViewer() const
void SetRequestedEvent(const G4Event *)
G4bool GetDrawEventOnlyIfToBeKept() const
void PrintAvailableGraphicsSystems(Verbosity) const
void SetReviewingKeptEvents(G4bool)
static Verbosity GetVerbosity()
void SetVerboseLevel(G4int)
G4bool GetReviewingKeptEvents() const
static Verbosity GetVerbosityValue(const G4String &)