Salome HOME
c07aa4df950896efa016ad21ca249b95cfd47225
[modules/gui.git] / src / VTKViewer / VTKViewer_Trihedron.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 #ifndef VTKVIEWER_TRIHEDRON_H
24 #define VTKVIEWER_TRIHEDRON_H
25
26 #include "VTKViewer.h"
27
28 #include <vtkObject.h>
29 #include <vtkFollower.h>
30
31 class vtkRenderer;
32 class vtkActorCollection;
33 class vtkCamera;
34 class vtkProperty;
35 class vtkPolyDataMapper;
36 class vtkLineSource;
37 class vtkConeSource;
38 class vtkVectorText;
39 class vtkTextActor;
40 class vtkTextMapper;
41
42 class VTKViewer_Axis;
43
44 #if !defined(VTK_XVERSION)
45 #define VTK_XVERSION (VTK_MAJOR_VERSION<<16)+(VTK_MINOR_VERSION<<8)+(VTK_BUILD_VERSION)
46 #endif
47
48 // VTKViewer_UnScaledActor is temporarily replaced with simple vtkTextActor
49 // This workaround caused by the bug with disappeared labels of the trihedron
50 // reproduced after migration from qt-4.4.3 to qt-4.5.2
51 #if (VTK_XVERSION < 0x050200)
52 #define IPAL21440
53 #endif
54
55 /*! \class vtkFollower
56  * See <a href="http://www.vtk.org/">vtk documentation</a>
57  */
58 /*!a subclass of actor that always faces the camera
59  *@see vtkFollower
60  */
61 class VTKVIEWER_EXPORT VTKViewer_UnScaledActor: public vtkFollower
62 {
63   VTKViewer_UnScaledActor(const VTKViewer_UnScaledActor&);
64   
65 public:
66   
67   vtkTypeMacro(VTKViewer_UnScaledActor,vtkFollower);
68   
69   /*!Create new instance of VTKViewer_UnScaledActor.*/
70   static VTKViewer_UnScaledActor *New();
71   
72   virtual vtkFloatingPointType* GetBounds();
73   virtual void SetSize(int theSize);
74   virtual void Render(vtkRenderer *theRenderer);
75
76 protected:
77   VTKViewer_UnScaledActor();
78   /*!Destructor. Do nothing.*/
79   ~VTKViewer_UnScaledActor(){}
80   
81   int mySize;
82 };
83
84 /*!a subclass of actor that always faces the camera
85  *@see vtkFollower
86  */
87 class VTKVIEWER_EXPORT VTKViewer_LineActor: public vtkFollower
88 {
89   VTKViewer_LineActor(const VTKViewer_LineActor&);
90   
91 public:
92   /*!vtk type macros.*/
93   vtkTypeMacro(VTKViewer_LineActor,vtkFollower);
94   
95   /*!Create new instance of VTKViewer_LineActor.*/
96   static VTKViewer_LineActor *New();
97   
98 #ifdef IPAL21440
99   /*! Sets Label actor.
100    * \param theLabelActor - vtkTextActor
101    */
102   void SetLabelActor(vtkTextActor* theLabelActor);
103 #else
104   /*! Sets Label actor.
105    * \param theLabelActor - VTKViewer_UnScaledActor
106    */
107   void SetLabelActor(VTKViewer_UnScaledActor* theLabelActor);
108 #endif
109   
110   /*! Sets Arrow actor.
111    * \param theLabelActor - VTKViewer_UnScaledActor
112    */
113   void SetArrowActor(vtkFollower* theArrowActor);
114
115   virtual void Render(vtkRenderer *theRenderer);
116   
117 protected:
118   
119   /*! Constructor which sets \a LabelActor and \a ArrowActor to NULL*/
120   VTKViewer_LineActor(){
121     LabelActor = NULL;
122     ArrowActor = NULL;
123   }
124
125   /*!Destructor which call SetLabelActor(NULL) and SetArrowActor(NULL)*/
126   ~VTKViewer_LineActor(){
127     SetLabelActor(NULL);
128     SetArrowActor(NULL);
129   }
130
131   /*!Label actor pointer*/
132 #ifdef IPAL21440
133   vtkTextActor* LabelActor;
134 #else
135   VTKViewer_UnScaledActor* LabelActor;
136 #endif
137
138   /*!Arrow actor pointer*/
139   vtkFollower* ArrowActor;
140 };
141
142 /*!This class provide support trihedron object in vtk viewer.*/
143 class VTKVIEWER_EXPORT VTKViewer_Trihedron : public vtkObject
144 {
145 protected:
146   /*!Initialize fields by default values.*/
147   VTKViewer_Trihedron();
148   
149   /*!Const copy constructor.*/
150   VTKViewer_Trihedron(const VTKViewer_Trihedron&);
151
152   /*!Destructor. Remove all fileds.*/
153   virtual ~VTKViewer_Trihedron();
154
155 public:
156   /*!vtk type macros.*/
157   vtkTypeMacro(VTKViewer_Trihedron,vtkObject);
158   
159   /*!Create new instance of VTKViewer_Trihedron.*/
160   static VTKViewer_Trihedron *New();
161   
162   /*!Sets size of trihedron.
163    * \param theSize - vtkFloatingPointType value
164    */
165   virtual void        SetSize(vtkFloatingPointType theSize);
166
167   /*! Get size of trihedron.
168    * \retval mySize - vtkFloatingPointType value
169    */
170   virtual vtkFloatingPointType  GetSize() { return mySize;}
171   
172   enum TVisibility{eOff, eOn, eOnlyLineOn};
173   
174   /*! Sets visibility for all Axis to \a theVis*/
175   virtual void        SetVisibility(TVisibility theVis);
176   
177   /*! OFF visibility for all Axis.*/
178   virtual void        VisibilityOff() { SetVisibility(eOff);}
179
180   /*! ON visibility for all Axis.*/
181   virtual void        VisibilityOn() { SetVisibility(eOn);}
182
183   /*! Gets visibility of myAxis[0] actor.*/
184   virtual TVisibility GetVisibility();
185   
186   /*! Add to render all Axis
187    * \param theRenderer - vtkRenderer pointer
188    */
189   virtual void        AddToRender(vtkRenderer* theRenderer);
190   
191   /*! Remove all actors from \a theRenderer which are in myPresent.
192    * \param theRenderer - vtkRenderer pointer
193    */
194   virtual void        RemoveFromRender(vtkRenderer* theRenderer);
195   
196   /*! Return count of visible actors.
197    * \param theRenderer - vtkRenderer pointer
198    */
199   virtual int         GetVisibleActorCount(vtkRenderer* theRenderer);
200   
201   /*! Check if actor belongs to the trihedron object
202    * \param theActor - vtkActor pointer
203    * \retval Return true if the actor belongs to the trihedron object
204    */
205   virtual bool        OwnActor(const vtkActor* theActor);
206
207 protected:
208   /*! Actor collection*/
209   vtkActorCollection* myPresent;
210   
211   /*! \li myAxis[0] - X Axis actor
212    *  \li myAxis[1] - Y Axis actor
213    *  \li myAxis[2] - Z Axis actor
214    */
215   VTKViewer_Axis*     myAxis[3];
216   
217   /*! Common size for trihedron, for each axis.*/
218   vtkFloatingPointType mySize;
219 };
220
221 /*!The base class for concreate Axis.
222  * Its only duty is to give correct initialization and destruction
223  * of its pipe-lines
224  */
225 class VTKVIEWER_EXPORT VTKViewer_Axis : public vtkObject
226 {
227 protected:
228   VTKViewer_Axis();
229   VTKViewer_Axis(const VTKViewer_Axis&);
230   virtual ~VTKViewer_Axis();
231   
232 public:
233   /*!vtk type macros.*/
234   vtkTypeMacro(VTKViewer_Axis,vtkObject);
235   
236   /*! Add to \a theRenderer actors: myLineActor,myLabelActor,myArrowActor
237    */
238   virtual void AddToRender(vtkRenderer* theRenderer);
239   virtual void RemoveFromRender(vtkRenderer* theRenderer);
240   
241   /*! Sets visibility for actors: myLineActor,myLabelActor,myArrowActor
242    */
243   virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
244   
245   /*! Return visibility of VTKViewer_Axis
246    * \retval myVisibility
247    */
248   virtual VTKViewer_Trihedron::TVisibility GetVisibility() { return myVisibility; }
249   
250   /*! Set camera for myLabelActor
251    */
252   virtual void SetCamera(vtkCamera* theCamera);
253
254   /*! Sets color for actors: myLineActor,myLabelActor,myArrowActor
255    * \param theRed - red component of the color
256    * \param theGreen - green component of the color
257    * \param theBlue - blue component of the color
258    */
259   virtual void SetColor(double theRed, double theGreen, double theBlue);
260   
261   /*! Set size of VTKViewer_Axis
262    */
263   virtual void SetSize(vtkFloatingPointType theSize);
264   
265   /*! Get label actor.
266    * \retval Return myLabelActor.
267    */
268 #ifdef IPAL21440
269   virtual vtkTextActor* GetLabel() { return myLabelActor; }
270 #else
271   virtual VTKViewer_UnScaledActor* GetLabel() { return myLabelActor; }
272 #endif
273   
274   /*! Get arrow actor.
275    * \retval Return myArrowActor
276    */
277   virtual vtkFollower* GetArrow() { return myArrowActor; }
278
279   /*! Check if actor belongs to the axis object
280    * \param theActor - vtkActor pointer
281    * \retval Return true if the actor belongs to the axis object
282    */
283   virtual bool OwnActor(const vtkActor* theActor);
284   
285 protected:
286   /*! Visibility flag.
287    */
288   VTKViewer_Trihedron::TVisibility myVisibility;
289
290   /*! \var myDir[3]
291    * Direction vector
292    */
293   /*! \var myRot[3]
294    * Orientation vector
295    */
296   vtkFloatingPointType myDir[3], myRot[3];
297   
298   /*! VTKViewer_LineActor actor pointer
299    */
300   VTKViewer_LineActor *myLineActor;
301
302   /*! vtkFollower actor pointer
303    */
304   vtkFollower *myArrowActor;
305
306   /*! VTKViewer_UnScaledActor actor pointer
307    */
308 #ifdef IPAL21440
309   vtkTextActor *myLabelActor;
310 #else
311   VTKViewer_UnScaledActor *myLabelActor;
312 #endif
313   
314   /*! \li myMapper[0] - for the Line pipe-line representation
315    *  \li myMapper[1] - for the Arrow pipe-line representation
316    *  \li myMapper[2] - for the Label pipe-line representation
317    */
318   vtkPolyDataMapper *myMapper[3];
319
320   /*! vtkLineSource pointer (Line)
321    */
322   vtkLineSource *myLineSource;
323
324   /*! vtkConeSource pointer (Arrow)
325    */
326   vtkConeSource *myConeSource;
327
328 #ifdef IPAL21440
329   /*! vtkTextMapper pointer (Label)
330    */
331   vtkTextMapper *myTextMapper;
332 #else
333   /*! VTKViewer_VectorText pointer (Label)
334    */
335   vtkVectorText* myVectorText;
336 #endif
337 };
338
339 #endif