Salome HOME
Copyrights update
[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/
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
35 class VTKViewer_Axis;
36 class VTKViewer_VectorText;
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 float* 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 //****************************************************************
115 /*!This class provide support trihedron object in vtk viewer.*/
116 class VTKVIEWER_EXPORT VTKVIEWER_EXPORT VTKViewer_Trihedron : public vtkObject
117 {
118 protected:
119   /*!Initialize fields by default values.*/
120   VTKViewer_Trihedron();
121   
122   /*!Const copy constructor.*/
123   VTKViewer_Trihedron(const VTKViewer_Trihedron&);
124
125   /*!Destructor. Remove all fileds.*/
126   virtual ~VTKViewer_Trihedron();
127
128 public:
129   /*!vtk type macros.*/
130   vtkTypeMacro(VTKViewer_Trihedron,vtkObject);
131   
132   /*!Create new instance of VTKViewer_Trihedron.*/
133   static VTKViewer_Trihedron *New();
134   
135   /*!Sets size of trihedron.
136    * \param theSize - float value
137    */
138   virtual void        SetSize(float theSize);
139
140   /*! Get size of trihedron.
141    * \retval mySize - float value
142    */
143   virtual float       GetSize() { return mySize;}
144   
145   enum TVisibility{eOff, eOn, eOnlyLineOn};
146   
147   /*! Sets visibility for all Axis to \a theVis*/
148   virtual void        SetVisibility(TVisibility theVis);
149   
150   /*! OFF visibility for all Axis.*/
151   virtual void        VisibilityOff() { SetVisibility(eOff);}
152
153   /*! ON visibility for all Axis.*/
154   virtual void        VisibilityOn() { SetVisibility(eOn);}
155
156   /*! Gets visibility of myAxis[0] actor.*/
157   virtual TVisibility GetVisibility();
158   
159   /*! Add to render all Axis
160    * \param theRenderer - vtkRenderer pointer
161    */
162   virtual void        AddToRender(vtkRenderer* theRenderer);
163   
164   /*! Remove all actors from \a theRenderer which are in myPresent.
165    * \param theRenderer - vtkRenderer pointer
166    */
167   virtual void        RemoveFromRender(vtkRenderer* theRenderer);
168   
169   /*! Return count of visible actors.
170    * \param theRenderer - vtkRenderer pointer
171    */
172   virtual int         GetVisibleActorCount(vtkRenderer* theRenderer);
173   
174 protected:
175   /*! Actor collection*/
176   vtkActorCollection* myPresent;
177   
178   /*! \li myAxis[0] - X Axis actor
179    *  \li myAxis[1] - Y Axis actor
180    *  \li myAxis[2] - Z Axis actor
181    */
182   VTKViewer_Axis*     myAxis[3];
183   
184   /*! Common size for trihedron, for each axis.*/
185   float               mySize;
186 };
187
188 //****************************************************************
189 /*!The base class for concreate Axis.
190  * Its only duty is to give correct initialization and destruction
191  * of its pipe-lines
192  */
193 class VTKVIEWER_EXPORT VTKViewer_Axis : public vtkObject
194 {
195 protected:
196   VTKViewer_Axis();
197   VTKViewer_Axis(const VTKViewer_Axis&);
198   virtual ~VTKViewer_Axis();
199   
200 public:
201   /*!vtk type macros.*/
202   vtkTypeMacro(VTKViewer_Axis,vtkObject);
203   
204   /*! Add to \a theRenderer actors: myLineActor,myLabelActor,myArrowActor
205    */
206   virtual void AddToRender(vtkRenderer* theRenderer);
207   virtual void RemoveFromRender(vtkRenderer* theRenderer);
208   
209   /*! Sets visibility for actors: myLineActor,myLabelActor,myArrowActor
210    */
211   virtual void SetVisibility(VTKViewer_Trihedron::TVisibility theVis);
212   
213   /*! Return visibility of VTKViewer_Axis
214    * \retval myVisibility
215    */
216   virtual VTKViewer_Trihedron::TVisibility GetVisibility() { return myVisibility; }
217   
218   /*! Set camera for myLabelActor
219    */
220   virtual void SetCamera(vtkCamera* theCamera);
221
222   /*! Sets \a theProperty for actors: myLineActor,myLabelActor,myArrowActor
223    */
224   virtual void SetProperty(vtkProperty* theProperty);
225   
226   /*! Set size of VTKViewer_Axis
227    */
228   virtual void SetSize(float theSize);
229   
230   /*! Get label actor.
231    * \retval Return myLabelActor.
232    */
233   virtual VTKViewer_UnScaledActor* GetLabel() { return myLabelActor; }
234   
235   /*! Get arrow actor.
236    * \retval Return myArrowActor
237    */
238   virtual VTKViewer_UnScaledActor* GetArrow() { return myArrowActor; }
239   
240 protected:
241   /*! Visibility flag.
242    */
243   VTKViewer_Trihedron::TVisibility myVisibility;
244
245   /*! \var myDir[3]
246    * Direction vector
247    */
248   /*! \var myRot[3]
249    * Orientation vector
250    */
251   float myDir[3], myRot[3];
252   
253   /*! VTKViewer_LineActor actor pointer
254    */
255   VTKViewer_LineActor *myLineActor;
256
257   /*! VTKViewer_UnScaledActor actor pointer
258    */
259   VTKViewer_UnScaledActor *myArrowActor;
260
261   /*! VTKViewer_UnScaledActor actor pointer
262    */
263   VTKViewer_UnScaledActor *myLabelActor;
264   
265   /*! \li myMapper[0] - for the Line pipe-line representation
266    *  \li myMapper[1] - for the Arrow pipe-line representation
267    *  \li myMapper[2] - for the Label pipe-line representation
268    */
269   vtkPolyDataMapper *myMapper[3];
270
271   /*! vtkLineSource pointer (Line)
272    */
273   vtkLineSource *myLineSource;
274
275   /*! vtkConeSource pointer (Arrow)
276    */
277   vtkConeSource *myConeSource;
278
279   /*! VTKViewer_VectorText pointer (Label)
280    */
281   VTKViewer_VectorText* myVectorText;
282 };
283
284 #endif