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