source: trunk/source/visualization/management/include/G4VisManager.hh @ 893

Last change on this file since 893 was 893, checked in by garnier, 15 years ago

make 3.80 added because 3.81 is bad

  • Property svn:mime-type set to text/cpp
File size: 19.3 KB
Line 
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//
26//
27// $Id: G4VisManager.hh,v 1.68 2008/01/04 22:03:46 allison Exp $
28// GEANT4 tag $Name: HEAD $
29//
30//
31
32// Class Description:
33//
34// The GEANT4 Visualization Manager - John Allison 02/Jan/1996.
35//
36// G4VisManager is a "Singleton", i.e., only one instance of it or any
37// derived class may exist.  A G4Exception is thrown if an attempt is
38// made to instantiate more than one.
39//
40// It is also an abstract class, so the user must derive his/her own
41// class from G4VisManager, implement the pure virtual function
42// RegisterGraphicsSystems, and instantiate an object of the derived
43// class - for an example see
44// visualization/include/G4VisExecutive.hh/icc.
45//
46// The recommended way for users to obtain a pointer to the vis
47// manager is with G4VVisManager::GetConcreteInstance (), being always
48// careful to test for non-zero.  This pointer is non-zero only when
49// (a) an object of the derived class exists and (b) when there is a
50// valid viewer available.
51//
52// Graphics system registration is normally done through the protected
53// pure virtual function RegisterGraphicsSystems called from
54// Initialise ().  You can also use the public function
55// RegisterGraphicsSystem (new MyGraphicsSystem) if you have your own
56// graphics system. A graphics system is, in effect, a factory for
57// scene handlers and viewers.
58//
59// The VisManager creates and manages graphics systems, scenes, scene
60// handlers, viewers and some models and model makers.  You can have
61// any number.  It has the concept of a "current viewer", and the
62// "current scene handler", the "current scene" and the "current
63// graphics system" which go with it.  You can select the current
64// viewer.  Most of the the operations of the VisManager take place
65// with the current viewer, in particular, the Draw operations.
66//
67// Each scene comprises drawable objects such as detector components
68// and hits when appropriate.  A scene handler translates a scene into
69// graphics-system-specific function calls and, possibly, a
70// graphics-system-dependent database - display lists, scene graphs,
71// etc.  Each viewer has its "view parameters" (see class description
72// of G4ViewParameters for available parameters and also for a
73// description of the concept of a "standard view" and all that).
74//
75// A friend class G4VisStateDependent is "state dependent", i.e., it
76// is notified on change of state (G4ApplicationState).  This is used
77// to message the G4VisManager to draw hits and trajectories in the
78// current scene at the end of event, as required.
79
80#ifndef G4VISMANAGER_HH
81#define G4VISMANAGER_HH
82
83#include "G4VVisManager.hh"
84
85#include "globals.hh"
86#include "G4GraphicsSystemList.hh"
87#include "G4ModelingParameters.hh"
88#include "G4NullModel.hh"
89#include "G4SceneHandlerList.hh"
90#include "G4SceneList.hh"
91#include "G4TrajectoriesModel.hh"
92#include "G4Transform3D.hh"
93#include "G4UImessenger.hh"
94
95#include <iostream>
96#include <vector>
97
98class G4Scene;
99class G4UIcommand;
100class G4UImessenger;
101class G4VisStateDependent;
102class G4VTrajectoryModel;
103class G4VUserVisAction;
104template <typename T> class G4VFilter;
105template <typename T> class G4VisFilterManager;
106template <typename T> class G4VisModelManager;
107template <typename T> class G4VModelFactory;
108class G4Event;
109
110namespace {
111  // Useful typedef's
112  typedef G4VModelFactory<G4VTrajectoryModel> G4TrajDrawModelFactory;
113  typedef G4VModelFactory< G4VFilter<G4VTrajectory> > G4TrajFilterFactory;
114  typedef G4VModelFactory< G4VFilter<G4VHit> > G4HitFilterFactory;
115}
116
117class G4VisManager: public G4VVisManager {
118
119  // Friends - classes and functions which need access to private
120  // members of G4VisManager.  This is mainly to obtain access to
121  // GetInstance (), which is private.  The correct way for normal
122  // users to obtain a pointer to the vis manager is with
123  // G4VVisManager::GetConcreteInstance (), always testing for
124  // non-zero.
125
126  // Odd friends that need access to the G4VisManager...
127  friend class G4RTSteppingAction;
128  friend class G4RayTrajectory;
129  friend class G4RayTracerSceneHandler;
130  friend class G4RTMessenger;
131  friend class G4OpenGLStoredSceneHandler;
132  friend class G4OpenGLViewerMessenger;
133  friend class G4OpenGLXViewerMessenger;
134  friend class G4OpenGLXmViewerMessenger;
135  friend class G4XXXSceneHandler;
136  friend class G4HepRepFileSceneHandler;
137
138  // Management friends...
139  friend class G4VSceneHandler;
140  friend class G4VViewer;
141
142  friend std::ostream & operator <<
143  (std::ostream &, const G4VGraphicsSystem &);
144
145  friend std::ostream & operator <<
146  (std::ostream &, const G4VSceneHandler &);
147
148  friend class G4VisStateDependent;
149
150  friend class G4VisCommandList;
151
152public: // With description
153
154  enum Verbosity {
155    quiet,         // Nothing is printed.
156    startup,       // Startup and endup messages are printed...
157    errors,        // ...and errors...
158    warnings,      // ...and warnings...
159    confirmations, // ...and confirming messages...
160    parameters,    // ...and parameters of scenes and views...
161    all            // ...and everything available.
162  };
163  // Simple graded message scheme.
164
165protected: // With description
166
167  G4VisManager ();
168  // The constructor is protected so that an object of the derived
169  // class may be constructed.
170
171public: // With description
172
173  virtual ~G4VisManager ();
174
175private:
176
177  // Private copy constructor and assigment operator - copying and
178  // assignment not allowed.  Keeps CodeWizard happy.
179  G4VisManager (const G4VisManager&);
180  G4VisManager& operator = (const G4VisManager&);
181
182  static G4VisManager* GetInstance ();
183  // Returns pointer to itself.  Throws a G4Exception if called before
184  // instantiation.  Private so that only friends can use; the normal
185  // user should instead use G4VVisManager::GetConcreteInstance () to
186  // get a "higher level" pointer for general use - but always test
187  // for non-zero.
188
189public: // With description
190
191  void Initialise ();
192  void Initialize ();  // Alias Initialise ().
193
194  G4bool RegisterGraphicsSystem (G4VGraphicsSystem*);
195  // Register an individual graphics system.  Normally this is done in
196  // a sub-class implementation of the protected virtual function,
197  // RegisterGraphicsSystems.  See, e.g., G4VisExecutive.icc.
198
199  void RegisterModelFactory(G4TrajDrawModelFactory* factory);
200  // Register trajectory draw model factory. Assumes ownership of factory.
201
202  void RegisterModel(G4VTrajectoryModel* model);
203  // Register trajectory model. Assumes ownership of model.
204
205  void RegisterModelFactory(G4TrajFilterFactory* factory);
206  // Register trajectory filter model factory. Assumes ownership of factory.
207
208  void RegisterModel(G4VFilter<G4VTrajectory>* filter);
209  // Register trajectory filter model. Assumes ownership of model.
210
211  void RegisterModelFactory(G4HitFilterFactory* factory);
212  // Register trajectory hit model factory. Assumes ownership of factory.
213
214  void RegisterModel(G4VFilter<G4VHit>* filter);
215  // Register trajectory hit model. Assumes ownership of model.
216
217  void SelectTrajectoryModel(const G4String& model);
218  // Set default trajectory model. Useful for use in compiled code
219
220  void RegisterMessenger(G4UImessenger* messenger);
221  // Register messenger. Assumes ownership of messenger.
222
223  /////////////////////////////////////////////////////////////////
224  // Now functions that implement the pure virtual functions of
225  // G4VVisManager for drawing various visualization primitives, useful
226  // for representing hits, digis, etc.
227
228  void Draw (const G4Circle&,
229    const G4Transform3D& objectTransformation = G4Transform3D());
230
231  void Draw (const G4NURBS&,
232    const G4Transform3D& objectTransformation = G4Transform3D());
233
234  void Draw (const G4Polyhedron&,
235    const G4Transform3D& objectTransformation = G4Transform3D());
236
237  void Draw (const G4Polyline&,
238    const G4Transform3D& objectTransformation = G4Transform3D());
239
240  void Draw (const G4Polymarker&,
241    const G4Transform3D& objectTransformation = G4Transform3D());
242
243  void Draw (const G4Scale&,
244    const G4Transform3D& objectTransformation = G4Transform3D());
245
246  void Draw (const G4Square&,
247    const G4Transform3D& objectTransformation = G4Transform3D());
248
249  void Draw (const G4Text&,
250    const G4Transform3D& objectTransformation = G4Transform3D());
251
252  virtual void Draw2D (const G4Circle&,
253    const G4Transform3D& objectTransformation = G4Transform3D());
254
255  virtual void Draw2D (const G4NURBS&,
256    const G4Transform3D& objectTransformation = G4Transform3D());
257
258  virtual void Draw2D (const G4Polyhedron&,
259    const G4Transform3D& objectTransformation = G4Transform3D());
260
261  virtual void Draw2D (const G4Polyline&,
262    const G4Transform3D& objectTransformation = G4Transform3D());
263
264  virtual void Draw2D (const G4Polymarker&,
265    const G4Transform3D& objectTransformation = G4Transform3D());
266
267  virtual void Draw2D (const G4Square&,
268    const G4Transform3D& objectTransformation = G4Transform3D());
269
270  virtual void Draw2D (const G4Text&,
271    const G4Transform3D& objectTransformation = G4Transform3D());
272
273  ////////////////////////////////////////////////////////////////////
274  // Now functions that implement the pure virtual functions of
275  // G4VVisManager for drawing a GEANT4 object.  Note that the
276  // visualization attributes needed in some cases override any
277  // visualization attributes that are associated with the object
278  // itself - thus you can, for example, change the colour of a
279  // physical volume.
280
281  void Draw (const G4VHit&);
282
283  void Draw (const G4VTrajectory&, G4int i_mode);
284  // i_mode is a parameter that can be used to control the drawing of
285  // the trajectory.  See, e.g., G4VTrajectory::DrawTrajectory.
286  // i_mode defaults to 0 by inheritance from G4VVisManager.
287
288  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
289    const G4Transform3D& objectTransformation = G4Transform3D());
290
291  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
292    const G4Transform3D& objectTransformation = G4Transform3D());
293
294  void Draw (const G4VSolid&, const G4VisAttributes&,
295    const G4Transform3D& objectTransformation = G4Transform3D());
296
297  ////////////////////////////////////////////////////////////////////////
298  // Now other pure virtual functions of G4VVisManager...
299
300  void GeometryHasChanged ();
301  // Used by run manager to notify change.
302
303  void DispatchToModel(const G4VTrajectory&, G4int i_mode);
304  // Draw the trajectory.
305
306  G4bool FilterTrajectory(const G4VTrajectory&);
307  G4bool FilterHit(const G4VHit&);
308
309  ////////////////////////////////////////////////////////////////////////
310  // Administration routines.
311
312  void CreateSceneHandler (G4String name = "");
313  // Creates scene handler for the current system.
314
315  void CreateViewer  (G4String name = "");
316  // Creates viewer for the current scene handler.
317
318private:
319
320  void BeginOfRun ();
321
322  void BeginOfEvent ();
323
324  void EndOfEvent ();
325  // This is called on change of state (G4ApplicationState).  It is
326  // used to draw hits and trajectories if included in the current
327  // scene at the end of event, as required.
328
329  void EndOfRun ();
330
331public: // With description
332
333  /////////////////////////////////////////////////////////////////////
334  // Access functions.
335
336  void Enable();
337  void Disable();
338  // Global enable/disable functions.
339
340  const G4VTrajectoryModel* CurrentTrajDrawModel() const;
341
342  G4VUserVisAction*            GetUserAction               () const;
343  G4VisExtent                  GetUserActionExtent         () const;
344  G4VGraphicsSystem*           GetCurrentGraphicsSystem    () const;
345  G4Scene*                     GetCurrentScene             () const;
346  G4VSceneHandler*             GetCurrentSceneHandler      () const;
347  G4VViewer*                   GetCurrentViewer            () const;
348  const G4GraphicsSystemList&  GetAvailableGraphicsSystems ();
349  // The above is non-const because it checks and updates the List by
350  // calling RegisterGraphicsSystems() if no graphics systems are
351  // already registered.
352  const G4SceneHandlerList&    GetAvailableSceneHandlers   () const;
353  const G4SceneList&           GetSceneList                () const;
354  Verbosity                    GetVerbosity                () const;
355  void  GetWindowSizeHint (G4int& xHint, G4int& yHint) const;
356  // Note: GetWindowSizeHint information is returned via the G4int& arguments.
357  void  GetWindowLocationHint (G4int& xHint, G4int& yHint) const;
358  const G4String&              GetXGeometryString          () const;
359  // GetXGeometryString is intended to be parsed by XParseGeometry.
360  // It contains the size information, as in GetWindowSizeHint, but
361  // may also contain the window position, e.g., "600x600-0+200.  The
362  // viewer should use this in preference to GetWindowSizeHint, since
363  // it contains more information.  (The size information in
364  // GetXGeometryString and GetWindowSizeHint is guaranteed to be
365  // identical.)
366  G4bool                       GetTransientsDrawnThisRun       () const;
367  G4bool                       GetTransientsDrawnThisEvent     () const;
368  const G4Event*               GetRequestedEvent               () const;
369  G4bool                       GetAbortReviewKeptEvents        () const;
370
371  void SetUserAction (G4VUserVisAction* pVisAction,
372                      const G4VisExtent& = G4VisExtent::NullExtent);
373  void SetUserActionExtent (const G4VisExtent&);
374  void              SetCurrentGraphicsSystem    (G4VGraphicsSystem* pSystem);
375  void              SetCurrentScene             (G4Scene*);
376  void              SetCurrentSceneHandler      (G4VSceneHandler* pScene);
377  void              SetCurrentViewer            (G4VViewer* pView);
378  G4SceneHandlerList& SetAvailableSceneHandlers ();  // Returns lvalue.
379  G4SceneList&      SetSceneList                ();  // Returns lvalue.
380  void              SetVerboseLevel             (G4int);
381  void              SetVerboseLevel             (const G4String&);
382  void              SetVerboseLevel             (Verbosity);
383  void              SetWindowSizeHint           (G4int xHint, G4int yHint);
384  void              SetWindowLocationHint           (G4int xHint, G4int yHint);
385  void              SetXGeometryString          (const G4String&);
386  void              SetEventRefreshing          (G4bool);
387  void              ResetTransientsDrawnFlags   ();
388  // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
389  void              SetRequestedEvent           (const G4Event*);
390  void              SetAbortReviewKeptEvents    (G4bool);
391
392  /////////////////////////////////////////////////////////////////////
393  // Utility functions.
394
395  G4String ViewerShortName (const G4String& viewerName) const;
396  // Returns shortened version of viewer name, i.e., up to first space,
397  // if any.
398
399  G4VViewer* GetViewer (const G4String& viewerName) const;
400  // Returns zero if not found.  Can use long or short name, but find
401  // is done on short name.
402
403  static Verbosity GetVerbosityValue(const G4String&);
404  // Returns verbosity given a string.  (Uses first character only.)
405
406  static Verbosity GetVerbosityValue(G4int);
407  // Returns verbosity given an integer.  If integer is out of range,
408  // selects verbosity at extreme of range.
409
410  static G4String VerbosityString(Verbosity);
411  // Converts the verbosity into a string for suitable for printing.
412 
413  static std::vector<G4String> VerbosityGuidanceStrings;
414  // Guidance on the use of visualization verbosity.
415
416protected:
417
418  virtual void RegisterGraphicsSystems () = 0;
419  // The sub-class must implement and make successive calls to
420  // RegisterGraphicsSystem.
421
422  virtual void RegisterModelFactories();
423  // Sub-class must register desired models
424
425  void RegisterMessengers              ();   // Command messengers.
426
427  const G4int           fVerbose;
428  // fVerbose is kept for backwards compatibility for some user
429  // examples.  (It is used in the derived user vis managers to print
430  // available graphics systems.)  It is initialised to 1 in the
431  // constructor and cannot be changed.
432
433  void PrintAvailableGraphicsSystems   () const;
434
435private:
436
437  void PrintAvailableModels            (Verbosity) const;
438  void PrintInvalidPointers            () const;
439  G4bool IsValidView ();
440  // True if view is valid.  Prints messages and sanitises various data.
441  void ClearTransientStoreIfMarked();
442  // Clears transient store of current scene handler if it is marked
443  // for clearing.  Assumes view is valid.
444
445  static G4VisManager*  fpInstance;         // Pointer to single instance.
446  G4bool                fInitialised;
447  G4VUserVisAction*     fpUserVisAction;    // User vis action callback.
448  G4VisExtent           fUserVisActionExtent;
449  G4VGraphicsSystem*    fpGraphicsSystem;   // Current graphics system.
450  G4Scene*              fpScene;            // Current scene.
451  G4VSceneHandler*      fpSceneHandler;     // Current scene handler.
452  G4VViewer*            fpViewer;           // Current viewer.
453  G4GraphicsSystemList  fAvailableGraphicsSystems;
454  G4SceneList           fSceneList;
455  G4SceneHandlerList    fAvailableSceneHandlers;
456  Verbosity             fVerbosity;
457  std::vector<G4UImessenger*> fMessengerList;
458  std::vector<G4UIcommand*>   fDirectoryList;
459  G4VisStateDependent*  fpStateDependent;   // Friend state dependent class.
460  G4int fWindowSizeHintX, fWindowSizeHintY; // For viewer...
461  G4int fWindowLocationHintX, fWindowLocationHintY; // For viewer...
462  G4String              fXGeometryString;   // ...construction.
463  G4TrajectoriesModel   dummyTrajectoriesModel;  // For passing drawing mode.
464  G4bool                fEventRefreshing;
465  G4bool                fTransientsDrawnThisRun;
466  G4bool                fTransientsDrawnThisEvent;
467  G4bool                fEventKeepingSuspended;
468  G4bool                fKeptLastEvent;
469  const G4Event*        fpRequestedEvent; // If non-zero, scene handler uses.
470  G4bool                fAbortReviewKeptEvents;
471
472  // Trajectory draw model manager
473  G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
474 
475  // Trajectory filter model manager
476  G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
477
478  // Hit filter model manager
479  G4VisFilterManager<G4VHit>* fpHitFilterMgr;
480
481};
482
483#include "G4VisManager.icc"
484
485#endif
Note: See TracBrowser for help on using the repository browser.