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

Last change on this file since 594 was 593, checked in by garnier, 18 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: 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.67 2007/07/10 17:49:27 allison Exp $
28// GEANT4 tag $Name: geant4-09-00-ref-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 G4bool GetTransientsDrawnThisRun () const;
347 G4bool GetTransientsDrawnThisEvent () const;
348 const G4Event* GetRequestedEvent () const;
349 G4bool GetAbortReviewKeptEvents () const;
350
351 void SetUserAction (G4VUserVisAction* pVisAction,
352 const G4VisExtent& = G4VisExtent::NullExtent);
353 void SetUserActionExtent (const G4VisExtent&);
354 void SetCurrentGraphicsSystem (G4VGraphicsSystem* pSystem);
355 void SetCurrentScene (G4Scene*);
356 void SetCurrentSceneHandler (G4VSceneHandler* pScene);
357 void SetCurrentViewer (G4VViewer* pView);
358 G4SceneHandlerList& SetAvailableSceneHandlers (); // Returns lvalue.
359 G4SceneList& SetSceneList (); // Returns lvalue.
360 void SetVerboseLevel (G4int);
361 void SetVerboseLevel (const G4String&);
362 void SetVerboseLevel (Verbosity);
363 void SetWindowSizeHint (G4int xHint, G4int yHint);
364 void SetXGeometryString (const G4String&);
365 void SetEventRefreshing (G4bool);
366 void ResetTransientsDrawnFlags ();
367 // If non-zero, requested event is used in G4VSceneHandler::ProcessScene.
368 void SetRequestedEvent (const G4Event*);
369 void SetAbortReviewKeptEvents (G4bool);
370
371 /////////////////////////////////////////////////////////////////////
372 // Utility functions.
373
374 G4String ViewerShortName (const G4String& viewerName) const;
375 // Returns shortened version of viewer name, i.e., up to first space,
376 // if any.
377
378 G4VViewer* GetViewer (const G4String& viewerName) const;
379 // Returns zero if not found. Can use long or short name, but find
380 // is done on short name.
381
382 static Verbosity GetVerbosityValue(const G4String&);
383 // Returns verbosity given a string. (Uses first character only.)
384
385 static Verbosity GetVerbosityValue(G4int);
386 // Returns verbosity given an integer. If integer is out of range,
387 // selects verbosity at extreme of range.
388
389 static G4String VerbosityString(Verbosity);
390 // Converts the verbosity into a string for suitable for printing.
391
392 static std::vector<G4String> VerbosityGuidanceStrings;
393 // Guidance on the use of visualization verbosity.
394
395protected:
396
397 virtual void RegisterGraphicsSystems () = 0;
398 // The sub-class must implement and make successive calls to
399 // RegisterGraphicsSystem.
400
401 virtual void RegisterModelFactories();
402 // Sub-class must register desired models
403
404 void RegisterMessengers (); // Command messengers.
405
406 const G4int fVerbose;
407 // fVerbose is kept for backwards compatibility for some user
408 // examples. (It is used in the derived user vis managers to print
409 // available graphics systems.) It is initialised to 1 in the
410 // constructor and cannot be changed.
411
412 void PrintAvailableGraphicsSystems () const;
413
414private:
415
416 void PrintAvailableModels (Verbosity) const;
417 void PrintInvalidPointers () const;
418 G4bool IsValidView ();
419 // True if view is valid. Prints messages and sanitises various data.
420 void ClearTransientStoreIfMarked();
421 // Clears transient store of current scene handler if it is marked
422 // for clearing. Assumes view is valid.
423
424 static G4VisManager* fpInstance; // Pointer to single instance.
425 G4bool fInitialised;
426 G4VUserVisAction* fpUserVisAction; // User vis action callback.
427 G4VisExtent fUserVisActionExtent;
428 G4VGraphicsSystem* fpGraphicsSystem; // Current graphics system.
429 G4Scene* fpScene; // Current scene.
430 G4VSceneHandler* fpSceneHandler; // Current scene handler.
431 G4VViewer* fpViewer; // Current viewer.
432 G4GraphicsSystemList fAvailableGraphicsSystems;
433 G4SceneList fSceneList;
434 G4SceneHandlerList fAvailableSceneHandlers;
435 Verbosity fVerbosity;
436 std::vector<G4UImessenger*> fMessengerList;
437 std::vector<G4UIcommand*> fDirectoryList;
438 G4VisStateDependent* fpStateDependent; // Friend state dependent class.
439 G4int fWindowSizeHintX, fWindowSizeHintY; // For viewer...
440 G4String fXGeometryString; // ...construction.
441 G4TrajectoriesModel dummyTrajectoriesModel; // For passing drawing mode.
442 G4bool fEventRefreshing;
443 G4bool fTransientsDrawnThisRun;
444 G4bool fTransientsDrawnThisEvent;
445 G4bool fEventKeepingSuspended;
446 G4bool fKeptLastEvent;
447 const G4Event* fpRequestedEvent; // If non-zero, scene handler uses.
448 G4bool fAbortReviewKeptEvents;
449
450 // Trajectory draw model manager
451 G4VisModelManager<G4VTrajectoryModel>* fpTrajDrawModelMgr;
452
453 // Trajectory filter model manager
454 G4VisFilterManager<G4VTrajectory>* fpTrajFilterMgr;
455
456 // Hit filter model manager
457 G4VisFilterManager<G4VHit>* fpHitFilterMgr;
458
459};
460
461#include "G4VisManager.icc"
462
463#endif
Note: See TracBrowser for help on using the repository browser.