Salome HOME
Implementation of the "22589: EDF 8048 - ergonomics of SMESH" issue.
[modules/gui.git] / src / SVTK / SVTK_Renderer.h
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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_AreaPicker;
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(double theSize, const bool theRelative = true);
134  
135   //! Get size of the trihedron in percents from bounding box of the scene
136   double  
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   //! Set Toggle trihedron visibility
157
158   void
159   SetTrihedronVisibility( const bool );
160
161   //! Adjust size of the trihedron to the bounding box of the scene
162   void 
163   OnAdjustTrihedron();
164
165   //----------------------------------------------------------------------------
166   //! Get graduated rules control
167   SVTK_CubeAxesActor2D* 
168   GetCubeAxes();
169
170   //! Is graduated rules displayed
171   bool 
172   IsCubeAxesDisplayed();
173
174   //! Toggle graduated rules visibility
175   void 
176   OnViewCubeAxes();
177
178   //! Adjust size of the graduated rules to the bounding box of the scene
179   void 
180   OnAdjustCubeAxes();
181
182   //----------------------------------------------------------------------------
183   //! Fit all presentation in the scene into the window
184   void OnFitAll(); 
185   
186   //! Set camera into predefined state
187   void OnResetView(); 
188
189   //! Reset camera clipping range to adjust the range to the bounding box of the scene
190   void OnResetClippingRange(); 
191
192   //! To reset direction of the camera to front view
193   void OnFrontView(); 
194
195   //! To reset direction of the camera to back view
196   void OnBackView(); 
197
198   //! To reset direction of the camera to top view
199   void OnTopView();
200
201   //! To reset direction of the camera to bottom view
202   void OnBottomView();
203
204   //! To reset direction of the camera to right view
205   void OnRightView(); 
206
207   //! To reset direction of the camera to left view
208   void OnLeftView();     
209
210   //! To rotate view 90 degrees clockwise
211   void onClockWiseView();
212
213   //! To rotate view 90 degrees counterclockwise
214   void onAntiClockWiseView();
215
216 protected:
217   SVTK_Renderer();
218   ~SVTK_Renderer();
219
220   virtual
221   bool
222   OnAdjustActors();
223
224   //----------------------------------------------------------------------------
225   // Priority at which events are processed
226   double myPriority;
227
228   // Used to process events
229   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
230
231   // Description:
232   // Main process event method
233   static void ProcessEvents(vtkObject* object, 
234                             unsigned long event,
235                             void* clientdata, 
236                             void* calldata);
237   
238   vtkSmartPointer<vtkRenderer> myDevice;
239   vtkRenderWindowInteractor* myInteractor;
240   vtkSmartPointer<SVTK_Selector> mySelector;
241
242   //----------------------------------------------------------------------------
243   vtkSmartPointer<VTKViewer_Transform> myTransform;
244
245   //----------------------------------------------------------------------------
246   // Highlight/ Prehighlight devices
247   vtkSmartPointer<vtkPointPicker> myPointPicker;
248   vtkSmartPointer<vtkCellPicker> myCellPicker;
249
250   vtkSmartPointer<SVTK_AreaPicker> myPointAreaPicker;
251   vtkSmartPointer<SVTK_AreaPicker> myCellAreaPicker;
252
253   vtkSmartPointer<vtkProperty> myPreHighlightProperty;
254   vtkSmartPointer<vtkProperty> myHighlightProperty;
255
256   //----------------------------------------------------------------------------
257   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
258   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
259   double myTrihedronSize;
260   bool myIsTrihedronRelative;
261   double myBndBox[6];
262 };
263
264 #ifdef WIN32
265 #pragma warning ( default:4251 )
266 #endif
267
268 #endif