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

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

John update

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