Salome HOME
Join modifications from branch OCC_development_for_3_2_0a2
[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, const bool theRelative = true);
131  
132   //! Get size of the trihedron in percents from bounding box of the scene
133   int  
134   GetTrihedronSize() const;
135
136   //! Shows if the size of the trihedron is relative
137   bool  
138   IsTrihedronRelative() const;
139
140   //----------------------------------------------------------------------------
141   //! Get trihedron control
142   VTKViewer_Trihedron* 
143   GetTrihedron();
144
145   //! Is trihedron displayed
146   bool 
147   IsTrihedronDisplayed();
148
149   //! Toggle trihedron visibility
150   void 
151   OnViewTrihedron(); 
152
153   //! Adjust size of the trihedron to the bounding box of the scene
154   void 
155   OnAdjustTrihedron();
156
157   //----------------------------------------------------------------------------
158   //! Get graduated rules control
159   SVTK_CubeAxesActor2D* 
160   GetCubeAxes();
161
162   //! Is graduated rules displayed
163   bool 
164   IsCubeAxesDisplayed();
165
166   //! Toggle graduated rules visibility
167   void 
168   OnViewCubeAxes();
169
170   //! Adjust size of the graduated rules to the bounding box of the scene
171   void 
172   OnAdjustCubeAxes();
173
174   //----------------------------------------------------------------------------
175   //! Fit all presentation in the scene into the window
176   void OnFitAll(); 
177   
178   //! Set camera into predefined state
179   void OnResetView(); 
180
181   //! Reset camera clipping range to adjust the range to the bounding box of the scene
182   void OnResetClippingRange(); 
183
184   //! To reset direction of the camera to front view
185   void OnFrontView(); 
186
187   //! To reset direction of the camera to back view
188   void OnBackView(); 
189
190   //! To reset direction of the camera to top view
191   void OnTopView();
192
193   //! To reset direction of the camera to bottom view
194   void OnBottomView();
195
196   //! To reset direction of the camera to right view
197   void OnRightView(); 
198
199   //! To reset direction of the camera to left view
200   void OnLeftView();     
201
202  protected:
203   SVTK_Renderer();
204   ~SVTK_Renderer();
205
206   virtual
207   bool
208   OnAdjustActors();
209
210   //----------------------------------------------------------------------------
211   // Priority at which events are processed
212   float myPriority;
213
214   // Used to process events
215   vtkSmartPointer<vtkCallbackCommand> myEventCallbackCommand;
216
217   // Description:
218   // Main process event method
219   static void ProcessEvents(vtkObject* object, 
220                             unsigned long event,
221                             void* clientdata, 
222                             void* calldata);
223   
224   vtkSmartPointer<vtkRenderer> myDevice;
225   vtkRenderWindowInteractor* myInteractor;
226   vtkSmartPointer<SVTK_Selector> mySelector;
227
228   //----------------------------------------------------------------------------
229   vtkSmartPointer<VTKViewer_Transform> myTransform;
230
231   //----------------------------------------------------------------------------
232   // Highlight/ Prehighlight devices
233   vtkSmartPointer<vtkPointPicker> myPointPicker;
234   vtkSmartPointer<vtkCellPicker> myCellPicker;
235
236   vtkSmartPointer<SVTK_RectPicker> myPointRectPicker;
237   vtkSmartPointer<SVTK_RectPicker> myCellRectPicker;
238
239   vtkSmartPointer<vtkProperty> myPreHighlightProperty;
240   vtkSmartPointer<vtkProperty> myHighlightProperty;
241
242   //----------------------------------------------------------------------------
243   vtkSmartPointer<SVTK_CubeAxesActor2D> myCubeAxes;
244   vtkSmartPointer<VTKViewer_Trihedron> myTrihedron;  
245   int  myTrihedronSize;
246   bool myIsTrihedronRelative;
247   float myBndBox[6];
248 };
249
250 #endif