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