Salome HOME
Copyright update 2020
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 // Copyright (C) 2007-2020  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 LightApp_SelectionMgr;
49 class QButtonGroup;
50 class QCheckBox;
51 class QFrame;
52 class QGroupBox;
53 class QPushButton;
54 class QStackedWidget;
55 class QTableWidget;
56 class QTableWidgetItem;
57 class SMESHGUI;
58 class SMESHGUI_FilterLibraryDlg;
59 class SMESH_Actor;
60 class SVTK_Selector;
61
62 /*!
63  *  Class       : SMESHGUI_FilterTable
64  *  Description : Frame containing 
65  *                  - Button group for switching entity type
66  *                  - Table for displaying filter criterions
67  *                  - Buttons for editing table
68  */
69
70 class SMESHGUI_EXPORT SMESHGUI_FilterTable : public QWidget
71 {
72   Q_OBJECT
73
74   class Table;
75   class ComboItem;
76   class IntSpinItem;
77   class DoubleSpinItem;
78   class CheckItem;
79   class AdditionalWidget;
80   class ComboDelegate;
81
82   typedef QMap<int, Table*> TableMap;
83
84 public:  
85   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const int );
86   SMESHGUI_FilterTable( SMESHGUI*, QWidget*, const QList<int>& );
87   virtual ~SMESHGUI_FilterTable();
88
89   void                      Init( const QList<int>& );
90
91   QGroupBox*                GetTableGrp();
92
93   bool                      IsValid( const bool = true, const int = -1 ) const;
94   int                       GetType() const;
95   void                      SetType(const int);
96   void                      RestorePreviousEntityType();
97   int                       NumRows( const int = -1 ) const;
98   void                      Clear( const int = -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, const int = -1 ) const;
105
106   void                      GetCriterion( const int,
107                                           SMESH::Filter::Criterion&,
108                                           const int = -1 ) const;
109
110   void                      SetCriterion( const int,
111                                           const SMESH::Filter::Criterion&,
112                                           const int = -1 );
113
114   void                      AddCriterion( const SMESH::Filter::Criterion&,
115                                           const int = -1 );
116
117   void                      Copy( const SMESHGUI_FilterTable* );
118   void                      SetValidity( const bool );
119
120   bool                      CurrentCell( int&, int& ) const;
121   void                      SetThreshold( const int,
122                                           const QString&,
123                                           const int = -1 );
124
125   bool                      GetThreshold( const int,
126                                           QString&,
127                                           const int = -1 );
128
129   void                      SetID( const int,
130                                    const QString&,
131                                    const int = -1 ); 
132   
133   bool                      GetID( const int,
134                                    QString&,
135                                    const int = -1 );
136
137   void                      Update();
138
139 signals:
140   void                      CopyFromClicked();
141   void                      AddToClicked();
142   void                      EntityTypeChanged( const int );
143   void                      NeedValidation();
144   void                      CriterionChanged( const int, const int );
145   void                      ThresholdChanged( const int, const int );
146   void                      CurrentChanged( int, int );
147
148 private slots:
149   void                      onAddBtn();
150   void                      onInsertBtn();
151   void                      onRemoveBtn();
152   void                      onClearBtn();
153   void                      onCopyFromBtn();
154   void                      onAddToBtn();
155   void                      onCriterionChanged( int, int );
156   void                      onEntityType( int );
157   void                      onCurrentChanged( int, int );
158
159 private:
160   void                      addRow( Table*, const int, const bool = true );
161   QTableWidgetItem*         getCriterionItem( const int ) const;
162   QTableWidgetItem*         getCompareItem() const;
163   QTableWidgetItem*         getUnaryItem() const;
164   QTableWidgetItem*         getBinaryItem() const;
165   const QMap<int, QString>& getCriteria( const int ) const;
166   const QMap<int, QString>& getCompare() const;
167   Table*                    createTable( QWidget*, const int );
168   QWidget*                  createAdditionalFrame( QWidget* );
169   int                       getFirstSelectedRow() const;
170   void                      onCriterionChanged( const int, const int, const int );
171
172   void                      updateBtnState();
173   void                      removeAdditionalWidget( QTableWidget*, const int );
174   void                      updateAdditionalWidget();
175   const char*               getPrecision( const int );
176
177   const QMap<int, QString>& getSupportedTypes() const;
178
179 private:
180   SMESHGUI*                 mySMESHGUI;
181
182   QGroupBox*                myTableGrp;
183   QWidget*                  mySwitchTableGrp;
184
185   TableMap                  myTables;
186   QPushButton*              myAddBtn;
187   QPushButton*              myInsertBtn;
188   QPushButton*              myRemoveBtn;
189   QPushButton*              myClearBtn;  
190   QPushButton*              myCopyFromBtn;  
191   QPushButton*              myAddToBtn;
192
193   QGroupBox*                myEntityTypeBox;
194   QButtonGroup*             myEntityTypeGrp;
195   int                       myEntityType;
196   int                       myIsValid;
197   bool                      myIsLocked;
198
199   SMESHGUI_FilterLibraryDlg* myLibDlg;
200
201   QStackedWidget*           myWgStack;
202
203   QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
204 };
205
206
207 /*!
208  *  Class       : SMESHGUI_FilterDlg
209  *  Description : Dialog to specify filters for VTK viewer
210  */
211
212 class SMESHGUI_FilterDlg : public QDialog
213 {
214   Q_OBJECT
215
216   // Source elements to be selected
217   enum { Mesh, Selection, Dialog, None };
218
219   // Buttons
220   enum { BTN_OK, BTN_Apply, BTN_Close, BTN_Help };
221
222 public:
223   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
224   SMESHGUI_FilterDlg( SMESHGUI*, const int );
225   virtual ~SMESHGUI_FilterDlg();
226
227   void                      Init( const QList<int>&, const bool setInViewer=true );
228   void                      Init( const int, const bool setInViewer=true );
229
230   void                      SetSelection();
231   void                      SetMesh (SMESH::SMESH_Mesh_var);
232   void                      SetGroup (SMESH::SMESH_GroupOnFilter_var);
233   void                      SetSourceWg( QWidget*, const bool initOnApply = true );
234   void                      SetEnabled( bool setInViewer, bool diffSources );
235
236   static SMESH::Filter::Criterion createCriterion();
237
238   SMESH::Filter_var         GetFilter() const;
239   void                      SetFilter(SMESH::Filter_var filter, int type);
240   void                      UnRegisterFilters();
241
242 signals:
243
244   void                      Accepted();
245
246 protected slots:
247   virtual void              reject();
248
249 private slots:
250
251   void                      onOk();
252   bool                      onApply();
253   void                      onHelp();
254   void                      onDeactivate();
255   void                      onSelectionDone();
256   void                      onCriterionChanged( const int, const int );
257   void                      onThresholdChanged( const int, const int );
258   void                      onCurrentChanged( int, int );
259   void                      onOpenView();
260   void                      onCloseView();
261
262 private:
263
264   void                      construct( const QList<int>& ); 
265
266   void                      enterEvent( QEvent* );
267   void                      keyPressEvent( QKeyEvent* );
268
269   // dialog creation
270   QWidget*                  createButtonFrame( QWidget* );
271   QWidget*                  createMainFrame( QWidget* );
272   QWidget*                  createSourceGroup( QWidget* );
273   void                      updateMainButtons();
274
275   // execution
276   bool                      isValid() const;
277   bool                      createFilter( const int );
278   void                      insertFilterInViewer();
279   void                      selectInViewer( const int, const QList<int>& );
280   void                      filterSource( const int, QList<int>& );
281   void                      filterSelectionSource( const int, QList<int>& );
282   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
283   void                      setIdsToWg( QWidget*, const QList<int>& );
284   Selection_Mode            getSelMode( const int ) const;
285   void                      updateSelection();
286   SMESH_Actor*              getActor();
287
288 private:
289   // widgets
290   QWidget*                  myMainFrame;
291   QButtonGroup*             mySourceGrp;
292
293   QCheckBox*                mySetInViewer;
294
295   QMap<int, QPushButton*>   myButtons;
296   
297   SMESHGUI_FilterTable*     myTable;
298
299   // initial fields
300   QList<int>                myTypes;
301   SMESHGUI*                 mySMESHGUI;
302   LightApp_SelectionMgr*    mySelectionMgr;
303   SVTK_Selector*            mySelector;
304   SMESH::SMESH_Mesh_var     myMesh;
305   SMESH::SMESH_GroupOnFilter_var myGroup;
306   bool                      myInitSourceWgOnApply;
307   bool                      myInsertEnabled;
308   bool                      myDiffSourcesEnabled;
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   bool                      myToRestoreSelMode;
320   int                       mySelModeToRestore;
321   void                      restoreSelMode();
322 };
323
324 #endif // SMESHGUI_FILTERDLG_H