Salome HOME
more orthography
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_ClippingDlg.h
1 // Copyright (C) 2007-2013  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 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_ClippingDlg.h
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_CLIPPINGDLG_H
28 #define SMESHGUI_CLIPPINGDLG_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32
33 // SALOME includes
34 #include <SVTK_ViewWindow.h>
35
36 // Qt includes
37 #include <QDialog>
38 #include <QPointer>
39
40 // VTK includes
41 #include <vtkPlane.h>
42 #include <vtkSmartPointer.h>
43
44 // STL includes
45 #include <list>
46 #include <map>
47 #include <vector>
48
49 class QGroupBox;
50 class QLabel;
51 class QPushButton;
52 class QCheckBox;
53 class QComboBox;
54 class QListWidget;
55 class QListWidgetItem;
56 class QStackedLayout;
57 class QSlider;
58 class QMenu;
59 class SALOME_Actor;
60 class SMESHGUI;
61 class SMESH_Actor;
62 class QtxDoubleSpinBox;
63 class vtkActor;
64 class vtkDataSetMapper;
65 class vtkPlaneSource;
66 class vtkCallbackCommand;
67 class vtkObject;
68 class vtkImplicitPlaneWidget;
69
70 namespace SMESH
71 {
72   enum Mode { Absolute, Relative };
73   enum Orientation { XY, YZ, ZX };
74
75   class OrientedPlane: public vtkPlane
76   {
77     vtkDataSetMapper* myMapper;
78
79     public:
80       static OrientedPlane *New();
81       static OrientedPlane *New(SVTK_ViewWindow* theViewWindow);
82       vtkTypeMacro (OrientedPlane, vtkPlane);
83
84       QPointer<SVTK_ViewWindow> myViewWindow;
85       SMESH::Orientation myRelativeOrientation;
86       float myDistance;
87       double myAngle[2];
88       double X, Y, Z, Dx, Dy, Dz;
89       int myAbsoluteOrientation;
90       bool IsInvert;
91       bool IsOpenGLClipping;
92       Mode PlaneMode;
93
94       vtkPlaneSource* myPlaneSource;
95       SALOME_Actor *myActor;
96
97       void SetOrientation (SMESH::Orientation theOrientation) { myRelativeOrientation = theOrientation; }
98       SMESH::Orientation GetOrientation() { return myRelativeOrientation; }
99
100       void SetDistance (float theDistance) { myDistance = theDistance; }
101       float GetDistance() { return myDistance; }
102
103       void ShallowCopy (OrientedPlane* theOrientedPlane);
104       OrientedPlane* InvertPlane ();
105
106     protected:
107       OrientedPlane(SVTK_ViewWindow* theViewWindow);
108       OrientedPlane();
109
110       void Init();
111
112       ~OrientedPlane();
113     private:
114       // Not implemented.
115       OrientedPlane (const OrientedPlane&);
116       void operator= (const OrientedPlane&);
117   };
118
119   typedef vtkSmartPointer<OrientedPlane>    TPlane;
120   typedef std::list<vtkActor*>              TActorList;
121
122   struct TPlaneData
123   {
124     TPlaneData( TPlane thePlane,
125                 TActorList theActorList )
126     {
127       Plane = thePlane;
128       ActorList = theActorList;
129     }
130     TPlane     Plane;
131     TActorList ActorList;
132   };
133
134   typedef std::vector<TPlane>               TPlaneVector;
135   typedef std::vector<TPlaneData>           TPlaneDataVector;
136 };
137
138 //=================================================================================
139 // class    : SMESHGUI_ClippingDlg
140 // purpose  :
141 //=================================================================================
142 class SMESHGUI_EXPORT SMESHGUI_ClippingDlg : public QDialog
143 {
144   Q_OBJECT
145
146 public:
147   SMESHGUI_ClippingDlg( SMESHGUI*, SVTK_ViewWindow* );
148   ~SMESHGUI_ClippingDlg();
149
150   static bool AddPlane ( SMESH::TActorList          theActorList,
151                          SMESH::OrientedPlane*      thePlane );
152 protected:
153   void        keyPressEvent( QKeyEvent* );
154   static void ProcessEvents( vtkObject* theObject,
155                              unsigned long theEvent,
156                              void* theClientData,
157                              void* theCallData);
158 private:
159   double  getDistance() const;
160   void    setDistance( const double );
161   double  getRotation1() const;
162   double  getRotation2() const;
163   void    setRotation( const double, const double );
164
165   void    setOrigin(double theVal[3]);
166   void    setDirection(double theVal[3]);
167
168   void    initializePlaneData();
169   void    initParam();
170   void    synchronize();
171   void    updateActorList();
172   void    updateActorItem( QListWidgetItem* theItem,
173                            bool theUpdateSelectAll,
174                            bool theUpdateClippingPlaneMap );
175   SMESH::TActorList getCurrentActors();
176
177   void    dumpPlaneData() const;
178   void    absolutePlaneToRelative ( double theOrigin[3], double theDir[3] );
179   void    setBoundsForPreviewWidget();
180   vtkImplicitPlaneWidget* createPreviewWidget();
181
182
183 private:
184   SMESHGUI*               mySMESHGUI;
185   SVTK_ViewWindow*        myViewWindow;
186   SMESH::TPlaneDataVector myPlanes;
187
188   vtkCallbackCommand*     myCallback;
189   vtkImplicitPlaneWidget* myPreviewWidget;
190   double                  myBounds[6];
191   
192   QComboBox*              ComboBoxPlanes;
193   QCheckBox*              isOpenGLClipping;
194   QPushButton*            buttonNew;
195   QMenu*                  MenuMode;
196   QPushButton*            buttonDelete;
197
198   QListWidget*            ActorList;
199   QCheckBox*              SelectAllCheckBox;
200
201   QStackedLayout*         ModeStackedLayout;
202
203   QGroupBox*              GroupAbsolutePoint;
204   QLabel*                 TextLabelX;
205   QLabel*                 TextLabelY;
206   QLabel*                 TextLabelZ;
207   QtxDoubleSpinBox*       SpinBox_X;
208   QtxDoubleSpinBox*       SpinBox_Y;
209   QtxDoubleSpinBox*       SpinBox_Z;
210   QPushButton*            resetButton;
211
212   QGroupBox*              GroupAbsoluteDirection;
213   QLabel*                 TextLabelDx;
214   QLabel*                 TextLabelDy;
215   QLabel*                 TextLabelDz;
216   QtxDoubleSpinBox*       SpinBox_Dx;
217   QtxDoubleSpinBox*       SpinBox_Dy;
218   QtxDoubleSpinBox*       SpinBox_Dz;
219   QPushButton*            invertButton;
220   QComboBox*              CBAbsoluteOrientation;
221
222   QGroupBox*              GroupRelative;
223   QLabel*                 TextLabelOrientation;
224   QLabel*                 TextLabelDistance;
225   QLabel*                 TextLabelRotation1;
226   QLabel*                 TextLabelRotation2;
227   QLabel*                 TLValueDistance;
228   QLabel*                 TLValueRotation1;
229   QLabel*                 TLValueRotation2;
230   QSlider*                SliderDistance;
231   QSlider*                SliderRotation1;
232   QSlider*                SliderRotation2;
233   QComboBox*              CBRelativeOrientation;
234
235   QCheckBox*              PreviewCheckBox;
236   QCheckBox*              AutoApplyCheckBox;
237
238   QPushButton*            buttonOk;
239   QPushButton*            buttonCancel;
240   QPushButton*            buttonApply;
241   QPushButton*            buttonHelp;
242   
243   bool                    myIsSelectPlane;
244   bool                    myIsPreviewMoved;
245   QString                 myHelpFileName;
246
247   SMESH::Mode             CurrentMode;
248
249 protected slots:
250   virtual void reject();
251
252 public slots:
253   void onModeAbsolute();
254   void onModeRelative();
255   void ClickOnNew();
256   void ClickOnDelete();
257   void onSelectPlane( int );
258   void onSelectAll( int );
259   void onActorItemChanged( QListWidgetItem* );
260   void SetCurrentPlaneParam();
261
262   void onIsOpenGLClipping(bool);
263   void OnPreviewToggle( bool );
264   void onAutoApply(bool);
265   void ClickOnOk();
266   void ClickOnApply();
267   void ClickOnHelp();
268
269   void SliderDistanceHasMoved(int);
270   void SliderRotation1HasMoved(int);
271   void SliderRotation2HasMoved(int);
272   void onSelectAbsoluteOrientation( int );
273   void onSelectRelativeOrientation( int );
274   void onReset();
275   void onInvert();
276 };
277
278 #endif // SMESHGUI_CLIPPINGDLG_H