source: trunk/geant4/visualization/management/src/G4VisManager.cc@ 630

Last change on this file since 630 was 610, checked in by garnier, 18 years ago

r661@mac-90108: laurentgarnier | 2007-11-22 18:10:43 +0100
en debug

  • Property svn:mime-type set to text/cpp
File size: 49.4 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.114 2007/11/10 14:59:46 allison 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 G4Text& text)
508{
509 if (IsValidView()) {
510 ClearTransientStoreIfMarked();
511 fpSceneHandler -> BeginPrimitives2D();
512 fpSceneHandler -> AddPrimitive(text);
513 fpSceneHandler -> EndPrimitives2D();
514 }
515}
516
517void G4VisManager::Draw (const G4VHit& hit) {
518 if (IsValidView ()) {
519 ClearTransientStoreIfMarked();
520 fpSceneHandler -> AddCompound (hit);
521 }
522}
523
524void G4VisManager::Draw (const G4VTrajectory& traj,
525 G4int i_mode) {
526 if (IsValidView ()) {
527 ClearTransientStoreIfMarked();
528 fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
529 dummyTrajectoriesModel.SetDrawingMode(i_mode);
530 fpSceneHandler -> AddCompound (traj);
531 }
532}
533
534void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
535 const G4VisAttributes& attribs,
536 const G4Transform3D& objectTransform) {
537 // Find corresponding solid.
538 G4VSolid* pSol = logicalVol.GetSolid ();
539 Draw (*pSol, attribs, objectTransform);
540}
541
542void G4VisManager::Draw (const G4VSolid& solid,
543 const G4VisAttributes& attribs,
544 const G4Transform3D& objectTransform) {
545 if (IsValidView ()) {
546 ClearTransientStoreIfMarked();
547 fpSceneHandler -> PreAddSolid (objectTransform, attribs);
548 solid.DescribeYourselfTo (*fpSceneHandler);
549 fpSceneHandler -> PostAddSolid ();
550 }
551}
552
553void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
554 const G4VisAttributes& attribs,
555 const G4Transform3D& objectTransform) {
556 // Find corresponding logical volume and solid.
557 G4LogicalVolume* pLV = physicalVol.GetLogicalVolume ();
558 G4VSolid* pSol = pLV -> GetSolid ();
559 Draw (*pSol, attribs, objectTransform);
560}
561
562void G4VisManager::CreateSceneHandler (G4String name) {
563 printf("G4VisManager::Initialise OK\n");
564 if (!fInitialised) Initialise ();
565 printf("G4VisManager::Initialise OK END\n");
566 if (fpGraphicsSystem) {
567 G4VSceneHandler* pSceneHandler =
568 fpGraphicsSystem -> CreateSceneHandler (name);
569 if (pSceneHandler) {
570 fAvailableSceneHandlers.push_back (pSceneHandler);
571 fpSceneHandler = pSceneHandler; // Make current.
572 }
573 else {
574 if(fVerbosity >= errors) {
575 G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
576 << fpGraphicsSystem -> GetName ()
577 << " scene creation.\n No action taken."
578 << G4endl;
579 }
580 }
581 }
582 else PrintInvalidPointers ();
583}
584
585void G4VisManager::CreateViewer (G4String name) {
586
587 printf("G4VisManager::Initialise OK\n");
588 if (!fInitialised) Initialise ();
589
590 if (fpSceneHandler)
591 printf("G4VisManager::CreateViewer OK\n");
592 else
593 printf("G4VisManager::CreateViewer NO SCENE HANDLER\n");
594
595 if (fpSceneHandler) {
596 G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
597 if (!p) {
598 if (fVerbosity >= errors) {
599 G4cout << "ERROR in G4VisManager::CreateViewer during "
600 << fpGraphicsSystem -> GetName ()
601 << " viewer creation.\n No action taken."
602 << G4endl;
603 }
604 } else {
605 p -> Initialise ();
606 if (p -> GetViewId() < 0) {
607 if (fVerbosity >= errors) {
608 G4cout << "ERROR in G4VisManager::CreateViewer during "
609 << fpGraphicsSystem -> GetName ()
610 << " viewer initialisation.\n No action taken."
611 << G4endl;
612 }
613 } else {
614 fpViewer = p; // Make current.
615 fpSceneHandler -> AddViewerToList (fpViewer);
616 fpSceneHandler -> SetCurrentViewer (fpViewer);
617
618 if (fVerbosity >= confirmations) {
619 G4cout << "G4VisManager::CreateViewer: new viewer created."
620 << G4endl;
621 }
622
623 const G4ViewParameters& vp = fpViewer->GetViewParameters();
624 if (fVerbosity >= parameters) {
625 G4cout << " view parameters are:\n " << vp << G4endl;
626 }
627
628 if (vp.IsCulling () && vp.IsCullingInvisible ()) {
629 static G4bool warned = false;
630 if (fVerbosity >= confirmations) {
631 if (!warned) {
632 G4cout <<
633 "NOTE: objects with visibility flag set to \"false\""
634 " will not be drawn!"
635 "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
636 "\n Also see other \"/vis/viewer/set\" commands."
637 << G4endl;
638 warned = true;
639 }
640 }
641 }
642 if (vp.IsCullingCovered ()) {
643 static G4bool warned = false;
644 if (fVerbosity >= warnings) {
645 if (!warned) {
646 G4cout <<
647 "WARNING: covered objects in solid mode will not be rendered!"
648 "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
649 "\n Also see other \"/vis/viewer/set\" commands."
650 << G4endl;
651 warned = true;
652 }
653 }
654 }
655 }
656 }
657 }
658 else PrintInvalidPointers ();
659}
660
661void G4VisManager::GeometryHasChanged () {
662 if (fVerbosity >= confirmations) {
663 G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
664 }
665
666 // Change the world...
667 G4VPhysicalVolume* pWorld =
668 G4TransportationManager::GetTransportationManager ()
669 -> GetNavigatorForTracking () -> GetWorldVolume ();
670 if (!pWorld) {
671 if (fVerbosity >= warnings) {
672 G4cout << "WARNING: There is no world volume!" << G4endl;
673 }
674 }
675
676 // Check scenes.
677 G4SceneList& sceneList = fSceneList;
678 G4int iScene, nScenes = sceneList.size ();
679 for (iScene = 0; iScene < nScenes; iScene++) {
680 G4Scene* pScene = sceneList [iScene];
681 std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList ();
682
683 if (modelList.size ()) {
684 G4bool modelInvalid;
685 do { // Remove, if required, one at a time.
686 modelInvalid = false;
687 std::vector<G4VModel*>::iterator iterModel;
688 for (iterModel = modelList.begin();
689 iterModel != modelList.end();
690 ++iterModel) {
691 modelInvalid = !((*iterModel) -> Validate (fVerbosity >= warnings));
692 if (modelInvalid) {
693 // Model invalid - remove and break.
694 if (fVerbosity >= warnings) {
695 G4cout << "WARNING: Model \""
696 << (*iterModel) -> GetGlobalDescription ()
697 <<
698 "\" is no longer valid - being removed\n from scene \""
699 << pScene -> GetName () << "\""
700 << G4endl;
701 }
702 modelList.erase (iterModel);
703 break;
704 }
705 }
706 } while (modelInvalid);
707
708 if (modelList.size () == 0) {
709 if (fVerbosity >= warnings) {
710 G4cout << "WARNING: No models left in this scene \""
711 << pScene -> GetName ()
712 << "\"."
713 << G4endl;
714 }
715 }
716 else {
717 pScene->CalculateExtent();
718 G4UImanager::GetUIpointer () ->
719 ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
720 }
721 }
722 }
723
724 // Check the manager's current scene...
725 if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
726 if (fVerbosity >= warnings) {
727 G4cout << "WARNING: The current scene \""
728 << fpScene -> GetName ()
729 << "\" has no models."
730 << G4endl;
731 }
732 }
733
734}
735
736G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory)
737{
738 return fpTrajFilterMgr->Accept(trajectory);
739}
740
741G4bool G4VisManager::FilterHit(const G4VHit& hit)
742{
743 return fpHitFilterMgr->Accept(hit);
744}
745
746void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode)
747{
748 G4bool visible(true);
749
750 // See if trajectory passes filter
751 G4bool passed = FilterTrajectory(trajectory);
752
753 if (!passed) {
754 // Draw invisible trajectory if trajectory failed filter and
755 // are filtering in soft mode
756 if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
757 else {return;}
758 }
759
760 // Go on to draw trajectory
761 assert (0 != fpTrajDrawModelMgr);
762
763 const G4VTrajectoryModel* model = CurrentTrajDrawModel();
764
765 assert (0 != model); // Should exist
766
767 model->Draw(trajectory, i_mode, visible);
768}
769
770void G4VisManager::SetUserAction
771(G4VUserVisAction* pVisAction,
772 const G4VisExtent& extent) {
773 fpUserVisAction = pVisAction;
774 fUserVisActionExtent = extent;
775 if (extent.GetExtentRadius() <= 0.) {
776 if (fVerbosity >= warnings) {
777 G4cout <<
778 "WARNING: No extent set for user vis action. (You may"
779 "\n set it later when adding with /vis/scene/add/userAction.)"
780 << G4endl;
781 }
782 }
783}
784
785void G4VisManager::SetCurrentScene (G4Scene* pScene) {
786 if (pScene != fpScene) {
787 // A change of scene. Therefore reset transients drawn flags. All
788 // memory of previous transient proceessing thereby erased...
789 ResetTransientsDrawnFlags();
790 }
791 fpScene = pScene;
792}
793
794void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
795 fpGraphicsSystem = pSystem;
796 if (fVerbosity >= confirmations) {
797 G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
798 << pSystem -> GetName () << G4endl;
799 }
800 // If current scene handler is of same graphics system, leave unchanged.
801 // Else find the most recent scene handler of same graphics system.
802 // Or clear pointers.
803 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
804 const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
805 G4int nSH = sceneHandlerList.size (); // No. of scene handlers.
806 G4int iSH;
807 for (iSH = nSH - 1; iSH >= 0; iSH--) {
808 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
809 }
810 if (iSH >= 0) {
811 fpSceneHandler = sceneHandlerList [iSH];
812 if (fVerbosity >= confirmations) {
813 G4cout << " Scene Handler now "
814 << fpSceneHandler -> GetName () << G4endl;
815 }
816 if (fpScene != fpSceneHandler -> GetScene ()) {
817 fpScene = fpSceneHandler -> GetScene ();
818 if (fVerbosity >= confirmations) {
819 G4cout << " Scene now \""
820 << fpScene -> GetName () << "\"" << G4endl;
821 }
822 }
823 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
824 if (viewerList.size ()) {
825 fpViewer = viewerList [0];
826 if (fVerbosity >= confirmations) {
827 G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
828 }
829 }
830 else {
831 fpViewer = 0;
832 }
833 }
834 else {
835 fpSceneHandler = 0;
836 fpViewer = 0;
837 }
838 }
839}
840
841void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
842 fpSceneHandler = pSceneHandler;
843 if (fVerbosity >= confirmations) {
844 G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
845 << pSceneHandler -> GetName () << "\"" << G4endl;
846 }
847 if (fpScene != fpSceneHandler -> GetScene ()) {
848 fpScene = fpSceneHandler -> GetScene ();
849 if (fVerbosity >= confirmations) {
850 G4cout << " Scene now \""
851 << fpScene -> GetName () << "\"" << G4endl;
852 }
853 }
854 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
855 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
856 if (fVerbosity >= confirmations) {
857 G4cout << " Graphics system now \""
858 << fpGraphicsSystem -> GetName () << "\"" << G4endl;
859 }
860 }
861 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
862 G4int nViewers = viewerList.size ();
863 if (nViewers) {
864 G4int iViewer;
865 for (iViewer = 0; iViewer < nViewers; iViewer++) {
866 if (fpViewer == viewerList [iViewer]) break;
867 }
868 if (iViewer >= nViewers) {
869 fpViewer = viewerList [0];
870 if (fVerbosity >= confirmations) {
871 G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
872 << G4endl;
873 }
874 }
875 IsValidView (); // Checks.
876 }
877 else {
878 fpViewer = 0;
879 if (fVerbosity >= warnings) {
880 G4cout <<
881 "WARNING: No viewers for this scene handler - please create one."
882 << G4endl;
883 }
884 }
885}
886
887void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
888 fpViewer = pViewer;
889 if (fVerbosity >= confirmations) {
890 G4cout << "G4VisManager::SetCurrentViewer: viewer now "
891 << pViewer -> GetName ()
892 << G4endl;
893 }
894 fpSceneHandler = fpViewer -> GetSceneHandler ();
895 fpSceneHandler -> SetCurrentViewer (pViewer);
896 fpScene = fpSceneHandler -> GetScene ();
897 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
898 IsValidView (); // Checks.
899}
900
901void G4VisManager::RegisterMessengers () {
902
903 // Instantiate individual messengers/commands (often - but not
904 // always - one command per messenger).
905
906 G4VVisCommand::SetVisManager (this); // Sets shared pointer to vis manager.
907
908 G4UIcommand* directory;
909
910 // Top level basic commands...
911 RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
912 RegisterMessenger(new G4VisCommandEnable);
913 RegisterMessenger(new G4VisCommandList);
914 RegisterMessenger(new G4VisCommandVerbose);
915
916 // Other top level commands...
917 RegisterMessenger(new G4VisCommandReviewKeptEvents);
918
919 // Compound commands...
920 RegisterMessenger(new G4VisCommandDrawTree);
921 RegisterMessenger(new G4VisCommandDrawView);
922 RegisterMessenger(new G4VisCommandDrawVolume);
923 RegisterMessenger(new G4VisCommandOpen);
924 RegisterMessenger(new G4VisCommandSpecify);
925
926 directory = new G4UIdirectory ("/vis/geometry/");
927 directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
928 fDirectoryList.push_back (directory);
929 RegisterMessenger(new G4VisCommandGeometryList);
930 RegisterMessenger(new G4VisCommandGeometryRestore);
931
932 directory = new G4UIdirectory ("/vis/geometry/set/");
933 directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
934 fDirectoryList.push_back (directory);
935 RegisterMessenger(new G4VisCommandGeometrySetColour);
936 RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
937 RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
938 RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
939 RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
940 RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
941 RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
942 RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
943 RegisterMessenger(new G4VisCommandGeometrySetVisibility);
944
945 directory = new G4UIdirectory ("/vis/scene/");
946 directory -> SetGuidance ("Operations on Geant4 scenes.");
947 fDirectoryList.push_back (directory);
948 RegisterMessenger(new G4VisCommandSceneCreate);
949 RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
950 RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
951 RegisterMessenger(new G4VisCommandSceneList);
952 RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
953 RegisterMessenger(new G4VisCommandSceneSelect);
954
955 directory = new G4UIdirectory ("/vis/scene/add/");
956 directory -> SetGuidance ("Add model to current scene.");
957 fDirectoryList.push_back (directory);
958 RegisterMessenger(new G4VisCommandSceneAddAxes);
959 RegisterMessenger(new G4VisCommandSceneAddEventID);
960 RegisterMessenger(new G4VisCommandSceneAddGhosts);
961 RegisterMessenger(new G4VisCommandSceneAddHits);
962 RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
963 RegisterMessenger(new G4VisCommandSceneAddLogo);
964 RegisterMessenger(new G4VisCommandSceneAddScale);
965 RegisterMessenger(new G4VisCommandSceneAddText);
966 RegisterMessenger(new G4VisCommandSceneAddTrajectories);
967 RegisterMessenger(new G4VisCommandSceneAddUserAction);
968 RegisterMessenger(new G4VisCommandSceneAddVolume);
969
970 directory = new G4UIdirectory ("/vis/sceneHandler/");
971 directory -> SetGuidance ("Operations on Geant4 scene handlers.");
972 fDirectoryList.push_back (directory);
973 RegisterMessenger(new G4VisCommandSceneHandlerAttach);
974 RegisterMessenger(new G4VisCommandSceneHandlerCreate);
975 RegisterMessenger(new G4VisCommandSceneHandlerList);
976 RegisterMessenger(new G4VisCommandSceneHandlerSelect);
977
978 directory = new G4UIdirectory ("/vis/viewer/");
979 directory -> SetGuidance ("Operations on Geant4 viewers.");
980 fDirectoryList.push_back (directory);
981 RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
982 RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
983 RegisterMessenger(new G4VisCommandViewerClear);
984 RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
985 RegisterMessenger(new G4VisCommandViewerClearTransients);
986 RegisterMessenger(new G4VisCommandViewerClone);
987 RegisterMessenger(new G4VisCommandViewerCreate);
988 RegisterMessenger(new G4VisCommandViewerDolly);
989 RegisterMessenger(new G4VisCommandViewerFlush);
990 RegisterMessenger(new G4VisCommandViewerList);
991 RegisterMessenger(new G4VisCommandViewerPan);
992 RegisterMessenger(new G4VisCommandViewerRebuild);
993 RegisterMessenger(new G4VisCommandViewerRefresh);
994 RegisterMessenger(new G4VisCommandViewerReset);
995 RegisterMessenger(new G4VisCommandViewerScale);
996 RegisterMessenger(new G4VisCommandViewerSelect);
997 RegisterMessenger(new G4VisCommandViewerUpdate);
998 RegisterMessenger(new G4VisCommandViewerZoom);
999
1000 directory = new G4UIdirectory ("/vis/viewer/set/");
1001 directory -> SetGuidance ("Set view parameters of current viewer.");
1002 fDirectoryList.push_back (directory);
1003 RegisterMessenger(new G4VisCommandsViewerSet);
1004
1005 // List manager commands
1006 RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
1007 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1008 RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
1009 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1010
1011 // Trajectory filter manager commands
1012 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
1013 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1014 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
1015 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1016
1017 // Hit filter manager commands
1018 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
1019 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1020 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
1021 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1022}
1023
1024void G4VisManager::PrintAvailableGraphicsSystems () const {
1025 G4int nSystems = fAvailableGraphicsSystems.size ();
1026 G4cout << "Current available graphics systems are:";
1027 if (nSystems) {
1028 for (int i = 0; i < nSystems; i++) {
1029 const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i];
1030 G4cout << "\n " << pSystem -> GetName ();
1031 if (pSystem -> GetNickname () != "") {
1032 G4cout << " (" << pSystem -> GetNickname () << ")";
1033 }
1034 }
1035 }
1036 else {
1037 G4cout << "\n NONE!!! None registered - yet! Mmmmm!";
1038 }
1039 G4cout << G4endl;
1040}
1041
1042void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1043{
1044 {
1045 //fpTrajDrawModelMgr->Print(G4cout);
1046 G4cout << "Registered model factories:" << G4endl;
1047 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1048 fpTrajDrawModelMgr->FactoryList();
1049 if (factoryList.empty()) G4cout << " None" << G4endl;
1050 else {
1051 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1052 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1053 (*i)->Print(G4cout);
1054 }
1055 const G4VisListManager<G4VTrajectoryModel>* listManager =
1056 fpTrajDrawModelMgr->ListManager();
1057 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1058 listManager->Map();
1059 if (!modelMap.empty()) {
1060 G4cout << "\nRegistered models:" << G4endl;
1061 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1062 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1063 G4cout << " " << i->second->Name();
1064 if (i->second == listManager->Current()) G4cout << " (Current)";
1065 G4cout << G4endl;
1066 if (verbosity >= parameters) i->second->Print(G4cout);
1067 }
1068 }
1069 }
1070
1071 G4cout << G4endl;
1072
1073 {
1074 //fpTrajFilterMgr->Print(G4cout);
1075 G4cout << "Registered filter factories:" << G4endl;
1076 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1077 factoryList = fpTrajFilterMgr->FactoryList();
1078 if (factoryList.empty()) G4cout << " None" << G4endl;
1079 else {
1080 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1081 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1082 (*i)->Print(G4cout);
1083 }
1084 const std::vector<G4VFilter<G4VTrajectory>*>&
1085 filterList = fpTrajFilterMgr->FilterList();
1086 if (!filterList.empty()) {
1087 G4cout << "\nRegistered filters:" << G4endl;
1088 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1089 for (i = filterList.begin(); i != filterList.end(); ++i) {
1090 G4cout << " " << (*i)->GetName() << G4endl;
1091 if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1092 }
1093 }
1094 }
1095}
1096
1097void G4VisManager::PrintInvalidPointers () const {
1098 if (fVerbosity >= errors) {
1099 G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
1100 if (!fpGraphicsSystem) {
1101 G4cout << "\n null graphics system pointer.";
1102 }
1103 else {
1104 G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1105 << " but:";
1106 if (!fpScene)
1107 G4cout <<
1108 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1109 " \"/vis/scene/create\".";
1110 if (!fpSceneHandler)
1111 G4cout <<
1112 "\n Null scene handler pointer. Use \"/vis/open\" or"
1113 " \"/vis/sceneHandler/create\".";
1114 if (!fpViewer )
1115 G4cout <<
1116 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1117 }
1118 G4cout << G4endl;
1119 }
1120}
1121
1122void G4VisManager::BeginOfRun ()
1123{
1124 //G4cout << "G4VisManager::BeginOfRun" << G4endl;
1125 fKeptLastEvent = false;
1126 fEventKeepingSuspended = false;
1127 fTransientsDrawnThisRun = false;
1128 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
1129}
1130
1131void G4VisManager::BeginOfEvent ()
1132{
1133 //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
1134 fTransientsDrawnThisEvent = false;
1135 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
1136}
1137
1138void G4VisManager::EndOfEvent ()
1139{
1140 //G4cout << "G4VisManager::EndOfEvent" << G4endl;
1141
1142 // Don't call IsValidView unless there is a scene handler. This
1143 // avoids WARNING message at end of event and run when the user has
1144 // not instantiated a scene handler, e.g., in batch mode.
1145 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1146 if (!valid) return;
1147
1148 G4RunManager* runManager = G4RunManager::GetRunManager();
1149 const G4Run* currentRun = runManager->GetCurrentRun();
1150
1151 G4EventManager* eventManager = G4EventManager::GetEventManager();
1152 const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1153 if (!currentEvent) return;
1154
1155 ClearTransientStoreIfMarked();
1156 fpSceneHandler->DrawEvent(currentEvent);
1157
1158 G4int nEventsToBeProcessed = 0;
1159 G4int nKeptEvents = 0;
1160 G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
1161 if (currentRun) {
1162 nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
1163 eventID = currentEvent->GetEventID();
1164 const std::vector<const G4Event*>* events =
1165 currentRun->GetEventVector();
1166 if (events) nKeptEvents = events->size();
1167 }
1168
1169 if (fpScene->GetRefreshAtEndOfEvent()) {
1170
1171 // Unless last event (in which case wait end of run)...
1172 if (eventID < nEventsToBeProcessed - 1) {
1173 fpViewer->ShowView();
1174 fpSceneHandler->SetMarkForClearingTransientStore(true);
1175 } else { // Last event...
1176 // Keep, but only if user has not kept any...
1177 if (!nKeptEvents) {
1178 eventManager->KeepTheCurrentEvent();
1179 fKeptLastEvent = true;
1180 }
1181 }
1182
1183 } else { // Accumulating events...
1184
1185 G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1186 if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) {
1187 fEventKeepingSuspended = true;
1188 static G4bool warned = false;
1189 if (!warned) {
1190 if (fVerbosity >= warnings) {
1191 G4cout <<
1192 "WARNING: G4VisManager::EndOfEvent: Event keeping suspended."
1193 "\n The number of events exceeds the maximum that may be kept, "
1194 << maxNumberOfKeptEvents << '.'
1195 << G4endl;
1196 }
1197 warned = true;
1198 }
1199 } else if (maxNumberOfKeptEvents != 0) {
1200 eventManager->KeepTheCurrentEvent();
1201 }
1202 }
1203}
1204
1205void G4VisManager::EndOfRun ()
1206{
1207 //G4cout << "G4VisManager::EndOfRun" << 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) {
1214 if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
1215 if (fpScene->GetRefreshAtEndOfRun()) {
1216 fpViewer->ShowView();
1217 fpSceneHandler->SetMarkForClearingTransientStore(true);
1218 }
1219 }
1220
1221 if (fEventKeepingSuspended && fVerbosity >= warnings) {
1222 G4cout <<
1223 "WARNING: G4VisManager::EndOfRun: Event keeping was suspended."
1224 "\n The number of events in the run exceeded the maximum to be kept, "
1225 << fpScene->GetMaxNumberOfKeptEvents() << '.' <<
1226 "\n The number of events to be kept can be changed with"
1227 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1228 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1229 << G4endl;
1230 }
1231 }
1232 fEventRefreshing = false;
1233
1234 G4RunManager* runManager = G4RunManager::GetRunManager();
1235 const G4Run* currentRun = runManager->GetCurrentRun();
1236
1237 G4int nKeptEvents = 0;
1238 const std::vector<const G4Event*>* events =
1239 currentRun? currentRun->GetEventVector(): 0;
1240 if (events) nKeptEvents = events->size();
1241
1242 if (nKeptEvents && !fKeptLastEvent) {
1243 if (!valid && fVerbosity >= warnings) G4cout << "WARNING: ";
1244 if (fVerbosity >= warnings) {
1245 G4cout << nKeptEvents;
1246 if (nKeptEvents == 1) G4cout << " event has";
1247 else G4cout << " events have";
1248 G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1249 }
1250 static G4bool warned = false;
1251 if (!valid && fVerbosity >= warnings && !warned) {
1252 G4cout <<
1253 " Only useful if before starting the run:"
1254 "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
1255 "\n b) the Draw method of any hits is implemented."
1256 "\n To view trajectories and hits:"
1257 "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
1258 "\n \"/vis/scene/add/hits\" and, possibly, \"/vis/viewer/flush\"."
1259 "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"."
1260 "\n To see events individually: \"/vis/reviewKeptEvents\"."
1261 << G4endl;
1262 warned = true;
1263 }
1264 }
1265}
1266
1267void G4VisManager::ClearTransientStoreIfMarked(){
1268 // Assumes valid view.
1269 if (fpSceneHandler->GetMarkForClearingTransientStore()) {
1270 fpSceneHandler->SetMarkForClearingTransientStore(false);
1271 fpSceneHandler->ClearTransientStore();
1272 }
1273 // Record if transients drawn. These local flags are only set
1274 // *after* ClearTransientStore. In the code in G4VSceneHandler
1275 // triggered by ClearTransientStore, use these flags so that
1276 // event refreshing is not done too early.
1277 fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
1278 fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
1279}
1280
1281void G4VisManager::ResetTransientsDrawnFlags()
1282{
1283 fTransientsDrawnThisRun = false;
1284 fTransientsDrawnThisEvent = false;
1285 G4SceneHandlerListConstIterator i;
1286 for (i = fAvailableSceneHandlers.begin();
1287 i != fAvailableSceneHandlers.end(); ++i) {
1288 (*i)->SetTransientsDrawnThisEvent(false);
1289 (*i)->SetTransientsDrawnThisRun(false);
1290 }
1291}
1292
1293G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
1294 G4String viewerShortName (viewerName);
1295 viewerShortName = viewerShortName (0, viewerShortName.find (' '));
1296 return viewerShortName.strip ();
1297}
1298
1299G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
1300 G4String viewerShortName = ViewerShortName (viewerName);
1301 size_t nHandlers = fAvailableSceneHandlers.size ();
1302 size_t iHandler, iViewer;
1303 G4VViewer* viewer = 0;
1304 G4bool found = false;
1305 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1306 G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
1307 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1308 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1309 viewer = viewerList [iViewer];
1310 if (viewerShortName == viewer -> GetShortName ()) {
1311 found = true;
1312 break;
1313 }
1314 }
1315 if (found) break;
1316 }
1317 if (found) return viewer;
1318 else return 0;
1319}
1320
1321std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
1322
1323G4String G4VisManager::VerbosityString(Verbosity verbosity) {
1324 G4String s;
1325 switch (verbosity) {
1326 case quiet: s = "quiet (0)"; break;
1327 case startup: s = "startup (1)"; break;
1328 case errors: s = "errors (2)"; break;
1329 case warnings: s = "warnings (3)"; break;
1330 case confirmations: s = "confirmations (4)"; break;
1331 case parameters: s = "parameters (5)"; break;
1332 case all: s = "all (6)"; break;
1333 }
1334 return s;
1335}
1336
1337G4VisManager::Verbosity
1338G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
1339 G4String s(verbosityString); s.toLower();
1340 Verbosity verbosity;
1341 if (s(0) == 'q') verbosity = quiet;
1342 else if (s(0) == 's') verbosity = startup;
1343 else if (s(0) == 'e') verbosity = errors;
1344 else if (s(0) == 'w') verbosity = warnings;
1345 else if (s(0) == 'c') verbosity = confirmations;
1346 else if (s(0) == 'p') verbosity = parameters;
1347 else if (s(0) == 'a') verbosity = all;
1348 else {
1349 G4int intVerbosity;
1350 std::istringstream is(s);
1351 is >> intVerbosity;
1352 if (!is) {
1353 G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
1354 << verbosityString << "\"";
1355 for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
1356 G4cout << '\n' << VerbosityGuidanceStrings[i];
1357 }
1358 verbosity = warnings;
1359 G4cout << "\n Returning " << VerbosityString(verbosity)
1360 << G4endl;
1361 }
1362 else {
1363 verbosity = GetVerbosityValue(intVerbosity);
1364 }
1365 }
1366 return verbosity;
1367}
1368
1369G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
1370 Verbosity verbosity;
1371 if (intVerbosity < quiet) verbosity = quiet;
1372 else if (intVerbosity > all) verbosity = all;
1373 else verbosity = Verbosity(intVerbosity);
1374 return verbosity;
1375}
1376
1377void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
1378 fVerbosity = GetVerbosityValue(intVerbosity);
1379}
1380
1381void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
1382 fVerbosity = GetVerbosityValue(verbosityString);
1383}
1384
1385G4bool G4VisManager::IsValidView () {
1386
1387 if (!fInitialised) Initialise ();
1388
1389 static G4bool noGSPrinting = true;
1390 if (!fpGraphicsSystem) {
1391 // Limit printing - we do not want printing if the user simply does
1392 // not want to use graphics, e.g., in batch mode.
1393 if (noGSPrinting) {
1394 noGSPrinting = false;
1395 if (fVerbosity >= warnings) {
1396 G4cout <<
1397 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
1398 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
1399 "\n Alternatively, to avoid this message, suppress instantiation of vis"
1400 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
1401 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
1402 "\n is non-zero."
1403 << G4endl;
1404 }
1405 }
1406 return false;
1407 }
1408
1409 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
1410 if (fVerbosity >= errors) {
1411 G4cout <<
1412 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
1413 << G4endl;
1414 PrintInvalidPointers ();
1415 }
1416 return false;
1417 }
1418
1419 if (fpScene != fpSceneHandler -> GetScene ()) {
1420 if (fVerbosity >= errors) {
1421 G4cout << "ERROR: G4VisManager::IsValidView ():";
1422 if (fpSceneHandler -> GetScene ()) {
1423 G4cout <<
1424 "\n The current scene \""
1425 << fpScene -> GetName ()
1426 << "\" is not handled by"
1427 "\n the current scene handler \""
1428 << fpSceneHandler -> GetName ()
1429 << "\""
1430 "\n (it currently handles scene \""
1431 << fpSceneHandler -> GetScene () -> GetName ()
1432 << "\")."
1433 "\n Either:"
1434 "\n (a) attach it to the scene handler with"
1435 "\n /vis/sceneHandler/attach "
1436 << fpScene -> GetName ()
1437 << ", or"
1438 "\n (b) create a new scene handler with "
1439 "\n /vis/sceneHandler/create <graphics-system>,"
1440 "\n in which case it should pick up the the new scene."
1441 << G4endl;
1442 }
1443 else {
1444 G4cout << "\n Scene handler \""
1445 << fpSceneHandler -> GetName ()
1446 << "\" has null scene pointer."
1447 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
1448 << G4endl;
1449 }
1450 }
1451 return false;
1452 }
1453
1454 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1455 if (viewerList.size () == 0) {
1456 if (fVerbosity >= errors) {
1457 G4cout <<
1458 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
1459 << fpSceneHandler -> GetName ()
1460 << "\" has no viewers. Do /vis/viewer/create."
1461 << G4endl;
1462 }
1463 return false;
1464 }
1465
1466 G4bool isValid = true;
1467 if (fpScene -> IsEmpty ()) { // Add world by default if possible...
1468 G4bool warn(fVerbosity >= warnings);
1469 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
1470 if (!successful || fpScene -> IsEmpty ()) { // If still empty...
1471 if (fVerbosity >= errors) {
1472 G4cout << "ERROR: G4VisManager::IsViewValid ():";
1473 G4cout <<
1474 "\n Attempt at some drawing operation when scene is empty."
1475 "\n Maybe the geometry has not yet been defined."
1476 " Try /run/initialize."
1477 << G4endl;
1478 }
1479 isValid = false;
1480 }
1481 else {
1482 G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
1483 if (fVerbosity >= warnings) {
1484 G4cout <<
1485 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
1486 "\n added and the scene handlers notified.";
1487 G4cout << G4endl;
1488 }
1489 }
1490 }
1491 if (isValid) SetConcreteInstance(this);
1492 return isValid;
1493}
1494
1495void
1496G4VisManager::RegisterModelFactories()
1497{
1498 if (fVerbosity >= warnings) {
1499 G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
1500 G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
1501 G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
1502 }
1503}
Note: See TracBrowser for help on using the repository browser.