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

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

Modif pour XGeometry complet. Avec debug

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