source: trunk/source/visualization/management/src/G4VisManager.cc@ 1346

Last change on this file since 1346 was 1346, checked in by garnier, 15 years ago

before tag

  • Property svn:mime-type set to text/cpp
File size: 57.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// $Id: G4VisManager.cc,v 1.131 2010/12/14 15:53:28 gcosmo Exp $
27// GEANT4 tag $Name: $
28//
29//
30// GEANT4 Visualization Manager - John Allison 02/Jan/1996.
31
32#include "G4VisManager.hh"
33
34#include "G4VisCommands.hh"
35#include "G4VisCommandsCompound.hh"
36#include "G4VisCommandsGeometry.hh"
37#include "G4VisCommandsGeometrySet.hh"
38#include "G4VisCommandsScene.hh"
39#include "G4VisCommandsSceneAdd.hh"
40#include "G4VisCommandsSceneHandler.hh"
41#include "G4VisCommandsViewer.hh"
42#include "G4VisCommandsViewerSet.hh"
43#include "G4UImanager.hh"
44#include "G4VisStateDependent.hh"
45#include "G4UIdirectory.hh"
46#include "G4VisFeaturesOfFukuiRenderer.hh"
47#include "G4VisFeaturesOfDAWNFILE.hh"
48#include "G4VisFeaturesOfOpenGL.hh"
49#include "G4VisFeaturesOfOpenInventor.hh"
50#include "G4VGraphicsSystem.hh"
51#include "G4VSceneHandler.hh"
52#include "G4VViewer.hh"
53#include "G4VPhysicalVolume.hh"
54#include "G4LogicalVolume.hh"
55#include "G4VSolid.hh"
56#include "G4Vector3D.hh"
57#include "G4Point3D.hh"
58#include "G4RotationMatrix.hh"
59#include "G4Polyline.hh"
60#include "G4Polyhedron.hh"
61#include "G4NURBS.hh"
62#include "G4NullModel.hh"
63#include "G4ModelingParameters.hh"
64#include "G4TransportationManager.hh"
65#include "G4VisCommandModelCreate.hh"
66#include "G4VisCommandsListManager.hh"
67#include "G4VisModelManager.hh"
68#include "G4VModelFactory.hh"
69#include "G4VisFilterManager.hh"
70#include "G4VTrajectoryModel.hh"
71#include "G4TrajectoryDrawByCharge.hh"
72#include "Randomize.hh"
73#include "G4RunManager.hh"
74#include "G4EventManager.hh"
75#include "G4Run.hh"
76#include "G4Event.hh"
77#include <sstream>
78
79G4VisManager* G4VisManager::fpInstance = 0;
80
81G4VisManager::Verbosity G4VisManager::fVerbosity = G4VisManager::warnings;
82
83G4VisManager::G4VisManager (const G4String& verbosityString):
84 fVerbose (1),
85 fInitialised (false),
86 fpUserVisAction (0),
87 fpGraphicsSystem (0),
88 fpScene (0),
89 fpSceneHandler (0),
90 fpViewer (0),
91 fpStateDependent (0),
92 fEventRefreshing (false),
93 fTransientsDrawnThisRun (false),
94 fTransientsDrawnThisEvent (false),
95 fEventKeepingSuspended (false),
96 fKeptLastEvent (false),
97 fpRequestedEvent (0),
98 fAbortReviewKeptEvents (false)
99 // All other objects use default constructors.
100{
101 fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
102 fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
103 fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
104 fpDigiFilterMgr = new G4VisFilterManager<G4VDigi>("/vis/filtering/digi");
105
106 VerbosityGuidanceStrings.push_back
107 ("Simple graded message scheme - digit or string (1st character defines):");
108 VerbosityGuidanceStrings.push_back
109 (" 0) quiet, // Nothing is printed.");
110 VerbosityGuidanceStrings.push_back
111 (" 1) startup, // Startup and endup messages are printed...");
112 VerbosityGuidanceStrings.push_back
113 (" 2) errors, // ...and errors...");
114 VerbosityGuidanceStrings.push_back
115 (" 3) warnings, // ...and warnings...");
116 VerbosityGuidanceStrings.push_back
117 (" 4) confirmations, // ...and confirming messages...");
118 VerbosityGuidanceStrings.push_back
119 (" 5) parameters, // ...and parameters of scenes and views...");
120 VerbosityGuidanceStrings.push_back
121 (" 6) all // ...and everything available.");
122
123 if (fpInstance) {
124 G4Exception
125 ("G4VisManager: attempt to Construct more than one VisManager.");
126 }
127
128 fpInstance = this;
129 SetConcreteInstance(this);
130
131 fpStateDependent = new G4VisStateDependent (this);
132 // No need to delete this; G4StateManager does this.
133
134 fVerbosity = GetVerbosityValue(verbosityString);
135 if (fVerbosity >= startup) {
136 G4cout
137 << "Visualization Manager instantiating with verbosity \""
138 << VerbosityString(fVerbosity)
139 << "\"..." << G4endl;
140 }
141
142 // Note: The specific graphics systems must be instantiated in a
143 // higher level library to avoid circular dependencies. Also,
144 // some specifically need additional external libararies that the
145 // user must supply. Therefore we ask the user to implement
146 // RegisterGraphicsSystems() and RegisterModelFactories()
147 // in a subclass. We have to wait for the subclass to instantiate
148 // so RegisterGraphicsSystems() cannot be called from this
149 // constructor; it is called from Initialise(). So we ask the
150 // user:
151 // (a) to write a subclass and implement RegisterGraphicsSystems()
152 // and RegisterModelFactories(). See
153 // visualization/include/G4VisExecutive.hh/icc as an example.
154 // (b) instantiate the subclass.
155 // (c) invoke the Initialise() method of the subclass.
156 // For example:
157 // ...
158 // #ifdef G4VIS_USE
159 // // Instantiate and initialise Visualization Manager.
160 // G4VisManager* visManager = new G4VisExecutive;
161 // visManager -> SetVerboseLevel (Verbose);
162 // visManager -> Initialise ();
163 // #endif
164 // // (Don't forget to delete visManager;)
165 // ...
166
167 // Make top level command directory...
168 G4UIcommand* directory;
169 directory = new G4UIdirectory ("/vis/");
170 directory -> SetGuidance ("Visualization commands.");
171 fDirectoryList.push_back (directory);
172
173 // Instantiate top level basic commands
174 G4VVisCommand::SetVisManager (this); // Sets shared pointer
175 RegisterMessenger(new G4VisCommandVerbose);
176 RegisterMessenger(new G4VisCommandInitialize);
177}
178
179G4VisManager::~G4VisManager () {
180 fpInstance = 0;
181 size_t i;
182 for (i = 0; i < fSceneList.size (); ++i) {
183 delete fSceneList[i];
184 }
185 for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
186 if (fAvailableSceneHandlers[i] != NULL) {
187 delete fAvailableSceneHandlers[i];
188 }
189 }
190 for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
191 if (fAvailableGraphicsSystems[i]) {
192 delete fAvailableGraphicsSystems[i];
193 }
194 }
195 if (fVerbosity >= startup) {
196 G4cout << "Graphics systems deleted." << G4endl;
197 G4cout << "Visualization Manager deleting..." << G4endl;
198 }
199 for (i = 0; i < fMessengerList.size (); ++i) {
200 delete fMessengerList[i];
201 }
202 for (i = 0; i < fDirectoryList.size (); ++i) {
203 delete fDirectoryList[i];
204 }
205
206 delete fpDigiFilterMgr;
207 delete fpHitFilterMgr;
208 delete fpTrajFilterMgr;
209 delete fpTrajDrawModelMgr;
210}
211
212G4VisManager* G4VisManager::GetInstance () {
213 if (!fpInstance) {
214 G4Exception
215 ("G4VisManager::GetInstance: VisManager not yet instantiated!");
216 }
217 return fpInstance;
218}
219
220void G4VisManager::Initialise () {
221
222 if (fInitialised && fVerbosity >= warnings) {
223 G4cout << "WARNING: G4VisManager::Initialise: already initialised."
224 << G4endl;
225 return;
226 }
227
228 if (fVerbosity >= startup) {
229 G4cout << "Visualization Manager initialising..." << G4endl;
230 }
231
232 if (fVerbosity >= parameters) {
233 G4cout <<
234 "\nYou have instantiated your own Visualization Manager, inheriting"
235 "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
236 "\n you should, normally, instantiate drivers which do not need"
237 "\n external packages or libraries, and, optionally, drivers under"
238 "\n control of environment variables."
239 "\n Also you should implement RegisterModelFactories()."
240 "\n See visualization/include/G4VisExecutive.hh/icc, for example."
241 "\n In your main() you will have something like:"
242 "\n #ifdef G4VIS_USE"
243 "\n G4VisManager* visManager = new G4VisExecutive;"
244 "\n visManager -> SetVerboseLevel (Verbose);"
245 "\n visManager -> Initialize ();"
246 "\n #endif"
247 "\n (Don't forget to delete visManager;)"
248 "\n"
249 << G4endl;
250 }
251
252 if (fVerbosity >= startup) {
253 G4cout << "Registering graphics systems..." << G4endl;
254 }
255
256 RegisterGraphicsSystems ();
257
258 if (fVerbosity >= startup) {
259 G4cout <<
260 "\nYou have successfully registered the following graphics systems."
261 << G4endl;
262 PrintAvailableGraphicsSystems ();
263 G4cout << G4endl;
264 }
265
266 // Make command directories for commands instantiated in the
267 // modeling subcategory...
268 G4UIcommand* directory;
269 directory = new G4UIdirectory ("/vis/modeling/");
270 directory -> SetGuidance ("Modeling commands.");
271 fDirectoryList.push_back (directory);
272 directory = new G4UIdirectory ("/vis/modeling/trajectories/");
273 directory -> SetGuidance ("Trajectory model commands.");
274 fDirectoryList.push_back (directory);
275 directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
276 directory -> SetGuidance ("Create trajectory models and messengers.");
277 fDirectoryList.push_back (directory);
278
279 // Filtering command directory
280 directory = new G4UIdirectory ("/vis/filtering/");
281 directory -> SetGuidance ("Filtering commands.");
282 fDirectoryList.push_back (directory);
283 directory = new G4UIdirectory ("/vis/filtering/trajectories/");
284 directory -> SetGuidance ("Trajectory filtering commands.");
285 fDirectoryList.push_back (directory);
286 directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
287 directory -> SetGuidance ("Create trajectory filters and messengers.");
288 fDirectoryList.push_back (directory);
289 directory = new G4UIdirectory ("/vis/filtering/hits/");
290 directory -> SetGuidance ("Hit filtering commands.");
291 fDirectoryList.push_back (directory);
292 directory = new G4UIdirectory ("/vis/filtering/hits/create/");
293 directory -> SetGuidance ("Create hit filters and messengers.");
294 fDirectoryList.push_back (directory);
295 directory = new G4UIdirectory ("/vis/filtering/digi/");
296 directory -> SetGuidance ("Digi filtering commands.");
297 fDirectoryList.push_back (directory);
298 directory = new G4UIdirectory ("/vis/filtering/digi/create/");
299 directory -> SetGuidance ("Create digi filters and messengers.");
300 fDirectoryList.push_back (directory);
301
302 RegisterMessengers ();
303
304 if (fVerbosity >= startup) {
305 G4cout << "Registering model factories..." << G4endl;
306 }
307
308 RegisterModelFactories();
309
310 if (fVerbosity >= startup) {
311 G4cout <<
312 "\nYou have successfully registered the following model factories."
313 << G4endl;
314 PrintAvailableModels (fVerbosity);
315 G4cout << G4endl;
316 }
317
318 fInitialised = true;
319}
320
321void G4VisManager::Enable() {
322 if (IsValidView ()) {
323 if (fVerbosity >= confirmations) {
324 G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
325 }
326 }
327 else {
328 if (fVerbosity >= warnings) {
329 G4cout <<
330 "G4VisManager::Enable: WARNING: visualization remains disabled for"
331 "\n above reasons. Rectifying with valid vis commands will"
332 "\n automatically enable."
333 << G4endl;
334 }
335 }
336}
337
338void G4VisManager::Disable() {
339 SetConcreteInstance(0);
340 if (fVerbosity >= confirmations) {
341 G4cout <<
342 "G4VisManager::Disable: visualization disabled."
343 "\n The pointer returned by GetConcreteInstance will be zero."
344 "\n Note that it will become enabled after some valid vis commands."
345 << G4endl;
346 }
347}
348
349const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () {
350 G4int nSystems = fAvailableGraphicsSystems.size ();
351 if (nSystems == 0) {
352 if (fVerbosity >= warnings) {
353 G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
354 "\n graphics system available!"
355 "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
356 "\n when you compiled/built the visualization code?"
357 "\n 2) Did you instantiate your own Visualization Manager and forget"
358 "\n to implement RegisterGraphicsSystems correctly?"
359 "\n 3) You can register your own graphics system, e.g.,"
360 "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
361 "\n after instantiating your vis manager and before"
362 "\n visManager->Initialize()."
363 << G4endl;
364 }
365 }
366 return fAvailableGraphicsSystems;
367}
368
369G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) {
370 G4bool happy = true;
371 if (pSystem) {
372 fAvailableGraphicsSystems.push_back (pSystem);
373 if (fVerbosity >= confirmations) {
374 G4cout << "G4VisManager::RegisterGraphicsSystem: "
375 << pSystem -> GetName ();
376 if (pSystem -> GetNickname () != "") {
377 G4cout << " (" << pSystem -> GetNickname () << ")";
378 }
379 G4cout << " registered." << G4endl;
380 }
381 }
382 else {
383 if (fVerbosity >= errors) {
384 G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!"
385 << G4endl;
386 }
387 happy=false;
388 }
389 return happy;
390}
391
392const G4VTrajectoryModel*
393G4VisManager::CurrentTrajDrawModel() const
394{
395 assert (0 != fpTrajDrawModelMgr);
396
397 const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current();
398
399 if (0 == model) {
400 // No model was registered with the trajectory model manager.
401 // Use G4TrajectoryDrawByCharge as a default.
402 fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated"));
403
404 if (fVerbosity >= warnings) {
405 G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
406 G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
407 }
408 }
409
410 model = fpTrajDrawModelMgr->Current();
411 assert (0 != model); // Should definitely exist now
412
413 return model;
414}
415
416void G4VisManager::RegisterModel(G4VTrajectoryModel* model)
417{
418 fpTrajDrawModelMgr->Register(model);
419}
420
421void
422G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory)
423{
424 fpTrajDrawModelMgr->Register(factory);
425}
426
427void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model)
428{
429 fpTrajFilterMgr->Register(model);
430}
431
432void
433G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory)
434{
435 fpTrajFilterMgr->Register(factory);
436}
437
438void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model)
439{
440 fpHitFilterMgr->Register(model);
441}
442
443void
444G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory)
445{
446 fpHitFilterMgr->Register(factory);
447}
448
449void G4VisManager::RegisterModel(G4VFilter<G4VDigi>* model)
450{
451 fpDigiFilterMgr->Register(model);
452}
453
454void
455G4VisManager::RegisterModelFactory(G4DigiFilterFactory* factory)
456{
457 fpDigiFilterMgr->Register(factory);
458}
459
460void G4VisManager::SelectTrajectoryModel(const G4String& model)
461{
462 fpTrajDrawModelMgr->SetCurrent(model);
463}
464
465void G4VisManager::Draw (const G4Circle& circle,
466 const G4Transform3D& objectTransform) {
467 if (IsValidView ()) {
468#ifdef G4DEBUG_VIS_MANAGEMENT
469 printf("G4VisManager::Draw circle\n");
470#endif
471 ClearTransientStoreIfMarked();
472 fpSceneHandler -> BeginPrimitives (objectTransform);
473 fpSceneHandler -> AddPrimitive (circle);
474 fpSceneHandler -> EndPrimitives ();
475 }
476}
477
478void G4VisManager::Draw (const G4NURBS& nurbs,
479 const G4Transform3D& objectTransform) {
480 if (IsValidView ()) {
481#ifdef G4DEBUG_VIS_MANAGEMENT
482 printf("G4VisManager::Draw nurbs\n");
483#endif
484 ClearTransientStoreIfMarked();
485 fpSceneHandler -> BeginPrimitives (objectTransform);
486 fpSceneHandler -> AddPrimitive (nurbs);
487 fpSceneHandler -> EndPrimitives ();
488 }
489}
490
491void G4VisManager::Draw (const G4Polyhedron& polyhedron,
492 const G4Transform3D& objectTransform) {
493 if (IsValidView ()) {
494#ifdef G4DEBUG_VIS_MANAGEMENT
495 printf("G4VisManager::Draw polyhedron\n");
496#endif
497 ClearTransientStoreIfMarked();
498 fpSceneHandler -> BeginPrimitives (objectTransform);
499 fpSceneHandler -> AddPrimitive (polyhedron);
500 fpSceneHandler -> EndPrimitives ();
501 }
502}
503
504void G4VisManager::Draw (const G4Polyline& line,
505 const G4Transform3D& objectTransform) {
506 if (IsValidView ()) {
507#ifdef G4DEBUG_VIS_MANAGEMENT
508 printf("G4VisManager::Draw line\n");
509#endif
510 ClearTransientStoreIfMarked();
511 fpSceneHandler -> BeginPrimitives (objectTransform);
512 fpSceneHandler -> AddPrimitive (line);
513 fpSceneHandler -> EndPrimitives ();
514 }
515}
516
517void G4VisManager::Draw (const G4Polymarker& polymarker,
518 const G4Transform3D& objectTransform) {
519 if (IsValidView ()) {
520#ifdef G4DEBUG_VIS_MANAGEMENT
521 printf("G4VisManager::Draw polymarker\n");
522#endif
523 ClearTransientStoreIfMarked();
524 fpSceneHandler -> BeginPrimitives (objectTransform);
525 fpSceneHandler -> AddPrimitive (polymarker);
526 fpSceneHandler -> EndPrimitives ();
527 }
528}
529
530void G4VisManager::Draw (const G4Scale& scale,
531 const G4Transform3D& objectTransform) {
532 if (IsValidView ()) {
533#ifdef G4DEBUG_VIS_MANAGEMENT
534 printf("G4VisManager::Draw scale\n");
535#endif
536 ClearTransientStoreIfMarked();
537 fpSceneHandler -> BeginPrimitives (objectTransform);
538 fpSceneHandler -> AddPrimitive (scale);
539 fpSceneHandler -> EndPrimitives ();
540 }
541}
542
543void G4VisManager::Draw (const G4Square& square,
544 const G4Transform3D& objectTransform) {
545 if (IsValidView ()) {
546#ifdef G4DEBUG_VIS_MANAGEMENT
547 printf("G4VisManager::Draw square\n");
548#endif
549 ClearTransientStoreIfMarked();
550 fpSceneHandler -> BeginPrimitives (objectTransform);
551 fpSceneHandler -> AddPrimitive (square);
552 fpSceneHandler -> EndPrimitives ();
553 }
554}
555
556void G4VisManager::Draw (const G4Text& text,
557 const G4Transform3D& objectTransform) {
558 if (IsValidView ()) {
559#ifdef G4DEBUG_VIS_MANAGEMENT
560 printf("G4VisManager::Draw text ______________________________\n");
561#endif
562 ClearTransientStoreIfMarked();
563 fpSceneHandler -> BeginPrimitives (objectTransform);
564 fpSceneHandler -> AddPrimitive (text);
565 fpSceneHandler -> EndPrimitives ();
566 }
567}
568
569void G4VisManager::Draw2D (const G4Circle& circle,
570 const G4Transform3D& objectTransform)
571{
572 if (IsValidView()) {
573#ifdef G4DEBUG_VIS_MANAGEMENT
574 printf("G4VisManager::Draw2d circle\n");
575#endif
576 ClearTransientStoreIfMarked();
577 fpSceneHandler -> BeginPrimitives2D(objectTransform);
578 fpSceneHandler -> AddPrimitive(circle);
579 fpSceneHandler -> EndPrimitives2D();
580 }
581}
582
583void G4VisManager::Draw2D (const G4NURBS& nurbs,
584 const G4Transform3D& objectTransform)
585{
586 if (IsValidView()) {
587#ifdef G4DEBUG_VIS_MANAGEMENT
588 printf("G4VisManager::Draw2d nurbs\n");
589#endif
590 ClearTransientStoreIfMarked();
591 fpSceneHandler -> BeginPrimitives2D(objectTransform);
592 fpSceneHandler -> AddPrimitive(nurbs);
593 fpSceneHandler -> EndPrimitives2D();
594 }
595}
596
597void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
598 const G4Transform3D& objectTransform)
599{
600 if (IsValidView()) {
601#ifdef G4DEBUG_VIS_MANAGEMENT
602 printf("G4VisManager::Draw2d polyhedron\n");
603#endif
604 ClearTransientStoreIfMarked();
605 fpSceneHandler -> BeginPrimitives2D(objectTransform);
606 fpSceneHandler -> AddPrimitive(polyhedron);
607 fpSceneHandler -> EndPrimitives2D();
608 }
609}
610
611void G4VisManager::Draw2D (const G4Polyline& line,
612 const G4Transform3D& objectTransform)
613{
614 if (IsValidView()) {
615#ifdef G4DEBUG_VIS_MANAGEMENT
616 printf("G4VisManager::Draw2d line\n");
617#endif
618 ClearTransientStoreIfMarked();
619 fpSceneHandler -> BeginPrimitives2D(objectTransform);
620 fpSceneHandler -> AddPrimitive(line);
621 fpSceneHandler -> EndPrimitives2D();
622 }
623}
624
625void G4VisManager::Draw2D (const G4Polymarker& polymarker,
626 const G4Transform3D& objectTransform)
627{
628 if (IsValidView()) {
629#ifdef G4DEBUG_VIS_MANAGEMENT
630 printf("G4VisManager::Draw2d polymarker\n");
631#endif
632 ClearTransientStoreIfMarked();
633 fpSceneHandler -> BeginPrimitives2D(objectTransform);
634 fpSceneHandler -> AddPrimitive(polymarker);
635 fpSceneHandler -> EndPrimitives2D();
636 }
637}
638
639void G4VisManager::Draw2D (const G4Square& square,
640 const G4Transform3D& objectTransform)
641{
642 if (IsValidView()) {
643#ifdef G4DEBUG_VIS_MANAGEMENT
644 printf("G4VisManager::Draw2d square\n");
645#endif
646 ClearTransientStoreIfMarked();
647 fpSceneHandler -> BeginPrimitives2D(objectTransform);
648 fpSceneHandler -> AddPrimitive(square);
649 fpSceneHandler -> EndPrimitives2D();
650 }
651}
652
653void G4VisManager::Draw2D (const G4Text& text,
654 const G4Transform3D& objectTransform)
655{
656 if (IsValidView()) {
657#ifdef G4DEBUG_VIS_MANAGEMENT
658 printf("G4VisManager::Draw2d text _____________________________\n");
659#endif
660 ClearTransientStoreIfMarked();
661 fpSceneHandler -> BeginPrimitives2D(objectTransform);
662 fpSceneHandler -> AddPrimitive(text);
663 fpSceneHandler -> EndPrimitives2D();
664 }
665}
666
667void G4VisManager::Draw (const G4VHit& hit) {
668 if (IsValidView ()) {
669#ifdef G4DEBUG_VIS_MANAGEMENT
670 printf("G4VisManager::Draw hit\n");
671#endif
672 ClearTransientStoreIfMarked();
673 fpSceneHandler -> AddCompound (hit);
674 }
675}
676
677void G4VisManager::Draw (const G4VDigi& digi) {
678 if (IsValidView ()) {
679#ifdef G4DEBUG_VIS_MANAGEMENT
680 printf("G4VisManager::Draw digi\n");
681#endif
682 ClearTransientStoreIfMarked();
683 fpSceneHandler -> AddCompound (digi);
684 }
685}
686
687void G4VisManager::Draw (const G4VTrajectory& traj,
688 G4int i_mode) {
689 if (IsValidView ()) {
690#ifdef G4DEBUG_VIS_MANAGEMENT
691 printf("G4VisManager::Draw traj\n");
692#endif
693 ClearTransientStoreIfMarked();
694 fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
695 dummyTrajectoriesModel.SetDrawingMode(i_mode);
696 fpSceneHandler -> AddCompound (traj);
697 }
698}
699
700void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
701 const G4VisAttributes& attribs,
702 const G4Transform3D& objectTransform) {
703 // Find corresponding solid.
704 G4VSolid* pSol = logicalVol.GetSolid ();
705#ifdef G4DEBUG_VIS_MANAGEMENT
706 printf("G4VisManager::Draw logicalVol\n");
707#endif
708 Draw (*pSol, attribs, objectTransform);
709}
710
711void G4VisManager::Draw (const G4VSolid& solid,
712 const G4VisAttributes& attribs,
713 const G4Transform3D& objectTransform) {
714 if (IsValidView ()) {
715#ifdef G4DEBUG_VIS_MANAGEMENT
716 printf("G4VisManager::Draw2d solid\n");
717#endif
718 ClearTransientStoreIfMarked();
719 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
720 solid.DescribeYourselfTo (*fpSceneHandler);
721 fpSceneHandler -> PostAddSolid ();
722 }
723}
724
725void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
726 const G4VisAttributes& attribs,
727 const G4Transform3D& objectTransform) {
728 // Find corresponding logical volume and solid.
729 G4LogicalVolume* pLV = physicalVol.GetLogicalVolume ();
730 G4VSolid* pSol = pLV -> GetSolid ();
731 Draw (*pSol, attribs, objectTransform);
732}
733
734void G4VisManager::CreateSceneHandler (G4String name) {
735 if (!fInitialised) Initialise ();
736 if (fpGraphicsSystem) {
737 G4VSceneHandler* pSceneHandler =
738 fpGraphicsSystem -> CreateSceneHandler (name);
739 if (pSceneHandler) {
740 fAvailableSceneHandlers.push_back (pSceneHandler);
741 fpSceneHandler = pSceneHandler; // Make current.
742 }
743 else {
744 if(fVerbosity >= errors) {
745 G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
746 << fpGraphicsSystem -> GetName ()
747 << " scene handler creation.\n No action taken."
748 << G4endl;
749 }
750 }
751 }
752 else PrintInvalidPointers ();
753}
754
755void G4VisManager::CreateViewer (G4String name,G4String XGeometry) {
756
757 if (!fInitialised) Initialise ();
758
759 if (!fpSceneHandler) {
760 PrintInvalidPointers ();
761 return;
762 }
763
764 G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
765
766 if (!p) {
767 if (fVerbosity >= errors) {
768 G4cout << "ERROR in G4VisManager::CreateViewer during "
769 << fpGraphicsSystem -> GetName ()
770 << " viewer creation.\n No action taken."
771 << G4endl;
772 }
773 return;
774 }
775
776 if (p -> GetViewId() < 0) {
777 if (fVerbosity >= errors) {
778 G4cout << "ERROR in G4VisManager::CreateViewer during "
779 << fpGraphicsSystem -> GetName ()
780 << " viewer initialisation.\n No action taken."
781 << G4endl;
782 }
783 return;
784 }
785
786 // Viewer is created, now we can set geometry parameters
787 // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
788
789 G4ViewParameters initialvp = p -> GetViewParameters();
790 initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
791 p -> SetViewParameters(initialvp);
792 p -> Initialise (); // (Viewer itself may change view parameters further.)
793
794 fpViewer = p; // Make current.
795 fpSceneHandler -> AddViewerToList (fpViewer);
796 fpSceneHandler -> SetCurrentViewer (fpViewer);
797 if (fVerbosity >= confirmations) {
798 G4cout << "G4VisManager::CreateViewer: new viewer created."
799 << G4endl;
800 }
801
802 const G4ViewParameters& vp = fpViewer->GetViewParameters();
803 if (fVerbosity >= parameters) {
804 G4cout << " view parameters are:\n " << vp << G4endl;
805 }
806
807 if (vp.IsCulling () && vp.IsCullingInvisible ()) {
808 static G4bool warned = false;
809 if (fVerbosity >= confirmations) {
810 if (!warned) {
811 G4cout <<
812 "NOTE: objects with visibility flag set to \"false\""
813 " will not be drawn!"
814 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
815 "\n Also see other \"/vis/viewer/set\" commands."
816 << G4endl;
817 warned = true;
818 }
819 }
820 }
821 if (vp.IsCullingCovered ()) {
822 static G4bool warned = false;
823 if (fVerbosity >= warnings) {
824 if (!warned) {
825 G4cout <<
826 "WARNING: covered objects in solid mode will not be rendered!"
827 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
828 "\n Also see other \"/vis/viewer/set\" commands."
829 << G4endl;
830 warned = true;
831 }
832 }
833 }
834}
835
836void G4VisManager::GeometryHasChanged () {
837 if (fVerbosity >= confirmations) {
838 G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
839 }
840
841 // Change the world...
842 G4VPhysicalVolume* pWorld =
843 G4TransportationManager::GetTransportationManager ()
844 -> GetNavigatorForTracking () -> GetWorldVolume ();
845 if (!pWorld) {
846 if (fVerbosity >= warnings) {
847 G4cout << "WARNING: There is no world volume!" << G4endl;
848 }
849 }
850
851 // Check scenes.
852 G4SceneList& sceneList = fSceneList;
853 G4int iScene, nScenes = sceneList.size ();
854 for (iScene = 0; iScene < nScenes; iScene++) {
855 G4Scene* pScene = sceneList [iScene];
856 std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList ();
857
858 if (modelList.size ()) {
859 G4bool modelInvalid;
860 do { // Remove, if required, one at a time.
861 modelInvalid = false;
862 std::vector<G4VModel*>::iterator iterModel;
863 for (iterModel = modelList.begin();
864 iterModel != modelList.end();
865 ++iterModel) {
866 modelInvalid = !((*iterModel) -> Validate (fVerbosity >= warnings));
867 if (modelInvalid) {
868 // Model invalid - remove and break.
869 if (fVerbosity >= warnings) {
870 G4cout << "WARNING: Model \""
871 << (*iterModel) -> GetGlobalDescription ()
872 <<
873 "\" is no longer valid - being removed\n from scene \""
874 << pScene -> GetName () << "\""
875 << G4endl;
876 }
877 modelList.erase (iterModel);
878 break;
879 }
880 }
881 } while (modelInvalid);
882
883 if (modelList.size () == 0) {
884 if (fVerbosity >= warnings) {
885 G4cout << "WARNING: No models left in this scene \""
886 << pScene -> GetName ()
887 << "\"."
888 << G4endl;
889 }
890 }
891 else {
892 pScene->CalculateExtent();
893 G4UImanager::GetUIpointer () ->
894 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
895 }
896 }
897 }
898
899 // Check the manager's current scene...
900 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
901 if (fVerbosity >= warnings) {
902 G4cout << "WARNING: The current scene \""
903 << fpScene -> GetName ()
904 << "\" has no models."
905 << G4endl;
906 }
907 }
908
909}
910void G4VisManager::NotifyHandlers () {
911
912 if (fVerbosity >= confirmations) {
913 G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
914 }
915
916 // Check scenes.
917 G4SceneList& sceneList = fSceneList;
918 G4int iScene, nScenes = sceneList.size ();
919 for (iScene = 0; iScene < nScenes; iScene++) {
920 G4Scene* pScene = sceneList [iScene];
921 std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList ();
922
923 if (modelList.size ()) {
924 pScene->CalculateExtent();
925 G4UImanager::GetUIpointer () ->
926 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
927 }
928 }
929
930 // Check the manager's current scene...
931 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
932 if (fVerbosity >= warnings) {
933 G4cout << "WARNING: The current scene \""
934 << fpScene -> GetName ()
935 << "\" has no models."
936 << G4endl;
937 }
938 }
939
940}
941
942G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory)
943{
944 return fpTrajFilterMgr->Accept(trajectory);
945}
946
947G4bool G4VisManager::FilterHit(const G4VHit& hit)
948{
949 return fpHitFilterMgr->Accept(hit);
950}
951
952G4bool G4VisManager::FilterDigi(const G4VDigi& digi)
953{
954 return fpDigiFilterMgr->Accept(digi);
955}
956
957void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory)
958{
959 G4bool visible(true);
960
961 // See if trajectory passes filter
962 G4bool passed = FilterTrajectory(trajectory);
963
964 if (!passed) {
965 // Draw invisible trajectory if trajectory failed filter and
966 // are filtering in soft mode
967 if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
968 else {return;}
969 }
970
971 // Go on to draw trajectory
972 assert (0 != fpTrajDrawModelMgr);
973
974 const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
975
976 assert (0 != trajectoryModel); // Should exist
977
978 trajectoryModel->Draw(trajectory, visible);
979}
980
981void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode)
982{
983 G4bool visible(true);
984
985 // See if trajectory passes filter
986 G4bool passed = FilterTrajectory(trajectory);
987
988 if (!passed) {
989 // Draw invisible trajectory if trajectory failed filter and
990 // are filtering in soft mode
991 if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
992 else {return;}
993 }
994
995 // Go on to draw trajectory
996 assert (0 != fpTrajDrawModelMgr);
997
998 const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
999
1000 assert (0 != trajectoryModel); // Should exist
1001
1002 if (IsValidView()) {
1003 G4TrajectoriesModel* trajectoriesModel =
1004 dynamic_cast<G4TrajectoriesModel*>(fpSceneHandler->GetModel());
1005 if (trajectoriesModel) {
1006 if (trajectoriesModel->IsDrawingModeSet()) {
1007 trajectoryModel->Draw(trajectory, i_mode, visible);
1008 } else {
1009 trajectoryModel->Draw(trajectory, visible);
1010 }
1011 } else {
1012 // Just draw at user's request
1013 trajectoryModel->Draw(trajectory, i_mode, visible);
1014 }
1015 }
1016}
1017
1018void G4VisManager::SetUserAction
1019(G4VUserVisAction* pVisAction,
1020 const G4VisExtent& extent) {
1021 fpUserVisAction = pVisAction;
1022 fUserVisActionExtent = extent;
1023 if (extent.GetExtentRadius() <= 0.) {
1024 if (fVerbosity >= warnings) {
1025 G4cout <<
1026 "WARNING: No extent set for user vis action. (You may"
1027 "\n set it later when adding with /vis/scene/add/userAction.)"
1028 << G4endl;
1029 }
1030 }
1031}
1032
1033void G4VisManager::SetCurrentScene (G4Scene* pScene) {
1034 if (pScene != fpScene) {
1035 // A change of scene. Therefore reset transients drawn flags. All
1036 // memory of previous transient proceessing thereby erased...
1037 ResetTransientsDrawnFlags();
1038 }
1039 fpScene = pScene;
1040}
1041
1042void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
1043 fpGraphicsSystem = pSystem;
1044 if (fVerbosity >= confirmations) {
1045 G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
1046 << pSystem -> GetName () << G4endl;
1047 }
1048 // If current scene handler is of same graphics system, leave unchanged.
1049 // Else find the most recent scene handler of same graphics system.
1050 // Or clear pointers.
1051 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1052 const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
1053 G4int nSH = sceneHandlerList.size (); // No. of scene handlers.
1054 G4int iSH;
1055 for (iSH = nSH - 1; iSH >= 0; iSH--) {
1056 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
1057 }
1058 if (iSH >= 0) {
1059 fpSceneHandler = sceneHandlerList [iSH];
1060 if (fVerbosity >= confirmations) {
1061 G4cout << " Scene Handler now "
1062 << fpSceneHandler -> GetName () << G4endl;
1063 }
1064 if (fpScene != fpSceneHandler -> GetScene ()) {
1065 fpScene = fpSceneHandler -> GetScene ();
1066 if (fVerbosity >= confirmations) {
1067 G4cout << " Scene now \""
1068 << fpScene -> GetName () << "\"" << G4endl;
1069 }
1070 }
1071 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1072 if (viewerList.size ()) {
1073 fpViewer = viewerList [0];
1074 if (fVerbosity >= confirmations) {
1075 G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
1076 }
1077 }
1078 else {
1079 fpViewer = 0;
1080 }
1081 }
1082 else {
1083 fpSceneHandler = 0;
1084 fpViewer = 0;
1085 }
1086 }
1087}
1088
1089void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
1090 fpSceneHandler = pSceneHandler;
1091 if (fVerbosity >= confirmations) {
1092 G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
1093 << pSceneHandler -> GetName () << "\"" << G4endl;
1094 }
1095 if (fpScene != fpSceneHandler -> GetScene ()) {
1096 fpScene = fpSceneHandler -> GetScene ();
1097 if (fVerbosity >= confirmations) {
1098 G4cout << " Scene now \""
1099 << fpScene -> GetName () << "\"" << G4endl;
1100 }
1101 }
1102 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1103 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1104 if (fVerbosity >= confirmations) {
1105 G4cout << " Graphics system now \""
1106 << fpGraphicsSystem -> GetName () << "\"" << G4endl;
1107 }
1108 }
1109 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1110 G4int nViewers = viewerList.size ();
1111 if (nViewers) {
1112 G4int iViewer;
1113 for (iViewer = 0; iViewer < nViewers; iViewer++) {
1114 if (fpViewer == viewerList [iViewer]) break;
1115 }
1116 if (iViewer >= nViewers) {
1117 fpViewer = viewerList [0];
1118 if (fVerbosity >= confirmations) {
1119 G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
1120 << G4endl;
1121 }
1122 }
1123 if (!IsValidView ()) {
1124 if (fVerbosity >= warnings) {
1125 G4cout <<
1126 "WARNING: Problem setting scene handler - please report circumstances."
1127 << G4endl;
1128 }
1129 }
1130 }
1131 else {
1132 fpViewer = 0;
1133 if (fVerbosity >= warnings) {
1134 G4cout <<
1135 "WARNING: No viewers for this scene handler - please create one."
1136 << G4endl;
1137 }
1138 }
1139}
1140
1141void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
1142 fpViewer = pViewer;
1143 if (fVerbosity >= confirmations) {
1144 G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1145 << pViewer -> GetName ()
1146 << G4endl;
1147 }
1148 fpSceneHandler = fpViewer -> GetSceneHandler ();
1149 fpSceneHandler -> SetCurrentViewer (pViewer);
1150 fpScene = fpSceneHandler -> GetScene ();
1151 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1152 if (!IsValidView ()) {
1153 if (fVerbosity >= warnings) {
1154 G4cout <<
1155 "WARNING: Problem setting viewer - please report circumstances."
1156 << G4endl;
1157 }
1158 }
1159}
1160
1161void G4VisManager::RegisterMessengers () {
1162
1163 // Instantiate individual messengers/commands (often - but not
1164 // always - one command per messenger).
1165
1166 G4UIcommand* directory;
1167
1168 // Top level commands...
1169 RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
1170 RegisterMessenger(new G4VisCommandEnable);
1171 RegisterMessenger(new G4VisCommandList);
1172 RegisterMessenger(new G4VisCommandReviewKeptEvents);
1173
1174 // Compound commands...
1175 RegisterMessenger(new G4VisCommandDrawTree);
1176 RegisterMessenger(new G4VisCommandDrawView);
1177 RegisterMessenger(new G4VisCommandDrawVolume);
1178 RegisterMessenger(new G4VisCommandOpen);
1179 RegisterMessenger(new G4VisCommandSpecify);
1180
1181 directory = new G4UIdirectory ("/vis/geometry/");
1182 directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
1183 fDirectoryList.push_back (directory);
1184 RegisterMessenger(new G4VisCommandGeometryList);
1185 RegisterMessenger(new G4VisCommandGeometryRestore);
1186
1187 directory = new G4UIdirectory ("/vis/geometry/set/");
1188 directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
1189 fDirectoryList.push_back (directory);
1190 RegisterMessenger(new G4VisCommandGeometrySetColour);
1191 RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
1192 RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
1193 RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
1194 RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
1195 RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
1196 RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
1197 RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
1198 RegisterMessenger(new G4VisCommandGeometrySetVisibility);
1199
1200 directory = new G4UIdirectory ("/vis/scene/");
1201 directory -> SetGuidance ("Operations on Geant4 scenes.");
1202 fDirectoryList.push_back (directory);
1203 RegisterMessenger(new G4VisCommandSceneCreate);
1204 RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
1205 RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
1206 RegisterMessenger(new G4VisCommandSceneList);
1207 RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
1208 RegisterMessenger(new G4VisCommandSceneSelect);
1209
1210 directory = new G4UIdirectory ("/vis/scene/add/");
1211 directory -> SetGuidance ("Add model to current scene.");
1212 fDirectoryList.push_back (directory);
1213 RegisterMessenger(new G4VisCommandSceneAddAxes);
1214 RegisterMessenger(new G4VisCommandSceneAddEventID);
1215 RegisterMessenger(new G4VisCommandSceneAddGhosts);
1216 RegisterMessenger(new G4VisCommandSceneAddHits);
1217 RegisterMessenger(new G4VisCommandSceneAddDigis);
1218 RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
1219 RegisterMessenger(new G4VisCommandSceneAddLogo);
1220 RegisterMessenger(new G4VisCommandSceneAddPSHits);
1221 RegisterMessenger(new G4VisCommandSceneAddScale);
1222 RegisterMessenger(new G4VisCommandSceneAddText);
1223 RegisterMessenger(new G4VisCommandSceneAddTrajectories);
1224 RegisterMessenger(new G4VisCommandSceneAddUserAction);
1225 RegisterMessenger(new G4VisCommandSceneAddVolume);
1226
1227 directory = new G4UIdirectory ("/vis/sceneHandler/");
1228 directory -> SetGuidance ("Operations on Geant4 scene handlers.");
1229 fDirectoryList.push_back (directory);
1230 RegisterMessenger(new G4VisCommandSceneHandlerAttach);
1231 RegisterMessenger(new G4VisCommandSceneHandlerCreate);
1232 RegisterMessenger(new G4VisCommandSceneHandlerList);
1233 RegisterMessenger(new G4VisCommandSceneHandlerSelect);
1234
1235 directory = new G4UIdirectory ("/vis/viewer/");
1236 directory -> SetGuidance ("Operations on Geant4 viewers.");
1237 fDirectoryList.push_back (directory);
1238 RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
1239 RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
1240 RegisterMessenger(new G4VisCommandViewerClear);
1241 RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
1242 RegisterMessenger(new G4VisCommandViewerClearTransients);
1243 RegisterMessenger(new G4VisCommandViewerClone);
1244 RegisterMessenger(new G4VisCommandViewerCreate);
1245 RegisterMessenger(new G4VisCommandViewerDolly);
1246 RegisterMessenger(new G4VisCommandViewerFlush);
1247 RegisterMessenger(new G4VisCommandViewerList);
1248 RegisterMessenger(new G4VisCommandViewerPan);
1249 RegisterMessenger(new G4VisCommandViewerRebuild);
1250 RegisterMessenger(new G4VisCommandViewerRefresh);
1251 RegisterMessenger(new G4VisCommandViewerReset);
1252 RegisterMessenger(new G4VisCommandViewerScale);
1253 RegisterMessenger(new G4VisCommandViewerSelect);
1254 RegisterMessenger(new G4VisCommandViewerUpdate);
1255 RegisterMessenger(new G4VisCommandViewerZoom);
1256
1257 directory = new G4UIdirectory ("/vis/viewer/set/");
1258 directory -> SetGuidance ("Set view parameters of current viewer.");
1259 fDirectoryList.push_back (directory);
1260 RegisterMessenger(new G4VisCommandsViewerSet);
1261
1262 // List manager commands
1263 RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
1264 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1265 RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
1266 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1267
1268 // Trajectory filter manager commands
1269 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
1270 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1271 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
1272 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1273
1274 // Hit filter manager commands
1275 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
1276 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1277 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
1278 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1279
1280 // Digi filter manager commands
1281 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VDigi> >
1282 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
1283 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VDigi> >
1284 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
1285}
1286
1287void G4VisManager::PrintAvailableGraphicsSystems () const {
1288 G4int nSystems = fAvailableGraphicsSystems.size ();
1289 G4cout << "Current available graphics systems are:";
1290 if (nSystems) {
1291 for (int i = 0; i < nSystems; i++) {
1292 const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i];
1293 G4cout << "\n " << pSystem -> GetName ();
1294 if (pSystem -> GetNickname () != "") {
1295 G4cout << " (" << pSystem -> GetNickname () << ")";
1296 }
1297 }
1298 }
1299 else {
1300 G4cout << "\n NONE!!! None registered - yet! Mmmmm!";
1301 }
1302 G4cout << G4endl;
1303}
1304
1305void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1306{
1307 {
1308 //fpTrajDrawModelMgr->Print(G4cout);
1309 G4cout << "Registered model factories:" << G4endl;
1310 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1311 fpTrajDrawModelMgr->FactoryList();
1312 if (factoryList.empty()) G4cout << " None" << G4endl;
1313 else {
1314 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1315 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1316 (*i)->Print(G4cout);
1317 }
1318 const G4VisListManager<G4VTrajectoryModel>* listManager =
1319 fpTrajDrawModelMgr->ListManager();
1320 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1321 listManager->Map();
1322 if (!modelMap.empty()) {
1323 G4cout << "\nRegistered models:" << G4endl;
1324 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1325 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1326 G4cout << " " << i->second->Name();
1327 if (i->second == listManager->Current()) G4cout << " (Current)";
1328 G4cout << G4endl;
1329 if (verbosity >= parameters) i->second->Print(G4cout);
1330 }
1331 }
1332 }
1333
1334 G4cout << G4endl;
1335
1336 {
1337 //fpTrajFilterMgr->Print(G4cout);
1338 G4cout << "Registered filter factories:" << G4endl;
1339 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1340 factoryList = fpTrajFilterMgr->FactoryList();
1341 if (factoryList.empty()) G4cout << " None" << G4endl;
1342 else {
1343 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1344 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1345 (*i)->Print(G4cout);
1346 }
1347 const std::vector<G4VFilter<G4VTrajectory>*>&
1348 filterList = fpTrajFilterMgr->FilterList();
1349 if (!filterList.empty()) {
1350 G4cout << "\nRegistered filters:" << G4endl;
1351 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1352 for (i = filterList.begin(); i != filterList.end(); ++i) {
1353 G4cout << " " << (*i)->GetName() << G4endl;
1354 if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1355 }
1356 }
1357 }
1358}
1359
1360void G4VisManager::PrintInvalidPointers () const {
1361 if (fVerbosity >= errors) {
1362 G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
1363 if (!fpGraphicsSystem) {
1364 G4cout << "\n null graphics system pointer.";
1365 }
1366 else {
1367 G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1368 << " but:";
1369 if (!fpScene)
1370 G4cout <<
1371 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1372 " \"/vis/scene/create\".";
1373 if (!fpSceneHandler)
1374 G4cout <<
1375 "\n Null scene handler pointer. Use \"/vis/open\" or"
1376 " \"/vis/sceneHandler/create\".";
1377 if (!fpViewer )
1378 G4cout <<
1379 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1380 }
1381 G4cout << G4endl;
1382 }
1383}
1384
1385void G4VisManager::BeginOfRun ()
1386{
1387 //G4cout << "G4VisManager::BeginOfRun" << G4endl;
1388 fKeptLastEvent = false;
1389 fEventKeepingSuspended = false;
1390 fTransientsDrawnThisRun = false;
1391 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
1392}
1393
1394void G4VisManager::BeginOfEvent ()
1395{
1396 //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
1397 fTransientsDrawnThisEvent = false;
1398 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
1399}
1400
1401void G4VisManager::EndOfEvent ()
1402{
1403 //G4cout << "G4VisManager::EndOfEvent" << G4endl;
1404
1405 // Don't call IsValidView unless there is a scene handler. This
1406 // avoids WARNING message at end of event and run when the user has
1407 // not instantiated a scene handler, e.g., in batch mode.
1408 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1409 if (!valid) return;
1410
1411 G4RunManager* runManager = G4RunManager::GetRunManager();
1412 const G4Run* currentRun = runManager->GetCurrentRun();
1413
1414 G4EventManager* eventManager = G4EventManager::GetEventManager();
1415 const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1416 if (!currentEvent) return;
1417
1418 ClearTransientStoreIfMarked();
1419#ifdef G4DEBUG_VIS_MANAGEMENT
1420 printf("G4VisManager::EndOfEvent DrawEvent ---------------------\n");
1421#endif
1422 fpSceneHandler->DrawEvent(currentEvent);
1423
1424 G4int nEventsToBeProcessed = 0;
1425 G4int nKeptEvents = 0;
1426 G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
1427 if (currentRun) {
1428 nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
1429 eventID = currentEvent->GetEventID();
1430 const std::vector<const G4Event*>* events =
1431 currentRun->GetEventVector();
1432 if (events) nKeptEvents = events->size();
1433 }
1434
1435 if (fpScene->GetRefreshAtEndOfEvent()) {
1436
1437 // Unless last event (in which case wait end of run)...
1438 if (eventID < nEventsToBeProcessed - 1) {
1439 fpViewer->ShowView();
1440 fpViewer->DrawView();
1441 fpSceneHandler->SetMarkForClearingTransientStore(true);
1442 } else { // Last event...
1443 // Keep, but only if user has not kept any...
1444 if (!nKeptEvents) {
1445 eventManager->KeepTheCurrentEvent();
1446 fKeptLastEvent = true;
1447 }
1448 }
1449
1450 } else { // Accumulating events...
1451
1452 G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1453 if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) {
1454 fEventKeepingSuspended = true;
1455 static G4bool warned = false;
1456 if (!warned) {
1457 if (fVerbosity >= warnings) {
1458 G4cout <<
1459 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1460 "\n The number of events exceeds the maximum, "
1461 << maxNumberOfKeptEvents <<
1462 ", that can be kept by the vis manager."
1463 << G4endl;
1464 }
1465 warned = true;
1466 }
1467 } else if (maxNumberOfKeptEvents != 0) {
1468 eventManager->KeepTheCurrentEvent();
1469 }
1470 }
1471}
1472
1473void G4VisManager::EndOfRun ()
1474{
1475 //G4cout << "G4VisManager::EndOfRun" << G4endl;
1476
1477 // Don't call IsValidView unless there is a scene handler. This
1478 // avoids WARNING message at end of event and run when the user has
1479 // not instantiated a scene handler, e.g., in batch mode.
1480 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1481 if (valid) {
1482 if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
1483 if (fpScene->GetRefreshAtEndOfRun()) {
1484 fpSceneHandler->DrawEndOfRunModels();
1485 fpViewer->ShowView();
1486 fpSceneHandler->SetMarkForClearingTransientStore(true);
1487 }
1488 }
1489
1490 if (fEventKeepingSuspended && fVerbosity >= warnings) {
1491 G4cout <<
1492 "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended."
1493 "\n The number of events in the run exceeded the maximum, "
1494 << fpScene->GetMaxNumberOfKeptEvents() <<
1495 ", that can be kept by the vis manager." <<
1496 "\n The number of events kept by the vis manager can be changed with"
1497 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1498 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1499 << G4endl;
1500 }
1501 }
1502 fEventRefreshing = false;
1503
1504 G4RunManager* runManager = G4RunManager::GetRunManager();
1505 const G4Run* currentRun = runManager->GetCurrentRun();
1506
1507 G4int nKeptEvents = 0;
1508 const std::vector<const G4Event*>* events =
1509 currentRun? currentRun->GetEventVector(): 0;
1510 if (events) nKeptEvents = events->size();
1511
1512 if (nKeptEvents && !fKeptLastEvent) {
1513 if (!valid && fVerbosity >= warnings) G4cout << "WARNING: ";
1514 if (fVerbosity >= warnings) {
1515 G4cout << nKeptEvents;
1516 if (nKeptEvents == 1) G4cout << " event has";
1517 else G4cout << " events have";
1518 G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1519 }
1520 static G4bool warned = false;
1521 if (!valid && fVerbosity >= warnings && !warned) {
1522 G4cout <<
1523 " Only useful if before starting the run:"
1524 "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
1525 "\n b) the Draw method of any hits or digis is implemented."
1526 "\n To view trajectories, hits or digis:"
1527 "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
1528 "\n \"/vis/scene/add/hits\" or \"/vis/scene/add/digitisations\""
1529 "\n and, possibly, \"/vis/viewer/flush\"."
1530 "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"."
1531 "\n To see events individually: \"/vis/reviewKeptEvents\"."
1532 << G4endl;
1533 warned = true;
1534 }
1535 }
1536}
1537
1538void G4VisManager::ClearTransientStoreIfMarked(){
1539 // Assumes valid view.
1540 if (fpSceneHandler->GetMarkForClearingTransientStore()) {
1541 fpSceneHandler->SetMarkForClearingTransientStore(false);
1542 fpSceneHandler->ClearTransientStore();
1543 }
1544 // Record if transients drawn. These local flags are only set
1545 // *after* ClearTransientStore. In the code in G4VSceneHandler
1546 // triggered by ClearTransientStore, use these flags so that
1547 // event refreshing is not done too early.
1548 fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
1549 fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
1550}
1551
1552void G4VisManager::ResetTransientsDrawnFlags()
1553{
1554 fTransientsDrawnThisRun = false;
1555 fTransientsDrawnThisEvent = false;
1556 G4SceneHandlerListConstIterator i;
1557 for (i = fAvailableSceneHandlers.begin();
1558 i != fAvailableSceneHandlers.end(); ++i) {
1559 (*i)->SetTransientsDrawnThisEvent(false);
1560 (*i)->SetTransientsDrawnThisRun(false);
1561 }
1562}
1563
1564G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
1565 G4String viewerShortName (viewerName);
1566 viewerShortName = viewerShortName (0, viewerShortName.find (' '));
1567 return viewerShortName.strip ();
1568}
1569
1570G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
1571 G4String viewerShortName = ViewerShortName (viewerName);
1572 size_t nHandlers = fAvailableSceneHandlers.size ();
1573 size_t iHandler, iViewer;
1574 G4VViewer* viewer = 0;
1575 G4bool found = false;
1576 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1577 G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
1578 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1579 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1580 viewer = viewerList [iViewer];
1581 if (viewerShortName == viewer -> GetShortName ()) {
1582 found = true;
1583 break;
1584 }
1585 }
1586 if (found) break;
1587 }
1588 if (found) return viewer;
1589 else return 0;
1590}
1591
1592std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
1593
1594G4String G4VisManager::VerbosityString(Verbosity verbosity) {
1595 G4String s;
1596 switch (verbosity) {
1597 case quiet: s = "quiet (0)"; break;
1598 case startup: s = "startup (1)"; break;
1599 case errors: s = "errors (2)"; break;
1600 case warnings: s = "warnings (3)"; break;
1601 case confirmations: s = "confirmations (4)"; break;
1602 case parameters: s = "parameters (5)"; break;
1603 case all: s = "all (6)"; break;
1604 }
1605 return s;
1606}
1607
1608G4VisManager::Verbosity
1609G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
1610 G4String s(verbosityString); s.toLower();
1611 Verbosity verbosity;
1612 if (s(0) == 'q') verbosity = quiet;
1613 else if (s(0) == 's') verbosity = startup;
1614 else if (s(0) == 'e') verbosity = errors;
1615 else if (s(0) == 'w') verbosity = warnings;
1616 else if (s(0) == 'c') verbosity = confirmations;
1617 else if (s(0) == 'p') verbosity = parameters;
1618 else if (s(0) == 'a') verbosity = all;
1619 else {
1620 G4int intVerbosity;
1621 std::istringstream is(s);
1622 is >> intVerbosity;
1623 if (!is) {
1624 G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
1625 << verbosityString << "\"";
1626 for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
1627 G4cout << '\n' << VerbosityGuidanceStrings[i];
1628 }
1629 verbosity = warnings;
1630 G4cout << "\n Returning " << VerbosityString(verbosity)
1631 << G4endl;
1632 }
1633 else {
1634 verbosity = GetVerbosityValue(intVerbosity);
1635 }
1636 }
1637 return verbosity;
1638}
1639
1640G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
1641 Verbosity verbosity;
1642 if (intVerbosity < quiet) verbosity = quiet;
1643 else if (intVerbosity > all) verbosity = all;
1644 else verbosity = Verbosity(intVerbosity);
1645 return verbosity;
1646}
1647
1648G4VisManager::Verbosity G4VisManager::GetVerbosity () {
1649 return fVerbosity;
1650}
1651
1652void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
1653 fVerbosity = GetVerbosityValue(intVerbosity);
1654}
1655
1656void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
1657 fVerbosity = GetVerbosityValue(verbosityString);
1658}
1659
1660G4bool G4VisManager::IsValidView () {
1661
1662 if (!fInitialised) Initialise ();
1663
1664 static G4bool noGSPrinting = true;
1665 if (!fpGraphicsSystem) {
1666 // Limit printing - we do not want printing if the user simply does
1667 // not want to use graphics, e.g., in batch mode.
1668 if (noGSPrinting) {
1669 noGSPrinting = false;
1670 if (fVerbosity >= warnings) {
1671 G4cout <<
1672 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
1673 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
1674 "\n Alternatively, to avoid this message, suppress instantiation of vis"
1675 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
1676 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
1677 "\n is non-zero."
1678 << G4endl;
1679 }
1680 }
1681 return false;
1682 }
1683
1684 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
1685 if (fVerbosity >= errors) {
1686 G4cout <<
1687 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
1688 << G4endl;
1689 PrintInvalidPointers ();
1690 }
1691 return false;
1692 }
1693
1694 if (fpScene != fpSceneHandler -> GetScene ()) {
1695 if (fVerbosity >= errors) {
1696 G4cout << "ERROR: G4VisManager::IsValidView ():";
1697 if (fpSceneHandler -> GetScene ()) {
1698 G4cout <<
1699 "\n The current scene \""
1700 << fpScene -> GetName ()
1701 << "\" is not handled by"
1702 "\n the current scene handler \""
1703 << fpSceneHandler -> GetName ()
1704 << "\""
1705 "\n (it currently handles scene \""
1706 << fpSceneHandler -> GetScene () -> GetName ()
1707 << "\")."
1708 "\n Either:"
1709 "\n (a) attach it to the scene handler with"
1710 "\n /vis/sceneHandler/attach "
1711 << fpScene -> GetName ()
1712 << ", or"
1713 "\n (b) create a new scene handler with "
1714 "\n /vis/sceneHandler/create <graphics-system>,"
1715 "\n in which case it should pick up the the new scene."
1716 << G4endl;
1717 }
1718 else {
1719 G4cout << "\n Scene handler \""
1720 << fpSceneHandler -> GetName ()
1721 << "\" has null scene pointer."
1722 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
1723 << G4endl;
1724 }
1725 }
1726 return false;
1727 }
1728
1729 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1730 if (viewerList.size () == 0) {
1731 if (fVerbosity >= errors) {
1732 G4cout <<
1733 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
1734 << fpSceneHandler -> GetName ()
1735 << "\" has no viewers. Do /vis/viewer/create."
1736 << G4endl;
1737 }
1738 return false;
1739 }
1740
1741 G4bool isValid = true;
1742 if (fpScene -> IsEmpty ()) { // Add world by default if possible...
1743 G4bool warn(fVerbosity >= warnings);
1744 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
1745 if (!successful || fpScene -> IsEmpty ()) { // If still empty...
1746 if (fVerbosity >= errors) {
1747 G4cout << "ERROR: G4VisManager::IsViewValid ():";
1748 G4cout <<
1749 "\n Attempt at some drawing operation when scene is empty."
1750 "\n Maybe the geometry has not yet been defined."
1751 " Try /run/initialize."
1752 << G4endl;
1753 }
1754 isValid = false;
1755 }
1756 else {
1757 G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
1758 if (fVerbosity >= warnings) {
1759 G4cout <<
1760 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
1761 "\n added and the scene handlers notified.";
1762 G4cout << G4endl;
1763 }
1764 }
1765 }
1766 if (isValid) SetConcreteInstance(this);
1767 return isValid;
1768}
1769
1770void
1771G4VisManager::RegisterModelFactories()
1772{
1773 if (fVerbosity >= warnings) {
1774 G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
1775 G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
1776 G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
1777 }
1778}
Note: See TracBrowser for help on using the repository browser.