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

Last change on this file since 597 was 593, checked in by garnier, 18 years ago

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

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