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

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

rien, juste un maj des tags

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