Salome HOME
Fix for bug PAL10409 (Filter "Belong to geom" fails if 2 geom shapes have the same...
[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 "SALOME_Selection.h"
38 #include "SALOME_InteractiveObject.hxx"
39 #include "SALOME_DataMapOfIOMapOfInteger.hxx"
40
41 #include <TColStd_IndexedMapOfInteger.hxx>
42
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_Filter)
45 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46
47 class QButtonGroup;
48 class QCheckBox;
49 class QCloseEvent;
50 class QComboBox;
51 class QEvent;
52 class QGroupBox;
53 class QPushButton;
54 class QStringList;
55 class QTable;
56 class QTableItem;
57 class QWidgetStack;
58 class SALOME_Selection;
59 class SMESHGUI;
60 class SMESHGUI_FilterLibraryDlg;
61
62 /*
63   Class       : SMESHGUI_FilterTable
64   Description : Frame containig 
65                   - Button group for switching entity type
66                   - Table for displaying filter criterions
67                   - Buttons for editing table
68 */
69
70 class SMESHGUI_FilterTable : public QFrame
71 {
72   Q_OBJECT
73
74   class Table;
75   class ComboItem;
76   class AdditionalWidget;
77
78   typedef QMap<int, Table*> TableMap;
79
80 public:  
81   
82                             SMESHGUI_FilterTable( QWidget* parent, 
83                                                   const int type );
84                             SMESHGUI_FilterTable( QWidget* parent, 
85                                                   const QValueList<int>& type );
86   virtual                   ~SMESHGUI_FilterTable();
87   
88   void                      Init( const int type );
89   void                      Init( const QValueList<int>& types );
90
91   QGroupBox*                GetTableGrp();
92
93   bool                      IsValid( const bool = true, const int theEntityType = -1 ) const;
94   int                       GetType() const;
95   void                      SetType( const int );
96   void                      RestorePreviousEntityType();
97   int                       NumRows( const int theEntityType = -1 ) const;
98   void                      Clear( const int theEntityType = -1 );
99   void                      SetEditable( const bool );
100   void                      SetEnabled( const bool );
101   void                      SetLibsEnabled( const bool );
102   bool                      IsEditable() const;
103
104   int                       GetCriterionType( const int theRow, const int theType = -1 ) const;
105   
106   void                      GetCriterion( const int                 theRow,
107                                           SMESH::Filter::Criterion& theCriterion,
108                                           const int                 theEntityType = -1 ) const;
109
110   void                      SetCriterion( const int                       theRow,
111                                           const SMESH::Filter::Criterion& theCriterion,
112                                           const int                       theEntityType = -1 );
113
114   void                      AddCriterion( const SMESH::Filter::Criterion& theCriterion,
115                                           const int    theEntityType = -1 );
116   
117   void                      Copy( const SMESHGUI_FilterTable* );
118   void                      SetValidity( const bool );
119
120   bool                      CurrentCell( int& theRow, int& theCol ) const;
121   void                      SetThreshold( const int      theRow,
122                                           const QString& theText,
123                                           const int      theEntityType = -1 );
124
125   bool                      GetThreshold( const int      theRow,
126                                           QString&       theText,
127                                           const int      theEntityType = -1 );
128
129   void                      SetID( const int      theRow,
130                                    const QString& theText,
131                                    const int      theEntityType = -1 ); 
132   
133   bool                      GetID( const int      theRow,
134                                    QString&       theText,
135                                    const int      theEntityType = -1 );
136
137   void                      Update();
138
139  
140 signals:
141
142   void                      CopyFromClicked();
143   void                      AddToClicked();
144   void                      EntityTypeChanged( const int );
145   void                      NeedValidation();
146   void                      CretarionChanged( const int theRow, const int theEntityType );
147   void                      CurrentChanged( int, int );
148   
149 private slots:
150
151   void                      onAddBtn();
152   void                      onInsertBtn();
153   void                      onRemoveBtn();
154   void                      onClearBtn();
155   void                      onCopyFromBtn();
156   void                      onAddToBtn();
157   void                      onCriterionChanged( int, int );
158   void                      onEntityType( int );
159   void                      onCurrentChanged( int, int );
160
161 private:
162
163   void                      addRow( Table*, const int, const bool toTheEnd = true );
164   QTableItem*               getCriterionItem( QTable*, const int );
165   QTableItem*               getCompareItem( QTable* );
166   QTableItem*               getUnaryItem( QTable* );
167   QTableItem*               getBinaryItem( QTable* );
168   const QMap<int, QString>& getCriteria( const int theType ) const;
169   const QMap<int, QString>& getCompare() const;
170   Table*                    createTable( QWidget*, const int );
171   QWidget*                  createAdditionalFrame( QWidget* theParent );
172   int                       getFirstSelectedRow() const;
173   void                      onCriterionChanged( const int, const int, const int  );
174   
175   void                      updateBtnState();
176   void                      removeAdditionalWidget( QTable* theTable, const int theRow );
177   void                      updateAdditionalWidget();
178
179   const QMap<int, QString>& getSupportedTypes() const;
180   
181 private:
182
183   QGroupBox*                myTableGrp;
184   QGroupBox*                mySwitchTableGrp;
185
186   TableMap                  myTables;
187   QPushButton*              myAddBtn;
188   QPushButton*              myInsertBtn;
189   QPushButton*              myRemoveBtn;
190   QPushButton*              myClearBtn;  
191   QPushButton*              myCopyFromBtn;  
192   QPushButton*              myAddToBtn;
193
194   QButtonGroup*             myEntityTypeGrp;
195   int                       myEntityType;
196   int                       myIsValid;
197   bool                      myIsLocked;
198   
199   SMESHGUI_FilterLibraryDlg* myLibDlg;
200
201   QWidgetStack*             myWgStack;
202   QMap<QTableItem*, AdditionalWidget*> myAddWidgets;
203 };
204
205
206 /*
207   Class       : SMESHGUI_FilterDlg
208   Description : Dialog to specify filters for VTK viewer
209 */
210
211 class SMESHGUI_FilterDlg : public QDialog
212
213   Q_OBJECT
214
215   // Source elements to be selected
216   enum { Mesh, Selection, Dialog, None };
217   
218   // Buttons
219   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close };
220
221 public:
222                             SMESHGUI_FilterDlg( QWidget*               parent,
223                                                 const QValueList<int>& types,
224                                                 const char*            name = 0 );
225                                                 
226                             SMESHGUI_FilterDlg( QWidget*               parent,
227                                                 const int              type,
228                                                 const char*            name = 0 );                                                    
229   virtual                   ~SMESHGUI_FilterDlg();
230
231   void                      Init( const QValueList<int>& types );
232   void                      Init( const int type );
233
234   void                      SetSelection( SALOME_Selection* );
235   void                      SetMesh( SMESH::SMESH_Mesh_ptr );
236   void                      SetSourceWg( QWidget* );
237
238   static SMESH::Filter::Criterion createCriterion();
239
240 signals:
241
242   void                      Accepted();
243
244 private slots:
245
246   void                      onOk();
247   bool                      onApply();
248   void                      onClose();
249   void                      onDeactivate();
250   void                      onSelectionDone();
251   void                      onCriterionChanged( const int, const int );
252   void                      onCurrentChanged( int, int );
253   
254 private:
255
256   void                      construct( const QValueList<int>& types ); 
257
258   void                      closeEvent( QCloseEvent* e );
259   void                      enterEvent ( QEvent * );
260
261   // dialog creation
262   QFrame*                   createButtonFrame( QWidget* );
263   QFrame*                   createMainFrame( QWidget* );
264   QButtonGroup*             createSourceGroup( QWidget* );
265   void                      updateMainButtons();
266   
267   // execution
268   bool                      isValid() const;
269   bool                      createFilter( const int theType );
270   void                      insertFilterInViewer();
271   void                      selectInViewer( const int theType,
272                                             const QValueList<int>& theIds );
273   void                      filterSource( const int            theType,
274                                           QValueList<int>&     theResIds );
275   void                      filterSelectionSource( const int            theType,
276                                                    QValueList<int>&     theResIds );
277   void                      getIdsFromWg( const QWidget*, QValueList<int>& ) const;
278   void                      setIdsToWg( QWidget*, const QValueList<int>& );
279   Selection_Mode            getSelMode( const int ) const;
280   void                      updateSelection();
281
282 private:
283
284   // widgets
285   QFrame*                   myMainFrame;
286   QButtonGroup*             mySourceGrp;
287
288   QCheckBox*                mySetInViewer;
289
290   QMap<int, QPushButton*>   myButtons;
291   
292   SMESHGUI_FilterTable*     myTable;
293
294   // initial fields
295   QValueList<int>           myTypes;
296   SMESHGUI*                 mySMESHGUI;
297   SALOME_Selection*         mySelection;
298   SMESH::SMESH_Mesh_ptr     myMesh;
299   QWidget*                  mySourceWg;
300
301   SALOME_DataMapOfIOMapOfInteger myIObjects;
302   bool                           myIsSelectionChanged;
303   QMap< int, SMESH::Filter_var > myFilter;
304   QMap< int, bool >              myInsertState;
305   QMap< int, int  >              myApplyToState;
306 };
307
308 #endif
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328