Salome HOME
5c24cefa13b315a4a25202a2deaa174d9bd751c5
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 #ifdef WIN32
56 #pragma warning ( disable:4251 )
57 #endif
58
59 /*! 
60   \class SVTK_Renderer
61   The class is a container for #vtkRenderer instance.
62   Main goal of the class is to apply common behaviour to all #SALOME_Actor, like
63   selection and preselection colors.
64   Also, the class is responsible for management of internal actors like trihedron an so on.
65  */
66 class SVTK_EXPORT SVTK_Renderer : public vtkObject
67 {
68  public:
69   vtkTypeMacro(SVTK_Renderer,vtkObject);
70   static SVTK_Renderer* New();
71
72   //----------------------------------------------------------------------------
73   //! Get its device
74   vtkRenderer* 
75   GetDevice();
76
77   //! Initialize the class
78   virtual
79   void 
80   Initialize(vtkRenderWindowInteractor* theInteractor,
81              SVTK_Selector* theSelector);
82
83   //----------------------------------------------------------------------------
84   //! Publishes pointed actor into the renderer
85   virtual
86   void 
87   AddActor(VTKViewer_Actor* theActor);
88
89   //! Removes pointed actor from the renderer
90   virtual
91   void 
92   RemoveActor(VTKViewer_Actor* theActor);
93
94   //! Get special container that keeps scaling of the scene 
95   VTKViewer_Transform* 
96   GetTransform();
97
98   //! Allows to apply a scale on the whole scene
99   virtual
100   void
101   SetScale( double theScale[3] );
102
103   //! Allows to get a scale that is applied on the whole scene
104   void
105   GetScale( double theScale[3] );
106
107   //----------------------------------------------------------------------------
108   //! Applies color and size (PointSize and LineWidth) of primitives in selection mode
109   void
110   SetSelectionProp(const double& theRed = 1, 
111                    const double& theGreen = 1,
112                    const double& theBlue = 0, 
113                    const int& theWidth = 5);
114
115   //! Applies color and size (PointSize and LineWidth) of primitives in preselection mode
116   void
117   SetPreselectionProp(const double& theRed = 0, 
118                       const double& theGreen = 1,
119                       const double& theBlue = 1, 
120                       const int& theWidth = 5);
121
122   //! Setup requested tolerance for the picking
123   void
124   SetSelectionTolerance(const double& theTolNodes = 0.025, 
125                         const double& theTolCell = 0.001,
126                         const double& theTolObjects = 0.025);
127
128   //----------------------------------------------------------------------------
129   //! Adjust all intenal actors (trihedron and graduated rules) to the scene
130   void
131   AdjustActors();
132
133   //! Set size of the trihedron in percents from bounding box of the scene
134   void
135   SetTrihedronSize(vtkFloatingPointType theSize, const bool theRelative = true);
136  
137   //! Get size of the trihedron in percents from bounding box of the scene
138   vtkFloatingPointType  
139   GetTrihedronSize() const;
140
141   //! Shows if the size of the trihedron is relative
142   bool  
143   IsTrihedronRelative() const;
144
145   //----------------------------------------------------------------------------
146   //! Get trihedron control
147   VTKViewer_Trihedron* 
148   GetTrihedron();
149
150   //! Is trihedron displayed
151   bool 
152   IsTrihedronDisplayed();
153
154   //! Toggle trihedron visibility
155   void 
156   OnViewTrihedron(); 
157
158   //! Adjust size of the trihedron to the bounding box of the scene
159   void 
160   OnAdjustTrihedron();
161
162   //----------------------------------------------------------------------------
163   //! Get graduated rules control
164   SVTK_CubeAxesActor2D* 
165   GetCubeAxes();
166
167   //! Is graduated rules displayed
168   bool 
169   IsCubeAxesDisplayed();
170
171   //! Toggle graduated rules visibility
172   void 
173   OnViewCubeAxes();
174
175   //! Adjust size of the graduated rules to the bounding box of the scene
176   void 
177   OnAdjustCubeAxes();
178
179   //----------------------------------------------------------------------------
180   //! Fit all presentation in the scene into the window
181   void OnFitAll(); 
182   
183   //! Set camera into predefined state
184   void OnResetView(); 
185
186   //! Reset camera clipping range to adjust the range to the bounding box of the scene
187   void OnResetClippingRange(); 
188
189   //! To reset direction of the camera to front view
190   void OnFrontView(); 
191
192   //! To reset direction of the camera to back view
193   void OnBackView(); 
194
195   //! To reset direction of the camera to top view
196   void OnTopView();
197
198   //! To reset direction of the camera to bottom view
199   void OnBottomView();
200
201   //! To reset direction of the camera to right view
202   void OnRightView(); 
203
204   //! To reset direction of the camera to left view
205   void OnLeftView();     
206
207  protected:
208   SVTK_Renderer();
209   ~SVTK_Renderer();
210
211   virtual
212   bool
213   OnAdjustActors();
214
215   //----------------------------------------------------------------------------
216   // Priority at which events are processed
217   vtkFloatingPointType myPriority;
218
219   // Used to process events
220   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
221
222   // Description:
223   // Main process event method
224   static void ProcessEvents(vtkObject* object, 
225                             unsigned long event,
226                             void* clientdata, 
227                             void* calldata);
228   
229   vtkSmartPointer<vtkRenderer> myDevice;
230   vtkRenderWindowInteractor* myInteractor;
231   vtkSmartPointer<SVTK_Selector> mySelector;
232
233   //----------------------------------------------------------------------------
234   vtkSmartPointer<VTKViewer_Transform> myTransform;
235
236   //----------------------------------------------------------------------------
237   // Highlight/ Prehighlight devices
238   vtkSmartPointer<vtkPointPicker> myPointPicker;
239   vtkSmartPointer<vtkCellPicker> myCellPicker;
240
241   vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
242   vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
243
244   vtkSmartPointer<vtkProperty> myPreHighlightProperty;
245   vtkSmartPointer<vtkProperty> myHighlightProperty;
246
247   //----------------------------------------------------------------------------
248   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
249   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
250   vtkFloatingPointType myTrihedronSize;
251   bool myIsTrihedronRelative;
252   vtkFloatingPointType myBndBox[6];
253 };
254
255 #ifdef WIN32
256 #pragma warning ( default:4251 )
257 #endif
258
259 #endif