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