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

Last change on this file since 1354 was 1347, checked in by garnier, 15 years ago

geant4 tag 9.4

  • Property svn:mime-type set to text/cpp
File size: 55.6 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.131 2010/12/14 15:53:28 gcosmo Exp $
27// GEANT4 tag $Name: geant4-09-04-ref-00 $
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 if (IsValidView()) {
943 G4TrajectoriesModel* trajectoriesModel =
944 dynamic_cast<G4TrajectoriesModel*>(fpSceneHandler->GetModel());
945 if (trajectoriesModel) {
946 if (trajectoriesModel->IsDrawingModeSet()) {
947 trajectoryModel->Draw(trajectory, i_mode, visible);
948 } else {
949 trajectoryModel->Draw(trajectory, visible);
950 }
951 } else {
952 // Just draw at user's request
953 trajectoryModel->Draw(trajectory, i_mode, visible);
954 }
955 }
956}
957
958void G4VisManager::SetUserAction
959(G4VUserVisAction* pVisAction,
960 const G4VisExtent& extent) {
961 fpUserVisAction = pVisAction;
962 fUserVisActionExtent = extent;
963 if (extent.GetExtentRadius() <= 0.) {
964 if (fVerbosity >= warnings) {
965 G4cout <<
966 "WARNING: No extent set for user vis action. (You may"
967 "\n set it later when adding with /vis/scene/add/userAction.)"
968 << G4endl;
969 }
970 }
971}
972
973void G4VisManager::SetCurrentScene (G4Scene* pScene) {
974 if (pScene != fpScene) {
975 // A change of scene. Therefore reset transients drawn flags. All
976 // memory of previous transient proceessing thereby erased...
977 ResetTransientsDrawnFlags();
978 }
979 fpScene = pScene;
980}
981
982void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
983 fpGraphicsSystem = pSystem;
984 if (fVerbosity >= confirmations) {
985 G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
986 << pSystem -> GetName () << G4endl;
987 }
988 // If current scene handler is of same graphics system, leave unchanged.
989 // Else find the most recent scene handler of same graphics system.
990 // Or clear pointers.
991 if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
992 const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
993 G4int nSH = sceneHandlerList.size (); // No. of scene handlers.
994 G4int iSH;
995 for (iSH = nSH - 1; iSH >= 0; iSH--) {
996 if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
997 }
998 if (iSH >= 0) {
999 fpSceneHandler = sceneHandlerList [iSH];
1000 if (fVerbosity >= confirmations) {
1001 G4cout << " Scene Handler now "
1002 << fpSceneHandler -> GetName () << G4endl;
1003 }
1004 if (fpScene != fpSceneHandler -> GetScene ()) {
1005 fpScene = fpSceneHandler -> GetScene ();
1006 if (fVerbosity >= confirmations) {
1007 G4cout << " Scene now \""
1008 << fpScene -> GetName () << "\"" << G4endl;
1009 }
1010 }
1011 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1012 if (viewerList.size ()) {
1013 fpViewer = viewerList [0];
1014 if (fVerbosity >= confirmations) {
1015 G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
1016 }
1017 }
1018 else {
1019 fpViewer = 0;
1020 }
1021 }
1022 else {
1023 fpSceneHandler = 0;
1024 fpViewer = 0;
1025 }
1026 }
1027}
1028
1029void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
1030 fpSceneHandler = pSceneHandler;
1031 if (fVerbosity >= confirmations) {
1032 G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
1033 << pSceneHandler -> GetName () << "\"" << G4endl;
1034 }
1035 if (fpScene != fpSceneHandler -> GetScene ()) {
1036 fpScene = fpSceneHandler -> GetScene ();
1037 if (fVerbosity >= confirmations) {
1038 G4cout << " Scene now \""
1039 << fpScene -> GetName () << "\"" << G4endl;
1040 }
1041 }
1042 if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1043 fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1044 if (fVerbosity >= confirmations) {
1045 G4cout << " Graphics system now \""
1046 << fpGraphicsSystem -> GetName () << "\"" << G4endl;
1047 }
1048 }
1049 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1050 G4int nViewers = viewerList.size ();
1051 if (nViewers) {
1052 G4int iViewer;
1053 for (iViewer = 0; iViewer < nViewers; iViewer++) {
1054 if (fpViewer == viewerList [iViewer]) break;
1055 }
1056 if (iViewer >= nViewers) {
1057 fpViewer = viewerList [0];
1058 if (fVerbosity >= confirmations) {
1059 G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
1060 << G4endl;
1061 }
1062 }
1063 if (!IsValidView ()) {
1064 if (fVerbosity >= warnings) {
1065 G4cout <<
1066 "WARNING: Problem setting scene handler - please report circumstances."
1067 << G4endl;
1068 }
1069 }
1070 }
1071 else {
1072 fpViewer = 0;
1073 if (fVerbosity >= warnings) {
1074 G4cout <<
1075 "WARNING: No viewers for this scene handler - please create one."
1076 << G4endl;
1077 }
1078 }
1079}
1080
1081void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
1082 fpViewer = pViewer;
1083 if (fVerbosity >= confirmations) {
1084 G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1085 << pViewer -> GetName ()
1086 << G4endl;
1087 }
1088 fpSceneHandler = fpViewer -> GetSceneHandler ();
1089 fpSceneHandler -> SetCurrentViewer (pViewer);
1090 fpScene = fpSceneHandler -> GetScene ();
1091 fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1092 if (!IsValidView ()) {
1093 if (fVerbosity >= warnings) {
1094 G4cout <<
1095 "WARNING: Problem setting viewer - please report circumstances."
1096 << G4endl;
1097 }
1098 }
1099}
1100
1101void G4VisManager::RegisterMessengers () {
1102
1103 // Instantiate individual messengers/commands (often - but not
1104 // always - one command per messenger).
1105
1106 G4UIcommand* directory;
1107
1108 // Top level commands...
1109 RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
1110 RegisterMessenger(new G4VisCommandEnable);
1111 RegisterMessenger(new G4VisCommandList);
1112 RegisterMessenger(new G4VisCommandReviewKeptEvents);
1113
1114 // Compound commands...
1115 RegisterMessenger(new G4VisCommandDrawTree);
1116 RegisterMessenger(new G4VisCommandDrawView);
1117 RegisterMessenger(new G4VisCommandDrawVolume);
1118 RegisterMessenger(new G4VisCommandOpen);
1119 RegisterMessenger(new G4VisCommandSpecify);
1120
1121 directory = new G4UIdirectory ("/vis/geometry/");
1122 directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
1123 fDirectoryList.push_back (directory);
1124 RegisterMessenger(new G4VisCommandGeometryList);
1125 RegisterMessenger(new G4VisCommandGeometryRestore);
1126
1127 directory = new G4UIdirectory ("/vis/geometry/set/");
1128 directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
1129 fDirectoryList.push_back (directory);
1130 RegisterMessenger(new G4VisCommandGeometrySetColour);
1131 RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
1132 RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
1133 RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
1134 RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
1135 RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
1136 RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
1137 RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
1138 RegisterMessenger(new G4VisCommandGeometrySetVisibility);
1139
1140 directory = new G4UIdirectory ("/vis/scene/");
1141 directory -> SetGuidance ("Operations on Geant4 scenes.");
1142 fDirectoryList.push_back (directory);
1143 RegisterMessenger(new G4VisCommandSceneCreate);
1144 RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
1145 RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
1146 RegisterMessenger(new G4VisCommandSceneList);
1147 RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
1148 RegisterMessenger(new G4VisCommandSceneSelect);
1149
1150 directory = new G4UIdirectory ("/vis/scene/add/");
1151 directory -> SetGuidance ("Add model to current scene.");
1152 fDirectoryList.push_back (directory);
1153 RegisterMessenger(new G4VisCommandSceneAddAxes);
1154 RegisterMessenger(new G4VisCommandSceneAddEventID);
1155 RegisterMessenger(new G4VisCommandSceneAddGhosts);
1156 RegisterMessenger(new G4VisCommandSceneAddHits);
1157 RegisterMessenger(new G4VisCommandSceneAddDigis);
1158 RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
1159 RegisterMessenger(new G4VisCommandSceneAddLogo);
1160 RegisterMessenger(new G4VisCommandSceneAddPSHits);
1161 RegisterMessenger(new G4VisCommandSceneAddScale);
1162 RegisterMessenger(new G4VisCommandSceneAddText);
1163 RegisterMessenger(new G4VisCommandSceneAddTrajectories);
1164 RegisterMessenger(new G4VisCommandSceneAddUserAction);
1165 RegisterMessenger(new G4VisCommandSceneAddVolume);
1166
1167 directory = new G4UIdirectory ("/vis/sceneHandler/");
1168 directory -> SetGuidance ("Operations on Geant4 scene handlers.");
1169 fDirectoryList.push_back (directory);
1170 RegisterMessenger(new G4VisCommandSceneHandlerAttach);
1171 RegisterMessenger(new G4VisCommandSceneHandlerCreate);
1172 RegisterMessenger(new G4VisCommandSceneHandlerList);
1173 RegisterMessenger(new G4VisCommandSceneHandlerSelect);
1174
1175 directory = new G4UIdirectory ("/vis/viewer/");
1176 directory -> SetGuidance ("Operations on Geant4 viewers.");
1177 fDirectoryList.push_back (directory);
1178 RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
1179 RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
1180 RegisterMessenger(new G4VisCommandViewerClear);
1181 RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
1182 RegisterMessenger(new G4VisCommandViewerClearTransients);
1183 RegisterMessenger(new G4VisCommandViewerClone);
1184 RegisterMessenger(new G4VisCommandViewerCreate);
1185 RegisterMessenger(new G4VisCommandViewerDolly);
1186 RegisterMessenger(new G4VisCommandViewerFlush);
1187 RegisterMessenger(new G4VisCommandViewerList);
1188 RegisterMessenger(new G4VisCommandViewerPan);
1189 RegisterMessenger(new G4VisCommandViewerRebuild);
1190 RegisterMessenger(new G4VisCommandViewerRefresh);
1191 RegisterMessenger(new G4VisCommandViewerReset);
1192 RegisterMessenger(new G4VisCommandViewerScale);
1193 RegisterMessenger(new G4VisCommandViewerSelect);
1194 RegisterMessenger(new G4VisCommandViewerUpdate);
1195 RegisterMessenger(new G4VisCommandViewerZoom);
1196
1197 directory = new G4UIdirectory ("/vis/viewer/set/");
1198 directory -> SetGuidance ("Set view parameters of current viewer.");
1199 fDirectoryList.push_back (directory);
1200 RegisterMessenger(new G4VisCommandsViewerSet);
1201
1202 // List manager commands
1203 RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
1204 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1205 RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
1206 (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
1207
1208 // Trajectory filter manager commands
1209 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
1210 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1211 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
1212 (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
1213
1214 // Hit filter manager commands
1215 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
1216 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1217 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
1218 (fpHitFilterMgr, fpHitFilterMgr->Placement()));
1219
1220 // Digi filter manager commands
1221 RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VDigi> >
1222 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
1223 RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VDigi> >
1224 (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
1225}
1226
1227void G4VisManager::PrintAvailableGraphicsSystems () const {
1228 G4int nSystems = fAvailableGraphicsSystems.size ();
1229 G4cout << "Current available graphics systems are:";
1230 if (nSystems) {
1231 for (int i = 0; i < nSystems; i++) {
1232 const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i];
1233 G4cout << "\n " << pSystem -> GetName ();
1234 if (pSystem -> GetNickname () != "") {
1235 G4cout << " (" << pSystem -> GetNickname () << ")";
1236 }
1237 }
1238 }
1239 else {
1240 G4cout << "\n NONE!!! None registered - yet! Mmmmm!";
1241 }
1242 G4cout << G4endl;
1243}
1244
1245void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1246{
1247 {
1248 //fpTrajDrawModelMgr->Print(G4cout);
1249 G4cout << "Registered model factories:" << G4endl;
1250 const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1251 fpTrajDrawModelMgr->FactoryList();
1252 if (factoryList.empty()) G4cout << " None" << G4endl;
1253 else {
1254 std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1255 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1256 (*i)->Print(G4cout);
1257 }
1258 const G4VisListManager<G4VTrajectoryModel>* listManager =
1259 fpTrajDrawModelMgr->ListManager();
1260 const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1261 listManager->Map();
1262 if (!modelMap.empty()) {
1263 G4cout << "\nRegistered models:" << G4endl;
1264 std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1265 for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1266 G4cout << " " << i->second->Name();
1267 if (i->second == listManager->Current()) G4cout << " (Current)";
1268 G4cout << G4endl;
1269 if (verbosity >= parameters) i->second->Print(G4cout);
1270 }
1271 }
1272 }
1273
1274 G4cout << G4endl;
1275
1276 {
1277 //fpTrajFilterMgr->Print(G4cout);
1278 G4cout << "Registered filter factories:" << G4endl;
1279 const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1280 factoryList = fpTrajFilterMgr->FactoryList();
1281 if (factoryList.empty()) G4cout << " None" << G4endl;
1282 else {
1283 std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1284 for (i = factoryList.begin(); i != factoryList.end(); ++i)
1285 (*i)->Print(G4cout);
1286 }
1287 const std::vector<G4VFilter<G4VTrajectory>*>&
1288 filterList = fpTrajFilterMgr->FilterList();
1289 if (!filterList.empty()) {
1290 G4cout << "\nRegistered filters:" << G4endl;
1291 std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1292 for (i = filterList.begin(); i != filterList.end(); ++i) {
1293 G4cout << " " << (*i)->GetName() << G4endl;
1294 if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1295 }
1296 }
1297 }
1298}
1299
1300void G4VisManager::PrintInvalidPointers () const {
1301 if (fVerbosity >= errors) {
1302 G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
1303 if (!fpGraphicsSystem) {
1304 G4cout << "\n null graphics system pointer.";
1305 }
1306 else {
1307 G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1308 << " but:";
1309 if (!fpScene)
1310 G4cout <<
1311 "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1312 " \"/vis/scene/create\".";
1313 if (!fpSceneHandler)
1314 G4cout <<
1315 "\n Null scene handler pointer. Use \"/vis/open\" or"
1316 " \"/vis/sceneHandler/create\".";
1317 if (!fpViewer )
1318 G4cout <<
1319 "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1320 }
1321 G4cout << G4endl;
1322 }
1323}
1324
1325void G4VisManager::BeginOfRun ()
1326{
1327 //G4cout << "G4VisManager::BeginOfRun" << G4endl;
1328 fKeptLastEvent = false;
1329 fEventKeepingSuspended = false;
1330 fTransientsDrawnThisRun = false;
1331 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
1332}
1333
1334void G4VisManager::BeginOfEvent ()
1335{
1336 //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
1337 fTransientsDrawnThisEvent = false;
1338 if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
1339}
1340
1341void G4VisManager::EndOfEvent ()
1342{
1343 //G4cout << "G4VisManager::EndOfEvent" << G4endl;
1344
1345 // Don't call IsValidView unless there is a scene handler. This
1346 // avoids WARNING message at end of event and run when the user has
1347 // not instantiated a scene handler, e.g., in batch mode.
1348 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1349 if (!valid) return;
1350
1351 G4RunManager* runManager = G4RunManager::GetRunManager();
1352 const G4Run* currentRun = runManager->GetCurrentRun();
1353
1354 G4EventManager* eventManager = G4EventManager::GetEventManager();
1355 const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1356 if (!currentEvent) return;
1357
1358 ClearTransientStoreIfMarked();
1359 fpSceneHandler->DrawEvent(currentEvent);
1360
1361 G4int nEventsToBeProcessed = 0;
1362 G4int nKeptEvents = 0;
1363 G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
1364 if (currentRun) {
1365 nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
1366 eventID = currentEvent->GetEventID();
1367 const std::vector<const G4Event*>* events =
1368 currentRun->GetEventVector();
1369 if (events) nKeptEvents = events->size();
1370 }
1371
1372 if (fpScene->GetRefreshAtEndOfEvent()) {
1373
1374 // Unless last event (in which case wait end of run)...
1375 if (eventID < nEventsToBeProcessed - 1) {
1376 fpViewer->ShowView();
1377 fpViewer->DrawView();
1378 fpSceneHandler->SetMarkForClearingTransientStore(true);
1379 } else { // Last event...
1380 // Keep, but only if user has not kept any...
1381 if (!nKeptEvents) {
1382 eventManager->KeepTheCurrentEvent();
1383 fKeptLastEvent = true;
1384 }
1385 }
1386
1387 } else { // Accumulating events...
1388
1389 G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1390 if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) {
1391 fEventKeepingSuspended = true;
1392 static G4bool warned = false;
1393 if (!warned) {
1394 if (fVerbosity >= warnings) {
1395 G4cout <<
1396 "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1397 "\n The number of events exceeds the maximum, "
1398 << maxNumberOfKeptEvents <<
1399 ", that can be kept by the vis manager."
1400 << G4endl;
1401 }
1402 warned = true;
1403 }
1404 } else if (maxNumberOfKeptEvents != 0) {
1405 eventManager->KeepTheCurrentEvent();
1406 }
1407 }
1408}
1409
1410void G4VisManager::EndOfRun ()
1411{
1412 //G4cout << "G4VisManager::EndOfRun" << G4endl;
1413
1414 // Don't call IsValidView unless there is a scene handler. This
1415 // avoids WARNING message at end of event and run when the user has
1416 // not instantiated a scene handler, e.g., in batch mode.
1417 G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
1418 if (valid) {
1419 if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
1420 if (fpScene->GetRefreshAtEndOfRun()) {
1421 fpSceneHandler->DrawEndOfRunModels();
1422 fpViewer->ShowView();
1423 fpSceneHandler->SetMarkForClearingTransientStore(true);
1424 }
1425 }
1426
1427 if (fEventKeepingSuspended && fVerbosity >= warnings) {
1428 G4cout <<
1429 "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended."
1430 "\n The number of events in the run exceeded the maximum, "
1431 << fpScene->GetMaxNumberOfKeptEvents() <<
1432 ", that can be kept by the vis manager." <<
1433 "\n The number of events kept by the vis manager can be changed with"
1434 "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1435 "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1436 << G4endl;
1437 }
1438 }
1439 fEventRefreshing = false;
1440
1441 G4RunManager* runManager = G4RunManager::GetRunManager();
1442 const G4Run* currentRun = runManager->GetCurrentRun();
1443
1444 G4int nKeptEvents = 0;
1445 const std::vector<const G4Event*>* events =
1446 currentRun? currentRun->GetEventVector(): 0;
1447 if (events) nKeptEvents = events->size();
1448
1449 if (nKeptEvents && !fKeptLastEvent) {
1450 if (!valid && fVerbosity >= warnings) G4cout << "WARNING: ";
1451 if (fVerbosity >= warnings) {
1452 G4cout << nKeptEvents;
1453 if (nKeptEvents == 1) G4cout << " event has";
1454 else G4cout << " events have";
1455 G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1456 }
1457 static G4bool warned = false;
1458 if (!valid && fVerbosity >= warnings && !warned) {
1459 G4cout <<
1460 " Only useful if before starting the run:"
1461 "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
1462 "\n b) the Draw method of any hits or digis is implemented."
1463 "\n To view trajectories, hits or digis:"
1464 "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
1465 "\n \"/vis/scene/add/hits\" or \"/vis/scene/add/digitisations\""
1466 "\n and, possibly, \"/vis/viewer/flush\"."
1467 "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"."
1468 "\n To see events individually: \"/vis/reviewKeptEvents\"."
1469 << G4endl;
1470 warned = true;
1471 }
1472 }
1473}
1474
1475void G4VisManager::ClearTransientStoreIfMarked(){
1476 // Assumes valid view.
1477 if (fpSceneHandler->GetMarkForClearingTransientStore()) {
1478 fpSceneHandler->SetMarkForClearingTransientStore(false);
1479 fpSceneHandler->ClearTransientStore();
1480 }
1481 // Record if transients drawn. These local flags are only set
1482 // *after* ClearTransientStore. In the code in G4VSceneHandler
1483 // triggered by ClearTransientStore, use these flags so that
1484 // event refreshing is not done too early.
1485 fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
1486 fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
1487}
1488
1489void G4VisManager::ResetTransientsDrawnFlags()
1490{
1491 fTransientsDrawnThisRun = false;
1492 fTransientsDrawnThisEvent = false;
1493 G4SceneHandlerListConstIterator i;
1494 for (i = fAvailableSceneHandlers.begin();
1495 i != fAvailableSceneHandlers.end(); ++i) {
1496 (*i)->SetTransientsDrawnThisEvent(false);
1497 (*i)->SetTransientsDrawnThisRun(false);
1498 }
1499}
1500
1501G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
1502 G4String viewerShortName (viewerName);
1503 viewerShortName = viewerShortName (0, viewerShortName.find (' '));
1504 return viewerShortName.strip ();
1505}
1506
1507G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
1508 G4String viewerShortName = ViewerShortName (viewerName);
1509 size_t nHandlers = fAvailableSceneHandlers.size ();
1510 size_t iHandler, iViewer;
1511 G4VViewer* viewer = 0;
1512 G4bool found = false;
1513 for (iHandler = 0; iHandler < nHandlers; iHandler++) {
1514 G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
1515 const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
1516 for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
1517 viewer = viewerList [iViewer];
1518 if (viewerShortName == viewer -> GetShortName ()) {
1519 found = true;
1520 break;
1521 }
1522 }
1523 if (found) break;
1524 }
1525 if (found) return viewer;
1526 else return 0;
1527}
1528
1529std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
1530
1531G4String G4VisManager::VerbosityString(Verbosity verbosity) {
1532 G4String s;
1533 switch (verbosity) {
1534 case quiet: s = "quiet (0)"; break;
1535 case startup: s = "startup (1)"; break;
1536 case errors: s = "errors (2)"; break;
1537 case warnings: s = "warnings (3)"; break;
1538 case confirmations: s = "confirmations (4)"; break;
1539 case parameters: s = "parameters (5)"; break;
1540 case all: s = "all (6)"; break;
1541 }
1542 return s;
1543}
1544
1545G4VisManager::Verbosity
1546G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
1547 G4String s(verbosityString); s.toLower();
1548 Verbosity verbosity;
1549 if (s(0) == 'q') verbosity = quiet;
1550 else if (s(0) == 's') verbosity = startup;
1551 else if (s(0) == 'e') verbosity = errors;
1552 else if (s(0) == 'w') verbosity = warnings;
1553 else if (s(0) == 'c') verbosity = confirmations;
1554 else if (s(0) == 'p') verbosity = parameters;
1555 else if (s(0) == 'a') verbosity = all;
1556 else {
1557 G4int intVerbosity;
1558 std::istringstream is(s);
1559 is >> intVerbosity;
1560 if (!is) {
1561 G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
1562 << verbosityString << "\"";
1563 for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
1564 G4cout << '\n' << VerbosityGuidanceStrings[i];
1565 }
1566 verbosity = warnings;
1567 G4cout << "\n Returning " << VerbosityString(verbosity)
1568 << G4endl;
1569 }
1570 else {
1571 verbosity = GetVerbosityValue(intVerbosity);
1572 }
1573 }
1574 return verbosity;
1575}
1576
1577G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
1578 Verbosity verbosity;
1579 if (intVerbosity < quiet) verbosity = quiet;
1580 else if (intVerbosity > all) verbosity = all;
1581 else verbosity = Verbosity(intVerbosity);
1582 return verbosity;
1583}
1584
1585G4VisManager::Verbosity G4VisManager::GetVerbosity () {
1586 return fVerbosity;
1587}
1588
1589void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
1590 fVerbosity = GetVerbosityValue(intVerbosity);
1591}
1592
1593void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
1594 fVerbosity = GetVerbosityValue(verbosityString);
1595}
1596
1597G4bool G4VisManager::IsValidView () {
1598
1599 if (!fInitialised) Initialise ();
1600
1601 static G4bool noGSPrinting = true;
1602 if (!fpGraphicsSystem) {
1603 // Limit printing - we do not want printing if the user simply does
1604 // not want to use graphics, e.g., in batch mode.
1605 if (noGSPrinting) {
1606 noGSPrinting = false;
1607 if (fVerbosity >= warnings) {
1608 G4cout <<
1609 "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
1610 "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
1611 "\n Alternatively, to avoid this message, suppress instantiation of vis"
1612 "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
1613 "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
1614 "\n is non-zero."
1615 << G4endl;
1616 }
1617 }
1618 return false;
1619 }
1620
1621 if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
1622 if (fVerbosity >= errors) {
1623 G4cout <<
1624 "ERROR: G4VisManager::IsValidView(): Current view is not valid."
1625 << G4endl;
1626 PrintInvalidPointers ();
1627 }
1628 return false;
1629 }
1630
1631 if (fpScene != fpSceneHandler -> GetScene ()) {
1632 if (fVerbosity >= errors) {
1633 G4cout << "ERROR: G4VisManager::IsValidView ():";
1634 if (fpSceneHandler -> GetScene ()) {
1635 G4cout <<
1636 "\n The current scene \""
1637 << fpScene -> GetName ()
1638 << "\" is not handled by"
1639 "\n the current scene handler \""
1640 << fpSceneHandler -> GetName ()
1641 << "\""
1642 "\n (it currently handles scene \""
1643 << fpSceneHandler -> GetScene () -> GetName ()
1644 << "\")."
1645 "\n Either:"
1646 "\n (a) attach it to the scene handler with"
1647 "\n /vis/sceneHandler/attach "
1648 << fpScene -> GetName ()
1649 << ", or"
1650 "\n (b) create a new scene handler with "
1651 "\n /vis/sceneHandler/create <graphics-system>,"
1652 "\n in which case it should pick up the the new scene."
1653 << G4endl;
1654 }
1655 else {
1656 G4cout << "\n Scene handler \""
1657 << fpSceneHandler -> GetName ()
1658 << "\" has null scene pointer."
1659 "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
1660 << G4endl;
1661 }
1662 }
1663 return false;
1664 }
1665
1666 const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1667 if (viewerList.size () == 0) {
1668 if (fVerbosity >= errors) {
1669 G4cout <<
1670 "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
1671 << fpSceneHandler -> GetName ()
1672 << "\" has no viewers. Do /vis/viewer/create."
1673 << G4endl;
1674 }
1675 return false;
1676 }
1677
1678 G4bool isValid = true;
1679 if (fpScene -> IsEmpty ()) { // Add world by default if possible...
1680 G4bool warn(fVerbosity >= warnings);
1681 G4bool successful = fpScene -> AddWorldIfEmpty (warn);
1682 if (!successful || fpScene -> IsEmpty ()) { // If still empty...
1683 if (fVerbosity >= errors) {
1684 G4cout << "ERROR: G4VisManager::IsViewValid ():";
1685 G4cout <<
1686 "\n Attempt at some drawing operation when scene is empty."
1687 "\n Maybe the geometry has not yet been defined."
1688 " Try /run/initialize."
1689 << G4endl;
1690 }
1691 isValid = false;
1692 }
1693 else {
1694 G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
1695 if (fVerbosity >= warnings) {
1696 G4cout <<
1697 "WARNING: G4VisManager: the scene was empty, \"world\" has been"
1698 "\n added and the scene handlers notified.";
1699 G4cout << G4endl;
1700 }
1701 }
1702 }
1703 if (isValid) SetConcreteInstance(this);
1704 return isValid;
1705}
1706
1707void
1708G4VisManager::RegisterModelFactories()
1709{
1710 if (fVerbosity >= warnings) {
1711 G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
1712 G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
1713 G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
1714 }
1715}
Note: See TracBrowser for help on using the repository browser.