source: trunk/geant4/visualization/management/include/G4VisManager.hh @ 537

Last change on this file since 537 was 531, checked in by garnier, 17 years ago

r660@mac-90108: laurentgarnier | 2007-06-25 16:10:12 +0200
ajout de fichiers NON modifies

  • Property svn:mime-type set to text/cpp
File size: 18.0 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.65 2006/11/21 14:23:20 allison Exp $
28// GEANT4 tag $Name: geant4-08-02-patch-01 $
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  void Draw2D (const G4Text&);
253
254  ////////////////////////////////////////////////////////////////////
255  // Now functions that implement the pure virtual functions of
256  // G4VVisManager for drawing a GEANT4 object.  Note that the
257  // visualization attributes needed in some cases override any
258  // visualization attributes that are associated with the object
259  // itself - thus you can, for example, change the colour of a
260  // physical volume.
261
262  void Draw (const G4VHit&);
263
264  void Draw (const G4VTrajectory&, G4int i_mode);
265  // i_mode is a parameter that can be used to control the drawing of
266  // the trajectory.  See, e.g., G4VTrajectory::DrawTrajectory.
267  // i_mode defaults to 0 by inheritance from G4VVisManager.
268
269  void Draw (const G4LogicalVolume&, const G4VisAttributes&,
270    const G4Transform3D& objectTransformation = G4Transform3D());
271
272  void Draw (const G4VPhysicalVolume&, const G4VisAttributes&,
273    const G4Transform3D& objectTransformation = G4Transform3D());
274
275  void Draw (const G4VSolid&, const G4VisAttributes&,
276    const G4Transform3D& objectTransformation = G4Transform3D());
277
278  ////////////////////////////////////////////////////////////////////////
279  // Now other pure virtual functions of G4VVisManager...
280
281  void GeometryHasChanged ();
282  // Used by run manager to notify change.
283
284  void DispatchToModel(const G4VTrajectory&, G4int i_mode);
285  // Draw the trajectory.
286
287  G4bool FilterTrajectory(const G4VTrajectory&);
288  G4bool FilterHit(const G4VHit&);
289
290  ////////////////////////////////////////////////////////////////////////
291  // Administration routines.
292
293  void CreateSceneHandler (G4String name = "");
294  // Creates scene handler for the current system.
295
296  void CreateViewer  (G4String name = "");
297  // Creates viewer for the current scene handler.
298
299private:
300
301  void BeginOfRun ();
302
303  void BeginOfEvent ();
304
305  void EndOfEvent ();
306  // This is called on change of state (G4ApplicationState).  It is
307  // used to draw hits and trajectories if included in the current
308  // scene at the end of event, as required.
309
310  void EndOfRun ();
311
312public: // With description
313
314  /////////////////////////////////////////////////////////////////////
315  // Access functions.
316
317  void Enable();
318  void Disable();
319  // Global enable/disable functions.
320
321  const G4VTrajectoryModel* CurrentTrajDrawModel() const;
322
323  G4VUserVisAction*            GetUserAction               () const;
324  G4VisExtent                  GetUserActionExtent         () const;
325  G4VGraphicsSystem*           GetCurrentGraphicsSystem    () const;
326  G4Scene*                     GetCurrentScene             () const;
327  G4VSceneHandler*             GetCurrentSceneHandler      () const;
328  G4VViewer*                   GetCurrentViewer            () const;
329  const G4GraphicsSystemList&  GetAvailableGraphicsSystems ();
330  // The above is non-const because it checks and updates the List by
331  // calling RegisterGraphicsSystems() if no graphics systems are
332  // already registered.
333  const G4SceneHandlerList&    GetAvailableSceneHandlers   () const;
334  const G4SceneList&           GetSceneList                () const;
335  Verbosity                    GetVerbosity                () const;
336  void  GetWindowSizeHint (G4int& xHint, G4int& yHint) const;
337  // Note: GetWindowSizeHint information is returned via the G4int& arguments.
338  const G4String&              GetXGeometryString          () const;
339  // GetXGeometryString is intended to be parsed by XParseGeometry.
340  // It contains the size information, as in GetWindowSizeHint, but
341  // may also contain the window position, e.g., "600x600-0+200.  The
342  // viewer should use this in preference to GetWindowSizeHint, since
343  // it contains more information.  (The size information in
344  // GetXGeometryString and GetWindowSizeHint is guaranteed to be
345  // identical.)
346  const G4String&              GetBeginOfLastRunRandomStatus   () const;
347  const G4String&              GetBeginOfLastEventRandomStatus () const;
348  G4int                        GetLastRunID                    () const;
349  G4bool                       GetTransientsDrawnThisRun       () const;
350  G4bool                       GetTransientsDrawnThisEvent     () const;
351
352  void SetUserAction (G4VUserVisAction* pVisAction,
353                      const G4VisExtent& = G4VisExtent::NullExtent);
354  void SetUserActionExtent (const G4VisExtent&);
355  void              SetCurrentGraphicsSystem    (G4VGraphicsSystem* pSystem);
356  void              SetCurrentScene             (G4Scene*);
357  void              SetCurrentSceneHandler      (G4VSceneHandler* pScene);
358  void              SetCurrentViewer            (G4VViewer* pView);
359  G4SceneHandlerList& SetAvailableSceneHandlers ();  // Returns lvalue.
360  G4SceneList&      SetSceneList                ();  // Returns lvalue.
361  void              SetVerboseLevel             (G4int);
362  void              SetVerboseLevel             (const G4String&);
363  void              SetVerboseLevel             (Verbosity);
364  void              SetWindowSizeHint           (G4int xHint, G4int yHint);
365  void              SetXGeometryString          (const G4String&);
366  void              SetEventRefreshing          (G4bool);
367  void              ResetTransientsDrawnFlags   ();
368
369  /////////////////////////////////////////////////////////////////////
370  // Utility functions.
371
372  G4String ViewerShortName (const G4String& viewerName) const;
373  // Returns shortened version of viewer name, i.e., up to first space,
374  // if any.
375
376  G4VViewer* GetViewer (const G4String& viewerName) const;
377  // Returns zero if not found.  Can use long or short name, but find
378  // is done on short name.
379
380  static Verbosity GetVerbosityValue(const G4String&);
381  // Returns verbosity given a string.  (Uses first character only.)
382
383  static Verbosity GetVerbosityValue(G4int);
384  // Returns verbosity given an integer.  If integer is out of range,
385  // selects verbosity at extreme of range.
386
387  static G4String VerbosityString(Verbosity);
388  // Converts the verbosity into a string for suitable for printing.
389 
390  static std::vector<G4String> VerbosityGuidanceStrings;
391  // Guidance on the use of visualization verbosity.
392
393protected:
394
395  virtual void RegisterGraphicsSystems () = 0;
396  // The sub-class must implement and make successive calls to
397  // RegisterGraphicsSystem.
398
399  virtual void RegisterModelFactories();
400  // Sub-class must register desired models
401
402  void RegisterMessengers              ();   // Command messengers.
403
404  const G4int           fVerbose;
405  // fVerbose is kept for backwards compatibility for some user
406  // examples.  (It is used in the derived user vis managers to print
407  // available graphics systems.)  It is initialised to 1 in the
408  // constructor and cannot be changed.
409
410  void PrintAvailableGraphicsSystems   () const;
411
412private:
413
414  void PrintAvailableModels            (Verbosity) const;
415  void PrintInvalidPointers            () const;
416  G4bool IsValidView ();
417  // True if view is valid.  Prints messages and sanitises various data.
418  void ClearTransientStoreIfMarked();
419  // Clears transient store of current scene handler if it is marked
420  // for clearing.  Assumes view is valid.
421
422  static G4VisManager*  fpInstance;         // Pointer to single instance.
423  G4bool                fInitialised;
424  G4VUserVisAction*     fpUserVisAction;    // User vis action callback.
425  G4VisExtent           fUserVisActionExtent;
426  G4VGraphicsSystem*    fpGraphicsSystem;   // Current graphics system.
427  G4Scene*              fpScene;            // Current scene.
428  G4VSceneHandler*      fpSceneHandler;     // Current scene handler.
429  G4VViewer*            fpViewer;           // Current viewer.
430  G4GraphicsSystemList  fAvailableGraphicsSystems;
431  G4SceneList           fSceneList;
432  G4SceneHandlerList    fAvailableSceneHandlers;
433  Verbosity             fVerbosity;
434  std::vector<G4UImessenger*> fMessengerList;
435  std::vector<G4UIcommand*>   fDirectoryList;
436  G4VisStateDependent*  fpStateDependent;   // Friend state dependent class.
437  G4int fWindowSizeHintX, fWindowSizeHintY; // For viewer...
438  G4String fXGeometryString;                // ...construction.
439  G4TrajectoriesModel dummyTrajectoriesModel;  // For passing drawing mode.
440  G4bool fEventRefreshing;
441  G4bool fTransientsDrawnThisRun;
442  G4bool fTransientsDrawnThisEvent;
443  G4bool fEventKeepingSuspended;
444  G4bool fKeptLastEvent;
445
446  // Trajectory draw model manager
447  G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
448 
449  // Trajectory filter model manager
450  G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
451
452  // Hit filter model manager
453  G4VisFilterManager<G4VHit>* fpHitFilterMgr;
454
455};
456
457#include "G4VisManager.icc"
458
459#endif
Note: See TracBrowser for help on using the repository browser.