Salome HOME
Fix bug 12796: Warning missed for the bad file 'test18.med'
[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.salome-platform.org/ or email : webmaster.salome@opencascade.com
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 "LightApp_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 LightApp_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                      SetID( const int      theRow,
134                                    const QString& theText,
135                                    const int      theEntityType = -1 ); 
136   
137   bool                      GetID( const int      theRow,
138                                    QString&       theText,
139                                    const int      theEntityType = -1 );
140
141   void                      Update();
142
143 signals:
144
145   void                      CopyFromClicked();
146   void                      AddToClicked();
147   void                      EntityTypeChanged (const int);
148   void                      NeedValidation();
149   void                      CriterionChanged (const int theRow, const int theEntityType);
150   void                      CurrentChanged (int, int);
151
152 private slots:
153
154   void                      onAddBtn();
155   void                      onInsertBtn();
156   void                      onRemoveBtn();
157   void                      onClearBtn();
158   void                      onCopyFromBtn();
159   void                      onAddToBtn();
160   void                      onCriterionChanged (int, int);
161   void                      onEntityType (int);
162   void                      onCurrentChanged (int, int);
163
164 private:
165
166   void                      addRow (Table*, const int, const bool toTheEnd = true);
167   QTableItem*               getCriterionItem (QTable*, const int);
168   QTableItem*               getCompareItem (QTable*);
169   QTableItem*               getUnaryItem (QTable*);
170   QTableItem*               getBinaryItem (QTable*);
171   const QMap<int, QString>& getCriteria (const int theType) const;
172   const QMap<int, QString>& getCompare() const;
173   Table*                    createTable (QWidget*, const int);
174   QWidget*                  createAdditionalFrame (QWidget* theParent);
175   int                       getFirstSelectedRow() const;
176   void                      onCriterionChanged (const int, const int, const int);
177
178   void                      updateBtnState();
179   void                      removeAdditionalWidget (QTable* theTable, const int theRow);
180   void                      updateAdditionalWidget();
181
182   const QMap<int, QString>& getSupportedTypes() const;
183
184 private:
185   SMESHGUI*                 mySMESHGUI;
186
187   QGroupBox*                myTableGrp;
188   QGroupBox*                mySwitchTableGrp;
189
190   TableMap                  myTables;
191   QPushButton*              myAddBtn;
192   QPushButton*              myInsertBtn;
193   QPushButton*              myRemoveBtn;
194   QPushButton*              myClearBtn;  
195   QPushButton*              myCopyFromBtn;  
196   QPushButton*              myAddToBtn;
197
198   QButtonGroup*             myEntityTypeGrp;
199   int                       myEntityType;
200   int                       myIsValid;
201   bool                      myIsLocked;
202
203   SMESHGUI_FilterLibraryDlg* myLibDlg;
204
205   QWidgetStack*              myWgStack;
206
207   QMap<QTableItem*, AdditionalWidget*> myAddWidgets;
208 };
209
210
211 /*!
212  *  Class       : SMESHGUI_FilterDlg
213  *  Description : Dialog to specify filters for VTK viewer
214  */
215
216 class SMESHGUI_FilterDlg : public QDialog
217 {
218   Q_OBJECT
219
220   // Source elements to be selected
221   enum { Mesh, Selection, Dialog, None };
222
223   // Buttons
224   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close, BTN_Help };
225
226 public:
227                             SMESHGUI_FilterDlg( SMESHGUI*,
228                                                 const QValueList<int>& types,
229                                                 const char*            name = 0);
230
231                             SMESHGUI_FilterDlg( SMESHGUI*,
232                                                 const int              type,
233                                                 const char*            name = 0);
234   virtual                   ~SMESHGUI_FilterDlg();
235
236   void                      Init (const QValueList<int>& types);
237   void                      Init (const int type);
238
239   void                      SetSelection();
240   void                      SetMesh (SMESH::SMESH_Mesh_ptr);
241   void                      SetSourceWg (QWidget*);
242
243   static SMESH::Filter::Criterion createCriterion();
244
245 signals:
246
247   void                      Accepted();
248
249 private slots:
250
251   void                      onOk();
252   bool                      onApply();
253   void                      onClose();
254   void                      onHelp();
255   void                      onDeactivate();
256   void                      onSelectionDone();
257   void                      onCriterionChanged (const int, const int);
258   void                      onCurrentChanged (int, int);
259
260 private:
261
262   void                      construct (const QValueList<int>& types); 
263
264   void                      closeEvent (QCloseEvent*);
265   void                      enterEvent (QEvent*);
266   void                      keyPressEvent(QKeyEvent*);
267
268   // dialog creation
269   QFrame*                   createButtonFrame (QWidget*);
270   QFrame*                   createMainFrame (QWidget*);
271   QButtonGroup*             createSourceGroup (QWidget*);
272   void                      updateMainButtons();
273
274   // execution
275   bool                      isValid() const;
276   bool                      createFilter (const int theType);
277   void                      insertFilterInViewer();
278   void                      selectInViewer (const int              theType,
279                                             const QValueList<int>& theIds);
280   void                      filterSource (const int        theType,
281                                           QValueList<int>& theResIds);
282   void                      filterSelectionSource (const int        theType,
283                                                    QValueList<int>& theResIds);
284   void                      getIdsFromWg (const QWidget*, QValueList<int>&) const;
285   void                      setIdsToWg (QWidget*, const QValueList<int>&);
286   Selection_Mode            getSelMode (const int) const;
287   void                      updateSelection();
288
289 private:
290
291   // widgets
292   QFrame*                   myMainFrame;
293   QButtonGroup*             mySourceGrp;
294
295   QCheckBox*                mySetInViewer;
296
297   QMap<int, QPushButton*>   myButtons;
298   
299   SMESHGUI_FilterTable*     myTable;
300
301   // initial fields
302   QValueList<int>           myTypes;
303   SMESHGUI*                 mySMESHGUI;
304   LightApp_SelectionMgr*    mySelectionMgr;
305   SVTK_Selector*            mySelector;
306   SMESH::SMESH_Mesh_ptr     myMesh;
307   QWidget*                  mySourceWg;
308
309   SALOME_DataMapOfIOMapOfInteger myIObjects;
310   bool                           myIsSelectionChanged;
311   QMap< int, SMESH::Filter_var > myFilter;
312   QMap< int, bool >              myInsertState;
313   QMap< int, int  >              myApplyToState;
314
315   QString                   myHelpFileName;
316 };
317
318 #endif