source: trunk/geant4/visualization/management/include/G4VSceneHandler.hh @ 656

Last change on this file since 656 was 593, checked in by garnier, 17 years ago

r627@mac-90108: laurentgarnier | 2007-11-09 07:57:42 +0100
modif dans les includes directives

  • Property svn:mime-type set to text/cpp
File size: 14.7 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: G4VSceneHandler.hh,v 1.39 2007/01/11 16:38:14 allison Exp $
28// GEANT4 tag $Name: geant4-09-00-ref-01 $
29//
30//
31// John Allison  19th July 1996.
32//
33// Class description
34//
35// Abstract interface class for graphics scene handlers.
36// Inherits from G4VGraphicsScene, in the intercoms category, which is
37// a minimal abstract interface for the GEANT4 kernel.
38
39#ifndef G4VSCENEHANDLER_HH
40#define G4VSCENEHANDLER_HH
41
42#include "globals.hh"
43
44#include <stack>
45
46#include "G4VGraphicsScene.hh"
47#include "G4ViewerList.hh"
48#include "G4ViewParameters.hh"
49
50class G4Scene;
51class G4VViewer;
52class G4Colour;
53class G4Visible;
54class G4ModelingParameters;
55class G4VModel;
56class G4VGraphicsSystem;
57class G4LogicalVolume;
58class G4VPhysicalVolume;
59class G4Material;
60class G4Event;
61class G4AttHolder;
62
63class G4VSceneHandler: public G4VGraphicsScene {
64
65public: // With description
66
67  friend std::ostream& operator << (std::ostream& os, const G4VSceneHandler& s);
68
69  enum MarkerSizeType {world, screen};
70
71  G4VSceneHandler (G4VGraphicsSystem& system,
72                   G4int id,
73                   const G4String& name = "");
74
75  virtual ~G4VSceneHandler ();
76
77  ///////////////////////////////////////////////////////////////////
78  // Methods for adding raw GEANT4 objects to the scene handler.  They
79  // must always be called in the triplet PreAddSolid, AddSolid and
80  // PostAddSolid.  The transformation and visualization attributes
81  // must be set by the call to PreAddSolid.  If your graphics system
82  // is sophisticated enough to handle a particular solid shape as a
83  // primitive, in your derived class write a function to override one
84  // or more of the following.  See the implementation of
85  // G4VSceneHandler::AddSolid (const G4Box& box) for more
86  // suggestions.  If not, please implement the base class invocation.
87
88  virtual void PreAddSolid (const G4Transform3D& objectTransformation,
89                           const G4VisAttributes& visAttribs);
90  // objectTransformation is the transformation in the world
91  // coordinate system of the object about to be added, and visAttribs
92  // is its visualization attributes.
93  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
94  // void MyXXXSceneHandler::PreAddSolid
95  //  (const G4Transform3D& objectTransformation,
96  //   const G4VisAttributes& visAttribs) {
97  //   G4VSceneHandler::PreAddSolid (objectTransformation, visAttribs);
98  //   ...
99  // }
100
101  virtual void PostAddSolid ();
102  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
103  // void MyXXXSceneHandler::PostAddSolid () {
104  //   ...
105  //   G4VSceneHandler::PostAddSolid ();
106  // }
107
108  virtual void AddSolid (const G4Box&);
109  virtual void AddSolid (const G4Cons&);
110  virtual void AddSolid (const G4Tubs&);
111  virtual void AddSolid (const G4Trd&);
112  virtual void AddSolid (const G4Trap&);
113  virtual void AddSolid (const G4Sphere&);
114  virtual void AddSolid (const G4Para&);
115  virtual void AddSolid (const G4Torus&);
116  virtual void AddSolid (const G4Polycone&);
117  virtual void AddSolid (const G4Polyhedra&);
118  virtual void AddSolid (const G4VSolid&);  // For solids not above.
119
120  ///////////////////////////////////////////////////////////////////
121  // Methods for adding "compound" GEANT4 objects to the scene
122  // handler.  These methods may either (a) invoke "user code" that
123  // uses the "user interface", G4VVisManager (see, for example,
124  // G4VSceneHandler, which for trajectories uses
125  // G4VTrajectory::DrawTrajectory, via G4TrajectoriesModel in the
126  // Modeling Category) or (b) invoke AddPrimitives below (between
127  // calls to Begin/EndPrimitives) or (c) use graphics-system-specific
128  // code or (d) any combination of the above.
129
130  virtual void AddCompound (const G4VTrajectory&);
131  virtual void AddCompound (const G4VHit&);
132
133  //////////////////////////////////////////////////////////////
134  // Functions for adding primitives.
135
136  virtual void BeginModeling ();
137  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
138  // void MyXXXSceneHandler::BeginModeling () {
139  //   G4VSceneHandler::BeginModeling ();
140  //   ...
141  // }
142
143  virtual void EndModeling ();
144  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
145  // void MyXXXSceneHandler::EndModeling () {
146  //   ...
147  //   G4VSceneHandler::EndModeling ();
148  // }
149
150  virtual void BeginPrimitives
151  (const G4Transform3D& objectTransformation);
152  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
153  // void MyXXXSceneHandler::BeginPrimitives
154  // (const G4Transform3D& objectTransformation) {
155  //   G4VSceneHandler::BeginPrimitives (objectTransformation);
156  //   ...
157  // }
158
159  virtual void EndPrimitives ();
160  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
161  // void MyXXXSceneHandler::EndPrimitives () {
162  //   ...
163  //   G4VSceneHandler::EndPrimitives ();
164  // }
165
166  virtual void BeginPrimitives2D ();
167  // The x,y coordinates of the primitives passed to AddPrimitive are
168  // intrepreted as screen coordinates, -1 < x,y < 1.  The
169  // z-coordinate is ignored.
170  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
171  // void MyXXXSceneHandler::BeginPrimitives2D
172  // (const G4Transform3D& objectTransformation) {
173  //   G4VSceneHandler::BeginPrimitives2D ();
174  //   ...
175  // }
176
177  virtual void EndPrimitives2D ();
178  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
179  // void MyXXXSceneHandler::EndPrimitives2D () {
180  //   ...
181  //   G4VSceneHandler::EndPrimitives2D ();
182  // }
183
184  virtual void AddPrimitive (const G4Polyline&)   = 0;
185  virtual void AddPrimitive (const G4Scale&);
186  // Default implementation in this class but can be over-ridden.
187  virtual void AddPrimitive (const G4Text&)       = 0;
188  virtual void AddPrimitive (const G4Circle&)     = 0;     
189  virtual void AddPrimitive (const G4Square&)     = 0;     
190  virtual void AddPrimitive (const G4Polymarker&);
191  // Default implementation in this class but can be over-ridden.
192  virtual void AddPrimitive (const G4Polyhedron&) = 0; 
193  virtual void AddPrimitive (const G4NURBS&)      = 0;       
194
195  //////////////////////////////////////////////////////////////
196  // Access functions.
197  const G4String&     GetName           () const;
198  G4int               GetSceneHandlerId () const;
199  G4int               GetViewCount      () const;
200  G4VGraphicsSystem*  GetGraphicsSystem () const;
201  G4Scene*            GetScene          () const;
202  const G4ViewerList& GetViewerList     () const;
203  G4VModel*           GetModel          () const;
204  G4VViewer*          GetCurrentViewer  () const;
205  G4bool              GetMarkForClearingTransientStore () const;
206  G4bool              IsReadyForTransients () const;
207  G4bool              GetTransientsDrawnThisEvent () const;
208  G4bool              GetTransientsDrawnThisRun   () const;
209  void          SetName          (const G4String&);
210  void          SetCurrentViewer (G4VViewer*);
211  void          SetScene         (G4Scene*);
212  G4ViewerList& SetViewerList    ();  // Non-const so you can change.
213  void          SetModel         (G4VModel*);
214  void          SetMarkForClearingTransientStore (G4bool);
215  // Sets flag which will cause transient store to be cleared at the
216  // next call to BeginPrimitives().  Maintained by vis manager.
217  void          SetTransientsDrawnThisEvent      (G4bool);
218  void          SetTransientsDrawnThisRun        (G4bool);
219  // Maintained by vis manager.
220
221  //////////////////////////////////////////////////////////////
222  // Public utility functions.
223
224  const G4Colour& GetColour (const G4Visible&);
225  const G4Colour& GetColor  (const G4Visible&);
226  // Returns colour of G4Visible object, or default global colour.
227
228  const G4Colour& GetTextColour (const G4Text&);
229  const G4Colour& GetTextColor  (const G4Text&);
230  // Returns colour of G4Text object, or default text colour.
231
232  G4double GetLineWidth(const G4VisAttributes*);
233  // Returns line width of G4VisAttributes multiplied by GlobalLineWidthScale.
234
235  G4ViewParameters::DrawingStyle GetDrawingStyle (const G4VisAttributes*);
236  // Returns drawing style from current view parameters, unless the user
237  // has forced through the vis attributes, thereby over-riding the
238  // current view parameter.
239
240  G4bool GetAuxEdgeVisible (const G4VisAttributes*);
241  // Returns auxiliary edge visibility from current view parameters,
242  // unless the user has forced through the vis attributes, thereby
243  // over-riding the current view parameter.
244
245  G4int GetNoOfSides(const G4VisAttributes*);
246  // Returns no. of sides (lines segments per circle) from current
247  // view parameters, unless the user has forced through the vis
248  // attributes, thereby over-riding the current view parameter.
249
250  G4double GetMarkerSize (const G4VMarker&, MarkerSizeType&);
251  // Returns applicable marker size (diameter) and type (in second
252  // argument).  Uses global default marker if marker sizes are not
253  // set.  Multiplies by GlobalMarkerScale.
254
255  G4double GetMarkerDiameter (const G4VMarker&, MarkerSizeType&);
256  // Alias for GetMarkerSize.
257
258  G4double GetMarkerRadius (const G4VMarker&, MarkerSizeType&);
259  // GetMarkerSize / 2.
260
261  G4ModelingParameters* CreateModelingParameters ();
262  // Only the scene handler and view know what the Modeling Parameters should
263  // be.  For historical reasons, the GEANT4 Visualization Environment
264  // maintains its own Scene Data and View Parameters, which must be
265  // converted, when needed, to Modeling Parameters.
266
267  void DrawEvent(const G4Event*);
268  // Checks scene's end-of-event model list and draws trajectories,
269  // hits, etc.
270
271  //////////////////////////////////////////////////////////////
272  // Administration functions.
273
274  G4int IncrementViewCount ();
275
276  virtual void ClearStore ();
277  // Clears graphics database (display lists) if any.  This base class
278  // implements some common functionality so...
279  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
280  // void MyXXXSceneHandler::ClearStore () {
281  //   G4VSceneHandler::ClearStore ();
282  //   ...
283  // }
284
285  virtual void ClearTransientStore ();
286  // Clears transient part of graphics database (display lists) if any.
287  // This base class implements some common functionality so...
288  // IMPORTANT: invoke this from your polymorphic versions, e.g.:
289  // void MyXXXSceneHandler::ClearTransientStore () {
290  //   G4VSceneHandler::ClearTransientStore ();
291  //   ...
292  // }
293
294  void AddViewerToList      (G4VViewer* pView);  // Add view to view List.
295  void RemoveViewerFromList (G4VViewer* pView);  // Remove view from view List.
296
297protected:
298
299  //////////////////////////////////////////////////////////////
300  // Default routine used by default AddSolid ().
301
302  virtual void RequestPrimitives (const G4VSolid& solid);
303
304  //////////////////////////////////////////////////////////////
305  // Other internal routines...
306
307  virtual const G4Polyhedron* CreateSectionPolyhedron ();
308  virtual const G4Polyhedron* CreateCutawayPolyhedron ();
309  // Generic clipping using the BooleanProcessor in graphics_reps is
310  // implemented in this class.  Subclasses that implement their own
311  // clipping should provide an override that returns zero.
312  void LoadAtts(const G4Visible&, G4AttHolder*);
313  // Load G4AttValues and G4AttDefs associated with the G4Visible
314  // object onto the G4AttHolder object.  It checks fpModel, and also
315  // loads the G4AttValues and G4AttDefs from G4PhysicalVolumeModel,
316  // G4VTrajectory, G4VTrajectoryPoint, or G4VHits, as appropriate.
317  // The G4AttHolder object is an object of a class that publicly
318  // inherits G4AttHolder - see, e.g., SoG4Polyhedron in the Open
319  // Inventor driver.  G4AttHolder deletes G4AttValues in its
320  // destructor to ensure proper clean-up of G4AttValues.
321
322  //////////////////////////////////////////////////////////////
323  // Data members
324
325  G4VGraphicsSystem& fSystem;          // Graphics system.
326  const G4int        fSceneHandlerId;  // Id of this instance.
327  G4String           fName;
328  G4int              fViewCount;       // To determine view ids.
329  G4ViewerList       fViewerList;      // Viewers.
330  G4VViewer*         fpViewer;         // Current viewer.
331  G4Scene*           fpScene;          // Scene for this scene handler.
332  G4bool             fMarkForClearingTransientStore;
333  G4bool             fReadyForTransients;  // I.e., not processing the
334                                           // run-duration part of scene.
335  G4bool             fTransientsDrawnThisEvent;  // Maintained by vis
336  G4bool             fTransientsDrawnThisRun;    // manager.
337  G4bool             fProcessingSolid; // True if within Pre/PostAddSolid.
338  G4bool             fSecondPassRequested;
339  G4bool             fSecondPass;    // ...in process.
340  G4VModel*          fpModel;        // Current model.
341  const G4Transform3D* fpObjectTransformation; // Current accumulated
342                                               // object transformation.
343  G4int              fNestingDepth; // For Begin/EndPrimitives.
344  const G4VisAttributes* fpVisAttribs;  // Working vis attributes.
345  const G4Transform3D fIdentityTransformation;
346
347private:
348
349  G4VSceneHandler (const G4VSceneHandler&);
350  G4VSceneHandler& operator = (const G4VSceneHandler&);
351
352  //////////////////////////////////////////////////////////////
353  // Friend function accessed only by views of this scene.
354
355  friend void G4VViewer::ProcessView ();
356
357  //////////////////////////////////////////////////////////////
358  // Private functions, etc..
359
360  void   ProcessScene     (G4VViewer& view);
361  // Accessed by G4VViewer::ProcessView ().
362
363};
364
365#include "G4VSceneHandler.icc"
366
367#endif
Note: See TracBrowser for help on using the repository browser.