]> SALOME platform Git repositories - modules/gui.git/blob - src/SVTK/SVTK_Renderer.h
Salome HOME
6012689ec5bf58a9013f93f22d2fa0131f65a0f5
[modules/gui.git] / src / SVTK / SVTK_Renderer.h
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS 
5 // 
6 //  This library is free software; you can redistribute it and/or 
7 //  modify it under the terms of the GNU Lesser General Public 
8 //  License as published by the Free Software Foundation; either 
9 //  version 2.1 of the License. 
10 // 
11 //  This library is distributed in the hope that it will be useful, 
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of 
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
14 //  Lesser General Public License for more details. 
15 // 
16 //  You should have received a copy of the GNU Lesser General Public 
17 //  License along with this library; if not, write to the Free Software 
18 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA 
19 // 
20 //  See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : 
25 //  Author : 
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef SVTK_Renderer_h
30 #define SVTK_Renderer_h
31
32 #include "SVTK.h"
33 #include "VTKViewer.h"
34
35 #include <vtkObject.h>
36 #include <vtkSmartPointer.h>
37
38 class vtkRenderer;
39 class vtkCallbackCommand;
40 class vtkRenderWindowInteractor;
41
42 class vtkPicker;
43 class vtkPointPicker;
44 class vtkCellPicker;
45 class vtkProperty;
46
47 class SVTK_RectPicker;
48
49 class VTKViewer_Trihedron;
50 class VTKViewer_Transform;
51 class SVTK_CubeAxesActor2D;
52 class VTKViewer_Actor;
53 class SVTK_Selector;
54
55
56 /*! 
57   \class SVTK_Renderer
58   The class is a container for #vtkRenderer instance.
59   Main goal of the class is to apply common behaviour to all #SALOME_Actor, like
60   selection and preselection colors.
61   Also, the class is responsible for management of internal actors like trihedron an so on.
62  */
63 class SVTK_EXPORT SVTK_Renderer : public vtkObject
64 {
65  public:
66   vtkTypeMacro(SVTK_Renderer,vtkObject);
67   static SVTK_Renderer* New();
68
69   //----------------------------------------------------------------------------
70   //! Get its device
71   vtkRenderer* 
72   GetDevice();
73
74   //! Initialize the class
75   virtual
76   void 
77   Initialize(vtkRenderWindowInteractor* theInteractor,
78              SVTK_Selector* theSelector);
79
80   //----------------------------------------------------------------------------
81   //! Publishes pointed actor into the renderer
82   virtual
83   void 
84   AddActor(VTKViewer_Actor* theActor);
85
86   //! Removes pointed actor from the renderer
87   virtual
88   void 
89   RemoveActor(VTKViewer_Actor* theActor);
90
91   //! Get special container that keeps scaling of the scene 
92   VTKViewer_Transform* 
93   GetTransform();
94
95   //! Allows to apply a scale on the whole scene
96   virtual
97   void
98   SetScale( double theScale[3] );
99
100   //! Allows to get a scale that is applied on the whole scene
101   void
102   GetScale( double theScale[3] );
103
104   //----------------------------------------------------------------------------
105   //! Applies color and size (PointSize and LineWidth) of primitives in selection mode
106   void
107   SetSelectionProp(const double& theRed = 1, 
108                    const double& theGreen = 1,
109                    const double& theBlue = 0, 
110                    const int& theWidth = 5);
111
112   //! Applies color and size (PointSize and LineWidth) of primitives in preselection mode
113   void
114   SetPreselectionProp(const double& theRed = 0, 
115                       const double& theGreen = 1,
116                       const double& theBlue = 1, 
117                       const int& theWidth = 5);
118
119   //! Setup requested tolerance for the picking
120   void
121   SetSelectionTolerance(const double& theTolNodes = 0.025, 
122                         const double& theTolCell = 0.001);
123
124   //----------------------------------------------------------------------------
125   //! Adjust all intenal actors (trihedron and graduated rules) to the scene
126   void
127   AdjustActors();
128
129   //! Set size of the trihedron in percents from bounding box of the scene
130   void
131   SetTrihedronSize(int theSize, const bool theRelative = true);
132  
133   //! Get size of the trihedron in percents from bounding box of the scene
134   int  
135   GetTrihedronSize() const;
136
137   //! Shows if the size of the trihedron is relative
138   bool  
139   IsTrihedronRelative() const;
140
141   //----------------------------------------------------------------------------
142   //! Get trihedron control
143   VTKViewer_Trihedron* 
144   GetTrihedron();
145
146   //! Is trihedron displayed
147   bool 
148   IsTrihedronDisplayed();
149
150   //! Toggle trihedron visibility
151   void 
152   OnViewTrihedron(); 
153
154   //! Adjust size of the trihedron to the bounding box of the scene
155   void 
156   OnAdjustTrihedron();
157
158   //----------------------------------------------------------------------------
159   //! Get graduated rules control
160   SVTK_CubeAxesActor2D* 
161   GetCubeAxes();
162
163   //! Is graduated rules displayed
164   bool 
165   IsCubeAxesDisplayed();
166
167   //! Toggle graduated rules visibility
168   void 
169   OnViewCubeAxes();
170
171   //! Adjust size of the graduated rules to the bounding box of the scene
172   void 
173   OnAdjustCubeAxes();
174
175   //----------------------------------------------------------------------------
176   //! Fit all presentation in the scene into the window
177   void OnFitAll(); 
178   
179   //! Set camera into predefined state
180   void OnResetView(); 
181
182   //! Reset camera clipping range to adjust the range to the bounding box of the scene
183   void OnResetClippingRange(); 
184
185   //! To reset direction of the camera to front view
186   void OnFrontView(); 
187
188   //! To reset direction of the camera to back view
189   void OnBackView(); 
190
191   //! To reset direction of the camera to top view
192   void OnTopView();
193
194   //! To reset direction of the camera to bottom view
195   void OnBottomView();
196
197   //! To reset direction of the camera to right view
198   void OnRightView(); 
199
200   //! To reset direction of the camera to left view
201   void OnLeftView();     
202
203  protected:
204   SVTK_Renderer();
205   ~SVTK_Renderer();
206
207   virtual
208   bool
209   OnAdjustActors();
210
211   //----------------------------------------------------------------------------
212   // Priority at which events are processed
213   vtkFloatingPointType myPriority;
214
215   // Used to process events
216   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
217
218   // Description:
219   // Main process event method
220   static void ProcessEvents(vtkObject* object, 
221                             unsigned long event,
222                             void* clientdata, 
223                             void* calldata);
224   
225   vtkSmartPointer<vtkRenderer> myDevice;
226   vtkRenderWindowInteractor* myInteractor;
227   vtkSmartPointer<SVTK_Selector> mySelector;
228
229   //----------------------------------------------------------------------------
230   vtkSmartPointer<VTKViewer_Transform> myTransform;
231
232   //----------------------------------------------------------------------------
233   // Highlight/ Prehighlight devices
234   vtkSmartPointer<vtkPointPicker> myPointPicker;
235   vtkSmartPointer<vtkCellPicker> myCellPicker;
236
237   vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
238   vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
239
240   vtkSmartPointer<vtkProperty> myPreHighlightProperty;
241   vtkSmartPointer<vtkProperty> myHighlightProperty;
242
243   //----------------------------------------------------------------------------
244   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
245   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
246   int  myTrihedronSize;
247   bool myIsTrihedronRelative;
248   vtkFloatingPointType myBndBox[6];
249 };
250
251 #endif