Salome HOME
Update version number: 3.1.0a2
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_FilterDlg.h
25 //  Author : Sergey LITONIN      
26 //  Module : SMESH
27
28
29 #ifndef SMESHGUI_FilterDlg_H
30 #define SMESHGUI_FilterDlg_H
31
32 #include <qdialog.h>
33 #include <qframe.h>
34 #include <qmap.h>
35 #include <qvaluelist.h>
36
37 #include "SalomeApp_SelectionMgr.h"
38 #include "SALOME_InteractiveObject.hxx"
39 #include "SALOME_DataMapOfIOMapOfInteger.hxx"
40 #include "SVTK_Selection.h"
41
42 #include <TColStd_IndexedMapOfInteger.hxx>
43
44 #include <SALOMEconfig.h>
45 #include CORBA_SERVER_HEADER(SMESH_Filter)
46 #include CORBA_SERVER_HEADER(SMESH_Mesh)
47
48 class QButtonGroup;
49 class QCheckBox;
50 class QCloseEvent;
51 class QComboBox;
52 class QEvent;
53 class QGroupBox;
54 class QPushButton;
55 class QStringList;
56 class QTable;
57 class QTableItem;
58 class QWidgetStack;
59 class SalomeApp_SelectionMgr;
60 class SMESHGUI;
61 class SMESHGUI_FilterLibraryDlg;
62 class SVTK_Selector;
63 class SVTK_ViewWindow;
64
65 /*!
66  *  Class       : SMESHGUI_FilterTable
67  *  Description : Frame containig 
68  *                  - Button group for switching entity type
69  *                  - Table for displaying filter criterions
70  *                  - Buttons for editing table
71  */
72
73 class SMESHGUI_FilterTable : public QFrame
74 {
75   Q_OBJECT
76
77   class Table;
78   class ComboItem;
79   class AdditionalWidget;
80
81   typedef QMap<int, Table*> TableMap;
82
83 public:  
84                             SMESHGUI_FilterTable( SMESHGUI*,
85                                                   QWidget* parent, 
86                                                   const int type);
87                             SMESHGUI_FilterTable( SMESHGUI*,
88                                                   QWidget* parent, 
89                                                   const QValueList<int>& type);
90   virtual                   ~SMESHGUI_FilterTable();
91
92   void                      Init (const int type);
93   void                      Init (const QValueList<int>& types);
94
95   QGroupBox*                GetTableGrp();
96
97   bool                      IsValid (const bool = true, const int theEntityType = -1) const;
98   int                       GetType() const;
99   void                      SetType (const int);
100   void                      RestorePreviousEntityType();
101   int                       NumRows (const int theEntityType = -1) const;
102   void                      Clear (const int theEntityType = -1);
103   void                      SetEditable (const bool);
104   void                      SetEnabled (const bool);
105   void                      SetLibsEnabled (const bool);
106   bool                      IsEditable() const;
107
108   int                       GetCriterionType (const int theRow, const int theType = -1) const;
109
110   void                      GetCriterion (const int                 theRow,
111                                           SMESH::Filter::Criterion& theCriterion,
112                                           const int                 theEntityType = -1) const;
113
114   void                      SetCriterion (const int                       theRow,
115                                           const SMESH::Filter::Criterion& theCriterion,
116                                           const int                       theEntityType = -1);
117
118   void                      AddCriterion (const SMESH::Filter::Criterion& theCriterion,
119                                           const int    theEntityType = -1);
120
121   void                      Copy (const SMESHGUI_FilterTable*);
122   void                      SetValidity (const bool);
123
124   bool                      CurrentCell (int& theRow, int& theCol) const;
125   void                      SetThreshold (const int      theRow,
126                                           const QString& theText,
127                                           const int      theEntityType = -1);
128
129   bool                      GetThreshold (const int      theRow,
130                                           QString&       theText,
131                                           const int      theEntityType = -1);
132
133   void                      Update();
134
135 signals:
136
137   void                      CopyFromClicked();
138   void                      AddToClicked();
139   void                      EntityTypeChanged (const int);
140   void                      NeedValidation();
141   void                      CriterionChanged (const int theRow, const int theEntityType);
142   void                      CurrentChanged (int, int);
143
144 private slots:
145
146   void                      onAddBtn();
147   void                      onInsertBtn();
148   void                      onRemoveBtn();
149   void                      onClearBtn();
150   void                      onCopyFromBtn();
151   void                      onAddToBtn();
152   void                      onCriterionChanged (int, int);
153   void                      onEntityType (int);
154   void                      onCurrentChanged (int, int);
155
156 private:
157
158   void                      addRow (Table*, const int, const bool toTheEnd = true);
159   QTableItem*               getCriterionItem (QTable*, const int);
160   QTableItem*               getCompareItem (QTable*);
161   QTableItem*               getUnaryItem (QTable*);
162   QTableItem*               getBinaryItem (QTable*);
163   const QMap<int, QString>& getCriteria (const int theType) const;
164   const QMap<int, QString>& getCompare() const;
165   Table*                    createTable (QWidget*, const int);
166   QWidget*                  createAdditionalFrame (QWidget* theParent);
167   int                       getFirstSelectedRow() const;
168   void                      onCriterionChanged (const int, const int, const int);
169
170   void                      updateBtnState();
171   void                      removeAdditionalWidget (QTable* theTable, const int theRow);
172   void                      updateAdditionalWidget();
173
174   const QMap<int, QString>& getSupportedTypes() const;
175
176 private:
177   SMESHGUI*                 mySMESHGUI;
178
179   QGroupBox*                myTableGrp;
180   QGroupBox*                mySwitchTableGrp;
181
182   TableMap                  myTables;
183   QPushButton*              myAddBtn;
184   QPushButton*              myInsertBtn;
185   QPushButton*              myRemoveBtn;
186   QPushButton*              myClearBtn;  
187   QPushButton*              myCopyFromBtn;  
188   QPushButton*              myAddToBtn;
189
190   QButtonGroup*             myEntityTypeGrp;
191   int                       myEntityType;
192   int                       myIsValid;
193   bool                      myIsLocked;
194
195   SMESHGUI_FilterLibraryDlg* myLibDlg;
196
197   QWidgetStack*              myWgStack;
198
199   QMap<QTableItem*, 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 };
217
218 public:
219                             SMESHGUI_FilterDlg( SMESHGUI*,
220                                                 const QValueList<int>& types,
221                                                 const char*            name = 0);
222
223                             SMESHGUI_FilterDlg( SMESHGUI*,
224                                                 const int              type,
225                                                 const char*            name = 0);
226   virtual                   ~SMESHGUI_FilterDlg();
227
228   void                      Init (const QValueList<int>& types);
229   void                      Init (const int type);
230
231   void                      SetSelection();
232   void                      SetMesh (SMESH::SMESH_Mesh_ptr);
233   void                      SetSourceWg (QWidget*);
234
235   static SMESH::Filter::Criterion createCriterion();
236
237 signals:
238
239   void                      Accepted();
240
241 private slots:
242
243   void                      onOk();
244   bool                      onApply();
245   void                      onClose();
246   void                      onDeactivate();
247   void                      onSelectionDone();
248   void                      onCriterionChanged (const int, const int);
249   void                      onCurrentChanged (int, int);
250
251 private:
252
253   void                      construct (const QValueList<int>& types); 
254
255   void                      closeEvent (QCloseEvent*);
256   void                      enterEvent (QEvent*);
257
258   // dialog creation
259   QFrame*                   createButtonFrame (QWidget*);
260   QFrame*                   createMainFrame (QWidget*);
261   QButtonGroup*             createSourceGroup (QWidget*);
262   void                      updateMainButtons();
263
264   // execution
265   bool                      isValid() const;
266   bool                      createFilter (const int theType);
267   void                      insertFilterInViewer();
268   void                      selectInViewer (const int              theType,
269                                             const QValueList<int>& theIds);
270   void                      filterSource (const int        theType,
271                                           QValueList<int>& theResIds);
272   void                      filterSelectionSource (const int        theType,
273                                                    QValueList<int>& theResIds);
274   void                      getIdsFromWg (const QWidget*, QValueList<int>&) const;
275   void                      setIdsToWg (QWidget*, const QValueList<int>&);
276   Selection_Mode            getSelMode (const int) const;
277   void                      updateSelection();
278
279 private:
280
281   // widgets
282   QFrame*                   myMainFrame;
283   QButtonGroup*             mySourceGrp;
284
285   QCheckBox*                mySetInViewer;
286
287   QMap<int, QPushButton*>   myButtons;
288   
289   SMESHGUI_FilterTable*     myTable;
290
291   // initial fields
292   QValueList<int>           myTypes;
293   SMESHGUI*                 mySMESHGUI;
294   SalomeApp_SelectionMgr*   mySelectionMgr;
295   SVTK_Selector*            mySelector;
296   SMESH::SMESH_Mesh_ptr     myMesh;
297   QWidget*                  mySourceWg;
298
299   SALOME_DataMapOfIOMapOfInteger myIObjects;
300   bool                           myIsSelectionChanged;
301   QMap< int, SMESH::Filter_var > myFilter;
302   QMap< int, bool >              myInsertState;
303   QMap< int, int  >              myApplyToState;
304 };
305
306 #endif