[531] | 1 | // |
---|
| 2 | // ******************************************************************** |
---|
| 3 | // * License and Disclaimer * |
---|
| 4 | // * * |
---|
| 5 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
| 6 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
| 7 | // * conditions of the Geant4 Software License, included in the file * |
---|
| 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
| 9 | // * include a list of copyright holders. * |
---|
| 10 | // * * |
---|
| 11 | // * Neither the authors of this software system, nor their employing * |
---|
| 12 | // * institutes,nor the agencies providing financial support for this * |
---|
| 13 | // * work make any representation or warranty, express or implied, * |
---|
| 14 | // * regarding this software system or assume any liability for its * |
---|
| 15 | // * use. Please see the license in the file LICENSE and URL above * |
---|
| 16 | // * for the full disclaimer and the limitation of liability. * |
---|
| 17 | // * * |
---|
| 18 | // * This code implementation is the result of the scientific and * |
---|
| 19 | // * technical work of the GEANT4 collaboration. * |
---|
| 20 | // * By using, copying, modifying or distributing the software (or * |
---|
| 21 | // * any work based on the software) you agree to acknowledge its * |
---|
| 22 | // * use in resulting scientific publications, and indicate your * |
---|
| 23 | // * acceptance of all terms of the Geant4 Software license. * |
---|
| 24 | // ******************************************************************** |
---|
| 25 | // |
---|
[1241] | 26 | // $Id: G4VisManager.cc,v 1.123 2010/03/08 16:34:17 lgarnier Exp $ |
---|
[907] | 27 | // GEANT4 tag $Name: $ |
---|
[531] | 28 | // |
---|
| 29 | // |
---|
| 30 | // GEANT4 Visualization Manager - John Allison 02/Jan/1996. |
---|
| 31 | |
---|
| 32 | #include "G4VisManager.hh" |
---|
| 33 | |
---|
| 34 | #include "G4VisCommands.hh" |
---|
| 35 | #include "G4VisCommandsCompound.hh" |
---|
| 36 | #include "G4VisCommandsGeometry.hh" |
---|
| 37 | #include "G4VisCommandsGeometrySet.hh" |
---|
| 38 | #include "G4VisCommandsScene.hh" |
---|
| 39 | #include "G4VisCommandsSceneAdd.hh" |
---|
| 40 | #include "G4VisCommandsSceneHandler.hh" |
---|
| 41 | #include "G4VisCommandsViewer.hh" |
---|
| 42 | #include "G4VisCommandsViewerSet.hh" |
---|
| 43 | #include "G4UImanager.hh" |
---|
| 44 | #include "G4VisStateDependent.hh" |
---|
| 45 | #include "G4UIdirectory.hh" |
---|
| 46 | #include "G4VisFeaturesOfFukuiRenderer.hh" |
---|
| 47 | #include "G4VisFeaturesOfDAWNFILE.hh" |
---|
| 48 | #include "G4VisFeaturesOfOpenGL.hh" |
---|
| 49 | #include "G4VisFeaturesOfOpenInventor.hh" |
---|
| 50 | #include "G4VGraphicsSystem.hh" |
---|
| 51 | #include "G4VSceneHandler.hh" |
---|
| 52 | #include "G4VViewer.hh" |
---|
| 53 | #include "G4VPhysicalVolume.hh" |
---|
| 54 | #include "G4LogicalVolume.hh" |
---|
| 55 | #include "G4VSolid.hh" |
---|
| 56 | #include "G4Vector3D.hh" |
---|
| 57 | #include "G4Point3D.hh" |
---|
| 58 | #include "G4RotationMatrix.hh" |
---|
| 59 | #include "G4Polyline.hh" |
---|
| 60 | #include "G4Polyhedron.hh" |
---|
| 61 | #include "G4NURBS.hh" |
---|
| 62 | #include "G4NullModel.hh" |
---|
| 63 | #include "G4ModelingParameters.hh" |
---|
| 64 | #include "G4TransportationManager.hh" |
---|
| 65 | #include "G4VisCommandModelCreate.hh" |
---|
| 66 | #include "G4VisCommandsListManager.hh" |
---|
| 67 | #include "G4VisModelManager.hh" |
---|
| 68 | #include "G4VModelFactory.hh" |
---|
| 69 | #include "G4VisFilterManager.hh" |
---|
| 70 | #include "G4VTrajectoryModel.hh" |
---|
| 71 | #include "G4TrajectoryDrawByCharge.hh" |
---|
| 72 | #include "Randomize.hh" |
---|
| 73 | #include "G4RunManager.hh" |
---|
[593] | 74 | #include "G4EventManager.hh" |
---|
[531] | 75 | #include "G4Run.hh" |
---|
| 76 | #include "G4Event.hh" |
---|
| 77 | #include <sstream> |
---|
| 78 | |
---|
| 79 | G4VisManager* G4VisManager::fpInstance = 0; |
---|
| 80 | |
---|
| 81 | G4VisManager::G4VisManager (): |
---|
| 82 | fVerbose (1), |
---|
| 83 | fInitialised (false), |
---|
| 84 | fpUserVisAction (0), |
---|
| 85 | fpGraphicsSystem (0), |
---|
| 86 | fpScene (0), |
---|
| 87 | fpSceneHandler (0), |
---|
| 88 | fpViewer (0), |
---|
[1170] | 89 | fVerbosity (warnings), |
---|
[531] | 90 | fpStateDependent (0), |
---|
| 91 | fEventRefreshing (false), |
---|
| 92 | fTransientsDrawnThisRun (false), |
---|
| 93 | fTransientsDrawnThisEvent (false), |
---|
| 94 | fEventKeepingSuspended (false), |
---|
[593] | 95 | fKeptLastEvent (false), |
---|
| 96 | fpRequestedEvent (0), |
---|
| 97 | fAbortReviewKeptEvents (false) |
---|
[531] | 98 | // All other objects use default constructors. |
---|
| 99 | { |
---|
| 100 | fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories"); |
---|
| 101 | fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories"); |
---|
| 102 | fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits"); |
---|
| 103 | |
---|
| 104 | VerbosityGuidanceStrings.push_back |
---|
| 105 | ("Simple graded message scheme - digit or string (1st character defines):"); |
---|
| 106 | VerbosityGuidanceStrings.push_back |
---|
| 107 | (" 0) quiet, // Nothing is printed."); |
---|
| 108 | VerbosityGuidanceStrings.push_back |
---|
| 109 | (" 1) startup, // Startup and endup messages are printed..."); |
---|
| 110 | VerbosityGuidanceStrings.push_back |
---|
| 111 | (" 2) errors, // ...and errors..."); |
---|
| 112 | VerbosityGuidanceStrings.push_back |
---|
| 113 | (" 3) warnings, // ...and warnings..."); |
---|
| 114 | VerbosityGuidanceStrings.push_back |
---|
| 115 | (" 4) confirmations, // ...and confirming messages..."); |
---|
| 116 | VerbosityGuidanceStrings.push_back |
---|
| 117 | (" 5) parameters, // ...and parameters of scenes and views..."); |
---|
| 118 | VerbosityGuidanceStrings.push_back |
---|
| 119 | (" 6) all // ...and everything available."); |
---|
| 120 | |
---|
| 121 | if (fpInstance) { |
---|
| 122 | G4Exception |
---|
[593] | 123 | ("G4VisManager: attempt to Construct more than one VisManager."); |
---|
[531] | 124 | } |
---|
| 125 | else { |
---|
| 126 | |
---|
| 127 | fpInstance = this; |
---|
| 128 | SetConcreteInstance(this); |
---|
| 129 | |
---|
| 130 | fpStateDependent = new G4VisStateDependent (this); |
---|
| 131 | // No need to delete this; G4StateManager does this. |
---|
| 132 | |
---|
| 133 | if (fVerbosity >= startup) { |
---|
| 134 | G4cout << "Visualization Manager instantiating..." << G4endl; |
---|
| 135 | } |
---|
| 136 | |
---|
| 137 | // Note: The specific graphics systems must be instantiated in a |
---|
| 138 | // higher level library to avoid circular dependencies. Also, |
---|
| 139 | // some specifically need additional external libararies that the |
---|
| 140 | // user must supply. Therefore we ask the user to implement |
---|
| 141 | // RegisterGraphicsSystems() and RegisterModelFactories() |
---|
| 142 | // in a subclass. We have to wait for the subclass to instantiate |
---|
| 143 | // so RegisterGraphicsSystems() cannot be called from this |
---|
| 144 | // constructor; it is called from Initialise(). So we ask the |
---|
| 145 | // user: |
---|
| 146 | // (a) to write a subclass and implement RegisterGraphicsSystems() |
---|
| 147 | // and RegisterModelFactories(). See |
---|
| 148 | // visualization/include/G4VisExecutive.hh/icc as an example. |
---|
| 149 | // (b) instantiate the subclass. |
---|
| 150 | // (c) invoke the Initialise() method of the subclass. |
---|
| 151 | // For example: |
---|
| 152 | // ... |
---|
| 153 | // #ifdef G4VIS_USE |
---|
| 154 | // // Instantiate and initialise Visualization Manager. |
---|
| 155 | // G4VisManager* visManager = new G4VisExecutive; |
---|
| 156 | // visManager -> SetVerboseLevel (Verbose); |
---|
| 157 | // visManager -> Initialise (); |
---|
| 158 | // #endif |
---|
| 159 | // // (Don't forget to delete visManager;) |
---|
| 160 | // ... |
---|
[944] | 161 | |
---|
| 162 | // Make top level command directory... |
---|
| 163 | G4UIcommand* directory; |
---|
| 164 | directory = new G4UIdirectory ("/vis/"); |
---|
| 165 | directory -> SetGuidance ("Visualization commands."); |
---|
| 166 | fDirectoryList.push_back (directory); |
---|
| 167 | |
---|
| 168 | // Instantiate top level basic commands |
---|
| 169 | G4VVisCommand::SetVisManager (this); // Sets shared pointer |
---|
| 170 | RegisterMessenger(new G4VisCommandVerbose); |
---|
| 171 | RegisterMessenger(new G4VisCommandInitialize); |
---|
[531] | 172 | } |
---|
| 173 | } |
---|
| 174 | |
---|
| 175 | G4VisManager::~G4VisManager () { |
---|
| 176 | fpInstance = 0; |
---|
| 177 | size_t i; |
---|
| 178 | for (i = 0; i < fSceneList.size (); ++i) { |
---|
| 179 | delete fSceneList[i]; |
---|
| 180 | } |
---|
| 181 | for (i = 0; i < fAvailableSceneHandlers.size (); ++i) { |
---|
[1170] | 182 | if (fAvailableSceneHandlers[i] != NULL) { |
---|
[531] | 183 | delete fAvailableSceneHandlers[i]; |
---|
| 184 | } |
---|
[1170] | 185 | } |
---|
[531] | 186 | for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) { |
---|
[1170] | 187 | if (fAvailableGraphicsSystems[i]) { |
---|
| 188 | delete fAvailableGraphicsSystems[i]; |
---|
| 189 | } |
---|
[531] | 190 | } |
---|
| 191 | if (fVerbosity >= startup) { |
---|
| 192 | G4cout << "Graphics systems deleted." << G4endl; |
---|
| 193 | G4cout << "Visualization Manager deleting..." << G4endl; |
---|
| 194 | } |
---|
| 195 | for (i = 0; i < fMessengerList.size (); ++i) { |
---|
| 196 | delete fMessengerList[i]; |
---|
| 197 | } |
---|
| 198 | for (i = 0; i < fDirectoryList.size (); ++i) { |
---|
| 199 | delete fDirectoryList[i]; |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | delete fpTrajDrawModelMgr; |
---|
| 203 | delete fpTrajFilterMgr; |
---|
| 204 | delete fpHitFilterMgr; |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | G4VisManager* G4VisManager::GetInstance () { |
---|
| 208 | if (!fpInstance) { |
---|
| 209 | G4Exception |
---|
| 210 | ("G4VisManager::GetInstance: VisManager not yet instantiated!"); |
---|
| 211 | } |
---|
| 212 | return fpInstance; |
---|
| 213 | } |
---|
| 214 | |
---|
| 215 | void G4VisManager::Initialise () { |
---|
| 216 | |
---|
[944] | 217 | if (fInitialised && fVerbosity >= warnings) { |
---|
| 218 | G4cout << "WARNING: G4VisManager::Initialise: already initialised." |
---|
| 219 | << G4endl; |
---|
| 220 | return; |
---|
| 221 | } |
---|
| 222 | |
---|
[531] | 223 | if (fVerbosity >= startup) { |
---|
| 224 | G4cout << "Visualization Manager initialising..." << G4endl; |
---|
| 225 | } |
---|
| 226 | |
---|
| 227 | if (fVerbosity >= parameters) { |
---|
| 228 | G4cout << |
---|
| 229 | "\nYou have instantiated your own Visualization Manager, inheriting" |
---|
| 230 | "\n G4VisManager and implementing RegisterGraphicsSystems(), in which" |
---|
| 231 | "\n you should, normally, instantiate drivers which do not need" |
---|
| 232 | "\n external packages or libraries, and, optionally, drivers under" |
---|
| 233 | "\n control of environment variables." |
---|
| 234 | "\n Also you should implement RegisterModelFactories()." |
---|
| 235 | "\n See visualization/include/G4VisExecutive.hh/icc, for example." |
---|
| 236 | "\n In your main() you will have something like:" |
---|
| 237 | "\n #ifdef G4VIS_USE" |
---|
| 238 | "\n G4VisManager* visManager = new G4VisExecutive;" |
---|
| 239 | "\n visManager -> SetVerboseLevel (Verbose);" |
---|
| 240 | "\n visManager -> Initialize ();" |
---|
| 241 | "\n #endif" |
---|
| 242 | "\n (Don't forget to delete visManager;)" |
---|
| 243 | "\n" |
---|
| 244 | << G4endl; |
---|
| 245 | } |
---|
| 246 | |
---|
| 247 | if (fVerbosity >= startup) { |
---|
| 248 | G4cout << "Registering graphics systems..." << G4endl; |
---|
| 249 | } |
---|
| 250 | |
---|
| 251 | RegisterGraphicsSystems (); |
---|
| 252 | |
---|
| 253 | if (fVerbosity >= startup) { |
---|
| 254 | G4cout << |
---|
| 255 | "\nYou have successfully registered the following graphics systems." |
---|
| 256 | << G4endl; |
---|
| 257 | PrintAvailableGraphicsSystems (); |
---|
| 258 | G4cout << G4endl; |
---|
| 259 | } |
---|
| 260 | |
---|
[944] | 261 | // Make command directories for commands instantiated in the |
---|
| 262 | // modeling subcategory... |
---|
[531] | 263 | G4UIcommand* directory; |
---|
| 264 | directory = new G4UIdirectory ("/vis/modeling/"); |
---|
| 265 | directory -> SetGuidance ("Modeling commands."); |
---|
| 266 | fDirectoryList.push_back (directory); |
---|
| 267 | directory = new G4UIdirectory ("/vis/modeling/trajectories/"); |
---|
| 268 | directory -> SetGuidance ("Trajectory model commands."); |
---|
| 269 | fDirectoryList.push_back (directory); |
---|
| 270 | directory = new G4UIdirectory ("/vis/modeling/trajectories/create/"); |
---|
| 271 | directory -> SetGuidance ("Create trajectory models and messengers."); |
---|
| 272 | fDirectoryList.push_back (directory); |
---|
| 273 | |
---|
| 274 | // Filtering command directory |
---|
| 275 | directory = new G4UIdirectory ("/vis/filtering/"); |
---|
| 276 | directory -> SetGuidance ("Filtering commands."); |
---|
| 277 | fDirectoryList.push_back (directory); |
---|
| 278 | directory = new G4UIdirectory ("/vis/filtering/trajectories/"); |
---|
| 279 | directory -> SetGuidance ("Trajectory filtering commands."); |
---|
| 280 | fDirectoryList.push_back (directory); |
---|
| 281 | directory = new G4UIdirectory ("/vis/filtering/trajectories/create/"); |
---|
| 282 | directory -> SetGuidance ("Create trajectory filters and messengers."); |
---|
| 283 | fDirectoryList.push_back (directory); |
---|
| 284 | directory = new G4UIdirectory ("/vis/filtering/hits/"); |
---|
| 285 | directory -> SetGuidance ("Hit filtering commands."); |
---|
| 286 | fDirectoryList.push_back (directory); |
---|
| 287 | directory = new G4UIdirectory ("/vis/filtering/hits/create/"); |
---|
| 288 | directory -> SetGuidance ("Create hit filters and messengers."); |
---|
| 289 | fDirectoryList.push_back (directory); |
---|
| 290 | |
---|
| 291 | RegisterMessengers (); |
---|
| 292 | |
---|
| 293 | if (fVerbosity >= startup) { |
---|
| 294 | G4cout << "Registering model factories..." << G4endl; |
---|
| 295 | } |
---|
| 296 | |
---|
| 297 | RegisterModelFactories(); |
---|
| 298 | |
---|
| 299 | if (fVerbosity >= startup) { |
---|
| 300 | G4cout << |
---|
| 301 | "\nYou have successfully registered the following model factories." |
---|
| 302 | << G4endl; |
---|
| 303 | PrintAvailableModels (fVerbosity); |
---|
| 304 | G4cout << G4endl; |
---|
| 305 | } |
---|
| 306 | |
---|
| 307 | fInitialised = true; |
---|
| 308 | } |
---|
| 309 | |
---|
| 310 | void G4VisManager::Enable() { |
---|
| 311 | if (IsValidView ()) { |
---|
| 312 | if (fVerbosity >= confirmations) { |
---|
| 313 | G4cout << "G4VisManager::Enable: visualization enabled." << G4endl; |
---|
| 314 | } |
---|
| 315 | } |
---|
| 316 | else { |
---|
| 317 | if (fVerbosity >= warnings) { |
---|
| 318 | G4cout << |
---|
| 319 | "G4VisManager::Enable: WARNING: visualization remains disabled for" |
---|
| 320 | "\n above reasons. Rectifying with valid vis commands will" |
---|
| 321 | "\n automatically enable." |
---|
| 322 | << G4endl; |
---|
| 323 | } |
---|
| 324 | } |
---|
| 325 | } |
---|
| 326 | |
---|
| 327 | void G4VisManager::Disable() { |
---|
| 328 | SetConcreteInstance(0); |
---|
| 329 | if (fVerbosity >= confirmations) { |
---|
| 330 | G4cout << |
---|
| 331 | "G4VisManager::Disable: visualization disabled." |
---|
| 332 | "\n The pointer returned by GetConcreteInstance will be zero." |
---|
| 333 | "\n Note that it will become enabled after some valid vis commands." |
---|
| 334 | << G4endl; |
---|
| 335 | } |
---|
| 336 | } |
---|
| 337 | |
---|
| 338 | const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () { |
---|
| 339 | G4int nSystems = fAvailableGraphicsSystems.size (); |
---|
| 340 | if (nSystems == 0) { |
---|
| 341 | if (fVerbosity >= warnings) { |
---|
| 342 | G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no" |
---|
| 343 | "\n graphics system available!" |
---|
| 344 | "\n 1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set" |
---|
| 345 | "\n when you compiled/built the visualization code?" |
---|
| 346 | "\n 2) Did you instantiate your own Visualization Manager and forget" |
---|
| 347 | "\n to implement RegisterGraphicsSystems correctly?" |
---|
| 348 | "\n 3) You can register your own graphics system, e.g.," |
---|
| 349 | "\n visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)" |
---|
| 350 | "\n after instantiating your vis manager and before" |
---|
| 351 | "\n visManager->Initialize()." |
---|
| 352 | << G4endl; |
---|
| 353 | } |
---|
| 354 | } |
---|
| 355 | return fAvailableGraphicsSystems; |
---|
| 356 | } |
---|
| 357 | |
---|
| 358 | G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) { |
---|
| 359 | G4bool happy = true; |
---|
| 360 | if (pSystem) { |
---|
| 361 | fAvailableGraphicsSystems.push_back (pSystem); |
---|
| 362 | if (fVerbosity >= confirmations) { |
---|
| 363 | G4cout << "G4VisManager::RegisterGraphicsSystem: " |
---|
| 364 | << pSystem -> GetName (); |
---|
| 365 | if (pSystem -> GetNickname () != "") { |
---|
| 366 | G4cout << " (" << pSystem -> GetNickname () << ")"; |
---|
| 367 | } |
---|
| 368 | G4cout << " registered." << G4endl; |
---|
| 369 | } |
---|
| 370 | } |
---|
| 371 | else { |
---|
| 372 | if (fVerbosity >= errors) { |
---|
| 373 | G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!" |
---|
| 374 | << G4endl; |
---|
| 375 | } |
---|
| 376 | happy=false; |
---|
| 377 | } |
---|
| 378 | return happy; |
---|
| 379 | } |
---|
| 380 | |
---|
| 381 | const G4VTrajectoryModel* |
---|
| 382 | G4VisManager::CurrentTrajDrawModel() const |
---|
| 383 | { |
---|
| 384 | assert (0 != fpTrajDrawModelMgr); |
---|
| 385 | |
---|
| 386 | const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current(); |
---|
| 387 | |
---|
| 388 | if (0 == model) { |
---|
| 389 | // No model was registered with the trajectory model manager. |
---|
| 390 | // Use G4TrajectoryDrawByCharge as a default. |
---|
| 391 | fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated")); |
---|
| 392 | |
---|
| 393 | if (fVerbosity >= warnings) { |
---|
| 394 | G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl; |
---|
| 395 | G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl; |
---|
| 396 | } |
---|
| 397 | } |
---|
| 398 | |
---|
| 399 | model = fpTrajDrawModelMgr->Current(); |
---|
| 400 | assert (0 != model); // Should definitely exist now |
---|
| 401 | |
---|
| 402 | return model; |
---|
| 403 | } |
---|
| 404 | |
---|
| 405 | void G4VisManager::RegisterModel(G4VTrajectoryModel* model) |
---|
| 406 | { |
---|
| 407 | fpTrajDrawModelMgr->Register(model); |
---|
| 408 | } |
---|
| 409 | |
---|
| 410 | void |
---|
| 411 | G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory) |
---|
| 412 | { |
---|
| 413 | fpTrajDrawModelMgr->Register(factory); |
---|
| 414 | } |
---|
| 415 | |
---|
| 416 | void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model) |
---|
| 417 | { |
---|
| 418 | fpTrajFilterMgr->Register(model); |
---|
| 419 | } |
---|
| 420 | |
---|
| 421 | void |
---|
| 422 | G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory) |
---|
| 423 | { |
---|
| 424 | fpTrajFilterMgr->Register(factory); |
---|
| 425 | } |
---|
| 426 | |
---|
| 427 | void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model) |
---|
| 428 | { |
---|
| 429 | fpHitFilterMgr->Register(model); |
---|
| 430 | } |
---|
| 431 | |
---|
| 432 | void |
---|
| 433 | G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory) |
---|
| 434 | { |
---|
| 435 | fpHitFilterMgr->Register(factory); |
---|
| 436 | } |
---|
| 437 | |
---|
| 438 | void G4VisManager::SelectTrajectoryModel(const G4String& model) |
---|
| 439 | { |
---|
| 440 | fpTrajDrawModelMgr->SetCurrent(model); |
---|
| 441 | } |
---|
| 442 | |
---|
| 443 | void G4VisManager::Draw (const G4Circle& circle, |
---|
| 444 | const G4Transform3D& objectTransform) { |
---|
| 445 | if (IsValidView ()) { |
---|
| 446 | ClearTransientStoreIfMarked(); |
---|
| 447 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 448 | fpSceneHandler -> AddPrimitive (circle); |
---|
| 449 | fpSceneHandler -> EndPrimitives (); |
---|
| 450 | } |
---|
| 451 | } |
---|
| 452 | |
---|
| 453 | void G4VisManager::Draw (const G4NURBS& nurbs, |
---|
| 454 | const G4Transform3D& objectTransform) { |
---|
| 455 | if (IsValidView ()) { |
---|
| 456 | ClearTransientStoreIfMarked(); |
---|
| 457 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 458 | fpSceneHandler -> AddPrimitive (nurbs); |
---|
| 459 | fpSceneHandler -> EndPrimitives (); |
---|
| 460 | } |
---|
| 461 | } |
---|
| 462 | |
---|
| 463 | void G4VisManager::Draw (const G4Polyhedron& polyhedron, |
---|
| 464 | const G4Transform3D& objectTransform) { |
---|
| 465 | if (IsValidView ()) { |
---|
| 466 | ClearTransientStoreIfMarked(); |
---|
| 467 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 468 | fpSceneHandler -> AddPrimitive (polyhedron); |
---|
| 469 | fpSceneHandler -> EndPrimitives (); |
---|
| 470 | } |
---|
| 471 | } |
---|
| 472 | |
---|
| 473 | void G4VisManager::Draw (const G4Polyline& line, |
---|
| 474 | const G4Transform3D& objectTransform) { |
---|
| 475 | if (IsValidView ()) { |
---|
| 476 | ClearTransientStoreIfMarked(); |
---|
| 477 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 478 | fpSceneHandler -> AddPrimitive (line); |
---|
[1242] | 479 | #ifndef G4VIS_BUILD_OPTIMISE_2 |
---|
[531] | 480 | fpSceneHandler -> EndPrimitives (); |
---|
[1242] | 481 | #endif |
---|
[531] | 482 | } |
---|
| 483 | } |
---|
| 484 | |
---|
| 485 | void G4VisManager::Draw (const G4Polymarker& polymarker, |
---|
| 486 | const G4Transform3D& objectTransform) { |
---|
| 487 | if (IsValidView ()) { |
---|
| 488 | ClearTransientStoreIfMarked(); |
---|
[1242] | 489 | #ifndef G4VIS_BUILD_OPTIMISE_2 |
---|
| 490 | // FIXME : test |
---|
[531] | 491 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
[1242] | 492 | #endif |
---|
[531] | 493 | fpSceneHandler -> AddPrimitive (polymarker); |
---|
[1242] | 494 | // FIXME : test |
---|
| 495 | #ifndef G4VIS_BUILD_OPTIMISE_2 |
---|
[531] | 496 | fpSceneHandler -> EndPrimitives (); |
---|
[1242] | 497 | #endif |
---|
[531] | 498 | } |
---|
| 499 | } |
---|
| 500 | |
---|
| 501 | void G4VisManager::Draw (const G4Scale& scale, |
---|
| 502 | const G4Transform3D& objectTransform) { |
---|
| 503 | if (IsValidView ()) { |
---|
| 504 | ClearTransientStoreIfMarked(); |
---|
| 505 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 506 | fpSceneHandler -> AddPrimitive (scale); |
---|
| 507 | fpSceneHandler -> EndPrimitives (); |
---|
| 508 | } |
---|
| 509 | } |
---|
| 510 | |
---|
| 511 | void G4VisManager::Draw (const G4Square& square, |
---|
| 512 | const G4Transform3D& objectTransform) { |
---|
| 513 | if (IsValidView ()) { |
---|
| 514 | ClearTransientStoreIfMarked(); |
---|
| 515 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 516 | fpSceneHandler -> AddPrimitive (square); |
---|
| 517 | fpSceneHandler -> EndPrimitives (); |
---|
| 518 | } |
---|
| 519 | } |
---|
| 520 | |
---|
| 521 | void G4VisManager::Draw (const G4Text& text, |
---|
| 522 | const G4Transform3D& objectTransform) { |
---|
| 523 | if (IsValidView ()) { |
---|
| 524 | ClearTransientStoreIfMarked(); |
---|
[1242] | 525 | // FIXME : test |
---|
| 526 | #ifndef G4VIS_BUILD_OPTIMISE_2 |
---|
[531] | 527 | fpSceneHandler -> BeginPrimitives (objectTransform); |
---|
| 528 | fpSceneHandler -> AddPrimitive (text); |
---|
[1242] | 529 | #endif |
---|
[531] | 530 | fpSceneHandler -> EndPrimitives (); |
---|
| 531 | } |
---|
| 532 | } |
---|
| 533 | |
---|
[688] | 534 | void G4VisManager::Draw2D (const G4Circle& circle, |
---|
| 535 | const G4Transform3D& objectTransform) |
---|
[531] | 536 | { |
---|
| 537 | if (IsValidView()) { |
---|
| 538 | ClearTransientStoreIfMarked(); |
---|
[688] | 539 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 540 | fpSceneHandler -> AddPrimitive(circle); |
---|
| 541 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 542 | } |
---|
| 543 | } |
---|
| 544 | |
---|
| 545 | void G4VisManager::Draw2D (const G4NURBS& nurbs, |
---|
| 546 | const G4Transform3D& objectTransform) |
---|
| 547 | { |
---|
| 548 | if (IsValidView()) { |
---|
| 549 | ClearTransientStoreIfMarked(); |
---|
| 550 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 551 | fpSceneHandler -> AddPrimitive(nurbs); |
---|
| 552 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 553 | } |
---|
| 554 | } |
---|
| 555 | |
---|
| 556 | void G4VisManager::Draw2D (const G4Polyhedron& polyhedron, |
---|
| 557 | const G4Transform3D& objectTransform) |
---|
| 558 | { |
---|
| 559 | if (IsValidView()) { |
---|
| 560 | ClearTransientStoreIfMarked(); |
---|
| 561 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 562 | fpSceneHandler -> AddPrimitive(polyhedron); |
---|
| 563 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 564 | } |
---|
| 565 | } |
---|
| 566 | |
---|
| 567 | void G4VisManager::Draw2D (const G4Polyline& line, |
---|
| 568 | const G4Transform3D& objectTransform) |
---|
| 569 | { |
---|
| 570 | if (IsValidView()) { |
---|
| 571 | ClearTransientStoreIfMarked(); |
---|
| 572 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 573 | fpSceneHandler -> AddPrimitive(line); |
---|
| 574 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 575 | } |
---|
| 576 | } |
---|
| 577 | |
---|
| 578 | void G4VisManager::Draw2D (const G4Polymarker& polymarker, |
---|
| 579 | const G4Transform3D& objectTransform) |
---|
| 580 | { |
---|
| 581 | if (IsValidView()) { |
---|
| 582 | ClearTransientStoreIfMarked(); |
---|
| 583 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 584 | fpSceneHandler -> AddPrimitive(polymarker); |
---|
| 585 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 586 | } |
---|
| 587 | } |
---|
| 588 | |
---|
| 589 | void G4VisManager::Draw2D (const G4Square& square, |
---|
| 590 | const G4Transform3D& objectTransform) |
---|
| 591 | { |
---|
| 592 | if (IsValidView()) { |
---|
| 593 | ClearTransientStoreIfMarked(); |
---|
| 594 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
| 595 | fpSceneHandler -> AddPrimitive(square); |
---|
| 596 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 597 | } |
---|
| 598 | } |
---|
| 599 | |
---|
| 600 | void G4VisManager::Draw2D (const G4Text& text, |
---|
| 601 | const G4Transform3D& objectTransform) |
---|
| 602 | { |
---|
| 603 | if (IsValidView()) { |
---|
| 604 | ClearTransientStoreIfMarked(); |
---|
| 605 | fpSceneHandler -> BeginPrimitives2D(objectTransform); |
---|
[531] | 606 | fpSceneHandler -> AddPrimitive(text); |
---|
| 607 | fpSceneHandler -> EndPrimitives2D(); |
---|
| 608 | } |
---|
| 609 | } |
---|
| 610 | |
---|
| 611 | void G4VisManager::Draw (const G4VHit& hit) { |
---|
| 612 | if (IsValidView ()) { |
---|
| 613 | ClearTransientStoreIfMarked(); |
---|
| 614 | fpSceneHandler -> AddCompound (hit); |
---|
| 615 | } |
---|
| 616 | } |
---|
| 617 | |
---|
| 618 | void G4VisManager::Draw (const G4VTrajectory& traj, |
---|
| 619 | G4int i_mode) { |
---|
| 620 | if (IsValidView ()) { |
---|
| 621 | ClearTransientStoreIfMarked(); |
---|
| 622 | fpSceneHandler -> SetModel (&dummyTrajectoriesModel); |
---|
| 623 | dummyTrajectoriesModel.SetDrawingMode(i_mode); |
---|
| 624 | fpSceneHandler -> AddCompound (traj); |
---|
| 625 | } |
---|
| 626 | } |
---|
| 627 | |
---|
| 628 | void G4VisManager::Draw (const G4LogicalVolume& logicalVol, |
---|
| 629 | const G4VisAttributes& attribs, |
---|
| 630 | const G4Transform3D& objectTransform) { |
---|
| 631 | // Find corresponding solid. |
---|
| 632 | G4VSolid* pSol = logicalVol.GetSolid (); |
---|
| 633 | Draw (*pSol, attribs, objectTransform); |
---|
| 634 | } |
---|
| 635 | |
---|
| 636 | void G4VisManager::Draw (const G4VSolid& solid, |
---|
| 637 | const G4VisAttributes& attribs, |
---|
| 638 | const G4Transform3D& objectTransform) { |
---|
| 639 | if (IsValidView ()) { |
---|
| 640 | ClearTransientStoreIfMarked(); |
---|
| 641 | fpSceneHandler -> PreAddSolid (objectTransform, attribs); |
---|
| 642 | solid.DescribeYourselfTo (*fpSceneHandler); |
---|
| 643 | fpSceneHandler -> PostAddSolid (); |
---|
| 644 | } |
---|
| 645 | } |
---|
| 646 | |
---|
| 647 | void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol, |
---|
| 648 | const G4VisAttributes& attribs, |
---|
| 649 | const G4Transform3D& objectTransform) { |
---|
| 650 | // Find corresponding logical volume and solid. |
---|
| 651 | G4LogicalVolume* pLV = physicalVol.GetLogicalVolume (); |
---|
| 652 | G4VSolid* pSol = pLV -> GetSolid (); |
---|
| 653 | Draw (*pSol, attribs, objectTransform); |
---|
| 654 | } |
---|
| 655 | |
---|
| 656 | void G4VisManager::CreateSceneHandler (G4String name) { |
---|
| 657 | if (!fInitialised) Initialise (); |
---|
| 658 | if (fpGraphicsSystem) { |
---|
| 659 | G4VSceneHandler* pSceneHandler = |
---|
| 660 | fpGraphicsSystem -> CreateSceneHandler (name); |
---|
| 661 | if (pSceneHandler) { |
---|
| 662 | fAvailableSceneHandlers.push_back (pSceneHandler); |
---|
| 663 | fpSceneHandler = pSceneHandler; // Make current. |
---|
| 664 | } |
---|
| 665 | else { |
---|
| 666 | if(fVerbosity >= errors) { |
---|
| 667 | G4cout << "ERROR in G4VisManager::CreateSceneHandler during " |
---|
| 668 | << fpGraphicsSystem -> GetName () |
---|
[1140] | 669 | << " scene handler creation.\n No action taken." |
---|
[531] | 670 | << G4endl; |
---|
| 671 | } |
---|
| 672 | } |
---|
| 673 | } |
---|
| 674 | else PrintInvalidPointers (); |
---|
| 675 | } |
---|
| 676 | |
---|
[896] | 677 | void G4VisManager::CreateViewer (G4String name,G4String XGeometry) { |
---|
[531] | 678 | |
---|
| 679 | if (!fInitialised) Initialise (); |
---|
| 680 | |
---|
[1140] | 681 | if (!fpSceneHandler) { |
---|
| 682 | PrintInvalidPointers (); |
---|
| 683 | return; |
---|
| 684 | } |
---|
[896] | 685 | |
---|
[1140] | 686 | G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name); |
---|
| 687 | |
---|
| 688 | if (!p) { |
---|
| 689 | if (fVerbosity >= errors) { |
---|
| 690 | G4cout << "ERROR in G4VisManager::CreateViewer during " |
---|
| 691 | << fpGraphicsSystem -> GetName () |
---|
| 692 | << " viewer creation.\n No action taken." |
---|
| 693 | << G4endl; |
---|
| 694 | } |
---|
| 695 | return; |
---|
| 696 | } |
---|
| 697 | |
---|
| 698 | if (p -> GetViewId() < 0) { |
---|
| 699 | if (fVerbosity >= errors) { |
---|
| 700 | G4cout << "ERROR in G4VisManager::CreateViewer during " |
---|
| 701 | << fpGraphicsSystem -> GetName () |
---|
| 702 | << " viewer initialisation.\n No action taken." |
---|
| 703 | << G4endl; |
---|
| 704 | } |
---|
| 705 | return; |
---|
| 706 | } |
---|
| 707 | |
---|
| 708 | // Viewer is created, now we can set geometry parameters |
---|
| 709 | // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there! |
---|
[897] | 710 | |
---|
[1140] | 711 | G4ViewParameters initialvp = p -> GetViewParameters(); |
---|
| 712 | initialvp.SetXGeometryString(XGeometry); //parse string and store parameters |
---|
| 713 | p -> SetViewParameters(initialvp); |
---|
| 714 | p -> Initialise (); // (Viewer itself may change view parameters further.) |
---|
[1136] | 715 | |
---|
[1140] | 716 | fpViewer = p; // Make current. |
---|
| 717 | fpSceneHandler -> AddViewerToList (fpViewer); |
---|
| 718 | fpSceneHandler -> SetCurrentViewer (fpViewer); |
---|
| 719 | if (fVerbosity >= confirmations) { |
---|
| 720 | G4cout << "G4VisManager::CreateViewer: new viewer created." |
---|
| 721 | << G4endl; |
---|
| 722 | } |
---|
[531] | 723 | |
---|
[1140] | 724 | const G4ViewParameters& vp = fpViewer->GetViewParameters(); |
---|
| 725 | if (fVerbosity >= parameters) { |
---|
| 726 | G4cout << " view parameters are:\n " << vp << G4endl; |
---|
| 727 | } |
---|
[593] | 728 | |
---|
[1140] | 729 | if (vp.IsCulling () && vp.IsCullingInvisible ()) { |
---|
| 730 | static G4bool warned = false; |
---|
| 731 | if (fVerbosity >= confirmations) { |
---|
| 732 | if (!warned) { |
---|
| 733 | G4cout << |
---|
[593] | 734 | "NOTE: objects with visibility flag set to \"false\"" |
---|
| 735 | " will not be drawn!" |
---|
| 736 | "\n \"/vis/viewer/set/culling global false\" to Draw such objects." |
---|
| 737 | "\n Also see other \"/vis/viewer/set\" commands." |
---|
[1140] | 738 | << G4endl; |
---|
| 739 | warned = true; |
---|
| 740 | } |
---|
| 741 | } |
---|
| 742 | } |
---|
| 743 | if (vp.IsCullingCovered ()) { |
---|
| 744 | static G4bool warned = false; |
---|
| 745 | if (fVerbosity >= warnings) { |
---|
| 746 | if (!warned) { |
---|
| 747 | G4cout << |
---|
[593] | 748 | "WARNING: covered objects in solid mode will not be rendered!" |
---|
| 749 | "\n \"/vis/viewer/set/culling coveredDaughters false\" to reverse this." |
---|
| 750 | "\n Also see other \"/vis/viewer/set\" commands." |
---|
[1140] | 751 | << G4endl; |
---|
| 752 | warned = true; |
---|
[531] | 753 | } |
---|
| 754 | } |
---|
| 755 | } |
---|
| 756 | } |
---|
| 757 | |
---|
| 758 | void G4VisManager::GeometryHasChanged () { |
---|
| 759 | if (fVerbosity >= confirmations) { |
---|
| 760 | G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl; |
---|
| 761 | } |
---|
| 762 | |
---|
| 763 | // Change the world... |
---|
| 764 | G4VPhysicalVolume* pWorld = |
---|
| 765 | G4TransportationManager::GetTransportationManager () |
---|
| 766 | -> GetNavigatorForTracking () -> GetWorldVolume (); |
---|
| 767 | if (!pWorld) { |
---|
| 768 | if (fVerbosity >= warnings) { |
---|
| 769 | G4cout << "WARNING: There is no world volume!" << G4endl; |
---|
| 770 | } |
---|
| 771 | } |
---|
| 772 | |
---|
| 773 | // Check scenes. |
---|
| 774 | G4SceneList& sceneList = fSceneList; |
---|
| 775 | G4int iScene, nScenes = sceneList.size (); |
---|
| 776 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 777 | G4Scene* pScene = sceneList [iScene]; |
---|
| 778 | std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList (); |
---|
| 779 | |
---|
| 780 | if (modelList.size ()) { |
---|
| 781 | G4bool modelInvalid; |
---|
| 782 | do { // Remove, if required, one at a time. |
---|
| 783 | modelInvalid = false; |
---|
| 784 | std::vector<G4VModel*>::iterator iterModel; |
---|
| 785 | for (iterModel = modelList.begin(); |
---|
| 786 | iterModel != modelList.end(); |
---|
| 787 | ++iterModel) { |
---|
| 788 | modelInvalid = !((*iterModel) -> Validate (fVerbosity >= warnings)); |
---|
| 789 | if (modelInvalid) { |
---|
| 790 | // Model invalid - remove and break. |
---|
| 791 | if (fVerbosity >= warnings) { |
---|
| 792 | G4cout << "WARNING: Model \"" |
---|
| 793 | << (*iterModel) -> GetGlobalDescription () |
---|
| 794 | << |
---|
| 795 | "\" is no longer valid - being removed\n from scene \"" |
---|
| 796 | << pScene -> GetName () << "\"" |
---|
| 797 | << G4endl; |
---|
| 798 | } |
---|
| 799 | modelList.erase (iterModel); |
---|
| 800 | break; |
---|
| 801 | } |
---|
| 802 | } |
---|
| 803 | } while (modelInvalid); |
---|
| 804 | |
---|
| 805 | if (modelList.size () == 0) { |
---|
| 806 | if (fVerbosity >= warnings) { |
---|
| 807 | G4cout << "WARNING: No models left in this scene \"" |
---|
| 808 | << pScene -> GetName () |
---|
| 809 | << "\"." |
---|
| 810 | << G4endl; |
---|
| 811 | } |
---|
| 812 | } |
---|
| 813 | else { |
---|
| 814 | pScene->CalculateExtent(); |
---|
| 815 | G4UImanager::GetUIpointer () -> |
---|
| 816 | ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName())); |
---|
| 817 | } |
---|
| 818 | } |
---|
| 819 | } |
---|
| 820 | |
---|
| 821 | // Check the manager's current scene... |
---|
| 822 | if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) { |
---|
| 823 | if (fVerbosity >= warnings) { |
---|
| 824 | G4cout << "WARNING: The current scene \"" |
---|
| 825 | << fpScene -> GetName () |
---|
| 826 | << "\" has no models." |
---|
| 827 | << G4endl; |
---|
| 828 | } |
---|
| 829 | } |
---|
| 830 | |
---|
[1241] | 831 | } |
---|
[933] | 832 | void G4VisManager::NotifyHandlers () { |
---|
[531] | 833 | |
---|
[933] | 834 | if (fVerbosity >= confirmations) { |
---|
| 835 | G4cout << "G4VisManager::NotifyHandler() called." << G4endl; |
---|
| 836 | } |
---|
| 837 | |
---|
| 838 | // Check scenes. |
---|
| 839 | G4SceneList& sceneList = fSceneList; |
---|
| 840 | G4int iScene, nScenes = sceneList.size (); |
---|
| 841 | for (iScene = 0; iScene < nScenes; iScene++) { |
---|
| 842 | G4Scene* pScene = sceneList [iScene]; |
---|
| 843 | std::vector<G4VModel*>& modelList = pScene -> SetRunDurationModelList (); |
---|
| 844 | |
---|
| 845 | if (modelList.size ()) { |
---|
| 846 | pScene->CalculateExtent(); |
---|
| 847 | G4UImanager::GetUIpointer () -> |
---|
| 848 | ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName())); |
---|
| 849 | } |
---|
| 850 | } |
---|
| 851 | |
---|
| 852 | // Check the manager's current scene... |
---|
| 853 | if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) { |
---|
| 854 | if (fVerbosity >= warnings) { |
---|
| 855 | G4cout << "WARNING: The current scene \"" |
---|
| 856 | << fpScene -> GetName () |
---|
| 857 | << "\" has no models." |
---|
| 858 | << G4endl; |
---|
| 859 | } |
---|
| 860 | } |
---|
| 861 | |
---|
| 862 | } |
---|
| 863 | |
---|
[531] | 864 | G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory) |
---|
| 865 | { |
---|
| 866 | return fpTrajFilterMgr->Accept(trajectory); |
---|
| 867 | } |
---|
| 868 | |
---|
| 869 | G4bool G4VisManager::FilterHit(const G4VHit& hit) |
---|
| 870 | { |
---|
| 871 | return fpHitFilterMgr->Accept(hit); |
---|
| 872 | } |
---|
| 873 | |
---|
| 874 | void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode) |
---|
| 875 | { |
---|
| 876 | G4bool visible(true); |
---|
| 877 | |
---|
| 878 | // See if trajectory passes filter |
---|
| 879 | G4bool passed = FilterTrajectory(trajectory); |
---|
| 880 | |
---|
| 881 | if (!passed) { |
---|
| 882 | // Draw invisible trajectory if trajectory failed filter and |
---|
| 883 | // are filtering in soft mode |
---|
| 884 | if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false; |
---|
| 885 | else {return;} |
---|
| 886 | } |
---|
| 887 | |
---|
| 888 | // Go on to draw trajectory |
---|
| 889 | assert (0 != fpTrajDrawModelMgr); |
---|
| 890 | |
---|
| 891 | const G4VTrajectoryModel* model = CurrentTrajDrawModel(); |
---|
| 892 | |
---|
| 893 | assert (0 != model); // Should exist |
---|
| 894 | |
---|
| 895 | model->Draw(trajectory, i_mode, visible); |
---|
| 896 | } |
---|
| 897 | |
---|
| 898 | void G4VisManager::SetUserAction |
---|
| 899 | (G4VUserVisAction* pVisAction, |
---|
| 900 | const G4VisExtent& extent) { |
---|
| 901 | fpUserVisAction = pVisAction; |
---|
| 902 | fUserVisActionExtent = extent; |
---|
| 903 | if (extent.GetExtentRadius() <= 0.) { |
---|
| 904 | if (fVerbosity >= warnings) { |
---|
| 905 | G4cout << |
---|
| 906 | "WARNING: No extent set for user vis action. (You may" |
---|
| 907 | "\n set it later when adding with /vis/scene/add/userAction.)" |
---|
| 908 | << G4endl; |
---|
| 909 | } |
---|
| 910 | } |
---|
| 911 | } |
---|
| 912 | |
---|
| 913 | void G4VisManager::SetCurrentScene (G4Scene* pScene) { |
---|
| 914 | if (pScene != fpScene) { |
---|
| 915 | // A change of scene. Therefore reset transients drawn flags. All |
---|
| 916 | // memory of previous transient proceessing thereby erased... |
---|
| 917 | ResetTransientsDrawnFlags(); |
---|
| 918 | } |
---|
| 919 | fpScene = pScene; |
---|
| 920 | } |
---|
| 921 | |
---|
| 922 | void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) { |
---|
| 923 | fpGraphicsSystem = pSystem; |
---|
| 924 | if (fVerbosity >= confirmations) { |
---|
| 925 | G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now " |
---|
| 926 | << pSystem -> GetName () << G4endl; |
---|
| 927 | } |
---|
| 928 | // If current scene handler is of same graphics system, leave unchanged. |
---|
| 929 | // Else find the most recent scene handler of same graphics system. |
---|
| 930 | // Or clear pointers. |
---|
| 931 | if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) { |
---|
| 932 | const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers; |
---|
| 933 | G4int nSH = sceneHandlerList.size (); // No. of scene handlers. |
---|
| 934 | G4int iSH; |
---|
| 935 | for (iSH = nSH - 1; iSH >= 0; iSH--) { |
---|
| 936 | if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break; |
---|
| 937 | } |
---|
| 938 | if (iSH >= 0) { |
---|
| 939 | fpSceneHandler = sceneHandlerList [iSH]; |
---|
| 940 | if (fVerbosity >= confirmations) { |
---|
| 941 | G4cout << " Scene Handler now " |
---|
| 942 | << fpSceneHandler -> GetName () << G4endl; |
---|
| 943 | } |
---|
| 944 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
| 945 | fpScene = fpSceneHandler -> GetScene (); |
---|
| 946 | if (fVerbosity >= confirmations) { |
---|
| 947 | G4cout << " Scene now \"" |
---|
| 948 | << fpScene -> GetName () << "\"" << G4endl; |
---|
| 949 | } |
---|
| 950 | } |
---|
| 951 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
| 952 | if (viewerList.size ()) { |
---|
| 953 | fpViewer = viewerList [0]; |
---|
| 954 | if (fVerbosity >= confirmations) { |
---|
| 955 | G4cout << " Viewer now " << fpViewer -> GetName () << G4endl; |
---|
| 956 | } |
---|
| 957 | } |
---|
| 958 | else { |
---|
| 959 | fpViewer = 0; |
---|
| 960 | } |
---|
| 961 | } |
---|
| 962 | else { |
---|
| 963 | fpSceneHandler = 0; |
---|
| 964 | fpViewer = 0; |
---|
| 965 | } |
---|
| 966 | } |
---|
| 967 | } |
---|
| 968 | |
---|
| 969 | void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) { |
---|
| 970 | fpSceneHandler = pSceneHandler; |
---|
| 971 | if (fVerbosity >= confirmations) { |
---|
| 972 | G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \"" |
---|
| 973 | << pSceneHandler -> GetName () << "\"" << G4endl; |
---|
| 974 | } |
---|
| 975 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
| 976 | fpScene = fpSceneHandler -> GetScene (); |
---|
| 977 | if (fVerbosity >= confirmations) { |
---|
| 978 | G4cout << " Scene now \"" |
---|
| 979 | << fpScene -> GetName () << "\"" << G4endl; |
---|
| 980 | } |
---|
| 981 | } |
---|
| 982 | if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) { |
---|
| 983 | fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem (); |
---|
| 984 | if (fVerbosity >= confirmations) { |
---|
| 985 | G4cout << " Graphics system now \"" |
---|
| 986 | << fpGraphicsSystem -> GetName () << "\"" << G4endl; |
---|
| 987 | } |
---|
| 988 | } |
---|
| 989 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
| 990 | G4int nViewers = viewerList.size (); |
---|
| 991 | if (nViewers) { |
---|
| 992 | G4int iViewer; |
---|
| 993 | for (iViewer = 0; iViewer < nViewers; iViewer++) { |
---|
| 994 | if (fpViewer == viewerList [iViewer]) break; |
---|
| 995 | } |
---|
| 996 | if (iViewer >= nViewers) { |
---|
| 997 | fpViewer = viewerList [0]; |
---|
| 998 | if (fVerbosity >= confirmations) { |
---|
| 999 | G4cout << " Viewer now \"" << fpViewer -> GetName () << "\"" |
---|
| 1000 | << G4endl; |
---|
| 1001 | } |
---|
| 1002 | } |
---|
| 1003 | IsValidView (); // Checks. |
---|
| 1004 | } |
---|
| 1005 | else { |
---|
| 1006 | fpViewer = 0; |
---|
| 1007 | if (fVerbosity >= warnings) { |
---|
| 1008 | G4cout << |
---|
| 1009 | "WARNING: No viewers for this scene handler - please create one." |
---|
| 1010 | << G4endl; |
---|
| 1011 | } |
---|
| 1012 | } |
---|
| 1013 | } |
---|
| 1014 | |
---|
| 1015 | void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) { |
---|
| 1016 | fpViewer = pViewer; |
---|
| 1017 | if (fVerbosity >= confirmations) { |
---|
| 1018 | G4cout << "G4VisManager::SetCurrentViewer: viewer now " |
---|
| 1019 | << pViewer -> GetName () |
---|
| 1020 | << G4endl; |
---|
| 1021 | } |
---|
| 1022 | fpSceneHandler = fpViewer -> GetSceneHandler (); |
---|
| 1023 | fpSceneHandler -> SetCurrentViewer (pViewer); |
---|
| 1024 | fpScene = fpSceneHandler -> GetScene (); |
---|
| 1025 | fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem (); |
---|
| 1026 | IsValidView (); // Checks. |
---|
| 1027 | } |
---|
| 1028 | |
---|
| 1029 | void G4VisManager::RegisterMessengers () { |
---|
| 1030 | |
---|
| 1031 | // Instantiate individual messengers/commands (often - but not |
---|
| 1032 | // always - one command per messenger). |
---|
| 1033 | |
---|
| 1034 | G4UIcommand* directory; |
---|
| 1035 | |
---|
[944] | 1036 | // Top level commands... |
---|
[593] | 1037 | RegisterMessenger(new G4VisCommandAbortReviewKeptEvents); |
---|
[531] | 1038 | RegisterMessenger(new G4VisCommandEnable); |
---|
| 1039 | RegisterMessenger(new G4VisCommandList); |
---|
| 1040 | RegisterMessenger(new G4VisCommandReviewKeptEvents); |
---|
| 1041 | |
---|
| 1042 | // Compound commands... |
---|
| 1043 | RegisterMessenger(new G4VisCommandDrawTree); |
---|
| 1044 | RegisterMessenger(new G4VisCommandDrawView); |
---|
| 1045 | RegisterMessenger(new G4VisCommandDrawVolume); |
---|
| 1046 | RegisterMessenger(new G4VisCommandOpen); |
---|
| 1047 | RegisterMessenger(new G4VisCommandSpecify); |
---|
| 1048 | |
---|
| 1049 | directory = new G4UIdirectory ("/vis/geometry/"); |
---|
| 1050 | directory -> SetGuidance("Operations on vis attributes of Geant4 geometry."); |
---|
| 1051 | fDirectoryList.push_back (directory); |
---|
| 1052 | RegisterMessenger(new G4VisCommandGeometryList); |
---|
| 1053 | RegisterMessenger(new G4VisCommandGeometryRestore); |
---|
| 1054 | |
---|
| 1055 | directory = new G4UIdirectory ("/vis/geometry/set/"); |
---|
| 1056 | directory -> SetGuidance("Set vis attributes of Geant4 geometry."); |
---|
| 1057 | fDirectoryList.push_back (directory); |
---|
| 1058 | RegisterMessenger(new G4VisCommandGeometrySetColour); |
---|
| 1059 | RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible); |
---|
| 1060 | RegisterMessenger(new G4VisCommandGeometrySetLineStyle); |
---|
| 1061 | RegisterMessenger(new G4VisCommandGeometrySetLineWidth); |
---|
| 1062 | RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible); |
---|
[593] | 1063 | RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle); |
---|
[531] | 1064 | RegisterMessenger(new G4VisCommandGeometrySetForceSolid); |
---|
| 1065 | RegisterMessenger(new G4VisCommandGeometrySetForceWireframe); |
---|
| 1066 | RegisterMessenger(new G4VisCommandGeometrySetVisibility); |
---|
| 1067 | |
---|
| 1068 | directory = new G4UIdirectory ("/vis/scene/"); |
---|
| 1069 | directory -> SetGuidance ("Operations on Geant4 scenes."); |
---|
| 1070 | fDirectoryList.push_back (directory); |
---|
| 1071 | RegisterMessenger(new G4VisCommandSceneCreate); |
---|
| 1072 | RegisterMessenger(new G4VisCommandSceneEndOfEventAction); |
---|
| 1073 | RegisterMessenger(new G4VisCommandSceneEndOfRunAction); |
---|
| 1074 | RegisterMessenger(new G4VisCommandSceneList); |
---|
| 1075 | RegisterMessenger(new G4VisCommandSceneNotifyHandlers); |
---|
| 1076 | RegisterMessenger(new G4VisCommandSceneSelect); |
---|
| 1077 | |
---|
| 1078 | directory = new G4UIdirectory ("/vis/scene/add/"); |
---|
| 1079 | directory -> SetGuidance ("Add model to current scene."); |
---|
| 1080 | fDirectoryList.push_back (directory); |
---|
| 1081 | RegisterMessenger(new G4VisCommandSceneAddAxes); |
---|
| 1082 | RegisterMessenger(new G4VisCommandSceneAddEventID); |
---|
| 1083 | RegisterMessenger(new G4VisCommandSceneAddGhosts); |
---|
| 1084 | RegisterMessenger(new G4VisCommandSceneAddHits); |
---|
| 1085 | RegisterMessenger(new G4VisCommandSceneAddLogicalVolume); |
---|
| 1086 | RegisterMessenger(new G4VisCommandSceneAddLogo); |
---|
[1140] | 1087 | RegisterMessenger(new G4VisCommandSceneAddPSHits); |
---|
[531] | 1088 | RegisterMessenger(new G4VisCommandSceneAddScale); |
---|
| 1089 | RegisterMessenger(new G4VisCommandSceneAddText); |
---|
| 1090 | RegisterMessenger(new G4VisCommandSceneAddTrajectories); |
---|
| 1091 | RegisterMessenger(new G4VisCommandSceneAddUserAction); |
---|
| 1092 | RegisterMessenger(new G4VisCommandSceneAddVolume); |
---|
| 1093 | |
---|
| 1094 | directory = new G4UIdirectory ("/vis/sceneHandler/"); |
---|
| 1095 | directory -> SetGuidance ("Operations on Geant4 scene handlers."); |
---|
| 1096 | fDirectoryList.push_back (directory); |
---|
| 1097 | RegisterMessenger(new G4VisCommandSceneHandlerAttach); |
---|
| 1098 | RegisterMessenger(new G4VisCommandSceneHandlerCreate); |
---|
| 1099 | RegisterMessenger(new G4VisCommandSceneHandlerList); |
---|
| 1100 | RegisterMessenger(new G4VisCommandSceneHandlerSelect); |
---|
| 1101 | |
---|
| 1102 | directory = new G4UIdirectory ("/vis/viewer/"); |
---|
| 1103 | directory -> SetGuidance ("Operations on Geant4 viewers."); |
---|
| 1104 | fDirectoryList.push_back (directory); |
---|
| 1105 | RegisterMessenger(new G4VisCommandViewerAddCutawayPlane); |
---|
| 1106 | RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane); |
---|
| 1107 | RegisterMessenger(new G4VisCommandViewerClear); |
---|
| 1108 | RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes); |
---|
| 1109 | RegisterMessenger(new G4VisCommandViewerClearTransients); |
---|
| 1110 | RegisterMessenger(new G4VisCommandViewerClone); |
---|
| 1111 | RegisterMessenger(new G4VisCommandViewerCreate); |
---|
| 1112 | RegisterMessenger(new G4VisCommandViewerDolly); |
---|
| 1113 | RegisterMessenger(new G4VisCommandViewerFlush); |
---|
| 1114 | RegisterMessenger(new G4VisCommandViewerList); |
---|
| 1115 | RegisterMessenger(new G4VisCommandViewerPan); |
---|
| 1116 | RegisterMessenger(new G4VisCommandViewerRebuild); |
---|
| 1117 | RegisterMessenger(new G4VisCommandViewerRefresh); |
---|
| 1118 | RegisterMessenger(new G4VisCommandViewerReset); |
---|
| 1119 | RegisterMessenger(new G4VisCommandViewerScale); |
---|
| 1120 | RegisterMessenger(new G4VisCommandViewerSelect); |
---|
| 1121 | RegisterMessenger(new G4VisCommandViewerUpdate); |
---|
| 1122 | RegisterMessenger(new G4VisCommandViewerZoom); |
---|
| 1123 | |
---|
| 1124 | directory = new G4UIdirectory ("/vis/viewer/set/"); |
---|
| 1125 | directory -> SetGuidance ("Set view parameters of current viewer."); |
---|
| 1126 | fDirectoryList.push_back (directory); |
---|
| 1127 | RegisterMessenger(new G4VisCommandsViewerSet); |
---|
| 1128 | |
---|
| 1129 | // List manager commands |
---|
| 1130 | RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> > |
---|
| 1131 | (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement())); |
---|
| 1132 | RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> > |
---|
| 1133 | (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement())); |
---|
| 1134 | |
---|
| 1135 | // Trajectory filter manager commands |
---|
| 1136 | RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> > |
---|
| 1137 | (fpTrajFilterMgr, fpTrajFilterMgr->Placement())); |
---|
| 1138 | RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> > |
---|
| 1139 | (fpTrajFilterMgr, fpTrajFilterMgr->Placement())); |
---|
| 1140 | |
---|
| 1141 | // Hit filter manager commands |
---|
| 1142 | RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> > |
---|
| 1143 | (fpHitFilterMgr, fpHitFilterMgr->Placement())); |
---|
| 1144 | RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> > |
---|
| 1145 | (fpHitFilterMgr, fpHitFilterMgr->Placement())); |
---|
| 1146 | } |
---|
| 1147 | |
---|
| 1148 | void G4VisManager::PrintAvailableGraphicsSystems () const { |
---|
| 1149 | G4int nSystems = fAvailableGraphicsSystems.size (); |
---|
| 1150 | G4cout << "Current available graphics systems are:"; |
---|
| 1151 | if (nSystems) { |
---|
| 1152 | for (int i = 0; i < nSystems; i++) { |
---|
| 1153 | const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems [i]; |
---|
| 1154 | G4cout << "\n " << pSystem -> GetName (); |
---|
| 1155 | if (pSystem -> GetNickname () != "") { |
---|
| 1156 | G4cout << " (" << pSystem -> GetNickname () << ")"; |
---|
| 1157 | } |
---|
| 1158 | } |
---|
| 1159 | } |
---|
| 1160 | else { |
---|
| 1161 | G4cout << "\n NONE!!! None registered - yet! Mmmmm!"; |
---|
| 1162 | } |
---|
| 1163 | G4cout << G4endl; |
---|
| 1164 | } |
---|
| 1165 | |
---|
| 1166 | void G4VisManager::PrintAvailableModels (Verbosity verbosity) const |
---|
| 1167 | { |
---|
| 1168 | { |
---|
| 1169 | //fpTrajDrawModelMgr->Print(G4cout); |
---|
| 1170 | G4cout << "Registered model factories:" << G4endl; |
---|
| 1171 | const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList = |
---|
| 1172 | fpTrajDrawModelMgr->FactoryList(); |
---|
| 1173 | if (factoryList.empty()) G4cout << " None" << G4endl; |
---|
| 1174 | else { |
---|
| 1175 | std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i; |
---|
| 1176 | for (i = factoryList.begin(); i != factoryList.end(); ++i) |
---|
| 1177 | (*i)->Print(G4cout); |
---|
| 1178 | } |
---|
| 1179 | const G4VisListManager<G4VTrajectoryModel>* listManager = |
---|
| 1180 | fpTrajDrawModelMgr->ListManager(); |
---|
| 1181 | const std::map<G4String, G4VTrajectoryModel*>& modelMap = |
---|
| 1182 | listManager->Map(); |
---|
| 1183 | if (!modelMap.empty()) { |
---|
| 1184 | G4cout << "\nRegistered models:" << G4endl; |
---|
| 1185 | std::map<G4String, G4VTrajectoryModel*>::const_iterator i; |
---|
| 1186 | for (i = modelMap.begin(); i != modelMap.end(); ++i) { |
---|
| 1187 | G4cout << " " << i->second->Name(); |
---|
| 1188 | if (i->second == listManager->Current()) G4cout << " (Current)"; |
---|
| 1189 | G4cout << G4endl; |
---|
| 1190 | if (verbosity >= parameters) i->second->Print(G4cout); |
---|
| 1191 | } |
---|
| 1192 | } |
---|
| 1193 | } |
---|
| 1194 | |
---|
| 1195 | G4cout << G4endl; |
---|
| 1196 | |
---|
| 1197 | { |
---|
| 1198 | //fpTrajFilterMgr->Print(G4cout); |
---|
| 1199 | G4cout << "Registered filter factories:" << G4endl; |
---|
| 1200 | const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>& |
---|
| 1201 | factoryList = fpTrajFilterMgr->FactoryList(); |
---|
| 1202 | if (factoryList.empty()) G4cout << " None" << G4endl; |
---|
| 1203 | else { |
---|
| 1204 | std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i; |
---|
| 1205 | for (i = factoryList.begin(); i != factoryList.end(); ++i) |
---|
| 1206 | (*i)->Print(G4cout); |
---|
| 1207 | } |
---|
| 1208 | const std::vector<G4VFilter<G4VTrajectory>*>& |
---|
| 1209 | filterList = fpTrajFilterMgr->FilterList(); |
---|
| 1210 | if (!filterList.empty()) { |
---|
| 1211 | G4cout << "\nRegistered filters:" << G4endl; |
---|
| 1212 | std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i; |
---|
| 1213 | for (i = filterList.begin(); i != filterList.end(); ++i) { |
---|
| 1214 | G4cout << " " << (*i)->GetName() << G4endl; |
---|
| 1215 | if (verbosity >= parameters) (*i)->PrintAll(G4cout); |
---|
| 1216 | } |
---|
| 1217 | } |
---|
| 1218 | } |
---|
| 1219 | } |
---|
| 1220 | |
---|
| 1221 | void G4VisManager::PrintInvalidPointers () const { |
---|
| 1222 | if (fVerbosity >= errors) { |
---|
| 1223 | G4cout << "ERROR: G4VisManager::PrintInvalidPointers:"; |
---|
| 1224 | if (!fpGraphicsSystem) { |
---|
| 1225 | G4cout << "\n null graphics system pointer."; |
---|
| 1226 | } |
---|
| 1227 | else { |
---|
| 1228 | G4cout << "\n Graphics system is " << fpGraphicsSystem -> GetName () |
---|
| 1229 | << " but:"; |
---|
| 1230 | if (!fpScene) |
---|
| 1231 | G4cout << |
---|
| 1232 | "\n Null scene pointer. Use \"/vis/drawVolume\" or" |
---|
| 1233 | " \"/vis/scene/create\"."; |
---|
| 1234 | if (!fpSceneHandler) |
---|
| 1235 | G4cout << |
---|
| 1236 | "\n Null scene handler pointer. Use \"/vis/open\" or" |
---|
| 1237 | " \"/vis/sceneHandler/create\"."; |
---|
| 1238 | if (!fpViewer ) |
---|
| 1239 | G4cout << |
---|
| 1240 | "\n Null viewer pointer. Use \"/vis/viewer/create\"."; |
---|
| 1241 | } |
---|
| 1242 | G4cout << G4endl; |
---|
| 1243 | } |
---|
| 1244 | } |
---|
| 1245 | |
---|
| 1246 | void G4VisManager::BeginOfRun () |
---|
| 1247 | { |
---|
[593] | 1248 | //G4cout << "G4VisManager::BeginOfRun" << G4endl; |
---|
[531] | 1249 | fKeptLastEvent = false; |
---|
| 1250 | fEventKeepingSuspended = false; |
---|
| 1251 | fTransientsDrawnThisRun = false; |
---|
| 1252 | if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false); |
---|
| 1253 | } |
---|
| 1254 | |
---|
| 1255 | void G4VisManager::BeginOfEvent () |
---|
| 1256 | { |
---|
[593] | 1257 | //G4cout << "G4VisManager::BeginOfEvent" << G4endl; |
---|
[531] | 1258 | fTransientsDrawnThisEvent = false; |
---|
| 1259 | if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false); |
---|
| 1260 | } |
---|
| 1261 | |
---|
| 1262 | void G4VisManager::EndOfEvent () |
---|
| 1263 | { |
---|
[593] | 1264 | //G4cout << "G4VisManager::EndOfEvent" << G4endl; |
---|
[531] | 1265 | |
---|
| 1266 | // Don't call IsValidView unless there is a scene handler. This |
---|
| 1267 | // avoids WARNING message at end of event and run when the user has |
---|
| 1268 | // not instantiated a scene handler, e.g., in batch mode. |
---|
| 1269 | G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView(); |
---|
| 1270 | if (!valid) return; |
---|
| 1271 | |
---|
| 1272 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 1273 | const G4Run* currentRun = runManager->GetCurrentRun(); |
---|
| 1274 | |
---|
[593] | 1275 | G4EventManager* eventManager = G4EventManager::GetEventManager(); |
---|
| 1276 | const G4Event* currentEvent = eventManager->GetConstCurrentEvent(); |
---|
[531] | 1277 | if (!currentEvent) return; |
---|
| 1278 | |
---|
| 1279 | ClearTransientStoreIfMarked(); |
---|
| 1280 | fpSceneHandler->DrawEvent(currentEvent); |
---|
| 1281 | |
---|
| 1282 | G4int nEventsToBeProcessed = 0; |
---|
| 1283 | G4int nKeptEvents = 0; |
---|
| 1284 | G4int eventID = -2; // (If no run manager, triggers ShowView as normal.) |
---|
| 1285 | if (currentRun) { |
---|
| 1286 | nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed(); |
---|
| 1287 | eventID = currentEvent->GetEventID(); |
---|
| 1288 | const std::vector<const G4Event*>* events = |
---|
| 1289 | currentRun->GetEventVector(); |
---|
| 1290 | if (events) nKeptEvents = events->size(); |
---|
| 1291 | } |
---|
[1170] | 1292 | |
---|
[531] | 1293 | if (fpScene->GetRefreshAtEndOfEvent()) { |
---|
| 1294 | |
---|
| 1295 | // Unless last event (in which case wait end of run)... |
---|
| 1296 | if (eventID < nEventsToBeProcessed - 1) { |
---|
| 1297 | fpViewer->ShowView(); |
---|
| 1298 | fpSceneHandler->SetMarkForClearingTransientStore(true); |
---|
| 1299 | } else { // Last event... |
---|
| 1300 | // Keep, but only if user has not kept any... |
---|
| 1301 | if (!nKeptEvents) { |
---|
[593] | 1302 | eventManager->KeepTheCurrentEvent(); |
---|
[531] | 1303 | fKeptLastEvent = true; |
---|
| 1304 | } |
---|
| 1305 | } |
---|
| 1306 | |
---|
| 1307 | } else { // Accumulating events... |
---|
| 1308 | |
---|
| 1309 | G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents(); |
---|
| 1310 | if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) { |
---|
| 1311 | fEventKeepingSuspended = true; |
---|
| 1312 | static G4bool warned = false; |
---|
| 1313 | if (!warned) { |
---|
| 1314 | if (fVerbosity >= warnings) { |
---|
| 1315 | G4cout << |
---|
[1140] | 1316 | "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended." |
---|
| 1317 | "\n The number of events exceeds the maximum, " |
---|
| 1318 | << maxNumberOfKeptEvents << |
---|
| 1319 | ", that can be kept by the vis manager." |
---|
[531] | 1320 | << G4endl; |
---|
| 1321 | } |
---|
| 1322 | warned = true; |
---|
| 1323 | } |
---|
| 1324 | } else if (maxNumberOfKeptEvents != 0) { |
---|
[593] | 1325 | eventManager->KeepTheCurrentEvent(); |
---|
[531] | 1326 | } |
---|
| 1327 | } |
---|
| 1328 | } |
---|
| 1329 | |
---|
| 1330 | void G4VisManager::EndOfRun () |
---|
| 1331 | { |
---|
[593] | 1332 | //G4cout << "G4VisManager::EndOfRun" << G4endl; |
---|
[1170] | 1333 | |
---|
[531] | 1334 | // Don't call IsValidView unless there is a scene handler. This |
---|
| 1335 | // avoids WARNING message at end of event and run when the user has |
---|
| 1336 | // not instantiated a scene handler, e.g., in batch mode. |
---|
| 1337 | G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView(); |
---|
| 1338 | if (valid) { |
---|
| 1339 | if (!fpSceneHandler->GetMarkForClearingTransientStore()) { |
---|
| 1340 | if (fpScene->GetRefreshAtEndOfRun()) { |
---|
[1170] | 1341 | fpSceneHandler->DrawEndOfRunModels(); |
---|
[531] | 1342 | fpViewer->ShowView(); |
---|
| 1343 | fpSceneHandler->SetMarkForClearingTransientStore(true); |
---|
| 1344 | } |
---|
| 1345 | } |
---|
| 1346 | |
---|
| 1347 | if (fEventKeepingSuspended && fVerbosity >= warnings) { |
---|
| 1348 | G4cout << |
---|
[1140] | 1349 | "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended." |
---|
| 1350 | "\n The number of events in the run exceeded the maximum, " |
---|
| 1351 | << fpScene->GetMaxNumberOfKeptEvents() << |
---|
| 1352 | ", that can be kept by the vis manager." << |
---|
| 1353 | "\n The number of events kept by the vis manager can be changed with" |
---|
| 1354 | "\n \"/vis/scene/endOfEventAction accumulate <N>\", where N is the" |
---|
| 1355 | "\n maximum number you wish to allow. N < 0 means \"unlimited\"." |
---|
[531] | 1356 | << G4endl; |
---|
| 1357 | } |
---|
| 1358 | } |
---|
| 1359 | fEventRefreshing = false; |
---|
| 1360 | |
---|
| 1361 | G4RunManager* runManager = G4RunManager::GetRunManager(); |
---|
| 1362 | const G4Run* currentRun = runManager->GetCurrentRun(); |
---|
| 1363 | |
---|
| 1364 | G4int nKeptEvents = 0; |
---|
| 1365 | const std::vector<const G4Event*>* events = |
---|
| 1366 | currentRun? currentRun->GetEventVector(): 0; |
---|
| 1367 | if (events) nKeptEvents = events->size(); |
---|
| 1368 | |
---|
| 1369 | if (nKeptEvents && !fKeptLastEvent) { |
---|
| 1370 | if (!valid && fVerbosity >= warnings) G4cout << "WARNING: "; |
---|
| 1371 | if (fVerbosity >= warnings) { |
---|
| 1372 | G4cout << nKeptEvents; |
---|
| 1373 | if (nKeptEvents == 1) G4cout << " event has"; |
---|
| 1374 | else G4cout << " events have"; |
---|
| 1375 | G4cout << " been kept for refreshing and/or reviewing." << G4endl; |
---|
| 1376 | } |
---|
| 1377 | static G4bool warned = false; |
---|
| 1378 | if (!valid && fVerbosity >= warnings && !warned) { |
---|
| 1379 | G4cout << |
---|
| 1380 | " Only useful if before starting the run:" |
---|
[606] | 1381 | "\n a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or" |
---|
[531] | 1382 | "\n b) the Draw method of any hits is implemented." |
---|
| 1383 | "\n To view trajectories and hits:" |
---|
| 1384 | "\n open a viewer, draw a volume, \"/vis/scene/add/trajectories\"" |
---|
| 1385 | "\n \"/vis/scene/add/hits\" and, possibly, \"/vis/viewer/flush\"." |
---|
[606] | 1386 | "\n To see all events: \"/vis/scene/endOfEventAction accumulate\"." |
---|
[531] | 1387 | "\n To see events individually: \"/vis/reviewKeptEvents\"." |
---|
| 1388 | << G4endl; |
---|
| 1389 | warned = true; |
---|
| 1390 | } |
---|
| 1391 | } |
---|
| 1392 | } |
---|
| 1393 | |
---|
| 1394 | void G4VisManager::ClearTransientStoreIfMarked(){ |
---|
| 1395 | // Assumes valid view. |
---|
| 1396 | if (fpSceneHandler->GetMarkForClearingTransientStore()) { |
---|
| 1397 | fpSceneHandler->SetMarkForClearingTransientStore(false); |
---|
| 1398 | fpSceneHandler->ClearTransientStore(); |
---|
| 1399 | } |
---|
| 1400 | // Record if transients drawn. These local flags are only set |
---|
| 1401 | // *after* ClearTransientStore. In the code in G4VSceneHandler |
---|
| 1402 | // triggered by ClearTransientStore, use these flags so that |
---|
| 1403 | // event refreshing is not done too early. |
---|
| 1404 | fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent(); |
---|
| 1405 | fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun(); |
---|
| 1406 | } |
---|
| 1407 | |
---|
| 1408 | void G4VisManager::ResetTransientsDrawnFlags() |
---|
| 1409 | { |
---|
| 1410 | fTransientsDrawnThisRun = false; |
---|
| 1411 | fTransientsDrawnThisEvent = false; |
---|
| 1412 | G4SceneHandlerListConstIterator i; |
---|
| 1413 | for (i = fAvailableSceneHandlers.begin(); |
---|
| 1414 | i != fAvailableSceneHandlers.end(); ++i) { |
---|
| 1415 | (*i)->SetTransientsDrawnThisEvent(false); |
---|
| 1416 | (*i)->SetTransientsDrawnThisRun(false); |
---|
| 1417 | } |
---|
| 1418 | } |
---|
| 1419 | |
---|
| 1420 | G4String G4VisManager::ViewerShortName (const G4String& viewerName) const { |
---|
| 1421 | G4String viewerShortName (viewerName); |
---|
| 1422 | viewerShortName = viewerShortName (0, viewerShortName.find (' ')); |
---|
| 1423 | return viewerShortName.strip (); |
---|
| 1424 | } |
---|
| 1425 | |
---|
| 1426 | G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const { |
---|
| 1427 | G4String viewerShortName = ViewerShortName (viewerName); |
---|
| 1428 | size_t nHandlers = fAvailableSceneHandlers.size (); |
---|
| 1429 | size_t iHandler, iViewer; |
---|
| 1430 | G4VViewer* viewer = 0; |
---|
| 1431 | G4bool found = false; |
---|
| 1432 | for (iHandler = 0; iHandler < nHandlers; iHandler++) { |
---|
| 1433 | G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler]; |
---|
| 1434 | const G4ViewerList& viewerList = sceneHandler -> GetViewerList (); |
---|
| 1435 | for (iViewer = 0; iViewer < viewerList.size (); iViewer++) { |
---|
| 1436 | viewer = viewerList [iViewer]; |
---|
| 1437 | if (viewerShortName == viewer -> GetShortName ()) { |
---|
| 1438 | found = true; |
---|
| 1439 | break; |
---|
| 1440 | } |
---|
| 1441 | } |
---|
| 1442 | if (found) break; |
---|
| 1443 | } |
---|
| 1444 | if (found) return viewer; |
---|
| 1445 | else return 0; |
---|
| 1446 | } |
---|
| 1447 | |
---|
| 1448 | std::vector<G4String> G4VisManager::VerbosityGuidanceStrings; |
---|
| 1449 | |
---|
| 1450 | G4String G4VisManager::VerbosityString(Verbosity verbosity) { |
---|
| 1451 | G4String s; |
---|
| 1452 | switch (verbosity) { |
---|
| 1453 | case quiet: s = "quiet (0)"; break; |
---|
| 1454 | case startup: s = "startup (1)"; break; |
---|
| 1455 | case errors: s = "errors (2)"; break; |
---|
| 1456 | case warnings: s = "warnings (3)"; break; |
---|
| 1457 | case confirmations: s = "confirmations (4)"; break; |
---|
| 1458 | case parameters: s = "parameters (5)"; break; |
---|
| 1459 | case all: s = "all (6)"; break; |
---|
| 1460 | } |
---|
| 1461 | return s; |
---|
| 1462 | } |
---|
| 1463 | |
---|
| 1464 | G4VisManager::Verbosity |
---|
| 1465 | G4VisManager::GetVerbosityValue(const G4String& verbosityString) { |
---|
| 1466 | G4String s(verbosityString); s.toLower(); |
---|
| 1467 | Verbosity verbosity; |
---|
| 1468 | if (s(0) == 'q') verbosity = quiet; |
---|
| 1469 | else if (s(0) == 's') verbosity = startup; |
---|
| 1470 | else if (s(0) == 'e') verbosity = errors; |
---|
| 1471 | else if (s(0) == 'w') verbosity = warnings; |
---|
| 1472 | else if (s(0) == 'c') verbosity = confirmations; |
---|
| 1473 | else if (s(0) == 'p') verbosity = parameters; |
---|
| 1474 | else if (s(0) == 'a') verbosity = all; |
---|
| 1475 | else { |
---|
| 1476 | G4int intVerbosity; |
---|
| 1477 | std::istringstream is(s); |
---|
| 1478 | is >> intVerbosity; |
---|
| 1479 | if (!is) { |
---|
| 1480 | G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \"" |
---|
| 1481 | << verbosityString << "\""; |
---|
| 1482 | for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) { |
---|
| 1483 | G4cout << '\n' << VerbosityGuidanceStrings[i]; |
---|
| 1484 | } |
---|
| 1485 | verbosity = warnings; |
---|
| 1486 | G4cout << "\n Returning " << VerbosityString(verbosity) |
---|
| 1487 | << G4endl; |
---|
| 1488 | } |
---|
| 1489 | else { |
---|
| 1490 | verbosity = GetVerbosityValue(intVerbosity); |
---|
| 1491 | } |
---|
| 1492 | } |
---|
| 1493 | return verbosity; |
---|
| 1494 | } |
---|
| 1495 | |
---|
| 1496 | G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) { |
---|
| 1497 | Verbosity verbosity; |
---|
| 1498 | if (intVerbosity < quiet) verbosity = quiet; |
---|
| 1499 | else if (intVerbosity > all) verbosity = all; |
---|
| 1500 | else verbosity = Verbosity(intVerbosity); |
---|
| 1501 | return verbosity; |
---|
| 1502 | } |
---|
| 1503 | |
---|
| 1504 | void G4VisManager::SetVerboseLevel (G4int intVerbosity) { |
---|
| 1505 | fVerbosity = GetVerbosityValue(intVerbosity); |
---|
| 1506 | } |
---|
| 1507 | |
---|
| 1508 | void G4VisManager::SetVerboseLevel (const G4String& verbosityString) { |
---|
| 1509 | fVerbosity = GetVerbosityValue(verbosityString); |
---|
| 1510 | } |
---|
| 1511 | |
---|
| 1512 | G4bool G4VisManager::IsValidView () { |
---|
| 1513 | |
---|
| 1514 | if (!fInitialised) Initialise (); |
---|
| 1515 | |
---|
| 1516 | static G4bool noGSPrinting = true; |
---|
| 1517 | if (!fpGraphicsSystem) { |
---|
| 1518 | // Limit printing - we do not want printing if the user simply does |
---|
| 1519 | // not want to use graphics, e.g., in batch mode. |
---|
| 1520 | if (noGSPrinting) { |
---|
| 1521 | noGSPrinting = false; |
---|
| 1522 | if (fVerbosity >= warnings) { |
---|
| 1523 | G4cout << |
---|
| 1524 | "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system" |
---|
| 1525 | "\n has been instantiated. Use \"/vis/open\" or \"/vis/sceneHandler/create\"." |
---|
| 1526 | "\n Alternatively, to avoid this message, suppress instantiation of vis" |
---|
| 1527 | "\n manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure" |
---|
| 1528 | "\n drawing code is executed only if G4VVisManager::GetConcreteInstance()" |
---|
| 1529 | "\n is non-zero." |
---|
| 1530 | << G4endl; |
---|
| 1531 | } |
---|
| 1532 | } |
---|
| 1533 | return false; |
---|
| 1534 | } |
---|
| 1535 | |
---|
| 1536 | if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) { |
---|
| 1537 | if (fVerbosity >= errors) { |
---|
| 1538 | G4cout << |
---|
| 1539 | "ERROR: G4VisManager::IsValidView(): Current view is not valid." |
---|
| 1540 | << G4endl; |
---|
| 1541 | PrintInvalidPointers (); |
---|
| 1542 | } |
---|
| 1543 | return false; |
---|
| 1544 | } |
---|
| 1545 | |
---|
| 1546 | if (fpScene != fpSceneHandler -> GetScene ()) { |
---|
| 1547 | if (fVerbosity >= errors) { |
---|
| 1548 | G4cout << "ERROR: G4VisManager::IsValidView ():"; |
---|
| 1549 | if (fpSceneHandler -> GetScene ()) { |
---|
| 1550 | G4cout << |
---|
| 1551 | "\n The current scene \"" |
---|
| 1552 | << fpScene -> GetName () |
---|
| 1553 | << "\" is not handled by" |
---|
| 1554 | "\n the current scene handler \"" |
---|
| 1555 | << fpSceneHandler -> GetName () |
---|
| 1556 | << "\"" |
---|
| 1557 | "\n (it currently handles scene \"" |
---|
| 1558 | << fpSceneHandler -> GetScene () -> GetName () |
---|
| 1559 | << "\")." |
---|
| 1560 | "\n Either:" |
---|
| 1561 | "\n (a) attach it to the scene handler with" |
---|
| 1562 | "\n /vis/sceneHandler/attach " |
---|
| 1563 | << fpScene -> GetName () |
---|
| 1564 | << ", or" |
---|
| 1565 | "\n (b) create a new scene handler with " |
---|
| 1566 | "\n /vis/sceneHandler/create <graphics-system>," |
---|
| 1567 | "\n in which case it should pick up the the new scene." |
---|
| 1568 | << G4endl; |
---|
| 1569 | } |
---|
| 1570 | else { |
---|
| 1571 | G4cout << "\n Scene handler \"" |
---|
| 1572 | << fpSceneHandler -> GetName () |
---|
| 1573 | << "\" has null scene pointer." |
---|
| 1574 | "\n Attach a scene with /vis/sceneHandler/attach [<scene-name>]" |
---|
| 1575 | << G4endl; |
---|
| 1576 | } |
---|
| 1577 | } |
---|
| 1578 | return false; |
---|
| 1579 | } |
---|
| 1580 | |
---|
| 1581 | const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList (); |
---|
| 1582 | if (viewerList.size () == 0) { |
---|
| 1583 | if (fVerbosity >= errors) { |
---|
| 1584 | G4cout << |
---|
| 1585 | "ERROR: G4VisManager::IsValidView (): the current scene handler\n \"" |
---|
| 1586 | << fpSceneHandler -> GetName () |
---|
| 1587 | << "\" has no viewers. Do /vis/viewer/create." |
---|
| 1588 | << G4endl; |
---|
| 1589 | } |
---|
| 1590 | return false; |
---|
| 1591 | } |
---|
| 1592 | |
---|
| 1593 | G4bool isValid = true; |
---|
| 1594 | if (fpScene -> IsEmpty ()) { // Add world by default if possible... |
---|
| 1595 | G4bool warn(fVerbosity >= warnings); |
---|
| 1596 | G4bool successful = fpScene -> AddWorldIfEmpty (warn); |
---|
| 1597 | if (!successful || fpScene -> IsEmpty ()) { // If still empty... |
---|
| 1598 | if (fVerbosity >= errors) { |
---|
| 1599 | G4cout << "ERROR: G4VisManager::IsViewValid ():"; |
---|
| 1600 | G4cout << |
---|
| 1601 | "\n Attempt at some drawing operation when scene is empty." |
---|
| 1602 | "\n Maybe the geometry has not yet been defined." |
---|
| 1603 | " Try /run/initialize." |
---|
| 1604 | << G4endl; |
---|
| 1605 | } |
---|
| 1606 | isValid = false; |
---|
| 1607 | } |
---|
| 1608 | else { |
---|
| 1609 | G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers"); |
---|
| 1610 | if (fVerbosity >= warnings) { |
---|
| 1611 | G4cout << |
---|
| 1612 | "WARNING: G4VisManager: the scene was empty, \"world\" has been" |
---|
| 1613 | "\n added and the scene handlers notified."; |
---|
| 1614 | G4cout << G4endl; |
---|
| 1615 | } |
---|
| 1616 | } |
---|
| 1617 | } |
---|
| 1618 | if (isValid) SetConcreteInstance(this); |
---|
| 1619 | return isValid; |
---|
| 1620 | } |
---|
| 1621 | |
---|
| 1622 | void |
---|
| 1623 | G4VisManager::RegisterModelFactories() |
---|
| 1624 | { |
---|
| 1625 | if (fVerbosity >= warnings) { |
---|
| 1626 | G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl; |
---|
| 1627 | G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl; |
---|
| 1628 | G4cout<<"class. See G4VisExecutive for an example."<<G4endl; |
---|
| 1629 | } |
---|
| 1630 | } |
---|