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

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

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

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