Salome HOME
Update copyright
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 // Copyright (C) 2007-2011  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
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                      CurrentChanged( int, int );
145
146 private slots:
147   void                      onAddBtn();
148   void                      onInsertBtn();
149   void                      onRemoveBtn();
150   void                      onClearBtn();
151   void                      onCopyFromBtn();
152   void                      onAddToBtn();
153   void                      onCriterionChanged( int, int );
154   void                      onEntityType( int );
155   void                      onCurrentChanged( int, int );
156
157 private:
158   void                      addRow( Table*, const int, const bool = true );
159   QTableWidgetItem*         getCriterionItem( const int ) const;
160   QTableWidgetItem*         getCompareItem() const;
161   QTableWidgetItem*         getUnaryItem() const;
162   QTableWidgetItem*         getBinaryItem() const;
163   const QMap<int, QString>& getCriteria( const int ) const;
164   const QMap<int, QString>& getCompare() const;
165   Table*                    createTable( QWidget*, const int );
166   QWidget*                  createAdditionalFrame( QWidget* );
167   int                       getFirstSelectedRow() const;
168   void                      onCriterionChanged( const int, const int, const int );
169
170   void                      updateBtnState();
171   void                      removeAdditionalWidget( QTableWidget*, const int );
172   void                      updateAdditionalWidget();
173   const char*               getPrecision( const int );
174
175   const QMap<int, QString>& getSupportedTypes() const;
176
177 private:
178   SMESHGUI*                 mySMESHGUI;
179
180   QGroupBox*                myTableGrp;
181   QWidget*                  mySwitchTableGrp;
182
183   TableMap                  myTables;
184   QPushButton*              myAddBtn;
185   QPushButton*              myInsertBtn;
186   QPushButton*              myRemoveBtn;
187   QPushButton*              myClearBtn;  
188   QPushButton*              myCopyFromBtn;  
189   QPushButton*              myAddToBtn;
190
191   QGroupBox*                myEntityTypeBox;
192   QButtonGroup*             myEntityTypeGrp;
193   int                       myEntityType;
194   int                       myIsValid;
195   bool                      myIsLocked;
196
197   SMESHGUI_FilterLibraryDlg* myLibDlg;
198
199   QStackedWidget*           myWgStack;
200
201   QMap<QTableWidgetItem*, AdditionalWidget*> myAddWidgets;
202 };
203
204
205 /*!
206  *  Class       : SMESHGUI_FilterDlg
207  *  Description : Dialog to specify filters for VTK viewer
208  */
209
210 class SMESHGUI_FilterDlg : public QDialog
211 {
212   Q_OBJECT
213
214   // Source elements to be selected
215   enum { Mesh, Selection, Dialog, None };
216
217   // Buttons
218   enum { BTN_OK, BTN_Apply, BTN_Close, BTN_Help };
219
220 public:
221   SMESHGUI_FilterDlg( SMESHGUI*, const QList<int>& );
222   SMESHGUI_FilterDlg( SMESHGUI*, const int );
223   virtual ~SMESHGUI_FilterDlg();
224
225   void                      Init( const QList<int>& );
226   void                      Init( const int );
227
228   void                      SetSelection();
229   void                      SetMesh (SMESH::SMESH_Mesh_var);
230   void                      SetSourceWg( QWidget*, const bool initOnApply = true );
231
232   static SMESH::Filter::Criterion createCriterion();
233
234 signals:
235
236   void                      Accepted();
237
238 private slots:
239
240   void                      onOk();
241   bool                      onApply();
242   void                      onClose();
243   void                      onHelp();
244   void                      onDeactivate();
245   void                      onSelectionDone();
246   void                      onCriterionChanged( const int, const int );
247   void                      onCurrentChanged( int, int );
248
249 private:
250
251   void                      construct( const QList<int>& ); 
252
253   void                      closeEvent( QCloseEvent* );
254   void                      enterEvent( QEvent* );
255   void                      keyPressEvent( QKeyEvent* );
256
257   // dialog creation
258   QWidget*                  createButtonFrame( QWidget* );
259   QWidget*                  createMainFrame( QWidget* );
260   QWidget*                  createSourceGroup( QWidget* );
261   void                      updateMainButtons();
262
263   // execution
264   bool                      isValid() const;
265   bool                      createFilter( const int );
266   void                      insertFilterInViewer();
267   void                      selectInViewer( const int, const QList<int>& );
268   void                      filterSource( const int, QList<int>& );
269   void                      filterSelectionSource( const int, QList<int>& );
270   void                      getIdsFromWg( const QWidget*, QList<int>& ) const;
271   void                      setIdsToWg( QWidget*, const QList<int>& );
272   Selection_Mode            getSelMode( const int ) const;
273   void                      updateSelection();
274
275 private:
276   // widgets
277   QWidget*                  myMainFrame;
278   QButtonGroup*             mySourceGrp;
279
280   QCheckBox*                mySetInViewer;
281
282   QMap<int, QPushButton*>   myButtons;
283   
284   SMESHGUI_FilterTable*     myTable;
285
286   // initial fields
287   QList<int>                myTypes;
288   SMESHGUI*                 mySMESHGUI;
289   LightApp_SelectionMgr*    mySelectionMgr;
290   SVTK_Selector*            mySelector;
291   SMESH::SMESH_Mesh_var     myMesh;
292   bool                      myInitSourceWgOnApply;
293   QWidget*                  mySourceWg;
294
295   SALOME_DataMapOfIOMapOfInteger myIObjects;
296   bool                           myIsSelectionChanged;
297   QMap< int, SMESH::Filter_var > myFilter;
298   QMap< int, bool >              myInsertState;
299   QMap< int, int  >              myApplyToState;
300
301   QString                   myHelpFileName;
302 };
303
304 #endif // SMESHGUI_FILTERDLG_H