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 11.1.2)


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