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