Geant4 Cross Reference

Cross-Referencing   Geant4
Geant4/visualization/management/src/G4VisManager.cc

Version: [ ReleaseNotes ] [ 1.0 ] [ 1.1 ] [ 2.0 ] [ 3.0 ] [ 3.1 ] [ 3.2 ] [ 4.0 ] [ 4.0.p1 ] [ 4.0.p2 ] [ 4.1 ] [ 4.1.p1 ] [ 5.0 ] [ 5.0.p1 ] [ 5.1 ] [ 5.1.p1 ] [ 5.2 ] [ 5.2.p1 ] [ 5.2.p2 ] [ 6.0 ] [ 6.0.p1 ] [ 6.1 ] [ 6.2 ] [ 6.2.p1 ] [ 6.2.p2 ] [ 7.0 ] [ 7.0.p1 ] [ 7.1 ] [ 7.1.p1 ] [ 8.0 ] [ 8.0.p1 ] [ 8.1 ] [ 8.1.p1 ] [ 8.1.p2 ] [ 8.2 ] [ 8.2.p1 ] [ 8.3 ] [ 8.3.p1 ] [ 8.3.p2 ] [ 9.0 ] [ 9.0.p1 ] [ 9.0.p2 ] [ 9.1 ] [ 9.1.p1 ] [ 9.1.p2 ] [ 9.1.p3 ] [ 9.2 ] [ 9.2.p1 ] [ 9.2.p2 ] [ 9.2.p3 ] [ 9.2.p4 ] [ 9.3 ] [ 9.3.p1 ] [ 9.3.p2 ] [ 9.4 ] [ 9.4.p1 ] [ 9.4.p2 ] [ 9.4.p3 ] [ 9.4.p4 ] [ 9.5 ] [ 9.5.p1 ] [ 9.5.p2 ] [ 9.6 ] [ 9.6.p1 ] [ 9.6.p2 ] [ 9.6.p3 ] [ 9.6.p4 ] [ 10.0 ] [ 10.0.p1 ] [ 10.0.p2 ] [ 10.0.p3 ] [ 10.0.p4 ] [ 10.1 ] [ 10.1.p1 ] [ 10.1.p2 ] [ 10.1.p3 ] [ 10.2 ] [ 10.2.p1 ] [ 10.2.p2 ] [ 10.2.p3 ] [ 10.3 ] [ 10.3.p1 ] [ 10.3.p2 ] [ 10.3.p3 ] [ 10.4 ] [ 10.4.p1 ] [ 10.4.p2 ] [ 10.4.p3 ] [ 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /visualization/management/src/G4VisManager.cc (Version 11.3.0) and /visualization/management/src/G4VisManager.cc (Version 10.1.p2)


  1 //                                                  1 //
  2 // *******************************************      2 // ********************************************************************
  3 // * License and Disclaimer                         3 // * License and Disclaimer                                           *
  4 // *                                                4 // *                                                                  *
  5 // * The  Geant4 software  is  copyright of th      5 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
  6 // * the Geant4 Collaboration.  It is provided      6 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
  7 // * conditions of the Geant4 Software License      7 // * conditions of the Geant4 Software License,  included in the file *
  8 // * LICENSE and available at  http://cern.ch/      8 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
  9 // * include a list of copyright holders.           9 // * include a list of copyright holders.                             *
 10 // *                                               10 // *                                                                  *
 11 // * Neither the authors of this software syst     11 // * Neither the authors of this software system, nor their employing *
 12 // * institutes,nor the agencies providing fin     12 // * institutes,nor the agencies providing financial support for this *
 13 // * work  make  any representation or  warran     13 // * work  make  any representation or  warranty, express or implied, *
 14 // * regarding  this  software system or assum     14 // * regarding  this  software system or assume any liability for its *
 15 // * use.  Please see the license in the file      15 // * use.  Please see the license in the file  LICENSE  and URL above *
 16 // * for the full disclaimer and the limitatio     16 // * for the full disclaimer and the limitation of liability.         *
 17 // *                                               17 // *                                                                  *
 18 // * This  code  implementation is the result      18 // * This  code  implementation is the result of  the  scientific and *
 19 // * technical work of the GEANT4 collaboratio     19 // * technical work of the GEANT4 collaboration.                      *
 20 // * By using,  copying,  modifying or  distri     20 // * By using,  copying,  modifying or  distributing the software (or *
 21 // * any work based  on the software)  you  ag     21 // * any work based  on the software)  you  agree  to acknowledge its *
 22 // * use  in  resulting  scientific  publicati     22 // * use  in  resulting  scientific  publications,  and indicate your *
 23 // * acceptance of all terms of the Geant4 Sof     23 // * acceptance of all terms of the Geant4 Software license.          *
 24 // *******************************************     24 // ********************************************************************
 25 //                                                 25 //
                                                   >>  26 // $Id: G4VisManager.cc 87360 2014-12-01 16:07:16Z gcosmo $
 26 //                                                 27 //
 27 //                                                 28 // 
 28 // GEANT4 Visualization Manager - John Allison     29 // GEANT4 Visualization Manager - John Allison 02/Jan/1996.
 29 // Michael Kelsey  31 Jan 2019 -- Add new comm << 
 30                                                    30 
 31 #include "G4VisManager.hh"                         31 #include "G4VisManager.hh"
 32                                                    32 
 33 #include "G4VisCommands.hh"                        33 #include "G4VisCommands.hh"
 34 #include "G4VisCommandsCompound.hh"                34 #include "G4VisCommandsCompound.hh"
 35 #include "G4VisCommandsGeometry.hh"                35 #include "G4VisCommandsGeometry.hh"
 36 #include "G4VisCommandsGeometrySet.hh"             36 #include "G4VisCommandsGeometrySet.hh"
 37 #include "G4VisCommandsMultithreading.hh"      << 
 38 #include "G4VisCommandsSet.hh"                     37 #include "G4VisCommandsSet.hh"
 39 #include "G4VisCommandsScene.hh"                   38 #include "G4VisCommandsScene.hh"
 40 #include "G4VisCommandsSceneAdd.hh"                39 #include "G4VisCommandsSceneAdd.hh"
 41 #include "G4VisCommandsPlotter.hh"             << 
 42 #include "G4VisCommandsSceneHandler.hh"            40 #include "G4VisCommandsSceneHandler.hh"
 43 #include "G4VisCommandsTouchable.hh"               41 #include "G4VisCommandsTouchable.hh"
 44 #include "G4VisCommandsTouchableSet.hh"            42 #include "G4VisCommandsTouchableSet.hh"
 45 #include "G4VisCommandsViewer.hh"                  43 #include "G4VisCommandsViewer.hh"
 46 #include "G4VisCommandsViewerDefault.hh"           44 #include "G4VisCommandsViewerDefault.hh"
 47 #include "G4VisCommandsViewerSet.hh"               45 #include "G4VisCommandsViewerSet.hh"
 48 #include "G4UImanager.hh"                          46 #include "G4UImanager.hh"
 49 #include "G4VisStateDependent.hh"                  47 #include "G4VisStateDependent.hh"
 50 #include "G4UIdirectory.hh"                        48 #include "G4UIdirectory.hh"
 51 #include "G4VGraphicsSystem.hh"                    49 #include "G4VGraphicsSystem.hh"
 52 #include "G4VSceneHandler.hh"                      50 #include "G4VSceneHandler.hh"
 53 #include "G4VViewer.hh"                            51 #include "G4VViewer.hh"
 54 #include "G4VPhysicalVolume.hh"                    52 #include "G4VPhysicalVolume.hh"
 55 #include "G4LogicalVolume.hh"                      53 #include "G4LogicalVolume.hh"
 56 #include "G4VSolid.hh"                             54 #include "G4VSolid.hh"
 57 #include "G4Vector3D.hh"                           55 #include "G4Vector3D.hh"
 58 #include "G4Point3D.hh"                            56 #include "G4Point3D.hh"
 59 #include "G4RotationMatrix.hh"                     57 #include "G4RotationMatrix.hh"
 60 #include "G4Polyline.hh"                           58 #include "G4Polyline.hh"
 61 #include "G4Polyhedron.hh"                         59 #include "G4Polyhedron.hh"
 62 #include "G4NullModel.hh"                          60 #include "G4NullModel.hh"
 63 #include "G4ModelingParameters.hh"                 61 #include "G4ModelingParameters.hh"
 64 #include "G4TransportationManager.hh"              62 #include "G4TransportationManager.hh"
 65 #include "G4VisCommandModelCreate.hh"              63 #include "G4VisCommandModelCreate.hh"
 66 #include "G4VisCommandsListManager.hh"             64 #include "G4VisCommandsListManager.hh"
 67 #include "G4VisModelManager.hh"                    65 #include "G4VisModelManager.hh"
 68 #include "G4VModelFactory.hh"                      66 #include "G4VModelFactory.hh"
 69 #include "G4VisFilterManager.hh"                   67 #include "G4VisFilterManager.hh"
 70 #include "G4VTrajectoryModel.hh"                   68 #include "G4VTrajectoryModel.hh"
 71 #include "G4TrajectoryDrawByCharge.hh"             69 #include "G4TrajectoryDrawByCharge.hh"
 72 #include "Randomize.hh"                            70 #include "Randomize.hh"
 73 #include "G4RunManager.hh"                         71 #include "G4RunManager.hh"
 74 #include "G4RunManagerFactory.hh"              << 
 75 #include "G4EventManager.hh"                       72 #include "G4EventManager.hh"
 76 #include "G4Run.hh"                                73 #include "G4Run.hh"
 77 #include "G4Event.hh"                              74 #include "G4Event.hh"
 78 #include <map>                                     75 #include <map>
 79 #include <set>                                     76 #include <set>
 80 #include <vector>                                  77 #include <vector>
 81 #include <sstream>                                 78 #include <sstream>
 82                                                    79 
                                                   >>  80 #ifdef G4MULTITHREADED
 83 #include "G4Threading.hh"                          81 #include "G4Threading.hh"
 84 #include "G4AutoLock.hh"                           82 #include "G4AutoLock.hh"
 85 #include "G4GeometryWorkspace.hh" // no_geant4 <<  83 #endif
 86 #include "G4SolidsWorkspace.hh"                << 
 87 #include <deque>                               << 
 88 #include <typeinfo>                            << 
 89 #include <chrono>                              << 
 90 #include <thread>                              << 
 91 #include <utility>                             << 
 92                                                << 
 93 #define G4warn G4cout                          << 
 94                                                << 
 95 // Local threading related variables           << 
 96 namespace {                                    << 
 97   G4bool mtRunInProgress = false;              << 
 98   std::deque<const G4Event*> mtVisEventQueue;  << 
 99   G4Thread* mtVisSubThread = 0;                << 
100   [[maybe_unused]] G4Mutex mtVisSubThreadMutex << 
101   //  G4Mutex visBeginOfRunMutex = G4MUTEX_INI << 
102   //  G4Mutex visBeginOfEventMutex = G4MUTEX_I << 
103   G4Mutex visEndOfEventMutex = G4MUTEX_INITIAL << 
104   //  G4Mutex visEndOfRunMutex = G4MUTEX_INITI << 
105   G4bool isSubEventRunManagerType = false;     << 
106   G4bool isValidViewForRun = false;            << 
107   G4bool isFakeRun = false;                    << 
108 }                                              << 
109                                                    84 
110 // Class statics                               << 
111 G4VisManager* G4VisManager::fpInstance = 0;        85 G4VisManager* G4VisManager::fpInstance = 0;
112                                                    86 
113 G4VisManager::Verbosity G4VisManager::fVerbosi     87 G4VisManager::Verbosity G4VisManager::fVerbosity = G4VisManager::warnings;
114                                                    88 
115 G4VisManager::G4VisManager (const G4String& ve <<  89 G4VisManager::G4VisManager (const G4String& verbosityString):
116 : fVerbose         (1)                         <<  90   fVerbose         (1),
117 , fDefaultGraphicsSystemName("OGL")          / <<  91   fInitialised     (false),
118 , fDefaultXGeometryString   ("600x600-0+0")  / <<  92   fpGraphicsSystem (0),
119 , fDefaultGraphicsSystemBasis ("G4VisManager i <<  93   fpScene          (0),
120 , fDefaultXGeometryStringBasis("G4VisManager i <<  94   fpSceneHandler   (0),
121 , fInitialised     (false)                     <<  95   fpViewer         (0),
122 , fpGraphicsSystem (0)                         <<  96   fpStateDependent (0),
123 , fpScene          (0)                         <<  97   fEventRefreshing          (false),
124 , fpSceneHandler   (0)                         <<  98   fTransientsDrawnThisRun   (false),
125 , fpViewer         (0)                         <<  99   fTransientsDrawnThisEvent (false),
126 , fpStateDependent (0)                         << 100   fNKeepRequests            (0),
127 , fEventRefreshing          (false)            << 101   fEventKeepingSuspended    (false),
128 , fTransientsDrawnThisRun   (false)            << 102   fKeptLastEvent            (false),
129 , fTransientsDrawnThisEvent (false)            << 103   fpRequestedEvent          (0),
130 , fNoOfEventsDrawnThisRun   (0)                << 104   fAbortReviewKeptEvents    (false),
131 , fNKeepForPostProcessingRequests (0)          << 105   fIsDrawGroup              (false),
132 , fNKeepTheEventRequests    (0)                << 106   fDrawGroupNestingDepth    (0),
133 , fEventKeepingSuspended    (false)            << 107   fIgnoreStateChanges       (false)
134 , fDrawEventOnlyIfToBeKept  (false)            << 108   // All other objects use default constructors.
135 , fpRequestedEvent          (0)                << 
136 , fReviewingKeptEvents      (false)            << 
137 , fAbortReviewKeptEvents    (false)            << 
138 , fReviewingPlots           (false)            << 
139 , fAbortReviewPlots         (false)            << 
140 , fIsDrawGroup              (false)            << 
141 , fDrawGroupNestingDepth    (0)                << 
142 , fIgnoreStateChanges       (false)            << 
143 , fMaxEventQueueSize        (100)              << 
144 , fWaitOnEventQueueFull     (true)             << 
145 // All other objects use default constructors. << 
146 {                                                 109 {
147   fpTrajDrawModelMgr = new G4VisModelManager<G    110   fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
148   fpTrajFilterMgr = new G4VisFilterManager<G4V    111   fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
149   fpHitFilterMgr = new G4VisFilterManager<G4VH    112   fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
150   fpDigiFilterMgr = new G4VisFilterManager<G4V    113   fpDigiFilterMgr = new G4VisFilterManager<G4VDigi>("/vis/filtering/digi");
151                                                   114 
152   VerbosityGuidanceStrings.push_back              115   VerbosityGuidanceStrings.push_back
153     ("Simple graded message scheme - digit or     116     ("Simple graded message scheme - digit or string (1st character defines):");
154   VerbosityGuidanceStrings.push_back              117   VerbosityGuidanceStrings.push_back
155     ("  0) quiet,         // Nothing is printe    118     ("  0) quiet,         // Nothing is printed.");
156   VerbosityGuidanceStrings.push_back              119   VerbosityGuidanceStrings.push_back
157     ("  1) startup,       // Startup and endup    120     ("  1) startup,       // Startup and endup messages are printed...");
158   VerbosityGuidanceStrings.push_back              121   VerbosityGuidanceStrings.push_back
159     ("  2) errors,        // ...and errors..."    122     ("  2) errors,        // ...and errors...");
160   VerbosityGuidanceStrings.push_back              123   VerbosityGuidanceStrings.push_back
161     ("  3) warnings,      // ...and warnings..    124     ("  3) warnings,      // ...and warnings...");
162   VerbosityGuidanceStrings.push_back              125   VerbosityGuidanceStrings.push_back
163     ("  4) confirmations, // ...and confirming    126     ("  4) confirmations, // ...and confirming messages...");
164   VerbosityGuidanceStrings.push_back              127   VerbosityGuidanceStrings.push_back
165     ("  5) parameters,    // ...and parameters    128     ("  5) parameters,    // ...and parameters of scenes and views...");
166   VerbosityGuidanceStrings.push_back              129   VerbosityGuidanceStrings.push_back
167     ("  6) all            // ...and everything    130     ("  6) all            // ...and everything available.");
168                                                   131 
169   if (fpInstance) {                               132   if (fpInstance) {
170     G4Exception                                   133     G4Exception
171       ("G4VisManager::G4VisManager",              134       ("G4VisManager::G4VisManager",
172        "visman0001", FatalException,              135        "visman0001", FatalException,
173        "Attempt to Construct more than one Vis    136        "Attempt to Construct more than one VisManager");
174   }                                               137   }
175                                                   138 
176   fpInstance = this;                              139   fpInstance = this;
177   SetConcreteInstance(this);                      140   SetConcreteInstance(this);
178                                                   141 
179   fpStateDependent = new G4VisStateDependent (    142   fpStateDependent = new G4VisStateDependent (this);
180   // No need to delete this; G4StateManager do    143   // No need to delete this; G4StateManager does this.
181                                                   144 
182   fVerbosity = GetVerbosityValue(verbosityStri    145   fVerbosity = GetVerbosityValue(verbosityString);
183   if (fVerbosity >= startup) {                    146   if (fVerbosity >= startup) {
184       G4cout                                      147       G4cout
185   << "Visualization Manager instantiating with    148   << "Visualization Manager instantiating with verbosity \""
186   << VerbosityString(fVerbosity)                  149   << VerbosityString(fVerbosity)
187   << "\"..." << G4endl;                           150   << "\"..." << G4endl;
188   }                                               151   }
189                                                   152 
190   // Note: The specific graphics systems must     153   // Note: The specific graphics systems must be instantiated in a
191   // higher level library to avoid circular de    154   // higher level library to avoid circular dependencies.  Also,
192   // some specifically need additional externa    155   // some specifically need additional external libararies that the
193   // user must supply.  Therefore we ask the u    156   // user must supply.  Therefore we ask the user to implement
194   // RegisterGraphicsSystems() and RegisterMod    157   // RegisterGraphicsSystems() and RegisterModelFactories()
195   // in a subclass.  We have to wait for the s    158   // in a subclass.  We have to wait for the subclass to instantiate
196   // so RegisterGraphicsSystems() cannot be ca    159   // so RegisterGraphicsSystems() cannot be called from this
197   // constructor; it is called from Initialise    160   // constructor; it is called from Initialise().  So we ask the
198   // user:                                        161   // user:
199   //   (a) to write a subclass and implement      162   //   (a) to write a subclass and implement  RegisterGraphicsSystems()
200   //       and RegisterModelFactories().  See     163   //       and RegisterModelFactories().  See
201   //       visualization/include/G4VisExecutiv    164   //       visualization/include/G4VisExecutive.hh/icc as an example.
202   //   (b) instantiate the subclass.              165   //   (b) instantiate the subclass.
203   //   (c) invoke the Initialise() method of t    166   //   (c) invoke the Initialise() method of the subclass.
204   // For example:                                 167   // For example:
205   //   ...                                        168   //   ...
                                                   >> 169   // #ifdef G4VIS_USE
206   //   // Instantiate and initialise Visualiza    170   //   // Instantiate and initialise Visualization Manager.
207   //   G4VisManager* visManager = new G4VisExe    171   //   G4VisManager* visManager = new G4VisExecutive;
208   //   visManager -> SetVerboseLevel (Verbose)    172   //   visManager -> SetVerboseLevel (Verbose);
209   //   visManager -> Initialise ();               173   //   visManager -> Initialise ();
                                                   >> 174   // #endif
210   //   // (Don't forget to delete visManager;)    175   //   // (Don't forget to delete visManager;)
211   //   ...                                        176   //   ...
212                                                   177 
213   // Make top level command directory...          178   // Make top level command directory...
214   // vis commands should *not* be broadcast to << 179   // Vis commands should *not* be broadcast to threads (2nd argument).
215   G4bool propagateToWorkers;                   << 180   G4UIcommand* directory = new G4UIdirectory ("/vis/",false);
216   auto directory = new G4UIdirectory ("/vis/", << 
217   directory -> SetGuidance ("Visualization com    181   directory -> SetGuidance ("Visualization commands.");
218   // Request commands in name order            << 
219   directory -> Sort();  // Ordering propagates << 
220   fDirectoryList.push_back (directory);           182   fDirectoryList.push_back (directory);
221                                                   183 
222   // Instantiate *basic* top level commands so    184   // Instantiate *basic* top level commands so that they can be used
223   // immediately after instantiation of the vi    185   // immediately after instantiation of the vis manager.  Other top
224   // level and lower level commands are instan    186   // level and lower level commands are instantiated later in
225   // RegisterMessengers.                          187   // RegisterMessengers.
226   G4VVisCommand::SetVisManager (this);  // Set    188   G4VVisCommand::SetVisManager (this);  // Sets shared pointer
227   RegisterMessenger(new G4VisCommandVerbose);     189   RegisterMessenger(new G4VisCommandVerbose);
228   RegisterMessenger(new G4VisCommandInitialize    190   RegisterMessenger(new G4VisCommandInitialize);
229 }                                                 191 }
230                                                   192 
231 G4VisManager::~G4VisManager()                  << 193 G4VisManager::~G4VisManager () {
232 {                                              << 194   fpInstance = 0;
233   G4UImanager* UImanager = G4UImanager::GetUIp << 195   size_t i;
234   UImanager->SetCoutDestination(nullptr);      << 
235   std::size_t i;                               << 
236   for (i = 0; i < fSceneList.size (); ++i) {      196   for (i = 0; i < fSceneList.size (); ++i) {
237     delete fSceneList[i];                         197     delete fSceneList[i];
238   }                                               198   }
239   for (i = 0; i < fAvailableSceneHandlers.size    199   for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
240   if (fAvailableSceneHandlers[i] != NULL) {       200   if (fAvailableSceneHandlers[i] != NULL) {
241     delete fAvailableSceneHandlers[i];            201     delete fAvailableSceneHandlers[i];
242   }                                               202   }
243   }                                               203   }
244   for (i = 0; i < fAvailableGraphicsSystems.si    204   for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
245     if (fAvailableGraphicsSystems[i]) {           205     if (fAvailableGraphicsSystems[i]) {
246       delete fAvailableGraphicsSystems[i];        206       delete fAvailableGraphicsSystems[i];
247     }                                             207     }
248   }                                               208   }
249   if (fVerbosity >= startup) {                    209   if (fVerbosity >= startup) {
250     G4cout << "Graphics systems deleted." << G    210     G4cout << "Graphics systems deleted." << G4endl;
251     G4cout << "Visualization Manager deleting.    211     G4cout << "Visualization Manager deleting..." << G4endl;
252   }                                               212   }
253   for (i = 0; i < fMessengerList.size (); ++i)    213   for (i = 0; i < fMessengerList.size (); ++i) {
254     delete fMessengerList[i];                     214     delete fMessengerList[i];
255   }                                               215   }
256   for (i = 0; i < fDirectoryList.size (); ++i)    216   for (i = 0; i < fDirectoryList.size (); ++i) {
257     delete fDirectoryList[i];                     217     delete fDirectoryList[i];
258   }                                               218   }
259                                                   219 
260   delete fpDigiFilterMgr;                         220   delete fpDigiFilterMgr;
261   delete fpHitFilterMgr;                          221   delete fpHitFilterMgr;
262   delete fpTrajFilterMgr;                         222   delete fpTrajFilterMgr;
263   delete fpTrajDrawModelMgr;                      223   delete fpTrajDrawModelMgr;
264   fpInstance = 0;                              << 
265 }                                                 224 }
266                                                   225 
267 G4VisManager* G4VisManager::GetInstance () {      226 G4VisManager* G4VisManager::GetInstance () {
268   if (!fpInstance) {                              227   if (!fpInstance) {
269     G4Exception                                   228     G4Exception
270       ("G4VisManager::GetInstance",               229       ("G4VisManager::GetInstance",
271        "visman0002", FatalException, "VisManag    230        "visman0002", FatalException, "VisManager not yet instantiated");
272   }                                               231   }
273   return fpInstance;                              232   return fpInstance;
274 }                                                 233 }
275                                                   234 
276 void G4VisManager::Initialise () {                235 void G4VisManager::Initialise () {
277                                                   236 
278   if (fInitialised && fVerbosity >= warnings)     237   if (fInitialised && fVerbosity >= warnings) {
279     G4warn << "WARNING: G4VisManager::Initiali << 238     G4cout << "WARNING: G4VisManager::Initialise: already initialised."
280      << G4endl;                                   239      << G4endl;
281     return;                                       240     return;
282   }                                               241   }
283                                                   242 
284   if (fVerbosity >= startup) {                    243   if (fVerbosity >= startup) {
285     G4cout << "Visualization Manager initialis    244     G4cout << "Visualization Manager initialising..." << G4endl;
286   }                                               245   }
287                                                   246 
288   if (fVerbosity >= parameters) {                 247   if (fVerbosity >= parameters) {
289     G4cout <<                                     248     G4cout <<
290       "\nYou have instantiated your own Visual    249       "\nYou have instantiated your own Visualization Manager, inheriting"
291       "\n  G4VisManager and implementing Regis    250       "\n  G4VisManager and implementing RegisterGraphicsSystems(), in which"
292       "\n  you should, normally, instantiate d    251       "\n  you should, normally, instantiate drivers which do not need"
293       "\n  external packages or libraries, and    252       "\n  external packages or libraries, and, optionally, drivers under"
294       "\n  control of environment variables."     253       "\n  control of environment variables."
295       "\n  Also you should implement RegisterM    254       "\n  Also you should implement RegisterModelFactories()."
296       "\n  See visualization/management/includ << 255       "\n  See visualization/include/G4VisExecutive.hh/icc, for example."
297       "\n  In your main() you will have someth    256       "\n  In your main() you will have something like:"
                                                   >> 257       "\n  #ifdef G4VIS_USE"
298       "\n    G4VisManager* visManager = new G4    258       "\n    G4VisManager* visManager = new G4VisExecutive;"
299       "\n    visManager -> SetVerboseLevel (Ve    259       "\n    visManager -> SetVerboseLevel (Verbose);"
300       "\n    visManager -> Initialize ();"        260       "\n    visManager -> Initialize ();"
                                                   >> 261       "\n  #endif"
301       "\n  (Don't forget to delete visManager;    262       "\n  (Don't forget to delete visManager;)"
302       "\n"                                        263       "\n"
303    << G4endl;                                     264    << G4endl;
304   }                                               265   }
305                                                   266 
306   if (fVerbosity >= startup) {                    267   if (fVerbosity >= startup) {
307     G4cout << "Registering graphics systems...    268     G4cout << "Registering graphics systems..." << G4endl;
308   }                                               269   }
309                                                   270 
310   RegisterGraphicsSystems ();                     271   RegisterGraphicsSystems ();
311                                                   272 
312   if (fVerbosity >= startup) {                    273   if (fVerbosity >= startup) {
313     G4cout <<                                     274     G4cout <<
314       "\nYou have successfully registered the     275       "\nYou have successfully registered the following graphics systems."
315    << G4endl;                                     276    << G4endl;
316     PrintAvailableGraphicsSystems (fVerbosity) << 277     PrintAvailableGraphicsSystems ();
317     G4cout << G4endl;                             278     G4cout << G4endl;
318   }                                               279   }
319                                                   280 
320   // Make command directories for commands ins    281   // Make command directories for commands instantiated in the
321   // modeling subcategory...                      282   // modeling subcategory...
322   G4UIcommand* directory;                         283   G4UIcommand* directory;
323   directory = new G4UIdirectory ("/vis/modelin    284   directory = new G4UIdirectory ("/vis/modeling/");
324   directory -> SetGuidance ("Modeling commands    285   directory -> SetGuidance ("Modeling commands.");
325   fDirectoryList.push_back (directory);           286   fDirectoryList.push_back (directory);
326   directory = new G4UIdirectory ("/vis/modelin    287   directory = new G4UIdirectory ("/vis/modeling/trajectories/");
327   directory -> SetGuidance ("Trajectory model     288   directory -> SetGuidance ("Trajectory model commands.");
328   fDirectoryList.push_back (directory);           289   fDirectoryList.push_back (directory);
329   directory = new G4UIdirectory ("/vis/modelin    290   directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
330   directory -> SetGuidance ("Create trajectory    291   directory -> SetGuidance ("Create trajectory models and messengers.");
331   fDirectoryList.push_back (directory);           292   fDirectoryList.push_back (directory);
332                                                   293 
333   // Filtering command directory                  294   // Filtering command directory
334   directory = new G4UIdirectory ("/vis/filteri    295   directory = new G4UIdirectory ("/vis/filtering/");
335   directory -> SetGuidance ("Filtering command    296   directory -> SetGuidance ("Filtering commands.");
336   fDirectoryList.push_back (directory);           297   fDirectoryList.push_back (directory);
337   directory = new G4UIdirectory ("/vis/filteri    298   directory = new G4UIdirectory ("/vis/filtering/trajectories/");
338   directory -> SetGuidance ("Trajectory filter    299   directory -> SetGuidance ("Trajectory filtering commands.");
339   fDirectoryList.push_back (directory);           300   fDirectoryList.push_back (directory);
340   directory = new G4UIdirectory ("/vis/filteri    301   directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
341   directory -> SetGuidance ("Create trajectory    302   directory -> SetGuidance ("Create trajectory filters and messengers.");
342   fDirectoryList.push_back (directory);           303   fDirectoryList.push_back (directory);
343   directory = new G4UIdirectory ("/vis/filteri    304   directory = new G4UIdirectory ("/vis/filtering/hits/");
344   directory -> SetGuidance ("Hit filtering com    305   directory -> SetGuidance ("Hit filtering commands.");
345   fDirectoryList.push_back (directory);           306   fDirectoryList.push_back (directory);
346   directory = new G4UIdirectory ("/vis/filteri    307   directory = new G4UIdirectory ("/vis/filtering/hits/create/");
347   directory -> SetGuidance ("Create hit filter    308   directory -> SetGuidance ("Create hit filters and messengers.");
348   fDirectoryList.push_back (directory);           309   fDirectoryList.push_back (directory);
349   directory = new G4UIdirectory ("/vis/filteri    310   directory = new G4UIdirectory ("/vis/filtering/digi/");
350   directory -> SetGuidance ("Digi filtering co    311   directory -> SetGuidance ("Digi filtering commands.");
351   fDirectoryList.push_back (directory);           312   fDirectoryList.push_back (directory);
352   directory = new G4UIdirectory ("/vis/filteri    313   directory = new G4UIdirectory ("/vis/filtering/digi/create/");
353   directory -> SetGuidance ("Create digi filte    314   directory -> SetGuidance ("Create digi filters and messengers.");
354   fDirectoryList.push_back (directory);           315   fDirectoryList.push_back (directory);
355                                                   316 
356   RegisterMessengers ();                          317   RegisterMessengers ();
357                                                   318 
358   if (fVerbosity >= startup) {                    319   if (fVerbosity >= startup) {
359     G4cout << "Registering model factories..."    320     G4cout << "Registering model factories..." << G4endl;
360   }                                               321   }
361                                                   322 
362   RegisterModelFactories();                       323   RegisterModelFactories();
363                                                   324 
364   if (fVerbosity >= startup) {                    325   if (fVerbosity >= startup) {
365     G4cout <<                                     326     G4cout <<
366       "\nYou have successfully registered the     327       "\nYou have successfully registered the following model factories."
367      << G4endl;                                   328      << G4endl;
368     PrintAvailableModels (fVerbosity);            329     PrintAvailableModels (fVerbosity);
369     G4cout << G4endl;                             330     G4cout << G4endl;
370   }                                               331   }
371                                                   332 
372   if (fVerbosity >= startup) {                    333   if (fVerbosity >= startup) {
373     PrintAvailableUserVisActions (fVerbosity);    334     PrintAvailableUserVisActions (fVerbosity);
374     G4cout << G4endl;                             335     G4cout << G4endl;
375   }                                               336   }
376                                                   337 
377   InitialiseG4ColourMap();                     << 
378                                                << 
379   if (fVerbosity >= startup) {                    338   if (fVerbosity >= startup) {
380     G4cout <<                                  << 339     PrintAvailableColours (fVerbosity);
381     "Some /vis commands (optionally) take a st << 340     G4cout << G4endl;
382     "\n\"/vis/list\" to see available colours. << 
383     << G4endl;                                 << 
384   }                                               341   }
385                                                   342 
386   fInitialised = true;                            343   fInitialised = true;
387 }                                                 344 }
388                                                   345 
389 void G4VisManager::InitialiseG4ColourMap() con << 
390 {                                              << 
391   G4Colour::InitialiseColourMap();  // Initial << 
392                                                << 
393   // our forever 65 named colors taken long ti << 
394   // Extracted from g4tools/include/tools/colo << 
395   // Copyright (C) 2010, Guy Barrand. All righ << 
396   // See the file tools.license for terms.     << 
397                                                << 
398 #define TOOLS_COLORS_STAT(name,r,g,b) \        << 
399 G4Colour::AddToMap(#name, G4Colour(r,g,b));    << 
400                                                << 
401   //0-9                                        << 
402   TOOLS_COLORS_STAT(aquamarine,0.496101F,0.996 << 
403   TOOLS_COLORS_STAT(mediumaquamarine,0.398444F << 
404   //  TOOLS_COLORS_STAT(black,0,0,0) (already  << 
405   //  TOOLS_COLORS_STAT(blue,0,0,1) (already d << 
406   TOOLS_COLORS_STAT(cadetblue,0.371099F,0.6171 << 
407   TOOLS_COLORS_STAT(cornflowerblue,0.390631F,0 << 
408   TOOLS_COLORS_STAT(darkslateblue,0.281254F,0. << 
409   TOOLS_COLORS_STAT(lightblue,0.675792F,0.8437 << 
410   TOOLS_COLORS_STAT(lightsteelblue,0.68751F,0. << 
411   TOOLS_COLORS_STAT(mediumblue,0,0,0.800793F)  << 
412                                                << 
413   //10-19                                      << 
414   TOOLS_COLORS_STAT(mediumslateblue,0.480476F, << 
415   TOOLS_COLORS_STAT(midnightblue,0.0976577F,0. << 
416   TOOLS_COLORS_STAT(navyblue,0,0,0.500008F)    << 
417   TOOLS_COLORS_STAT(navy,0,0,0.500008F)        << 
418   TOOLS_COLORS_STAT(skyblue,0.527352F,0.8047F, << 
419   TOOLS_COLORS_STAT(slateblue,0.414069F,0.3515 << 
420   TOOLS_COLORS_STAT(steelblue,0.273442F,0.5078 << 
421   TOOLS_COLORS_STAT(coral,0.996109F,0.496101F, << 
422   //  TOOLS_COLORS_STAT(cyan,0,1,1) (already d << 
423   TOOLS_COLORS_STAT(firebrick,0.695323F,0.1328 << 
424                                                << 
425   //20-29                                      << 
426   //  TOOLS_COLORS_STAT(brown,0.644541F,0.1640 << 
427   TOOLS_COLORS_STAT(gold,0.996109F,0.839857F,0 << 
428   TOOLS_COLORS_STAT(goldenrod,0.851575F,0.6445 << 
429   //  TOOLS_COLORS_STAT(green,0,1,0) (already  << 
430   TOOLS_COLORS_STAT(darkgreen,0,0.390631F,0)   << 
431   TOOLS_COLORS_STAT(darkolivegreen,0.332036F,0 << 
432   TOOLS_COLORS_STAT(forestgreen,0.132815F,0.54 << 
433   TOOLS_COLORS_STAT(limegreen,0.195315F,0.8007 << 
434   TOOLS_COLORS_STAT(mediumseagreen,0.234379F,0 << 
435   TOOLS_COLORS_STAT(mediumspringgreen,0,0.9765 << 
436                                                << 
437   //30-39                                      << 
438   TOOLS_COLORS_STAT(palegreen,0.593759F,0.9804 << 
439   TOOLS_COLORS_STAT(seagreen,0.17969F,0.542977 << 
440   TOOLS_COLORS_STAT(springgreen,0,0.996109F,0. << 
441   TOOLS_COLORS_STAT(yellowgreen,0.601572F,0.80 << 
442   TOOLS_COLORS_STAT(darkslategrey,0.183597F,0. << 
443   TOOLS_COLORS_STAT(dimgrey,0.410163F,0.410163 << 
444   TOOLS_COLORS_STAT(lightgrey,0.824231F,0.8242 << 
445   //  TOOLS_COLORS_STAT(grey,0.750011F,0.75001 << 
446   TOOLS_COLORS_STAT(khaki,0.937514F,0.898451F, << 
447   //  TOOLS_COLORS_STAT(magenta,1,0,1) (alread << 
448                                                << 
449   //40-49                                      << 
450   TOOLS_COLORS_STAT(maroon,0.68751F,0.187503F, << 
451   TOOLS_COLORS_STAT(orange,0.996109F,0.644541F << 
452   TOOLS_COLORS_STAT(orchid,0.851575F,0.437507F << 
453   TOOLS_COLORS_STAT(darkorchid,0.597665F,0.195 << 
454   TOOLS_COLORS_STAT(mediumorchid,0.726574F,0.3 << 
455   TOOLS_COLORS_STAT(pink,0.996109F,0.750011F,0 << 
456   TOOLS_COLORS_STAT(plum,0.863294F,0.62501F,0. << 
457   //  TOOLS_COLORS_STAT(red,1,0,0) (already de << 
458   TOOLS_COLORS_STAT(indianred,0.800793F,0.3593 << 
459   TOOLS_COLORS_STAT(mediumvioletred,0.777356F, << 
460                                                << 
461   //50-59                                      << 
462   TOOLS_COLORS_STAT(orangered,0.996109F,0.2695 << 
463   TOOLS_COLORS_STAT(violetred,0.812512F,0.1250 << 
464   TOOLS_COLORS_STAT(salmon,0.976577F,0.500008F << 
465   TOOLS_COLORS_STAT(sienna,0.62501F,0.320317F, << 
466   TOOLS_COLORS_STAT(tan,0.820325F,0.703136F,0. << 
467   TOOLS_COLORS_STAT(thistle,0.843763F,0.746105 << 
468   TOOLS_COLORS_STAT(turquoise,0.250004F,0.8750 << 
469   TOOLS_COLORS_STAT(darkturquoise,0,0.8047F,0. << 
470   TOOLS_COLORS_STAT(mediumturquoise,0.281254F, << 
471   TOOLS_COLORS_STAT(violet,0.929702F,0.50782F, << 
472                                                << 
473   //60-64                                      << 
474   TOOLS_COLORS_STAT(blueviolet,0.539071F,0.167 << 
475   TOOLS_COLORS_STAT(wheat,0.957046F,0.867201F, << 
476   //  TOOLS_COLORS_STAT(white,1,1,1) (already  << 
477   //  TOOLS_COLORS_STAT(yellow,1,1,0) (already << 
478   TOOLS_COLORS_STAT(greenyellow,0.675792F,0.99 << 
479                                                << 
480 #undef TOOLS_COLORS_STAT                       << 
481 }                                              << 
482                                                << 
483 void G4VisManager::RegisterMessengers () {        346 void G4VisManager::RegisterMessengers () {
484                                                   347   
485   // Instantiate individual messengers/command    348   // Instantiate individual messengers/commands (often - but not
486   // always - one command per messenger).         349   // always - one command per messenger).
487                                                   350   
488   G4UIcommand* directory;                         351   G4UIcommand* directory;
489                                                   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...
                                                   >> 359   RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
                                                   >> 360   RegisterMessenger(new G4VisCommandEnable);
                                                   >> 361   RegisterMessenger(new G4VisCommandList);
                                                   >> 362   RegisterMessenger(new G4VisCommandReviewKeptEvents);
                                                   >> 363   
                                                   >> 364   // Compound commands...
                                                   >> 365   RegisterMessenger(new G4VisCommandDrawTree);
                                                   >> 366   RegisterMessenger(new G4VisCommandDrawView);
                                                   >> 367   RegisterMessenger(new G4VisCommandDrawVolume);
                                                   >> 368   RegisterMessenger(new G4VisCommandOpen);
                                                   >> 369   RegisterMessenger(new G4VisCommandSpecify);
                                                   >> 370   
490   directory = new G4UIdirectory ("/vis/geometr    371   directory = new G4UIdirectory ("/vis/geometry/");
491   directory -> SetGuidance("Operations on vis     372   directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
492   fDirectoryList.push_back (directory);           373   fDirectoryList.push_back (directory);
493   RegisterMessenger(new G4VisCommandGeometryLi    374   RegisterMessenger(new G4VisCommandGeometryList);
494   RegisterMessenger(new G4VisCommandGeometryRe    375   RegisterMessenger(new G4VisCommandGeometryRestore);
495                                                   376   
496   directory = new G4UIdirectory ("/vis/geometr    377   directory = new G4UIdirectory ("/vis/geometry/set/");
497   directory -> SetGuidance("Set vis attributes    378   directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
498   fDirectoryList.push_back (directory);           379   fDirectoryList.push_back (directory);
499   RegisterMessenger(new G4VisCommandGeometrySe    380   RegisterMessenger(new G4VisCommandGeometrySetColour);
500   RegisterMessenger(new G4VisCommandGeometrySe    381   RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
501   RegisterMessenger(new G4VisCommandGeometrySe    382   RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
502   RegisterMessenger(new G4VisCommandGeometrySe    383   RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
503   RegisterMessenger(new G4VisCommandGeometrySe    384   RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
504   RegisterMessenger(new G4VisCommandGeometrySe << 
505   RegisterMessenger(new G4VisCommandGeometrySe    385   RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
506   RegisterMessenger(new G4VisCommandGeometrySe    386   RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
507   RegisterMessenger(new G4VisCommandGeometrySe    387   RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
508   RegisterMessenger(new G4VisCommandGeometrySe    388   RegisterMessenger(new G4VisCommandGeometrySetVisibility);
509                                                   389   
510   directory = new G4UIdirectory ("/vis/multith << 
511   directory -> SetGuidance("Commands unique to << 
512   fDirectoryList.push_back (directory);        << 
513   RegisterMessenger(new G4VisCommandMultithrea << 
514   RegisterMessenger(new G4VisCommandMultithrea << 
515                                                << 
516   directory = new G4UIdirectory ("/vis/set/");    390   directory = new G4UIdirectory ("/vis/set/");
517   directory -> SetGuidance                        391   directory -> SetGuidance
518     ("Set quantities for use in future command    392     ("Set quantities for use in future commands where appropriate.");
519   fDirectoryList.push_back (directory);           393   fDirectoryList.push_back (directory);
520   RegisterMessenger(new G4VisCommandSetArrow3D << 
521   RegisterMessenger(new G4VisCommandSetColour)    394   RegisterMessenger(new G4VisCommandSetColour);
522   RegisterMessenger(new G4VisCommandSetExtentF << 
523   RegisterMessenger(new G4VisCommandSetLineWid    395   RegisterMessenger(new G4VisCommandSetLineWidth);
524   RegisterMessenger(new G4VisCommandSetTextCol    396   RegisterMessenger(new G4VisCommandSetTextColour);
525   RegisterMessenger(new G4VisCommandSetTextLay    397   RegisterMessenger(new G4VisCommandSetTextLayout);
526   RegisterMessenger(new G4VisCommandSetTextSiz    398   RegisterMessenger(new G4VisCommandSetTextSize);
527   RegisterMessenger(new G4VisCommandSetTouchab    399   RegisterMessenger(new G4VisCommandSetTouchable);
528   RegisterMessenger(new G4VisCommandSetVolumeF << 400   
529                                                << 
530   directory = new G4UIdirectory ("/vis/scene/"    401   directory = new G4UIdirectory ("/vis/scene/");
531   directory -> SetGuidance ("Operations on Gea    402   directory -> SetGuidance ("Operations on Geant4 scenes.");
532   fDirectoryList.push_back (directory);           403   fDirectoryList.push_back (directory);
533   RegisterMessenger(new G4VisCommandSceneActiv    404   RegisterMessenger(new G4VisCommandSceneActivateModel);
534   RegisterMessenger(new G4VisCommandSceneCreat    405   RegisterMessenger(new G4VisCommandSceneCreate);
535   RegisterMessenger(new G4VisCommandSceneEndOf    406   RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
536   RegisterMessenger(new G4VisCommandSceneEndOf    407   RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
537   RegisterMessenger(new G4VisCommandSceneList)    408   RegisterMessenger(new G4VisCommandSceneList);
538   RegisterMessenger(new G4VisCommandSceneNotif    409   RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
539   RegisterMessenger(new G4VisCommandSceneRemov << 
540   RegisterMessenger(new G4VisCommandSceneSelec    410   RegisterMessenger(new G4VisCommandSceneSelect);
541   RegisterMessenger(new G4VisCommandSceneShowE << 411   
542                                                << 
543   directory = new G4UIdirectory ("/vis/scene/a    412   directory = new G4UIdirectory ("/vis/scene/add/");
544   directory -> SetGuidance ("Add model to curr    413   directory -> SetGuidance ("Add model to current scene.");
545   fDirectoryList.push_back (directory);           414   fDirectoryList.push_back (directory);
546   RegisterMessenger(new G4VisCommandSceneAddAr    415   RegisterMessenger(new G4VisCommandSceneAddArrow);
547   RegisterMessenger(new G4VisCommandSceneAddAr    416   RegisterMessenger(new G4VisCommandSceneAddArrow2D);
548   RegisterMessenger(new G4VisCommandSceneAddAx    417   RegisterMessenger(new G4VisCommandSceneAddAxes);
549   RegisterMessenger(new G4VisCommandSceneAddDa    418   RegisterMessenger(new G4VisCommandSceneAddDate);
550   RegisterMessenger(new G4VisCommandSceneAddDi    419   RegisterMessenger(new G4VisCommandSceneAddDigis);
551   RegisterMessenger(new G4VisCommandSceneAddEv    420   RegisterMessenger(new G4VisCommandSceneAddEventID);
552   RegisterMessenger(new G4VisCommandSceneAddEx    421   RegisterMessenger(new G4VisCommandSceneAddExtent);
553   RegisterMessenger(new G4VisCommandSceneAddEl << 
554   RegisterMessenger(new G4VisCommandSceneAddFr    422   RegisterMessenger(new G4VisCommandSceneAddFrame);
555   RegisterMessenger(new G4VisCommandSceneAddGP << 
556   RegisterMessenger(new G4VisCommandSceneAddHi    423   RegisterMessenger(new G4VisCommandSceneAddHits);
557   RegisterMessenger(new G4VisCommandSceneAddLi    424   RegisterMessenger(new G4VisCommandSceneAddLine);
558   RegisterMessenger(new G4VisCommandSceneAddLi    425   RegisterMessenger(new G4VisCommandSceneAddLine2D);
559   RegisterMessenger(new G4VisCommandSceneAddLo << 
560   RegisterMessenger(new G4VisCommandSceneAddLo    426   RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
561   RegisterMessenger(new G4VisCommandSceneAddLo    427   RegisterMessenger(new G4VisCommandSceneAddLogo);
562   RegisterMessenger(new G4VisCommandSceneAddLo    428   RegisterMessenger(new G4VisCommandSceneAddLogo2D);
563   RegisterMessenger(new G4VisCommandSceneAddMa    429   RegisterMessenger(new G4VisCommandSceneAddMagneticField);
564   RegisterMessenger(new G4VisCommandSceneAddPl << 
565   RegisterMessenger(new G4VisCommandSceneAddPS    430   RegisterMessenger(new G4VisCommandSceneAddPSHits);
566   RegisterMessenger(new G4VisCommandSceneAddSc    431   RegisterMessenger(new G4VisCommandSceneAddScale);
567   RegisterMessenger(new G4VisCommandSceneAddTe    432   RegisterMessenger(new G4VisCommandSceneAddText);
568   RegisterMessenger(new G4VisCommandSceneAddTe    433   RegisterMessenger(new G4VisCommandSceneAddText2D);
569   RegisterMessenger(new G4VisCommandSceneAddTr    434   RegisterMessenger(new G4VisCommandSceneAddTrajectories);
570   RegisterMessenger(new G4VisCommandSceneAddUs    435   RegisterMessenger(new G4VisCommandSceneAddUserAction);
571   RegisterMessenger(new G4VisCommandSceneAddVo    436   RegisterMessenger(new G4VisCommandSceneAddVolume);
572                                                   437   
573   RegisterMessenger(new G4VisCommandPlotterCre << 
574   RegisterMessenger(new G4VisCommandPlotterSet << 
575   RegisterMessenger(new G4VisCommandPlotterAdd << 
576   RegisterMessenger(new G4VisCommandPlotterAdd << 
577   RegisterMessenger(new G4VisCommandPlotterAdd << 
578   RegisterMessenger(new G4VisCommandPlotterCle << 
579   RegisterMessenger(new G4VisCommandPlotterCle << 
580   RegisterMessenger(new G4VisCommandPlotterLis << 
581   RegisterMessenger(new G4VisCommandPlotterAdd << 
582   RegisterMessenger(new G4VisCommandPlotterAdd << 
583                                                << 
584   directory = new G4UIdirectory ("/vis/sceneHa    438   directory = new G4UIdirectory ("/vis/sceneHandler/");
585   directory -> SetGuidance ("Operations on Gea    439   directory -> SetGuidance ("Operations on Geant4 scene handlers.");
586   fDirectoryList.push_back (directory);           440   fDirectoryList.push_back (directory);
587   RegisterMessenger(new G4VisCommandSceneHandl    441   RegisterMessenger(new G4VisCommandSceneHandlerAttach);
588   RegisterMessenger(new G4VisCommandSceneHandl    442   RegisterMessenger(new G4VisCommandSceneHandlerCreate);
589   RegisterMessenger(new G4VisCommandSceneHandl    443   RegisterMessenger(new G4VisCommandSceneHandlerList);
590   RegisterMessenger(new G4VisCommandSceneHandl    444   RegisterMessenger(new G4VisCommandSceneHandlerSelect);
591                                                   445   
592   directory = new G4UIdirectory ("/vis/touchab    446   directory = new G4UIdirectory ("/vis/touchable/");
593   directory -> SetGuidance ("Operations on tou    447   directory -> SetGuidance ("Operations on touchables.");
594   fDirectoryList.push_back (directory);           448   fDirectoryList.push_back (directory);
595   RegisterMessenger(new G4VisCommandsTouchable    449   RegisterMessenger(new G4VisCommandsTouchable);
596                                                   450   
597   directory = new G4UIdirectory ("/vis/touchab    451   directory = new G4UIdirectory ("/vis/touchable/set/");
598   directory -> SetGuidance ("Set vis attribute    452   directory -> SetGuidance ("Set vis attributes of current touchable.");
599   fDirectoryList.push_back (directory);           453   fDirectoryList.push_back (directory);
600   RegisterMessenger(new G4VisCommandsTouchable    454   RegisterMessenger(new G4VisCommandsTouchableSet);
601                                                   455 
602   directory = new G4UIdirectory ("/vis/viewer/    456   directory = new G4UIdirectory ("/vis/viewer/");
603   directory -> SetGuidance ("Operations on Gea    457   directory -> SetGuidance ("Operations on Geant4 viewers.");
604   fDirectoryList.push_back (directory);           458   fDirectoryList.push_back (directory);
605   RegisterMessenger(new G4VisCommandViewerAddC    459   RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
606   RegisterMessenger(new G4VisCommandViewerCent << 
607   RegisterMessenger(new G4VisCommandViewerChan    460   RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
608   RegisterMessenger(new G4VisCommandViewerClea    461   RegisterMessenger(new G4VisCommandViewerClear);
609   RegisterMessenger(new G4VisCommandViewerClea    462   RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
610   RegisterMessenger(new G4VisCommandViewerClea    463   RegisterMessenger(new G4VisCommandViewerClearTransients);
611   RegisterMessenger(new G4VisCommandViewerClea << 
612   RegisterMessenger(new G4VisCommandViewerClon    464   RegisterMessenger(new G4VisCommandViewerClone);
613   RegisterMessenger(new G4VisCommandViewerColo << 
614   RegisterMessenger(new G4VisCommandViewerCopy    465   RegisterMessenger(new G4VisCommandViewerCopyViewFrom);
615   RegisterMessenger(new G4VisCommandViewerCrea    466   RegisterMessenger(new G4VisCommandViewerCreate);
616   RegisterMessenger(new G4VisCommandViewerDoll    467   RegisterMessenger(new G4VisCommandViewerDolly);
617   RegisterMessenger(new G4VisCommandViewerFlus    468   RegisterMessenger(new G4VisCommandViewerFlush);
618   RegisterMessenger(new G4VisCommandViewerInte << 
619   RegisterMessenger(new G4VisCommandViewerList    469   RegisterMessenger(new G4VisCommandViewerList);
620   RegisterMessenger(new G4VisCommandViewerPan)    470   RegisterMessenger(new G4VisCommandViewerPan);
621   RegisterMessenger(new G4VisCommandViewerRebu    471   RegisterMessenger(new G4VisCommandViewerRebuild);
622   RegisterMessenger(new G4VisCommandViewerRefr    472   RegisterMessenger(new G4VisCommandViewerRefresh);
623   RegisterMessenger(new G4VisCommandViewerRese    473   RegisterMessenger(new G4VisCommandViewerReset);
624   RegisterMessenger(new G4VisCommandViewerRese << 
625   RegisterMessenger(new G4VisCommandViewerSave    474   RegisterMessenger(new G4VisCommandViewerSave);
626   RegisterMessenger(new G4VisCommandViewerScal    475   RegisterMessenger(new G4VisCommandViewerScale);
627   RegisterMessenger(new G4VisCommandViewerSele    476   RegisterMessenger(new G4VisCommandViewerSelect);
628   RegisterMessenger(new G4VisCommandViewerUpda    477   RegisterMessenger(new G4VisCommandViewerUpdate);
629   RegisterMessenger(new G4VisCommandViewerZoom    478   RegisterMessenger(new G4VisCommandViewerZoom);
630                                                   479   
631   directory = new G4UIdirectory ("/vis/viewer/    480   directory = new G4UIdirectory ("/vis/viewer/default/");
632   directory -> SetGuidance("Set default values    481   directory -> SetGuidance("Set default values for future viewers.");
633   fDirectoryList.push_back (directory);           482   fDirectoryList.push_back (directory);
634   RegisterMessenger(new G4VisCommandViewerDefa    483   RegisterMessenger(new G4VisCommandViewerDefaultHiddenEdge);
635   RegisterMessenger(new G4VisCommandViewerDefa    484   RegisterMessenger(new G4VisCommandViewerDefaultStyle);
636                                                   485   
637   directory = new G4UIdirectory ("/vis/viewer/    486   directory = new G4UIdirectory ("/vis/viewer/set/");
638   directory -> SetGuidance ("Set view paramete    487   directory -> SetGuidance ("Set view parameters of current viewer.");
639   fDirectoryList.push_back (directory);           488   fDirectoryList.push_back (directory);
640   RegisterMessenger(new G4VisCommandsViewerSet    489   RegisterMessenger(new G4VisCommandsViewerSet);
641                                                   490   
642   // *Basic* top level commands were instantia << 
643   // so that they can be used immediately afte << 
644   // vis manager.  Other top level commands, i << 
645   // (i.e., commands that invoke other command << 
646                                                << 
647   RegisterMessenger(new G4VisCommandAbortRevie << 
648   RegisterMessenger(new G4VisCommandAbortRevie << 
649   RegisterMessenger(new G4VisCommandDrawOnlyTo << 
650   RegisterMessenger(new G4VisCommandDrawTree); << 
651   RegisterMessenger(new G4VisCommandDrawView); << 
652   RegisterMessenger(new G4VisCommandDrawLogica << 
653   RegisterMessenger(new G4VisCommandDrawVolume << 
654   RegisterMessenger(new G4VisCommandEnable);   << 
655   RegisterMessenger(new G4VisCommandList);     << 
656   RegisterMessenger(new G4VisCommandOpen);     << 
657   RegisterMessenger(new G4VisCommandPlot);     << 
658   RegisterMessenger(new G4VisCommandReviewKept << 
659   RegisterMessenger(new G4VisCommandReviewPlot << 
660   RegisterMessenger(new G4VisCommandSpecify);  << 
661                                                << 
662   // List manager commands                        491   // List manager commands
663   RegisterMessenger(new G4VisCommandListManage    492   RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
664         (fpTrajDrawModelMgr, fpTrajDrawModelMg    493         (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
665   RegisterMessenger(new G4VisCommandListManage    494   RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
666         (fpTrajDrawModelMgr, fpTrajDrawModelMg    495         (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
667                                                   496   
668   // Trajectory filter manager commands           497   // Trajectory filter manager commands
669   RegisterMessenger(new G4VisCommandListManage    498   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
670                     (fpTrajFilterMgr, fpTrajFi    499                     (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
671   RegisterMessenger(new G4VisCommandManagerMod    500   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
672                     (fpTrajFilterMgr, fpTrajFi    501                     (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
673                                                   502   
674   // Hit filter manager commands                  503   // Hit filter manager commands
675   RegisterMessenger(new G4VisCommandListManage    504   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
676                     (fpHitFilterMgr, fpHitFilt    505                     (fpHitFilterMgr, fpHitFilterMgr->Placement()));
677   RegisterMessenger(new G4VisCommandManagerMod    506   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
678                     (fpHitFilterMgr, fpHitFilt    507                     (fpHitFilterMgr, fpHitFilterMgr->Placement()));
679                                                   508   
680   // Digi filter manager commands                 509   // Digi filter manager commands
681   RegisterMessenger(new G4VisCommandListManage    510   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VDigi> >
682                     (fpDigiFilterMgr, fpDigiFi    511                     (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
683   RegisterMessenger(new G4VisCommandManagerMod    512   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VDigi> >
684                     (fpDigiFilterMgr, fpDigiFi    513                     (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
685 }                                                 514 }
686                                                   515 
687 #include <tools/histo/h1d>                     << 
688 #include <tools/histo/h2d>                     << 
689                                                << 
690 namespace {                                    << 
691   struct PlotResults {                         << 
692     std::size_t fNumberOfPlots = 0;            << 
693     std::size_t fTotalEntries = 0;             << 
694   };                                           << 
695   template <typename HT>  // tools::histo::h1d << 
696   PlotResults ResultsOfHnPlots(const G4String& << 
697     PlotResults plotResults;                   << 
698     auto ui = G4UImanager::GetUIpointer();     << 
699     auto keepControlVerbose = ui->GetVerboseLe << 
700     ui->SetVerboseLevel(0);                    << 
701     auto status = ui->ApplyCommand("/analysis/ << 
702     ui->SetVerboseLevel(keepControlVerbose);   << 
703     if(status==G4UIcommandStatus::fCommandSucc << 
704       G4String hexString = ui->GetCurrentValue << 
705       if(hexString.size()) {                   << 
706         void* ptr; std::istringstream is(hexSt << 
707         auto vectorOfPlots = (const std::vecto << 
708         for (std::size_t i = 0; i < vectorOfPl << 
709           auto plot = (*vectorOfPlots)[i];     << 
710           if (plot == nullptr) continue;  // I << 
711           ++plotResults.fNumberOfPlots;        << 
712           plotResults.fTotalEntries += plot->e << 
713         }                                      << 
714       }                                        << 
715     }                                          << 
716     return plotResults;                        << 
717   }                                            << 
718   void PrintListOfPlots() {                    << 
719     std::size_t numberOfPlots = 0;             << 
720     std::size_t numberOfEntries = 0;           << 
721     PlotResults h1results = ResultsOfHnPlots<t << 
722     numberOfPlots += h1results.fNumberOfPlots; << 
723     numberOfEntries += h1results.fTotalEntries << 
724     PlotResults h2results = ResultsOfHnPlots<t << 
725     numberOfPlots += h2results.fNumberOfPlots; << 
726     numberOfEntries += h2results.fTotalEntries << 
727     if (numberOfPlots > 0) {                   << 
728       G4warn << "There are histograms that can << 
729       if (h1results.fNumberOfPlots > 0) {      << 
730         G4warn << "\n  " << h1results.fNumberO << 
731       }                                        << 
732       if (h2results.fNumberOfPlots > 0) {      << 
733         G4warn << "\n  " << h2results.fNumberO << 
734       }                                        << 
735       G4warn                                   << 
736       << "\n  List them with \"/analysis/list\ << 
737       << "\n  View them immediately with \"/vi << 
738       << G4endl;                               << 
739       if (numberOfEntries == 0) {              << 
740         G4warn <<                              << 
741         "  But...there are no entries. To make << 
742         "\n  plotting in this UI session, use  << 
743         "\n  EndOfRunAction and Reset() in you << 
744         << G4endl;                             << 
745       }                                        << 
746     }                                          << 
747   }                                            << 
748 }                                              << 
749                                                << 
750 void G4VisManager::Enable() {                     516 void G4VisManager::Enable() {
751   if (IsValidView ()) {                           517   if (IsValidView ()) {
752     SetConcreteInstance(this);                    518     SetConcreteInstance(this);
753     if (fVerbosity >= confirmations) {            519     if (fVerbosity >= confirmations) {
754       G4cout << "G4VisManager::Enable: visuali    520       G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
755     }                                             521     }
756     if (fVerbosity >= warnings) {              << 
757       std::size_t nKeptEvents = 0;             << 
758       const G4Run* run = G4RunManager::GetRunM << 
759       if (run) nKeptEvents = run->GetNumberOfK << 
760       G4String isare("are"),plural("s");       << 
761       if (nKeptEvents == 1) {isare = "is"; plu << 
762       G4cout <<                                << 
763       "There " << isare << ' ' << nKeptEvents  << 
764       << G4endl;                               << 
765       if (nKeptEvents > 0) {                   << 
766         G4cout <<                              << 
767   "  \"/vis/reviewKeptEvents\" to review one b << 
768   "\n  To see accumulated, \"/vis/enable\", th << 
769         << G4endl;                             << 
770       }                                        << 
771       PrintListOfPlots();                      << 
772     }                                          << 
773   }                                               522   }
774   else {                                          523   else {
775     if (fVerbosity >= warnings) {                 524     if (fVerbosity >= warnings) {
776       G4warn <<                                << 525       G4cout <<
777   "G4VisManager::Enable: WARNING: visualizatio    526   "G4VisManager::Enable: WARNING: visualization remains disabled for"
778   "\n  above reasons.  Rectifying with valid v    527   "\n  above reasons.  Rectifying with valid vis commands will"
779   "\n  automatically enable."                     528   "\n  automatically enable."
780        << G4endl;                                 529        << G4endl;
781     }                                             530     }
782   }                                               531   }
783 }                                                 532 }
784                                                   533 
785 void G4VisManager::Disable() {                    534 void G4VisManager::Disable() {
786   SetConcreteInstance(0);                         535   SetConcreteInstance(0);
787   if (fVerbosity >= confirmations) {              536   if (fVerbosity >= confirmations) {
788     G4cout <<                                     537     G4cout <<
789     "G4VisManager::Disable: visualization disa << 538       "G4VisManager::Disable: visualization disabled."
790     "\n  The pointer returned by GetConcreteIn << 539       "\n  The pointer returned by GetConcreteInstance will be zero."
791     "\n  Note that it will become enabled afte << 540       "\n  Note that it will become enabled after some valid vis commands."
792      << G4endl;                                   541      << G4endl;
793   }                                               542   }
794   if (fVerbosity >= warnings) {                << 
795     G4int currentTrajectoryType =              << 
796     G4RunManagerKernel::GetRunManagerKernel()- << 
797     if (currentTrajectoryType > 0) {           << 
798     G4warn <<                                  << 
799       "You may wish to disable trajectory prod << 
800       "\n  \"/tracking/storeTrajectory 0\""    << 
801       "\nbut don't forget to re-enable with"   << 
802       "\n  \"/vis/enable\""                    << 
803       "\n  \"/tracking/storeTrajectory " << cu << 
804       << "\"\n  and maybe \"/vis/viewer/rebuil << 
805       << G4endl;                               << 
806     }                                          << 
807   }                                            << 
808 }                                                 543 }
809                                                   544 
810 const G4GraphicsSystemList& G4VisManager::GetA    545 const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () {
811   std::size_t nSystems = fAvailableGraphicsSys << 546   G4int nSystems = fAvailableGraphicsSystems.size ();
812   if (nSystems == 0) {                            547   if (nSystems == 0) {
813     if (fVerbosity >= warnings) {                 548     if (fVerbosity >= warnings) {
814       G4warn << "G4VisManager::GetAvailableGra << 549       G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
815   "\n graphics system available!"                 550   "\n graphics system available!"
816   "\n  1) Did you have environment variables G    551   "\n  1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
817   "\n     when you compiled/built the visualiz    552   "\n     when you compiled/built the visualization code?"
818   "\n  2) Did you instantiate your own Visuali    553   "\n  2) Did you instantiate your own Visualization Manager and forget"
819   "\n     to implement RegisterGraphicsSystems    554   "\n     to implement RegisterGraphicsSystems correctly?"
820   "\n  3) You can register your own graphics s    555   "\n  3) You can register your own graphics system, e.g.,"
821   "\n     visManager->RegisterGraphicsSystem(n    556   "\n     visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
822   "\n     after instantiating your vis manager    557   "\n     after instantiating your vis manager and before"
823   "\n     visManager->Initialize()."              558   "\n     visManager->Initialize()."
824        << G4endl;                                 559        << G4endl;
825     }                                             560     }
826   }                                               561   }
827   return fAvailableGraphicsSystems;               562   return fAvailableGraphicsSystems;
828 }                                                 563 }
829                                                   564 
830 G4bool G4VisManager::RegisterGraphicsSystem (G    565 G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) {
831   G4bool happy = true;                            566   G4bool happy = true;
832   if (pSystem) {                                  567   if (pSystem) {
833     fAvailableGraphicsSystems.push_back (pSyst    568     fAvailableGraphicsSystems.push_back (pSystem);
834     if (fVerbosity >= confirmations) {            569     if (fVerbosity >= confirmations) {
835       G4cout << "G4VisManager::RegisterGraphic    570       G4cout << "G4VisManager::RegisterGraphicsSystem: "
836        << pSystem -> GetName ();                  571        << pSystem -> GetName ();
837       if (pSystem -> GetNickname () != "") {      572       if (pSystem -> GetNickname () != "") {
838   G4cout << " (" << pSystem -> GetNickname ()     573   G4cout << " (" << pSystem -> GetNickname () << ")";
839       }                                           574       }
840       G4cout << " registered." << G4endl;         575       G4cout << " registered." << G4endl;
841     }                                             576     }
842   }                                               577   }
843   else {                                          578   else {
844     if (fVerbosity >= errors) {                   579     if (fVerbosity >= errors) {
845       G4warn << "G4VisManager::RegisterGraphic << 580       G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!"
846        << G4endl;                                 581        << G4endl;
847     }                                             582     }
848     happy=false;                                  583     happy=false;
849   }                                               584   }
850   return happy;                                   585   return happy;
851 }                                                 586 }
852                                                   587 
853 const G4VTrajectoryModel*                         588 const G4VTrajectoryModel*
854 G4VisManager::CurrentTrajDrawModel() const        589 G4VisManager::CurrentTrajDrawModel() const
855 {                                                 590 {
856   assert (0 != fpTrajDrawModelMgr);               591   assert (0 != fpTrajDrawModelMgr);
857                                                   592 
858   const G4VTrajectoryModel* model = fpTrajDraw    593   const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current();
859                                                   594 
860   if (0 == model) {                               595   if (0 == model) {
861     // No model was registered with the trajec    596     // No model was registered with the trajectory model manager.
862     // Use G4TrajectoryDrawByCharge as a fallb << 597     // Use G4TrajectoryDrawByCharge as a default.
863     fpTrajDrawModelMgr->Register(new G4Traject << 598     fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated"));
                                                   >> 599 
864     if (fVerbosity >= warnings) {                 600     if (fVerbosity >= warnings) {
865       G4warn<<"G4VisManager: Using G4Trajector << 601       G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
866       G4warn<<"See commands in /vis/modeling/t << 602       G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
867     }                                             603     }
868   }                                               604   }
869                                                   605 
870   model = fpTrajDrawModelMgr->Current();          606   model = fpTrajDrawModelMgr->Current();
871   assert (0 != model); // Should definitely ex    607   assert (0 != model); // Should definitely exist now
872                                                   608 
873   return model;                                   609   return model;
874 }                                                 610 }
875                                                   611 
876 void G4VisManager::RegisterModel(G4VTrajectory << 612 void G4VisManager::RegisterModel(G4VTrajectoryModel* model) 
877 {                                                 613 {
878   fpTrajDrawModelMgr->Register(model);            614   fpTrajDrawModelMgr->Register(model);
879 }                                                 615 }
880                                                   616 
881 void                                              617 void
882 G4VisManager::RegisterModelFactory(G4TrajDrawM    618 G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory) 
883 {                                                 619 {
884   fpTrajDrawModelMgr->Register(factory);          620   fpTrajDrawModelMgr->Register(factory);
885 }                                                 621 }
886                                                   622 
887 void G4VisManager::RegisterModel(G4VFilter<G4V    623 void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model)
888 {                                                 624 {
889   fpTrajFilterMgr->Register(model);               625   fpTrajFilterMgr->Register(model);
890 }                                                 626 }
891                                                   627 
892 void                                              628 void
893 G4VisManager::RegisterModelFactory(G4TrajFilte    629 G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory)
894 {                                                 630 {
895   fpTrajFilterMgr->Register(factory);             631   fpTrajFilterMgr->Register(factory);
896 }                                                 632 }
897                                                   633 
898 void G4VisManager::RegisterModel(G4VFilter<G4V    634 void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model)
899 {                                                 635 {
900   fpHitFilterMgr->Register(model);                636   fpHitFilterMgr->Register(model);
901 }                                                 637 }
902                                                   638 
903 void                                              639 void
904 G4VisManager::RegisterModelFactory(G4HitFilter    640 G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory)
905 {                                                 641 {
906   fpHitFilterMgr->Register(factory);              642   fpHitFilterMgr->Register(factory);
907 }                                                 643 }
908                                                   644 
909 void G4VisManager::RegisterModel(G4VFilter<G4V    645 void G4VisManager::RegisterModel(G4VFilter<G4VDigi>* model)
910 {                                                 646 {
911   fpDigiFilterMgr->Register(model);               647   fpDigiFilterMgr->Register(model);
912 }                                                 648 }
913                                                   649 
914 void                                              650 void
915 G4VisManager::RegisterModelFactory(G4DigiFilte    651 G4VisManager::RegisterModelFactory(G4DigiFilterFactory* factory)
916 {                                                 652 {
917   fpDigiFilterMgr->Register(factory);             653   fpDigiFilterMgr->Register(factory);
918 }                                                 654 }
919                                                   655 
920 void G4VisManager::SelectTrajectoryModel(const    656 void G4VisManager::SelectTrajectoryModel(const G4String& model) 
921 {                                                 657 {
922    fpTrajDrawModelMgr->SetCurrent(model);         658    fpTrajDrawModelMgr->SetCurrent(model);
923 }                                                 659 }
924                                                   660 
925 void G4VisManager::BeginDraw (const G4Transfor    661 void G4VisManager::BeginDraw (const G4Transform3D& objectTransform)
926 {                                                 662 {
                                                   >> 663 #ifdef G4MULTITHREADED
927   if (G4Threading::IsWorkerThread()) return;      664   if (G4Threading::IsWorkerThread()) return;
928                                                << 665 #endif
929   fDrawGroupNestingDepth++;                       666   fDrawGroupNestingDepth++;
930   if (fDrawGroupNestingDepth > 1) {               667   if (fDrawGroupNestingDepth > 1) {
931     G4Exception                                   668     G4Exception
932       ("G4VisManager::BeginDraw",                 669       ("G4VisManager::BeginDraw",
933        "visman0008", JustWarning,                 670        "visman0008", JustWarning,
934        "Nesting detected. It is illegal to nes    671        "Nesting detected. It is illegal to nest Begin/EndDraw."
935        "\n Ignored");                             672        "\n Ignored");
936     return;                                       673     return;
937   }                                               674   }
938   if (IsValidView ()) {                           675   if (IsValidView ()) {
939     ClearTransientStoreIfMarked();                676     ClearTransientStoreIfMarked();
940     fpSceneHandler -> BeginPrimitives (objectT    677     fpSceneHandler -> BeginPrimitives (objectTransform);
941     fIsDrawGroup = true;                          678     fIsDrawGroup = true;
942   }                                               679   }
943 }                                                 680 }
944                                                   681 
945 void G4VisManager::EndDraw ()                     682 void G4VisManager::EndDraw ()
946 {                                                 683 {
                                                   >> 684 #ifdef G4MULTITHREADED
947   if (G4Threading::IsWorkerThread()) return;      685   if (G4Threading::IsWorkerThread()) return;
948                                                << 686 #endif
949   fDrawGroupNestingDepth--;                       687   fDrawGroupNestingDepth--;
950   if (fDrawGroupNestingDepth != 0) {              688   if (fDrawGroupNestingDepth != 0) {
951     if (fDrawGroupNestingDepth < 0) fDrawGroup    689     if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
952     return;                                       690     return;
953   }                                               691   }
954   if (IsValidView ()) {                           692   if (IsValidView ()) {
955     fpSceneHandler -> EndPrimitives ();           693     fpSceneHandler -> EndPrimitives ();
956   }                                               694   }
957   fIsDrawGroup = false;                           695   fIsDrawGroup = false;
958 }                                                 696 }
959                                                   697 
960 void G4VisManager::BeginDraw2D (const G4Transf    698 void G4VisManager::BeginDraw2D (const G4Transform3D& objectTransform)
961 {                                                 699 {
                                                   >> 700 #ifdef G4MULTITHREADED
962   if (G4Threading::IsWorkerThread()) return;      701   if (G4Threading::IsWorkerThread()) return;
963                                                << 702 #endif
964   fDrawGroupNestingDepth++;                       703   fDrawGroupNestingDepth++;
965   if (fDrawGroupNestingDepth > 1) {               704   if (fDrawGroupNestingDepth > 1) {
966     G4Exception                                   705     G4Exception
967       ("G4VisManager::BeginDraw2D",               706       ("G4VisManager::BeginDraw2D",
968        "visman0009", JustWarning,                 707        "visman0009", JustWarning,
969        "Nesting detected. It is illegal to nes    708        "Nesting detected. It is illegal to nest Begin/EndDraw2D."
970        "\n Ignored");                             709        "\n Ignored");
971     return;                                       710     return;
972   }                                               711   }
973   if (IsValidView ()) {                           712   if (IsValidView ()) {
974     ClearTransientStoreIfMarked();                713     ClearTransientStoreIfMarked();
975     fpSceneHandler -> BeginPrimitives2D (objec    714     fpSceneHandler -> BeginPrimitives2D (objectTransform);
976     fIsDrawGroup = true;                          715     fIsDrawGroup = true;
977   }                                               716   }
978 }                                                 717 }
979                                                   718 
980 void G4VisManager::EndDraw2D ()                   719 void G4VisManager::EndDraw2D ()
981 {                                                 720 {
                                                   >> 721 #ifdef G4MULTITHREADED
982   if (G4Threading::IsWorkerThread()) return;      722   if (G4Threading::IsWorkerThread()) return;
983                                                << 723 #endif
984   fDrawGroupNestingDepth--;                       724   fDrawGroupNestingDepth--;
985   if (fDrawGroupNestingDepth != 0) {              725   if (fDrawGroupNestingDepth != 0) {
986     if (fDrawGroupNestingDepth < 0) fDrawGroup    726     if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
987     return;                                       727     return;
988   }                                               728   }
989   if (IsValidView ()) {                           729   if (IsValidView ()) {
990     fpSceneHandler -> EndPrimitives2D ();         730     fpSceneHandler -> EndPrimitives2D ();
991   }                                               731   }
992   fIsDrawGroup = false;                           732   fIsDrawGroup = false;
993 }                                                 733 }
994                                                   734 
995 template <class T> void G4VisManager::DrawT       735 template <class T> void G4VisManager::DrawT
996 (const T& graphics_primitive, const G4Transfor    736 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
                                                   >> 737 #ifdef G4MULTITHREADED
997   if (G4Threading::IsWorkerThread()) return;      738   if (G4Threading::IsWorkerThread()) return;
998                                                << 739 #endif
999   if (fIsDrawGroup) {                             740   if (fIsDrawGroup) {
1000     if (objectTransform != fpSceneHandler->Ge    741     if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
1001       G4Exception                                742       G4Exception
1002   ("G4VSceneHandler::DrawT",                     743   ("G4VSceneHandler::DrawT",
1003    "visman0010", FatalException,                 744    "visman0010", FatalException,
1004    "Different transform detected in Begin/End    745    "Different transform detected in Begin/EndDraw group.");
1005     }                                            746     }
1006     fpSceneHandler -> AddPrimitive (graphics_    747     fpSceneHandler -> AddPrimitive (graphics_primitive);
1007   } else {                                       748   } else {
1008     if (IsValidView ()) {                        749     if (IsValidView ()) {
1009       ClearTransientStoreIfMarked();             750       ClearTransientStoreIfMarked();
1010       fpSceneHandler -> BeginPrimitives (obje    751       fpSceneHandler -> BeginPrimitives (objectTransform);
1011       fpSceneHandler -> AddPrimitive (graphic    752       fpSceneHandler -> AddPrimitive (graphics_primitive);
1012       fpSceneHandler -> EndPrimitives ();        753       fpSceneHandler -> EndPrimitives ();
1013     }                                            754     }
1014   }                                              755   }
1015 }                                                756 }
1016                                                  757 
1017 template <class T> void G4VisManager::DrawT2D    758 template <class T> void G4VisManager::DrawT2D
1018 (const T& graphics_primitive, const G4Transfo    759 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
                                                   >> 760 #ifdef G4MULTITHREADED
1019   if (G4Threading::IsWorkerThread()) return;     761   if (G4Threading::IsWorkerThread()) return;
1020                                               << 762 #endif
1021   if (fIsDrawGroup) {                            763   if (fIsDrawGroup) {
1022     if (objectTransform != fpSceneHandler->Ge    764     if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
1023       G4Exception                                765       G4Exception
1024   ("G4VSceneHandler::DrawT",                     766   ("G4VSceneHandler::DrawT",
1025    "visman0011", FatalException,                 767    "visman0011", FatalException,
1026    "Different transform detected in Begin/End    768    "Different transform detected in Begin/EndDraw2D group.");
1027     }                                            769     }
1028     fpSceneHandler -> AddPrimitive (graphics_    770     fpSceneHandler -> AddPrimitive (graphics_primitive);
1029   } else {                                       771   } else {
1030     if (IsValidView ()) {                        772     if (IsValidView ()) {
1031       ClearTransientStoreIfMarked();             773       ClearTransientStoreIfMarked();
1032       fpSceneHandler -> BeginPrimitives2D (ob    774       fpSceneHandler -> BeginPrimitives2D (objectTransform);
1033       fpSceneHandler -> AddPrimitive (graphic    775       fpSceneHandler -> AddPrimitive (graphics_primitive);
1034       fpSceneHandler -> EndPrimitives2D ();      776       fpSceneHandler -> EndPrimitives2D ();
1035     }                                            777     }
1036   }                                              778   }
1037 }                                                779 }
1038                                                  780 
1039 void G4VisManager::Draw (const G4Circle& circ    781 void G4VisManager::Draw (const G4Circle& circle,
1040        const G4Transform3D& objectTransform)     782        const G4Transform3D& objectTransform)
1041 {                                                783 {
1042   DrawT (circle, objectTransform);               784   DrawT (circle, objectTransform);
1043 }                                                785 }
1044                                                  786 
1045 void G4VisManager::Draw (const G4Polyhedron&     787 void G4VisManager::Draw (const G4Polyhedron& polyhedron,
1046        const G4Transform3D& objectTransform)     788        const G4Transform3D& objectTransform)
1047 {                                                789 {
1048   DrawT (polyhedron, objectTransform);           790   DrawT (polyhedron, objectTransform);
1049 }                                                791 }
1050                                                  792 
1051 void G4VisManager::Draw (const G4Polyline& li    793 void G4VisManager::Draw (const G4Polyline& line,
1052        const G4Transform3D& objectTransform)     794        const G4Transform3D& objectTransform)
1053 {                                                795 {
1054   DrawT (line, objectTransform);                 796   DrawT (line, objectTransform);
1055 }                                                797 }
1056                                                  798 
1057 void G4VisManager::Draw (const G4Polymarker&     799 void G4VisManager::Draw (const G4Polymarker& polymarker,
1058        const G4Transform3D& objectTransform)     800        const G4Transform3D& objectTransform)
1059 {                                                801 {
1060   DrawT (polymarker, objectTransform);           802   DrawT (polymarker, objectTransform);
1061 }                                                803 }
1062                                                  804 
                                                   >> 805 void G4VisManager::Draw (const G4Scale& scale,
                                                   >> 806        const G4Transform3D& objectTransform)
                                                   >> 807 {
                                                   >> 808   DrawT (scale, objectTransform);
                                                   >> 809 }
                                                   >> 810 
1063 void G4VisManager::Draw (const G4Square& squa    811 void G4VisManager::Draw (const G4Square& square,
1064        const G4Transform3D& objectTransform)     812        const G4Transform3D& objectTransform)
1065 {                                                813 {
1066   DrawT (square, objectTransform);               814   DrawT (square, objectTransform);
1067 }                                                815 }
1068                                                  816 
1069 void G4VisManager::Draw (const G4Text& text,     817 void G4VisManager::Draw (const G4Text& text,
1070        const G4Transform3D& objectTransform)     818        const G4Transform3D& objectTransform)
1071 {                                                819 {
1072   DrawT (text, objectTransform);                 820   DrawT (text, objectTransform);
1073 }                                                821 }
1074                                                  822 
1075 void G4VisManager::Draw2D (const G4Circle& ci    823 void G4VisManager::Draw2D (const G4Circle& circle,
1076          const G4Transform3D& objectTransform    824          const G4Transform3D& objectTransform)
1077 {                                                825 {
1078   DrawT2D (circle, objectTransform);             826   DrawT2D (circle, objectTransform);
1079 }                                                827 }
1080                                                  828 
1081 void G4VisManager::Draw2D (const G4Polyhedron    829 void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
1082          const G4Transform3D& objectTransform    830          const G4Transform3D& objectTransform)
1083 {                                                831 {
1084   DrawT2D (polyhedron, objectTransform);         832   DrawT2D (polyhedron, objectTransform);
1085 }                                                833 }
1086                                                  834 
1087 void G4VisManager::Draw2D (const G4Polyline&     835 void G4VisManager::Draw2D (const G4Polyline& line,
1088          const G4Transform3D& objectTransform    836          const G4Transform3D& objectTransform)
1089 {                                                837 {
1090   DrawT2D (line, objectTransform);               838   DrawT2D (line, objectTransform);
1091 }                                                839 }
1092                                                  840 
1093 void G4VisManager::Draw2D (const G4Polymarker    841 void G4VisManager::Draw2D (const G4Polymarker& polymarker,
1094          const G4Transform3D& objectTransform    842          const G4Transform3D& objectTransform)
1095 {                                                843 {
1096   DrawT2D (polymarker, objectTransform);         844   DrawT2D (polymarker, objectTransform);
1097 }                                                845 }
1098                                                  846 
1099 void G4VisManager::Draw2D (const G4Square& sq    847 void G4VisManager::Draw2D (const G4Square& square,
1100          const G4Transform3D& objectTransform    848          const G4Transform3D& objectTransform)
1101 {                                                849 {
1102   DrawT2D (square, objectTransform);             850   DrawT2D (square, objectTransform);
1103 }                                                851 }
1104                                                  852 
1105 void G4VisManager::Draw2D (const G4Text& text    853 void G4VisManager::Draw2D (const G4Text& text,
1106          const G4Transform3D& objectTransform    854          const G4Transform3D& objectTransform)
1107 {                                                855 {
1108   DrawT2D (text, objectTransform);               856   DrawT2D (text, objectTransform);
1109 }                                                857 }
1110                                                  858 
1111 void G4VisManager::Draw (const G4VHit& hit) {    859 void G4VisManager::Draw (const G4VHit& hit) {
                                                   >> 860 #ifdef G4MULTITHREADED
1112   if (G4Threading::IsWorkerThread()) return;     861   if (G4Threading::IsWorkerThread()) return;
1113                                               << 862 #endif
1114   if (fIsDrawGroup) {                            863   if (fIsDrawGroup) {
1115     fpSceneHandler -> AddCompound (hit);         864     fpSceneHandler -> AddCompound (hit);
1116   } else {                                       865   } else {
1117     if (IsValidView ()) {                        866     if (IsValidView ()) {
1118       ClearTransientStoreIfMarked();             867       ClearTransientStoreIfMarked();
1119       fpSceneHandler -> AddCompound (hit);       868       fpSceneHandler -> AddCompound (hit);
1120     }                                            869     }
1121   }                                              870   }
1122 }                                                871 }
1123                                                  872 
1124 void G4VisManager::Draw (const G4VDigi& digi)    873 void G4VisManager::Draw (const G4VDigi& digi) {
                                                   >> 874 #ifdef G4MULTITHREADED
1125   if (G4Threading::IsWorkerThread()) return;     875   if (G4Threading::IsWorkerThread()) return;
1126                                               << 876 #endif
1127   if (fIsDrawGroup) {                            877   if (fIsDrawGroup) {
1128     fpSceneHandler -> AddCompound (digi);        878     fpSceneHandler -> AddCompound (digi);
1129   } else {                                       879   } else {
1130     if (IsValidView ()) {                        880     if (IsValidView ()) {
1131       ClearTransientStoreIfMarked();             881       ClearTransientStoreIfMarked();
1132       fpSceneHandler -> AddCompound (digi);      882       fpSceneHandler -> AddCompound (digi);
1133     }                                            883     }
1134   }                                              884   }
1135 }                                                885 }
1136                                                  886 
1137 void G4VisManager::Draw (const G4VTrajectory&    887 void G4VisManager::Draw (const G4VTrajectory& traj) {
                                                   >> 888 #ifdef G4MULTITHREADED
1138   if (G4Threading::IsWorkerThread()) return;     889   if (G4Threading::IsWorkerThread()) return;
1139                                               << 890 #endif
1140   // A trajectory needs a trajectories model     891   // A trajectory needs a trajectories model to provide G4Atts, etc.
1141   static G4TrajectoriesModel trajectoriesMode    892   static G4TrajectoriesModel trajectoriesModel;
1142   trajectoriesModel.SetCurrentTrajectory(&tra    893   trajectoriesModel.SetCurrentTrajectory(&traj);
1143   G4RunManager* runManager = G4RunManagerFact << 894   const G4Run* currentRun = G4RunManager::GetRunManager()->GetCurrentRun();
1144   const G4Run* currentRun  = runManager->GetC << 
1145   if (currentRun) {                              895   if (currentRun) {
1146     trajectoriesModel.SetRunID(currentRun->Ge    896     trajectoriesModel.SetRunID(currentRun->GetRunID());
1147   }                                              897   }
1148   const G4Event* currentEvent =                  898   const G4Event* currentEvent =
1149   G4EventManager::GetEventManager()->GetConst    899   G4EventManager::GetEventManager()->GetConstCurrentEvent();
1150   if (currentEvent) {                            900   if (currentEvent) {
1151     trajectoriesModel.SetEventID(currentEvent    901     trajectoriesModel.SetEventID(currentEvent->GetEventID());
1152   }                                              902   }
1153   if (fIsDrawGroup) {                            903   if (fIsDrawGroup) {
1154     fpSceneHandler -> SetModel (&trajectories    904     fpSceneHandler -> SetModel (&trajectoriesModel);
1155     fpSceneHandler -> AddCompound (traj);        905     fpSceneHandler -> AddCompound (traj);
1156     fpSceneHandler -> SetModel (0);              906     fpSceneHandler -> SetModel (0);
1157   } else {                                       907   } else {
1158     if (IsValidView ()) {                        908     if (IsValidView ()) {
1159       ClearTransientStoreIfMarked();             909       ClearTransientStoreIfMarked();
1160       fpSceneHandler -> SetModel (&trajectori    910       fpSceneHandler -> SetModel (&trajectoriesModel);
1161       fpSceneHandler -> AddCompound (traj);      911       fpSceneHandler -> AddCompound (traj);
1162       fpSceneHandler -> SetModel (0);            912       fpSceneHandler -> SetModel (0);
1163     }                                            913     }
1164   }                                              914   }
1165 }                                                915 }
1166                                                  916 
1167 void G4VisManager::Draw (const G4LogicalVolum    917 void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
1168        const G4VisAttributes& attribs,           918        const G4VisAttributes& attribs,
1169        const G4Transform3D& objectTransform)     919        const G4Transform3D& objectTransform) {
                                                   >> 920 #ifdef G4MULTITHREADED
1170   if (G4Threading::IsWorkerThread()) return;     921   if (G4Threading::IsWorkerThread()) return;
1171                                               << 922 #endif
1172   // Find corresponding solid.                   923   // Find corresponding solid.
1173   G4VSolid* pSol = logicalVol.GetSolid ();       924   G4VSolid* pSol = logicalVol.GetSolid ();
1174   Draw (*pSol, attribs, objectTransform);        925   Draw (*pSol, attribs, objectTransform);
1175 }                                                926 }
1176                                                  927 
1177 void G4VisManager::Draw (const G4VSolid& soli    928 void G4VisManager::Draw (const G4VSolid& solid,
1178        const G4VisAttributes& attribs,           929        const G4VisAttributes& attribs,
1179        const G4Transform3D& objectTransform)     930        const G4Transform3D& objectTransform) {
                                                   >> 931 #ifdef G4MULTITHREADED
1180   if (G4Threading::IsWorkerThread()) return;     932   if (G4Threading::IsWorkerThread()) return;
1181                                               << 933 #endif
1182   if (fIsDrawGroup) {                            934   if (fIsDrawGroup) {
1183     fpSceneHandler -> PreAddSolid (objectTran    935     fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1184     solid.DescribeYourselfTo (*fpSceneHandler    936     solid.DescribeYourselfTo (*fpSceneHandler);
1185     fpSceneHandler -> PostAddSolid ();           937     fpSceneHandler -> PostAddSolid ();
1186   } else {                                       938   } else {
1187     if (IsValidView ()) {                        939     if (IsValidView ()) {
1188       ClearTransientStoreIfMarked();             940       ClearTransientStoreIfMarked();
1189       fpSceneHandler -> PreAddSolid (objectTr    941       fpSceneHandler -> PreAddSolid (objectTransform, attribs);
1190       solid.DescribeYourselfTo (*fpSceneHandl    942       solid.DescribeYourselfTo (*fpSceneHandler);
1191       fpSceneHandler -> PostAddSolid ();         943       fpSceneHandler -> PostAddSolid ();
1192     }                                            944     }
1193   }                                              945   }
1194 }                                                946 }
1195                                                  947 
1196 void G4VisManager::Draw (const G4VPhysicalVol    948 void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
1197        const G4VisAttributes& attribs,           949        const G4VisAttributes& attribs,
1198        const G4Transform3D& objectTransform)     950        const G4Transform3D& objectTransform) {
                                                   >> 951 #ifdef G4MULTITHREADED
1199   if (G4Threading::IsWorkerThread()) return;     952   if (G4Threading::IsWorkerThread()) return;
1200                                               << 953 #endif
1201   // Note: It is tempting to use a temporary     954   // Note: It is tempting to use a temporary model here, as for
1202   // trajectories, in order to get at the G4A    955   // trajectories, in order to get at the G4Atts of the physical
1203   // volume.  I tried it (JA).  But it's not     956   // volume.  I tried it (JA).  But it's not easy to pass the
1204   // vis attributes.  Also other aspects of t    957   // vis attributes.  Also other aspects of the model seem not to
1205   // be properly set up.  So, the idea has be    958   // be properly set up.  So, the idea has been abandoned for the time
1206   // being.  The model pointer will be null.     959   // being.  The model pointer will be null.  So when picking there
1207   // will be no G4Atts from this physical vol    960   // will be no G4Atts from this physical volume.
1208   //                                             961   //
1209   // If this is called from DrawHit, for exam    962   // If this is called from DrawHit, for example, the user may G4Atts to the
1210   // hit and these will be available with "/v    963   // hit and these will be available with "/vis/scene/add/hits".
1211   //                                             964   //
1212   // Find corresponding logical volume and so    965   // Find corresponding logical volume and solid.
1213   G4LogicalVolume* pLV  = physicalVol.GetLogi    966   G4LogicalVolume* pLV  = physicalVol.GetLogicalVolume ();
1214   G4VSolid*        pSol = pLV -> GetSolid ();    967   G4VSolid*        pSol = pLV -> GetSolid ();
1215   Draw (*pSol, attribs, objectTransform);        968   Draw (*pSol, attribs, objectTransform);
1216 }                                                969 }
1217                                                  970 
1218 void G4VisManager::DrawGeometry               << 
1219 (G4VPhysicalVolume* v, const G4Transform3D& t << 
1220 // Draws a geometry tree starting at the spec << 
1221 {                                             << 
1222   auto modelingParameters = fpSceneHandler->C << 
1223   auto depth = G4PhysicalVolumeModel::UNLIMIT << 
1224   const G4bool useFullExtent = true;          << 
1225   G4PhysicalVolumeModel aPVModel(v,depth,t,mo << 
1226   aPVModel.DescribeYourselfTo(*fpSceneHandler << 
1227   delete modelingParameters;                  << 
1228 }                                             << 
1229                                               << 
1230 void G4VisManager::CreateSceneHandler (const     971 void G4VisManager::CreateSceneHandler (const G4String& name) {
1231   if (!fInitialised) Initialise ();              972   if (!fInitialised) Initialise ();
1232   if (fpGraphicsSystem) {                        973   if (fpGraphicsSystem) {
1233     G4VSceneHandler* pSceneHandler =             974     G4VSceneHandler* pSceneHandler =
1234       fpGraphicsSystem -> CreateSceneHandler     975       fpGraphicsSystem -> CreateSceneHandler (name);
1235     if (pSceneHandler) {                         976     if (pSceneHandler) {
1236       fAvailableSceneHandlers.push_back (pSce    977       fAvailableSceneHandlers.push_back (pSceneHandler);
1237       fpSceneHandler = pSceneHandler;            978       fpSceneHandler = pSceneHandler;                         // Make current.
1238     }                                            979     }
1239     else {                                       980     else {
1240       if (fVerbosity >= errors) {                981       if (fVerbosity >= errors) {
1241   G4warn << "ERROR in G4VisManager::CreateSce << 982   G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
1242          << fpGraphicsSystem -> GetName ()       983          << fpGraphicsSystem -> GetName ()
1243          << " scene handler creation.\n  No a    984          << " scene handler creation.\n  No action taken."
1244          << G4endl;                              985          << G4endl;
1245       }                                          986       }
1246     }                                            987     }
1247   }                                              988   }
1248   else PrintInvalidPointers ();                  989   else PrintInvalidPointers ();
1249 }                                                990 }
1250                                                  991 
1251 void G4VisManager::CreateViewer                  992 void G4VisManager::CreateViewer
1252 (const G4String& name, const G4String& XGeome    993 (const G4String& name, const G4String& XGeometry)
1253 {                                                994 {
1254                                                  995 
1255   if (!fInitialised) Initialise ();              996   if (!fInitialised) Initialise ();
1256                                                  997 
1257   if (!fpSceneHandler) {                         998   if (!fpSceneHandler) {
1258     PrintInvalidPointers ();                     999     PrintInvalidPointers ();
1259     return;                                      1000     return;
1260   }                                              1001   }
1261                                                  1002 
1262   G4VViewer* p = fpGraphicsSystem -> CreateVi    1003   G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
1263                                                  1004 
1264   if (!p) {                                      1005   if (!p) {
1265     if (fVerbosity >= errors) {                  1006     if (fVerbosity >= errors) {
1266       G4warn << "ERROR in G4VisManager::Creat << 1007       G4cerr << "ERROR in G4VisManager::CreateViewer during "
1267        << fpGraphicsSystem -> GetName ()         1008        << fpGraphicsSystem -> GetName ()
1268        << " viewer creation.\n  No action tak    1009        << " viewer creation.\n  No action taken."
1269        << G4endl;                                1010        << G4endl;
1270     }                                            1011     }
1271     return;                                      1012     return;
1272   }                                              1013   }
1273                                                  1014 
1274   if (p -> GetViewId() < 0) {                    1015   if (p -> GetViewId() < 0) {
1275     if (fVerbosity >= errors) {                  1016     if (fVerbosity >= errors) {
1276       G4warn << "ERROR in G4VisManager::Creat << 1017       G4cerr << "ERROR in G4VisManager::CreateViewer during "
1277        << fpGraphicsSystem -> GetName ()         1018        << fpGraphicsSystem -> GetName ()
1278        << " viewer instantiation.\n  No actio << 1019        << " viewer initialisation.\n  No action taken."
1279        << G4endl;                                1020        << G4endl;
1280     }                                            1021     }
1281     return;                                      1022     return;
1282   }                                              1023   }
1283                                                  1024 
1284   // Viewer is created, now we can set geomet    1025   // Viewer is created, now we can set geometry parameters
1285   // Before 12/2008, it was done in G4VViewer    1026   // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
1286                                                  1027     
1287   G4ViewParameters initialvp = p -> GetViewPa    1028   G4ViewParameters initialvp = p -> GetViewParameters();
1288   initialvp.SetXGeometryString(XGeometry); //    1029   initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
1289   p -> SetViewParameters(initialvp);             1030   p -> SetViewParameters(initialvp);
1290   p -> Initialise ();  // (Viewer itself may     1031   p -> Initialise ();  // (Viewer itself may change view parameters further.)
1291   if (p -> GetViewId() < 0) {                 << 
1292     if (fVerbosity >= errors) {               << 
1293       G4warn << "ERROR in G4VisManager::Creat << 
1294        << fpGraphicsSystem -> GetName ()      << 
1295        << " viewer initialisation.\n  No acti << 
1296        << G4endl;                             << 
1297     }                                         << 
1298     return;                                   << 
1299   }                                           << 
1300                                                  1032 
1301   fpViewer = p;                             /    1033   fpViewer = p;                             // Make current.
1302   fpSceneHandler -> AddViewerToList (fpViewer    1034   fpSceneHandler -> AddViewerToList (fpViewer);
1303   fpSceneHandler -> SetCurrentViewer (fpViewe    1035   fpSceneHandler -> SetCurrentViewer (fpViewer);
1304   if (fVerbosity >= confirmations) {             1036   if (fVerbosity >= confirmations) {
1305     G4cout << "G4VisManager::CreateViewer: ne    1037     G4cout << "G4VisManager::CreateViewer: new viewer created."
1306      << G4endl;                                  1038      << G4endl;
1307   }                                              1039   }
1308                                                  1040 
1309   const G4ViewParameters& vp = fpViewer->GetV    1041   const G4ViewParameters& vp = fpViewer->GetViewParameters();
1310   if (fVerbosity >= parameters) {                1042   if (fVerbosity >= parameters) {
1311     G4cout << " view parameters are:\n  " <<     1043     G4cout << " view parameters are:\n  " << vp << G4endl;
1312   }                                              1044   }
1313                                                  1045 
1314   if (vp.IsCulling () && vp.IsCullingInvisibl    1046   if (vp.IsCulling () && vp.IsCullingInvisible ()) {
1315     static G4bool warned = false;                1047     static G4bool warned = false;
1316     if (fVerbosity >= confirmations) {           1048     if (fVerbosity >= confirmations) {
1317       if (!warned) {                             1049       if (!warned) {
1318   G4cout <<                                      1050   G4cout <<
1319   "NOTE: objects with visibility flag set to     1051   "NOTE: objects with visibility flag set to \"false\""
1320   " will not be drawn!"                          1052   " will not be drawn!"
1321   "\n  \"/vis/viewer/set/culling global false    1053   "\n  \"/vis/viewer/set/culling global false\" to Draw such objects."
1322   "\n  Also see other \"/vis/viewer/set\" com    1054   "\n  Also see other \"/vis/viewer/set\" commands."
1323          << G4endl;                              1055          << G4endl;
1324   warned = true;                                 1056   warned = true;
1325       }                                          1057       }
1326     }                                            1058     }
1327   }                                              1059   }
1328   if (vp.IsCullingCovered ()) {                  1060   if (vp.IsCullingCovered ()) {
1329     static G4bool warned = false;                1061     static G4bool warned = false;
1330     if (fVerbosity >= warnings) {                1062     if (fVerbosity >= warnings) {
1331       if (!warned) {                             1063       if (!warned) {
1332   G4warn <<                                   << 1064   G4cout <<
1333   "WARNING: covered objects in solid mode wil    1065   "WARNING: covered objects in solid mode will not be rendered!"
1334   "\n  \"/vis/viewer/set/culling coveredDaugh    1066   "\n  \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
1335   "\n  Also see other \"/vis/viewer/set\" com    1067   "\n  Also see other \"/vis/viewer/set\" commands."
1336          << G4endl;                              1068          << G4endl;
1337   warned = true;                                 1069   warned = true;
1338       }                                          1070       }
1339     }                                            1071     }
1340   }                                              1072   }
1341 }                                                1073 }
1342                                                  1074 
1343 void G4VisManager::GeometryHasChanged () {       1075 void G4VisManager::GeometryHasChanged () {
1344   if (fVerbosity >= confirmations) {             1076   if (fVerbosity >= confirmations) {
1345     G4cout << "G4VisManager::GeometryHasChang    1077     G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
1346   }                                              1078   }
1347                                                  1079 
1348   // Change the world...                         1080   // Change the world...
1349   G4VPhysicalVolume* pWorld =                    1081   G4VPhysicalVolume* pWorld =
1350     G4TransportationManager::GetTransportatio    1082     G4TransportationManager::GetTransportationManager ()
1351     -> GetNavigatorForTracking () -> GetWorld    1083     -> GetNavigatorForTracking () -> GetWorldVolume ();
1352   if (!pWorld) {                                 1084   if (!pWorld) {
1353     if (fVerbosity >= warnings) {                1085     if (fVerbosity >= warnings) {
1354       G4warn << "WARNING: There is no world v << 1086       G4cout << "WARNING: There is no world volume!" << G4endl;
1355     }                                            1087     }
1356   }                                              1088   }
1357                                                  1089 
1358   // Check scenes.                               1090   // Check scenes.
1359   G4SceneList& sceneList = fSceneList;           1091   G4SceneList& sceneList = fSceneList;
1360   std::size_t iScene, nScenes = sceneList.siz << 1092   G4int iScene, nScenes = sceneList.size ();
1361   for (iScene = 0; iScene < nScenes; ++iScene << 1093   for (iScene = 0; iScene < nScenes; iScene++) {
1362     G4Scene* pScene = sceneList [iScene];        1094     G4Scene* pScene = sceneList [iScene];
1363     std::vector<G4Scene::Model>& modelList =     1095     std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1364     if (modelList.size ()) {                     1096     if (modelList.size ()) {
1365       G4bool modelInvalid;                       1097       G4bool modelInvalid;
1366       do {  // Remove, if required, one at a     1098       do {  // Remove, if required, one at a time.
1367   modelInvalid = false;                          1099   modelInvalid = false;
1368   std::vector<G4Scene::Model>::iterator iterM    1100   std::vector<G4Scene::Model>::iterator iterModel;
1369   for (iterModel = modelList.begin();            1101   for (iterModel = modelList.begin();
1370        iterModel != modelList.end();             1102        iterModel != modelList.end();
1371        ++iterModel) {                            1103        ++iterModel) {
1372     modelInvalid = !(iterModel->fpModel->Vali    1104     modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=warnings));
1373     if (modelInvalid) {                          1105     if (modelInvalid) {
1374       // Model invalid - remove and break.       1106       // Model invalid - remove and break.
1375       if (fVerbosity >= warnings) {              1107       if (fVerbosity >= warnings) {
1376         G4warn << "WARNING: Model \""         << 1108         G4cout << "WARNING: Model \""
1377          << iterModel->fpModel->GetGlobalDesc    1109          << iterModel->fpModel->GetGlobalDescription ()
1378          <<                                      1110          <<
1379     "\" is no longer valid - being removed\n     1111     "\" is no longer valid - being removed\n  from scene \""
1380          << pScene -> GetName () << "\""         1112          << pScene -> GetName () << "\""
1381          << G4endl;                              1113          << G4endl;
1382       }                                          1114       }
1383       modelList.erase (iterModel);               1115       modelList.erase (iterModel);
1384       break;                                     1116       break;
1385     }                                            1117     }
1386   }                                              1118   }
1387       } while (modelInvalid);                    1119       } while (modelInvalid);
1388                                                  1120 
1389       if (modelList.size () == 0) {              1121       if (modelList.size () == 0) {
1390   if (fVerbosity >= warnings) {                  1122   if (fVerbosity >= warnings) {
1391     G4warn << "WARNING: No run-duration model << 1123     G4cout << "WARNING: No models left in this scene \""
1392      << pScene -> GetName ()                     1124      << pScene -> GetName ()
1393      << "\"."                                    1125      << "\"."
1394      << G4endl;                                  1126      << G4endl;
1395   }                                              1127   }
1396         if (pWorld) {                         << 
1397           if (fVerbosity >= warnings) {       << 
1398             G4warn << "  Adding current world << 
1399             << pScene -> GetName ()           << 
1400             << "\"."                          << 
1401             << G4endl;                        << 
1402           }                                   << 
1403           pScene->AddRunDurationModel(new G4P << 
1404           // (The above includes a re-calcula << 
1405           G4UImanager::GetUIpointer () ->     << 
1406           ApplyCommand (G4String("/vis/scene/ << 
1407         }                                     << 
1408       }                                          1128       }
1409       else {                                     1129       else {
1410   pScene->CalculateExtent();  // Recalculate  << 1130   pScene->CalculateExtent();
1411   G4UImanager::GetUIpointer () ->                1131   G4UImanager::GetUIpointer () ->
1412     ApplyCommand (G4String("/vis/scene/notify    1132     ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1413       }                                          1133       }
1414     }                                            1134     }
1415   }                                              1135   }
1416                                                  1136 
1417   // Check the manager's current scene...        1137   // Check the manager's current scene...
1418   if (fpScene && fpScene -> GetRunDurationMod    1138   if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1419     if (fVerbosity >= warnings) {                1139     if (fVerbosity >= warnings) {
1420       G4warn << "WARNING: The current scene \ << 1140       G4cout << "WARNING: The current scene \""
1421        << fpScene -> GetName ()                  1141        << fpScene -> GetName ()
1422        << "\" has no run duration models."    << 1142        << "\" has no models."
1423              << "\n  Use \"/vis/scene/add/vol << 
1424        << G4endl;                                1143        << G4endl;
1425     }                                            1144     }
1426     // Clean up                               << 
1427     if (fpSceneHandler) {                     << 
1428       fpSceneHandler->ClearTransientStore();  << 
1429       fpSceneHandler->ClearStore();           << 
1430       if (fpViewer) {                         << 
1431         fpViewer->NeedKernelVisit();          << 
1432         fpViewer->SetView();                  << 
1433         fpViewer->ClearView();                << 
1434         fpViewer->FinishView();               << 
1435       }                                       << 
1436     }                                         << 
1437   }                                              1145   }
1438 }                                                1146 }
1439                                                  1147 
1440 void G4VisManager::NotifyHandlers () {           1148 void G4VisManager::NotifyHandlers () {
1441                                                  1149 
1442   if (fVerbosity >= confirmations) {             1150   if (fVerbosity >= confirmations) {
1443     G4cout << "G4VisManager::NotifyHandler()     1151     G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
1444   }                                              1152   }
1445                                                  1153 
1446   if (IsValidView()) {                        << 1154   // Check scenes.
1447                                               << 1155   G4SceneList& sceneList = fSceneList;
1448     // Check scenes.                          << 1156   G4int iScene, nScenes = sceneList.size ();
1449     G4SceneList& sceneList = fSceneList;      << 1157   for (iScene = 0; iScene < nScenes; iScene++) {
1450     std::size_t iScene, nScenes = sceneList.s << 1158     G4Scene* pScene = sceneList [iScene];
1451     for (iScene = 0; iScene < nScenes; ++iSce << 1159     std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
1452       G4Scene* pScene = sceneList [iScene];   << 1160     
1453       std::vector<G4Scene::Model>& modelList  << 1161     if (modelList.size ()) {
1454                                               << 1162       pScene->CalculateExtent();
1455       if (modelList.size ()) {                << 1163       G4UImanager::GetUIpointer () ->
1456         pScene->CalculateExtent();            << 
1457         G4UImanager::GetUIpointer () ->       << 
1458         ApplyCommand (G4String("/vis/scene/no    1164         ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
1459       }                                       << 
1460     }                                            1165     }
                                                   >> 1166   }
1461                                                  1167 
1462     // Check the manager's current scene...   << 1168   // Check the manager's current scene...
1463     if (fpScene && fpScene -> GetRunDurationM << 1169   if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
1464       if (fVerbosity >= warnings) {           << 1170     if (fVerbosity >= warnings) {
1465         G4warn << "WARNING: The current scene << 1171       G4cout << "WARNING: The current scene \""
1466         << fpScene -> GetName ()              << 1172        << fpScene -> GetName ()
1467         << "\" has no run duration models."   << 1173        << "\" has no models."
1468         << "\n  Use \"/vis/scene/add/volume\" << 1174        << G4endl;
1469         << G4endl;                            << 
1470       }                                       << 
1471       fpSceneHandler->ClearTransientStore();  << 
1472       fpSceneHandler->ClearStore();           << 
1473       fpViewer->NeedKernelVisit();            << 
1474       fpViewer->SetView();                    << 
1475       fpViewer->ClearView();                  << 
1476       fpViewer->FinishView();                 << 
1477     }                                            1175     }
1478   }                                              1176   }
1479 }                                                1177 }
1480                                                  1178 
1481 G4bool G4VisManager::FilterTrajectory(const G    1179 G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory)
1482 {                                                1180 {
1483   return fpTrajFilterMgr->Accept(trajectory);    1181   return fpTrajFilterMgr->Accept(trajectory);
1484 }                                                1182 }   
1485                                                  1183 
1486 G4bool G4VisManager::FilterHit(const G4VHit&     1184 G4bool G4VisManager::FilterHit(const G4VHit& hit)
1487 {                                                1185 {
1488   return fpHitFilterMgr->Accept(hit);            1186   return fpHitFilterMgr->Accept(hit);
1489 }                                                1187 }   
1490                                                  1188 
1491 G4bool G4VisManager::FilterDigi(const G4VDigi    1189 G4bool G4VisManager::FilterDigi(const G4VDigi& digi)
1492 {                                                1190 {
1493   return fpDigiFilterMgr->Accept(digi);          1191   return fpDigiFilterMgr->Accept(digi);
1494 }                                                1192 }   
1495                                                  1193 
1496 void G4VisManager::DispatchToModel(const G4VT    1194 void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory)
1497 {                                                1195 {
1498   G4bool visible(true);                          1196   G4bool visible(true);
1499                                                  1197 
1500   // See if trajectory passes filter             1198   // See if trajectory passes filter
1501   G4bool passed = FilterTrajectory(trajectory    1199   G4bool passed = FilterTrajectory(trajectory);
1502                                                  1200 
1503   if (!passed) {                                 1201   if (!passed) {
1504     // Draw invisible trajectory if trajector    1202     // Draw invisible trajectory if trajectory failed filter and
1505     // are filtering in soft mode                1203     // are filtering in soft mode
1506     if (fpTrajFilterMgr->GetMode() == FilterM    1204     if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
1507     else {return;}                               1205     else {return;}
1508   }                                              1206   }
1509                                                  1207 
1510   // Go on to draw trajectory                    1208   // Go on to draw trajectory
1511   assert (0 != fpTrajDrawModelMgr);              1209   assert (0 != fpTrajDrawModelMgr);
1512                                                  1210 
1513   const G4VTrajectoryModel* trajectoryModel =    1211   const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
1514                                                  1212 
1515   assert (0 != trajectoryModel); // Should ex    1213   assert (0 != trajectoryModel); // Should exist
1516                                                  1214 
1517   if (IsValidView()) {                           1215   if (IsValidView()) {
1518       trajectoryModel->Draw(trajectory, visib    1216       trajectoryModel->Draw(trajectory, visible);
1519   }                                              1217   }
1520 }                                                1218 }
1521                                                  1219 
1522 void G4VisManager::RegisterRunDurationUserVis    1220 void G4VisManager::RegisterRunDurationUserVisAction
1523 (const G4String& name,                           1221 (const G4String& name,
1524  G4VUserVisAction* pVisAction,                   1222  G4VUserVisAction* pVisAction,
1525  const G4VisExtent& extent) {                    1223  const G4VisExtent& extent) {
1526   fRunDurationUserVisActions.push_back(UserVi    1224   fRunDurationUserVisActions.push_back(UserVisAction(name,pVisAction));
1527   if (extent.GetExtentRadius() > 0.) {           1225   if (extent.GetExtentRadius() > 0.) {
1528     fUserVisActionExtents[pVisAction] = exten    1226     fUserVisActionExtents[pVisAction] = extent;
1529   } else {                                       1227   } else {
1530     if (fVerbosity >= warnings) {                1228     if (fVerbosity >= warnings) {
1531       G4warn <<                               << 1229       G4cout << 
1532   "WARNING: No extent set for user vis action    1230   "WARNING: No extent set for user vis action \"" << name << "\"."
1533        << G4endl;                                1231        << G4endl;
1534     }                                            1232     }
1535   }                                              1233   }
1536   if (fVerbosity >= confirmations) {          << 
1537     G4cout                                    << 
1538     << "Run duration user vis action \"" << n << 
1539     << G4endl;                                << 
1540   }                                           << 
1541 }                                                1234 }
1542                                                  1235 
1543 void G4VisManager::RegisterEndOfEventUserVisA    1236 void G4VisManager::RegisterEndOfEventUserVisAction
1544 (const G4String& name,                           1237 (const G4String& name,
1545  G4VUserVisAction* pVisAction,                   1238  G4VUserVisAction* pVisAction,
1546  const G4VisExtent& extent) {                    1239  const G4VisExtent& extent) {
1547   fEndOfEventUserVisActions.push_back(UserVis    1240   fEndOfEventUserVisActions.push_back(UserVisAction(name,pVisAction));
1548   if (extent.GetExtentRadius() > 0.) {           1241   if (extent.GetExtentRadius() > 0.) {
1549     fUserVisActionExtents[pVisAction] = exten    1242     fUserVisActionExtents[pVisAction] = extent;
1550   } else {                                       1243   } else {
1551     if (fVerbosity >= warnings) {                1244     if (fVerbosity >= warnings) {
1552       G4warn <<                               << 1245       G4cout << 
1553   "WARNING: No extent set for user vis action    1246   "WARNING: No extent set for user vis action \"" << name << "\"."
1554        << G4endl;                                1247        << G4endl;
1555     }                                            1248     }
1556   }                                              1249   }
1557   if (fVerbosity >= confirmations) {          << 
1558     G4cout                                    << 
1559     << "End of event user vis action \"" << n << 
1560     << G4endl;                                << 
1561   }                                           << 
1562 }                                                1250 }
1563                                                  1251 
1564 void G4VisManager::RegisterEndOfRunUserVisAct    1252 void G4VisManager::RegisterEndOfRunUserVisAction
1565 (const G4String& name,                           1253 (const G4String& name,
1566  G4VUserVisAction* pVisAction,                   1254  G4VUserVisAction* pVisAction,
1567  const G4VisExtent& extent) {                    1255  const G4VisExtent& extent) {
1568   fEndOfRunUserVisActions.push_back(UserVisAc    1256   fEndOfRunUserVisActions.push_back(UserVisAction(name,pVisAction));
1569   if (extent.GetExtentRadius() > 0.) {           1257   if (extent.GetExtentRadius() > 0.) {
1570     fUserVisActionExtents[pVisAction] = exten    1258     fUserVisActionExtents[pVisAction] = extent;
1571   } else {                                       1259   } else {
1572     if (fVerbosity >= warnings) {                1260     if (fVerbosity >= warnings) {
1573       G4warn <<                               << 1261       G4cout << 
1574   "WARNING: No extent set for user vis action    1262   "WARNING: No extent set for user vis action \"" << name << "\"."
1575        << G4endl;                                1263        << G4endl;
1576     }                                            1264     }
1577   }                                              1265   }
1578   if (fVerbosity >= confirmations) {          << 
1579     G4cout                                    << 
1580     << "End of run user vis action \"" << nam << 
1581     << G4endl;                                << 
1582   }                                           << 
1583 }                                                1266 }
1584                                                  1267 
1585 void G4VisManager::SetCurrentScene (G4Scene*     1268 void G4VisManager::SetCurrentScene (G4Scene* pScene) {
1586   if (pScene != fpScene) {                       1269   if (pScene != fpScene) {
1587     // A change of scene.  Therefore reset tr    1270     // A change of scene.  Therefore reset transients drawn flags.  All
1588     // memory of previous transient proceessi    1271     // memory of previous transient proceessing thereby erased...
1589     ResetTransientsDrawnFlags();                 1272     ResetTransientsDrawnFlags();
1590   }                                              1273   }
1591   fpScene = pScene;                              1274   fpScene = pScene;
1592 }                                                1275 }
1593                                                  1276 
1594 void G4VisManager::SetCurrentGraphicsSystem (    1277 void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
1595   fpGraphicsSystem = pSystem;                    1278   fpGraphicsSystem = pSystem;
1596   if (fVerbosity >= confirmations) {             1279   if (fVerbosity >= confirmations) {
1597     G4cout << "G4VisManager::SetCurrentGraphi    1280     G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
1598      << pSystem -> GetName () << G4endl;         1281      << pSystem -> GetName () << G4endl;
1599   }                                              1282   }
1600   // If current scene handler is of same grap    1283   // If current scene handler is of same graphics system, leave unchanged.
1601   // Else find the most recent scene handler     1284   // Else find the most recent scene handler of same graphics system.
1602   // Or clear pointers.                          1285   // Or clear pointers.
1603   if (!(fpSceneHandler && fpSceneHandler -> G    1286   if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
1604     const G4SceneHandlerList& sceneHandlerLis    1287     const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
1605     G4int nSH = (G4int)sceneHandlerList.size  << 1288     G4int nSH = sceneHandlerList.size ();  // No. of scene handlers.
1606     G4int iSH;                                   1289     G4int iSH;
1607     for (iSH = nSH - 1; iSH >= 0; iSH--) {       1290     for (iSH = nSH - 1; iSH >= 0; iSH--) {
1608       if (sceneHandlerList [iSH] -> GetGraphi    1291       if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
1609     }                                            1292     }
1610     if (iSH >= 0) {                              1293     if (iSH >= 0) {
1611       fpSceneHandler = sceneHandlerList [iSH]    1294       fpSceneHandler = sceneHandlerList [iSH];
1612       if (fVerbosity >= confirmations) {         1295       if (fVerbosity >= confirmations) {
1613   G4cout << "  Scene Handler now "               1296   G4cout << "  Scene Handler now "
1614          << fpSceneHandler -> GetName () << G    1297          << fpSceneHandler -> GetName () << G4endl;
1615       }                                          1298       }
1616       if (fpScene != fpSceneHandler -> GetSce    1299       if (fpScene != fpSceneHandler -> GetScene ()) {
1617   fpScene = fpSceneHandler -> GetScene ();       1300   fpScene = fpSceneHandler -> GetScene ();
1618   if (fVerbosity >= confirmations) {             1301   if (fVerbosity >= confirmations) {
1619     G4cout << "  Scene now \""                   1302     G4cout << "  Scene now \""
1620      << fpScene -> GetName () << "\"" << G4en    1303      << fpScene -> GetName () << "\"" << G4endl;
1621   }                                              1304   }
1622       }                                          1305       }
1623       const G4ViewerList& viewerList = fpScen    1306       const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1624       if (viewerList.size ()) {                  1307       if (viewerList.size ()) {
1625   fpViewer = viewerList [0];                     1308   fpViewer = viewerList [0];
1626   if (fVerbosity >= confirmations) {             1309   if (fVerbosity >= confirmations) {
1627     G4cout << "  Viewer now " << fpViewer ->     1310     G4cout << "  Viewer now " << fpViewer -> GetName () << G4endl;
1628   }                                              1311   }
1629       }                                          1312       }
1630       else {                                     1313       else {
1631   fpViewer = 0;                                  1314   fpViewer = 0;
1632       }                                          1315       }
1633     }                                            1316     }
1634     else {                                       1317     else {
1635       fpSceneHandler = 0;                        1318       fpSceneHandler = 0;
1636       fpViewer = 0;                              1319       fpViewer = 0;
1637     }                                            1320     }
1638   }                                              1321   }
1639 }                                                1322 }
1640                                                  1323 
1641 void G4VisManager::SetCurrentSceneHandler (G4    1324 void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
1642   fpSceneHandler = pSceneHandler;                1325   fpSceneHandler = pSceneHandler;
1643   if (fVerbosity >= confirmations) {             1326   if (fVerbosity >= confirmations) {
1644     G4cout << "G4VisManager::SetCurrentSceneH    1327     G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
1645      << pSceneHandler -> GetName () << "\"" <    1328      << pSceneHandler -> GetName () << "\"" << G4endl;
1646   }                                              1329   }
1647   if (fpScene != fpSceneHandler -> GetScene (    1330   if (fpScene != fpSceneHandler -> GetScene ()) {
1648     fpScene = fpSceneHandler -> GetScene ();     1331     fpScene = fpSceneHandler -> GetScene ();
1649     if (fVerbosity >= confirmations) {           1332     if (fVerbosity >= confirmations) {
1650       G4cout << "  Scene now \""                 1333       G4cout << "  Scene now \""
1651        << fpScene -> GetName () << "\"" << G4    1334        << fpScene -> GetName () << "\"" << G4endl;
1652     }                                            1335     }
1653   }                                              1336   }
1654   if (fpGraphicsSystem != pSceneHandler -> Ge    1337   if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
1655     fpGraphicsSystem = pSceneHandler -> GetGr    1338     fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
1656     if (fVerbosity >= confirmations) {           1339     if (fVerbosity >= confirmations) {
1657       G4cout << "  Graphics system now \""       1340       G4cout << "  Graphics system now \""
1658        << fpGraphicsSystem -> GetName () << "    1341        << fpGraphicsSystem -> GetName () << "\"" << G4endl;
1659     }                                            1342     }
1660   }                                              1343   }
1661   const G4ViewerList& viewerList = fpSceneHan    1344   const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
1662   std::size_t nViewers = viewerList.size ();  << 1345   G4int nViewers = viewerList.size ();
1663   if (nViewers) {                                1346   if (nViewers) {
1664     std::size_t iViewer;                      << 1347     G4int iViewer;
1665     for (iViewer = 0; iViewer < nViewers; ++i << 1348     for (iViewer = 0; iViewer < nViewers; iViewer++) {
1666       if (fpViewer == viewerList [iViewer]) b    1349       if (fpViewer == viewerList [iViewer]) break;
1667     }                                            1350     }
1668     if (iViewer >= nViewers) {                   1351     if (iViewer >= nViewers) {
1669       fpViewer = viewerList [0];                 1352       fpViewer = viewerList [0];
1670       if (fVerbosity >= confirmations) {         1353       if (fVerbosity >= confirmations) {
1671   G4cout << "  Viewer now \"" << fpViewer ->     1354   G4cout << "  Viewer now \"" << fpViewer -> GetName () << "\""
1672          << G4endl;                              1355          << G4endl;
1673       }                                          1356       }
1674     }                                            1357     }
1675     if (!IsValidView ()) {                       1358     if (!IsValidView ()) {
1676       if (fVerbosity >= warnings) {              1359       if (fVerbosity >= warnings) {
1677   G4warn <<                                   << 1360   G4cout <<
1678   "WARNING: Problem setting scene handler - p    1361   "WARNING: Problem setting scene handler - please report circumstances."
1679          << G4endl;                              1362          << G4endl;
1680       }                                          1363       }
1681     }                                            1364     }
1682   }                                              1365   }
1683   else {                                         1366   else {
1684     fpViewer = 0;                                1367     fpViewer = 0;
1685     if (fVerbosity >= warnings) {                1368     if (fVerbosity >= warnings) {
1686       G4warn <<                               << 1369       G4cout <<
1687   "WARNING: No viewers for this scene handler    1370   "WARNING: No viewers for this scene handler - please create one."
1688        << G4endl;                                1371        << G4endl;
1689     }                                            1372     }
1690   }                                              1373   }
1691 }                                                1374 }
1692                                                  1375 
1693 void G4VisManager::SetCurrentViewer (G4VViewe    1376 void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
1694   fpViewer  = pViewer;                           1377   fpViewer  = pViewer;
1695   if (fpViewer == nullptr) {                  << 
1696     if (fVerbosity >= confirmations) {        << 
1697       G4cout << "G4VisManager::SetCurrentView << 
1698       << G4endl;                              << 
1699     }                                         << 
1700     return;                                   << 
1701   }                                           << 
1702   if (fVerbosity >= confirmations) {             1378   if (fVerbosity >= confirmations) {
1703     G4cout << "G4VisManager::SetCurrentViewer    1379     G4cout << "G4VisManager::SetCurrentViewer: viewer now "
1704      << pViewer -> GetName ()                    1380      << pViewer -> GetName ()
1705      << G4endl;                                  1381      << G4endl;
1706   }                                              1382   }
1707   fpSceneHandler = fpViewer -> GetSceneHandle    1383   fpSceneHandler = fpViewer -> GetSceneHandler ();
1708   if (!fpSceneHandler) {                         1384   if (!fpSceneHandler) {
1709     if (fVerbosity >= warnings) {                1385     if (fVerbosity >= warnings) {
1710       G4warn <<                               << 1386       G4cout <<
1711       "WARNING: No scene handler for this vie    1387       "WARNING: No scene handler for this viewer - please create one."
1712       << G4endl;                                 1388       << G4endl;
1713     }                                            1389     }
1714     return;                                      1390     return;
1715   }                                              1391   }
1716   // JA: I don't think we need this. Setview  << 
1717   // fpViewer->SetView();                     << 
1718   fpSceneHandler -> SetCurrentViewer (pViewer    1392   fpSceneHandler -> SetCurrentViewer (pViewer);
1719   fpScene = fpSceneHandler -> GetScene ();       1393   fpScene = fpSceneHandler -> GetScene ();
1720   fpGraphicsSystem = fpSceneHandler -> GetGra    1394   fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
1721   if (!IsValidView ()) {                         1395   if (!IsValidView ()) {
1722     if (fVerbosity >= warnings) {                1396     if (fVerbosity >= warnings) {
1723       G4warn <<                               << 1397       G4cout <<
1724   "WARNING: Problem setting viewer - please r    1398   "WARNING: Problem setting viewer - please report circumstances."
1725        << G4endl;                                1399        << G4endl;
1726     }                                            1400     }
1727   }                                              1401   }
1728 }                                                1402 }
1729                                                  1403 
1730 void G4VisManager::PrintAvailableGraphicsSyst << 1404 namespace {
1731 (Verbosity verbosity, std::ostream& out) cons << 1405   struct NicknameComparison {
1732 {                                             << 1406     bool operator() (const G4String& lhs, const G4String& rhs) const
1733   out << "Registered graphics systems are:\n" << 1407     {return lhs.length()<rhs.length();}
1734   if (fAvailableGraphicsSystems.size ()) {    << 1408   };
1735     for (const auto& gs: fAvailableGraphicsSy << 1409 }
1736       const G4String& name = gs->GetName();   << 1410 
1737       const std::vector<G4String>& nicknames  << 1411 void G4VisManager::PrintAvailableGraphicsSystems () const {
1738       if (verbosity >= warnings) {            << 1412   G4int nSystems = fAvailableGraphicsSystems.size ();
1739         // Brief output                       << 1413   G4cout << "Current available graphics systems are:";
1740         out << "  " << name << " (";          << 1414   if (nSystems) {
1741         for (std::size_t i = 0; i < nicknames << 1415     // Make a map of graphics systems names (there may be repeated systems)
1742           if (i != 0) {                       << 1416     // and for each name a set of nicknames.  The nicknames are ordered
1743             out << ", ";                      << 1417     // by length - see struct NicknameComparison above.
1744           }                                   << 1418     std::map<G4String,std::set<G4String,NicknameComparison> > systemMap;
1745           out << nicknames[i];                << 1419     for (G4int i = 0; i < nSystems; i++) {
1746         }                                     << 1420       const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems[i];
1747         out << ')';                           << 1421       systemMap[pSystem->GetName()].insert(pSystem->GetNickname());
1748       } else {                                << 1422     }
1749         // Full output                        << 1423     // Print the map.
1750         out << *gs;                           << 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;
1751       }                                          1432       }
1752       out << std::endl;                       << 1433       G4cout << ')';
1753     }                                            1434     }
1754     out <<                                    << 
1755     "You may choose a graphics system (driver << 
1756     "\nthe command \"/vis/open\" or \"/vis/sc << 
1757     "\nor you may omit the driver parameter a << 
1758     "\n- by argument in the construction of G << 
1759     "\n- by environment variable \"G4VIS_DEFA << 
1760     "\n- by entry in \"~/.g4session\";"       << 
1761     "\n- by build flags."                     << 
1762     "\n- Note: This feature is not allowed in << 
1763     "\nFor further information see \"examples << 
1764     "\nand \"vis.mac\"."                      << 
1765     << std::endl;                             << 
1766   } else {                                    << 
1767     out << "  NONE!!!  None registered - yet! << 
1768   }                                              1435   }
                                                   >> 1436   else {
                                                   >> 1437     G4cout << "\n  NONE!!!  None registered - yet!  Mmmmm!";
                                                   >> 1438   }
                                                   >> 1439   G4cout << G4endl;
1769 }                                                1440 }
1770                                                  1441 
1771 void G4VisManager::PrintAvailableModels (Verb    1442 void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
1772 {                                                1443 {
1773   {                                              1444   {
1774     //fpTrajDrawModelMgr->Print(G4cout);         1445     //fpTrajDrawModelMgr->Print(G4cout);
1775     G4cout << "Registered model factories:" <    1446     G4cout << "Registered model factories:" << G4endl;
1776     const std::vector<G4VModelFactory<G4VTraj    1447     const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
1777       fpTrajDrawModelMgr->FactoryList();         1448       fpTrajDrawModelMgr->FactoryList();
1778     if (factoryList.empty()) G4cout << "  Non    1449     if (factoryList.empty()) G4cout << "  None" << G4endl;
1779     else {                                       1450     else {
1780       std::vector<G4VModelFactory<G4VTrajecto    1451       std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
1781       for (i = factoryList.begin(); i != fact << 1452       for (i = factoryList.begin(); i != factoryList.end(); ++i)
1782         (*i)->Print(G4cout);                  << 1453   (*i)->Print(G4cout);
1783       }                                       << 
1784     }                                            1454     }
1785     G4cout << "\nRegistered models:" << G4end << 
1786     const G4VisListManager<G4VTrajectoryModel    1455     const G4VisListManager<G4VTrajectoryModel>* listManager =
1787       fpTrajDrawModelMgr->ListManager();         1456       fpTrajDrawModelMgr->ListManager();
1788     const std::map<G4String, G4VTrajectoryMod    1457     const std::map<G4String, G4VTrajectoryModel*>& modelMap =
1789       listManager->Map();                        1458       listManager->Map();
1790     if (modelMap.empty()) G4cout << "  None"  << 1459     if (!modelMap.empty()) {
1791     else {                                    << 1460       G4cout << "\nRegistered models:" << G4endl;
1792       std::map<G4String, G4VTrajectoryModel*>    1461       std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
1793       for (i = modelMap.begin(); i != modelMa    1462       for (i = modelMap.begin(); i != modelMap.end(); ++i) {
1794   G4cout << "  " << i->second->Name();           1463   G4cout << "  " << i->second->Name();
1795   if (i->second == listManager->Current()) G4    1464   if (i->second == listManager->Current()) G4cout << " (Current)";
1796   G4cout << G4endl;                              1465   G4cout << G4endl;
1797   if (verbosity >= parameters) i->second->Pri    1466   if (verbosity >= parameters) i->second->Print(G4cout);
1798       }                                          1467       }
1799     }                                            1468     }
1800   }                                              1469   }
1801                                                  1470 
1802   G4cout << G4endl;                              1471   G4cout << G4endl;
1803                                                  1472 
1804   {                                              1473   {
1805     //fpTrajFilterMgr->Print(G4cout);            1474     //fpTrajFilterMgr->Print(G4cout);
1806     G4cout << "Registered filter factories:"     1475     G4cout << "Registered filter factories:" << G4endl;
1807     const std::vector<G4VModelFactory<G4VFilt    1476     const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
1808       factoryList = fpTrajFilterMgr->FactoryL    1477       factoryList = fpTrajFilterMgr->FactoryList();
1809     if (factoryList.empty()) G4cout << "  Non    1478     if (factoryList.empty()) G4cout << "  None" << G4endl;
1810     else {                                       1479     else {
1811       std::vector<G4VModelFactory<G4VFilter<G    1480       std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
1812       for (i = factoryList.begin(); i != fact << 1481       for (i = factoryList.begin(); i != factoryList.end(); ++i)
1813         (*i)->Print(G4cout);                  << 1482   (*i)->Print(G4cout);
1814       }                                       << 
1815     }                                            1483     }
1816                                               << 
1817     G4cout << "\nRegistered filters:" << G4en << 
1818     const std::vector<G4VFilter<G4VTrajectory    1484     const std::vector<G4VFilter<G4VTrajectory>*>&
1819       filterList = fpTrajFilterMgr->FilterLis    1485       filterList = fpTrajFilterMgr->FilterList();
1820     if (filterList.empty()) G4cout << "  None << 1486     if (!filterList.empty()) {
1821     else {                                    << 1487       G4cout << "\nRegistered filters:" << G4endl;
1822       std::vector<G4VFilter<G4VTrajectory>*>:    1488       std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
1823       for (i = filterList.begin(); i != filte    1489       for (i = filterList.begin(); i != filterList.end(); ++i) {
1824   G4cout << "  " << (*i)->GetName() << G4endl    1490   G4cout << "  " << (*i)->GetName() << G4endl;
1825   if (verbosity >= parameters) (*i)->PrintAll    1491   if (verbosity >= parameters) (*i)->PrintAll(G4cout);
1826       }                                          1492       }
1827     }                                            1493     }
1828   }                                              1494   }
1829 }                                                1495 }
1830                                                  1496 
1831 void G4VisManager::PrintAvailableUserVisActio    1497 void G4VisManager::PrintAvailableUserVisActions (Verbosity) const
1832 {                                                1498 {
1833   G4cout <<                                      1499   G4cout <<
1834     "You have successfully registered the fol    1500     "You have successfully registered the following user vis actions."
1835    << G4endl;                                    1501    << G4endl;
1836   G4cout << "Run Duration User Vis Actions:";    1502   G4cout << "Run Duration User Vis Actions:";
1837   if (fRunDurationUserVisActions.empty()) G4c    1503   if (fRunDurationUserVisActions.empty()) G4cout << " none" << G4endl;
1838   else {                                         1504   else {
1839     G4cout << G4endl;                            1505     G4cout << G4endl;
1840     for (std::size_t i = 0; i < fRunDurationU << 1506     for (size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
1841       const G4String& name = fRunDurationUser    1507       const G4String& name = fRunDurationUserVisActions[i].fName;
1842       G4cout << "  " << name << G4endl;          1508       G4cout << "  " << name << G4endl;
1843     }                                            1509     }
1844   }                                              1510   }
1845                                                  1511 
1846   G4cout << "End of Event User Vis Actions:";    1512   G4cout << "End of Event User Vis Actions:";
1847   if (fEndOfEventUserVisActions.empty()) G4co    1513   if (fEndOfEventUserVisActions.empty()) G4cout << " none" << G4endl;
1848   else {                                         1514   else {
1849     G4cout << G4endl;                            1515     G4cout << G4endl;
1850     for (std::size_t i = 0; i < fEndOfEventUs << 1516     for (size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
1851       const G4String& name = fEndOfEventUserV    1517       const G4String& name = fEndOfEventUserVisActions[i].fName;
1852       G4cout << "  " << name << G4endl;          1518       G4cout << "  " << name << G4endl;
1853     }                                            1519     }
1854   }                                              1520   }
1855                                                  1521 
1856   G4cout << "End of Run User Vis Actions:";      1522   G4cout << "End of Run User Vis Actions:";
1857   if (fEndOfRunUserVisActions.empty()) G4cout    1523   if (fEndOfRunUserVisActions.empty()) G4cout << " none" << G4endl;
1858   else {                                         1524   else {
1859     G4cout << G4endl;                            1525     G4cout << G4endl;
1860     for (std::size_t i = 0; i < fEndOfRunUser << 1526     for (size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
1861       const G4String& name = fEndOfRunUserVis    1527       const G4String& name = fEndOfRunUserVisActions[i].fName;
1862       G4cout << "  " << name << G4endl;          1528       G4cout << "  " << name << G4endl;
1863     }                                            1529     }
1864   }                                              1530   }
1865 }                                                1531 }
1866                                                  1532 
1867 void G4VisManager::PrintAvailableColours (Ver    1533 void G4VisManager::PrintAvailableColours (Verbosity) const {
1868   G4cout <<                                      1534   G4cout <<
1869   "Some /vis commands (optionally) take a str << 1535     "Some /vis commands (optionally) take a string to specify colour."
1870   "\nThey are also available in your C++ code << 1536     "\nAvailable colours:\n  ";
1871   "\n  G4Colour niceColour;  // Default - whi << 1537   const std::map<G4String, G4Colour>& map = G4Colour::GetMap();
1872   "\n  G4Colour::GetColour(\"pink\", niceColo << 1538   for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
1873   "\n  logical->SetVisAttributes(niceColour); << 1539        i != map.end();) {
1874   "\nSee G4Colour.hh."                        << 1540     G4cout << i->first;
1875   "\nAvailable colours";                      << 1541     if (++i != map.end()) G4cout << ", ";
1876   for (const auto& i: G4Colour::GetMap()) {   << 
1877     G4cout << ", " << i.first;                << 
1878   }                                              1542   }
1879   G4cout << G4endl;                              1543   G4cout << G4endl;
1880 }                                                1544 }
1881                                                  1545 
1882 void G4VisManager::PrintInvalidPointers () co    1546 void G4VisManager::PrintInvalidPointers () const {
1883   if (fVerbosity >= errors) {                    1547   if (fVerbosity >= errors) {
1884     G4warn << "ERROR: G4VisManager::PrintInva << 1548     G4cerr << "ERROR: G4VisManager::PrintInvalidPointers:";
1885     if (!fpGraphicsSystem) {                     1549     if (!fpGraphicsSystem) {
1886       G4warn << "\n null graphics system poin << 1550       G4cerr << "\n null graphics system pointer.";
1887     }                                            1551     }
1888     else {                                       1552     else {
1889       G4warn << "\n  Graphics system is " <<  << 1553       G4cerr << "\n  Graphics system is " << fpGraphicsSystem -> GetName ()
1890        << " but:";                               1554        << " but:";
1891       if (!fpScene)                              1555       if (!fpScene)
1892   G4warn <<                                   << 1556   G4cerr <<
1893     "\n  Null scene pointer. Use \"/vis/drawV    1557     "\n  Null scene pointer. Use \"/vis/drawVolume\" or"
1894     " \"/vis/scene/create\".";                   1558     " \"/vis/scene/create\".";
1895       if (!fpSceneHandler)                       1559       if (!fpSceneHandler)
1896   G4warn <<                                   << 1560   G4cerr <<
1897     "\n  Null scene handler pointer. Use \"/v    1561     "\n  Null scene handler pointer. Use \"/vis/open\" or"
1898     " \"/vis/sceneHandler/create\".";            1562     " \"/vis/sceneHandler/create\".";
1899       if (!fpViewer )                            1563       if (!fpViewer )
1900   G4warn <<                                   << 1564   G4cerr <<
1901     "\n  Null viewer pointer. Use \"/vis/view    1565     "\n  Null viewer pointer. Use \"/vis/viewer/create\".";
1902     }                                            1566     }
1903     G4warn << G4endl;                         << 1567     G4cerr << G4endl;
1904   }                                              1568   }
1905 }                                                1569 }
1906                                                  1570 
1907                                               << 
1908 G4ThreadFunReturnType G4VisManager::G4VisSubT << 
1909 {                                             << 
1910 #ifdef G4MULTITHREADED                           1571 #ifdef G4MULTITHREADED
1911   G4VisManager* pVisManager = (G4VisManager*) << 1572 // Start of multithreaded versions of Begin/EndOfRun/Event.
1912   G4VSceneHandler* pSceneHandler = pVisManage << 
1913   if (!pSceneHandler) return 0;               << 
1914   G4Scene* pScene = pSceneHandler->GetScene() << 
1915   if (!pScene) return 0;                      << 
1916   G4VViewer* pViewer = pVisManager->GetCurren << 
1917   if (!pViewer) return 0;                     << 
1918                                               << 
1919   G4UImanager::GetUIpointer()->SetUpForSpecia << 
1920                                               << 
1921   // Set up geometry and navigation for a thr << 
1922   G4GeometryWorkspace::GetPool()->CreateAndUs << 
1923   G4SolidsWorkspace::GetPool()->CreateAndUseW << 
1924   G4Navigator* navigator = G4TransportationMa << 
1925                              ->GetNavigatorFo << 
1926   navigator->SetWorldVolume(                  << 
1927     G4RunManagerFactory::GetMasterRunManagerK << 
1928                                               << 
1929   pViewer->SwitchToVisSubThread();            << 
1930                                               << 
1931   while (true) {                              << 
1932                                               << 
1933     G4MUTEXLOCK(&mtVisSubThreadMutex);        << 
1934     std::size_t eventQueueSize = mtVisEventQu << 
1935     G4MUTEXUNLOCK(&mtVisSubThreadMutex);      << 
1936     // G4cout << "Event queue size (A): " <<  << 
1937                                               << 
1938     while (eventQueueSize) {                  << 
1939                                               << 
1940       G4MUTEXLOCK(&mtVisSubThreadMutex);      << 
1941       const G4Event* event = mtVisEventQueue. << 
1942       G4MUTEXUNLOCK(&mtVisSubThreadMutex);    << 
1943                                               << 
1944       // Here comes the event drawing         << 
1945       pVisManager->SetTransientsDrawnThisEven << 
1946       pSceneHandler->SetTransientsDrawnThisEv << 
1947                                               << 
1948       // We are about to draw the event (traj << 
1949       // have to clear the previous event(s)  << 
1950       // needs to be drawn afresh, e.g., the  << 
1951       // "accumulate" is not requested, the o << 
1952       // We have postponed this so that, for  << 
1953       // previous event(s) stay on screen unt << 
1954       // along.  For a file-writing viewer th << 
1955       // See, for example, G4HepRepFileSceneH << 
1956       pVisManager->ClearTransientStoreIfMarke << 
1957                                               << 
1958       // Now draw the event...                << 
1959       pSceneHandler->DrawEvent(event);        << 
1960       ++pVisManager->fNoOfEventsDrawnThisRun; << 
1961                                               << 
1962       // Then pop and release event           << 
1963       G4MUTEXLOCK(&mtVisSubThreadMutex);      << 
1964       mtVisEventQueue.pop_front();            << 
1965       pVisManager->EndOfEventCleanup(event);  << 
1966       eventQueueSize = mtVisEventQueue.size() << 
1967       G4MUTEXUNLOCK(&mtVisSubThreadMutex);    << 
1968     }                                         << 
1969                                               << 
1970     G4MUTEXLOCK(&mtVisSubThreadMutex);        << 
1971     G4bool runInProgress = mtRunInProgress;   << 
1972     G4MUTEXUNLOCK(&mtVisSubThreadMutex);      << 
1973     if (!runInProgress) {                     << 
1974       // EndOfRun on master thread has signal << 
1975       // nothing to draw so...                << 
1976       break;                                  << 
1977     }                                         << 
1978                                                  1573 
1979     // Run still in progress but nothing to d << 1574 #include "G4Threading.hh"
1980     std::this_thread::sleep_for(std::chrono:: << 1575 #include "G4AutoLock.hh"
1981   }                                           << 1576 namespace {
1982                                               << 1577 //  G4Mutex visBeginOfRunMutex = G4MUTEX_INITIALIZER;
1983   // Inform viewer that we have finished all  << 1578 //  G4Mutex visBeginOfEventMutex = G4MUTEX_INITIALIZER;
1984   pViewer->DoneWithVisSubThread();            << 1579   G4Mutex visEndOfEventMutex = G4MUTEX_INITIALIZER;
1985   pViewer->MovingToMasterThread();            << 1580 //  G4Mutex visEndOfRunMutex = G4MUTEX_INITIALIZER;
1986 #else                                         << 
1987   G4ConsumeParameters(p);                     << 
1988 #endif                                        << 
1989   return nullptr;                             << 
1990 }                                                1581 }
1991                                                  1582 
1992 void G4VisManager::BeginOfRun ()                 1583 void G4VisManager::BeginOfRun ()
1993 {                                                1584 {
1994   if (fIgnoreStateChanges) return;               1585   if (fIgnoreStateChanges) return;
1995   if (G4Threading::IsWorkerThread()) return;     1586   if (G4Threading::IsWorkerThread()) return;
1996   if (!GetConcreteInstance()) return;         << 1587   fNKeepRequests = 0;
1997                                               << 1588   fKeptLastEvent = false;
1998   // Check if view is valid                   << 
1999   // Protect IsValidView() with fpSceneHandle << 
2000   isValidViewForRun = fpSceneHandler && IsVal << 
2001   if (!isValidViewForRun) return;             << 
2002                                               << 
2003   // For a fake run...                        << 
2004   G4RunManager* runManager = G4RunManagerFact << 
2005   G4int nEventsToBeProcessed = runManager->Ge << 
2006   isFakeRun = (nEventsToBeProcessed == 0);    << 
2007   if (isFakeRun) return;                      << 
2008                                               << 
2009   // Is the run manager a sub-event type?     << 
2010   G4RunManager::RMType rmType = runManager->G << 
2011   isSubEventRunManagerType =                  << 
2012   (rmType == G4RunManager::subEventMasterRM)  << 
2013   (rmType == G4RunManager::subEventWorkerRM); << 
2014                                               << 
2015   fNKeepForPostProcessingRequests = 0;        << 
2016   fNKeepTheEventRequests = 0;                 << 
2017   fEventKeepingSuspended = false;                1589   fEventKeepingSuspended = false;
2018   fTransientsDrawnThisRun = false;               1590   fTransientsDrawnThisRun = false;
2019   if (fpSceneHandler) fpSceneHandler->SetTran    1591   if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
2020   fNoOfEventsDrawnThisRun = 0;                << 
2021                                               << 
2022   // Check to see if the user has created a t << 
2023   // a default one. To avoid code duplication << 
2024   // and its result (a const G4VTrajectoryMod << 
2025   // The function is called again later when  << 
2026   CurrentTrajDrawModel();                     << 
2027                                               << 
2028   // Actions only in MT mode                  << 
2029   if (G4Threading::IsMultithreadedApplication << 
2030                                               << 
2031     // Inform viewer that we have finished al << 
2032     if (fpViewer) fpViewer->DoneWithMasterThr << 
2033                                               << 
2034     // Start vis sub-thread                   << 
2035     G4MUTEXLOCK(&mtVisSubThreadMutex);        << 
2036     mtRunInProgress = true;                   << 
2037     G4MUTEXUNLOCK(&mtVisSubThreadMutex);      << 
2038     mtVisSubThread = new G4Thread;            << 
2039     // Launch vis thread                      << 
2040     G4THREADCREATE(mtVisSubThread,G4VisSubThr << 
2041                                               << 
2042     // Tricky things for some viewers (e.g.,  << 
2043     // - Launch the vis thread                << 
2044     // - Wait for the vis thread to set its Q << 
2045     // - Then move current QOpenGL context (i << 
2046     // - Go ahead                             << 
2047     if (fpViewer) fpViewer->MovingToVisSubThr << 
2048   }                                           << 
2049 }                                                1592 }
2050                                                  1593 
2051 void G4VisManager::BeginOfEvent ()               1594 void G4VisManager::BeginOfEvent ()
2052 {                                                1595 {
2053   if (fIgnoreStateChanges) return;               1596   if (fIgnoreStateChanges) return;
2054   if (!GetConcreteInstance()) return;         << 
2055   if (!isValidViewForRun) return;             << 
2056   if (isFakeRun) return;                      << 
2057                                               << 
2058   // Some instructions that should NOT be in  << 
2059   // TODO: protect with G4Threading::IsMultit << 
2060 #ifndef G4MULTITHREADED                       << 
2061   // These instructions are in G4VisSubThread << 
2062   fTransientsDrawnThisEvent = false;          << 
2063   if (fpSceneHandler) fpSceneHandler->SetTran << 
2064 #endif                                        << 
2065 }                                                1597 }
2066                                                  1598 
2067 // Here begins a sequence of functions that d << 
2068 // Sequential/Serial mode:                    << 
2069 //   EndOfEvent is invoked by a state change  << 
2070 //     EndOfEvent pulls the event from the Ev << 
2071 //     EndOfEventKernel draws the event and c << 
2072 //     (Unless the user him/herself has reque << 
2073 //      also sets KeepTheEvent for a certain  << 
2074 //      of events. The run manager keeps thes << 
2075 //      run, so, for example, the vis manager << 
2076 // Multithreading/Tasking:                    << 
2077 //   EndOfEvent is invoked by a state change  << 
2078 //     EndOfEvent pulls the event from the (w << 
2079 //     EndOfEventKernel pushes it to the vis  << 
2080 //       are marked KeepForPostProcessing so  << 
2081 //       PostProcessingFinished in EndOfEvent << 
2082 //     EndOfEventKernel also sets KeepTheEven << 
2083 //     The vis sub thread pulls events from t << 
2084 //       calls EndOfEventCleanup, which calls << 
2085 // Sub-event parallelism:                     << 
2086 //   EndOfEvent is invoked by a state change  << 
2087 //     multithreading, but actually, the even << 
2088 //     employed on sub-events, so we ignore s << 
2089 //     G4SubEvtRunManager knows when the even << 
2090 //   Events are pushed to the Vis Manager by  << 
2091 //      when the event is ready. EventReadyFo << 
2092 //      processsing continues as for Multithr << 
2093                                               << 
2094 void G4VisManager::EndOfEvent ()                 1599 void G4VisManager::EndOfEvent ()
2095 {                                                1600 {
2096   if (fIgnoreStateChanges) return;               1601   if (fIgnoreStateChanges) return;
                                                   >> 1602 
2097   if (!GetConcreteInstance()) return;            1603   if (!GetConcreteInstance()) return;
2098   if (!isValidViewForRun) return;             << 
2099   if (isFakeRun) return;                      << 
2100                                                  1604 
2101   // For sub-event parallelism, this is not t << 1605   // Don't call IsValidView unless there is a scene handler.  This
2102   if (isSubEventRunManagerType) return;       << 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;
2103                                                  1610 
2104   G4AutoLock al(&visEndOfEventMutex);            1611   G4AutoLock al(&visEndOfEventMutex);
2105                                                  1612 
2106   G4RunManager* runManager = G4RunManagerFact << 1613   if (!fEventKeepingSuspended) {
2107                                               << 
2108   const G4Run* currentRun = runManager->GetCu << 
2109   if (!currentRun) return;                    << 
2110                                                  1614 
2111   // This gets the appropriate event manager  << 1615     G4EventManager* eventManager = G4EventManager::GetEventManager();
2112   G4EventManager* eventManager = G4EventManag << 1616 //    const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
2113   const G4Event* currentEvent = eventManager- << 1617 //    if (!currentEvent) return;
2114   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;
2115                                                  1626 
2116   // Call kernel                              << 1627     G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
2117   EndOfEventKernel(currentEvent);             << 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   }
2118 }                                                1648 }
2119                                                  1649 
2120 void G4VisManager::EventReadyForVis(const G4E << 1650 void G4VisManager::EndOfRun ()
2121 // This is invoked by G4SubEvtRunManager.     << 
2122 // The event is passed to EndOfEventKernel.   << 
2123 {                                                1651 {
2124   if (fIgnoreStateChanges) return;               1652   if (fIgnoreStateChanges) return;
2125   if (!GetConcreteInstance()) return;         << 
2126   if (!isValidViewForRun) return;             << 
2127   if (isFakeRun) return;                      << 
2128                                                  1653 
2129   G4AutoLock al(&visEndOfEventMutex);         << 1654   if (G4Threading::IsWorkerThread()) return;
2130   EndOfEventKernel(event);                    << 
2131 }                                             << 
2132                                               << 
2133 void G4VisManager::EndOfEventKernel (const G4 << 
2134 {                                             << 
2135   // Note: we are still subject to the mutex  << 
2136                                               << 
2137   // Discard event if fDrawEventOnlyIfToBeKep << 
2138   // user has requested the event to be kept. << 
2139   if (fDrawEventOnlyIfToBeKept) {             << 
2140     if (!currentEvent->KeepTheEventFlag()) re << 
2141   }                                           << 
2142                                               << 
2143   if (G4Threading::IsMultithreadedApplication << 
2144                                               << 
2145     // Wait if too many events in the queue.  << 
2146     G4MUTEXLOCK(&mtVisSubThreadMutex);        << 
2147     std::size_t eventQueueSize = mtVisEventQu << 
2148     G4MUTEXUNLOCK(&mtVisSubThreadMutex);      << 
2149                                               << 
2150     G4bool eventQueueFull = false;            << 
2151     while (fMaxEventQueueSize > 0 && (G4int)e << 
2152                                               << 
2153       if (fWaitOnEventQueueFull) {            << 
2154                                               << 
2155         static G4bool warned = false;         << 
2156         if (!warned) {                        << 
2157           G4warn <<                           << 
2158           "WARNING: The number of events in t << 
2159           "\n  the maximum, "                 << 
2160           << fMaxEventQueueSize <<            << 
2161           ".\n  If, during a multithreaded ru << 
2162           "\n  visualisation by more than thi << 
2163           "\n  until the vis sub-thread has d << 
2164           "\n  from the queue.  You may chang << 
2165           "\n  \"/vis/multithreading/maxEvent << 
2166           "\n  number you wish to allow.  N < << 
2167           "\n  Alternatively you may choose t << 
2168           "\n  \"/vis/multithreading/actionOn << 
2169           "\n  To avoid visualisation altoget << 
2170           "\n  And maybe \"/tracking/storeTra << 
2171           << G4endl;                          << 
2172           warned = true;                      << 
2173         }                                     << 
2174                                                  1655 
2175         // Wait a while to give event drawing << 1656   // Don't call IsValidView unless there is a scene handler.  This
2176         std::this_thread::sleep_for(std::chro << 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;
2177                                                  1661 
2178       } else {                                << 1662   //  G4AutoLock al(&visEndOfRunMutex);
                                                   >> 1663   
                                                   >> 1664   G4RunManager* runManager = G4RunManager::GetRunManager();
                                                   >> 1665   const G4Run* currentRun = runManager->GetCurrentRun();
                                                   >> 1666   if (!currentRun) return;
2179                                                  1667 
2180         static G4bool warned = false;         << 1668   const std::vector<const G4Event*>*
2181         if (!warned) {                        << 1669   eventsFromThreads = currentRun->GetEventVector();
2182           G4warn <<                           << 1670   G4int nKeptEvents = eventsFromThreads ? eventsFromThreads->size() : 0;
2183           "WARNING: The number of events in t << 1671   if (nKeptEvents) {
2184           "\n  the maximum, "                 << 1672     if (fVerbosity >= warnings) {
2185           << fMaxEventQueueSize <<            << 1673       G4cout << "WARNING: " << nKeptEvents;
2186           ".\n  Some events have been discard << 1674       if (nKeptEvents == 1) G4cout << " event has";
2187           "\n  behaviour with \"/vis/multithr << 1675       else G4cout << " events have";
2188           "\n  To avoid visualisation altoget << 1676       G4cout << " been kept for refreshing and/or reviewing." << G4endl;
2189           "\n  And maybe \"/tracking/storeTra << 1677       if (nKeptEvents != fNKeepRequests) {
2190           << G4endl;                          << 1678         G4cout << "  (Note: ";
2191           warned = true;                      << 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";
2192         }                                        1685         }
2193                                               << 1686         G4cout << " made by the vis manager.)" << G4endl;
2194         eventQueueFull = true;  // Causes eve << 
2195         break;                                << 
2196       }                                          1687       }
2197                                               << 1688       G4cout << "  \"/vis/reviewKeptEvents\" to review them." << G4endl;
2198       G4MUTEXLOCK(&mtVisSubThreadMutex);      << 
2199       eventQueueSize = mtVisEventQueue.size() << 
2200       G4MUTEXUNLOCK(&mtVisSubThreadMutex);    << 
2201     }                                            1689     }
                                                   >> 1690   }
2202                                                  1691 
2203     if (!eventQueueFull) {                    << 1692   if (fEventKeepingSuspended && fVerbosity >= warnings) {
2204                                               << 1693     G4cout <<
2205       if (RequiredToBeKeptForVis(currentEvent << 1694     "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
2206         currentEvent->KeepTheEvent();         << 1695     "\n  The number of events in the run exceeded the maximum, "
2207         fNKeepTheEventRequests++;  // Counts  << 1696     << fpScene->GetMaxNumberOfKeptEvents() <<
2208       }                                       << 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   }
2209                                                  1703 
2210       G4MUTEXLOCK(&mtVisSubThreadMutex);      << 1704   if (GetConcreteInstance() && eventsFromThreads) {
                                                   >> 1705     std::vector<const G4Event*>::const_iterator i;
                                                   >> 1706     if (fpScene->GetRefreshAtEndOfEvent()) {
                                                   >> 1707 
                                                   >> 1708       for (i = eventsFromThreads->begin(); i != eventsFromThreads->end(); ++i) {
                                                   >> 1709         if (fVerbosity >= confirmations) {
                                                   >> 1710           G4cout << "Drawing event " << (*i)->GetEventID() << G4endl;
                                                   >> 1711         }
2211                                                  1712 
2212       // Keep while post processing (i.e., dr << 1713         // We are about to draw the event (trajectories, etc.), but first we
2213       // Make sure the event is not deleted b << 1714         // have to clear the previous event(s) if necessary.  If this event
2214       currentEvent->KeepForPostProcessing();  << 1715         // needs to be drawn afresh, e.g., the first event or any event when
2215       fNKeepForPostProcessingRequests++;      << 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         }
                                                   >> 1736         ClearTransientStoreIfMarked();
                                                   >> 1737         // ...and restore...
                                                   >> 1738         eoeModels = tmpEoeModels;
                                                   >> 1739         eorModels = tmpEorModels;
                                                   >> 1740 
                                                   >> 1741         fTransientsDrawnThisEvent = false;
                                                   >> 1742         fpSceneHandler->SetTransientsDrawnThisEvent(false);
                                                   >> 1743         fpSceneHandler->DrawEvent(*i);
                                                   >> 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();
                                                   >> 1750         fpSceneHandler->SetMarkForClearingTransientStore(true);
                                                   >> 1751       }
2216                                                  1752 
2217       // Put event on vis queue               << 1753     } else {  // Accumulate events.
2218       mtVisEventQueue.push_back(currentEvent) << 
2219                                                  1754 
2220       G4MUTEXUNLOCK(&mtVisSubThreadMutex);    << 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       }
                                                   >> 1779       ClearTransientStoreIfMarked();
                                                   >> 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;
                                                   >> 1789         fpSceneHandler->SetTransientsDrawnThisEvent(false);
                                                   >> 1790         fpSceneHandler->DrawEvent(*i);
                                                   >> 1791       }
                                                   >> 1792       if (fpScene->GetRefreshAtEndOfRun()) {
                                                   >> 1793         fpSceneHandler->DrawEndOfRunModels();
                                                   >> 1794         fpViewer->ShowView();
                                                   >> 1795         // An extra refresh for auto-refresh viewers
                                                   >> 1796         if (fpViewer->GetViewParameters().IsAutoRefresh()) {
                                                   >> 1797           fpViewer->RefreshView();
                                                   >> 1798         }
                                                   >> 1799         fpSceneHandler->SetMarkForClearingTransientStore(true);
                                                   >> 1800       } else {
                                                   >> 1801         if (fpGraphicsSystem->GetFunctionality() ==
                                                   >> 1802             G4VGraphicsSystem::fileWriter) {
                                                   >> 1803           if (fVerbosity >= warnings) {
                                                   >> 1804             G4cout << "\"/vis/viewer/update\" to close file." << G4endl;
                                                   >> 1805           }
                                                   >> 1806         }
                                                   >> 1807       }
2221     }                                            1808     }
                                                   >> 1809   }
                                                   >> 1810   fEventRefreshing = false;
                                                   >> 1811 }
2222                                                  1812 
2223   } else {                                    << 1813 // End of multithreaded versions of Begin/EndOfRun/Event.
2224                                               << 1814 #else
2225     // Sequential mode                        << 1815 // Start of sequential versions of Begin/EndOfRun/Event.
2226                                               << 
2227     // We are about to draw the event (trajec << 
2228     // have to clear the previous event(s) if << 
2229     // needs to be drawn afresh, e.g., the fi << 
2230     // "accumulate" is not requested, the old << 
2231     // We have postponed this so that, for no << 
2232     // previous event(s) stay on screen until << 
2233     // along.  For a file-writing viewer the  << 
2234     // See, for example, G4HepRepFileSceneHan << 
2235     ClearTransientStoreIfMarked();            << 
2236                                               << 
2237     // Keep while post processing (i.e., draw << 
2238     currentEvent->KeepForPostProcessing();    << 
2239     fNKeepForPostProcessingRequests++;        << 
2240                                               << 
2241     if (RequiredToBeKeptForVis(currentEvent-> << 
2242       currentEvent->KeepTheEvent();           << 
2243       fNKeepTheEventRequests++;  // Counts nu << 
2244     }                                         << 
2245                                                  1816 
2246     // Now draw the event...                  << 1817 void G4VisManager::BeginOfRun ()
2247     fpSceneHandler->DrawEvent(currentEvent);  << 1818 {
2248     ++fNoOfEventsDrawnThisRun;                << 1819   if (fIgnoreStateChanges) return;
                                                   >> 1820   //G4cout << "G4VisManager::BeginOfRun" << G4endl;
                                                   >> 1821   fNKeepRequests = 0;
                                                   >> 1822   fKeptLastEvent = false;
                                                   >> 1823   fEventKeepingSuspended = false;
                                                   >> 1824   fTransientsDrawnThisRun = false;
                                                   >> 1825   if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
                                                   >> 1826 }
2249                                                  1827 
2250     EndOfEventCleanup(currentEvent);          << 1828 void G4VisManager::BeginOfEvent ()
2251   }                                           << 1829 {
                                                   >> 1830   if (fIgnoreStateChanges) return;
                                                   >> 1831   //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
                                                   >> 1832   fTransientsDrawnThisEvent = false;
                                                   >> 1833   if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
2252 }                                                1834 }
2253                                                  1835 
2254 void G4VisManager::EndOfEventCleanup(const G4 << 1836 void G4VisManager::EndOfEvent ()
2255 {                                                1837 {
2256   if (fpScene->GetRefreshAtEndOfEvent()) {    << 1838   if (fIgnoreStateChanges) return;
2257                                                  1839 
2258     fpSceneHandler->SetMarkForClearingTransie << 1840   if (!GetConcreteInstance()) return;
2259                                                  1841 
2260     // ShowView guarantees the view is flushe << 1842   // Don't call IsValidView unless there is a scene handler.  This
2261     // triggers other features such as pickin << 1843   // avoids WARNING message at end of event and run when the user has
2262     // file-writing viewers to close the file << 1844   // not instantiated a scene handler, e.g., in batch mode.
2263     fpViewer->ShowView();                     << 1845   G4bool valid = fpSceneHandler && IsValidView();
2264   }                                           << 1846   if (!valid) return;
2265                                                  1847 
2266   currentEvent->PostProcessingFinished();     << 1848   G4EventManager* eventManager = G4EventManager::GetEventManager();
                                                   >> 1849   const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
                                                   >> 1850   if (!currentEvent) return;
                                                   >> 1851 
                                                   >> 1852   //G4cout << "G4VisManager::EndOfEvent" << G4endl;
                                                   >> 1853 
                                                   >> 1854   DrawEvent(currentEvent);
2267 }                                                1855 }
2268                                                  1856 
2269 G4bool G4VisManager::RequiredToBeKeptForVis ( << 1857 void G4VisManager::EndOfRun ()
2270 // i.e., kept by the run manager at least to  << 
2271 {                                                1858 {
2272   G4bool requiredToBeKept = false;            << 1859   if (fIgnoreStateChanges) return;
                                                   >> 1860   //G4cout << "G4VisManager::EndOfRun" << G4endl;
2273                                                  1861 
2274   G4RunManager* runManager = G4RunManagerFact << 1862   G4RunManager* runManager = G4RunManager::GetRunManager();
2275   G4int nEventsToBeProcessed = runManager->Ge << 1863   const G4Run* currentRun = runManager->GetCurrentRun();
2276                                                  1864 
2277   if (fpScene->GetRefreshAtEndOfEvent()) {  / << 1865   G4int nKeptEvents = 0;
                                                   >> 1866   const std::vector<const G4Event*>* events =
                                                   >> 1867   currentRun? currentRun->GetEventVector(): 0;
                                                   >> 1868   if (events) nKeptEvents = events->size();
2278                                                  1869 
2279     // Keep last event only                   << 1870   if (nKeptEvents && !fKeptLastEvent) {
2280     if (eventID == nEventsToBeProcessed - 1)  << 1871     if (fVerbosity >= warnings) {
2281       requiredToBeKept = true;                << 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;
2282     }                                            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   }
2283                                                  1905 
2284   } else {  //  Accumulating events           << 1906   if (fEventKeepingSuspended && fVerbosity >= warnings) {
2285                                               << 1907     G4cout <<
2286     G4int maxNumberOfKeptEvents = fpScene->Ge << 1908     "WARNING: G4VisManager::EndOfRun: Automatic event keeping was suspended."
2287                                               << 1909     "\n  The number of events in the run exceeded the maximum, "
2288     if (maxNumberOfKeptEvents >= 0) {  // Eve << 1910     << fpScene->GetMaxNumberOfKeptEvents() <<
2289                                               << 1911     ", that may be\n  kept by the vis manager." <<
2290       if (fNKeepTheEventRequests < maxNumberO << 1912     "\n  The number of events kept by the vis manager can be changed with"
2291                                               << 1913     "\n  \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
2292         // Not yet reached the limit          << 1914     "\n  maximum number you wish to allow.  N < 0 means \"unlimited\"."
2293         requiredToBeKept = true;              << 1915     << G4endl;
                                                   >> 1916   }
2294                                                  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) {
                                                   >> 1923     if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
                                                   >> 1924       if (fpScene->GetRefreshAtEndOfRun()) {
                                                   >> 1925   fpSceneHandler->DrawEndOfRunModels();
                                                   >> 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.
                                                   >> 1933         if (fpViewer->GetViewParameters().IsAutoRefresh()) {
                                                   >> 1934           fpViewer->RefreshView();
                                                   >> 1935         }
                                                   >> 1936   fpSceneHandler->SetMarkForClearingTransientStore(true);
2295       } else {                                   1937       } else {
2296                                               << 1938         if (fpGraphicsSystem->GetFunctionality() ==
2297         // We have already reached the limit  << 1939             G4VGraphicsSystem::fileWriter) {
2298         fEventKeepingSuspended = true;        << 
2299         static G4bool warned = false;         << 
2300         if (!warned) {                        << 
2301           if (fVerbosity >= warnings) {          1940           if (fVerbosity >= warnings) {
2302             G4warn <<                         << 1941             G4cout << "\"/vis/viewer/update\" to close file." << G4endl;
2303             "WARNING: G4VisManager::EndOfEven << 
2304             << G4endl;                        << 
2305             if (maxNumberOfKeptEvents > 0) {  << 
2306               G4warn <<                       << 
2307               "\n  The number of events excee << 
2308               << maxNumberOfKeptEvents <<     << 
2309               ", that may be kept by\n  the v << 
2310               << G4endl;                      << 
2311             }                                 << 
2312           }                                      1942           }
2313           warned = true;                      << 
2314         }                                        1943         }
2315       }                                          1944       }
2316                                               << 
2317     } else {  // Indefinite event keeping (ma << 
2318                                               << 
2319       requiredToBeKept = true;                << 
2320                                               << 
2321     }                                            1945     }
2322   }                                              1946   }
2323                                               << 1947   fEventRefreshing = false;
2324   return requiredToBeKept;                    << 
2325 }                                                1948 }
2326                                                  1949 
2327 void G4VisManager::EndOfRun ()                << 1950 void G4VisManager::DrawEvent(const G4Event* event)
2328 {                                                1951 {
2329   if (fIgnoreStateChanges) return;            << 1952   G4EventManager* eventManager = G4EventManager::GetEventManager();
2330   if (G4Threading::IsWorkerThread()) return;  << 1953   
2331   if (!GetConcreteInstance()) return;         << 1954   G4RunManager* runManager = G4RunManager::GetRunManager();
2332   if (!isValidViewForRun) return;             << 
2333   if (isFakeRun) return;                      << 
2334                                               << 
2335   G4RunManager* runManager = G4RunManagerFact << 
2336                                               << 
2337   // For a fake run...                        << 
2338   G4int nEventsToBeProcessed = runManager->Ge << 
2339   if (nEventsToBeProcessed == 0) return;      << 
2340                                               << 
2341   const G4Run* currentRun = runManager->GetCu    1955   const G4Run* currentRun = runManager->GetCurrentRun();
2342   if (!currentRun) return;                       1956   if (!currentRun) return;
2343                                                  1957 
2344   //  G4AutoLock al(&visEndOfRunMutex);  ???  << 1958   // We are about to draw the event (trajectories, etc.), but first we
2345   if (G4Threading::IsMultithreadedApplication << 1959   // have to clear the previous event(s) if necessary.  If this event
2346     // Reset flag so that sub-thread exits wh << 1960   // needs to be drawn afresh, e.g., the first event or any event when
2347     G4MUTEXLOCK(&mtVisSubThreadMutex);        << 1961   // "accumulate" is not requested, the old event has to be cleared.
2348     mtRunInProgress = false;                  << 1962   // We have postponed this so that, for normal viewers like OGL, the
2349     G4MUTEXUNLOCK(&mtVisSubThreadMutex);      << 1963   // previous event(s) stay on screen until this new event comes
2350     // Wait for sub-thread to finish.         << 1964   // along.  For a file-writing viewer the geometry has to be drawn.
2351     G4THREADJOIN(*mtVisSubThread);            << 1965   // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
2352     delete mtVisSubThread;                    << 1966   ClearTransientStoreIfMarked();
2353     fpViewer->SwitchToMasterThread();         << 1967 
2354   }                                           << 1968   // Now draw the event...
2355                                               << 1969   fpSceneHandler->DrawEvent(event);
2356   if (G4Threading::IsMultithreadedApplication << 1970 
2357     G4int noOfEventsRequested = runManager->G << 1971   G4int nEventsToBeProcessed = 0;
2358     if (fNoOfEventsDrawnThisRun != noOfEvents << 1972   G4int nKeptEvents = 0;
2359       if (!fWaitOnEventQueueFull && fVerbosit << 1973   G4int eventID = -2;  // (If no run manager, triggers ShowView as normal.)
2360         G4warn                                << 1974   if (currentRun) {
2361         << "WARNING: Number of events drawn t << 1975     nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
2362         << fNoOfEventsDrawnThisRun << ", is d << 1976     eventID = event->GetEventID();
2363         << noOfEventsRequested <<             << 1977     const std::vector<const G4Event*>* events =
2364         ".\n  (This is because you requested  << 1978     currentRun->GetEventVector();
2365         << G4endl;                            << 1979     if (events) nKeptEvents = events->size();
2366       }                                       << 
2367     }                                         << 
2368   }                                           << 
2369                                               << 
2370   G4int nKeptEvents = currentRun->GetNumberOf << 
2371   if (fVerbosity >= warnings && nKeptEvents > << 
2372     G4warn << nKeptEvents;                    << 
2373     if (nKeptEvents == 1) G4warn << " event h << 
2374     else G4warn << " events have";            << 
2375     G4warn << " been kept for refreshing and/ << 
2376     if (nKeptEvents != fNKeepTheEventRequests << 
2377       if (fNKeepTheEventRequests == 0) {      << 
2378         G4warn << "No keep requests were";    << 
2379       } else if (fNKeepTheEventRequests == 1) << 
2380         G4warn << "1 keep request was";       << 
2381       } else {                                << 
2382         G4warn << fNKeepTheEventRequests << " << 
2383       }                                       << 
2384       G4warn << " made by the vis manager.";  << 
2385       if (fNKeepTheEventRequests == 0) {      << 
2386         G4warn <<                             << 
2387         "\n  The kept events are those you ha << 
2388       } else {                                << 
2389         G4warn <<                             << 
2390         "\n  The same or further events may h << 
2391         "\n  To turn off event keeping by the << 
2392         "\n  or use /vis/scene/endOfEventActi << 
2393       }                                       << 
2394       G4warn << G4endl;                       << 
2395     }                                         << 
2396     G4warn <<                                 << 
2397   "  \"/vis/reviewKeptEvents\" to review one  << 
2398   "\n  To see accumulated, \"/vis/enable\", t << 
2399     << G4endl;                                << 
2400   }                                              1980   }
2401                                                  1981 
2402   if (fVerbosity >= warnings) PrintListOfPlot << 1982   if (fpScene->GetRefreshAtEndOfEvent()) {
2403                                                  1983 
2404   if (fEventKeepingSuspended && fVerbosity >= << 1984     // Unless last event (in which case wait end of run)...
2405     G4warn <<                                 << 1985     if (eventID < nEventsToBeProcessed - 1) {
2406     "WARNING: G4VisManager::EndOfRun: Automat << 1986       // ShowView guarantees the view comes to the screen.  No action
2407     << G4endl;                                << 1987       // is taken for passive viewers like OGL*X (without picking enabled),
2408     if (fpScene->GetMaxNumberOfKeptEvents() > << 1988       // but it passes control to interactive viewers, such as OGL*X (with
2409       G4warn <<                               << 1989       // picking enabled) or OGL*Xm, and allows file-writing viewers to
2410       "  The number of events in the run exce << 1990       // close the file.
2411       << fpScene->GetMaxNumberOfKeptEvents()  << 1991       fpViewer->ShowView();
2412       ", that may be\n  kept by the vis manag << 1992       fpSceneHandler->SetMarkForClearingTransientStore(true);
2413       "\n  The number of events kept by the v << 1993     } else {  // Last event...
2414       "\n  \"/vis/scene/endOfEventAction accu << 1994               // Keep, but only if user has not kept any...
2415       "\n  maximum number you wish to allow.  << 1995       if (!nKeptEvents) {
2416       << G4endl;                              << 1996         eventManager->KeepTheCurrentEvent();
                                                   >> 1997         fNKeepRequests++;
                                                   >> 1998         fKeptLastEvent = true;
                                                   >> 1999       }
2417     }                                            2000     }
2418   }                                           << 
2419                                                  2001 
2420 //    // if (!fpSceneHandler->GetMarkForClear << 2002   } else {  //  Accumulating events...
2421 //    // is here.  It prevents ShowView at en << 2003 
2422 //    // for sequential mode, but MT mode see << 2004     G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
2423 //    // figured out why). ???? JA ????       << 2005     if (maxNumberOfKeptEvents > 0 && fNKeepRequests >= maxNumberOfKeptEvents) {
2424 //    if (!fpSceneHandler->GetMarkForClearing << 2006       fEventKeepingSuspended = true;
2425   if (fpScene->GetRefreshAtEndOfRun()) {      << 2007       static G4bool warned = false;
2426     fpSceneHandler->DrawEndOfRunModels();     << 2008       if (!warned) {
2427     // An extra refresh for auto-refresh view << 2009         if (fVerbosity >= warnings) {
2428     // ???? I DON'T WHY THIS IS NECESSARY ??? << 2010           G4cout <<
2429     if (fpViewer->GetViewParameters().IsAutoR << 2011           "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
2430       fpViewer->RefreshView();                << 2012           "\n  The number of events exceeds the maximum, "
2431     }                                         << 2013           << maxNumberOfKeptEvents <<
2432     // ShowView guarantees the view is flushe << 2014           ", that may be kept by\n  the vis manager."
2433     // triggers other features such picking ( << 2015           << G4endl;
2434     // file-writing viewers to close the file << 2016         }
2435     fpViewer->ShowView();                     << 2017         warned = true;
2436     fpSceneHandler->SetMarkForClearingTransie << 2018       }
2437   } else {                                    << 2019     } else if (maxNumberOfKeptEvents != 0) {
2438     if (fpGraphicsSystem->GetFunctionality()  << 2020       // If not disabled nor suspended.
2439         G4VGraphicsSystem::fileWriter) {      << 2021       if (GetConcreteInstance() && !fEventKeepingSuspended) {
2440       if (fVerbosity >= warnings) {           << 2022         //        G4cout << "Requesting keeping event " << event->GetEventID() << G4endl;
2441         G4warn << "\"/vis/viewer/update\" to  << 2023         eventManager->KeepTheCurrentEvent();
                                                   >> 2024         fNKeepRequests++;
2442       }                                          2025       }
2443     }                                            2026     }
2444   }                                              2027   }
2445 //}                                           << 
2446   fEventRefreshing = false;                   << 
2447 }                                                2028 }
2448                                                  2029 
                                                   >> 2030 #endif  // End of sequential versions of Begin/EndOfRun/Event.
                                                   >> 2031 
2449 void G4VisManager::ClearTransientStoreIfMarke    2032 void G4VisManager::ClearTransientStoreIfMarked(){
2450   // Assumes valid view.                         2033   // Assumes valid view.
2451   if (fpSceneHandler->GetMarkForClearingTrans    2034   if (fpSceneHandler->GetMarkForClearingTransientStore()) {
2452     fpSceneHandler->SetMarkForClearingTransie    2035     fpSceneHandler->SetMarkForClearingTransientStore(false);
2453     fpSceneHandler->ClearTransientStore();       2036     fpSceneHandler->ClearTransientStore();
2454   }                                              2037   }
2455   // Record if transients drawn.  These local    2038   // Record if transients drawn.  These local flags are only set
2456   // *after* ClearTransientStore.  In the cod    2039   // *after* ClearTransientStore.  In the code in G4VSceneHandler
2457   // triggered by ClearTransientStore, use th    2040   // triggered by ClearTransientStore, use these flags so that
2458   // event refreshing is not done too early.     2041   // event refreshing is not done too early.
2459   fTransientsDrawnThisEvent = fpSceneHandler-    2042   fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
2460   fTransientsDrawnThisRun = fpSceneHandler->G    2043   fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
2461 }                                                2044 }
2462                                                  2045 
2463 void G4VisManager::ResetTransientsDrawnFlags(    2046 void G4VisManager::ResetTransientsDrawnFlags()
2464 {                                                2047 {
2465   fTransientsDrawnThisRun = false;               2048   fTransientsDrawnThisRun = false;
2466   fTransientsDrawnThisEvent = false;             2049   fTransientsDrawnThisEvent = false;
2467   G4SceneHandlerListConstIterator i;             2050   G4SceneHandlerListConstIterator i;
2468   for (i = fAvailableSceneHandlers.begin();      2051   for (i = fAvailableSceneHandlers.begin();
2469        i != fAvailableSceneHandlers.end(); ++    2052        i != fAvailableSceneHandlers.end(); ++i) {
2470     (*i)->SetTransientsDrawnThisEvent(false);    2053     (*i)->SetTransientsDrawnThisEvent(false);
2471     (*i)->SetTransientsDrawnThisRun(false);      2054     (*i)->SetTransientsDrawnThisRun(false);
2472   }                                              2055   }
2473 }                                                2056 }
2474                                                  2057 
2475 G4String G4VisManager::ViewerShortName (const    2058 G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
2476   const G4String& viewerShortName = viewerNam << 2059   G4String viewerShortName (viewerName);
2477   return G4StrUtil::strip_copy(viewerShortNam << 2060   viewerShortName = viewerShortName (0, viewerShortName.find (' '));
                                                   >> 2061   return viewerShortName.strip ();
2478 }                                                2062 }
2479                                                  2063 
2480 G4VViewer* G4VisManager::GetViewer (const G4S    2064 G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
2481   G4String viewerShortName = ViewerShortName     2065   G4String viewerShortName = ViewerShortName (viewerName);
2482   std::size_t nHandlers = fAvailableSceneHand << 2066   size_t nHandlers = fAvailableSceneHandlers.size ();
2483   std::size_t iHandler, iViewer;              << 2067   size_t iHandler, iViewer;
2484   G4VViewer* viewer = 0;                         2068   G4VViewer* viewer = 0;
2485   G4bool found = false;                          2069   G4bool found = false;
2486   for (iHandler = 0; iHandler < nHandlers; iH    2070   for (iHandler = 0; iHandler < nHandlers; iHandler++) {
2487     G4VSceneHandler* sceneHandler = fAvailabl    2071     G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
2488     const G4ViewerList& viewerList = sceneHan    2072     const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
2489     for (iViewer = 0; iViewer < viewerList.si    2073     for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
2490       viewer = viewerList [iViewer];             2074       viewer = viewerList [iViewer];
2491       if (viewerShortName == viewer -> GetSho    2075       if (viewerShortName == viewer -> GetShortName ()) {
2492   found = true;                                  2076   found = true;
2493   break;                                         2077   break;
2494       }                                          2078       }
2495     }                                            2079     }
2496     if (found) break;                            2080     if (found) break;
2497   }                                              2081   }
2498   if (found) return viewer;                      2082   if (found) return viewer;
2499   else return 0;                                 2083   else return 0;
2500 }                                                2084 }
2501                                                  2085 
2502 std::vector<G4String> G4VisManager::Verbosity    2086 std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
2503                                                  2087 
2504 G4String G4VisManager::VerbosityString(Verbos    2088 G4String G4VisManager::VerbosityString(Verbosity verbosity) {
2505   G4String rs;                                   2089   G4String rs;
2506   switch (verbosity) {                           2090   switch (verbosity) {
2507   case         quiet: rs = "quiet (0)"; break    2091   case         quiet: rs = "quiet (0)"; break;
2508   case       startup: rs = "startup (1)"; bre    2092   case       startup: rs = "startup (1)"; break;
2509   case        errors: rs = "errors (2)"; brea    2093   case        errors: rs = "errors (2)"; break;
2510   case      warnings: rs = "warnings (3)"; br    2094   case      warnings: rs = "warnings (3)"; break;
2511   case confirmations: rs = "confirmations (4)    2095   case confirmations: rs = "confirmations (4)"; break;
2512   case    parameters: rs = "parameters (5)";     2096   case    parameters: rs = "parameters (5)"; break;
2513   case           all: rs = "all (6)"; break;     2097   case           all: rs = "all (6)"; break;
2514   }                                              2098   }
2515   return rs;                                     2099   return rs;
2516 }                                                2100 }
2517                                                  2101 
2518 void G4VisManager::PrintAvailableVerbosity(st << 
2519 {                                             << 
2520   os << "Available verbosity options:";       << 
2521   for (std::size_t i = 0; i < VerbosityGuidan << 
2522     os << '\n' << VerbosityGuidanceStrings[i] << 
2523   }                                           << 
2524   os << "\nCurrent verbosity: " << G4VisManag << 
2525   os << std::endl;                            << 
2526 }                                             << 
2527                                               << 
2528 G4VisManager::Verbosity                          2102 G4VisManager::Verbosity
2529 G4VisManager::GetVerbosityValue(const G4Strin    2103 G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
2530   G4String ss = G4StrUtil::to_lower_copy(verb << 2104   G4String ss(verbosityString); ss.toLower();
2531   Verbosity verbosity;                           2105   Verbosity verbosity;
2532   if      (ss[0] == 'q') verbosity = quiet;   << 2106   if      (ss(0) == 'q') verbosity = quiet;
2533   else if (ss[0] == 's') verbosity = startup; << 2107   else if (ss(0) == 's') verbosity = startup;
2534   else if (ss[0] == 'e') verbosity = errors;  << 2108   else if (ss(0) == 'e') verbosity = errors;
2535   else if (ss[0] == 'w') verbosity = warnings << 2109   else if (ss(0) == 'w') verbosity = warnings;
2536   else if (ss[0] == 'c') verbosity = confirma << 2110   else if (ss(0) == 'c') verbosity = confirmations;
2537   else if (ss[0] == 'p') verbosity = paramete << 2111   else if (ss(0) == 'p') verbosity = parameters;
2538   else if (ss[0] == 'a') verbosity = all;     << 2112   else if (ss(0) == 'a') verbosity = all;
2539   else {                                         2113   else {
2540     // Could be an integer                    << 
2541     G4int intVerbosity;                          2114     G4int intVerbosity;
2542     std::istringstream is(ss);                   2115     std::istringstream is(ss);
2543     is >> intVerbosity;                          2116     is >> intVerbosity;
2544     if (!is) {                                   2117     if (!is) {
2545       G4warn << "ERROR: G4VisManager::GetVerb << 2118       G4cerr << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
2546        << verbosityString << "\"\n";          << 2119        << verbosityString << "\"";
2547       PrintAvailableVerbosity(G4warn);        << 2120       for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
2548       // Return existing verbosity            << 2121   G4cerr << '\n' << VerbosityGuidanceStrings[i];
2549       return fVerbosity;                      << 2122       }
                                                   >> 2123       verbosity = warnings;
                                                   >> 2124       G4cerr << "\n  Returning " << VerbosityString(verbosity)
                                                   >> 2125        << G4endl;
2550     }                                            2126     }
2551     else {                                       2127     else {
2552       verbosity = GetVerbosityValue(intVerbos    2128       verbosity = GetVerbosityValue(intVerbosity);
2553     }                                            2129     }
2554   }                                              2130   }
2555   return verbosity;                              2131   return verbosity;
2556 }                                                2132 }
2557                                                  2133 
2558 G4VisManager::Verbosity G4VisManager::GetVerb    2134 G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
2559   Verbosity verbosity;                           2135   Verbosity verbosity;
2560   if      (intVerbosity < quiet) verbosity =     2136   if      (intVerbosity < quiet) verbosity = quiet;
2561   else if (intVerbosity > all)   verbosity =     2137   else if (intVerbosity > all)   verbosity = all;
2562   else                           verbosity =     2138   else                           verbosity = Verbosity(intVerbosity);
2563   return verbosity;                              2139   return verbosity;
2564 }                                                2140 }
2565                                                  2141 
2566 G4VisManager::Verbosity G4VisManager::GetVerb    2142 G4VisManager::Verbosity G4VisManager::GetVerbosity () {
2567   return fVerbosity;                             2143   return fVerbosity;
2568 }                                                2144 }
2569                                                  2145 
2570 void G4VisManager::SetVerboseLevel (G4int int    2146 void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
2571   fVerbosity = GetVerbosityValue(intVerbosity    2147   fVerbosity = GetVerbosityValue(intVerbosity);
2572 }                                                2148 }
2573                                                  2149 
2574 void G4VisManager::SetVerboseLevel (const G4S    2150 void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
2575   fVerbosity = GetVerbosityValue(verbosityStr    2151   fVerbosity = GetVerbosityValue(verbosityString);
2576 }                                                2152 }
2577                                                  2153 
2578 G4bool G4VisManager::IsValidView () {            2154 G4bool G4VisManager::IsValidView () {
2579                                                  2155 
2580   if (!fInitialised) Initialise ();              2156   if (!fInitialised) Initialise ();
2581                                                  2157 
2582   static G4bool noGSPrinting = true;             2158   static G4bool noGSPrinting = true;
2583   if (!fpGraphicsSystem) {                       2159   if (!fpGraphicsSystem) {
2584     // Limit printing - we do not want printi    2160     // Limit printing - we do not want printing if the user simply does
2585     // not want to use graphics, e.g., in bat    2161     // not want to use graphics, e.g., in batch mode.
2586     if (noGSPrinting) {                          2162     if (noGSPrinting) {
2587       noGSPrinting = false;                      2163       noGSPrinting = false;
2588       if (fVerbosity >= warnings) {              2164       if (fVerbosity >= warnings) {
2589   G4warn <<                                   << 2165   G4cout <<
2590   "WARNING: G4VisManager::IsValidView(): Atte    2166   "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
2591   "\n  has been instantiated.  Use \"/vis/ope    2167   "\n  has been instantiated.  Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
2592   "\n  Alternatively, to avoid this message,     2168   "\n  Alternatively, to avoid this message, suppress instantiation of vis"
2593   "\n  manager (G4VisExecutive) and ensure dr << 2169   "\n  manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
2594   "\n  G4VVisManager::GetConcreteInstance() i << 2170   "\n  drawing code is executed only if G4VVisManager::GetConcreteInstance()"
2595         << G4endl;                            << 2171   "\n  is non-zero."
                                                   >> 2172          << G4endl;
2596       }                                          2173       }
2597     }                                            2174     }
2598     return false;                                2175     return false;
2599   }                                              2176   }
2600                                                  2177 
2601   if ((!fpScene) || (!fpSceneHandler) || (!fp    2178   if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
2602     if (fVerbosity >= errors) {                  2179     if (fVerbosity >= errors) {
2603       G4warn <<                               << 2180       G4cerr <<
2604   "ERROR: G4VisManager::IsValidView(): Curren    2181   "ERROR: G4VisManager::IsValidView(): Current view is not valid."
2605        << G4endl;                                2182        << G4endl;
2606       PrintInvalidPointers ();                   2183       PrintInvalidPointers ();
2607     }                                            2184     }
2608     return false;                                2185     return false;
2609   }                                              2186   }
2610                                                  2187 
2611   if (fpScene != fpSceneHandler -> GetScene (    2188   if (fpScene != fpSceneHandler -> GetScene ()) {
2612     if (fVerbosity >= errors) {                  2189     if (fVerbosity >= errors) {
2613       G4warn << "ERROR: G4VisManager::IsValid << 2190       G4cerr << "ERROR: G4VisManager::IsValidView ():";
2614       if (fpSceneHandler -> GetScene ()) {       2191       if (fpSceneHandler -> GetScene ()) {
2615   G4warn <<                                   << 2192   G4cout <<
2616     "\n  The current scene \""                   2193     "\n  The current scene \""
2617          << fpScene -> GetName ()                2194          << fpScene -> GetName ()
2618          << "\" is not handled by"               2195          << "\" is not handled by"
2619     "\n  the current scene handler \""           2196     "\n  the current scene handler \""
2620          << fpSceneHandler -> GetName ()         2197          << fpSceneHandler -> GetName ()
2621          << "\""                                 2198          << "\""
2622     "\n  (it currently handles scene \""         2199     "\n  (it currently handles scene \""
2623          << fpSceneHandler -> GetScene () ->     2200          << fpSceneHandler -> GetScene () -> GetName ()
2624          << "\")."                               2201          << "\")."
2625     "\n  Either:"                                2202     "\n  Either:"
2626     "\n  (a) attach it to the scene handler w    2203     "\n  (a) attach it to the scene handler with"
2627     "\n      /vis/sceneHandler/attach "          2204     "\n      /vis/sceneHandler/attach "
2628          << fpScene -> GetName ()                2205          << fpScene -> GetName ()
2629          << ", or"                               2206          << ", or"
2630     "\n  (b) create a new scene handler with     2207     "\n  (b) create a new scene handler with "
2631     "\n      /vis/sceneHandler/create <graphi    2208     "\n      /vis/sceneHandler/create <graphics-system>,"
2632     "\n      in which case it should pick up     2209     "\n      in which case it should pick up the the new scene."
2633          << G4endl;                              2210          << G4endl;
2634       }                                          2211       }
2635       else {                                     2212       else {
2636   G4warn << "\n  Scene handler \""            << 2213   G4cout << "\n  Scene handler \""
2637          << fpSceneHandler -> GetName ()         2214          << fpSceneHandler -> GetName ()
2638          << "\" has null scene pointer."         2215          << "\" has null scene pointer."
2639     "\n  Attach a scene with /vis/sceneHandle    2216     "\n  Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
2640          << G4endl;                              2217          << G4endl;
2641       }                                          2218       }
2642     }                                            2219     }
2643     return false;                                2220     return false;
2644   }                                              2221   }
2645                                                  2222 
2646   const G4ViewerList& viewerList = fpSceneHan    2223   const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
2647   if (viewerList.size () == 0) {                 2224   if (viewerList.size () == 0) {
2648     if (fVerbosity >= errors) {                  2225     if (fVerbosity >= errors) {
2649       G4warn <<                               << 2226       G4cerr <<
2650   "ERROR: G4VisManager::IsValidView (): the c    2227   "ERROR: G4VisManager::IsValidView (): the current scene handler\n  \""
2651        << fpSceneHandler -> GetName ()           2228        << fpSceneHandler -> GetName ()
2652        << "\" has no viewers.  Do /vis/viewer    2229        << "\" has no viewers.  Do /vis/viewer/create."
2653        << G4endl;                                2230        << G4endl;
2654     }                                            2231     }
2655     return false;                                2232     return false;
2656   }                                              2233   }
2657                                                  2234 
2658   G4bool isValid = true;                         2235   G4bool isValid = true;
2659   if (fpScene -> IsEmpty ()) {  // Add world     2236   if (fpScene -> IsEmpty ()) {  // Add world by default if possible...
2660     G4bool warn(fVerbosity >= warnings);         2237     G4bool warn(fVerbosity >= warnings);
2661     G4bool successful = fpScene -> AddWorldIf    2238     G4bool successful = fpScene -> AddWorldIfEmpty (warn);
2662     if (!successful || fpScene -> IsEmpty ())    2239     if (!successful || fpScene -> IsEmpty ()) {        // If still empty...
2663       if (fVerbosity >= errors) {                2240       if (fVerbosity >= errors) {
2664   G4warn << "ERROR: G4VisManager::IsValidView << 2241   G4cerr << "ERROR: G4VisManager::IsValidView ():";
2665   G4warn <<                                   << 2242   G4cerr <<
2666     "\n  Attempt at some drawing operation wh    2243     "\n  Attempt at some drawing operation when scene is empty."
2667     "\n  Maybe the geometry has not yet been     2244     "\n  Maybe the geometry has not yet been defined."
2668     "  Try /run/initialize."                     2245     "  Try /run/initialize."
2669           "\n  Or use \"/vis/scene/add/extent    2246           "\n  Or use \"/vis/scene/add/extent\"."
2670          << G4endl;                              2247          << G4endl;
2671       }                                          2248       }
2672       isValid = false;                           2249       isValid = false;
2673     }                                            2250     }
2674     else {                                       2251     else {
2675       G4UImanager::GetUIpointer()->ApplyComma    2252       G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
2676       if (fVerbosity >= warnings) {              2253       if (fVerbosity >= warnings) {
2677   G4warn <<                                   << 2254   G4cout <<
2678     "WARNING: G4VisManager: the scene was emp    2255     "WARNING: G4VisManager: the scene was empty, \"world\" has been"
2679     "\n  added and the scene handlers notifie    2256     "\n  added and the scene handlers notified.";
2680   G4warn << G4endl;                           << 2257   G4cout << G4endl;
2681       }                                          2258       }
2682     }                                            2259     }
2683   }                                              2260   }
2684   return isValid;                                2261   return isValid;
2685 }                                                2262 }
2686                                                  2263 
2687 void                                             2264 void
2688 G4VisManager::RegisterModelFactories()           2265 G4VisManager::RegisterModelFactories() 
2689 {                                                2266 {
2690   if (fVerbosity >= warnings) {                  2267   if (fVerbosity >= warnings) {
2691     G4warn<<"G4VisManager: No model factories << 2268     G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
2692     G4warn<<"G4VisManager::RegisterModelFacto << 2269     G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
2693     G4warn<<"class. See G4VisExecutive for an << 2270     G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
2694   }                                              2271   }
2695 }                                                2272 }
2696                                                  2273 
                                                   >> 2274 #ifdef G4MULTITHREADED
2697 void G4VisManager::SetUpForAThread()             2275 void G4VisManager::SetUpForAThread()
2698 {                                                2276 {
2699   // TODO: protect with G4Threading::IsMultit << 
2700 #ifdef G4MULTITHREADED                        << 
2701   new G4VisStateDependent(this);                 2277   new G4VisStateDependent(this); 
2702 #endif                                        << 
2703 }                                                2278 }
                                                   >> 2279 #endif
2704                                                  2280 
2705 void G4VisManager::IgnoreStateChanges(G4bool     2281 void G4VisManager::IgnoreStateChanges(G4bool val)
2706 {                                                2282 {
2707   fIgnoreStateChanges = val;                     2283   fIgnoreStateChanges = val; 
2708 }                                                2284 }
2709                                                  2285