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

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

mise a jour des tags

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