1 // SALOME VTKViewer : build VTK viewer into Salome desktop
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : VISU_PlanesWidget.h
25 // Author : Peter KURNEV
29 #ifndef __VISU_PlanesWidget_h
30 #define __VISU_PlanesWidget_h
32 #include "VISU_ImplicitFunctionWidget.hxx"
34 class vtkPolyDataMapper;
38 class vtkSphereSource;
43 class vtkOutlineFilter;
44 class vtkFeatureEdges;
47 class vtkImplicitBoolean;
48 class vtkImplicitFunction;
49 class VISU_UnScaledActor;
52 class VISU_PlanesWidget : public VISU_ImplicitFunctionWidget
56 // Instantiate the object.
57 static VISU_PlanesWidget *New();
59 vtkTypeRevisionMacro(VISU_PlanesWidget,VISU_ImplicitFunctionWidget);
60 void PrintSelf(ostream& os, vtkIndent indent);
62 void SetDistance (const float theDistance);
63 float Distance()const;
65 vtkGetMacro(InitialLength,float);
67 virtual vtkImplicitFunction* ImplicitFunction();
70 // Methods that satisfy the superclass' API.
71 virtual void SetEnabled(int);
72 virtual void PlaceWidget(float bounds[6]);
75 // Get the origin of the plane.
76 void SetOrigin(float x, float y, float z);
77 void SetOrigin(float x[3]);
79 void GetOrigin(float xyz[3]);
82 // Get the normal to the plane.
83 void SetNormal(float x, float y, float z);
84 void SetNormal(float x[3]);
86 void GetNormal(float xyz[3]);
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
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);
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);
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);
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);
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);
134 // Satisfies superclass API. This returns a pointer to the underlying
135 // PolyData (which represents the plane).
136 //vtkPolyDataSource* GetPolyDataSource();
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);
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);
151 // Get the properties on the normal (line and cone).
152 vtkGetObjectMacro(NormalProperty,vtkProperty);
153 vtkGetObjectMacro(SelectedNormalProperty,vtkProperty);
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);
162 // Get the property of the outline.
163 vtkGetObjectMacro(OutlineProperty,vtkProperty);
164 vtkGetObjectMacro(SelectedOutlineProperty,vtkProperty);
167 // Get the property of the intersection edges. (This property also
168 // applies to the edges when tubed.)
169 vtkGetObjectMacro(EdgesProperty,vtkProperty);
171 void InitialPlaceWidget(float bds[6]);
175 ~VISU_PlanesWidget();
177 //BTX - manage the state of the widget
194 static void ProcessEvents(vtkObject* object, unsigned long event,
195 void* clientdata, void* calldata);
197 // ProcessEvents() dispatches to these methods.
198 void OnLeftButtonDown();
199 void OnLeftButtonUp();
200 void OnMiddleButtonDown();
201 void OnMiddleButtonUp();
202 void OnRightButtonDown();
203 void OnRightButtonUp();
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);
216 void CreateDefaultProperties();
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]);
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
242 vtkImplicitBoolean *myImplicitFunction;
244 // The bounding box is represented by a single voxel image data
246 vtkOutlineFilter *myOutline;
247 vtkPolyDataMapper *myOutlineMapper;
248 vtkActor *myOutlineActor;
250 int OutlineTranslation; //whether the outline can be moved
252 // The cut plane is produced with a vtkCutter
253 vtkCutter *myCutter1;
254 vtkPolyDataMapper *myCutMapper1;
255 vtkActor *myCutActor1;
257 vtkCutter *myCutter2;
258 vtkPolyDataMapper *myCutMapper2;
259 vtkActor *myCutActor2;
261 vtkFeatureEdges *myEdges2;
262 vtkPolyDataMapper *myEdgesMapper2;
263 vtkActor *myEdgesActor2;
267 vtkFeatureEdges *myEdges1;
268 vtkPolyDataMapper *myEdgesMapper1;
269 vtkActor *myEdgesActor1;
272 vtkConeSource *ConeSource;
273 vtkPolyDataMapper *ConeMapper;
274 VISU_UnScaledActor *ConeActor;
276 vtkLineSource *LineSource;
277 vtkPolyDataMapper *LineMapper;
280 vtkConeSource *ConeSource2;
281 vtkPolyDataMapper *ConeMapper2;
282 VISU_UnScaledActor *ConeActor2;
284 vtkLineSource *LineSource2;
285 vtkPolyDataMapper *LineMapper2;
286 vtkActor *LineActor2;
287 // The origin positioning handle
288 vtkSphereSource *Sphere;
289 vtkPolyDataMapper *SphereMapper;
290 VISU_UnScaledActor *SphereActor;
293 vtkCellPicker *Picker;
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;
308 VISU_PlanesWidget(const VISU_PlanesWidget&); //Not implemented
309 void operator=(const VISU_ImplicitFunctionWidget&); //Not implemented