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