Salome HOME
Prevent exception at shape selection if no mesh was pre-selected
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.h
1 //  SMESH SMESHGUI : GUI for SMESH component
2 //
3 //  Copyright (C) 2003  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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org 
21 //
22 //
23 //
24 //  File   : SMESHGUI_FilterDlg.h
25 //  Author : Sergey LITONIN      
26 //  Module : SMESH
27
28
29 #ifndef SMESHGUI_FilterDlg_H
30 #define SMESHGUI_FilterDlg_H
31
32 #include <qdialog.h>
33 #include <qframe.h>
34 #include <qmap.h>
35 #include <qvaluelist.h>
36
37 #include "SALOME_Selection.h"
38 #include "SALOME_InteractiveObject.hxx"
39 #include "SALOME_DataMapOfIOMapOfInteger.hxx"
40
41 #include <TColStd_IndexedMapOfInteger.hxx>
42
43 #include <SALOMEconfig.h>
44 #include CORBA_SERVER_HEADER(SMESH_Filter)
45 #include CORBA_SERVER_HEADER(SMESH_Mesh)
46
47 class QButtonGroup;
48 class QCheckBox;
49 class QCloseEvent;
50 class QComboBox;
51 class QEvent;
52 class QGroupBox;
53 class QPushButton;
54 class QStringList;
55 class QTable;
56 class QTableItem;
57 class QWidgetStack;
58 class SALOME_Selection;
59 class SMESHGUI;
60 class SMESHGUI_FilterLibraryDlg;
61
62 /*
63   Class       : SMESHGUI_FilterTable
64   Description : Frame containig 
65                   - Button group for switching entity type
66                   - Table for displaying filter criterions
67                   - Buttons for editing table
68 */
69
70 class SMESHGUI_FilterTable : public QFrame
71 {
72   Q_OBJECT
73
74   class Table;
75   class ComboItem;
76   class AdditionalWidget;
77
78   typedef QMap<int, Table*> TableMap;
79
80 public:  
81   
82                             SMESHGUI_FilterTable( QWidget* parent, 
83                                                   const int type );
84                             SMESHGUI_FilterTable( QWidget* parent, 
85                                                   const QValueList<int>& type );
86   virtual                   ~SMESHGUI_FilterTable();
87   
88   void                      Init( const int type );
89   void                      Init( const QValueList<int>& types );
90
91   QGroupBox*                GetTableGrp();
92
93   bool                      IsValid( const bool = true, const int theEntityType = -1 ) const;
94   int                       GetType() const;
95   void                      SetType( const int );
96   void                      RestorePreviousEntityType();
97   int                       NumRows( const int theEntityType = -1 ) const;
98   void                      Clear( const int theEntityType = -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 theRow, const int theType = -1 ) const;
105   
106   void                      GetCriterion( const int                 theRow,
107                                           SMESH::Filter::Criterion& theCriterion,
108                                           const int                 theEntityType = -1 ) const;
109
110   void                      SetCriterion( const int                       theRow,
111                                           const SMESH::Filter::Criterion& theCriterion,
112                                           const int                       theEntityType = -1 );
113
114   void                      AddCriterion( const SMESH::Filter::Criterion& theCriterion,
115                                           const int    theEntityType = -1 );
116   
117   void                      Copy( const SMESHGUI_FilterTable* );
118   void                      SetValidity( const bool );
119
120   bool                      CurrentCell( int& theRow, int& theCol ) const;
121   void                      SetThreshold( const int      theRow,
122                                           const QString& theText,
123                                           const int      theEntityType = -1 );
124
125   bool                      GetThreshold( const int      theRow,
126                                           QString&       theText,
127                                           const int      theEntityType = -1 );
128
129   void                      Update();
130
131  
132 signals:
133
134   void                      CopyFromClicked();
135   void                      AddToClicked();
136   void                      EntityTypeChanged( const int );
137   void                      NeedValidation();
138   void                      CretarionChanged( const int theRow, const int theEntityType );
139   void                      CurrentChanged( int, int );
140   
141 private slots:
142
143   void                      onAddBtn();
144   void                      onInsertBtn();
145   void                      onRemoveBtn();
146   void                      onClearBtn();
147   void                      onCopyFromBtn();
148   void                      onAddToBtn();
149   void                      onCriterionChanged( int, int );
150   void                      onEntityType( int );
151   void                      onCurrentChanged( int, int );
152
153 private:
154
155   void                      addRow( Table*, const int, const bool toTheEnd = true );
156   QTableItem*               getCriterionItem( QTable*, const int );
157   QTableItem*               getCompareItem( QTable* );
158   QTableItem*               getUnaryItem( QTable* );
159   QTableItem*               getBinaryItem( QTable* );
160   const QMap<int, QString>& getCriteria( const int theType ) const;
161   const QMap<int, QString>& getCompare() const;
162   Table*                    createTable( QWidget*, const int );
163   QWidget*                  createAdditionalFrame( QWidget* theParent );
164   int                       getFirstSelectedRow() const;
165   void                      onCriterionChanged( const int, const int, const int  );
166   
167   void                      updateBtnState();
168   void                      removeAdditionalWidget( QTable* theTable, const int theRow );
169   void                      updateAdditionalWidget();
170
171   const QMap<int, QString>& getSupportedTypes() const;
172   
173 private:
174
175   QGroupBox*                myTableGrp;
176   QGroupBox*                mySwitchTableGrp;
177
178   TableMap                  myTables;
179   QPushButton*              myAddBtn;
180   QPushButton*              myInsertBtn;
181   QPushButton*              myRemoveBtn;
182   QPushButton*              myClearBtn;  
183   QPushButton*              myCopyFromBtn;  
184   QPushButton*              myAddToBtn;
185
186   QButtonGroup*             myEntityTypeGrp;
187   int                       myEntityType;
188   int                       myIsValid;
189   
190   SMESHGUI_FilterLibraryDlg* myLibDlg;
191
192   QWidgetStack*             myWgStack;
193   QMap<QTableItem*, AdditionalWidget*> myAddWidgets;
194 };
195
196
197 /*
198   Class       : SMESHGUI_FilterDlg
199   Description : Dialog to specify filters for VTK viewer
200 */
201
202 class SMESHGUI_FilterDlg : public QDialog
203
204   Q_OBJECT
205
206   // Source elements to be selected
207   enum { Mesh, Selection, Dialog, None };
208   
209   // Buttons
210   enum { BTN_OK, BTN_Cancel, BTN_Apply, BTN_Close };
211
212 public:
213                             SMESHGUI_FilterDlg( QWidget*               parent,
214                                                 const QValueList<int>& types,
215                                                 const char*            name = 0 );
216                                                 
217                             SMESHGUI_FilterDlg( QWidget*               parent,
218                                                 const int              type,
219                                                 const char*            name = 0 );                                                    
220   virtual                   ~SMESHGUI_FilterDlg();
221
222   void                      Init( const QValueList<int>& types );
223   void                      Init( const int type );
224
225   void                      SetSelection( SALOME_Selection* );
226   void                      SetMesh( SMESH::SMESH_Mesh_ptr );
227   void                      SetSourceWg( QWidget* );
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                      onDeactivate();
241   void                      onSelectionDone();
242   void                      onCriterionChanged( const int, const int );
243   void                      onCurrentChanged( int, int );
244   
245 private:
246
247   void                      construct( const QValueList<int>& types ); 
248
249   void                      closeEvent( QCloseEvent* e );
250   void                      enterEvent ( QEvent * );
251
252   // dialog creation
253   QFrame*                   createButtonFrame( QWidget* );
254   QFrame*                   createMainFrame( QWidget* );
255   QButtonGroup*             createSourceGroup( QWidget* );
256   void                      updateMainButtons();
257   
258   // execution
259   bool                      isValid() const;
260   bool                      createFilter( const int theType );
261   void                      insertFilterInViewer();
262   void                      selectInViewer( const int theType,
263                                             const QValueList<int>& theIds );
264   void                      filterSource( const int            theType,
265                                           QValueList<int>&     theResIds );
266   void                      filterSelectionSource( const int            theType,
267                                                    QValueList<int>&     theResIds );
268   void                      getIdsFromWg( const QWidget*, QValueList<int>& ) const;
269   void                      setIdsToWg( QWidget*, const QValueList<int>& );
270   Selection_Mode            getSelMode( const int ) const;
271   void                      updateSelection();
272
273 private:
274
275   // widgets
276   QFrame*                   myMainFrame;
277   QButtonGroup*             mySourceGrp;
278
279   QCheckBox*                mySetInViewer;
280
281   QMap<int, QPushButton*>   myButtons;
282   
283   SMESHGUI_FilterTable*     myTable;
284
285   // initial fields
286   QValueList<int>           myTypes;
287   SMESHGUI*                 mySMESHGUI;
288   SALOME_Selection*         mySelection;
289   SMESH::SMESH_Mesh_ptr     myMesh;
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
299 #endif
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319