Salome HOME
Fix for Bug IPAL8945
[modules/visu.git] / src / PIPELINE / VISU_PlanesWidget.hxx
1 //  SALOME VTKViewer : build VTK viewer into Salome desktop
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : VISU_PlanesWidget.h
25 //  Author : Peter KURNEV
26 //  Module : SALOME
27 //  $Header$
28
29 #ifndef __VISU_PlanesWidget_h
30 #define __VISU_PlanesWidget_h
31
32 #include "VISU_ImplicitFunctionWidget.hxx"
33 class vtkActor;
34 class vtkPolyDataMapper;
35 class vtkCellPicker;
36 class vtkConeSource;
37 class vtkLineSource;
38 class vtkSphereSource;
39 class vtkPlane;
40 class vtkCutter;
41 class vtkProperty;
42 class vtkImageData;
43 class vtkOutlineFilter;
44 class vtkFeatureEdges;
45 class vtkPolyData;
46 class vtkTransform;
47 class vtkImplicitBoolean;
48 class vtkImplicitFunction;
49 class VISU_UnScaledActor;
50 class vtkDataSet;
51
52 class  VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
53 {
54 public:
55   // Description:
56   // Instantiate the object.
57   static VISU_PlanesWidget *New();
58
59   vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
60   void PrintSelf(ostream& os, vtkIndent indent);
61
62   void SetDistance (const float theDistance);
63   float Distance()const;
64
65   vtkGetMacro(InitialLength,float);
66
67   virtual vtkImplicitFunction* ImplicitFunction();
68
69   // Description:
70   // Methods that satisfy the superclass' API.
71   virtual void SetEnabled(int);
72   virtual void PlaceWidget(float bounds[6]);
73
74   // Description:
75   // Get the origin of the plane.
76   void SetOrigin(float x, float y, float z);
77   void SetOrigin(float x[3]);
78   float* GetOrigin();
79   void GetOrigin(float xyz[3]);
80
81   // Description:
82   // Get the normal to the plane.
83   void SetNormal(float x, float y, float z);
84   void SetNormal(float x[3]);
85   float* GetNormal();
86   void GetNormal(float xyz[3]);
87   
88   // Description:
89   // Force the plane widget to be aligned with one of the x-y-z axes.
90   // If one axis is set on, the other two will be set off.
91   // Remember that when the state changes, a ModifiedEvent is invoked.
92   // This can be used to snap the plane to the axes if it is orginally
93   // not aligned.
94   void SetNormalToXAxis(int);
95   vtkGetMacro(NormalToXAxis,int);
96   vtkBooleanMacro(NormalToXAxis,int);
97   void SetNormalToYAxis(int);
98   vtkGetMacro(NormalToYAxis,int);
99   vtkBooleanMacro(NormalToYAxis,int);
100   void SetNormalToZAxis(int);
101   vtkGetMacro(NormalToZAxis,int);
102   vtkBooleanMacro(NormalToZAxis,int);
103
104   // Description:
105   // Turn on/off tubing of the wire outline of the plane. The tube thickens
106   // the line by wrapping with a vtkTubeFilter.
107   //vtkSetMacro(Tubing,int);
108   //vtkGetMacro(Tubing,int);
109   //vtkBooleanMacro(Tubing,int);
110
111   // Description:
112   // Enable/disable the drawing of the plane. In some cases the plane
113   // interferes with the object that it is operating on (i.e., the
114   // plane interferes with the cut surface it produces producing
115   // z-buffer artifacts.)
116   void SetDrawPlane(int plane);
117   int GetDrawPlane(){
118     return myDrawPlane;
119   }
120
121   // Description:
122   // Turn on/off the ability to translate the bounding box by grabbing it
123   // with the left mouse button.
124   vtkSetMacro(OutlineTranslation,int);
125   vtkGetMacro(OutlineTranslation,int);
126   vtkBooleanMacro(OutlineTranslation,int);
127
128   // Description:
129   // Grab the polydata that defines the plane. The polydata contains a single
130   // polygon that is clipped by the bounding box.
131   void GetPolyData(vtkPolyData *pd);
132
133   // Description:
134   // Satisfies superclass API.  This returns a pointer to the underlying
135   // PolyData (which represents the plane).
136   //vtkPolyDataSource* GetPolyDataSource();
137    
138   // Description:
139   // Get the implicit function for the plane. The user must provide the
140   // instance of the class vtkPlane. Note that vtkPlane is a subclass of
141   // vtkImplicitFunction, meaning that it can be used by a variety of filters
142   // to perform clipping, cutting, and selection of data.
143   void GetPlane(vtkPlane *plane);
144
145   // Description:
146   // Satisfies the superclass API.  This will change the state of the widget
147   // to match changes that have been made to the underlying PolyDataSource
148   void UpdatePlacement(void);
149
150   // Description:
151   // Get the properties on the normal (line and cone).
152   vtkGetObjectMacro(NormalProperty,vtkProperty);
153   vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
154   
155   // Description:
156   // Get the plane properties. The properties of the plane when selected 
157   // and unselected can be manipulated.
158   vtkGetObjectMacro(PlaneProperty,vtkProperty);
159   vtkGetObjectMacro(SelectedPlaneProperty,vtkProperty);
160
161   // Description:
162   // Get the property of the outline.
163   vtkGetObjectMacro(OutlineProperty,vtkProperty);
164   vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
165
166   // Description:
167   // Get the property of the intersection edges. (This property also
168   // applies to the edges when tubed.)
169   vtkGetObjectMacro(EdgesProperty,vtkProperty);
170
171   void InitialPlaceWidget(float bds[6]);
172
173 protected:
174   VISU_PlanesWidget();
175   ~VISU_PlanesWidget();
176
177 //BTX - manage the state of the widget
178   int State;
179   enum WidgetState
180   {
181     Start=0,
182     MovingPlane,
183     MovingOutline,
184     MovingOrigin,
185     Scaling,
186     Pushing,
187     Rotating,
188     Outside,
189     ChangeDistance
190   };
191 //ETX
192     
193   //handles the events
194   static void ProcessEvents(vtkObject* object, unsigned long event,
195                             void* clientdata, void* calldata);
196
197   // ProcessEvents() dispatches to these methods.
198   void OnLeftButtonDown();
199   void OnLeftButtonUp();
200   void OnMiddleButtonDown();
201   void OnMiddleButtonUp();
202   void OnRightButtonDown();
203   void OnRightButtonUp();
204   void OnMouseMove();
205   //
206   // Methods to manipulate the plane
207   void ConstrainOrigin(float x[3]);
208   void Rotate(int X, int Y, double *p1, double *p2, double *vpn);
209   void TranslatePlane(double *p1, double *p2);
210   void TranslateOutline(double *p1, double *p2);
211   void TranslateOrigin(double *p1, double *p2);
212   void Push(double *p1, double *p2);
213   void Scale(double *p1, double *p2, int X, int Y);
214   void PushDistance(double *p1, double *p2);
215
216   void CreateDefaultProperties();
217   
218   void GeneratePlane();
219   //virtual void SizeHandles();
220   void HighlightPlane(int highlight);
221   void HighlightNormal(int highlight);
222   void HighlightOutline(int highlight);
223   void UpdateRepresentation();
224   void SetOriginInternal(float x[3]);
225
226   // Controlling ivars
227   int NormalToXAxis;
228   int NormalToYAxis;
229   int NormalToZAxis;
230   
231
232   // Flags to handle mouse events
233   bool HandleMoveEvent;
234   bool HandleLeftButtonEvent;
235   bool HandleMiddleButtonEvent;
236   bool HandleRightButtonEvent;
237   // The actual plane which is being manipulated
238   vtkPlane *myPlane1;
239   vtkPlane *myPlane2;
240   
241   float myDistance; 
242   vtkImplicitBoolean *myImplicitFunction;
243
244   // The bounding box is represented by a single voxel image data
245   vtkImageData      *myBox;
246   vtkOutlineFilter  *myOutline;
247   vtkPolyDataMapper *myOutlineMapper;
248   vtkActor          *myOutlineActor;
249   
250   int OutlineTranslation; //whether the outline can be moved
251   
252   // The cut plane is produced with a vtkCutter
253   vtkCutter         *myCutter1;
254   vtkPolyDataMapper *myCutMapper1;
255   vtkActor          *myCutActor1;
256
257   vtkCutter         *myCutter2;
258   vtkPolyDataMapper *myCutMapper2;
259   vtkActor          *myCutActor2;
260   
261   vtkFeatureEdges   *myEdges2;
262   vtkPolyDataMapper *myEdgesMapper2;
263   vtkActor          *myEdgesActor2;
264
265   int               myDrawPlane;
266
267   vtkFeatureEdges   *myEdges1;
268   vtkPolyDataMapper *myEdgesMapper1;
269   vtkActor          *myEdgesActor1;
270
271   // The + normal cone
272   vtkConeSource      *ConeSource;
273   vtkPolyDataMapper  *ConeMapper;
274   VISU_UnScaledActor *ConeActor;
275   // The + normal line
276   vtkLineSource     *LineSource;
277   vtkPolyDataMapper *LineMapper;
278   vtkActor          *LineActor;
279   // The - normal cone
280   vtkConeSource      *ConeSource2;
281   vtkPolyDataMapper  *ConeMapper2;
282   VISU_UnScaledActor *ConeActor2;
283   // The - normal line
284   vtkLineSource     *LineSource2;
285   vtkPolyDataMapper *LineMapper2;
286   vtkActor          *LineActor2;
287   // The origin positioning handle
288   vtkSphereSource    *Sphere;
289   vtkPolyDataMapper  *SphereMapper;
290   VISU_UnScaledActor *SphereActor;
291
292   // Do the picking
293   vtkCellPicker *Picker;
294   
295   // Transform the normal (used for rotation)
296   vtkTransform *Transform;
297   // Properties used to control the appearance of selected objects and
298   // the manipulator in general.
299   vtkProperty *NormalProperty;
300   vtkProperty *SelectedNormalProperty;
301   vtkProperty *PlaneProperty;
302   vtkProperty *SelectedPlaneProperty;
303   vtkProperty *OutlineProperty;
304   vtkProperty *SelectedOutlineProperty;
305   vtkProperty *EdgesProperty;
306   
307 private:
308   VISU_PlanesWidget(const VISU_PlanesWidget&);  //Not implemented
309   void operator=(const VISU_ImplicitFunctionWidget&);  //Not implemented
310 };
311
312 #endif