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