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