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