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