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