Salome HOME
ce571c82b2debbfd006194915b8fd2ed50ce2c76
[modules/visu.git] / src / PIPELINE / VISU_SphereWidget.hxx
1 //  Copyright (C) 2007-2008  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 #ifndef __VISU_SphereWidget_h
23 #define __VISU_SphereWidget_h
24
25 #include "VISUPipeline.hxx"
26 #include "VISU_ImplicitFunctionWidget.hxx"
27
28 class VISU_UnScaledActor;
29
30 class vtkActor;
31 class vtkPolyDataMapper;
32 class vtkPoints;
33 class vtkPolyData;
34 class vtkSphereSource;
35 class vtkSphere;
36 class vtkCellPicker;
37 class vtkProperty;
38 class vtkSphere;
39 class vtkImplicitSum;
40 class vtkImplicitFunction;
41 //
42 class VISU_PIPELINE_EXPORT VISU_SphereWidget : public VISU_ImplicitFunctionWidget
43 {
44 public:
45   // Description:
46   // Instantiate the object.
47   static VISU_SphereWidget *New();
48   vtkTypeRevisionMacro(VISU_SphereWidget,VISU_ImplicitFunctionWidget);
49   void PrintSelf(ostream& os, vtkIndent indent);
50
51   virtual vtkImplicitFunction* ImplicitFunction();
52   
53   // Description:
54   // Methods that satisfy the superclass' API.
55   virtual void SetEnabled(int);
56   //
57   //PlaceWidget
58   virtual void PlaceWidget(vtkFloatingPointType bounds[6]);
59   //
60   // Description:
61   // Set/Get the resolution of the sphere in the Theta direction.
62   void SetThetaResolution(int r);
63   int GetThetaResolution(); 
64   // Description:
65   // Set/Get the resolution of the sphere in the Phi direction.
66   void SetPhiResolution(int r);
67   int GetPhiResolution();
68
69   // Description:
70   // Set/Get the radius of sphere. Default is .5.
71   void SetRadius(vtkFloatingPointType r); 
72   vtkFloatingPointType GetRadius();
73   
74
75   // Description:
76   // Set/Get the center of the sphere.
77   void SetCenter(vtkFloatingPointType x, 
78                  vtkFloatingPointType y, 
79                  vtkFloatingPointType z); 
80   void SetCenter(vtkFloatingPointType x[3]); 
81   
82   vtkFloatingPointType* GetCenter(); 
83   void GetCenter(vtkFloatingPointType xyz[3]); 
84   
85   // Description:
86   // Set the ratio of the radius changing.
87   void SetRatio(vtkFloatingPointType r) { myRatio = r; } 
88   vtkFloatingPointType GetRatio() { return myRatio; } 
89
90   void ChangeRadius(bool up);
91
92   void GetPolyData(vtkPolyData *pd);
93
94   void GetSphere(vtkSphere *sphere);
95
96   
97   vtkProperty* GetSphereProperty ();
98   vtkProperty* GetSelectedSphereProperty ();
99   
100     
101 protected:
102   VISU_SphereWidget();
103   ~VISU_SphereWidget();
104
105   //handles the events
106   static void ProcessEvents(vtkObject* object, 
107                             unsigned long event,
108                             void* clientdata, 
109                             void* calldata);
110
111   // ProcessEvents() dispatches to these methods.
112   void OnLeftButtonDown();
113   void OnLeftButtonUp();
114   void OnMiddleButtonDown();
115   void OnMiddleButtonUp();
116   void OnMouseMove();
117
118   void HighlightSphere(int highlight);
119
120   // Methods to manipulate the sphere widget
121   void Translate(double *p1, double *p2);
122   void Scale(double *p1, double *p2, int X, int Y);
123
124   //virtual void SizeHandles();
125   void CreateDefaultProperties();
126
127   //BTX - manage the state of the widget
128   int myState;
129   enum WidgetState
130   {
131     Start=0,
132     Moving,
133     Scaling,
134     Positioning,
135     Outside
136   };
137   //ETX
138   // the sphere
139   vtkActor       *mySphereActor;
140   vtkPolyDataMapper *mySphereMapper;
141   vtkSphereSource   *mySphereSource;
142   //
143   // the Picker
144   vtkCellPicker *myPicker;
145   // Properties used to control the appearance of selected objects and
146   // the manipulator in general.
147   vtkProperty *mySphereProperty;
148   vtkProperty *mySelectedSphereProperty;
149   vtkFloatingPointType myRmin;
150   vtkSphere *mySphere;
151   vtkImplicitSum* myImplicitSum;
152   vtkFloatingPointType myRatio;
153 private:
154   VISU_SphereWidget(const VISU_SphereWidget&);  //Not implemented
155   void operator=(const VISU_SphereWidget&);  //Not implemented
156 };
157
158 #endif