Salome HOME
SMH: Preparation version 3.0.0 - merge (HEAD+POLYWORK)
[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 (QWidget* parent, 
85                                                   const int type);
86                             SMESHGUI_FilterTable (QWidget* parent, 
87                                                   const QValueList<int>& type);
88   virtual                   ~SMESHGUI_FilterTable();
89
90   void                      Init (const int type);
91   void                      Init (const QValueList<int>& types);
92
93   QGroupBox*                GetTableGrp();
94
95   bool                      IsValid (const bool = true, const int theEntityType = -1) const;
96   int                       GetType() const;
97   void                      SetType (const int);
98   void                      RestorePreviousEntityType();
99   int                       NumRows (const int theEntityType = -1) const;
100   void                      Clear (const int theEntityType = -1);
101   void                      SetEditable (const bool);
102   void                      SetEnabled (const bool);
103   void                      SetLibsEnabled (const bool);
104   bool                      IsEditable() const;
105
106   int                       GetCriterionType (const int theRow, const int theType = -1) const;
107
108   void                      GetCriterion (const int                 theRow,
109                                           SMESH::Filter::Criterion& theCriterion,
110                                           const int                 theEntityType = -1) const;
111
112   void                      SetCriterion (const int                       theRow,
113                                           const SMESH::Filter::Criterion& theCriterion,
114                                           const int                       theEntityType = -1);
115
116   void                      AddCriterion (const SMESH::Filter::Criterion& theCriterion,
117                                           const int    theEntityType = -1);
118
119   void                      Copy (const SMESHGUI_FilterTable*);
120   void                      SetValidity (const bool);
121
122   bool                      CurrentCell (int& theRow, int& theCol) const;
123   void                      SetThreshold (const int      theRow,
124                                           const QString& theText,
125                                           const int      theEntityType = -1);
126
127   bool                      GetThreshold (const int      theRow,
128                                           QString&       theText,
129                                           const int      theEntityType = -1);
130
131   void                      Update();
132
133 signals:
134
135   void                      CopyFromClicked();
136   void                      AddToClicked();
137   void                      EntityTypeChanged (const int);
138   void                      NeedValidation();
139   void                      CretarionChanged (const int theRow, const int theEntityType);
140   void                      CurrentChanged (int, int);
141
142 private slots:
143
144   void                      onAddBtn();
145   void                      onInsertBtn();
146   void                      onRemoveBtn();
147   void                      onClearBtn();
148   void                      onCopyFromBtn();
149   void                      onAddToBtn();
150   void                      onCriterionChanged (int, int);
151   void                      onEntityType (int);
152   void                      onCurrentChanged (int, int);
153
154 private:
155
156   void                      addRow (Table*, const int, const bool toTheEnd = true);
157   QTableItem*               getCriterionItem (QTable*, const int);
158   QTableItem*               getCompareItem (QTable*);
159   QTableItem*               getUnaryItem (QTable*);
160   QTableItem*               getBinaryItem (QTable*);
161   const QMap<int, QString>& getCriteria (const int theType) const;
162   const QMap<int, QString>& getCompare() const;
163   Table*                    createTable (QWidget*, const int);
164   QWidget*                  createAdditionalFrame (QWidget* theParent);
165   int                       getFirstSelectedRow() const;
166   void                      onCriterionChanged (const int, const int, const int);
167
168   void                      updateBtnState();
169   void                      removeAdditionalWidget (QTable* theTable, const int theRow);
170   void                      updateAdditionalWidget();
171
172   const QMap<int, QString>& getSupportedTypes() const;
173
174 private:
175
176   QGroupBox*                myTableGrp;
177   QGroupBox*                mySwitchTableGrp;
178
179   TableMap                  myTables;
180   QPushButton*              myAddBtn;
181   QPushButton*              myInsertBtn;
182   QPushButton*              myRemoveBtn;
183   QPushButton*              myClearBtn;  
184   QPushButton*              myCopyFromBtn;  
185   QPushButton*              myAddToBtn;
186
187   QButtonGroup*             myEntityTypeGrp;
188   int                       myEntityType;
189   int                       myIsValid;
190
191   SMESHGUI_FilterLibraryDlg* myLibDlg;
192
193   QWidgetStack*              myWgStack;
194
195   QMap<QTableItem*, AdditionalWidget*> myAddWidgets;
196 };
197
198
199 /*!
200  *  Class       : SMESHGUI_FilterDlg
201  *  Description : Dialog to specify filters for VTK viewer
202  */
203
204 class SMESHGUI_FilterDlg : public QDialog
205 {
206   Q_OBJECT
207
208   // Source elements to be selected
209   enum { Mesh, Selection, Dialog, None };
210
211   // Buttons
212   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close };
213
214 public:
215                             SMESHGUI_FilterDlg( SMESHGUI*,
216                                                 const QValueList<int>& types,
217                                                 const char*            name = 0);
218
219                             SMESHGUI_FilterDlg( SMESHGUI*,
220                                                 const int              type,
221                                                 const char*            name = 0);
222   virtual                   ~SMESHGUI_FilterDlg();
223
224   void                      Init (const QValueList<int>& types);
225   void                      Init (const int type);
226
227   void                      SetSelection();
228   void                      SetMesh (SMESH::SMESH_Mesh_ptr);
229   void                      SetSourceWg (QWidget*);
230
231   static SMESH::Filter::Criterion createCriterion();
232
233 signals:
234
235   void                      Accepted();
236
237 private slots:
238
239   void                      onOk();
240   bool                      onApply();
241   void                      onClose();
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 QValueList<int>& types); 
250
251   void                      closeEvent (QCloseEvent*);
252   void                      enterEvent (QEvent*);
253
254   // dialog creation
255   QFrame*                   createButtonFrame (QWidget*);
256   QFrame*                   createMainFrame (QWidget*);
257   QButtonGroup*             createSourceGroup (QWidget*);
258   void                      updateMainButtons();
259
260   // execution
261   bool                      isValid() const;
262   bool                      createFilter (const int theType);
263   void                      insertFilterInViewer();
264   void                      selectInViewer (const int              theType,
265                                             const QValueList<int>& theIds);
266   void                      filterSource (const int        theType,
267                                           QValueList<int>& theResIds);
268   void                      filterSelectionSource (const int        theType,
269                                                    QValueList<int>& theResIds);
270   void                      getIdsFromWg (const QWidget*, QValueList<int>&) const;
271   void                      setIdsToWg (QWidget*, const QValueList<int>&);
272   Selection_Mode            getSelMode (const int) const;
273   void                      updateSelection();
274
275 private:
276
277   // widgets
278   QFrame*                   myMainFrame;
279   QButtonGroup*             mySourceGrp;
280
281   QCheckBox*                mySetInViewer;
282
283   QMap<int, QPushButton*>   myButtons;
284   
285   SMESHGUI_FilterTable*     myTable;
286
287   // initial fields
288   QValueList<int>           myTypes;
289   SMESHGUI*                 mySMESHGUI;
290   SalomeApp_SelectionMgr*   mySelectionMgr;
291   SVTK_Selector*            mySelector;
292   SVTK_ViewWindow*          myViewWindow;
293   SMESH::SMESH_Mesh_ptr     myMesh;
294   QWidget*                  mySourceWg;
295
296   SALOME_DataMapOfIOMapOfInteger myIObjects;
297   bool                           myIsSelectionChanged;
298   QMap< int, SMESH::Filter_var > myFilter;
299   QMap< int, bool >              myInsertState;
300   QMap< int, int  >              myApplyToState;
301 };
302
303 #endif