Salome HOME
ed1c95e9d921d3eb9f90632c1c29f9f8c5eb487b
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 //  Copyright (C) 2003-2007  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 // SMESH SMESHGUI : GUI for SMESH component
23 // File   : SMESHGUI_FilterDlg.h
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
25 //
26 #ifndef SMESHGUI_FILTERDLG_H
27 #define SMESHGUI_FILTERDLG_H
28
29 // SMESH includes
30 #include "SMESH_SMESHGUI.hxx"
31
32 // Qt includes
33 #include <QWidget>
34 #include <QDialog>
35 #include <QMap>
36 #include <QList>
37
38 // SALOME GUI includes
39 #include <SALOME_DataMapOfIOMapOfInteger.hxx>
40 #include <SVTK_Selection.h>
41
42 // IDL includes
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_Filter)
45 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46
47 class QFrame;
48 class QButtonGroup;
49 class QCheckBox;
50 class QGroupBox;
51 class QPushButton;
52 class QTableWidget;
53 class QTableWidgetItem;
54 class QStackedWidget;
55 class LightApp_SelectionMgr;
56 class SMESHGUI;
57 class SMESHGUI_FilterLibraryDlg;
58 class SVTK_Selector;
59
60 /*!
61  *  Class       : SMESHGUI_FilterTable
62  *  Description : Frame containig 
63  *                  - Button group for switching entity type
64  *                  - Table for displaying filter criterions
65  *                  - Buttons for editing table
66  */
67
68 class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
69 {
70   Q_OBJECT
71
72   class Table;
73   class ComboItem;
74   class CheckItem;
75   class AdditionalWidget;
76   class ComboDelegate;
77
78   typedef QMap<int, Table*> TableMap;
79
80 public:  
81   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
82   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
83   virtual ~SMESHGUI_FilterTable();
84
85   void                      Init( const QList<int>& );
86
87   QGroupBox*                GetTableGrp();
88
89   bool                      IsValid( const bool = true, const int = -1 ) const;
90   int                       GetType() const;
91   void                      SetType(const int);
92   void                      RestorePreviousEntityType();
93   int                       NumRows( const int = -1 ) const;
94   void                      Clear( const int = -1 );
95   void                      SetEditable( const bool );
96   void                      SetEnabled( const bool );
97   void                      SetLibsEnabled( const bool );
98   bool                      IsEditable() const;
99
100   int                       GetCriterionType( const int, const int = -1 ) const;
101
102   void                      GetCriterion( const int,
103                                           SMESH::Filter::Criterion&,
104                                           const int = -1 ) const;
105
106   void                      SetCriterion( const int,
107                                           const SMESH::Filter::Criterion&,
108                                           const int = -1 );
109
110   void                      AddCriterion( const SMESH::Filter::Criterion&,
111                                           const int = -1 );
112
113   void                      Copy( const SMESHGUI_FilterTable* );
114   void                      SetValidity( const bool );
115
116   bool                      CurrentCell( int&, int& ) const;
117   void                      SetThreshold( const int,
118                                           const QString&,
119                                           const int = -1 );
120
121   bool                      GetThreshold( const int,
122                                           QString&,
123                                           const int = -1 );
124
125   void                      SetID( const int,
126                                    const QString&,
127                                    const int = -1 ); 
128   
129   bool                      GetID( const int,
130                                    QString&,
131                                    const int = -1 );
132
133   void                      Update();
134
135 signals:
136   void                      CopyFromClicked();
137   void                      AddToClicked();
138   void                      EntityTypeChanged( const int );
139   void                      NeedValidation();
140   void                      CriterionChanged( const int, const int );
141   void                      CurrentChanged( int, int );
142
143 private slots:
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   void                      addRow( Table*, const int, const bool = true );
156   QTableWidgetItem*         getCriterionItem( const int ) const;
157   QTableWidgetItem*         getCompareItem() const;
158   QTableWidgetItem*         getUnaryItem() const;
159   QTableWidgetItem*         getBinaryItem() const;
160   const QMap<int, QString>& getCriteria( const int ) const;
161   const QMap<int, QString>& getCompare() const;
162   Table*                    createTable( QWidget*, const int );
163   QWidget*                  createAdditionalFrame( QWidget* );
164   int                       getFirstSelectedRow() const;
165   void                      onCriterionChanged( const int, const int, const int );
166
167   void                      updateBtnState();
168   void                      removeAdditionalWidget( QTableWidget*, const int );
169   void                      updateAdditionalWidget();
170
171   const QMap<int, QString>& getSupportedTypes() const;
172
173 private:
174   SMESHGUI*                 mySMESHGUI;
175
176   QGroupBox*                myTableGrp;
177   QWidget*                  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   QGroupBox*                myEntityTypeBox;
188   QButtonGroup*             myEntityTypeGrp;
189   int                       myEntityType;
190   int                       myIsValid;
191   bool                      myIsLocked;
192
193   SMESHGUI_FilterLibraryDlg* myLibDlg;
194
195   QStackedWidget*           myWgStack;
196
197   QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
198 };
199
200
201 /*!
202  *  Class       : SMESHGUI_FilterDlg
203  *  Description : Dialog to specify filters for VTK viewer
204  */
205
206 class SMESHGUI_FilterDlg : public QDialog
207 {
208   Q_OBJECT
209
210   // Source elements to be selected
211   enum { Mesh, Selection, Dialog, None };
212
213   // Buttons
214   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close, BTN_Help };
215
216 public:
217   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
218   SMESHGUI_FilterDlg( SMESHGUI*, const int );
219   virtual ~SMESHGUI_FilterDlg();
220
221   void                      Init( const QList<int>& );
222   void                      Init( const int );
223
224   void                      SetSelection();
225   void                      SetMesh (SMESH::SMESH_Mesh_var);
226   void                      SetSourceWg( QWidget* );
227
228   static SMESH::Filter::Criterion createCriterion();
229
230 signals:
231
232   void                      Accepted();
233
234 private slots:
235
236   void                      onOk();
237   bool                      onApply();
238   void                      onClose();
239   void                      onHelp();
240   void                      onDeactivate();
241   void                      onSelectionDone();
242   void                      onCriterionChanged( const int, const int );
243   void                      onCurrentChanged( int, int );
244
245 private:
246
247   void                      construct( const QList<int>& ); 
248
249   void                      closeEvent( QCloseEvent* );
250   void                      enterEvent( QEvent* );
251   void                      keyPressEvent( QKeyEvent* );
252
253   // dialog creation
254   QWidget*                  createButtonFrame( QWidget* );
255   QWidget*                  createMainFrame( QWidget* );
256   QWidget*                  createSourceGroup( QWidget* );
257   void                      updateMainButtons();
258
259   // execution
260   bool                      isValid() const;
261   bool                      createFilter( const int );
262   void                      insertFilterInViewer();
263   void                      selectInViewer( const int, const QList<int>& );
264   void                      filterSource( const int, QList<int>& );
265   void                      filterSelectionSource( const int, QList<int>& );
266   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
267   void                      setIdsToWg( QWidget*, const QList<int>& );
268   Selection_Mode            getSelMode( const int ) const;
269   void                      updateSelection();
270
271 private:
272   // widgets
273   QWidget*                  myMainFrame;
274   QButtonGroup*             mySourceGrp;
275
276   QCheckBox*                mySetInViewer;
277
278   QMap<int, QPushButton*>   myButtons;
279   
280   SMESHGUI_FilterTable*     myTable;
281
282   // initial fields
283   QList<int>                myTypes;
284   SMESHGUI*                 mySMESHGUI;
285   LightApp_SelectionMgr*    mySelectionMgr;
286   SVTK_Selector*            mySelector;
287   SMESH::SMESH_Mesh_var     myMesh;
288   QWidget*                  mySourceWg;
289
290   SALOME_DataMapOfIOMapOfInteger myIObjects;
291   bool                           myIsSelectionChanged;
292   QMap< int, SMESH::Filter_var > myFilter;
293   QMap< int, bool >              myInsertState;
294   QMap< int, int  >              myApplyToState;
295
296   QString                   myHelpFileName;
297 };
298
299 #endif // SMESHGUI_FILTERDLG_H