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