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