Geant4  10.00.p03
G4VisManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4VisManager.cc 77479 2013-11-25 10:01:22Z gcosmo $
27 //
28 //
29 // GEANT4 Visualization Manager - John Allison 02/Jan/1996.
30 
31 #include "G4VisManager.hh"
32 
33 #include "G4VisCommands.hh"
34 #include "G4VisCommandsCompound.hh"
35 #include "G4VisCommandsGeometry.hh"
37 #include "G4VisCommandsSet.hh"
38 #include "G4VisCommandsScene.hh"
39 #include "G4VisCommandsSceneAdd.hh"
42 #include "G4VisCommandsViewer.hh"
45 #include "G4UImanager.hh"
46 #include "G4VisStateDependent.hh"
47 #include "G4UIdirectory.hh"
48 #include "G4VGraphicsSystem.hh"
49 #include "G4VSceneHandler.hh"
50 #include "G4VViewer.hh"
51 #include "G4VPhysicalVolume.hh"
52 #include "G4LogicalVolume.hh"
53 #include "G4VSolid.hh"
54 #include "G4Vector3D.hh"
55 #include "G4Point3D.hh"
56 #include "G4RotationMatrix.hh"
57 #include "G4Polyline.hh"
58 #include "G4Polyhedron.hh"
59 #include "G4NullModel.hh"
60 #include "G4ModelingParameters.hh"
64 #include "G4VisModelManager.hh"
65 #include "G4VModelFactory.hh"
66 #include "G4VisFilterManager.hh"
67 #include "G4VTrajectoryModel.hh"
69 #include "Randomize.hh"
70 #include "G4RunManager.hh"
71 #include "G4EventManager.hh"
72 #include "G4Run.hh"
73 #include "G4Event.hh"
74 #include <map>
75 #include <set>
76 #include <vector>
77 #include <sstream>
78 
79 #ifdef G4MULTITHREADED
80 #include "G4Threading.hh"
81 #include "G4AutoLock.hh"
82 #endif
83 
85 
87 
88 G4VisManager::G4VisManager (const G4String& verbosityString):
89  fVerbose (1),
90  fInitialised (false),
91  fpGraphicsSystem (0),
92  fpScene (0),
93  fpSceneHandler (0),
94  fpViewer (0),
95  fpStateDependent (0),
96  fEventRefreshing (false),
97  fTransientsDrawnThisRun (false),
98  fTransientsDrawnThisEvent (false),
99  fNKeepRequests (0),
100  fEventKeepingSuspended (false),
101  fKeptLastEvent (false),
102  fpRequestedEvent (0),
103  fAbortReviewKeptEvents (false),
104  fIsDrawGroup (false),
105  fDrawGroupNestingDepth (0),
106  fIgnoreStateChanges (false)
107  // All other objects use default constructors.
108 {
109  fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
110  fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
111  fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
112  fpDigiFilterMgr = new G4VisFilterManager<G4VDigi>("/vis/filtering/digi");
113 
114  VerbosityGuidanceStrings.push_back
115  ("Simple graded message scheme - digit or string (1st character defines):");
116  VerbosityGuidanceStrings.push_back
117  (" 0) quiet, // Nothing is printed.");
118  VerbosityGuidanceStrings.push_back
119  (" 1) startup, // Startup and endup messages are printed...");
120  VerbosityGuidanceStrings.push_back
121  (" 2) errors, // ...and errors...");
122  VerbosityGuidanceStrings.push_back
123  (" 3) warnings, // ...and warnings...");
124  VerbosityGuidanceStrings.push_back
125  (" 4) confirmations, // ...and confirming messages...");
126  VerbosityGuidanceStrings.push_back
127  (" 5) parameters, // ...and parameters of scenes and views...");
128  VerbosityGuidanceStrings.push_back
129  (" 6) all // ...and everything available.");
130 
131  if (fpInstance) {
133  ("G4VisManager::G4VisManager",
134  "visman0001", FatalException,
135  "Attempt to Construct more than one VisManager");
136  }
137 
138  fpInstance = this;
139  SetConcreteInstance(this);
140 
142  // No need to delete this; G4StateManager does this.
143 
144  fVerbosity = GetVerbosityValue(verbosityString);
145  if (fVerbosity >= startup) {
146  G4cout
147  << "Visualization Manager instantiating with verbosity \""
149  << "\"..." << G4endl;
150  }
151 
152  // Note: The specific graphics systems must be instantiated in a
153  // higher level library to avoid circular dependencies. Also,
154  // some specifically need additional external libararies that the
155  // user must supply. Therefore we ask the user to implement
156  // RegisterGraphicsSystems() and RegisterModelFactories()
157  // in a subclass. We have to wait for the subclass to instantiate
158  // so RegisterGraphicsSystems() cannot be called from this
159  // constructor; it is called from Initialise(). So we ask the
160  // user:
161  // (a) to write a subclass and implement RegisterGraphicsSystems()
162  // and RegisterModelFactories(). See
163  // visualization/include/G4VisExecutive.hh/icc as an example.
164  // (b) instantiate the subclass.
165  // (c) invoke the Initialise() method of the subclass.
166  // For example:
167  // ...
168  // #ifdef G4VIS_USE
169  // // Instantiate and initialise Visualization Manager.
170  // G4VisManager* visManager = new G4VisExecutive;
171  // visManager -> SetVerboseLevel (Verbose);
172  // visManager -> Initialise ();
173  // #endif
174  // // (Don't forget to delete visManager;)
175  // ...
176 
177  // Make top level command directory...
178  // Vis commands should *not* be broadcast to threads (2nd argument).
179  G4UIcommand* directory = new G4UIdirectory ("/vis/",false);
180  directory -> SetGuidance ("Visualization commands.");
181  fDirectoryList.push_back (directory);
182 
183  // Instantiate *basic* top level commands so that they can be used
184  // immediately after instantiation of the vis manager. Other top
185  // level and lower level commands are instantiated later in
186  // RegisterMessengers.
187  G4VVisCommand::SetVisManager (this); // Sets shared pointer
190 }
191 
193  fpInstance = 0;
194  size_t i;
195  for (i = 0; i < fSceneList.size (); ++i) {
196  delete fSceneList[i];
197  }
198  for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
199  if (fAvailableSceneHandlers[i] != NULL) {
200  delete fAvailableSceneHandlers[i];
201  }
202  }
203  for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
204  if (fAvailableGraphicsSystems[i]) {
205  delete fAvailableGraphicsSystems[i];
206  }
207  }
208  if (fVerbosity >= startup) {
209  G4cout << "Graphics systems deleted." << G4endl;
210  G4cout << "Visualization Manager deleting..." << G4endl;
211  }
212  for (i = 0; i < fMessengerList.size (); ++i) {
213  delete fMessengerList[i];
214  }
215  for (i = 0; i < fDirectoryList.size (); ++i) {
216  delete fDirectoryList[i];
217  }
218 
219  delete fpDigiFilterMgr;
220  delete fpHitFilterMgr;
221  delete fpTrajFilterMgr;
222  delete fpTrajDrawModelMgr;
223 }
224 
226  if (!fpInstance) {
228  ("G4VisManager::GetInstance",
229  "visman0002", FatalException, "VisManager not yet instantiated");
230  }
231  return fpInstance;
232 }
233 
235 
236  if (fInitialised && fVerbosity >= warnings) {
237  G4cout << "WARNING: G4VisManager::Initialise: already initialised."
238  << G4endl;
239  return;
240  }
241 
242  if (fVerbosity >= startup) {
243  G4cout << "Visualization Manager initialising..." << G4endl;
244  }
245 
246  if (fVerbosity >= parameters) {
247  G4cout <<
248  "\nYou have instantiated your own Visualization Manager, inheriting"
249  "\n G4VisManager and implementing RegisterGraphicsSystems(), in which"
250  "\n you should, normally, instantiate drivers which do not need"
251  "\n external packages or libraries, and, optionally, drivers under"
252  "\n control of environment variables."
253  "\n Also you should implement RegisterModelFactories()."
254  "\n See visualization/include/G4VisExecutive.hh/icc, for example."
255  "\n In your main() you will have something like:"
256  "\n #ifdef G4VIS_USE"
257  "\n G4VisManager* visManager = new G4VisExecutive;"
258  "\n visManager -> SetVerboseLevel (Verbose);"
259  "\n visManager -> Initialize ();"
260  "\n #endif"
261  "\n (Don't forget to delete visManager;)"
262  "\n"
263  << G4endl;
264  }
265 
266  if (fVerbosity >= startup) {
267  G4cout << "Registering graphics systems..." << G4endl;
268  }
269 
271 
272  if (fVerbosity >= startup) {
273  G4cout <<
274  "\nYou have successfully registered the following graphics systems."
275  << G4endl;
277  G4cout << G4endl;
278  }
279 
280  // Make command directories for commands instantiated in the
281  // modeling subcategory...
282  G4UIcommand* directory;
283  directory = new G4UIdirectory ("/vis/modeling/");
284  directory -> SetGuidance ("Modeling commands.");
285  fDirectoryList.push_back (directory);
286  directory = new G4UIdirectory ("/vis/modeling/trajectories/");
287  directory -> SetGuidance ("Trajectory model commands.");
288  fDirectoryList.push_back (directory);
289  directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
290  directory -> SetGuidance ("Create trajectory models and messengers.");
291  fDirectoryList.push_back (directory);
292 
293  // Filtering command directory
294  directory = new G4UIdirectory ("/vis/filtering/");
295  directory -> SetGuidance ("Filtering commands.");
296  fDirectoryList.push_back (directory);
297  directory = new G4UIdirectory ("/vis/filtering/trajectories/");
298  directory -> SetGuidance ("Trajectory filtering commands.");
299  fDirectoryList.push_back (directory);
300  directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
301  directory -> SetGuidance ("Create trajectory filters and messengers.");
302  fDirectoryList.push_back (directory);
303  directory = new G4UIdirectory ("/vis/filtering/hits/");
304  directory -> SetGuidance ("Hit filtering commands.");
305  fDirectoryList.push_back (directory);
306  directory = new G4UIdirectory ("/vis/filtering/hits/create/");
307  directory -> SetGuidance ("Create hit filters and messengers.");
308  fDirectoryList.push_back (directory);
309  directory = new G4UIdirectory ("/vis/filtering/digi/");
310  directory -> SetGuidance ("Digi filtering commands.");
311  fDirectoryList.push_back (directory);
312  directory = new G4UIdirectory ("/vis/filtering/digi/create/");
313  directory -> SetGuidance ("Create digi filters and messengers.");
314  fDirectoryList.push_back (directory);
315 
317 
318  if (fVerbosity >= startup) {
319  G4cout << "Registering model factories..." << G4endl;
320  }
321 
323 
324  if (fVerbosity >= startup) {
325  G4cout <<
326  "\nYou have successfully registered the following model factories."
327  << G4endl;
329  G4cout << G4endl;
330  }
331 
332  if (fVerbosity >= startup) {
334  G4cout << G4endl;
335  }
336 
337  if (fVerbosity >= startup) {
339  G4cout << G4endl;
340  }
341 
342  fInitialised = true;
343 }
344 
346 
347  // Instantiate individual messengers/commands (often - but not
348  // always - one command per messenger).
349 
350  G4UIcommand* directory;
351 
352  // *Basic* top level commands were instantiated in the constructor
353  // so that they can be used immediately after instantiation of the
354  // vis manager. Other top level and lower level commands are
355  // instantiated here.
356 
357  // Other top level commands...
362 
363  // Compound commands...
369 
370  directory = new G4UIdirectory ("/vis/geometry/");
371  directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
372  fDirectoryList.push_back (directory);
375 
376  directory = new G4UIdirectory ("/vis/geometry/set/");
377  directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
378  fDirectoryList.push_back (directory);
388 
389  directory = new G4UIdirectory ("/vis/set/");
390  directory -> SetGuidance
391  ("Set quantities for use in future commands where appropriate.");
392  fDirectoryList.push_back (directory);
398 
399  directory = new G4UIdirectory ("/vis/scene/");
400  directory -> SetGuidance ("Operations on Geant4 scenes.");
401  fDirectoryList.push_back (directory);
409 
410  directory = new G4UIdirectory ("/vis/scene/add/");
411  directory -> SetGuidance ("Add model to current scene.");
412  fDirectoryList.push_back (directory);
434 
435  directory = new G4UIdirectory ("/vis/sceneHandler/");
436  directory -> SetGuidance ("Operations on Geant4 scene handlers.");
437  fDirectoryList.push_back (directory);
442 
443  directory = new G4UIdirectory ("/vis/touchable/");
444  directory -> SetGuidance ("Operations on touchables.");
445  fDirectoryList.push_back (directory);
446  directory = new G4UIdirectory ("/vis/touchable/set/");
447  directory -> SetGuidance ("Set vis attributes of current touchable.");
448  fDirectoryList.push_back (directory);
450 
451  directory = new G4UIdirectory ("/vis/viewer/");
452  directory -> SetGuidance ("Operations on Geant4 viewers.");
453  fDirectoryList.push_back (directory);
474 
475  directory = new G4UIdirectory ("/vis/viewer/default/");
476  directory -> SetGuidance("Set default values for future viewers.");
477  fDirectoryList.push_back (directory);
480 
481  directory = new G4UIdirectory ("/vis/viewer/set/");
482  directory -> SetGuidance ("Set view parameters of current viewer.");
483  fDirectoryList.push_back (directory);
485 
486  // List manager commands
491 
492  // Trajectory filter manager commands
497 
498  // Hit filter manager commands
503 
504  // Digi filter manager commands
509 }
510 
512  if (IsValidView ()) {
513  SetConcreteInstance(this);
514  if (fVerbosity >= confirmations) {
515  G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
516  }
517  }
518  else {
519  if (fVerbosity >= warnings) {
520  G4cout <<
521  "G4VisManager::Enable: WARNING: visualization remains disabled for"
522  "\n above reasons. Rectifying with valid vis commands will"
523  "\n automatically enable."
524  << G4endl;
525  }
526  }
527 }
528 
531  if (fVerbosity >= confirmations) {
532  G4cout <<
533  "G4VisManager::Disable: visualization disabled."
534  "\n The pointer returned by GetConcreteInstance will be zero."
535  "\n Note that it will become enabled after some valid vis commands."
536  << G4endl;
537  }
538 }
539 
541  G4int nSystems = fAvailableGraphicsSystems.size ();
542  if (nSystems == 0) {
543  if (fVerbosity >= warnings) {
544  G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
545  "\n graphics system available!"
546  "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
547  "\n when you compiled/built the visualization code?"
548  "\n 2) Did you instantiate your own Visualization Manager and forget"
549  "\n to implement RegisterGraphicsSystems correctly?"
550  "\n 3) You can register your own graphics system, e.g.,"
551  "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
552  "\n after instantiating your vis manager and before"
553  "\n visManager->Initialize()."
554  << G4endl;
555  }
556  }
558 }
559 
561  G4bool happy = true;
562  if (pSystem) {
563  fAvailableGraphicsSystems.push_back (pSystem);
564  if (fVerbosity >= confirmations) {
565  G4cout << "G4VisManager::RegisterGraphicsSystem: "
566  << pSystem -> GetName ();
567  if (pSystem -> GetNickname () != "") {
568  G4cout << " (" << pSystem -> GetNickname () << ")";
569  }
570  G4cout << " registered." << G4endl;
571  }
572  }
573  else {
574  if (fVerbosity >= errors) {
575  G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!"
576  << G4endl;
577  }
578  happy=false;
579  }
580  return happy;
581 }
582 
583 const G4VTrajectoryModel*
585 {
586  assert (0 != fpTrajDrawModelMgr);
587 
589 
590  if (0 == model) {
591  // No model was registered with the trajectory model manager.
592  // Use G4TrajectoryDrawByCharge as a default.
594 
595  if (fVerbosity >= warnings) {
596  G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
597  G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
598  }
599  }
600 
601  model = fpTrajDrawModelMgr->Current();
602  assert (0 != model); // Should definitely exist now
603 
604  return model;
605 }
606 
608 {
610 }
611 
612 void
614 {
615  fpTrajDrawModelMgr->Register(factory);
616 }
617 
619 {
620  fpTrajFilterMgr->Register(model);
621 }
622 
623 void
625 {
626  fpTrajFilterMgr->Register(factory);
627 }
628 
630 {
631  fpHitFilterMgr->Register(model);
632 }
633 
634 void
636 {
637  fpHitFilterMgr->Register(factory);
638 }
639 
641 {
642  fpDigiFilterMgr->Register(model);
643 }
644 
645 void
647 {
648  fpDigiFilterMgr->Register(factory);
649 }
650 
652 {
654 }
655 
656 void G4VisManager::BeginDraw (const G4Transform3D& objectTransform)
657 {
658 #ifdef G4MULTITHREADED
659  if (G4Threading::IsWorkerThread()) return;
660 #endif
662  if (fDrawGroupNestingDepth > 1) {
664  ("G4VSceneHandler::BeginDraw",
665  "visman0008", JustWarning,
666  "Nesting detected. It is illegal to nest Begin/EndDraw."
667  "\n Ignored");
668  return;
669  }
670  if (IsValidView ()) {
672  fpSceneHandler -> BeginPrimitives (objectTransform);
673  fIsDrawGroup = true;
674  }
675 }
676 
678 {
679 #ifdef G4MULTITHREADED
680  if (G4Threading::IsWorkerThread()) return;
681 #endif
683  if (fDrawGroupNestingDepth != 0) {
685  return;
686  }
687  if (IsValidView ()) {
688  fpSceneHandler -> EndPrimitives ();
689  }
690  fIsDrawGroup = false;
691 }
692 
693 void G4VisManager::BeginDraw2D (const G4Transform3D& objectTransform)
694 {
695 #ifdef G4MULTITHREADED
696  if (G4Threading::IsWorkerThread()) return;
697 #endif
699  if (fDrawGroupNestingDepth > 1) {
701  ("G4VSceneHandler::BeginDraw2D",
702  "visman0009", JustWarning,
703  "Nesting detected. It is illegal to nest Begin/EndDraw2D."
704  "\n Ignored");
705  return;
706  }
707  if (IsValidView ()) {
709  fpSceneHandler -> BeginPrimitives2D (objectTransform);
710  fIsDrawGroup = true;
711  }
712 }
713 
715 {
716 #ifdef G4MULTITHREADED
717  if (G4Threading::IsWorkerThread()) return;
718 #endif
720  if (fDrawGroupNestingDepth != 0) {
722  return;
723  }
724  if (IsValidView ()) {
725  fpSceneHandler -> EndPrimitives2D ();
726  }
727  fIsDrawGroup = false;
728 }
729 
730 template <class T> void G4VisManager::DrawT
731 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
732 #ifdef G4MULTITHREADED
733  if (G4Threading::IsWorkerThread()) return;
734 #endif
735  if (fIsDrawGroup) {
736  if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
738  ("G4VSceneHandler::DrawT",
739  "visman0010", FatalException,
740  "Different transform detected in Begin/EndDraw group.");
741  }
742  fpSceneHandler -> AddPrimitive (graphics_primitive);
743  } else {
744  if (IsValidView ()) {
745  ClearTransientStoreIfMarked();
746  fpSceneHandler -> BeginPrimitives (objectTransform);
747  fpSceneHandler -> AddPrimitive (graphics_primitive);
748  fpSceneHandler -> EndPrimitives ();
749  }
750  }
751 }
752 
753 template <class T> void G4VisManager::DrawT2D
754 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
755 #ifdef G4MULTITHREADED
756  if (G4Threading::IsWorkerThread()) return;
757 #endif
758  if (fIsDrawGroup) {
759  if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
761  ("G4VSceneHandler::DrawT",
762  "visman0011", FatalException,
763  "Different transform detected in Begin/EndDraw2D group.");
764  }
765  fpSceneHandler -> AddPrimitive (graphics_primitive);
766  } else {
767  if (IsValidView ()) {
768  ClearTransientStoreIfMarked();
769  fpSceneHandler -> BeginPrimitives2D (objectTransform);
770  fpSceneHandler -> AddPrimitive (graphics_primitive);
771  fpSceneHandler -> EndPrimitives2D ();
772  }
773  }
774 }
775 
776 void G4VisManager::Draw (const G4Circle& circle,
777  const G4Transform3D& objectTransform)
778 {
779  DrawT (circle, objectTransform);
780 }
781 
782 void G4VisManager::Draw (const G4Polyhedron& polyhedron,
783  const G4Transform3D& objectTransform)
784 {
785  DrawT (polyhedron, objectTransform);
786 }
787 
788 void G4VisManager::Draw (const G4Polyline& line,
789  const G4Transform3D& objectTransform)
790 {
791  DrawT (line, objectTransform);
792 }
793 
794 void G4VisManager::Draw (const G4Polymarker& polymarker,
795  const G4Transform3D& objectTransform)
796 {
797  DrawT (polymarker, objectTransform);
798 }
799 
800 void G4VisManager::Draw (const G4Scale& scale,
801  const G4Transform3D& objectTransform)
802 {
803  DrawT (scale, objectTransform);
804 }
805 
806 void G4VisManager::Draw (const G4Square& square,
807  const G4Transform3D& objectTransform)
808 {
809  DrawT (square, objectTransform);
810 }
811 
812 void G4VisManager::Draw (const G4Text& text,
813  const G4Transform3D& objectTransform)
814 {
815  DrawT (text, objectTransform);
816 }
817 
818 void G4VisManager::Draw2D (const G4Circle& circle,
819  const G4Transform3D& objectTransform)
820 {
821  DrawT2D (circle, objectTransform);
822 }
823 
824 void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
825  const G4Transform3D& objectTransform)
826 {
827  DrawT2D (polyhedron, objectTransform);
828 }
829 
831  const G4Transform3D& objectTransform)
832 {
833  DrawT2D (line, objectTransform);
834 }
835 
836 void G4VisManager::Draw2D (const G4Polymarker& polymarker,
837  const G4Transform3D& objectTransform)
838 {
839  DrawT2D (polymarker, objectTransform);
840 }
841 
842 void G4VisManager::Draw2D (const G4Square& square,
843  const G4Transform3D& objectTransform)
844 {
845  DrawT2D (square, objectTransform);
846 }
847 
848 void G4VisManager::Draw2D (const G4Text& text,
849  const G4Transform3D& objectTransform)
850 {
851  DrawT2D (text, objectTransform);
852 }
853 
854 void G4VisManager::Draw (const G4VHit& hit) {
855 #ifdef G4MULTITHREADED
856  if (G4Threading::IsWorkerThread()) return;
857 #endif
858  if (fIsDrawGroup) {
859  fpSceneHandler -> AddCompound (hit);
860  } else {
861  if (IsValidView ()) {
863  fpSceneHandler -> AddCompound (hit);
864  }
865  }
866 }
867 
868 void G4VisManager::Draw (const G4VDigi& digi) {
869 #ifdef G4MULTITHREADED
870  if (G4Threading::IsWorkerThread()) return;
871 #endif
872  if (fIsDrawGroup) {
873  fpSceneHandler -> AddCompound (digi);
874  } else {
875  if (IsValidView ()) {
877  fpSceneHandler -> AddCompound (digi);
878  }
879  }
880 }
881 
882 void G4VisManager::Draw (const G4VTrajectory& traj) {
883 #ifdef G4MULTITHREADED
884  if (G4Threading::IsWorkerThread()) return;
885 #endif
886  if (fIsDrawGroup) {
887  fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
888  fpSceneHandler -> AddCompound (traj);
889  } else {
890  if (IsValidView ()) {
892  fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
893  fpSceneHandler -> AddCompound (traj);
894  }
895  }
896 }
897 
898 void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
899  const G4VisAttributes& attribs,
900  const G4Transform3D& objectTransform) {
901 #ifdef G4MULTITHREADED
902  if (G4Threading::IsWorkerThread()) return;
903 #endif
904  // Find corresponding solid.
905  G4VSolid* pSol = logicalVol.GetSolid ();
906  Draw (*pSol, attribs, objectTransform);
907 }
908 
909 void G4VisManager::Draw (const G4VSolid& solid,
910  const G4VisAttributes& attribs,
911  const G4Transform3D& objectTransform) {
912 #ifdef G4MULTITHREADED
913  if (G4Threading::IsWorkerThread()) return;
914 #endif
915  if (fIsDrawGroup) {
916  fpSceneHandler -> PreAddSolid (objectTransform, attribs);
918  fpSceneHandler -> PostAddSolid ();
919  } else {
920  if (IsValidView ()) {
922  fpSceneHandler -> PreAddSolid (objectTransform, attribs);
924  fpSceneHandler -> PostAddSolid ();
925  }
926  }
927 }
928 
929 void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
930  const G4VisAttributes& attribs,
931  const G4Transform3D& objectTransform) {
932  // Find corresponding logical volume and solid.
933 #ifdef G4MULTITHREADED
934  if (G4Threading::IsWorkerThread()) return;
935 #endif
936  G4LogicalVolume* pLV = physicalVol.GetLogicalVolume ();
937  G4VSolid* pSol = pLV -> GetSolid ();
938  Draw (*pSol, attribs, objectTransform);
939 }
940 
942  if (!fInitialised) Initialise ();
943  if (fpGraphicsSystem) {
944  G4VSceneHandler* pSceneHandler =
946  if (pSceneHandler) {
947  fAvailableSceneHandlers.push_back (pSceneHandler);
948  fpSceneHandler = pSceneHandler; // Make current.
949  }
950  else {
951  if (fVerbosity >= errors) {
952  G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
953  << fpGraphicsSystem -> GetName ()
954  << " scene handler creation.\n No action taken."
955  << G4endl;
956  }
957  }
958  }
959  else PrintInvalidPointers ();
960 }
961 
963 (const G4String& name, const G4String& XGeometry)
964 {
965 
966  if (!fInitialised) Initialise ();
967 
968  if (!fpSceneHandler) {
969  PrintInvalidPointers ();
970  return;
971  }
972 
973  G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
974 
975  if (!p) {
976  if (fVerbosity >= errors) {
977  G4cout << "ERROR in G4VisManager::CreateViewer during "
978  << fpGraphicsSystem -> GetName ()
979  << " viewer creation.\n No action taken."
980  << G4endl;
981  }
982  return;
983  }
984 
985  if (p -> GetViewId() < 0) {
986  if (fVerbosity >= errors) {
987  G4cout << "ERROR in G4VisManager::CreateViewer during "
988  << fpGraphicsSystem -> GetName ()
989  << " viewer initialisation.\n No action taken."
990  << G4endl;
991  }
992  return;
993  }
994 
995  // Viewer is created, now we can set geometry parameters
996  // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
997 
998  G4ViewParameters initialvp = p -> GetViewParameters();
999  initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
1000  p -> SetViewParameters(initialvp);
1001  p -> Initialise (); // (Viewer itself may change view parameters further.)
1002 
1003  fpViewer = p; // Make current.
1004  fpSceneHandler -> AddViewerToList (fpViewer);
1005  fpSceneHandler -> SetCurrentViewer (fpViewer);
1006  if (fVerbosity >= confirmations) {
1007  G4cout << "G4VisManager::CreateViewer: new viewer created."
1008  << G4endl;
1009  }
1010 
1011  const G4ViewParameters& vp = fpViewer->GetViewParameters();
1012  if (fVerbosity >= parameters) {
1013  G4cout << " view parameters are:\n " << vp << G4endl;
1014  }
1015 
1016  if (vp.IsCulling () && vp.IsCullingInvisible ()) {
1017  static G4bool warned = false;
1018  if (fVerbosity >= confirmations) {
1019  if (!warned) {
1020  G4cout <<
1021  "NOTE: objects with visibility flag set to \"false\""
1022  " will not be drawn!"
1023  "\n \"/vis/viewer/set/culling global false\" to Draw such objects."
1024  "\n Also see other \"/vis/viewer/set\" commands."
1025  << G4endl;
1026  warned = true;
1027  }
1028  }
1029  }
1030  if (vp.IsCullingCovered ()) {
1031  static G4bool warned = false;
1032  if (fVerbosity >= warnings) {
1033  if (!warned) {
1034  G4cout <<
1035  "WARNING: covered objects in solid mode will not be rendered!"
1036  "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1037  "\n Also see other \"/vis/viewer/set\" commands."
1038  << G4endl;
1039  warned = true;
1040  }
1041  }
1042  }
1043 }
1044 
1046  if (fVerbosity >= confirmations) {
1047  G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
1048  }
1049 
1050  // Change the world...
1051  G4VPhysicalVolume* pWorld =
1053  -> GetNavigatorForTracking () -> GetWorldVolume ();
1054  if (!pWorld) {
1055  if (fVerbosity >= warnings) {
1056  G4cout << "WARNING: There is no world volume!" << G4endl;
1057  }
1058  }
1059 
1060  // Check scenes.
1061  G4SceneList& sceneList = fSceneList;
1062  G4int iScene, nScenes = sceneList.size ();
1063  for (iScene = 0; iScene < nScenes; iScene++) {
1064  G4Scene* pScene = sceneList [iScene];
1065  std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1066  if (modelList.size ()) {
1067  G4bool modelInvalid;
1068  do { // Remove, if required, one at a time.
1069  modelInvalid = false;
1070  std::vector<G4Scene::Model>::iterator iterModel;
1071  for (iterModel = modelList.begin();
1072  iterModel != modelList.end();
1073  ++iterModel) {
1074  modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=warnings));
1075  if (modelInvalid) {
1076  // Model invalid - remove and break.
1077  if (fVerbosity >= warnings) {
1078  G4cout << "WARNING: Model \""
1079  << iterModel->fpModel->GetGlobalDescription ()
1080  <<
1081  "\" is no longer valid - being removed\n from scene \""
1082  << pScene -> GetName () << "\""
1083  << G4endl;
1084  }
1085  modelList.erase (iterModel);
1086  break;
1087  }
1088  }
1089  } while (modelInvalid);
1090 
1091  if (modelList.size () == 0) {
1092  if (fVerbosity >= warnings) {
1093  G4cout << "WARNING: No models left in this scene \""
1094  << pScene -> GetName ()
1095  << "\"."
1096  << G4endl;
1097  }
1098  }
1099  else {
1100  pScene->CalculateExtent();
1102  ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1103  }
1104  }
1105  }
1106 
1107  // Check the manager's current scene...
1108  if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1109  if (fVerbosity >= warnings) {
1110  G4cout << "WARNING: The current scene \""
1111  << fpScene -> GetName ()
1112  << "\" has no models."
1113  << G4endl;
1114  }
1115  }
1116 }
1117 
1119 
1120  if (fVerbosity >= confirmations) {
1121  G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
1122  }
1123 
1124  // Check scenes.
1125  G4SceneList& sceneList = fSceneList;
1126  G4int iScene, nScenes = sceneList.size ();
1127  for (iScene = 0; iScene < nScenes; iScene++) {
1128  G4Scene* pScene = sceneList [iScene];
1129  std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1130 
1131  if (modelList.size ()) {
1132  pScene->CalculateExtent();
1134  ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1135  }
1136  }
1137 
1138  // Check the manager's current scene...
1139  if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1140  if (fVerbosity >= warnings) {
1141  G4cout << "WARNING: The current scene \""
1142  << fpScene -> GetName ()
1143  << "\" has no models."
1144  << G4endl;
1145  }
1146  }
1147 }
1148 
1150 {
1151  return fpTrajFilterMgr->Accept(trajectory);
1152 }
1153 
1155 {
1156  return fpHitFilterMgr->Accept(hit);
1157 }
1158 
1160 {
1161  return fpDigiFilterMgr->Accept(digi);
1162 }
1163 
1165 {
1166  G4bool visible(true);
1167 
1168  // See if trajectory passes filter
1169  G4bool passed = FilterTrajectory(trajectory);
1170 
1171  if (!passed) {
1172  // Draw invisible trajectory if trajectory failed filter and
1173  // are filtering in soft mode
1174  if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
1175  else {return;}
1176  }
1177 
1178  // Go on to draw trajectory
1179  assert (0 != fpTrajDrawModelMgr);
1180 
1181  const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
1182 
1183  assert (0 != trajectoryModel); // Should exist
1184 
1185  if (IsValidView()) {
1186  trajectoryModel->Draw(trajectory, visible);
1187  }
1188 }
1189 
1191 (const G4String& name,
1192  G4VUserVisAction* pVisAction,
1193  const G4VisExtent& extent) {
1194  fRunDurationUserVisActions.push_back(UserVisAction(name,pVisAction));
1195  if (extent.GetExtentRadius() > 0.) {
1196  fUserVisActionExtents[pVisAction] = extent;
1197  } else {
1198  if (fVerbosity >= warnings) {
1199  G4cout <<
1200  "WARNING: No extent set for user vis action \"" << name << "\"."
1201  << G4endl;
1202  }
1203  }
1204 }
1205 
1207 (const G4String& name,
1208  G4VUserVisAction* pVisAction,
1209  const G4VisExtent& extent) {
1210  fEndOfEventUserVisActions.push_back(UserVisAction(name,pVisAction));
1211  if (extent.GetExtentRadius() > 0.) {
1212  fUserVisActionExtents[pVisAction] = extent;
1213  } else {
1214  if (fVerbosity >= warnings) {
1215  G4cout <<
1216  "WARNING: No extent set for user vis action \"" << name << "\"."
1217  << G4endl;
1218  }
1219  }
1220 }
1221 
1223 (const G4String& name,
1224  G4VUserVisAction* pVisAction,
1225  const G4VisExtent& extent) {
1226  fEndOfRunUserVisActions.push_back(UserVisAction(name,pVisAction));
1227  if (extent.GetExtentRadius() > 0.) {
1228  fUserVisActionExtents[pVisAction] = extent;
1229  } else {
1230  if (fVerbosity >= warnings) {
1231  G4cout <<
1232  "WARNING: No extent set for user vis action \"" << name << "\"."
1233  << G4endl;
1234  }
1235  }
1236 }
1237 
1239  if (pScene != fpScene) {
1240  // A change of scene. Therefore reset transients drawn flags. All
1241  // memory of previous transient proceessing thereby erased...
1243  }
1244  fpScene = pScene;
1245 }
1246 
1248  fpGraphicsSystem = pSystem;
1249  if (fVerbosity >= confirmations) {
1250  G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
1251  << pSystem -> GetName () << G4endl;
1252  }
1253  // If current scene handler is of same graphics system, leave unchanged.
1254  // Else find the most recent scene handler of same graphics system.
1255  // Or clear pointers.
1256  if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1257  const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
1258  G4int nSH = sceneHandlerList.size (); // No. of scene handlers.
1259  G4int iSH;
1260  for (iSH = nSH - 1; iSH >= 0; iSH--) {
1261  if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
1262  }
1263  if (iSH >= 0) {
1264  fpSceneHandler = sceneHandlerList [iSH];
1265  if (fVerbosity >= confirmations) {
1266  G4cout << " Scene Handler now "
1267  << fpSceneHandler -> GetName () << G4endl;
1268  }
1269  if (fpScene != fpSceneHandler -> GetScene ()) {
1270  fpScene = fpSceneHandler -> GetScene ();
1271  if (fVerbosity >= confirmations) {
1272  G4cout << " Scene now \""
1273  << fpScene -> GetName () << "\"" << G4endl;
1274  }
1275  }
1276  const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1277  if (viewerList.size ()) {
1278  fpViewer = viewerList [0];
1279  if (fVerbosity >= confirmations) {
1280  G4cout << " Viewer now " << fpViewer -> GetName () << G4endl;
1281  }
1282  }
1283  else {
1284  fpViewer = 0;
1285  }
1286  }
1287  else {
1288  fpSceneHandler = 0;
1289  fpViewer = 0;
1290  }
1291  }
1292 }
1293 
1295  fpSceneHandler = pSceneHandler;
1296  if (fVerbosity >= confirmations) {
1297  G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
1298  << pSceneHandler -> GetName () << "\"" << G4endl;
1299  }
1300  if (fpScene != fpSceneHandler -> GetScene ()) {
1301  fpScene = fpSceneHandler -> GetScene ();
1302  if (fVerbosity >= confirmations) {
1303  G4cout << " Scene now \""
1304  << fpScene -> GetName () << "\"" << G4endl;
1305  }
1306  }
1307  if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1308  fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1309  if (fVerbosity >= confirmations) {
1310  G4cout << " Graphics system now \""
1311  << fpGraphicsSystem -> GetName () << "\"" << G4endl;
1312  }
1313  }
1314  const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1315  G4int nViewers = viewerList.size ();
1316  if (nViewers) {
1317  G4int iViewer;
1318  for (iViewer = 0; iViewer < nViewers; iViewer++) {
1319  if (fpViewer == viewerList [iViewer]) break;
1320  }
1321  if (iViewer >= nViewers) {
1322  fpViewer = viewerList [0];
1323  if (fVerbosity >= confirmations) {
1324  G4cout << " Viewer now \"" << fpViewer -> GetName () << "\""
1325  << G4endl;
1326  }
1327  }
1328  if (!IsValidView ()) {
1329  if (fVerbosity >= warnings) {
1330  G4cout <<
1331  "WARNING: Problem setting scene handler - please report circumstances."
1332  << G4endl;
1333  }
1334  }
1335  }
1336  else {
1337  fpViewer = 0;
1338  if (fVerbosity >= warnings) {
1339  G4cout <<
1340  "WARNING: No viewers for this scene handler - please create one."
1341  << G4endl;
1342  }
1343  }
1344 }
1345 
1347  fpViewer = pViewer;
1348  if (fVerbosity >= confirmations) {
1349  G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1350  << pViewer -> GetName ()
1351  << G4endl;
1352  }
1353  fpSceneHandler = fpViewer -> GetSceneHandler ();
1354  fpSceneHandler -> SetCurrentViewer (pViewer);
1355  fpScene = fpSceneHandler -> GetScene ();
1356  fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1357  if (!IsValidView ()) {
1358  if (fVerbosity >= warnings) {
1359  G4cout <<
1360  "WARNING: Problem setting viewer - please report circumstances."
1361  << G4endl;
1362  }
1363  }
1364 }
1365 
1366 namespace {
1367  struct NicknameComparison {
1368  bool operator() (const G4String& lhs, const G4String& rhs) const
1369  {return lhs.length()<rhs.length();}
1370  };
1371 }
1372 
1374  G4int nSystems = fAvailableGraphicsSystems.size ();
1375  G4cout << "Current available graphics systems are:";
1376  if (nSystems) {
1377  // Make a map of graphics systems names (there may be repeated systems)
1378  // and for each name a set of nicknames. The nicknames are ordered
1379  // by length - see struct NicknameComparison above.
1380  std::map<G4String,std::set<G4String,NicknameComparison> > systemMap;
1381  for (G4int i = 0; i < nSystems; i++) {
1382  const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems[i];
1383  systemMap[pSystem->GetName()].insert(pSystem->GetNickname());
1384  }
1385  // Print the map.
1386  std::map<G4String,std::set<G4String,NicknameComparison> >::const_iterator i;
1387  for (i = systemMap.begin(); i != systemMap.end(); ++i) {
1388  G4cout << "\n " << i->first << " (";
1389  const std::set<G4String,NicknameComparison>& nicknames = i->second;
1390  std::set<G4String,NicknameComparison>::const_iterator j;
1391  for (j = nicknames.begin(); j != nicknames.end(); ++j) {
1392  if (j != nicknames.begin()) G4cout << ", ";
1393  G4cout << *j;
1394  }
1395  G4cout << ')';
1396  }
1397  }
1398  else {
1399  G4cout << "\n NONE!!! None registered - yet! Mmmmm!";
1400  }
1401  G4cout << G4endl;
1402 }
1403 
1405 {
1406  {
1407  //fpTrajDrawModelMgr->Print(G4cout);
1408  G4cout << "Registered model factories:" << G4endl;
1409  const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1411  if (factoryList.empty()) G4cout << " None" << G4endl;
1412  else {
1413  std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1414  for (i = factoryList.begin(); i != factoryList.end(); ++i)
1415  (*i)->Print(G4cout);
1416  }
1417  const G4VisListManager<G4VTrajectoryModel>* listManager =
1419  const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1420  listManager->Map();
1421  if (!modelMap.empty()) {
1422  G4cout << "\nRegistered models:" << G4endl;
1423  std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1424  for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1425  G4cout << " " << i->second->Name();
1426  if (i->second == listManager->Current()) G4cout << " (Current)";
1427  G4cout << G4endl;
1428  if (verbosity >= parameters) i->second->Print(G4cout);
1429  }
1430  }
1431  }
1432 
1433  G4cout << G4endl;
1434 
1435  {
1436  //fpTrajFilterMgr->Print(G4cout);
1437  G4cout << "Registered filter factories:" << G4endl;
1438  const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1439  factoryList = fpTrajFilterMgr->FactoryList();
1440  if (factoryList.empty()) G4cout << " None" << G4endl;
1441  else {
1442  std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1443  for (i = factoryList.begin(); i != factoryList.end(); ++i)
1444  (*i)->Print(G4cout);
1445  }
1446  const std::vector<G4VFilter<G4VTrajectory>*>&
1447  filterList = fpTrajFilterMgr->FilterList();
1448  if (!filterList.empty()) {
1449  G4cout << "\nRegistered filters:" << G4endl;
1450  std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1451  for (i = filterList.begin(); i != filterList.end(); ++i) {
1452  G4cout << " " << (*i)->GetName() << G4endl;
1453  if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1454  }
1455  }
1456  }
1457 }
1458 
1460 {
1461  G4cout <<
1462  "You have successfully registered the following user vis actions."
1463  << G4endl;
1464  G4cout << "Run Duration User Vis Actions:";
1465  if (fRunDurationUserVisActions.empty()) G4cout << " none" << G4endl;
1466  else {
1467  G4cout << G4endl;
1468  for (size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
1469  const G4String& name = fRunDurationUserVisActions[i].fName;
1470  G4cout << " " << name << G4endl;
1471  }
1472  }
1473 
1474  G4cout << "End of Event User Vis Actions:";
1475  if (fEndOfEventUserVisActions.empty()) G4cout << " none" << G4endl;
1476  else {
1477  G4cout << G4endl;
1478  for (size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
1479  const G4String& name = fEndOfEventUserVisActions[i].fName;
1480  G4cout << " " << name << G4endl;
1481  }
1482  }
1483 
1484  G4cout << "End of Run User Vis Actions:";
1485  if (fEndOfRunUserVisActions.empty()) G4cout << " none" << G4endl;
1486  else {
1487  G4cout << G4endl;
1488  for (size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
1489  const G4String& name = fEndOfRunUserVisActions[i].fName;
1490  G4cout << " " << name << G4endl;
1491  }
1492  }
1493 }
1494 
1496  G4cout <<
1497  "Some /vis commands (optionally) take a string to specify colour."
1498  "\nAvailable colours:\n ";
1499  const std::map<G4String, G4Colour>& map = G4Colour::GetMap();
1500  for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1501  i != map.end();) {
1502  G4cout << i->first;
1503  if (++i != map.end()) G4cout << ", ";
1504  }
1505  G4cout << G4endl;
1506 }
1507 
1509  if (fVerbosity >= errors) {
1510  G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
1511  if (!fpGraphicsSystem) {
1512  G4cout << "\n null graphics system pointer.";
1513  }
1514  else {
1515  G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName ()
1516  << " but:";
1517  if (!fpScene)
1518  G4cout <<
1519  "\n Null scene pointer. Use \"/vis/drawVolume\" or"
1520  " \"/vis/scene/create\".";
1521  if (!fpSceneHandler)
1522  G4cout <<
1523  "\n Null scene handler pointer. Use \"/vis/open\" or"
1524  " \"/vis/sceneHandler/create\".";
1525  if (!fpViewer )
1526  G4cout <<
1527  "\n Null viewer pointer. Use \"/vis/viewer/create\".";
1528  }
1529  G4cout << G4endl;
1530  }
1531 }
1532 
1533 #ifdef G4MULTITHREADED
1534 // Start of multithreaded versions of Begin/EndOfRun/Event.
1535 
1536 #include "G4Threading.hh"
1537 #include "G4AutoLock.hh"
1538 namespace {
1539 // G4Mutex visBeginOfRunMutex = G4MUTEX_INITIALIZER;
1540 // G4Mutex visBeginOfEventMutex = G4MUTEX_INITIALIZER;
1541  G4Mutex visEndOfEventMutex = G4MUTEX_INITIALIZER;
1542 // G4Mutex visEndOfRunMutex = G4MUTEX_INITIALIZER;
1543 }
1544 
1546 {
1547  if (fIgnoreStateChanges) return;
1548  if (G4Threading::IsWorkerThread()) return;
1549  fNKeepRequests = 0;
1550  fKeptLastEvent = false;
1551  fEventKeepingSuspended = false;
1552  fTransientsDrawnThisRun = false;
1554 }
1555 
1557 {
1558  if (fIgnoreStateChanges) return;
1559 }
1560 
1562 {
1563  if (fIgnoreStateChanges) return;
1564 
1565  if (!GetConcreteInstance()) return;
1566 
1567  // Don't call IsValidView unless there is a scene handler. This
1568  // avoids WARNING message at end of event and run when the user has
1569  // not instantiated a scene handler, e.g., in batch mode.
1570  G4bool valid = fpSceneHandler && IsValidView();
1571  if (!valid) return;
1572 
1573  G4AutoLock al(&visEndOfEventMutex);
1574 
1575  if (!fEventKeepingSuspended) {
1576 
1578 // const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1579 // if (!currentEvent) return;
1580 
1581 // G4RunManager* runManager = G4RunManager::GetRunManager();
1582 // const G4Run* currentRun = runManager->GetCurrentRun();
1583 // if (!currentRun) return;
1584 //
1585 // const std::vector<const G4Event*>*
1586 // eventsFromThreads = currentRun->GetEventVector();
1587 // G4int nKeptEvents = eventsFromThreads ? eventsFromThreads->size() : 0;
1588 
1589  G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1590  if (maxNumberOfKeptEvents > 0 && fNKeepRequests >= maxNumberOfKeptEvents) {
1591  fEventKeepingSuspended = true;
1592  static G4bool warned = false;
1593  if (!warned) {
1594  if (fVerbosity >= warnings) {
1595  G4cout <<
1596  "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1597  "\n The number of events exceeds the maximum, "
1598  << maxNumberOfKeptEvents <<
1599  ", that may be kept by \n the vis manager."
1600  << G4endl;
1601  }
1602  warned = true;
1603  }
1604  } else if (maxNumberOfKeptEvents != 0) {
1605 // G4cout << "Requesting keeping event " << currentEvent->GetEventID() << G4endl;
1606  eventManager->KeepTheCurrentEvent();
1607  fNKeepRequests++;
1608  }
1609  }
1610 }
1611 
1612 void G4VisManager::EndOfRun ()
1613 {
1614  if (fIgnoreStateChanges) return;
1615 
1616  if (G4Threading::IsWorkerThread()) return;
1617 
1618  // Don't call IsValidView unless there is a scene handler. This
1619  // avoids WARNING message at end of event and run when the user has
1620  // not instantiated a scene handler, e.g., in batch mode.
1621  G4bool valid = fpSceneHandler && IsValidView();
1622  if (!valid) return;
1623 
1624  // G4AutoLock al(&visEndOfRunMutex);
1625 
1626  G4RunManager* runManager = G4RunManager::GetRunManager();
1627  const G4Run* currentRun = runManager->GetCurrentRun();
1628  if (!currentRun) return;
1629 
1630  const std::vector<const G4Event*>*
1631  eventsFromThreads = currentRun->GetEventVector();
1632  G4int nKeptEvents = eventsFromThreads ? eventsFromThreads->size() : 0;
1633  if (nKeptEvents) {
1634  if (fVerbosity >= warnings) {
1635  G4cout << "WARNING: " << nKeptEvents;
1636  if (nKeptEvents == 1) G4cout << " event has";
1637  else G4cout << " events have";
1638  G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1639  if (nKeptEvents != fNKeepRequests) {
1640  G4cout << " (Note: ";
1641  if (fNKeepRequests == 0) {
1642  G4cout << "No keep requests were";
1643  } else if (fNKeepRequests == 1) {
1644  G4cout << "Only 1 keep request was";
1645  } else {
1646  G4cout << "Only " << fNKeepRequests << " keep requests were";
1647  }
1648  G4cout << " made by the vis manager.)" << G4endl;
1649  }
1650  G4cout << " \"/vis/reviewKeptEvents\" to review them." << G4endl;
1651  }
1652  }
1653 
1655  G4cout <<
1656  "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
1657  "\n The number of events in the run exceeded the maximum, "
1659  ", that may be\n kept by the vis manager." <<
1660  "\n The number of events kept by the vis manager can be changed with"
1661  "\n \"/vis/scene/endOfEventAction [accumulate|refresh] <N>\", where N"
1662  "\n is the maximum number you wish to allow. N < 0 means \"unlimited\"."
1663  << G4endl;
1664  }
1665 
1666  if (GetConcreteInstance() && eventsFromThreads) {
1667  std::vector<const G4Event*>::const_iterator i;
1669  for (i = eventsFromThreads->begin(); i != eventsFromThreads->end(); ++i) {
1670  if (fVerbosity >= confirmations) {
1671  G4cout << "Drawing event " << (*i)->GetEventID() << G4endl;
1672  }
1673 
1674  // We are about to draw the event (trajectories, etc.), but first we
1675  // have to clear the previous event(s) if necessary. If this event
1676  // needs to be drawn afresh, e.g., the first event or any event when
1677  // "accumulate" is not requested, the old event has to be cleared.
1678  // We have postponed this so that, for normal viewers like OGL, the
1679  // previous event(s) stay on screen until this new event comes
1680  // along. For a file-writing viewer the geometry has to be drawn.
1681  // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
1682  // But, for this stop-gap solution...
1683  // Deactivate end-of-event and end-of-run models...
1684  G4Scene* scene = fpSceneHandler->GetScene();
1685  std::vector<G4Scene::Model>& eoeModels = scene->SetEndOfEventModelList();
1686  std::vector<G4Scene::Model> tmpEoeModels = eoeModels;
1687  std::vector<G4Scene::Model>::iterator iEoe;
1688  for (iEoe = eoeModels.begin(); iEoe != eoeModels.end(); ++iEoe) {
1689  iEoe->fActive = false;
1690  }
1691  std::vector<G4Scene::Model>& eorModels = scene->SetEndOfRunModelList();
1692  std::vector<G4Scene::Model> tmpEorModels = eorModels;
1693  std::vector<G4Scene::Model>::iterator iEor;
1694  for (iEor = eoeModels.begin(); iEor != eoeModels.end(); ++iEor) {
1695  iEor->fActive = false;
1696  }
1698  // ...and restore...
1699  eoeModels = tmpEoeModels;
1700  eorModels = tmpEorModels;
1701 
1702  fTransientsDrawnThisEvent = false;
1705  // ShowView guarantees the view comes to the screen. No action
1706  // is taken for passive viewers like OGL*X, but it passes control to
1707  // interactive viewers, such OGL*Xm and allows file-writing
1708  // viewers to close the file.
1709  fpViewer->ShowView();
1711  }
1712 
1713  } else { // Accumulate events.
1714 
1715  // We are about to draw the event (trajectories, etc.), but first we
1716  // have to clear the previous event(s) if necessary. If this event
1717  // needs to be drawn afresh, e.g., the first event or any event when
1718  // "accumulate" is not requested, the old event has to be cleared.
1719  // We have postponed this so that, for normal viewers like OGL, the
1720  // previous event(s) stay on screen until this new event comes
1721  // along. For a file-writing viewer the geometry has to be drawn.
1722  // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
1723  // But, for this stop-gap solution...
1724  // Deactivate end-of-event and end-of-run models...
1725  G4Scene* scene = fpSceneHandler->GetScene();
1726  std::vector<G4Scene::Model>& eoeModels = scene->SetEndOfEventModelList();
1727  std::vector<G4Scene::Model> tmpEoeModels = eoeModels;
1728  std::vector<G4Scene::Model>::iterator iEoe;
1729  for (iEoe = eoeModels.begin(); iEoe != eoeModels.end(); ++iEoe) {
1730  iEoe->fActive = false;
1731  }
1732  std::vector<G4Scene::Model>& eorModels = scene->SetEndOfRunModelList();
1733  std::vector<G4Scene::Model> tmpEorModels = eorModels;
1734  std::vector<G4Scene::Model>::iterator iEor;
1735  for (iEor = eoeModels.begin(); iEor != eoeModels.end(); ++iEor) {
1736  iEor->fActive = false;
1737  }
1739  // ...and restore...
1740  eoeModels = tmpEoeModels;
1741  eorModels = tmpEorModels;
1742 
1743  fTransientsDrawnThisEvent = false;
1745  for (i = eventsFromThreads->begin(); i != eventsFromThreads->end(); ++i) {
1746  if (fVerbosity >= confirmations) {
1747  G4cout << "Drawing event " << (*i)->GetEventID() << G4endl;
1748  }
1750  }
1751  if (fpScene->GetRefreshAtEndOfRun()) {
1753  fpViewer->ShowView();
1754  // An extra refresh for auto-refresh viewers
1756  fpViewer->RefreshView();
1757  }
1759  }
1760  }
1761  }
1762 }
1763 
1764 // End of multithreaded versions of Begin/EndOfRun/Event.
1765 #else
1766 // Start of sequential versions of Begin/EndOfRun/Event.
1767 
1769 {
1770  if (fIgnoreStateChanges) return;
1771  //G4cout << "G4VisManager::BeginOfRun" << G4endl;
1772  fNKeepRequests = 0;
1773  fKeptLastEvent = false;
1774  fEventKeepingSuspended = false;
1775  fTransientsDrawnThisRun = false;
1777 }
1778 
1780 {
1781  if (fIgnoreStateChanges) return;
1782  //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
1783  fTransientsDrawnThisEvent = false;
1785 }
1786 
1788 {
1789  if (fIgnoreStateChanges) return;
1790 
1791  if (!GetConcreteInstance()) return;
1792 
1793  // Don't call IsValidView unless there is a scene handler. This
1794  // avoids WARNING message at end of event and run when the user has
1795  // not instantiated a scene handler, e.g., in batch mode.
1796  G4bool valid = fpSceneHandler && IsValidView();
1797  if (!valid) return;
1798 
1800  const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
1801  if (!currentEvent) return;
1802 
1803  G4RunManager* runManager = G4RunManager::GetRunManager();
1804  const G4Run* currentRun = runManager->GetCurrentRun();
1805  if (!currentRun) return;
1806 
1807  //G4cout << "G4VisManager::EndOfEvent" << G4endl;
1808 
1809  // We are about to draw the event (trajectories, etc.), but first we
1810  // have to clear the previous event(s) if necessary. If this event
1811  // needs to be drawn afresh, e.g., the first event or any event when
1812  // "accumulate" is not requested, the old event has to be cleared.
1813  // We have postponed this so that, for normal viewers like OGL, the
1814  // previous event(s) stay on screen until this new event comes
1815  // along. For a file-writing viewer the geometry has to be drawn.
1816  // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
1818 
1819  // Now draw the event...
1820  fpSceneHandler->DrawEvent(currentEvent);
1821 
1822  G4int nEventsToBeProcessed = 0;
1823  G4int nKeptEvents = 0;
1824  G4int eventID = -2; // (If no run manager, triggers ShowView as normal.)
1825  if (currentRun) {
1826  nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
1827  eventID = currentEvent->GetEventID();
1828  const std::vector<const G4Event*>* events =
1829  currentRun->GetEventVector();
1830  if (events) nKeptEvents = events->size();
1831  }
1832 
1834 
1835  // Unless last event (in which case wait end of run)...
1836  if (eventID < nEventsToBeProcessed - 1) {
1837  // ShowView guarantees the view comes to the screen. No action
1838  // is taken for passive viewers like OGL*X, but it passes control to
1839  // interactive viewers, such OGL*Xm and allows file-writing
1840  // viewers to close the file.
1841  fpViewer->ShowView();
1843  } else { // Last event...
1844  // Keep, but only if user has not kept any...
1845  if (!nKeptEvents) {
1846  eventManager->KeepTheCurrentEvent();
1847  fNKeepRequests++;
1848  fKeptLastEvent = true;
1849  }
1850  }
1851 
1852  } else { // Accumulating events...
1853 
1854  G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
1855  if (maxNumberOfKeptEvents > 0 && fNKeepRequests >= maxNumberOfKeptEvents) {
1856  fEventKeepingSuspended = true;
1857  static G4bool warned = false;
1858  if (!warned) {
1859  if (fVerbosity >= warnings) {
1860  G4cout <<
1861  "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
1862  "\n The number of events exceeds the maximum, "
1863  << maxNumberOfKeptEvents <<
1864  ", that may be kept by\n the vis manager."
1865  << G4endl;
1866  }
1867  warned = true;
1868  }
1869  } else if (maxNumberOfKeptEvents != 0) {
1870  // If not disabled nor suspended.
1872 // G4cout << "Requesting keeping event " << currentEvent->GetEventID() << G4endl;
1873  eventManager->KeepTheCurrentEvent();
1874  fNKeepRequests++;
1875  }
1876  }
1877  }
1878 }
1879 
1881 {
1882  if (fIgnoreStateChanges) return;
1883  //G4cout << "G4VisManager::EndOfRun" << G4endl;
1884 
1885  G4RunManager* runManager = G4RunManager::GetRunManager();
1886  const G4Run* currentRun = runManager->GetCurrentRun();
1887 
1888  G4int nKeptEvents = 0;
1889  const std::vector<const G4Event*>* events =
1890  currentRun? currentRun->GetEventVector(): 0;
1891  if (events) nKeptEvents = events->size();
1892 
1893  if (nKeptEvents && !fKeptLastEvent) {
1894  if (fVerbosity >= warnings) {
1895  G4cout << "WARNING: " << nKeptEvents;
1896  if (nKeptEvents == 1) G4cout << " event has";
1897  else G4cout << " events have";
1898  G4cout << " been kept for refreshing and/or reviewing." << G4endl;
1899  if (nKeptEvents != fNKeepRequests) {
1900  G4cout << " (Note: ";
1901  if (fNKeepRequests == 0) {
1902  G4cout << "No keep requests were";
1903  } else if (fNKeepRequests == 1) {
1904  G4cout << "Only 1 keep request was";
1905  } else {
1906  G4cout << "Only " << fNKeepRequests << " keep requests were";
1907  }
1908  G4cout << " made by the vis manager.)" << G4endl;
1909  }
1910  G4cout << " \"/vis/reviewKeptEvents\" to review them." << G4endl;
1911  }
1912  // static G4bool warned = false;
1913  // if (!valid && fVerbosity >= warnings && !warned) {
1914  // G4cout <<
1915  // " Only useful if before starting the run:"
1916  // "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
1917  // "\n b) the Draw method of any hits or digis is implemented."
1918  // "\n To view trajectories, hits or digis:"
1919  // "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
1920  // "\n \"/vis/scene/add/hits\" or \"/vis/scene/add/digitisations\""
1921  // "\n and, possibly, \"/vis/viewer/flush\"."
1922  // "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"."
1923  // "\n To see events individually: \"/vis/reviewKeptEvents\"."
1924  // << G4endl;
1925  // warned = true;
1926  // }
1927  }
1928 
1930  G4cout <<
1931  "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
1932  "\n The number of events in the run exceeded the maximum, "
1934  ", that may be\n kept by the vis manager." <<
1935  "\n The number of events kept by the vis manager can be changed with"
1936  "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
1937  "\n maximum number you wish to allow. N < 0 means \"unlimited\"."
1938  << G4endl;
1939  }
1940 
1941  // Don't call IsValidView unless there is a scene handler. This
1942  // avoids WARNING message at end of event and run when the user has
1943  // not instantiated a scene handler, e.g., in batch mode.
1944  G4bool valid = fpSceneHandler && IsValidView();
1945  if (GetConcreteInstance() && valid) {
1947  if (fpScene->GetRefreshAtEndOfRun()) {
1949  // ShowView guarantees the view comes to the screen. No action
1950  // is taken for passive viewers like OGL*X, but it passes control to
1951  // interactive viewers, such OGL*Xm and allows file-writing
1952  // viewers to close the file.
1953  fpViewer->ShowView();
1954  // An extra refresh for auto-refresh viewers
1956  fpViewer->RefreshView();
1957  }
1959  }
1960  }
1961  }
1962  fEventRefreshing = false;
1963 }
1964 
1965 #endif // End of sequential versions of Begin/EndOfRun/Event.
1966 
1968  // Assumes valid view.
1972  }
1973  // Record if transients drawn. These local flags are only set
1974  // *after* ClearTransientStore. In the code in G4VSceneHandler
1975  // triggered by ClearTransientStore, use these flags so that
1976  // event refreshing is not done too early.
1979 }
1980 
1982 {
1983  fTransientsDrawnThisRun = false;
1984  fTransientsDrawnThisEvent = false;
1986  for (i = fAvailableSceneHandlers.begin();
1987  i != fAvailableSceneHandlers.end(); ++i) {
1988  (*i)->SetTransientsDrawnThisEvent(false);
1989  (*i)->SetTransientsDrawnThisRun(false);
1990  }
1991 }
1992 
1994  G4String viewerShortName (viewerName);
1995  viewerShortName = viewerShortName (0, viewerShortName.find (' '));
1996  return viewerShortName.strip ();
1997 }
1998 
1999 G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
2000  G4String viewerShortName = ViewerShortName (viewerName);
2001  size_t nHandlers = fAvailableSceneHandlers.size ();
2002  size_t iHandler, iViewer;
2003  G4VViewer* viewer = 0;
2004  G4bool found = false;
2005  for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2006  G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
2007  const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2008  for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2009  viewer = viewerList [iViewer];
2010  if (viewerShortName == viewer -> GetShortName ()) {
2011  found = true;
2012  break;
2013  }
2014  }
2015  if (found) break;
2016  }
2017  if (found) return viewer;
2018  else return 0;
2019 }
2020 
2021 std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
2022 
2024  G4String rs;
2025  switch (verbosity) {
2026  case quiet: rs = "quiet (0)"; break;
2027  case startup: rs = "startup (1)"; break;
2028  case errors: rs = "errors (2)"; break;
2029  case warnings: rs = "warnings (3)"; break;
2030  case confirmations: rs = "confirmations (4)"; break;
2031  case parameters: rs = "parameters (5)"; break;
2032  case all: rs = "all (6)"; break;
2033  }
2034  return rs;
2035 }
2036 
2039  G4String ss(verbosityString); ss.toLower();
2040  Verbosity verbosity;
2041  if (ss(0) == 'q') verbosity = quiet;
2042  else if (ss(0) == 's') verbosity = startup;
2043  else if (ss(0) == 'e') verbosity = errors;
2044  else if (ss(0) == 'w') verbosity = warnings;
2045  else if (ss(0) == 'c') verbosity = confirmations;
2046  else if (ss(0) == 'p') verbosity = parameters;
2047  else if (ss(0) == 'a') verbosity = all;
2048  else {
2049  G4int intVerbosity;
2050  std::istringstream is(ss);
2051  is >> intVerbosity;
2052  if (!is) {
2053  G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2054  << verbosityString << "\"";
2055  for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
2056  G4cout << '\n' << VerbosityGuidanceStrings[i];
2057  }
2058  verbosity = warnings;
2059  G4cout << "\n Returning " << VerbosityString(verbosity)
2060  << G4endl;
2061  }
2062  else {
2063  verbosity = GetVerbosityValue(intVerbosity);
2064  }
2065  }
2066  return verbosity;
2067 }
2068 
2070  Verbosity verbosity;
2071  if (intVerbosity < quiet) verbosity = quiet;
2072  else if (intVerbosity > all) verbosity = all;
2073  else verbosity = Verbosity(intVerbosity);
2074  return verbosity;
2075 }
2076 
2078  return fVerbosity;
2079 }
2080 
2082  fVerbosity = GetVerbosityValue(intVerbosity);
2083 }
2084 
2085 void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
2086  fVerbosity = GetVerbosityValue(verbosityString);
2087 }
2088 
2090 
2091  if (!fInitialised) Initialise ();
2092 
2093  static G4bool noGSPrinting = true;
2094  if (!fpGraphicsSystem) {
2095  // Limit printing - we do not want printing if the user simply does
2096  // not want to use graphics, e.g., in batch mode.
2097  if (noGSPrinting) {
2098  noGSPrinting = false;
2099  if (fVerbosity >= warnings) {
2100  G4cout <<
2101  "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2102  "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2103  "\n Alternatively, to avoid this message, suppress instantiation of vis"
2104  "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
2105  "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()"
2106  "\n is non-zero."
2107  << G4endl;
2108  }
2109  }
2110  return false;
2111  }
2112 
2113  if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2114  if (fVerbosity >= errors) {
2115  G4cout <<
2116  "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2117  << G4endl;
2119  }
2120  return false;
2121  }
2122 
2123  if (fpScene != fpSceneHandler -> GetScene ()) {
2124  if (fVerbosity >= errors) {
2125  G4cout << "ERROR: G4VisManager::IsValidView ():";
2126  if (fpSceneHandler -> GetScene ()) {
2127  G4cout <<
2128  "\n The current scene \""
2129  << fpScene -> GetName ()
2130  << "\" is not handled by"
2131  "\n the current scene handler \""
2132  << fpSceneHandler -> GetName ()
2133  << "\""
2134  "\n (it currently handles scene \""
2135  << fpSceneHandler -> GetScene () -> GetName ()
2136  << "\")."
2137  "\n Either:"
2138  "\n (a) attach it to the scene handler with"
2139  "\n /vis/sceneHandler/attach "
2140  << fpScene -> GetName ()
2141  << ", or"
2142  "\n (b) create a new scene handler with "
2143  "\n /vis/sceneHandler/create <graphics-system>,"
2144  "\n in which case it should pick up the the new scene."
2145  << G4endl;
2146  }
2147  else {
2148  G4cout << "\n Scene handler \""
2149  << fpSceneHandler -> GetName ()
2150  << "\" has null scene pointer."
2151  "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2152  << G4endl;
2153  }
2154  }
2155  return false;
2156  }
2157 
2158  const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2159  if (viewerList.size () == 0) {
2160  if (fVerbosity >= errors) {
2161  G4cout <<
2162  "ERROR: G4VisManager::IsValidView (): the current scene handler\n \""
2163  << fpSceneHandler -> GetName ()
2164  << "\" has no viewers. Do /vis/viewer/create."
2165  << G4endl;
2166  }
2167  return false;
2168  }
2169 
2170  G4bool isValid = true;
2171  if (fpScene -> IsEmpty ()) { // Add world by default if possible...
2172  G4bool warn(fVerbosity >= warnings);
2173  G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2174  if (!successful || fpScene -> IsEmpty ()) { // If still empty...
2175  if (fVerbosity >= errors) {
2176  G4cout << "ERROR: G4VisManager::IsViewValid ():";
2177  G4cout <<
2178  "\n Attempt at some drawing operation when scene is empty."
2179  "\n Maybe the geometry has not yet been defined."
2180  " Try /run/initialize."
2181  << G4endl;
2182  }
2183  isValid = false;
2184  }
2185  else {
2186  G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
2187  if (fVerbosity >= warnings) {
2188  G4cout <<
2189  "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2190  "\n added and the scene handlers notified.";
2191  G4cout << G4endl;
2192  }
2193  }
2194  }
2195  return isValid;
2196 }
2197 
2198 void
2200 {
2201  if (fVerbosity >= warnings) {
2202  G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
2203  G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
2204  G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
2205  }
2206 }
2207 
2208 #ifdef G4MULTITHREADED
2209 void G4VisManager::SetUpForAThread()
2210 {
2211  new G4VisStateDependent(this);
2212 }
2213 #endif
2214 
2216 {
2217  fIgnoreStateChanges = val;
2218 }
G4bool FilterDigi(const G4VDigi &)
void Initialise()
void RegisterEndOfEventUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void RegisterModelFactory(G4TrajDrawModelFactory *factory)
G4VisFilterManager< G4VTrajectory > * fpTrajFilterMgr
Definition: G4Text.hh:73
static Verbosity fVerbosity
const std::vector< Factory * > & FactoryList() const
void PrintAvailableColours(Verbosity) const
G4VisFilterManager< G4VHit > * fpHitFilterMgr
void PrintAvailableUserVisActions(Verbosity) const
virtual void RegisterModelFactories()
void PrintAvailableModels(Verbosity) const
void SetCurrentSceneHandler(G4VSceneHandler *)
G4TrajectoriesModel dummyTrajectoriesModel
static G4VVisManager * GetConcreteInstance()
G4String strip(G4int strip_Type=trailing, char c=' ')
G4bool IsCullingInvisible() const
virtual void ShowView()
Definition: G4VViewer.cc:113
G4String name
Definition: TRTMaterials.hh:40
void RegisterEndOfRunUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
G4VisStateDependent * fpStateDependent
void PrintInvalidPointers() const
#define assert(x)
Definition: mymalloc.cc:1309
void SetVerboseLevel(G4int)
const G4ViewParameters & GetViewParameters() const
G4int fNKeepRequests
void GeometryHasChanged()
const std::vector< const G4Event * > * GetEventVector() const
Definition: G4Run.hh:115
const Model * Current() const
Definition: G4VHit.hh:48
void SetCurrentScene(G4Scene *)
std::vector< Model > & SetEndOfRunModelList()
G4bool GetMarkForClearingTransientStore() const
G4bool GetRefreshAtEndOfEvent() const
static std::vector< G4String > VerbosityGuidanceStrings
const G4String & GetName() const
int G4int
Definition: G4Types.hh:78
static Verbosity GetVerbosityValue(const G4String &)
const G4Run * GetCurrentRun() const
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:158
void EndDraw2D()
void BeginDraw(const G4Transform3D &objectTransformation=G4Transform3D())
const G4VTrajectoryModel * CurrentTrajDrawModel() const
G4bool fTransientsDrawnThisEvent
const std::vector< Filter * > & FilterList() const
std::vector< G4UIcommand * > fDirectoryList
G4bool IsValidView()
std::vector< G4UImessenger * > fMessengerList
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
void RegisterMessengers()
G4int GetEventID() const
Definition: G4Event.hh:140
std::vector< G4VSceneHandler * >::const_iterator G4SceneHandlerListConstIterator
static G4VisManager * fpInstance
G4String Placement() const
void RegisterMessenger(G4UImessenger *messenger)
void SelectTrajectoryModel(const G4String &model)
G4VSceneHandler * fpSceneHandler
void PrintAvailableGraphicsSystems() const
void SetTransientsDrawnThisEvent(G4bool)
std::vector< UserVisAction > fEndOfRunUserVisActions
G4double GetExtentRadius() const
Definition: G4VisExtent.cc:73
G4int fDrawGroupNestingDepth
virtual void IgnoreStateChanges(G4bool)
G4bool fEventKeepingSuspended
G4String ViewerShortName(const G4String &viewerName) const
friend class G4VisStateDependent
G4GLOB_DLL std::ostream G4cout
std::vector< UserVisAction > fRunDurationUserVisActions
bool Accept(const T &)
G4VisModelManager< G4VTrajectoryModel > * fpTrajDrawModelMgr
void Register(Model *)
G4SceneHandlerList fAvailableSceneHandlers
const std::map< G4String, T * > & Map() const
bool G4bool
Definition: G4Types.hh:79
G4bool FilterTrajectory(const G4VTrajectory &)
virtual void Draw(const G4VTrajectory &trajectory, const G4bool &visible=true) const =0
G4bool GetRefreshAtEndOfRun() const
void ResetTransientsDrawnFlags()
G4bool GetTransientsDrawnThisRun() const
static G4VisManager * GetInstance()
Definition: G4Run.hh:46
void SetCurrentGraphicsSystem(G4VGraphicsSystem *)
void SetXGeometryString(const G4String &)
const T * Current() const
HepGeom::Transform3D G4Transform3D
G4bool GetTransientsDrawnThisEvent() const
G4Scene * fpScene
G4bool IsCullingCovered() const
virtual ~G4VisManager()
void CalculateExtent()
Definition: G4Scene.cc:72
G4VisFilterManager< G4VDigi > * fpDigiFilterMgr
void toLower()
const G4String & GetNickname() const
G4String Placement() const
G4bool fEventRefreshing
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4bool IsWorkerThread()
Definition: G4Threading.cc:104
static G4TransportationManager * GetTransportationManager()
void RegisterRunDurationUserVisAction(const G4String &name, G4VUserVisAction *, const G4VisExtent &=G4VisExtent::NullExtent)
void SetCurrentViewer(G4VViewer *)
virtual void DescribeYourselfTo(G4VGraphicsScene &scene) const =0
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:74
G4int G4Mutex
Definition: G4Threading.hh:156
G4Scene * GetScene() const
void SetCurrent(const G4String &)
G4GraphicsSystemList fAvailableGraphicsSystems
const G4String & GetName() const
G4VisManager(const G4String &verbosityString="warnings")
Definition: G4VisManager.cc:88
G4bool FilterHit(const G4VHit &)
G4LogicalVolume * GetLogicalVolume() const
G4bool fInitialised
void DrawEvent(const G4Event *)
G4VViewer * GetViewer(const G4String &viewerName) const
void DrawT(const T &graphics_primitive, const G4Transform3D &objectTransform)
std::vector< UserVisAction > fEndOfEventUserVisActions
std::vector< Model > & SetEndOfEventModelList()
void BeginDraw2D(const G4Transform3D &objectTransformation=G4Transform3D())
static G4String VerbosityString(Verbosity)
static G4EventManager * GetEventManager()
const List * ListManager() const
FilterMode::Mode GetMode() const
static Verbosity GetVerbosity()
G4bool fIgnoreStateChanges
void RefreshView()
G4VViewer * fpViewer
void Draw(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
static void SetVisManager(G4VisManager *)
virtual void RegisterGraphicsSystems()=0
G4int GetNumberOfEventToBeProcessed() const
Definition: G4Run.hh:83
#define G4endl
Definition: G4ios.hh:61
void RegisterModel(G4VTrajectoryModel *model)
const std::vector< Factory * > & FactoryList() const
G4bool RegisterGraphicsSystem(G4VGraphicsSystem *)
void BeginOfEvent()
void DispatchToModel(const G4VTrajectory &)
static const std::map< G4String, G4Colour > & GetMap()
Definition: G4Colour.cc:147
void CreateViewer(const G4String &name="", const G4String &XGeometry="")
virtual void ClearTransientStore()
void SetTransientsDrawnThisRun(G4bool)
const G4Event * GetConstCurrentEvent()
void CreateSceneHandler(const G4String &name="")
G4VGraphicsSystem * fpGraphicsSystem
void DrawT2D(const T &graphics_primitive, const G4Transform3D &objectTransform)
const G4GraphicsSystemList & GetAvailableGraphicsSystems()
G4bool IsCulling() const
void NotifyHandlers()
G4int GetMaxNumberOfKeptEvents() const
static void SetConcreteInstance(G4VVisManager *)
void Draw2D(const G4Circle &, const G4Transform3D &objectTransformation=G4Transform3D())
void ClearTransientStoreIfMarked()
G4bool fIsDrawGroup
void SetMarkForClearingTransientStore(G4bool)
void KeepTheCurrentEvent()
G4bool IsAutoRefresh() const
G4bool fKeptLastEvent
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432
G4VSolid * GetSolid() const
G4bool fTransientsDrawnThisRun
G4SceneList fSceneList