G4VisManager.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // 
00029 // GEANT4 Visualization Manager - John Allison 02/Jan/1996.
00030 
00031 #include "G4VisManager.hh"
00032 
00033 #include "G4VisCommands.hh"
00034 #include "G4VisCommandsCompound.hh"
00035 #include "G4VisCommandsGeometry.hh"
00036 #include "G4VisCommandsGeometrySet.hh"
00037 #include "G4VisCommandsSet.hh"
00038 #include "G4VisCommandsScene.hh"
00039 #include "G4VisCommandsSceneAdd.hh"
00040 #include "G4VisCommandsSceneHandler.hh"
00041 #include "G4VisCommandsTouchableSet.hh"
00042 #include "G4VisCommandsViewer.hh"
00043 #include "G4VisCommandsViewerDefault.hh"
00044 #include "G4VisCommandsViewerSet.hh"
00045 #include "G4UImanager.hh"
00046 #include "G4VisStateDependent.hh"
00047 #include "G4UIdirectory.hh"
00048 #include "G4VGraphicsSystem.hh"
00049 #include "G4VSceneHandler.hh"
00050 #include "G4VViewer.hh"
00051 #include "G4VPhysicalVolume.hh"
00052 #include "G4LogicalVolume.hh"
00053 #include "G4VSolid.hh"
00054 #include "G4Vector3D.hh"
00055 #include "G4Point3D.hh"
00056 #include "G4RotationMatrix.hh"
00057 #include "G4Polyline.hh"
00058 #include "G4Polyhedron.hh"
00059 #include "G4NURBS.hh"
00060 #include "G4NullModel.hh"
00061 #include "G4ModelingParameters.hh"
00062 #include "G4TransportationManager.hh"
00063 #include "G4VisCommandModelCreate.hh"
00064 #include "G4VisCommandsListManager.hh"
00065 #include "G4VisModelManager.hh"
00066 #include "G4VModelFactory.hh"
00067 #include "G4VisFilterManager.hh"
00068 #include "G4VTrajectoryModel.hh"
00069 #include "G4TrajectoryDrawByCharge.hh"
00070 #include "Randomize.hh"
00071 #include "G4RunManager.hh"
00072 #include "G4EventManager.hh"
00073 #include "G4Run.hh"
00074 #include "G4Event.hh"
00075 #include <map>
00076 #include <set>
00077 #include <vector>
00078 #include <sstream>
00079 
00080 G4VisManager* G4VisManager::fpInstance = 0;
00081 
00082 G4VisManager::Verbosity G4VisManager::fVerbosity = G4VisManager::warnings;
00083 
00084 G4VisManager::G4VisManager (const G4String& verbosityString):
00085   fVerbose         (1),
00086   fInitialised     (false),
00087   fpGraphicsSystem (0),
00088   fpScene          (0),
00089   fpSceneHandler   (0),
00090   fpViewer         (0),
00091   fpStateDependent (0),
00092   fEventRefreshing          (false),
00093   fTransientsDrawnThisRun   (false),
00094   fTransientsDrawnThisEvent (false),
00095   fEventKeepingSuspended    (false),
00096   fKeptLastEvent            (false),
00097   fpRequestedEvent (0),
00098   fAbortReviewKeptEvents    (false),
00099   fIsDrawGroup              (false),
00100   fDrawGroupNestingDepth    (0)
00101   // All other objects use default constructors.
00102 {
00103   fpTrajDrawModelMgr = new G4VisModelManager<G4VTrajectoryModel>("/vis/modeling/trajectories");
00104   fpTrajFilterMgr = new G4VisFilterManager<G4VTrajectory>("/vis/filtering/trajectories");
00105   fpHitFilterMgr = new G4VisFilterManager<G4VHit>("/vis/filtering/hits");
00106   fpDigiFilterMgr = new G4VisFilterManager<G4VDigi>("/vis/filtering/digi");
00107 
00108   VerbosityGuidanceStrings.push_back
00109     ("Simple graded message scheme - digit or string (1st character defines):");
00110   VerbosityGuidanceStrings.push_back
00111     ("  0) quiet,         // Nothing is printed.");
00112   VerbosityGuidanceStrings.push_back
00113     ("  1) startup,       // Startup and endup messages are printed...");
00114   VerbosityGuidanceStrings.push_back
00115     ("  2) errors,        // ...and errors...");
00116   VerbosityGuidanceStrings.push_back
00117     ("  3) warnings,      // ...and warnings...");
00118   VerbosityGuidanceStrings.push_back
00119     ("  4) confirmations, // ...and confirming messages...");
00120   VerbosityGuidanceStrings.push_back
00121     ("  5) parameters,    // ...and parameters of scenes and views...");
00122   VerbosityGuidanceStrings.push_back
00123     ("  6) all            // ...and everything available.");
00124 
00125   if (fpInstance) {
00126     G4Exception
00127       ("G4VisManager::G4VisManager",
00128        "visman0001", FatalException,
00129        "Attempt to Construct more than one VisManager");
00130   }
00131 
00132   fpInstance = this;
00133   SetConcreteInstance(this);
00134 
00135   fpStateDependent = new G4VisStateDependent (this);
00136   // No need to delete this; G4StateManager does this.
00137 
00138   fVerbosity = GetVerbosityValue(verbosityString);
00139   if (fVerbosity >= startup) {
00140       G4cout
00141         << "Visualization Manager instantiating with verbosity \""
00142         << VerbosityString(fVerbosity)
00143         << "\"..." << G4endl;
00144   }
00145 
00146   // Note: The specific graphics systems must be instantiated in a
00147   // higher level library to avoid circular dependencies.  Also,
00148   // some specifically need additional external libararies that the
00149   // user must supply.  Therefore we ask the user to implement
00150   // RegisterGraphicsSystems() and RegisterModelFactories()
00151   // in a subclass.  We have to wait for the subclass to instantiate
00152   // so RegisterGraphicsSystems() cannot be called from this
00153   // constructor; it is called from Initialise().  So we ask the
00154   // user:
00155   //   (a) to write a subclass and implement  RegisterGraphicsSystems()
00156   //       and RegisterModelFactories().  See
00157   //       visualization/include/G4VisExecutive.hh/icc as an example.
00158   //   (b) instantiate the subclass.
00159   //   (c) invoke the Initialise() method of the subclass.
00160   // For example:
00161   //   ...
00162   // #ifdef G4VIS_USE
00163   //   // Instantiate and initialise Visualization Manager.
00164   //   G4VisManager* visManager = new G4VisExecutive;
00165   //   visManager -> SetVerboseLevel (Verbose);
00166   //   visManager -> Initialise ();
00167   // #endif
00168   //   // (Don't forget to delete visManager;)
00169   //   ...
00170 
00171   // Make top level command directory...
00172   G4UIcommand* directory;
00173   directory = new G4UIdirectory ("/vis/");
00174   directory -> SetGuidance ("Visualization commands.");
00175   fDirectoryList.push_back (directory);
00176 
00177   // Instantiate *basic* top level commands so that they can be used
00178   // immediately after instantiation of the vis manager.  Other top
00179   // level and lower level commands are instantiated later in
00180   // RegisterMessengers.
00181   G4VVisCommand::SetVisManager (this);  // Sets shared pointer
00182   RegisterMessenger(new G4VisCommandVerbose);
00183   RegisterMessenger(new G4VisCommandInitialize);
00184 }
00185 
00186 G4VisManager::~G4VisManager () {
00187   fpInstance = 0;
00188   size_t i;
00189   for (i = 0; i < fSceneList.size (); ++i) {
00190     delete fSceneList[i];
00191   }
00192   for (i = 0; i < fAvailableSceneHandlers.size (); ++i) {
00193   if (fAvailableSceneHandlers[i] != NULL) {
00194     delete fAvailableSceneHandlers[i];
00195   }
00196   }
00197   for (i = 0; i < fAvailableGraphicsSystems.size (); ++i) {
00198     if (fAvailableGraphicsSystems[i]) {
00199       delete fAvailableGraphicsSystems[i];
00200     }
00201   }
00202   if (fVerbosity >= startup) {
00203     G4cout << "Graphics systems deleted." << G4endl;
00204     G4cout << "Visualization Manager deleting..." << G4endl;
00205   }
00206   for (i = 0; i < fMessengerList.size (); ++i) {
00207     delete fMessengerList[i];
00208   }
00209   for (i = 0; i < fDirectoryList.size (); ++i) {
00210     delete fDirectoryList[i];
00211   }
00212 
00213   delete fpDigiFilterMgr;
00214   delete fpHitFilterMgr;
00215   delete fpTrajFilterMgr;
00216   delete fpTrajDrawModelMgr;
00217 }
00218 
00219 G4VisManager* G4VisManager::GetInstance () {
00220   if (!fpInstance) {
00221     G4Exception
00222       ("G4VisManager::GetInstance",
00223        "visman0002", FatalException, "VisManager not yet instantiated");
00224   }
00225   return fpInstance;
00226 }
00227 
00228 void G4VisManager::Initialise () {
00229 
00230   if (fInitialised && fVerbosity >= warnings) {
00231     G4cout << "WARNING: G4VisManager::Initialise: already initialised."
00232            << G4endl;
00233     return;
00234   }
00235 
00236   if (fVerbosity >= startup) {
00237     G4cout << "Visualization Manager initialising..." << G4endl;
00238   }
00239 
00240   if (fVerbosity >= parameters) {
00241     G4cout <<
00242       "\nYou have instantiated your own Visualization Manager, inheriting"
00243       "\n  G4VisManager and implementing RegisterGraphicsSystems(), in which"
00244       "\n  you should, normally, instantiate drivers which do not need"
00245       "\n  external packages or libraries, and, optionally, drivers under"
00246       "\n  control of environment variables."
00247       "\n  Also you should implement RegisterModelFactories()."
00248       "\n  See visualization/include/G4VisExecutive.hh/icc, for example."
00249       "\n  In your main() you will have something like:"
00250       "\n  #ifdef G4VIS_USE"
00251       "\n    G4VisManager* visManager = new G4VisExecutive;"
00252       "\n    visManager -> SetVerboseLevel (Verbose);"
00253       "\n    visManager -> Initialize ();"
00254       "\n  #endif"
00255       "\n  (Don't forget to delete visManager;)"
00256       "\n"
00257          << G4endl;
00258   }
00259 
00260   if (fVerbosity >= startup) {
00261     G4cout << "Registering graphics systems..." << G4endl;
00262   }
00263 
00264   RegisterGraphicsSystems ();
00265 
00266   if (fVerbosity >= startup) {
00267     G4cout <<
00268       "\nYou have successfully registered the following graphics systems."
00269          << G4endl;
00270     PrintAvailableGraphicsSystems ();
00271     G4cout << G4endl;
00272   }
00273 
00274   // Make command directories for commands instantiated in the
00275   // modeling subcategory...
00276   G4UIcommand* directory;
00277   directory = new G4UIdirectory ("/vis/modeling/");
00278   directory -> SetGuidance ("Modeling commands.");
00279   fDirectoryList.push_back (directory);
00280   directory = new G4UIdirectory ("/vis/modeling/trajectories/");
00281   directory -> SetGuidance ("Trajectory model commands.");
00282   fDirectoryList.push_back (directory);
00283   directory = new G4UIdirectory ("/vis/modeling/trajectories/create/");
00284   directory -> SetGuidance ("Create trajectory models and messengers.");
00285   fDirectoryList.push_back (directory);
00286 
00287   // Filtering command directory
00288   directory = new G4UIdirectory ("/vis/filtering/");
00289   directory -> SetGuidance ("Filtering commands.");
00290   fDirectoryList.push_back (directory);
00291   directory = new G4UIdirectory ("/vis/filtering/trajectories/");
00292   directory -> SetGuidance ("Trajectory filtering commands.");
00293   fDirectoryList.push_back (directory);
00294   directory = new G4UIdirectory ("/vis/filtering/trajectories/create/");
00295   directory -> SetGuidance ("Create trajectory filters and messengers.");
00296   fDirectoryList.push_back (directory);
00297   directory = new G4UIdirectory ("/vis/filtering/hits/");
00298   directory -> SetGuidance ("Hit filtering commands.");
00299   fDirectoryList.push_back (directory);
00300   directory = new G4UIdirectory ("/vis/filtering/hits/create/");
00301   directory -> SetGuidance ("Create hit filters and messengers.");
00302   fDirectoryList.push_back (directory);
00303   directory = new G4UIdirectory ("/vis/filtering/digi/");
00304   directory -> SetGuidance ("Digi filtering commands.");
00305   fDirectoryList.push_back (directory);
00306   directory = new G4UIdirectory ("/vis/filtering/digi/create/");
00307   directory -> SetGuidance ("Create digi filters and messengers.");
00308   fDirectoryList.push_back (directory);
00309 
00310   RegisterMessengers ();
00311 
00312   if (fVerbosity >= startup) {
00313     G4cout << "Registering model factories..." << G4endl;
00314   }
00315 
00316   RegisterModelFactories();
00317 
00318   if (fVerbosity >= startup) {
00319     G4cout <<
00320       "\nYou have successfully registered the following model factories."
00321            << G4endl;
00322     PrintAvailableModels (fVerbosity);
00323     G4cout << G4endl;
00324   }
00325 
00326   if (fVerbosity >= startup) {
00327     PrintAvailableUserVisActions (fVerbosity);
00328     G4cout << G4endl;
00329   }
00330 
00331   if (fVerbosity >= startup) {
00332     PrintAvailableColours (fVerbosity);
00333     G4cout << G4endl;
00334   }
00335 
00336   fInitialised = true;
00337 }
00338 
00339 void G4VisManager::RegisterMessengers () {
00340   
00341   // Instantiate individual messengers/commands (often - but not
00342   // always - one command per messenger).
00343   
00344   G4UIcommand* directory;
00345   
00346   // *Basic* top level commands were instantiated in the constructor
00347   // so that they can be used immediately after instantiation of the
00348   // vis manager.  Other top level and lower level commands are
00349   // instantiated here.
00350   
00351   // Other top level commands...
00352   RegisterMessenger(new G4VisCommandAbortReviewKeptEvents);
00353   RegisterMessenger(new G4VisCommandEnable);
00354   RegisterMessenger(new G4VisCommandList);
00355   RegisterMessenger(new G4VisCommandReviewKeptEvents);
00356   
00357   // Compound commands...
00358   RegisterMessenger(new G4VisCommandDrawTree);
00359   RegisterMessenger(new G4VisCommandDrawView);
00360   RegisterMessenger(new G4VisCommandDrawVolume);
00361   RegisterMessenger(new G4VisCommandOpen);
00362   RegisterMessenger(new G4VisCommandSpecify);
00363   
00364   directory = new G4UIdirectory ("/vis/geometry/");
00365   directory -> SetGuidance("Operations on vis attributes of Geant4 geometry.");
00366   fDirectoryList.push_back (directory);
00367   RegisterMessenger(new G4VisCommandGeometryList);
00368   RegisterMessenger(new G4VisCommandGeometryRestore);
00369   
00370   directory = new G4UIdirectory ("/vis/geometry/set/");
00371   directory -> SetGuidance("Set vis attributes of Geant4 geometry.");
00372   fDirectoryList.push_back (directory);
00373   RegisterMessenger(new G4VisCommandGeometrySetColour);
00374   RegisterMessenger(new G4VisCommandGeometrySetDaughtersInvisible);
00375   RegisterMessenger(new G4VisCommandGeometrySetLineStyle);
00376   RegisterMessenger(new G4VisCommandGeometrySetLineWidth);
00377   RegisterMessenger(new G4VisCommandGeometrySetForceAuxEdgeVisible);
00378   RegisterMessenger(new G4VisCommandGeometrySetForceLineSegmentsPerCircle);
00379   RegisterMessenger(new G4VisCommandGeometrySetForceSolid);
00380   RegisterMessenger(new G4VisCommandGeometrySetForceWireframe);
00381   RegisterMessenger(new G4VisCommandGeometrySetVisibility);
00382   
00383   directory = new G4UIdirectory ("/vis/set/");
00384   directory -> SetGuidance
00385     ("Set quantities for use in future commands where appropriate.");
00386   fDirectoryList.push_back (directory);
00387   RegisterMessenger(new G4VisCommandSetColour);
00388   RegisterMessenger(new G4VisCommandSetLineWidth);
00389   RegisterMessenger(new G4VisCommandSetTextColour);
00390   RegisterMessenger(new G4VisCommandSetTextLayout);
00391   RegisterMessenger(new G4VisCommandSetTouchable);
00392   
00393   directory = new G4UIdirectory ("/vis/scene/");
00394   directory -> SetGuidance ("Operations on Geant4 scenes.");
00395   fDirectoryList.push_back (directory);
00396   RegisterMessenger(new G4VisCommandSceneActivateModel);
00397   RegisterMessenger(new G4VisCommandSceneCreate);
00398   RegisterMessenger(new G4VisCommandSceneEndOfEventAction);
00399   RegisterMessenger(new G4VisCommandSceneEndOfRunAction);
00400   RegisterMessenger(new G4VisCommandSceneList);
00401   RegisterMessenger(new G4VisCommandSceneNotifyHandlers);
00402   RegisterMessenger(new G4VisCommandSceneSelect);
00403   
00404   directory = new G4UIdirectory ("/vis/scene/add/");
00405   directory -> SetGuidance ("Add model to current scene.");
00406   fDirectoryList.push_back (directory);
00407   RegisterMessenger(new G4VisCommandSceneAddArrow);
00408   RegisterMessenger(new G4VisCommandSceneAddArrow2D);
00409   RegisterMessenger(new G4VisCommandSceneAddAxes);
00410   RegisterMessenger(new G4VisCommandSceneAddDate);
00411   RegisterMessenger(new G4VisCommandSceneAddDigis);
00412   RegisterMessenger(new G4VisCommandSceneAddEventID);
00413   RegisterMessenger(new G4VisCommandSceneAddFrame);
00414   RegisterMessenger(new G4VisCommandSceneAddGhosts);
00415   RegisterMessenger(new G4VisCommandSceneAddHits);
00416   RegisterMessenger(new G4VisCommandSceneAddLine);
00417   RegisterMessenger(new G4VisCommandSceneAddLine2D);
00418   RegisterMessenger(new G4VisCommandSceneAddLogicalVolume);
00419   RegisterMessenger(new G4VisCommandSceneAddLogo);
00420   RegisterMessenger(new G4VisCommandSceneAddLogo2D);
00421   RegisterMessenger(new G4VisCommandSceneAddPSHits);
00422   RegisterMessenger(new G4VisCommandSceneAddScale);
00423   RegisterMessenger(new G4VisCommandSceneAddText);
00424   RegisterMessenger(new G4VisCommandSceneAddText2D);
00425   RegisterMessenger(new G4VisCommandSceneAddTrajectories);
00426   RegisterMessenger(new G4VisCommandSceneAddUserAction);
00427   RegisterMessenger(new G4VisCommandSceneAddVolume);
00428   
00429   directory = new G4UIdirectory ("/vis/sceneHandler/");
00430   directory -> SetGuidance ("Operations on Geant4 scene handlers.");
00431   fDirectoryList.push_back (directory);
00432   RegisterMessenger(new G4VisCommandSceneHandlerAttach);
00433   RegisterMessenger(new G4VisCommandSceneHandlerCreate);
00434   RegisterMessenger(new G4VisCommandSceneHandlerList);
00435   RegisterMessenger(new G4VisCommandSceneHandlerSelect);
00436   
00437   directory = new G4UIdirectory ("/vis/touchable/");
00438   directory -> SetGuidance ("Operations on touchables.");
00439   directory = new G4UIdirectory ("/vis/touchable/set/");
00440   directory -> SetGuidance ("Set vis attributes of current touchable.");
00441   fDirectoryList.push_back (directory);
00442   RegisterMessenger(new G4VisCommandsTouchableSet);
00443 
00444   directory = new G4UIdirectory ("/vis/viewer/");
00445   directory -> SetGuidance ("Operations on Geant4 viewers.");
00446   fDirectoryList.push_back (directory);
00447   RegisterMessenger(new G4VisCommandViewerAddCutawayPlane);
00448   RegisterMessenger(new G4VisCommandViewerChangeCutawayPlane);
00449   RegisterMessenger(new G4VisCommandViewerClear);
00450   RegisterMessenger(new G4VisCommandViewerClearCutawayPlanes);
00451   RegisterMessenger(new G4VisCommandViewerClearTransients);
00452   RegisterMessenger(new G4VisCommandViewerClone);
00453   RegisterMessenger(new G4VisCommandViewerCopyViewFrom);
00454   RegisterMessenger(new G4VisCommandViewerCreate);
00455   RegisterMessenger(new G4VisCommandViewerDolly);
00456   RegisterMessenger(new G4VisCommandViewerFlush);
00457   RegisterMessenger(new G4VisCommandViewerList);
00458   RegisterMessenger(new G4VisCommandViewerPan);
00459   RegisterMessenger(new G4VisCommandViewerRebuild);
00460   RegisterMessenger(new G4VisCommandViewerRefresh);
00461   RegisterMessenger(new G4VisCommandViewerReset);
00462   RegisterMessenger(new G4VisCommandViewerSave);
00463   RegisterMessenger(new G4VisCommandViewerScale);
00464   RegisterMessenger(new G4VisCommandViewerSelect);
00465   RegisterMessenger(new G4VisCommandViewerUpdate);
00466   RegisterMessenger(new G4VisCommandViewerZoom);
00467   
00468   directory = new G4UIdirectory ("/vis/viewer/default/");
00469   directory -> SetGuidance("Set default values for future viewers.");
00470   fDirectoryList.push_back (directory);
00471   RegisterMessenger(new G4VisCommandViewerDefaultHiddenEdge);
00472   RegisterMessenger(new G4VisCommandViewerDefaultStyle);
00473   
00474   directory = new G4UIdirectory ("/vis/viewer/set/");
00475   directory -> SetGuidance ("Set view parameters of current viewer.");
00476   fDirectoryList.push_back (directory);
00477   RegisterMessenger(new G4VisCommandsViewerSet);
00478   
00479   // List manager commands
00480   RegisterMessenger(new G4VisCommandListManagerList< G4VisModelManager<G4VTrajectoryModel> >
00481                     (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
00482   RegisterMessenger(new G4VisCommandListManagerSelect< G4VisModelManager<G4VTrajectoryModel> >
00483                     (fpTrajDrawModelMgr, fpTrajDrawModelMgr->Placement()));
00484   
00485   // Trajectory filter manager commands
00486   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VTrajectory> >
00487                     (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
00488   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VTrajectory> >
00489                     (fpTrajFilterMgr, fpTrajFilterMgr->Placement()));
00490   
00491   // Hit filter manager commands
00492   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VHit> >
00493                     (fpHitFilterMgr, fpHitFilterMgr->Placement()));
00494   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VHit> >
00495                     (fpHitFilterMgr, fpHitFilterMgr->Placement()));
00496   
00497   // Digi filter manager commands
00498   RegisterMessenger(new G4VisCommandListManagerList< G4VisFilterManager<G4VDigi> >
00499                     (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
00500   RegisterMessenger(new G4VisCommandManagerMode< G4VisFilterManager<G4VDigi> >
00501                     (fpDigiFilterMgr, fpDigiFilterMgr->Placement()));
00502 }
00503 
00504 void G4VisManager::Enable() {
00505   if (IsValidView ()) {
00506     if (fVerbosity >= confirmations) {
00507       G4cout << "G4VisManager::Enable: visualization enabled." << G4endl;
00508     }
00509   }
00510   else {
00511     if (fVerbosity >= warnings) {
00512       G4cout <<
00513         "G4VisManager::Enable: WARNING: visualization remains disabled for"
00514         "\n  above reasons.  Rectifying with valid vis commands will"
00515         "\n  automatically enable."
00516              << G4endl;
00517     }
00518   }
00519 }
00520 
00521 void G4VisManager::Disable() {
00522   SetConcreteInstance(0);
00523   if (fVerbosity >= confirmations) {
00524     G4cout <<
00525       "G4VisManager::Disable: visualization disabled."
00526       "\n  The pointer returned by GetConcreteInstance will be zero."
00527       "\n  Note that it will become enabled after some valid vis commands."
00528            << G4endl;
00529   }
00530 }
00531 
00532 const G4GraphicsSystemList& G4VisManager::GetAvailableGraphicsSystems () {
00533   G4int nSystems = fAvailableGraphicsSystems.size ();
00534   if (nSystems == 0) {
00535     if (fVerbosity >= warnings) {
00536       G4cout << "G4VisManager::GetAvailableGraphicsSystems: WARNING: no"
00537         "\n graphics system available!"
00538         "\n  1) Did you have environment variables G4VIS_BUILD_xxxx_DRIVER set"
00539         "\n     when you compiled/built the visualization code?"
00540         "\n  2) Did you instantiate your own Visualization Manager and forget"
00541         "\n     to implement RegisterGraphicsSystems correctly?"
00542         "\n  3) You can register your own graphics system, e.g.,"
00543         "\n     visManager->RegisterGraphicsSystem(new MyGraphicsSystem);)"
00544         "\n     after instantiating your vis manager and before"
00545         "\n     visManager->Initialize()."
00546              << G4endl;
00547     }
00548   }
00549   return fAvailableGraphicsSystems;
00550 }
00551 
00552 G4bool G4VisManager::RegisterGraphicsSystem (G4VGraphicsSystem* pSystem) {
00553   G4bool happy = true;
00554   if (pSystem) {
00555     fAvailableGraphicsSystems.push_back (pSystem);
00556     if (fVerbosity >= confirmations) {
00557       G4cout << "G4VisManager::RegisterGraphicsSystem: "
00558              << pSystem -> GetName ();
00559       if (pSystem -> GetNickname () != "") {
00560         G4cout << " (" << pSystem -> GetNickname () << ")";
00561       }
00562       G4cout << " registered." << G4endl;
00563     }
00564   }
00565   else {
00566     if (fVerbosity >= errors) {
00567       G4cout << "G4VisManager::RegisterGraphicsSystem: null pointer!"
00568              << G4endl;
00569     }
00570     happy=false;
00571   }
00572   return happy;
00573 }
00574 
00575 const G4VTrajectoryModel*
00576 G4VisManager::CurrentTrajDrawModel() const
00577 {
00578   assert (0 != fpTrajDrawModelMgr);
00579 
00580   const G4VTrajectoryModel* model = fpTrajDrawModelMgr->Current();
00581 
00582   if (0 == model) {
00583     // No model was registered with the trajectory model manager.
00584     // Use G4TrajectoryDrawByCharge as a default.
00585     fpTrajDrawModelMgr->Register(new G4TrajectoryDrawByCharge("AutoGenerated"));
00586 
00587     if (fVerbosity >= warnings) {
00588       G4cout<<"G4VisManager: Using G4TrajectoryDrawByCharge as default trajectory model."<<G4endl;
00589       G4cout<<"See commands in /vis/modeling/trajectories/ for other options."<<G4endl;
00590     }
00591   }
00592 
00593   model = fpTrajDrawModelMgr->Current();
00594   assert (0 != model); // Should definitely exist now
00595 
00596   return model;
00597 }
00598 
00599 void G4VisManager::RegisterModel(G4VTrajectoryModel* model) 
00600 {
00601   fpTrajDrawModelMgr->Register(model);
00602 }
00603 
00604 void
00605 G4VisManager::RegisterModelFactory(G4TrajDrawModelFactory* factory) 
00606 {
00607   fpTrajDrawModelMgr->Register(factory);
00608 }
00609 
00610 void G4VisManager::RegisterModel(G4VFilter<G4VTrajectory>* model)
00611 {
00612   fpTrajFilterMgr->Register(model);
00613 }
00614 
00615 void
00616 G4VisManager::RegisterModelFactory(G4TrajFilterFactory* factory)
00617 {
00618   fpTrajFilterMgr->Register(factory);
00619 }
00620 
00621 void G4VisManager::RegisterModel(G4VFilter<G4VHit>* model)
00622 {
00623   fpHitFilterMgr->Register(model);
00624 }
00625 
00626 void
00627 G4VisManager::RegisterModelFactory(G4HitFilterFactory* factory)
00628 {
00629   fpHitFilterMgr->Register(factory);
00630 }
00631 
00632 void G4VisManager::RegisterModel(G4VFilter<G4VDigi>* model)
00633 {
00634   fpDigiFilterMgr->Register(model);
00635 }
00636 
00637 void
00638 G4VisManager::RegisterModelFactory(G4DigiFilterFactory* factory)
00639 {
00640   fpDigiFilterMgr->Register(factory);
00641 }
00642 
00643 void G4VisManager::SelectTrajectoryModel(const G4String& model) 
00644 {
00645    fpTrajDrawModelMgr->SetCurrent(model);
00646 }
00647 
00648 void G4VisManager::BeginDraw (const G4Transform3D& objectTransform)
00649 {
00650   fDrawGroupNestingDepth++;
00651   if (fDrawGroupNestingDepth > 1) {
00652     G4Exception
00653       ("G4VSceneHandler::BeginDraw",
00654        "visman0008", JustWarning,
00655        "Nesting detected. It is illegal to nest Begin/EndDraw."
00656        "\n Ignored");
00657     return;
00658   }
00659   if (IsValidView ()) {
00660     ClearTransientStoreIfMarked();
00661     fpSceneHandler -> BeginPrimitives (objectTransform);
00662     fIsDrawGroup = true;
00663   }
00664 }
00665 
00666 void G4VisManager::EndDraw ()
00667 {
00668   fDrawGroupNestingDepth--;
00669   if (fDrawGroupNestingDepth != 0) {
00670     if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
00671     return;
00672   }
00673   if (IsValidView ()) {
00674     fpSceneHandler -> EndPrimitives ();
00675   }
00676   fIsDrawGroup = false;
00677 }
00678 
00679 void G4VisManager::BeginDraw2D (const G4Transform3D& objectTransform)
00680 {
00681   fDrawGroupNestingDepth++;
00682   if (fDrawGroupNestingDepth > 1) {
00683     G4Exception
00684       ("G4VSceneHandler::BeginDraw2D",
00685        "visman0009", JustWarning,
00686        "Nesting detected. It is illegal to nest Begin/EndDraw2D."
00687        "\n Ignored");
00688     return;
00689   }
00690   if (IsValidView ()) {
00691     ClearTransientStoreIfMarked();
00692     fpSceneHandler -> BeginPrimitives2D (objectTransform);
00693     fIsDrawGroup = true;
00694   }
00695 }
00696 
00697 void G4VisManager::EndDraw2D ()
00698 {
00699   fDrawGroupNestingDepth--;
00700   if (fDrawGroupNestingDepth != 0) {
00701     if (fDrawGroupNestingDepth < 0) fDrawGroupNestingDepth = 0;
00702     return;
00703   }
00704   if (IsValidView ()) {
00705     fpSceneHandler -> EndPrimitives2D ();
00706   }
00707   fIsDrawGroup = false;
00708 }
00709 
00710 template <class T> void G4VisManager::DrawT
00711 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
00712   if (fIsDrawGroup) {
00713     if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
00714       G4Exception
00715         ("G4VSceneHandler::DrawT",
00716          "visman0010", FatalException,
00717          "Different transform detected in Begin/EndDraw group.");
00718     }
00719     fpSceneHandler -> AddPrimitive (graphics_primitive);
00720   } else {
00721     if (IsValidView ()) {
00722       ClearTransientStoreIfMarked();
00723       fpSceneHandler -> BeginPrimitives (objectTransform);
00724       fpSceneHandler -> AddPrimitive (graphics_primitive);
00725       fpSceneHandler -> EndPrimitives ();
00726     }
00727   }
00728 }
00729 
00730 template <class T> void G4VisManager::DrawT2D
00731 (const T& graphics_primitive, const G4Transform3D& objectTransform) {
00732   if (fIsDrawGroup) {
00733     if (objectTransform != fpSceneHandler->GetObjectTransformation()) {
00734       G4Exception
00735         ("G4VSceneHandler::DrawT",
00736          "visman0011", FatalException,
00737          "Different transform detected in Begin/EndDraw2D group.");
00738     }
00739     fpSceneHandler -> AddPrimitive (graphics_primitive);
00740   } else {
00741     if (IsValidView ()) {
00742       ClearTransientStoreIfMarked();
00743       fpSceneHandler -> BeginPrimitives2D (objectTransform);
00744       fpSceneHandler -> AddPrimitive (graphics_primitive);
00745       fpSceneHandler -> EndPrimitives2D ();
00746     }
00747   }
00748 }
00749 
00750 void G4VisManager::Draw (const G4Circle& circle,
00751                          const G4Transform3D& objectTransform)
00752 {
00753   DrawT (circle, objectTransform);
00754 }
00755 
00756 void G4VisManager::Draw (const G4NURBS& nurbs,
00757                          const G4Transform3D& objectTransform)
00758 {
00759   DrawT (nurbs, objectTransform);
00760 }
00761 
00762 void G4VisManager::Draw (const G4Polyhedron& polyhedron,
00763                          const G4Transform3D& objectTransform)
00764 {
00765   DrawT (polyhedron, objectTransform);
00766 }
00767 
00768 void G4VisManager::Draw (const G4Polyline& line,
00769                          const G4Transform3D& objectTransform)
00770 {
00771   DrawT (line, objectTransform);
00772 }
00773 
00774 void G4VisManager::Draw (const G4Polymarker& polymarker,
00775                          const G4Transform3D& objectTransform)
00776 {
00777   DrawT (polymarker, objectTransform);
00778 }
00779 
00780 void G4VisManager::Draw (const G4Scale& scale,
00781                          const G4Transform3D& objectTransform)
00782 {
00783   DrawT (scale, objectTransform);
00784 }
00785 
00786 void G4VisManager::Draw (const G4Square& square,
00787                          const G4Transform3D& objectTransform)
00788 {
00789   DrawT (square, objectTransform);
00790 }
00791 
00792 void G4VisManager::Draw (const G4Text& text,
00793                          const G4Transform3D& objectTransform)
00794 {
00795   DrawT (text, objectTransform);
00796 }
00797 
00798 void G4VisManager::Draw2D (const G4Circle& circle,
00799                            const G4Transform3D& objectTransform)
00800 {
00801   DrawT2D (circle, objectTransform);
00802 }
00803 
00804 void G4VisManager::Draw2D (const G4NURBS& nurbs,
00805                            const G4Transform3D& objectTransform)
00806 {
00807   DrawT2D (nurbs, objectTransform);
00808 }
00809 
00810 void G4VisManager::Draw2D (const G4Polyhedron& polyhedron,
00811                            const G4Transform3D& objectTransform)
00812 {
00813   DrawT2D (polyhedron, objectTransform);
00814 }
00815 
00816 void G4VisManager::Draw2D (const G4Polyline& line,
00817                            const G4Transform3D& objectTransform)
00818 {
00819   DrawT2D (line, objectTransform);
00820 }
00821 
00822 void G4VisManager::Draw2D (const G4Polymarker& polymarker,
00823                            const G4Transform3D& objectTransform)
00824 {
00825   DrawT2D (polymarker, objectTransform);
00826 }
00827 
00828 void G4VisManager::Draw2D (const G4Square& square,
00829                            const G4Transform3D& objectTransform)
00830 {
00831   DrawT2D (square, objectTransform);
00832 }
00833 
00834 void G4VisManager::Draw2D (const G4Text& text,
00835                            const G4Transform3D& objectTransform)
00836 {
00837   DrawT2D (text, objectTransform);
00838 }
00839 
00840 void G4VisManager::Draw (const G4VHit& hit) {
00841   if (fIsDrawGroup) {
00842     fpSceneHandler -> AddCompound (hit);
00843   } else {
00844     if (IsValidView ()) {
00845       ClearTransientStoreIfMarked();
00846       fpSceneHandler -> AddCompound (hit);
00847     }
00848   }
00849 }
00850 
00851 void G4VisManager::Draw (const G4VDigi& digi) {
00852   if (fIsDrawGroup) {
00853     fpSceneHandler -> AddCompound (digi);
00854   } else {
00855     if (IsValidView ()) {
00856       ClearTransientStoreIfMarked();
00857       fpSceneHandler -> AddCompound (digi);
00858     }
00859   }
00860 }
00861 
00862 void G4VisManager::Draw (const G4VTrajectory& traj,
00863                          G4int i_mode) {
00864   if (fIsDrawGroup) {
00865     fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
00866     dummyTrajectoriesModel.SetDrawingMode(i_mode);
00867     fpSceneHandler -> AddCompound (traj);
00868   } else {
00869     if (IsValidView ()) {
00870       ClearTransientStoreIfMarked();
00871       fpSceneHandler -> SetModel (&dummyTrajectoriesModel);
00872       dummyTrajectoriesModel.SetDrawingMode(i_mode);
00873       fpSceneHandler -> AddCompound (traj);
00874     }
00875   }
00876 }
00877 
00878 void G4VisManager::Draw (const G4LogicalVolume& logicalVol,
00879                          const G4VisAttributes& attribs,
00880                          const G4Transform3D& objectTransform) {
00881   // Find corresponding solid.
00882   G4VSolid* pSol = logicalVol.GetSolid ();
00883   Draw (*pSol, attribs, objectTransform);
00884 }
00885 
00886 void G4VisManager::Draw (const G4VSolid& solid,
00887                          const G4VisAttributes& attribs,
00888                          const G4Transform3D& objectTransform) {
00889   if (fIsDrawGroup) {
00890     fpSceneHandler -> PreAddSolid (objectTransform, attribs);
00891     solid.DescribeYourselfTo (*fpSceneHandler);
00892     fpSceneHandler -> PostAddSolid ();
00893   } else {
00894     if (IsValidView ()) {
00895       ClearTransientStoreIfMarked();
00896       fpSceneHandler -> PreAddSolid (objectTransform, attribs);
00897       solid.DescribeYourselfTo (*fpSceneHandler);
00898       fpSceneHandler -> PostAddSolid ();
00899     }
00900   }
00901 }
00902 
00903 void G4VisManager::Draw (const G4VPhysicalVolume& physicalVol,
00904                          const G4VisAttributes& attribs,
00905                          const G4Transform3D& objectTransform) {
00906   // Find corresponding logical volume and solid.
00907   G4LogicalVolume* pLV  = physicalVol.GetLogicalVolume ();
00908   G4VSolid*        pSol = pLV -> GetSolid ();
00909   Draw (*pSol, attribs, objectTransform);
00910 }
00911 
00912 void G4VisManager::CreateSceneHandler (G4String name) {
00913   if (!fInitialised) Initialise ();
00914   if (fpGraphicsSystem) {
00915     G4VSceneHandler* pSceneHandler =
00916       fpGraphicsSystem -> CreateSceneHandler (name);
00917     if (pSceneHandler) {
00918       fAvailableSceneHandlers.push_back (pSceneHandler);
00919       fpSceneHandler = pSceneHandler;                         // Make current.
00920     }
00921     else {
00922       if(fVerbosity >= errors) {
00923         G4cout << "ERROR in G4VisManager::CreateSceneHandler during "
00924                << fpGraphicsSystem -> GetName ()
00925                << " scene handler creation.\n  No action taken."
00926                << G4endl;
00927       }
00928     }
00929   }
00930   else PrintInvalidPointers ();
00931 }
00932 
00933 void G4VisManager::CreateViewer (G4String name,G4String XGeometry) {
00934 
00935   if (!fInitialised) Initialise ();
00936 
00937   if (!fpSceneHandler) {
00938     PrintInvalidPointers ();
00939     return;
00940   }
00941 
00942   G4VViewer* p = fpGraphicsSystem -> CreateViewer (*fpSceneHandler, name);
00943 
00944   if (!p) {
00945     if (fVerbosity >= errors) {
00946       G4cout << "ERROR in G4VisManager::CreateViewer during "
00947              << fpGraphicsSystem -> GetName ()
00948              << " viewer creation.\n  No action taken."
00949              << G4endl;
00950     }
00951     return;
00952   }
00953 
00954   if (p -> GetViewId() < 0) {
00955     if (fVerbosity >= errors) {
00956       G4cout << "ERROR in G4VisManager::CreateViewer during "
00957              << fpGraphicsSystem -> GetName ()
00958              << " viewer initialisation.\n  No action taken."
00959              << G4endl;
00960     }
00961     return;
00962   }
00963 
00964   // Viewer is created, now we can set geometry parameters
00965   // Before 12/2008, it was done in G4VViewer.cc but it did not have to be there!
00966     
00967   G4ViewParameters initialvp = p -> GetViewParameters();
00968   initialvp.SetXGeometryString(XGeometry); //parse string and store parameters
00969   p -> SetViewParameters(initialvp);
00970   p -> Initialise ();  // (Viewer itself may change view parameters further.)
00971 
00972   fpViewer = p;                             // Make current.
00973   fpSceneHandler -> AddViewerToList (fpViewer);
00974   fpSceneHandler -> SetCurrentViewer (fpViewer);
00975   if (fVerbosity >= confirmations) {
00976     G4cout << "G4VisManager::CreateViewer: new viewer created."
00977            << G4endl;
00978   }
00979 
00980   const G4ViewParameters& vp = fpViewer->GetViewParameters();
00981   if (fVerbosity >= parameters) {
00982     G4cout << " view parameters are:\n  " << vp << G4endl;
00983   }
00984 
00985   if (vp.IsCulling () && vp.IsCullingInvisible ()) {
00986     static G4bool warned = false;
00987     if (fVerbosity >= confirmations) {
00988       if (!warned) {
00989         G4cout <<
00990   "NOTE: objects with visibility flag set to \"false\""
00991   " will not be drawn!"
00992   "\n  \"/vis/viewer/set/culling global false\" to Draw such objects."
00993   "\n  Also see other \"/vis/viewer/set\" commands."
00994                << G4endl;
00995         warned = true;
00996       }
00997     }
00998   }
00999   if (vp.IsCullingCovered ()) {
01000     static G4bool warned = false;
01001     if (fVerbosity >= warnings) {
01002       if (!warned) {
01003         G4cout <<
01004   "WARNING: covered objects in solid mode will not be rendered!"
01005   "\n  \"/vis/viewer/set/culling coveredDaughters false\" to reverse this."
01006   "\n  Also see other \"/vis/viewer/set\" commands."
01007                << G4endl;
01008         warned = true;
01009       }
01010     }
01011   }
01012 }
01013 
01014 void G4VisManager::GeometryHasChanged () {
01015   if (fVerbosity >= confirmations) {
01016     G4cout << "G4VisManager::GeometryHasChanged() called." << G4endl;
01017   }
01018 
01019   // Change the world...
01020   G4VPhysicalVolume* pWorld =
01021     G4TransportationManager::GetTransportationManager ()
01022     -> GetNavigatorForTracking () -> GetWorldVolume ();
01023   if (!pWorld) {
01024     if (fVerbosity >= warnings) {
01025       G4cout << "WARNING: There is no world volume!" << G4endl;
01026     }
01027   }
01028 
01029   // Check scenes.
01030   G4SceneList& sceneList = fSceneList;
01031   G4int iScene, nScenes = sceneList.size ();
01032   for (iScene = 0; iScene < nScenes; iScene++) {
01033     G4Scene* pScene = sceneList [iScene];
01034     std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
01035     if (modelList.size ()) {
01036       G4bool modelInvalid;
01037       do {  // Remove, if required, one at a time.
01038         modelInvalid = false;
01039         std::vector<G4Scene::Model>::iterator iterModel;
01040         for (iterModel = modelList.begin();
01041              iterModel != modelList.end();
01042              ++iterModel) {
01043           modelInvalid = !(iterModel->fpModel->Validate(fVerbosity>=warnings));
01044           if (modelInvalid) {
01045             // Model invalid - remove and break.
01046             if (fVerbosity >= warnings) {
01047               G4cout << "WARNING: Model \""
01048                      << iterModel->fpModel->GetGlobalDescription ()
01049                      <<
01050                 "\" is no longer valid - being removed\n  from scene \""
01051                      << pScene -> GetName () << "\""
01052                      << G4endl;
01053             }
01054             modelList.erase (iterModel);
01055             break;
01056           }
01057         }
01058       } while (modelInvalid);
01059 
01060       if (modelList.size () == 0) {
01061         if (fVerbosity >= warnings) {
01062           G4cout << "WARNING: No models left in this scene \""
01063                  << pScene -> GetName ()
01064                  << "\"."
01065                  << G4endl;
01066         }
01067       }
01068       else {
01069         pScene->CalculateExtent();
01070         G4UImanager::GetUIpointer () ->
01071           ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
01072       }
01073     }
01074   }
01075 
01076   // Check the manager's current scene...
01077   if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
01078     if (fVerbosity >= warnings) {
01079       G4cout << "WARNING: The current scene \""
01080              << fpScene -> GetName ()
01081              << "\" has no models."
01082              << G4endl;
01083     }
01084   }
01085 
01086 }
01087 void G4VisManager::NotifyHandlers () {
01088 
01089   if (fVerbosity >= confirmations) {
01090     G4cout << "G4VisManager::NotifyHandler() called." << G4endl;
01091   }
01092 
01093   // Check scenes.
01094   G4SceneList& sceneList = fSceneList;
01095   G4int iScene, nScenes = sceneList.size ();
01096   for (iScene = 0; iScene < nScenes; iScene++) {
01097     G4Scene* pScene = sceneList [iScene];
01098     std::vector<G4Scene::Model>& modelList = pScene -> SetRunDurationModelList ();
01099     
01100     if (modelList.size ()) {
01101       pScene->CalculateExtent();
01102       G4UImanager::GetUIpointer () ->
01103         ApplyCommand (G4String("/vis/scene/notifyHandlers " + pScene->GetName()));
01104     }
01105   }
01106 
01107   // Check the manager's current scene...
01108   if (fpScene && fpScene -> GetRunDurationModelList ().size () == 0) {
01109     if (fVerbosity >= warnings) {
01110       G4cout << "WARNING: The current scene \""
01111              << fpScene -> GetName ()
01112              << "\" has no models."
01113              << G4endl;
01114     }
01115   }
01116 
01117 }
01118 
01119 G4bool G4VisManager::FilterTrajectory(const G4VTrajectory& trajectory)
01120 {
01121   return fpTrajFilterMgr->Accept(trajectory);
01122 }   
01123 
01124 G4bool G4VisManager::FilterHit(const G4VHit& hit)
01125 {
01126   return fpHitFilterMgr->Accept(hit);
01127 }   
01128 
01129 G4bool G4VisManager::FilterDigi(const G4VDigi& digi)
01130 {
01131   return fpDigiFilterMgr->Accept(digi);
01132 }   
01133 
01134 void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory)
01135 {
01136   G4bool visible(true);
01137 
01138   // See if trajectory passes filter
01139   G4bool passed = FilterTrajectory(trajectory);
01140 
01141   if (!passed) {
01142     // Draw invisible trajectory if trajectory failed filter and
01143     // are filtering in soft mode
01144     if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
01145     else {return;}
01146   }
01147 
01148   // Go on to draw trajectory
01149   assert (0 != fpTrajDrawModelMgr);
01150 
01151   const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
01152 
01153   assert (0 != trajectoryModel); // Should exist
01154 
01155   trajectoryModel->Draw(trajectory, visible);
01156 }
01157 
01158 void G4VisManager::DispatchToModel(const G4VTrajectory& trajectory, G4int i_mode)
01159 {
01160   G4bool visible(true);
01161 
01162   // See if trajectory passes filter
01163   G4bool passed = FilterTrajectory(trajectory);
01164 
01165   if (!passed) {
01166     // Draw invisible trajectory if trajectory failed filter and
01167     // are filtering in soft mode
01168     if (fpTrajFilterMgr->GetMode() == FilterMode::Soft) visible = false;
01169     else {return;}
01170   }
01171 
01172   // Go on to draw trajectory
01173   assert (0 != fpTrajDrawModelMgr);
01174 
01175   const G4VTrajectoryModel* trajectoryModel = CurrentTrajDrawModel();
01176 
01177   assert (0 != trajectoryModel); // Should exist
01178 
01179   if (IsValidView()) {
01180     G4TrajectoriesModel* trajectoriesModel =
01181       dynamic_cast<G4TrajectoriesModel*>(fpSceneHandler->GetModel());
01182     if (trajectoriesModel) {
01183       if (trajectoriesModel->IsDrawingModeSet()) {
01184         trajectoryModel->Draw(trajectory, i_mode, visible);
01185       } else {
01186         trajectoryModel->Draw(trajectory, visible);
01187       }
01188     } else {
01189       // Just draw at user's request
01190       trajectoryModel->Draw(trajectory, i_mode, visible);
01191     }
01192   }
01193 }
01194 
01195 void G4VisManager::RegisterRunDurationUserVisAction
01196 (const G4String& name,
01197  G4VUserVisAction* pVisAction,
01198  const G4VisExtent& extent) {
01199   fRunDurationUserVisActions.push_back(UserVisAction(name,pVisAction));
01200   if (extent.GetExtentRadius() > 0.) {
01201     fUserVisActionExtents[pVisAction] = extent;
01202   } else {
01203     if (fVerbosity >= warnings) {
01204       G4cout << 
01205         "WARNING: No extent set for user vis action \"" << name << "\"."
01206              << G4endl;
01207     }
01208   }
01209 }
01210 
01211 void G4VisManager::RegisterEndOfEventUserVisAction
01212 (const G4String& name,
01213  G4VUserVisAction* pVisAction,
01214  const G4VisExtent& extent) {
01215   fEndOfEventUserVisActions.push_back(UserVisAction(name,pVisAction));
01216   if (extent.GetExtentRadius() > 0.) {
01217     fUserVisActionExtents[pVisAction] = extent;
01218   } else {
01219     if (fVerbosity >= warnings) {
01220       G4cout << 
01221         "WARNING: No extent set for user vis action \"" << name << "\"."
01222              << G4endl;
01223     }
01224   }
01225 }
01226 
01227 void G4VisManager::RegisterEndOfRunUserVisAction
01228 (const G4String& name,
01229  G4VUserVisAction* pVisAction,
01230  const G4VisExtent& extent) {
01231   fEndOfRunUserVisActions.push_back(UserVisAction(name,pVisAction));
01232   fUserVisActionExtents[pVisAction] = extent;
01233   if (extent.GetExtentRadius() <= 0.) {
01234     if (fVerbosity >= warnings) {
01235       G4cout << 
01236         "WARNING: No extent set for user vis action \"" << name << "\"."
01237              << G4endl;
01238     }
01239   }
01240 }
01241 
01242 void G4VisManager::SetCurrentScene (G4Scene* pScene) {
01243   if (pScene != fpScene) {
01244     // A change of scene.  Therefore reset transients drawn flags.  All
01245     // memory of previous transient proceessing thereby erased...
01246     ResetTransientsDrawnFlags();
01247   }
01248   fpScene = pScene;
01249 }
01250 
01251 void G4VisManager::SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem) {
01252   fpGraphicsSystem = pSystem;
01253   if (fVerbosity >= confirmations) {
01254     G4cout << "G4VisManager::SetCurrentGraphicsSystem: system now "
01255            << pSystem -> GetName () << G4endl;
01256   }
01257   // If current scene handler is of same graphics system, leave unchanged.
01258   // Else find the most recent scene handler of same graphics system.
01259   // Or clear pointers.
01260   if (!(fpSceneHandler && fpSceneHandler -> GetGraphicsSystem () == pSystem)) {
01261     const G4SceneHandlerList& sceneHandlerList = fAvailableSceneHandlers;
01262     G4int nSH = sceneHandlerList.size ();  // No. of scene handlers.
01263     G4int iSH;
01264     for (iSH = nSH - 1; iSH >= 0; iSH--) {
01265       if (sceneHandlerList [iSH] -> GetGraphicsSystem () == pSystem) break;
01266     }
01267     if (iSH >= 0) {
01268       fpSceneHandler = sceneHandlerList [iSH];
01269       if (fVerbosity >= confirmations) {
01270         G4cout << "  Scene Handler now "
01271                << fpSceneHandler -> GetName () << G4endl;
01272       }
01273       if (fpScene != fpSceneHandler -> GetScene ()) {
01274         fpScene = fpSceneHandler -> GetScene ();
01275         if (fVerbosity >= confirmations) {
01276           G4cout << "  Scene now \""
01277                  << fpScene -> GetName () << "\"" << G4endl;
01278         }
01279       }
01280       const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
01281       if (viewerList.size ()) {
01282         fpViewer = viewerList [0];
01283         if (fVerbosity >= confirmations) {
01284           G4cout << "  Viewer now " << fpViewer -> GetName () << G4endl;
01285         }
01286       }
01287       else {
01288         fpViewer = 0;
01289       }
01290     }
01291     else {
01292       fpSceneHandler = 0;
01293       fpViewer = 0;
01294     }
01295   }
01296 }
01297 
01298 void G4VisManager::SetCurrentSceneHandler (G4VSceneHandler* pSceneHandler) {
01299   fpSceneHandler = pSceneHandler;
01300   if (fVerbosity >= confirmations) {
01301     G4cout << "G4VisManager::SetCurrentSceneHandler: scene handler now \""
01302            << pSceneHandler -> GetName () << "\"" << G4endl;
01303   }
01304   if (fpScene != fpSceneHandler -> GetScene ()) {
01305     fpScene = fpSceneHandler -> GetScene ();
01306     if (fVerbosity >= confirmations) {
01307       G4cout << "  Scene now \""
01308              << fpScene -> GetName () << "\"" << G4endl;
01309     }
01310   }
01311   if (fpGraphicsSystem != pSceneHandler -> GetGraphicsSystem ()) {
01312     fpGraphicsSystem = pSceneHandler -> GetGraphicsSystem ();
01313     if (fVerbosity >= confirmations) {
01314       G4cout << "  Graphics system now \""
01315              << fpGraphicsSystem -> GetName () << "\"" << G4endl;
01316     }
01317   }
01318   const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
01319   G4int nViewers = viewerList.size ();
01320   if (nViewers) {
01321     G4int iViewer;
01322     for (iViewer = 0; iViewer < nViewers; iViewer++) {
01323       if (fpViewer == viewerList [iViewer]) break;
01324     }
01325     if (iViewer >= nViewers) {
01326       fpViewer = viewerList [0];
01327       if (fVerbosity >= confirmations) {
01328         G4cout << "  Viewer now \"" << fpViewer -> GetName () << "\""
01329                << G4endl;
01330       }
01331     }
01332     if (!IsValidView ()) {
01333       if (fVerbosity >= warnings) {
01334         G4cout <<
01335   "WARNING: Problem setting scene handler - please report circumstances."
01336                << G4endl;
01337       }
01338     }
01339   }
01340   else {
01341     fpViewer = 0;
01342     if (fVerbosity >= warnings) {
01343       G4cout <<
01344         "WARNING: No viewers for this scene handler - please create one."
01345              << G4endl;
01346     }
01347   }
01348 }
01349 
01350 void G4VisManager::SetCurrentViewer (G4VViewer* pViewer) {
01351   fpViewer  = pViewer;
01352   if (fVerbosity >= confirmations) {
01353     G4cout << "G4VisManager::SetCurrentViewer: viewer now "
01354            << pViewer -> GetName ()
01355            << G4endl;
01356   }
01357   fpSceneHandler = fpViewer -> GetSceneHandler ();
01358   fpSceneHandler -> SetCurrentViewer (pViewer);
01359   fpScene = fpSceneHandler -> GetScene ();
01360   fpGraphicsSystem = fpSceneHandler -> GetGraphicsSystem ();
01361   if (!IsValidView ()) {
01362     if (fVerbosity >= warnings) {
01363       G4cout <<
01364         "WARNING: Problem setting viewer - please report circumstances."
01365              << G4endl;
01366     }
01367   }
01368 }
01369 
01370 namespace {
01371   struct NicknameComparison {
01372     bool operator() (const G4String& lhs, const G4String& rhs) const
01373     {return lhs.length()<rhs.length();}
01374   };
01375 }
01376 
01377 void G4VisManager::PrintAvailableGraphicsSystems () const {
01378   G4int nSystems = fAvailableGraphicsSystems.size ();
01379   G4cout << "Current available graphics systems are:";
01380   if (nSystems) {
01381     // Make a map of graphics systems names (there may be repeated systems)
01382     // and for each name a set of nicknames.  The nicknames are ordered
01383     // by length - see struct NicknameComparison above.
01384     std::map<G4String,std::set<G4String,NicknameComparison> > systemMap;
01385     for (G4int i = 0; i < nSystems; i++) {
01386       const G4VGraphicsSystem* pSystem = fAvailableGraphicsSystems[i];
01387       systemMap[pSystem->GetName()].insert(pSystem->GetNickname());
01388     }
01389     // Print the map.
01390     std::map<G4String,std::set<G4String,NicknameComparison> >::const_iterator i;
01391     for (i = systemMap.begin(); i != systemMap.end(); ++i) {
01392       G4cout << "\n  " << i->first << " (";
01393       const std::set<G4String,NicknameComparison>& nicknames = i->second;
01394       std::set<G4String,NicknameComparison>::const_iterator j;
01395       for (j = nicknames.begin(); j != nicknames.end(); ++j) {
01396         if (j != nicknames.begin()) G4cout << ", ";
01397         G4cout << *j;
01398       }
01399       G4cout << ')';
01400     }
01401   }
01402   else {
01403     G4cout << "\n  NONE!!!  None registered - yet!  Mmmmm!";
01404   }
01405   G4cout << G4endl;
01406 }
01407 
01408 void G4VisManager::PrintAvailableModels (Verbosity verbosity) const
01409 {
01410   {
01411     //fpTrajDrawModelMgr->Print(G4cout);
01412     G4cout << "Registered model factories:" << G4endl;
01413     const std::vector<G4VModelFactory<G4VTrajectoryModel>*>& factoryList =
01414       fpTrajDrawModelMgr->FactoryList();
01415     if (factoryList.empty()) G4cout << "  None" << G4endl;
01416     else {
01417       std::vector<G4VModelFactory<G4VTrajectoryModel>*>::const_iterator i;
01418       for (i = factoryList.begin(); i != factoryList.end(); ++i)
01419         (*i)->Print(G4cout);
01420     }
01421     const G4VisListManager<G4VTrajectoryModel>* listManager =
01422       fpTrajDrawModelMgr->ListManager();
01423     const std::map<G4String, G4VTrajectoryModel*>& modelMap =
01424       listManager->Map();
01425     if (!modelMap.empty()) {
01426       G4cout << "\nRegistered models:" << G4endl;
01427       std::map<G4String, G4VTrajectoryModel*>::const_iterator i;
01428       for (i = modelMap.begin(); i != modelMap.end(); ++i) {
01429         G4cout << "  " << i->second->Name();
01430         if (i->second == listManager->Current()) G4cout << " (Current)";
01431         G4cout << G4endl;
01432         if (verbosity >= parameters) i->second->Print(G4cout);
01433       }
01434     }
01435   }
01436 
01437   G4cout << G4endl;
01438 
01439   {
01440     //fpTrajFilterMgr->Print(G4cout);
01441     G4cout << "Registered filter factories:" << G4endl;
01442     const std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>&
01443       factoryList = fpTrajFilterMgr->FactoryList();
01444     if (factoryList.empty()) G4cout << "  None" << G4endl;
01445     else {
01446       std::vector<G4VModelFactory<G4VFilter<G4VTrajectory> >*>::const_iterator i;
01447       for (i = factoryList.begin(); i != factoryList.end(); ++i)
01448         (*i)->Print(G4cout);
01449     }
01450     const std::vector<G4VFilter<G4VTrajectory>*>&
01451       filterList = fpTrajFilterMgr->FilterList();
01452     if (!filterList.empty()) {
01453       G4cout << "\nRegistered filters:" << G4endl;
01454       std::vector<G4VFilter<G4VTrajectory>*>::const_iterator i;
01455       for (i = filterList.begin(); i != filterList.end(); ++i) {
01456         G4cout << "  " << (*i)->GetName() << G4endl;
01457         if (verbosity >= parameters) (*i)->PrintAll(G4cout);
01458       }
01459     }
01460   }
01461 }
01462 
01463 void G4VisManager::PrintAvailableUserVisActions (Verbosity) const
01464 {
01465   G4cout <<
01466     "You have successfully registered the following user vis actions."
01467          << G4endl;
01468   G4cout << "Run Duration User Vis Actions:";
01469   if (fRunDurationUserVisActions.empty()) G4cout << " none" << G4endl;
01470   else {
01471     G4cout << G4endl;
01472     for (size_t i = 0; i < fRunDurationUserVisActions.size(); i++) {
01473       const G4String& name = fRunDurationUserVisActions[i].fName;
01474       G4cout << "  " << name << G4endl;
01475     }
01476   }
01477 
01478   G4cout << "End of Event User Vis Actions:";
01479   if (fEndOfEventUserVisActions.empty()) G4cout << " none" << G4endl;
01480   else {
01481     G4cout << G4endl;
01482     for (size_t i = 0; i < fEndOfEventUserVisActions.size(); i++) {
01483       const G4String& name = fEndOfEventUserVisActions[i].fName;
01484       G4cout << "  " << name << G4endl;
01485     }
01486   }
01487 
01488   G4cout << "End of Run User Vis Actions:";
01489   if (fEndOfRunUserVisActions.empty()) G4cout << " none" << G4endl;
01490   else {
01491     G4cout << G4endl;
01492     for (size_t i = 0; i < fEndOfRunUserVisActions.size(); i++) {
01493       const G4String& name = fEndOfRunUserVisActions[i].fName;
01494       G4cout << "  " << name << G4endl;
01495     }
01496   }
01497 }
01498 
01499 void G4VisManager::PrintAvailableColours (Verbosity) const {
01500   G4cout <<
01501     "Some /vis commands (optionally) take a string to specify colour."
01502     "\nAvailable colours:\n  ";
01503   const std::map<G4String, G4Colour>& map = G4Colour::GetMap();
01504   for (std::map<G4String, G4Colour>::const_iterator i = map.begin();
01505        i != map.end();) {
01506     G4cout << i->first;
01507     if (++i != map.end()) G4cout << ", ";
01508   }
01509   G4cout << G4endl;
01510 }
01511 
01512 void G4VisManager::PrintInvalidPointers () const {
01513   if (fVerbosity >= errors) {
01514     G4cout << "ERROR: G4VisManager::PrintInvalidPointers:";
01515     if (!fpGraphicsSystem) {
01516       G4cout << "\n null graphics system pointer.";
01517     }
01518     else {
01519       G4cout << "\n  Graphics system is " << fpGraphicsSystem -> GetName ()
01520              << " but:";
01521       if (!fpScene)
01522         G4cout <<
01523           "\n  Null scene pointer. Use \"/vis/drawVolume\" or"
01524           " \"/vis/scene/create\".";
01525       if (!fpSceneHandler)
01526         G4cout <<
01527           "\n  Null scene handler pointer. Use \"/vis/open\" or"
01528           " \"/vis/sceneHandler/create\".";
01529       if (!fpViewer )
01530         G4cout <<
01531           "\n  Null viewer pointer. Use \"/vis/viewer/create\".";
01532     }
01533     G4cout << G4endl;
01534   }
01535 }
01536 
01537 void G4VisManager::BeginOfRun ()
01538 {
01539   //G4cout << "G4VisManager::BeginOfRun" << G4endl;
01540   fKeptLastEvent = false;
01541   fEventKeepingSuspended = false;
01542   fTransientsDrawnThisRun = false;
01543   if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisRun(false);
01544 }
01545 
01546 void G4VisManager::BeginOfEvent ()
01547 {
01548   //G4cout << "G4VisManager::BeginOfEvent" << G4endl;
01549   fTransientsDrawnThisEvent = false;
01550   if (fpSceneHandler) fpSceneHandler->SetTransientsDrawnThisEvent(false);
01551 }
01552 
01553 void G4VisManager::EndOfEvent ()
01554 {
01555   //G4cout << "G4VisManager::EndOfEvent" << G4endl;
01556 
01557   // Don't call IsValidView unless there is a scene handler.  This
01558   // avoids WARNING message at end of event and run when the user has
01559   // not instantiated a scene handler, e.g., in batch mode.
01560   G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
01561   if (!valid) return;
01562 
01563   G4RunManager* runManager = G4RunManager::GetRunManager();
01564   const G4Run* currentRun = runManager->GetCurrentRun();
01565 
01566   G4EventManager* eventManager = G4EventManager::GetEventManager();
01567   const G4Event* currentEvent = eventManager->GetConstCurrentEvent();
01568   if (!currentEvent) return;
01569 
01570   // We are about to draw the event (trajectories, etc.), but first we
01571   // have to clear the previous event(s) if necessary.  If this event
01572   // needs to be drawn afresh, e.g., the first event or any event when
01573   // "accumulate" is not requested, the old event has to be cleared.
01574   // We have postponed this so that, for normal viewers like OGL, the
01575   // previous event(s) stay on screen until this new event comes
01576   // along.  For a file-writing viewer the geometry has to be drawn.
01577   // See, for example, G4HepRepFileSceneHandler::ClearTransientStore.
01578   ClearTransientStoreIfMarked();
01579 
01580   // Now draw the event...
01581   fpSceneHandler->DrawEvent(currentEvent);
01582 
01583   G4int nEventsToBeProcessed = 0;
01584   G4int nKeptEvents = 0;
01585   G4int eventID = -2;  // (If no run manager, triggers ShowView as normal.)
01586   if (currentRun) {
01587     nEventsToBeProcessed = currentRun->GetNumberOfEventToBeProcessed();
01588     eventID = currentEvent->GetEventID();
01589     const std::vector<const G4Event*>* events =
01590       currentRun->GetEventVector();
01591     if (events) nKeptEvents = events->size();
01592   }
01593 
01594   if (fpScene->GetRefreshAtEndOfEvent()) {
01595 
01596     // Unless last event (in which case wait end of run)...
01597     if (eventID < nEventsToBeProcessed - 1) {
01598       // ShowView guarantees the view comes to the screen.  No action
01599       // is taken for normal viewers like OGL, but file-writing
01600       // viewers have to close the file.
01601       fpViewer->ShowView();
01602       fpSceneHandler->SetMarkForClearingTransientStore(true);
01603     } else {  // Last event...
01604       // Keep, but only if user has not kept any...
01605       if (!nKeptEvents) {
01606         eventManager->KeepTheCurrentEvent();
01607         fKeptLastEvent = true;
01608       }
01609     }
01610 
01611   } else {  //  Accumulating events...
01612 
01613     G4int maxNumberOfKeptEvents = fpScene->GetMaxNumberOfKeptEvents();
01614     if (maxNumberOfKeptEvents > 0 && nKeptEvents >= maxNumberOfKeptEvents) {
01615       fEventKeepingSuspended = true;
01616       static G4bool warned = false;
01617       if (!warned) {
01618         if (fVerbosity >= warnings) {
01619           G4cout <<
01620  "WARNING: G4VisManager::EndOfEvent: Automatic event keeping suspended."
01621  "\n  The number of events exceeds the maximum, "
01622                  << maxNumberOfKeptEvents <<
01623  ", that can be kept by the vis manager."
01624                  << G4endl;
01625         }
01626         warned = true;
01627       }
01628     } else if (maxNumberOfKeptEvents != 0) {
01629       eventManager->KeepTheCurrentEvent();
01630     }
01631   }
01632 }
01633 
01634 void G4VisManager::EndOfRun ()
01635 {
01636   //G4cout << "G4VisManager::EndOfRun" << G4endl;
01637 
01638   // Don't call IsValidView unless there is a scene handler.  This
01639   // avoids WARNING message at end of event and run when the user has
01640   // not instantiated a scene handler, e.g., in batch mode.
01641   G4bool valid = GetConcreteInstance() && fpSceneHandler && IsValidView();
01642   if (valid) {
01643     if (!fpSceneHandler->GetMarkForClearingTransientStore()) {
01644       if (fpScene->GetRefreshAtEndOfRun()) {
01645         fpSceneHandler->DrawEndOfRunModels();
01646         // ShowView guarantees the view comes to the screen.  No
01647         // action is taken for normal viewers like OGL, but
01648         // file-writing viewers have to close the file.
01649         fpViewer->ShowView();
01650         // An extra refresh for auto-refresh viewers
01651         if (fpViewer->GetViewParameters().IsAutoRefresh()) {
01652           fpViewer->RefreshView();
01653         }
01654         fpSceneHandler->SetMarkForClearingTransientStore(true);
01655       }
01656     }
01657 
01658     if (fEventKeepingSuspended && fVerbosity >= warnings) {
01659       G4cout <<
01660  "WARNING: G4VisManager::EndOfRun: Automatic event keeping has been suspended."
01661  "\n  The number of events in the run exceeded the maximum, "
01662              << fpScene->GetMaxNumberOfKeptEvents() <<
01663  ", that can be kept by the vis manager." <<
01664  "\n  The number of events kept by the vis manager can be changed with"
01665  "\n  \"/vis/scene/endOfEventAction accumulate <N>\", where N is the"
01666  "\n  maximum number you wish to allow.  N < 0 means \"unlimited\"."
01667              << G4endl;
01668     }
01669   }
01670   fEventRefreshing = false;
01671 
01672   G4RunManager* runManager = G4RunManager::GetRunManager();
01673   const G4Run* currentRun = runManager->GetCurrentRun();
01674   
01675   G4int nKeptEvents = 0;
01676   const std::vector<const G4Event*>* events =
01677     currentRun? currentRun->GetEventVector(): 0;
01678   if (events) nKeptEvents = events->size();
01679 
01680   if (nKeptEvents && !fKeptLastEvent) {
01681     if (!valid && fVerbosity >= warnings) G4cout << "WARNING: ";
01682     if (fVerbosity >= warnings) {
01683       G4cout << nKeptEvents;
01684       if (nKeptEvents == 1) G4cout << " event has";
01685       else G4cout << " events have";
01686       G4cout << " been kept for refreshing and/or reviewing." << G4endl;
01687     }
01688     static G4bool warned = false;
01689     if (!valid && fVerbosity >= warnings && !warned) {
01690       G4cout <<
01691         "  Only useful if before starting the run:"
01692         "\n    a) trajectories are stored (\"/vis/scene/add/trajectories [smooth|rich]\"), or"
01693         "\n    b) the Draw method of any hits or digis is implemented."
01694         "\n  To view trajectories, hits or digis:"
01695         "\n    open a viewer, draw a volume, \"/vis/scene/add/trajectories\""
01696         "\n    \"/vis/scene/add/hits\" or \"/vis/scene/add/digitisations\""
01697         "\n    and, possibly, \"/vis/viewer/flush\"."
01698         "\n  To see all events: \"/vis/scene/endOfEventAction accumulate\"."
01699         "\n  To see events individually: \"/vis/reviewKeptEvents\"."
01700              << G4endl;
01701       warned = true;
01702     }
01703   }
01704 }
01705 
01706 void G4VisManager::ClearTransientStoreIfMarked(){
01707   // Assumes valid view.
01708   if (fpSceneHandler->GetMarkForClearingTransientStore()) {
01709     fpSceneHandler->SetMarkForClearingTransientStore(false);
01710     fpSceneHandler->ClearTransientStore();
01711   }
01712   // Record if transients drawn.  These local flags are only set
01713   // *after* ClearTransientStore.  In the code in G4VSceneHandler
01714   // triggered by ClearTransientStore, use these flags so that
01715   // event refreshing is not done too early.
01716   fTransientsDrawnThisEvent = fpSceneHandler->GetTransientsDrawnThisEvent();
01717   fTransientsDrawnThisRun = fpSceneHandler->GetTransientsDrawnThisRun();
01718 }
01719 
01720 void G4VisManager::ResetTransientsDrawnFlags()
01721 {
01722   fTransientsDrawnThisRun = false;
01723   fTransientsDrawnThisEvent = false;
01724   G4SceneHandlerListConstIterator i;
01725   for (i = fAvailableSceneHandlers.begin();
01726        i != fAvailableSceneHandlers.end(); ++i) {
01727     (*i)->SetTransientsDrawnThisEvent(false);
01728     (*i)->SetTransientsDrawnThisRun(false);
01729   }
01730 }
01731 
01732 G4String G4VisManager::ViewerShortName (const G4String& viewerName) const {
01733   G4String viewerShortName (viewerName);
01734   viewerShortName = viewerShortName (0, viewerShortName.find (' '));
01735   return viewerShortName.strip ();
01736 }
01737 
01738 G4VViewer* G4VisManager::GetViewer (const G4String& viewerName) const {
01739   G4String viewerShortName = ViewerShortName (viewerName);
01740   size_t nHandlers = fAvailableSceneHandlers.size ();
01741   size_t iHandler, iViewer;
01742   G4VViewer* viewer = 0;
01743   G4bool found = false;
01744   for (iHandler = 0; iHandler < nHandlers; iHandler++) {
01745     G4VSceneHandler* sceneHandler = fAvailableSceneHandlers [iHandler];
01746     const G4ViewerList& viewerList = sceneHandler -> GetViewerList ();
01747     for (iViewer = 0; iViewer < viewerList.size (); iViewer++) {
01748       viewer = viewerList [iViewer];
01749       if (viewerShortName == viewer -> GetShortName ()) {
01750         found = true;
01751         break;
01752       }
01753     }
01754     if (found) break;
01755   }
01756   if (found) return viewer;
01757   else return 0;
01758 }
01759 
01760 std::vector<G4String> G4VisManager::VerbosityGuidanceStrings;
01761 
01762 G4String G4VisManager::VerbosityString(Verbosity verbosity) {
01763   G4String rs;
01764   switch (verbosity) {
01765   case         quiet: rs = "quiet (0)"; break;
01766   case       startup: rs = "startup (1)"; break;
01767   case        errors: rs = "errors (2)"; break;
01768   case      warnings: rs = "warnings (3)"; break;
01769   case confirmations: rs = "confirmations (4)"; break;
01770   case    parameters: rs = "parameters (5)"; break;
01771   case           all: rs = "all (6)"; break;
01772   }
01773   return rs;
01774 }
01775 
01776 G4VisManager::Verbosity
01777 G4VisManager::GetVerbosityValue(const G4String& verbosityString) {
01778   G4String ss(verbosityString); ss.toLower();
01779   Verbosity verbosity;
01780   if      (ss(0) == 'q') verbosity = quiet;
01781   else if (ss(0) == 's') verbosity = startup;
01782   else if (ss(0) == 'e') verbosity = errors;
01783   else if (ss(0) == 'w') verbosity = warnings;
01784   else if (ss(0) == 'c') verbosity = confirmations;
01785   else if (ss(0) == 'p') verbosity = parameters;
01786   else if (ss(0) == 'a') verbosity = all;
01787   else {
01788     G4int intVerbosity;
01789     std::istringstream is(ss);
01790     is >> intVerbosity;
01791     if (!is) {
01792       G4cout << "ERROR: G4VisManager::GetVerbosityValue: invalid verbosity \""
01793              << verbosityString << "\"";
01794       for (size_t i = 0; i < VerbosityGuidanceStrings.size(); ++i) {
01795         G4cout << '\n' << VerbosityGuidanceStrings[i];
01796       }
01797       verbosity = warnings;
01798       G4cout << "\n  Returning " << VerbosityString(verbosity)
01799              << G4endl;
01800     }
01801     else {
01802       verbosity = GetVerbosityValue(intVerbosity);
01803     }
01804   }
01805   return verbosity;
01806 }
01807 
01808 G4VisManager::Verbosity G4VisManager::GetVerbosityValue(G4int intVerbosity) {
01809   Verbosity verbosity;
01810   if      (intVerbosity < quiet) verbosity = quiet;
01811   else if (intVerbosity > all)   verbosity = all;
01812   else                           verbosity = Verbosity(intVerbosity);
01813   return verbosity;
01814 }
01815 
01816 G4VisManager::Verbosity G4VisManager::GetVerbosity () {
01817   return fVerbosity;
01818 }
01819 
01820 void G4VisManager::SetVerboseLevel (G4int intVerbosity) {
01821   fVerbosity = GetVerbosityValue(intVerbosity);
01822 }
01823 
01824 void G4VisManager::SetVerboseLevel (const G4String& verbosityString) {
01825   fVerbosity = GetVerbosityValue(verbosityString);
01826 }
01827 
01828 G4bool G4VisManager::IsValidView () {
01829 
01830   if (!fInitialised) Initialise ();
01831 
01832   static G4bool noGSPrinting = true;
01833   if (!fpGraphicsSystem) {
01834     // Limit printing - we do not want printing if the user simply does
01835     // not want to use graphics, e.g., in batch mode.
01836     if (noGSPrinting) {
01837       noGSPrinting = false;
01838       if (fVerbosity >= warnings) {
01839         G4cout <<
01840   "WARNING: G4VisManager::IsValidView(): Attempt to draw when no graphics system"
01841   "\n  has been instantiated.  Use \"/vis/open\" or \"/vis/sceneHandler/create\"."
01842   "\n  Alternatively, to avoid this message, suppress instantiation of vis"
01843   "\n  manager (G4VisExecutive), possibly by setting G4VIS_NONE, and ensure"
01844   "\n  drawing code is executed only if G4VVisManager::GetConcreteInstance()"
01845   "\n  is non-zero."
01846                << G4endl;
01847       }
01848     }
01849     return false;
01850   }
01851 
01852   if ((!fpScene) || (!fpSceneHandler) || (!fpViewer)) {
01853     if (fVerbosity >= errors) {
01854       G4cout <<
01855         "ERROR: G4VisManager::IsValidView(): Current view is not valid."
01856              << G4endl;
01857       PrintInvalidPointers ();
01858     }
01859     return false;
01860   }
01861 
01862   if (fpScene != fpSceneHandler -> GetScene ()) {
01863     if (fVerbosity >= errors) {
01864       G4cout << "ERROR: G4VisManager::IsValidView ():";
01865       if (fpSceneHandler -> GetScene ()) {
01866         G4cout <<
01867           "\n  The current scene \""
01868                << fpScene -> GetName ()
01869                << "\" is not handled by"
01870           "\n  the current scene handler \""
01871                << fpSceneHandler -> GetName ()
01872                << "\""
01873           "\n  (it currently handles scene \""
01874                << fpSceneHandler -> GetScene () -> GetName ()
01875                << "\")."
01876           "\n  Either:"
01877           "\n  (a) attach it to the scene handler with"
01878           "\n      /vis/sceneHandler/attach "
01879                << fpScene -> GetName ()
01880                <<       ", or"
01881           "\n  (b) create a new scene handler with "
01882           "\n      /vis/sceneHandler/create <graphics-system>,"
01883           "\n      in which case it should pick up the the new scene."
01884                << G4endl;
01885       }
01886       else {
01887         G4cout << "\n  Scene handler \""
01888                << fpSceneHandler -> GetName ()
01889                << "\" has null scene pointer."
01890           "\n  Attach a scene with /vis/sceneHandler/attach [<scene-name>]"
01891                << G4endl;
01892       }
01893     }
01894     return false;
01895   }
01896 
01897   const G4ViewerList& viewerList = fpSceneHandler -> GetViewerList ();
01898   if (viewerList.size () == 0) {
01899     if (fVerbosity >= errors) {
01900       G4cout <<
01901         "ERROR: G4VisManager::IsValidView (): the current scene handler\n  \""
01902              << fpSceneHandler -> GetName ()
01903              << "\" has no viewers.  Do /vis/viewer/create."
01904              << G4endl;
01905     }
01906     return false;
01907   }
01908 
01909   G4bool isValid = true;
01910   if (fpScene -> IsEmpty ()) {  // Add world by default if possible...
01911     G4bool warn(fVerbosity >= warnings);
01912     G4bool successful = fpScene -> AddWorldIfEmpty (warn);
01913     if (!successful || fpScene -> IsEmpty ()) {        // If still empty...
01914       if (fVerbosity >= errors) {
01915         G4cout << "ERROR: G4VisManager::IsViewValid ():";
01916         G4cout <<
01917           "\n  Attempt at some drawing operation when scene is empty."
01918           "\n  Maybe the geometry has not yet been defined."
01919           "  Try /run/initialize."
01920                << G4endl;
01921       }
01922       isValid = false;
01923     }
01924     else {
01925       G4UImanager::GetUIpointer()->ApplyCommand ("/vis/scene/notifyHandlers");
01926       if (fVerbosity >= warnings) {
01927         G4cout <<
01928           "WARNING: G4VisManager: the scene was empty, \"world\" has been"
01929           "\n  added and the scene handlers notified.";
01930         G4cout << G4endl;
01931       }
01932     }
01933   }
01934   if (isValid) SetConcreteInstance(this);
01935   return isValid;
01936 }
01937 
01938 void
01939 G4VisManager::RegisterModelFactories() 
01940 {
01941   if (fVerbosity >= warnings) {
01942     G4cout<<"G4VisManager: No model factories registered with G4VisManager."<<G4endl;
01943     G4cout<<"G4VisManager::RegisterModelFactories() should be overridden in derived"<<G4endl;
01944     G4cout<<"class. See G4VisExecutive for an example."<<G4endl;
01945   }
01946 }

Generated on Mon May 27 17:50:16 2013 for Geant4 by  doxygen 1.4.7