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

Last change on this file since 1136 was 1136, checked in by garnier, 16 years ago

debug updates

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