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

Last change on this file since 991 was 933, checked in by garnier, 17 years ago

John update

  • Property svn:mime-type set to text/cpp
File size: 18.4 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.70 2009/02/25 18:28:00 lgarnier Exp $
28// GEANT4 tag $Name: $
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 NotifyHandlers();
304 // Notify scene handlers (G4VGraphicsScene objects) that the scene
305 // has changed so that they may rebuild their graphics database, if
306 // any, and redraw all views.
307
308 void DispatchToModel(const G4VTrajectory&, G4int i_mode);
309 // Draw the trajectory.
310
311 G4bool FilterTrajectory(const G4VTrajectory&);
312 G4bool FilterHit(const G4VHit&);
313
314 ////////////////////////////////////////////////////////////////////////
315 // Administration routines.
316
317 void CreateSceneHandler (G4String name = "");
318 // Creates scene handler for the current system.
319
320 void CreateViewer (G4String name = "",G4String XGeometry = "");
321 // Creates viewer for the current scene handler.
322
323private:
324
325 void BeginOfRun ();
326
327 void BeginOfEvent ();
328
329 void EndOfEvent ();
330 // This is called on change of state (G4ApplicationState). It is
331 // used to draw hits and trajectories if included in the current
332 // scene at the end of event, as required.
333
334 void EndOfRun ();
335
336public: // With description
337
338 /////////////////////////////////////////////////////////////////////
339 // Access functions.
340
341 void Enable();
342 void Disable();
343 // Global enable/disable functions.
344
345 const G4VTrajectoryModel* CurrentTrajDrawModel() const;
346
347 G4VUserVisAction* GetUserAction () const;
348 G4VisExtent GetUserActionExtent () const;
349 G4VGraphicsSystem* GetCurrentGraphicsSystem () const;
350 G4Scene* GetCurrentScene () const;
351 G4VSceneHandler* GetCurrentSceneHandler () const;
352 G4VViewer* GetCurrentViewer () const;
353 const G4GraphicsSystemList& GetAvailableGraphicsSystems ();
354 // The above is non-const because it checks and updates the List by
355 // calling RegisterGraphicsSystems() if no graphics systems are
356 // already registered.
357 const G4SceneHandlerList& GetAvailableSceneHandlers () const;
358 const G4SceneList& GetSceneList () const;
359 Verbosity GetVerbosity () const;
360 G4bool GetTransientsDrawnThisRun () const;
361 G4bool GetTransientsDrawnThisEvent () const;
362 const G4Event* GetRequestedEvent () const;
363 G4bool GetAbortReviewKeptEvents () const;
364
365 void SetUserAction (G4VUserVisAction* pVisAction,
366 const G4VisExtent& = G4VisExtent::NullExtent);
367 void SetUserActionExtent (const G4VisExtent&);
368 void SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem);
369 void SetCurrentScene (G4Scene*);
370 void SetCurrentSceneHandler (G4VSceneHandler* pScene);
371 void SetCurrentViewer (G4VViewer* pView);
372 G4SceneHandlerList& SetAvailableSceneHandlers (); // Returns lvalue.
373 G4SceneList& SetSceneList (); // Returns lvalue.
374 void SetVerboseLevel (G4int);
375 void SetVerboseLevel (const G4String&);
376 void SetVerboseLevel (Verbosity);
377 void SetEventRefreshing (G4bool);
378 void ResetTransientsDrawnFlags ();
379 // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
380 void SetRequestedEvent (const G4Event*);
381 void SetAbortReviewKeptEvents (G4bool);
382
383 /////////////////////////////////////////////////////////////////////
384 // Utility functions.
385
386 G4String ViewerShortName (const G4String& viewerName) const;
387 // Returns shortened version of viewer name, i.e., up to first space,
388 // if any.
389
390 G4VViewer* GetViewer (const G4String& viewerName) const;
391 // Returns zero if not found. Can use long or short name, but find
392 // is done on short name.
393
394 static Verbosity GetVerbosityValue(const G4String&);
395 // Returns verbosity given a string. (Uses first character only.)
396
397 static Verbosity GetVerbosityValue(G4int);
398 // Returns verbosity given an integer. If integer is out of range,
399 // selects verbosity at extreme of range.
400
401 static G4String VerbosityString(Verbosity);
402 // Converts the verbosity into a string for suitable for printing.
403
404 static std::vector<G4String> VerbosityGuidanceStrings;
405 // Guidance on the use of visualization verbosity.
406
407protected:
408
409 virtual void RegisterGraphicsSystems () = 0;
410 // The sub-class must implement and make successive calls to
411 // RegisterGraphicsSystem.
412
413 virtual void RegisterModelFactories();
414 // Sub-class must register desired models
415
416 void RegisterMessengers (); // Command messengers.
417
418 const G4int fVerbose;
419 // fVerbose is kept for backwards compatibility for some user
420 // examples. (It is used in the derived user vis managers to print
421 // available graphics systems.) It is initialised to 1 in the
422 // constructor and cannot be changed.
423
424 void PrintAvailableGraphicsSystems () const;
425
426private:
427
428 void PrintAvailableModels (Verbosity) const;
429 void PrintInvalidPointers () const;
430 G4bool IsValidView ();
431 // True if view is valid. Prints messages and sanitises various data.
432 void ClearTransientStoreIfMarked();
433 // Clears transient store of current scene handler if it is marked
434 // for clearing. Assumes view is valid.
435
436 static G4VisManager* fpInstance; // Pointer to single instance.
437 G4bool fInitialised;
438 G4VUserVisAction* fpUserVisAction; // User vis action callback.
439 G4VisExtent fUserVisActionExtent;
440 G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
441 G4Scene* fpScene; // Current scene.
442 G4VSceneHandler* fpSceneHandler; // Current scene handler.
443 G4VViewer* fpViewer; // Current viewer.
444 G4GraphicsSystemList fAvailableGraphicsSystems;
445 G4SceneList fSceneList;
446 G4SceneHandlerList fAvailableSceneHandlers;
447 Verbosity fVerbosity;
448 std::vector<G4UImessenger*> fMessengerList;
449 std::vector<G4UIcommand*> fDirectoryList;
450 G4VisStateDependent* fpStateDependent; // Friend state dependent class.
451 G4TrajectoriesModel dummyTrajectoriesModel; // For passing drawing mode.
452 G4bool fEventRefreshing;
453 G4bool fTransientsDrawnThisRun;
454 G4bool fTransientsDrawnThisEvent;
455 G4bool fEventKeepingSuspended;
456 G4bool fKeptLastEvent;
457 const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
458 G4bool fAbortReviewKeptEvents;
459
460 // Trajectory draw model manager
461 G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
462
463 // Trajectory filter model manager
464 G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
465
466 // Hit filter model manager
467 G4VisFilterManager<G4VHit>* fpHitFilterMgr;
468
469};
470
471#include "G4VisManager.icc"
472
473#endif
Note: See TracBrowser for help on using the repository browser.