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

Last change on this file since 1308 was 1292, checked in by garnier, 15 years ago

update from CVS

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