Salome HOME
22806: EDF SMESH: Regression: Prism_3D error
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 // Copyright (C) 2007-2014  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, or (at your option) any later version.
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 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_FilterDlg.h
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 //
27 #ifndef SMESHGUI_FILTERDLG_H
28 #define SMESHGUI_FILTERDLG_H
29
30 // SMESH includes
31 #include "SMESH_SMESHGUI.hxx"
32
33 // Qt includes
34 #include <QWidget>
35 #include <QDialog>
36 #include <QMap>
37 #include <QList>
38
39 // SALOME GUI includes
40 #include <SALOME_DataMapOfIOMapOfInteger.hxx>
41 #include <SVTK_Selection.h>
42
43 // IDL includes
44 #include <SALOMEconfig.h>
45 #include CORBA_SERVER_HEADER(SMESH_Filter)
46 #include CORBA_SERVER_HEADER(SMESH_Mesh)
47
48 class QFrame;
49 class QButtonGroup;
50 class QCheckBox;
51 class QGroupBox;
52 class QPushButton;
53 class QTableWidget;
54 class QTableWidgetItem;
55 class QStackedWidget;
56 class LightApp_SelectionMgr;
57 class SMESHGUI;
58 class SMESHGUI_FilterLibraryDlg;
59 class SVTK_Selector;
60
61 /*!
62  *  Class       : SMESHGUI_FilterTable
63  *  Description : Frame containig 
64  *                  - Button group for switching entity type
65  *                  - Table for displaying filter criterions
66  *                  - Buttons for editing table
67  */
68
69 class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
70 {
71   Q_OBJECT
72
73   class Table;
74   class ComboItem;
75   class IntSpinItem;
76   class DoubleSpinItem;
77   class CheckItem;
78   class AdditionalWidget;
79   class ComboDelegate;
80
81   typedef QMap<int, Table*> TableMap;
82
83 public:  
84   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
85   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
86   virtual ~SMESHGUI_FilterTable();
87
88   void                      Init( const QList<int>& );
89
90   QGroupBox*                GetTableGrp();
91
92   bool                      IsValid( const bool = true, const int = -1 ) const;
93   int                       GetType() const;
94   void                      SetType(const int);
95   void                      RestorePreviousEntityType();
96   int                       NumRows( const int = -1 ) const;
97   void                      Clear( const int = -1 );
98   void                      SetEditable( const bool );
99   void                      SetEnabled( const bool );
100   void                      SetLibsEnabled( const bool );
101   bool                      IsEditable() const;
102
103   int                       GetCriterionType( const int, const int = -1 ) const;
104
105   void                      GetCriterion( const int,
106                                           SMESH::Filter::Criterion&,
107                                           const int = -1 ) const;
108
109   void                      SetCriterion( const int,
110                                           const SMESH::Filter::Criterion&,
111                                           const int = -1 );
112
113   void                      AddCriterion( const SMESH::Filter::Criterion&,
114                                           const int = -1 );
115
116   void                      Copy( const SMESHGUI_FilterTable* );
117   void                      SetValidity( const bool );
118
119   bool                      CurrentCell( int&, int& ) const;
120   void                      SetThreshold( const int,
121                                           const QString&,
122                                           const int = -1 );
123
124   bool                      GetThreshold( const int,
125                                           QString&,
126                                           const int = -1 );
127
128   void                      SetID( const int,
129                                    const QString&,
130                                    const int = -1 ); 
131   
132   bool                      GetID( const int,
133                                    QString&,
134                                    const int = -1 );
135
136   void                      Update();
137
138 signals:
139   void                      CopyFromClicked();
140   void                      AddToClicked();
141   void                      EntityTypeChanged( const int );
142   void                      NeedValidation();
143   void                      CriterionChanged( const int, const int );
144   void                      ThresholdChanged( const int, const int );
145   void                      CurrentChanged( int, int );
146
147 private slots:
148   void                      onAddBtn();
149   void                      onInsertBtn();
150   void                      onRemoveBtn();
151   void                      onClearBtn();
152   void                      onCopyFromBtn();
153   void                      onAddToBtn();
154   void                      onCriterionChanged( int, int );
155   void                      onEntityType( int );
156   void                      onCurrentChanged( int, int );
157
158 private:
159   void                      addRow( Table*, const int, const bool = true );
160   QTableWidgetItem*         getCriterionItem( const int ) const;
161   QTableWidgetItem*         getCompareItem() const;
162   QTableWidgetItem*         getUnaryItem() const;
163   QTableWidgetItem*         getBinaryItem() const;
164   const QMap<int, QString>& getCriteria( const int ) const;
165   const QMap<int, QString>& getCompare() const;
166   Table*                    createTable( QWidget*, const int );
167   QWidget*                  createAdditionalFrame( QWidget* );
168   int                       getFirstSelectedRow() const;
169   void                      onCriterionChanged( const int, const int, const int );
170
171   void                      updateBtnState();
172   void                      removeAdditionalWidget( QTableWidget*, const int );
173   void                      updateAdditionalWidget();
174   const char*               getPrecision( const int );
175
176   const QMap<int, QString>& getSupportedTypes() const;
177
178 private:
179   SMESHGUI*                 mySMESHGUI;
180
181   QGroupBox*                myTableGrp;
182   QWidget*                  mySwitchTableGrp;
183
184   TableMap                  myTables;
185   QPushButton*              myAddBtn;
186   QPushButton*              myInsertBtn;
187   QPushButton*              myRemoveBtn;
188   QPushButton*              myClearBtn;  
189   QPushButton*              myCopyFromBtn;  
190   QPushButton*              myAddToBtn;
191
192   QGroupBox*                myEntityTypeBox;
193   QButtonGroup*             myEntityTypeGrp;
194   int                       myEntityType;
195   int                       myIsValid;
196   bool                      myIsLocked;
197
198   SMESHGUI_FilterLibraryDlg* myLibDlg;
199
200   QStackedWidget*           myWgStack;
201
202   QMap<QTableWidgetItem*, 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_Apply, BTN_Close, BTN_Help };
220
221 public:
222   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
223   SMESHGUI_FilterDlg( SMESHGUI*, const int );
224   virtual ~SMESHGUI_FilterDlg();
225
226   void                      Init( const QList<int>&, const bool setInViewer=true );
227   void                      Init( const int, const bool setInViewer=true );
228
229   void                      SetSelection();
230   void                      SetMesh (SMESH::SMESH_Mesh_var);
231   void                      SetSourceWg( QWidget*, const bool initOnApply = true );
232   void                      SetEnabled( bool setInViewer, bool diffSources );
233
234   static SMESH::Filter::Criterion createCriterion();
235
236   SMESH::Filter_var         GetFilter() const;
237   void                      SetFilter(SMESH::Filter_var filter, int type);
238   void                      UnRegisterFilters();
239
240 signals:
241
242   void                      Accepted();
243
244 protected slots:
245   virtual void              reject();
246
247 private slots:
248
249   void                      onOk();
250   bool                      onApply();
251   void                      onHelp();
252   void                      onDeactivate();
253   void                      onSelectionDone();
254   void                      onCriterionChanged( const int, const int );
255   void                      onThresholdChanged( const int, const int );
256   void                      onCurrentChanged( int, int );
257
258 private:
259
260   void                      construct( const QList<int>& ); 
261
262   void                      enterEvent( QEvent* );
263   void                      keyPressEvent( QKeyEvent* );
264
265   // dialog creation
266   QWidget*                  createButtonFrame( QWidget* );
267   QWidget*                  createMainFrame( QWidget* );
268   QWidget*                  createSourceGroup( QWidget* );
269   void                      updateMainButtons();
270
271   // execution
272   bool                      isValid() const;
273   bool                      createFilter( const int );
274   void                      insertFilterInViewer();
275   void                      selectInViewer( const int, const QList<int>& );
276   void                      filterSource( const int, QList<int>& );
277   void                      filterSelectionSource( const int, QList<int>& );
278   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
279   void                      setIdsToWg( QWidget*, const QList<int>& );
280   Selection_Mode            getSelMode( const int ) const;
281   void                      updateSelection();
282
283 private:
284   // widgets
285   QWidget*                  myMainFrame;
286   QButtonGroup*             mySourceGrp;
287
288   QCheckBox*                mySetInViewer;
289
290   QMap<int, QPushButton*>   myButtons;
291   
292   SMESHGUI_FilterTable*     myTable;
293
294   // initial fields
295   QList<int>                myTypes;
296   SMESHGUI*                 mySMESHGUI;
297   LightApp_SelectionMgr*    mySelectionMgr;
298   SVTK_Selector*            mySelector;
299   SMESH::SMESH_Mesh_var     myMesh;
300   bool                      myInitSourceWgOnApply;
301   bool                      myInsertEnabled;
302   bool                      myDiffSourcesEnabled;
303   QWidget*                  mySourceWg;
304
305   SALOME_DataMapOfIOMapOfInteger myIObjects;
306   bool                           myIsSelectionChanged;
307   QMap< int, SMESH::Filter_var > myFilter;
308   QMap< int, bool >              myInsertState;
309   QMap< int, int  >              myApplyToState;
310
311   QString                   myHelpFileName;
312
313   bool                      myToRestoreSelMode;
314   int                       mySelModeToRestore;
315   void                      restoreSelMode();
316 };
317
318 #endif // SMESHGUI_FILTERDLG_H