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