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