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