Salome HOME
17f0622faca4cd64a172e91a6abe6e1c97cd387e
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 //  Copyright (C) 2007-2010  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_FilterDlg.h
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_FILTERDLG_H
28 #define SMESHGUI_FILTERDLG_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32
33 // Qt includes
34 #include <QWidget>
35 #include <QDialog>
36 #include <QMap>
37 #include <QList>
38
39 // SALOME GUI includes
40 #include <SALOME_DataMapOfIOMapOfInteger.hxx>
41 #include <SVTK_Selection.h>
42
43 // IDL includes
44 #include <SALOMEconfig.h>
45 #include CORBA_SERVER_HEADER(SMESH_Filter)
46 #include CORBA_SERVER_HEADER(SMESH_Mesh)
47
48 class QFrame;
49 class QButtonGroup;
50 class QCheckBox;
51 class QGroupBox;
52 class QPushButton;
53 class QTableWidget;
54 class QTableWidgetItem;
55 class QStackedWidget;
56 class LightApp_SelectionMgr;
57 class SMESHGUI;
58 class SMESHGUI_FilterLibraryDlg;
59 class SVTK_Selector;
60
61 /*!
62  *  Class       : SMESHGUI_FilterTable
63  *  Description : Frame containig 
64  *                  - Button group for switching entity type
65  *                  - Table for displaying filter criterions
66  *                  - Buttons for editing table
67  */
68
69 class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
70 {
71   Q_OBJECT
72
73   class Table;
74   class ComboItem;
75   class CheckItem;
76   class AdditionalWidget;
77   class ComboDelegate;
78
79   typedef QMap<int, Table*> TableMap;
80
81 public:  
82   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
83   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
84   virtual ~SMESHGUI_FilterTable();
85
86   void                      Init( const QList<int>& );
87
88   QGroupBox*                GetTableGrp();
89
90   bool                      IsValid( const bool = true, const int = -1 ) const;
91   int                       GetType() const;
92   void                      SetType(const int);
93   void                      RestorePreviousEntityType();
94   int                       NumRows( const int = -1 ) const;
95   void                      Clear( const int = -1 );
96   void                      SetEditable( const bool );
97   void                      SetEnabled( const bool );
98   void                      SetLibsEnabled( const bool );
99   bool                      IsEditable() const;
100
101   int                       GetCriterionType( const int, const int = -1 ) const;
102
103   void                      GetCriterion( const int,
104                                           SMESH::Filter::Criterion&,
105                                           const int = -1 ) const;
106
107   void                      SetCriterion( const int,
108                                           const SMESH::Filter::Criterion&,
109                                           const int = -1 );
110
111   void                      AddCriterion( const SMESH::Filter::Criterion&,
112                                           const int = -1 );
113
114   void                      Copy( const SMESHGUI_FilterTable* );
115   void                      SetValidity( const bool );
116
117   bool                      CurrentCell( int&, int& ) const;
118   void                      SetThreshold( const int,
119                                           const QString&,
120                                           const int = -1 );
121
122   bool                      GetThreshold( const int,
123                                           QString&,
124                                           const int = -1 );
125
126   void                      SetID( const int,
127                                    const QString&,
128                                    const int = -1 ); 
129   
130   bool                      GetID( const int,
131                                    QString&,
132                                    const int = -1 );
133
134   void                      Update();
135
136 signals:
137   void                      CopyFromClicked();
138   void                      AddToClicked();
139   void                      EntityTypeChanged( const int );
140   void                      NeedValidation();
141   void                      CriterionChanged( const int, const int );
142   void                      CurrentChanged( int, int );
143
144 private slots:
145   void                      onAddBtn();
146   void                      onInsertBtn();
147   void                      onRemoveBtn();
148   void                      onClearBtn();
149   void                      onCopyFromBtn();
150   void                      onAddToBtn();
151   void                      onCriterionChanged( int, int );
152   void                      onEntityType( int );
153   void                      onCurrentChanged( int, int );
154
155 private:
156   void                      addRow( Table*, const int, const bool = true );
157   QTableWidgetItem*         getCriterionItem( const int ) const;
158   QTableWidgetItem*         getCompareItem() const;
159   QTableWidgetItem*         getUnaryItem() const;
160   QTableWidgetItem*         getBinaryItem() const;
161   const QMap<int, QString>& getCriteria( const int ) const;
162   const QMap<int, QString>& getCompare() const;
163   Table*                    createTable( QWidget*, const int );
164   QWidget*                  createAdditionalFrame( QWidget* );
165   int                       getFirstSelectedRow() const;
166   void                      onCriterionChanged( const int, const int, const int );
167
168   void                      updateBtnState();
169   void                      removeAdditionalWidget( QTableWidget*, const int );
170   void                      updateAdditionalWidget();
171   const char*               getPrecision( const int );
172
173   const QMap<int, QString>& getSupportedTypes() const;
174
175 private:
176   SMESHGUI*                 mySMESHGUI;
177
178   QGroupBox*                myTableGrp;
179   QWidget*                  mySwitchTableGrp;
180
181   TableMap                  myTables;
182   QPushButton*              myAddBtn;
183   QPushButton*              myInsertBtn;
184   QPushButton*              myRemoveBtn;
185   QPushButton*              myClearBtn;  
186   QPushButton*              myCopyFromBtn;  
187   QPushButton*              myAddToBtn;
188
189   QGroupBox*                myEntityTypeBox;
190   QButtonGroup*             myEntityTypeGrp;
191   int                       myEntityType;
192   int                       myIsValid;
193   bool                      myIsLocked;
194
195   SMESHGUI_FilterLibraryDlg* myLibDlg;
196
197   QStackedWidget*           myWgStack;
198
199   QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
200 };
201
202
203 /*!
204  *  Class       : SMESHGUI_FilterDlg
205  *  Description : Dialog to specify filters for VTK viewer
206  */
207
208 class SMESHGUI_FilterDlg : public QDialog
209 {
210   Q_OBJECT
211
212   // Source elements to be selected
213   enum { Mesh, Selection, Dialog, None };
214
215   // Buttons
216   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close, BTN_Help };
217
218 public:
219   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
220   SMESHGUI_FilterDlg( SMESHGUI*, const int );
221   virtual ~SMESHGUI_FilterDlg();
222
223   void                      Init( const QList<int>& );
224   void                      Init( const int );
225
226   void                      SetSelection();
227   void                      SetMesh (SMESH::SMESH_Mesh_var);
228   void                      SetSourceWg( QWidget*, const bool initOnApply = true );
229
230   static SMESH::Filter::Criterion createCriterion();
231
232 signals:
233
234   void                      Accepted();
235
236 private slots:
237
238   void                      onOk();
239   bool                      onApply();
240   void                      onClose();
241   void                      onHelp();
242   void                      onDeactivate();
243   void                      onSelectionDone();
244   void                      onCriterionChanged( const int, const int );
245   void                      onCurrentChanged( int, int );
246
247 private:
248
249   void                      construct( const QList<int>& ); 
250
251   void                      closeEvent( QCloseEvent* );
252   void                      enterEvent( QEvent* );
253   void                      keyPressEvent( QKeyEvent* );
254
255   // dialog creation
256   QWidget*                  createButtonFrame( QWidget* );
257   QWidget*                  createMainFrame( QWidget* );
258   QWidget*                  createSourceGroup( QWidget* );
259   void                      updateMainButtons();
260
261   // execution
262   bool                      isValid() const;
263   bool                      createFilter( const int );
264   void                      insertFilterInViewer();
265   void                      selectInViewer( const int, const QList<int>& );
266   void                      filterSource( const int, QList<int>& );
267   void                      filterSelectionSource( const int, QList<int>& );
268   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
269   void                      setIdsToWg( QWidget*, const QList<int>& );
270   Selection_Mode            getSelMode( const int ) const;
271   void                      updateSelection();
272
273 private:
274   // widgets
275   QWidget*                  myMainFrame;
276   QButtonGroup*             mySourceGrp;
277
278   QCheckBox*                mySetInViewer;
279
280   QMap<int, QPushButton*>   myButtons;
281   
282   SMESHGUI_FilterTable*     myTable;
283
284   // initial fields
285   QList<int>                myTypes;
286   SMESHGUI*                 mySMESHGUI;
287   LightApp_SelectionMgr*    mySelectionMgr;
288   SVTK_Selector*            mySelector;
289   SMESH::SMESH_Mesh_var     myMesh;
290   bool                      myInitSourceWgOnApply;
291   QWidget*                  mySourceWg;
292
293   SALOME_DataMapOfIOMapOfInteger myIObjects;
294   bool                           myIsSelectionChanged;
295   QMap< int, SMESH::Filter_var > myFilter;
296   QMap< int, bool >              myInsertState;
297   QMap< int, int  >              myApplyToState;
298
299   QString                   myHelpFileName;
300 };
301
302 #endif // SMESHGUI_FILTERDLG_H