Salome HOME
Integration of PAL/SALOME V2.1.0c from OCC
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
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.cxx
25 //  Author : Sergey LITONIN
26 //  Module : SMESH
27
28 #include "SMESHGUI_FilterDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
34
35 #include "SMESHGUI_Filter.h"
36 #include "SMESH_Actor.h"
37 #include "VTKViewer_ViewFrame.h"
38 #include "QAD_Desktop.h"
39 #include "QAD_MessageBox.h"
40 #include "QAD_RightFrame.h"
41 #include "QAD_Config.h"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx"
44 #include "SALOMEGUI_QtCatchCorbaException.hxx"
45 #include "SMESHGUI_FilterLibraryDlg.h"
46 #include "SALOME_TypeFilter.hxx"
47
48 #include "GEOMBase.h"
49 #include "GEOM_FaceFilter.hxx"
50
51 #include <TColStd_MapOfInteger.hxx>
52 #include <TColStd_IndexedMapOfInteger.hxx>
53 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
54 #include <Precision.hxx>
55 #include <BRep_Tool.hxx>
56 #include <TopoDS_Shape.hxx>
57 #include <TopoDS.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <Geom_Plane.hxx>
60 #include <Geom_CylindricalSurface.hxx>
61
62 #include <qframe.h>
63 #include <qlayout.h>
64 #include <qlineedit.h>
65 #include <qpushbutton.h>
66 #include <qgroupbox.h>
67 #include <qtable.h>
68 #include <qstringlist.h>
69 #include <qlayout.h>
70 #include <qwidgetstack.h>
71 #include <qapplication.h>
72 #include <qcombobox.h>
73 #include <qfontmetrics.h>
74 #include <qmessagebox.h>
75 #include <qlabel.h>
76 #include <qbuttongroup.h>
77 #include <qradiobutton.h>
78 #include <qregexp.h>
79 #include <qlistbox.h>
80 #include <qcheckbox.h>
81 #include <qobjectlist.h>
82 #include <qvalidator.h>
83
84 #define SPACING 5                  
85 #define MARGIN  10
86
87 using namespace SMESH;
88
89 static int maxLength( const QMap<int, QString> theMap, const QFontMetrics& theMetrics )
90 {
91   int aRes = 0;
92   QMap<int, QString>::const_iterator anIter;
93   for ( anIter = theMap.begin(); anIter != theMap.end(); ++anIter )
94     aRes = Max( aRes, theMetrics.width( anIter.data() ) );
95   return aRes; 
96 }
97
98 static int getFilterId( SMESH::ElementType theType )
99 {
100   switch ( theType )
101   {
102     case SMESH::NODE   : return SMESHGUI_NodeFilter;
103     case SMESH::EDGE   : return SMESHGUI_EdgeFilter;
104     case SMESH::FACE   : return SMESHGUI_FaceFilter;
105     case SMESH::VOLUME : return SMESHGUI_VolumeFilter;
106     case SMESH::ALL    : return SMESHGUI_AllElementsFilter;
107     default            : return SMESHGUI_UnknownFilter;
108   }
109 }
110
111 /*
112   Class       : SMESHGUI_FilterTable::AdditionalWidget
113   Description : Class for storing additional parameters of criterion
114 */
115
116 class SMESHGUI_FilterTable::AdditionalWidget : public QFrame
117 {
118 public:
119   enum { Tolerance };
120   
121 public:
122
123                           AdditionalWidget( QWidget* theParent );
124   virtual                 ~AdditionalWidget();
125
126   virtual void            GetParameters( QValueList<int>& ) const;
127   virtual bool            IsValid( const bool theMsg = true ) const;
128   virtual double          GetDouble( const int theId ) const;
129   virtual int             GetInteger( const int theId ) const;
130   virtual QString         GetString( const int theId ) const;
131   virtual void            SetDouble( const int theId, const double theVal );
132   virtual void            SetInteger( const int theId, const int theVal );
133   virtual void            SetString( const int theId, const QString& theVal );
134   void                    SetEditable( const int theId, const bool isEditable );
135   void                    SetEditable( const bool isEditable );
136
137 private:
138   QMap< int, QLineEdit* > myLineEdits;
139 };
140
141 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget( QWidget* theParent )
142 : QFrame( theParent )
143 {
144   QLabel* aLabel = new QLabel( tr( "SMESH_TOLERANCE" ), this );
145   myLineEdits[ Tolerance ] = new QLineEdit( this );
146   QDoubleValidator* aValidator = new QDoubleValidator( myLineEdits[ Tolerance ] );
147   aValidator->setBottom( 0 );
148   myLineEdits[ Tolerance ]->setValidator( aValidator );
149
150   QHBoxLayout* aLay = new QHBoxLayout( this, 0, SPACING );
151   aLay->addWidget( aLabel );
152   aLay->addWidget( myLineEdits[ Tolerance ] );
153   
154   QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
155   aLay->addItem( aSpacer );
156
157   QString aText = QString( "%1" ).arg( Precision::Confusion() );
158   myLineEdits[ Tolerance ]->setText( aText );
159 }
160 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
161 {
162 }
163
164 void SMESHGUI_FilterTable::AdditionalWidget::GetParameters( QValueList<int>& theList ) const
165 {
166   theList.clear();
167   theList.append( Tolerance );
168 }
169
170 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid( const bool theMsg ) const
171 {
172   if ( !isEnabled() )
173     return true;
174
175   QValueList<int> aParams;
176   GetParameters( aParams );
177   QValueList<int>::const_iterator anIter;
178   for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
179   {
180     const QLineEdit* aWg = myLineEdits[ *anIter ];
181     int p = 0;
182     QString aText = aWg->text();
183     if ( aWg->isEnabled() && aWg->validator()->validate( aText, p ) != QValidator::Acceptable )
184     {
185       if ( theMsg )
186           QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
187             tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
188         return false;
189     }
190   }
191
192   return true;
193 }
194
195 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble( const int theId ) const
196 {
197   return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toDouble() : 0;
198 }
199
200 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger( const int theId ) const
201 {
202   return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toInt() : 0;
203 }
204
205 QString SMESHGUI_FilterTable::AdditionalWidget::GetString( const int theId ) const
206 {
207   return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text() : QString("");
208 }
209
210 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble( const int theId, const double theVal )
211 {
212   if ( myLineEdits.contains( theId ) )
213     myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
214 }
215
216 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger( const int theId, const int theVal )
217 {
218   if ( myLineEdits.contains( theId ) )
219     myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
220 }
221
222 void SMESHGUI_FilterTable::AdditionalWidget::SetString( const int theId, const QString& theVal )
223 {
224   if ( myLineEdits.contains( theId ) )
225     myLineEdits[ theId ]->setText( theVal );
226 }
227
228 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const int theId, const bool isEditable )
229 {
230   if ( myLineEdits.contains( theId ) )
231     myLineEdits[ theId ]->setEdited( isEditable );
232 }
233
234 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const bool isEditable )
235 {
236   QValueList<int> aParams;
237   GetParameters( aParams );
238   QValueList<int>::const_iterator anIter;
239   for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
240     myLineEdits[ *anIter ]->setEdited( isEditable );
241 }
242
243 /*
244   Class       : SMESHGUI_FilterTable::ComboItem
245   Description : Combo table item. Identificator corresponding to string may be assigned
246 */
247
248 class SMESHGUI_FilterTable::ComboItem : public QComboTableItem
249
250 {
251 public:
252                           ComboItem( QTable*, const QMap<int, QString>& );
253   virtual                 ~ComboItem();
254
255   virtual void            setStringList ( const QStringList & l );
256   void                    setStringList( const QMap<int, QString>& theIds );
257
258   int                     GetValue() const;
259   void                    SetValue( const int );
260   
261 private:
262   
263   QMap<int, int>          myNumToId;
264   QMap<int, int>          myIdToNum;
265 };
266
267 SMESHGUI_FilterTable::ComboItem::ComboItem( QTable*                   theParent, 
268                                             const QMap<int, QString>& theIds )
269 : QComboTableItem( theParent, QStringList() )
270 {
271   setStringList( theIds );
272 }
273
274 void SMESHGUI_FilterTable::ComboItem::setStringList( const QStringList & l )
275 {
276   QComboTableItem::setStringList( l );
277 }
278
279 void SMESHGUI_FilterTable::ComboItem::setStringList( const QMap<int, QString>& theIds )
280 {
281   int i = 0;
282   QStringList aList;
283   QMap<int, QString>::const_iterator anIter;
284   for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
285   {
286     myNumToId[ i ] = anIter.key();
287     myIdToNum[ anIter.key() ] = i;
288     aList.append( anIter.data() );
289     i++;
290   }
291
292   setStringList( aList );
293 }
294
295 SMESHGUI_FilterTable::ComboItem::~ComboItem()
296 {
297 }
298   
299 int SMESHGUI_FilterTable::ComboItem::GetValue() const
300 {
301   return myNumToId[ currentItem() ];
302 }
303
304 void SMESHGUI_FilterTable::ComboItem::SetValue( const int theVal )
305 {
306   setCurrentItem( myIdToNum[ theVal ] );
307 }
308
309
310 /*
311   Class       : SMESHGUI_FilterTable::Table            
312   Description : Table used by this widget
313 */
314
315 class SMESHGUI_FilterTable::Table : public QTable
316 {
317 public:
318                           Table( QWidget* parent );
319                           Table( int numRows, int numCols, QWidget* parent = 0 );
320   virtual                 ~Table();
321
322   void                    SetEditable( const bool state, const int row, const int col );
323   bool                    IsEditable( const int row, const int col ) const;  
324
325   virtual void            insertRows( int row, int count = 1 );
326   virtual QString         text( int row, int col ) const;
327 };
328
329 //=======================================================================
330 // name    : SMESHGUI_FilterTable::Table::Table
331 // Purpose : Constructor
332 //=======================================================================
333 SMESHGUI_FilterTable::Table::Table( QWidget* parent )
334 : QTable( parent, "SMESHGUI_FilterTable::Table" )
335 {
336 }
337
338 SMESHGUI_FilterTable::Table::Table( int numRows, int numCols, QWidget* parent )
339 : QTable( numRows, numCols, parent, "SMESHGUI_FilterTable::Table" )
340 {
341 }
342
343 SMESHGUI_FilterTable::Table::~Table()
344 {
345 }
346
347 //=======================================================================
348 // name    : SMESHGUI_FilterTable::Table::SetEditable
349 // Purpose : Set editable of specified cell
350 //=======================================================================
351 void SMESHGUI_FilterTable::Table::SetEditable( const bool isEditable, const int row, const int col )
352 {
353   QTableItem* anItem = item( row, col );
354   if( anItem )
355     takeItem( anItem );
356
357   if ( !isEditable )
358     setItem( row, col, new QTableItem( this, QTableItem::Never, "" ) );
359   else
360     setItem( row, col, new QTableItem( this, QTableItem::OnTyping, "" ) );
361 }
362
363 //=======================================================================
364 // name    : SMESHGUI_FilterTable::Table::IsEditable
365 // Purpose : Verify wheter cell is editable
366 //=======================================================================
367 bool SMESHGUI_FilterTable::Table::IsEditable( const int row, const int col ) const
368 {
369   QTableItem* anItem = item( row, col );
370   return anItem == 0 || anItem->editType() != QTableItem::Never;
371 }
372
373 //=======================================================================
374 // name    : SMESHGUI_FilterTable::Table::insertRows
375 // Purpose : Insert rows ( virtual redefined )
376 //=======================================================================
377 void SMESHGUI_FilterTable::Table::insertRows( int row, int count )
378 {
379   int anEditRow = currEditRow();
380   int anEditCol = currEditCol();
381
382   if ( anEditRow >= 0 && anEditCol >= 0 )
383     endEdit( anEditRow, anEditCol, true, false );
384
385   QTable::insertRows( row, count );
386 }
387
388 //=======================================================================
389 // name    : SMESHGUI_FilterTable::Table::text
390 // Purpose : Get text from cell ( virtual redefined ) 
391 //=======================================================================
392 QString SMESHGUI_FilterTable::Table::text( int row, int col ) const
393 {
394   int anEditRow = currEditRow();
395   int anEditCol = currEditCol();
396
397   if ( anEditRow >= 0 && anEditCol >= 0 && anEditRow == row && anEditCol == col )
398     ((Table*)this)->endEdit( row, col, true, false );
399
400   return QTable::text( row, col );
401 }
402
403
404
405 /*
406   Class       : SMESHGUI_FilterTable
407   Description : Frame containig 
408                   - Button group for switching entity type
409                   - Table for displaying filter criterions
410                   - Buttons for editing table and filter libraries
411 */
412
413 //=======================================================================
414 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
415 // Purpose : Constructor
416 //=======================================================================
417 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent, 
418                                             const int type )
419 : QFrame( parent )                                            
420 {
421   myEntityType = -1;
422   Init( type );
423 }                 
424
425 //=======================================================================
426 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
427 // Purpose : Constructor
428 //=======================================================================
429 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent, 
430                                             const QValueList<int>& types )
431 : QFrame( parent )                                            
432 {
433   myEntityType = -1;
434   Init( types );
435 }                                            
436
437 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
438 {
439 }
440
441 //=======================================================================
442 // name    : SMESHGUI_FilterTable::Init
443 // Purpose : Create table corresponding to the specified type
444 //=======================================================================
445 void SMESHGUI_FilterTable::Init( const int type )
446 {
447   QValueList<int> aTypes;
448   aTypes.append( type );
449   Init( aTypes );
450 }
451
452 //=======================================================================
453 // name    : SMESHGUI_FilterTable::Init
454 // Purpose : Create table corresponding to the specified type
455 //=======================================================================
456 void SMESHGUI_FilterTable::Init( const QValueList<int>& theTypes )
457 {
458   if ( theTypes.isEmpty() )
459     return;
460   
461   // Create buttons if necessary
462   
463   if ( myTables.isEmpty() ) 
464   {
465     int aType = theTypes.first();
466
467     // create main layout
468     QVBoxLayout* aMainLay = new QVBoxLayout( this );
469     QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, this );
470     aMainGrp->setFrameStyle( QFrame::NoFrame );
471     aMainGrp->setInsideMargin( 0 );
472     aMainLay->addWidget( aMainGrp );
473     
474     // create switch of entity types
475     myEntityTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "ENTITY_TYPE" ), aMainGrp );
476     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
477     QMap<int, QString>::const_iterator anIter;
478     for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
479     {
480       QRadioButton* aBtn = new QRadioButton( anIter.data(), myEntityTypeGrp );
481       myEntityTypeGrp->insert( aBtn, anIter.key() );
482     }
483
484     myTableGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FILTER" ), aMainGrp  );
485     QFrame* aTableFrame = new QFrame( myTableGrp );
486   
487     // create table
488     mySwitchTableGrp = new QGroupBox( 1, Qt::Horizontal, aTableFrame );
489     mySwitchTableGrp->setFrameStyle( QFrame::NoFrame );
490     mySwitchTableGrp->setInsideMargin( 0 );
491     
492     myTables[ aType ] = createTable( mySwitchTableGrp, aType );
493   
494     // create buttons
495     myAddBtn      = new QPushButton( tr( "ADD" ), aTableFrame );
496     myRemoveBtn   = new QPushButton( tr( "REMOVE" ), aTableFrame );
497     myClearBtn    = new QPushButton( tr( "CLEAR" ), aTableFrame );
498     myInsertBtn   = new QPushButton( tr( "INSERT" ), aTableFrame );
499     myCopyFromBtn = new QPushButton( tr( "COPY_FROM" ), aTableFrame );
500     myAddToBtn    = new QPushButton( tr( "ADD_TO" ), aTableFrame );
501
502     myAddBtn->setAutoDefault( false );
503     myRemoveBtn->setAutoDefault( false );
504     myClearBtn->setAutoDefault( false );
505     myInsertBtn->setAutoDefault( false );
506     myCopyFromBtn->setAutoDefault( false );
507     myAddToBtn->setAutoDefault( false );
508
509     myCopyFromBtn->hide();
510     myAddToBtn->hide();
511     
512     // layout widgets
513     QGridLayout* aLay = new QGridLayout( aTableFrame, 8, 2, 0, SPACING );
514
515     aLay->addMultiCellWidget( mySwitchTableGrp, 0, 6, 0, 0 );
516     aLay->addWidget( myAddBtn, 0, 1 );
517     aLay->addWidget( myInsertBtn, 1, 1 );
518     aLay->addWidget( myRemoveBtn, 2, 1 );
519     aLay->addWidget( myClearBtn, 3, 1 );
520     aLay->addWidget( myCopyFromBtn, 5, 1 );
521     aLay->addWidget( myAddToBtn, 6, 1 );
522     aLay->addMultiCellWidget( createAdditionalFrame( aTableFrame ), 7, 7, 0, 1  );
523     
524     aLay->setColStretch( 0, 1 );
525     aLay->setColStretch( 1, 0 );
526     
527     QSpacerItem* aVSpacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
528     aLay->addItem( aVSpacer, 4, 1 );
529     
530     // signals and slots
531     connect( myAddBtn,    SIGNAL( clicked() ), this, SLOT( onAddBtn() ) );
532     connect( myInsertBtn, SIGNAL( clicked() ), this, SLOT( onInsertBtn() ) );
533     connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveBtn() ) );
534     connect( myClearBtn,  SIGNAL( clicked() ), this, SLOT( onClearBtn() ) );
535   
536     connect( myCopyFromBtn, SIGNAL( clicked() ), this, SLOT( onCopyFromBtn() ) );
537     connect( myAddToBtn,    SIGNAL( clicked() ), this, SLOT( onAddToBtn() ) );
538     
539     connect( myEntityTypeGrp, SIGNAL( clicked( int ) ), this, SLOT( onEntityType( int ) ) );
540     
541     myLibDlg = 0;
542   }
543   
544   // Hide buttons of entity types if necessary
545   const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
546   QMap<int, QString>::const_iterator anIt;
547   for ( anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt )
548   {
549     QButton* aBtn = myEntityTypeGrp->find( anIt.key() );
550     theTypes.contains( anIt.key() ) ? aBtn->show() : aBtn->hide();
551   }
552
553   // select first button if there is no selected buttons or it is hidden
554   QButton* aBtn = myEntityTypeGrp->selected();
555   if (  aBtn == 0 || theTypes.find( myEntityTypeGrp->id( aBtn ) ) == theTypes.end() )
556     myEntityTypeGrp->setButton( theTypes.first() );
557
558   if ( theTypes.count() == 1 )
559     myEntityTypeGrp->hide();
560   else
561     myEntityTypeGrp->show();
562
563   myTableGrp->updateGeometry();
564   int aType = myEntityTypeGrp->id( myEntityTypeGrp->selected() );
565   onEntityType( aType );
566 }
567
568 //=======================================================================
569 // name    : SMESHGUI_FilterTable::GetTableGrp
570 // Purpose : Get group box containing table. May be used for adding new widgets in it
571 ////=======================================================================
572 QWidget* SMESHGUI_FilterTable::createAdditionalFrame( QWidget* theParent )
573 {
574   QFrame* aFrame = new QFrame( theParent );
575   
576   QFrame* aLine1 = new QFrame( aFrame );
577   QFrame* aLine2 = new QFrame( aFrame );
578   aLine1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
579   aLine2->setFrameStyle( QFrame::HLine | QFrame::Sunken );
580   aLine1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
581   aLine2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
582   
583   QLabel* aLabel = new QLabel( tr( "ADDITIONAL_PARAMETERS" ), aFrame );
584
585   myWgStack = new QWidgetStack( aFrame );
586
587   QGridLayout* aLay = new QGridLayout( aFrame, 2, 3, 0, SPACING );
588   aLay->addWidget( aLine1, 0, 0 );
589   aLay->addWidget( aLabel, 0, 1 );
590   aLay->addWidget( aLine2, 0, 2 );
591   aLay->addMultiCellWidget( myWgStack, 1, 1, 0, 2 );
592
593   return aFrame;
594 }
595
596 //=======================================================================
597 // name    : SMESHGUI_FilterTable::GetTableGrp
598 // Purpose : Get group box containing table. May be used for adding new widgets in it
599 ////=======================================================================
600 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
601 {
602   return myTableGrp;
603 }
604
605 //=======================================================================
606 // name    : SMESHGUI_FilterTable::onEntityType
607 // Purpose : SLOT. Called when entity type changed.
608 //           Display corresponding table 
609 //=======================================================================
610 void SMESHGUI_FilterTable::onEntityType( int theType )
611 {
612   if ( myEntityType == theType )
613     return;
614
615   myIsValid = true;
616   emit NeedValidation();
617   if ( !myIsValid )
618   {
619     myEntityTypeGrp->setButton( myEntityType );
620     return;
621   }
622
623   myEntityType = theType;
624   
625   if ( !myTables.contains( theType ) )
626     myTables[ theType ] = createTable( mySwitchTableGrp, theType );    
627   
628   TableMap::iterator anIter;
629   for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
630     myEntityType == anIter.key() ? anIter.data()->show() : anIter.data()->hide();
631
632   updateBtnState();
633   qApp->processEvents();
634   myTables[ myEntityType ]->updateGeometry();
635   adjustSize();
636
637   emit EntityTypeChanged( theType );
638
639 }
640
641 //=======================================================================
642 // name    : SMESHGUI_FilterTable::IsValid
643 // Purpose : Verify validity of entered data
644 //=======================================================================
645 bool SMESHGUI_FilterTable::IsValid( const bool theMess, const int theEntityType ) const
646 {
647   int aType = theEntityType == -1 ? GetType() : theEntityType;
648
649   Table* aTable = myTables[ aType ];
650   for ( int i = 0, n = aTable->numRows(); i < n; i++ )
651   {
652     int aCriterion = GetCriterionType( i, aType );
653
654     if ( aCriterion == FT_RangeOfIds ||
655          aCriterion == FT_BelongToGeom ||
656          aCriterion == FT_BelongToPlane ||
657          aCriterion == FT_BelongToCylinder )
658     {
659       if ( aTable->text( i, 2 ).isEmpty() )
660       {
661         if ( theMess )
662           QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
663             tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
664         return false;
665       }
666     }
667     else
668     {
669       bool aRes = false;
670       aTable->blockSignals( true );
671       double  aThreshold = ( int )aTable->text( i, 2 ).toDouble( &aRes );
672       aTable->blockSignals( false );
673
674       if ( !aRes && aTable->IsEditable( i, 2 ) )
675       {
676         if ( theMess )
677           QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
678             tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
679         return false;
680       }
681       else if ( aType == SMESH::EDGE &&
682                 GetCriterionType( i, aType ) == SMESH::FT_MultiConnection &&
683                 aThreshold == 1 )
684       {
685         if ( theMess )
686           QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
687             tr( "SMESH_INSUFFICIENT_DATA" ), tr( "MULTIEDGES_ERROR" ), QMessageBox::Ok );
688         return false;
689       }
690     }
691
692     QTableItem* anItem = aTable->item( i, 0 );
693     if ( myAddWidgets.contains( anItem ) && !myAddWidgets[ anItem ]->IsValid() )
694       return false;
695   }
696
697   return true;
698 }
699
700 //=======================================================================
701 // name    : SMESHGUI_FilterTable::SetValidity
702 // Purpose : Set validity of the table
703 //=======================================================================
704 void SMESHGUI_FilterTable::SetValidity( const bool isValid )
705 {
706   myIsValid = isValid;
707 }
708
709 //=======================================================================
710 // name    : SMESHGUI_FilterTable::GetType
711 // Purpose : Get current entity type
712 //=======================================================================
713 int SMESHGUI_FilterTable::GetType() const
714 {
715   return myEntityType;
716 }
717
718 //=======================================================================
719 // name    : SMESHGUI_FilterTable::SetType
720 // Purpose : Set current entity type
721 //=======================================================================
722 void SMESHGUI_FilterTable::SetType( const int type )
723 {
724   myEntityTypeGrp->setButton( type );
725   onEntityType( type );
726 }
727
728 //=======================================================================
729 // name    : SMESHGUI_FilterTable::RestorePreviousEntityType
730 // Purpose : Restore previous entity type
731 //=======================================================================
732 void SMESHGUI_FilterTable::RestorePreviousEntityType()
733 {
734   SetType( myEntityType );
735 }
736
737 //=======================================================================
738 // name    : SMESHGUI_FilterTable::GetCriterionType
739 // Purpose : Get type of criterion from specified row ( corresponding enums in h-file )
740 //=======================================================================
741 int SMESHGUI_FilterTable::GetCriterionType( const int theRow, const int theType ) const
742 {
743   int aType = theType == -1 ? GetType() : theType;
744   Table* aTable = myTables[ aType ];
745   ComboItem* anItem = (ComboItem*)aTable->item( theRow, 0 );
746   return anItem != 0 ? anItem->GetValue() : FT_Undefined;
747 }
748
749 //=======================================================================
750 // name    : SMESHGUI_FilterTable::GetCriterion
751 // Purpose : Get parameters of criterion from specified row
752 //=======================================================================
753 void SMESHGUI_FilterTable::GetCriterion( const int                 theRow,
754                                          SMESH::Filter::Criterion& theCriterion,
755                                          const int                 theEntityType ) const
756 {
757   int aType = theEntityType == -1 ? GetType() : theEntityType;
758   Table* aTable = myTables[ aType ];
759   
760   theCriterion.Type = ( (ComboItem*)aTable->item( theRow, 0 ) )->GetValue();
761   theCriterion.UnaryOp = ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->isChecked() ? FT_LogicalNOT : FT_Undefined;
762   theCriterion.BinaryOp = theRow != aTable->numRows() - 1 ?
763     ( (ComboItem*)aTable->item( theRow, 4 ) )->GetValue() : FT_Undefined;
764   theCriterion.TypeOfElement = (ElementType)aType;
765
766   int aCriterionType = GetCriterionType( theRow, aType );
767
768   if ( aCriterionType != FT_RangeOfIds &&
769        aCriterionType != FT_BelongToGeom &&
770        aCriterionType != FT_BelongToPlane &&
771        aCriterionType != FT_BelongToCylinder )
772   {
773     theCriterion.Compare = ( (ComboItem*)aTable->item( theRow, 1 ) )->GetValue();
774     theCriterion.Threshold = aTable->item( theRow, 2 )->text().toDouble();
775   }
776   else
777     theCriterion.ThresholdStr = aTable->text( theRow, 2 ).latin1();
778
779   QTableItem* anItem = aTable->item( theRow, 0 );
780   if ( myAddWidgets.contains( anItem ) )
781     theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble( AdditionalWidget::Tolerance );
782 }
783
784 //=======================================================================
785 // name    : SMESHGUI_FilterTable::SetCriterion
786 // Purpose : Set parameters of criterion of specified row
787 //=======================================================================
788 void SMESHGUI_FilterTable::SetCriterion( const int                       theRow,
789                                          const SMESH::Filter::Criterion& theCriterion,
790                                          const int                       theEntityType )
791 {
792   int aType = theEntityType == -1 ? GetType() : theEntityType;
793
794   Table* aTable = myTables[ aType ];
795
796   if ( theRow > aTable->numRows() - 1 )
797     return;
798
799   ( (ComboItem*)aTable->item( theRow, 0 ) )->SetValue( theCriterion.Type );
800   onCriterionChanged( theRow, 0, aType );
801   ( (ComboItem*)aTable->item( theRow, 1 ) )->SetValue( theCriterion.Compare );
802   ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->setChecked( theCriterion.UnaryOp == FT_LogicalNOT );
803
804   if ( theCriterion.BinaryOp != FT_Undefined )
805   {
806     if ( !aTable->IsEditable( theRow, 4 ) )
807       aTable->setItem( theRow, 4, getBinaryItem( aTable ) );
808     ( (ComboItem*)aTable->item( theRow, 4 ) )->SetValue( theCriterion.BinaryOp );
809   }
810   else
811     aTable->SetEditable( false, theRow, 4 );
812
813   if ( theCriterion.Type != FT_RangeOfIds &&
814        theCriterion.Type != FT_BelongToGeom &&
815        theCriterion.Type != FT_BelongToPlane &&
816        theCriterion.Type != FT_BelongToCylinder )
817     aTable->setText( theRow, 2, QString( "%1" ).arg( theCriterion.Threshold, 0, 'g', 15 ) );
818   else
819     aTable->setText( theRow, 2, QString( theCriterion.ThresholdStr ) );
820
821   if ( theCriterion.Compare == FT_EqualTo ||
822        theCriterion.Type    == FT_BelongToPlane ||
823        theCriterion.Type    == FT_BelongToCylinder )
824   {
825     QTableItem* anItem = aTable->item( theRow, 0 );
826     if ( !myAddWidgets.contains( anItem ) )
827     {
828       myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
829       myWgStack->addWidget( myAddWidgets[ anItem ] );
830     }
831     myAddWidgets[ anItem ]->SetDouble( AdditionalWidget::Tolerance, theCriterion.Tolerance );
832   }
833
834   emit CretarionChanged( theRow, aType );
835
836 }
837
838 //=======================================================================
839 // name    : SMESHGUI_FilterTable::Update
840 // Purpose : Update table
841 //=======================================================================
842 void SMESHGUI_FilterTable::Update()
843 {
844   Table* aTable = myTables[ GetType() ];
845   int aCurrRow = aTable->currentRow();
846   int numRows = aTable->numRows();
847   if ( ( aCurrRow < 0 || aCurrRow >= numRows ) && numRows > 0 )
848     aTable->setCurrentCell( 0, 0 );
849   updateAdditionalWidget();
850 }
851
852 //=======================================================================
853 // name    : SMESHGUI_FilterTable::AddCriterion
854 // Purpose : Add criterion with parameters
855 //=======================================================================
856 void SMESHGUI_FilterTable::AddCriterion( const SMESH::Filter::Criterion& theCriterion,
857                                          const int                       theEntityType )
858 {
859   int aType = theEntityType == -1 ? GetType() : theEntityType;
860   Table* aTable = myTables[ aType ];
861   addRow( aTable, aType );
862   SetCriterion( aTable->numRows() - 1, theCriterion );
863 }
864
865 //=======================================================================
866 // name    : SMESHGUI_FilterTable::NumRows
867 // Purpose : Get number of criterions of current type
868 //=======================================================================
869 int SMESHGUI_FilterTable::NumRows( const int theEntityType ) const
870 {
871   return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->numRows();
872 }
873
874 //=======================================================================
875 // name    : SMESHGUI_FilterTable::Clear
876 // Purpose : Clear current table
877 //=======================================================================
878 void SMESHGUI_FilterTable::Clear( const int theType )
879 {
880   int aType = theType == -1 ? GetType() : theType;
881   QTable* aTable = myTables[ aType ];
882
883   if ( aTable->numRows() == 0 )
884     return;
885
886   while ( aTable->numRows() > 0 )
887   {
888     removeAdditionalWidget( aTable, 0 );
889     aTable->removeRow( 0 );
890   }
891
892   updateBtnState();
893 }
894
895 //=======================================================================
896 // name    : SMESHGUI_FilterTable::onAddBtn
897 // Purpose : SLOT. Called then "Add" button pressed.
898 //           Adds new string to table
899 //=======================================================================
900 void SMESHGUI_FilterTable::onAddBtn()
901 {
902   int aType = GetType();
903   addRow( myTables[ aType ], aType );
904
905   Table* aTable = myTables[ aType ];
906   Update();
907 }
908
909 //=======================================================================
910 // name    : SMESHGUI_FilterTable::onInsertBtn
911 // Purpose : SLOT. Called then "Insert" button pressed.
912 //           Inserts new string before current one
913 //=======================================================================
914 void SMESHGUI_FilterTable::onInsertBtn()
915 {
916   addRow( myTables[ GetType() ], GetType(), false );
917 }
918
919 //=======================================================================
920 // name    : SMESHGUI_FilterTable::onRemoveBtn
921 // Purpose : SLOT. Called then "Remove" button pressed.
922 //           Removes current string from table
923 //=======================================================================
924 void SMESHGUI_FilterTable::onRemoveBtn()
925 {
926   Table* aTable = myTables[ GetType() ];
927
928   if ( aTable->numRows() == 0 )
929     return;
930
931   QMemArray<int> aRows;
932   for ( int i = 0, n = aTable->numRows(); i < n; i++ )
933   {
934     if ( aTable->isRowSelected( i ) )
935     {
936       aRows.resize( aRows.size() + 1 );
937       aRows[ aRows.size() - 1 ] = i;
938       removeAdditionalWidget( aTable, i );
939     }
940   }
941
942   aTable->removeRows( aRows );
943
944   // remove control of binary logical operation from last row
945   if ( aTable->numRows() > 0 )
946     aTable->SetEditable( false, aTable->numRows() - 1, 4 );
947
948   updateBtnState();
949 }
950
951 //=======================================================================
952 // name    : SMESHGUI_FilterTable::updateAdditionalWidget
953 // Purpose : Enable/Disable widget with additonal parameters
954 //=======================================================================
955 void SMESHGUI_FilterTable::updateAdditionalWidget()
956 {
957   Table* aTable = myTables[ GetType() ];
958   int aRow = aTable->currentRow();
959   if ( aRow < 0 || aRow >= aTable->numRows() )
960   {
961     myWgStack->setEnabled( false );
962     return;
963   }
964
965   ComboItem* anItem = ( (ComboItem*)aTable->item( aRow, 0 ) );
966   bool toEnable = ( (ComboItem*)aTable->item( aRow, 1 ) )->GetValue() == FT_EqualTo &&
967                   GetCriterionType( aRow ) != FT_BelongToGeom &&
968                   GetCriterionType( aRow ) != FT_RangeOfIds &&
969                   GetCriterionType( aRow ) != FT_FreeEdges;
970   if ( !myAddWidgets.contains( anItem ) )
971   {
972     myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
973     myWgStack->addWidget( myAddWidgets[ anItem ] );
974   }
975
976   myWgStack->raiseWidget( myWgStack->id( myAddWidgets[ anItem ] ) );
977   myWgStack->setEnabled( toEnable );
978 }
979
980 //=======================================================================
981 // name    : SMESHGUI_FilterTable::removeAdditionalWidget
982 // Purpose : Remove widgets containing additional parameters from widget
983 //           stack and internal map
984 //=======================================================================
985 void SMESHGUI_FilterTable::removeAdditionalWidget( QTable* theTable, const int theRow )
986 {
987   QTableItem* anItem = theTable->item( theRow, 0 );
988   if ( myAddWidgets.contains( anItem ) )
989   {
990     myWgStack->removeWidget( myAddWidgets[ anItem ] );
991     myAddWidgets[ anItem ]->reparent( 0, QPoint() );
992     delete myAddWidgets[ anItem ];
993     myAddWidgets.remove( anItem );
994   }
995 }
996
997 //=======================================================================
998 // name    : SMESHGUI_FilterTable::onClearBtn
999 // Purpose : SLOT. Called then "Clear" button pressed.
1000 //           Removes all strings from table
1001 //=======================================================================
1002 void SMESHGUI_FilterTable::onClearBtn()
1003 {
1004   QTable* aTable = myTables[ GetType() ];
1005
1006   if ( aTable->numRows() == 0 )
1007     return;
1008
1009   while ( aTable->numRows() > 0 )
1010   {
1011     removeAdditionalWidget( aTable, 0 );
1012     aTable->removeRow( 0 );
1013   }
1014
1015   updateBtnState();
1016 }
1017
1018 //=======================================================================
1019 // name    : SMESHGUI_FilterTable::onCurrentChanged()
1020 // Purpose : SLOT. Called when current cell changed
1021 //=======================================================================
1022 void SMESHGUI_FilterTable::onCurrentChanged( int theRow, int theCol )
1023 {
1024   updateAdditionalWidget();
1025   emit CurrentChanged( theRow, theCol );
1026 }
1027
1028 //=======================================================================
1029 // name    : SMESHGUI_FilterTable::onCriterionChanged()
1030 // Purpose : Provides reaction on change of criterion
1031 //=======================================================================
1032 void SMESHGUI_FilterTable::onCriterionChanged( const int row, const int col, const int entityType )
1033 {
1034   int aType = entityType == -1 ? GetType() : entityType;
1035   Table* aTable = myTables[ aType ];
1036   ComboItem* aCompareItem = (ComboItem*)aTable->item( row, 1 );
1037
1038   int aCriterionType = GetCriterionType( row );
1039
1040   if ( aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1041        aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges )
1042   {
1043     if ( aCompareItem->count() > 0 )
1044       aCompareItem->setStringList( QStringList() );
1045     aTable->SetEditable( false, row, 2 );
1046   }
1047   else if ( aCriterionType == SMESH::FT_RangeOfIds ||
1048             aCriterionType == SMESH::FT_BelongToGeom ||
1049             aCriterionType == SMESH::FT_BelongToPlane ||
1050             aCriterionType == SMESH::FT_BelongToCylinder )
1051   {
1052     QMap<int, QString> aMap;
1053     aMap[ FT_EqualTo ] = tr( "EQUAL_TO" );
1054     aCompareItem->setStringList( aMap );
1055     if ( !aTable->IsEditable( row, 2 ) )
1056       aTable->SetEditable( true, row, 2 );
1057   }
1058   else
1059   {
1060     if ( aCompareItem->count() != 3 )
1061     {
1062       aCompareItem->setStringList( QStringList() );
1063       aCompareItem->setStringList( getCompare() );
1064     }
1065
1066     QString aText = aTable->text( row, 2 );
1067     bool isOk = false;
1068     aText.toDouble( &isOk );
1069     aTable->setText( row, 2, isOk ? aText : QString("") );
1070     if ( !aTable->IsEditable( row, 2 ) )
1071       aTable->SetEditable( true, row, 2 );
1072   }
1073
1074   updateAdditionalWidget();
1075   
1076   emit CretarionChanged( row, entityType );
1077 }
1078
1079 //=======================================================================
1080 // name    : SMESHGUI_FilterTable::onCriterionChanged()
1081 // Purpose : SLOT. Called then contents of table changed
1082 //           Provides reaction on change of criterion
1083 //=======================================================================
1084 void SMESHGUI_FilterTable::onCriterionChanged( int row, int col )
1085 {
1086   onCriterionChanged( row, col, -1 );
1087 }
1088
1089 //=======================================================================
1090 // name    : SMESHGUI_FilterTable::getFirstSelectedRow
1091 // Purpose : Get first selected row
1092 //=======================================================================
1093 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1094 {
1095   QTable* aTable = myTables[ GetType() ];
1096   for ( int i = 0, n = aTable->numRows(); i < n; i++ )
1097     if ( aTable->isRowSelected( i ) )
1098       return i;
1099
1100   int aRow = aTable->currentRow();
1101   return aRow >= 0 && aRow < aTable->numRows() ? aRow : -1;
1102 }
1103
1104 //=======================================================================
1105 // name    : SMESHGUI_FilterTable::addRow
1106 // Purpose : Add row at the end of table
1107 //=======================================================================
1108 void SMESHGUI_FilterTable::addRow( Table* theTable, const int theType, const bool toTheEnd )
1109 {
1110   int aCurrRow = 0;
1111   int aSelectedRow = getFirstSelectedRow();
1112   int aCurrCol = theTable->currentColumn();
1113
1114   if ( toTheEnd || aSelectedRow == -1 )
1115   {
1116     theTable->insertRows( theTable->numRows() );
1117     aCurrRow = theTable->numRows() - 1;
1118   }
1119   else
1120   {
1121     theTable->insertRows( aSelectedRow );
1122     aCurrRow = aSelectedRow;
1123   }
1124
1125   // Criteria
1126   theTable->setItem( aCurrRow, 0, getCriterionItem( theTable, theType ) );
1127
1128   // Compare
1129   theTable->setItem( aCurrRow, 1, getCompareItem( theTable ) );
1130
1131   // Threshold
1132   //theTable->setItem( aCurrRow, 2, new QTableItem( theTable ) );  
1133
1134   //Logical operation NOT
1135   theTable->setItem( aCurrRow, 3, getUnaryItem( theTable ) );
1136   
1137   // Logical binary operation for previous value
1138   int anAddBinOpStr = -1;
1139   if ( aCurrRow == theTable->numRows() - 1 )
1140     anAddBinOpStr = aCurrRow - 1;
1141   else if ( aCurrRow >= 0  )
1142     anAddBinOpStr = aCurrRow;
1143   
1144   if ( theTable->item( aCurrRow, 4 ) == 0 ||
1145        theTable->item( aCurrRow, 4 )->rtti() != 1 )
1146   {
1147     
1148
1149     if ( anAddBinOpStr >= 0 &&
1150          ( theTable->item( anAddBinOpStr, 4 ) == 0 ||
1151            theTable->item( anAddBinOpStr, 4 )->rtti() != 1 ) )
1152       theTable->setItem( anAddBinOpStr, 4, getBinaryItem( theTable ) );
1153   }
1154   
1155   theTable->SetEditable( false, theTable->numRows() - 1, 4 );
1156
1157   if ( aCurrRow >=0 && aCurrRow < theTable->numRows() &&
1158        aCurrCol >=0 && aCurrCol < theTable->numRows() )
1159   theTable->setCurrentCell( aCurrRow, aCurrCol );
1160
1161   onCriterionChanged( aCurrRow, 0 );
1162
1163   updateBtnState();
1164 }
1165
1166 //=======================================================================
1167 // name    : SMESHGUI_FilterTable::getCriterionItem
1168 // Purpose : Get combo table item for criteria of specified type
1169 //=======================================================================
1170 QTableItem* SMESHGUI_FilterTable::getCriterionItem( QTable* theParent , const int theType )
1171 {
1172   return new ComboItem( theParent, getCriteria( theType ) );
1173 }
1174
1175 //=======================================================================
1176 // name    : SMESHGUI_FilterTable::getCompareItem
1177 // Purpose : Get combo table item for operation of comparision
1178 //=======================================================================
1179 QTableItem* SMESHGUI_FilterTable::getCompareItem( QTable* theParent )
1180 {
1181   return new ComboItem( theParent, getCompare() );
1182 }
1183
1184 //=======================================================================
1185 // name    : SMESHGUI_FilterTable::getBinaryItem
1186 // Purpose :
1187 //=======================================================================
1188 QTableItem* SMESHGUI_FilterTable::getBinaryItem( QTable* theParent )
1189 {
1190   static QMap<int, QString> aMap;
1191   if ( aMap.isEmpty() )
1192   {
1193     aMap[ SMESH::FT_LogicalAND ] = tr( "AND" );
1194     aMap[ SMESH::FT_LogicalOR  ] = tr( "OR" );
1195   }
1196
1197   return new ComboItem( theParent, aMap );
1198 }
1199
1200 //=======================================================================
1201 // name    : SMESHGUI_FilterTable::getUnaryItem
1202 // Purpose : Get check table item
1203 //=======================================================================
1204 QTableItem* SMESHGUI_FilterTable::getUnaryItem( QTable* theParent )
1205 {
1206   return new QCheckTableItem( theParent, tr( "NOT" ) );
1207 }
1208
1209 //=======================================================================
1210 // name    : SMESHGUI_FilterTable::getSupportedTypes
1211 // Purpose : Get all supported type
1212 //=======================================================================
1213 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1214 {
1215   static QMap<int, QString> aTypes;
1216   if ( aTypes.isEmpty() )
1217   {
1218     aTypes[ SMESH::NODE   ] = tr( "NODES" );
1219     aTypes[ SMESH::EDGE   ] = tr( "EDGES" );
1220     aTypes[ SMESH::FACE   ] = tr( "FACES" );
1221     aTypes[ SMESH::VOLUME ] = tr( "VOLUMES" );
1222   }
1223
1224   return aTypes;
1225 }
1226
1227 //=======================================================================
1228 // name    : SMESHGUI_FilterTable::getCriteria
1229 // Purpose : Get criteria for specified type
1230 //=======================================================================
1231 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria( const int theType ) const
1232 {
1233   if ( theType == SMESH::NODE )
1234   {
1235     static QMap<int, QString> aCriteria;
1236     if ( aCriteria.isEmpty() )
1237     {
1238       aCriteria[ SMESH::FT_RangeOfIds       ] = tr( "RANGE_OF_IDS" );
1239       aCriteria[ SMESH::FT_BelongToGeom     ] = tr( "BELONG_TO_GEOM" );
1240       aCriteria[ SMESH::FT_BelongToPlane    ] = tr( "BELONG_TO_PLANE" );
1241       aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1242     }
1243     return aCriteria;
1244   }
1245   else if ( theType == SMESH::EDGE )
1246   {
1247     static QMap<int, QString> aCriteria;
1248     if ( aCriteria.isEmpty() )
1249     {
1250       aCriteria[ SMESH::FT_FreeBorders      ] = tr( "FREE_BORDERS" );
1251       aCriteria[ SMESH::FT_MultiConnection  ] = tr( "MULTI_BORDERS" );
1252       aCriteria[ SMESH::FT_Length           ] = tr( "LENGTH" );
1253       aCriteria[ SMESH::FT_RangeOfIds       ] = tr( "RANGE_OF_IDS" );
1254       aCriteria[ SMESH::FT_BelongToGeom     ] = tr( "BELONG_TO_GEOM" );
1255       aCriteria[ SMESH::FT_BelongToPlane    ] = tr( "BELONG_TO_PLANE" );
1256       aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1257     }
1258     return aCriteria;
1259   }
1260   else if ( theType == SMESH::FACE )
1261   {
1262     static QMap<int, QString> aCriteria;
1263     if ( aCriteria.isEmpty() )
1264     {
1265       aCriteria[ SMESH::FT_AspectRatio      ] = tr( "ASPECT_RATIO" );
1266       aCriteria[ SMESH::FT_Warping          ] = tr( "WARPING" );
1267       aCriteria[ SMESH::FT_MinimumAngle     ] = tr( "MINIMUM_ANGLE" );
1268       aCriteria[ SMESH::FT_Taper            ] = tr( "TAPER" );
1269       aCriteria[ SMESH::FT_Skew             ] = tr( "SKEW" );
1270       aCriteria[ SMESH::FT_Area             ] = tr( "AREA" );
1271       aCriteria[ SMESH::FT_FreeEdges        ] = tr( "FREE_EDGES" );
1272       aCriteria[ SMESH::FT_RangeOfIds       ] = tr( "RANGE_OF_IDS" );
1273       aCriteria[ SMESH::FT_BelongToGeom     ] = tr( "BELONG_TO_GEOM" );
1274       aCriteria[ SMESH::FT_BelongToPlane    ] = tr( "BELONG_TO_PLANE" );
1275       aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1276     }
1277     return aCriteria;
1278   }
1279   else if ( theType == SMESH::VOLUME )
1280   {
1281     static QMap<int, QString> aCriteria;
1282     if ( aCriteria.isEmpty() )
1283     {
1284       aCriteria[ SMESH::FT_RangeOfIds   ] = tr( "RANGE_OF_IDS" );
1285       aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1286     }
1287     return aCriteria;
1288   }
1289   else
1290   {
1291     static QMap<int, QString> aCriteria;
1292     return aCriteria;
1293   }
1294 }
1295
1296
1297 //=======================================================================
1298 // name    : SMESHGUI_FilterTable::getCompare
1299 // Purpose : Get operation of comparison
1300 //=======================================================================
1301 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1302 {
1303   static QMap<int, QString> aMap;
1304
1305   if ( aMap.isEmpty() )
1306   {
1307     aMap[ SMESH::FT_LessThan ] = tr( "LESS_THAN" );
1308     aMap[ SMESH::FT_MoreThan ] = tr( "MORE_THAN" );
1309     aMap[ SMESH::FT_EqualTo  ] = tr( "EQUAL_TO"  );
1310   }
1311
1312   return aMap;
1313 }
1314
1315 //=======================================================================
1316 // name    : SMESHGUI_FilterTable::createTable
1317 // Purpose : Create table
1318 //=======================================================================
1319 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable( QWidget*  theParent,
1320                                                                 const int theType )
1321 {
1322   // create table
1323   Table* aTable= new Table( 0, 5, theParent );
1324
1325   QHeader* aHeaders = aTable->horizontalHeader();
1326
1327   QFontMetrics aMetrics( aHeaders->font() );
1328
1329   // append spaces to the header of criteria in order to
1330   // provide visibility of criterion inside comboboxes
1331   static int aMaxLenCr = 0;
1332
1333   if ( aMaxLenCr == 0 )
1334   {
1335     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1336     QMap<int, QString>::const_iterator anIter;
1337     for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
1338       aMaxLenCr = Max( maxLength( getCriteria( anIter.key() ), aMetrics ), aMaxLenCr );
1339   }
1340
1341   static int aLenCr = abs(  aMaxLenCr -
1342                             aMetrics.width( tr( "CRITERION" ) ) ) / aMetrics.width( ' ' ) + 5;
1343
1344   static int aLenCo = abs(  maxLength( getCompare(), aMetrics ) -
1345                             aMetrics.width( tr( "COMPARE" ) ) ) / aMetrics.width( ' ' ) + 5;
1346
1347   QString aCrStr;
1348   aCrStr.fill( ' ', aLenCr );
1349   QString aCoStr;
1350   aCoStr.fill( ' ', 10 );
1351
1352   aHeaders->setLabel( 0, tr( "CRITERION" ) + aCrStr );
1353   aHeaders->setLabel( 1, tr( "COMPARE" ) + aCoStr );
1354   aHeaders->setLabel( 2, tr( "THRESHOLD_VALUE" ) );
1355   aHeaders->setLabel( 3, tr( "UNARY" ) );
1356   aHeaders->setLabel( 4, tr( "BINARY" ) + "  " );
1357
1358   // set geometry of the table
1359   for ( int i = 0; i <= 4; i++ )
1360     aTable->adjustColumn( i );
1361
1362   aTable->updateGeometry();
1363   QSize aSize = aTable->sizeHint();
1364   int aWidth = aSize.width();
1365   aTable->setMinimumSize( QSize( aWidth, aWidth / 2 ) );
1366   aTable->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) );
1367
1368   connect( aTable, SIGNAL( valueChanged( int, int ) ),
1369            this,   SLOT( onCriterionChanged( int, int ) ) );
1370
1371   connect( aTable, SIGNAL( currentChanged( int, int ) ),
1372            this,   SLOT( onCurrentChanged( int, int ) ) );
1373
1374   return aTable;
1375 }
1376
1377 //=======================================================================
1378 // name    : SMESHGUI_FilterTable::updateBtnState
1379 // Purpose : Update button state
1380 //=======================================================================
1381 void SMESHGUI_FilterTable::updateBtnState()
1382 {
1383   myRemoveBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1384   myClearBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1385 }
1386
1387 //=======================================================================
1388 // name    : SMESHGUI_FilterTable::SetEditable
1389 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1390 //=======================================================================
1391 void SMESHGUI_FilterTable::SetEditable( const bool isEditable )
1392 {
1393   TableMap::iterator anIter;
1394   for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
1395   {
1396     anIter.data()->setReadOnly( !isEditable );
1397
1398     if ( isEditable )
1399     {
1400       myAddBtn->show();
1401       myInsertBtn->show();
1402       myRemoveBtn->show();
1403       myClearBtn->show();
1404     }
1405     else
1406     {
1407       myAddBtn->hide();
1408       myInsertBtn->hide();
1409       myRemoveBtn->hide();
1410       myClearBtn->hide();
1411     }
1412   }
1413
1414   QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1415   for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1416     anIter2.data()->SetEditable( isEditable );
1417 }
1418
1419 //=======================================================================
1420 // name    : SMESHGUI_FilterTable::SetEnabled
1421 // Purpose : Enable/Disable table. Switching type of elements already enabled
1422 //=======================================================================
1423 void SMESHGUI_FilterTable::SetEnabled( const bool isEnabled )
1424 {
1425   myAddBtn->setEnabled( isEnabled );
1426   myInsertBtn->setEnabled( isEnabled );
1427   myRemoveBtn->setEnabled( isEnabled );
1428   myClearBtn->setEnabled( isEnabled );
1429
1430   if ( isEnabled )
1431     updateBtnState();
1432   
1433   QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1434   for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1435     anIter2.data()->setEnabled( isEnabled );
1436 }
1437
1438 //=======================================================================
1439 // name    : SMESHGUI_FilterTable::IsEditable
1440 // Purpose : Verify whether table is editable
1441 //=======================================================================
1442 bool SMESHGUI_FilterTable::IsEditable() const
1443 {
1444   return !myTables[ GetType() ]->isReadOnly();
1445 }
1446
1447 //=======================================================================
1448 // name    : SMESHGUI_FilterTable::SetLibsEnabled
1449 // Purpose : Show/hide buttons for work with libraries
1450 //=======================================================================
1451 void SMESHGUI_FilterTable::SetLibsEnabled( const bool isEnabled )
1452 {
1453   if ( isEnabled )
1454   {
1455     myCopyFromBtn->show();
1456     myAddToBtn->show();
1457   }
1458   else
1459   {
1460     myCopyFromBtn->hide();
1461     myAddToBtn->hide();
1462   }
1463 }
1464
1465 //=======================================================================
1466 // name    : SMESHGUI_FilterTable::onCopyFromBtn
1467 // Purpose : SLOT. Called the "Copy from ..." button clicked
1468 //           Display filter library dialog
1469 //=======================================================================
1470 void SMESHGUI_FilterTable::onCopyFromBtn()
1471 {
1472   if ( myLibDlg == 0 )
1473     myLibDlg = new SMESHGUI_FilterLibraryDlg(
1474       this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1475   else
1476     myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1477
1478   if ( myLibDlg->exec() == QDialog::Accepted )
1479   {
1480     Copy( myLibDlg->GetTable() );
1481     Update();
1482   }
1483 }
1484
1485 //=======================================================================
1486 // name    : SMESHGUI_FilterTable::onAddToBtn
1487 // Purpose : SLOT. Called the "Add to ..." button clicked
1488 //           Display filter library dialog
1489 //=======================================================================
1490 void SMESHGUI_FilterTable::onAddToBtn()
1491 {
1492   if ( !IsValid( true ) )
1493     return;
1494   if ( myLibDlg == 0 )
1495     myLibDlg = new SMESHGUI_FilterLibraryDlg(
1496       this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1497   else
1498     myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1499
1500   myLibDlg->SetTable( this );
1501     
1502   myLibDlg->exec();
1503 }                                          
1504
1505 //=======================================================================
1506 // name    : SMESHGUI_FilterTable::Copy
1507 // Purpose : Initialise table with values of other table
1508 //=======================================================================
1509 void SMESHGUI_FilterTable::Copy( const SMESHGUI_FilterTable* theTable )
1510 {
1511   Clear();
1512
1513   for ( int i = 0, n = theTable->NumRows(); i < n; i++ )
1514   {
1515     SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1516     theTable->GetCriterion( i, aCriterion );
1517     AddCriterion( aCriterion );
1518   }
1519 }
1520
1521 //=======================================================================
1522 // name    : SMESHGUI_FilterTable::CurrentCell
1523 // Purpose : Returns current cell
1524 //=======================================================================
1525 bool SMESHGUI_FilterTable::CurrentCell( int& theRow, int& theCol ) const
1526 {
1527   theRow = myTables[ GetType() ]->currentRow();
1528   theCol = myTables[ GetType() ]->currentColumn();
1529   return theRow >= 0 && theCol >= 0;
1530 }
1531
1532 //=======================================================================
1533 // name    : SMESHGUI_FilterTable::SetText
1534 // Purpose : Set text and internal value in cell of threshold value 
1535 //=======================================================================
1536 void SMESHGUI_FilterTable::SetThreshold( const int      theRow,
1537                                          const QString& theText,
1538                                          const int      theEntityType )
1539 {
1540   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1541   aTable->setText( theRow, 2, theText );
1542 }
1543
1544 //=======================================================================
1545 // name    : SMESHGUI_FilterTable::SetText
1546 // Purpose : Get text and internal value from cell of threshold value
1547 //=======================================================================
1548 bool SMESHGUI_FilterTable::GetThreshold( const int      theRow,
1549                                          QString&       theText,
1550                                          const int      theEntityType )
1551 {
1552   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1553   QTableItem* anItem = aTable->item( theRow, 2 );
1554   if ( anItem != 0 )
1555   {
1556     theText = anItem->text();
1557     return true;    
1558   }
1559   else
1560    return false;
1561 }
1562
1563 /*                                                                                                                                                 
1564   Class       : SMESHGUI_FilterDlg
1565   Description : Dialog to specify filters for VTK viewer
1566 */
1567
1568
1569 //=======================================================================
1570 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1571 // Purpose : Constructor
1572 //=======================================================================
1573 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget*               theParent,
1574                                         const QValueList<int>& theTypes,
1575                                         const char*            theName )
1576 : QDialog( theParent, theName, false,
1577            WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1578 {
1579   construct( theTypes );
1580 }
1581
1582 //=======================================================================
1583 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1584 // Purpose : Constructor
1585 //=======================================================================
1586 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget*    theParent,
1587                                         const int   theType,
1588                                         const char* theName )
1589 : QDialog( theParent, theName, false,
1590            WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1591 {
1592   QValueList<int> aTypes;
1593   aTypes.append( theType );
1594   construct( aTypes );
1595 }
1596
1597 //=======================================================================
1598 // name    : SMESHGUI_FilterDlg::construct
1599 // Purpose : Construct dialog ( called by constructor )
1600 //=======================================================================
1601 void SMESHGUI_FilterDlg::construct( const QValueList<int>& theTypes )
1602 {
1603   myTypes = theTypes;
1604
1605   setCaption( tr( "CAPTION" ) );
1606
1607   QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
1608
1609   myMainFrame        = createMainFrame  ( this );
1610   QFrame* aBtnFrame  = createButtonFrame( this );
1611
1612   aDlgLay->addWidget( myMainFrame );
1613   aDlgLay->addWidget( aBtnFrame );
1614
1615   aDlgLay->setStretchFactor( myMainFrame, 1 );
1616
1617   Init( myTypes );
1618 }
1619
1620 //=======================================================================
1621 // name    : SMESHGUI_FilterDlg::createMainFrame
1622 // Purpose : Create frame containing dialog's input fields
1623 //=======================================================================
1624 QFrame* SMESHGUI_FilterDlg::createMainFrame( QWidget* theParent )
1625 {
1626   QGroupBox* aMainFrame = new QGroupBox( 1, Qt::Horizontal, theParent );
1627   aMainFrame->setFrameStyle( QFrame::NoFrame );
1628   aMainFrame->setInsideMargin( 0 );
1629
1630   // filter frame
1631
1632   myTable = new SMESHGUI_FilterTable( aMainFrame, myTypes );
1633   myTable->SetLibsEnabled( true );
1634
1635   QFrame* aLine = new QFrame( myTable->GetTableGrp() );
1636   aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
1637
1638   mySetInViewer = new QCheckBox( tr( "SET_IN_VIEWER" ), myTable->GetTableGrp() );
1639   mySetInViewer->setChecked( true );
1640
1641   // other controls
1642   mySourceGrp = createSourceGroup( aMainFrame );
1643
1644   connect( myTable, SIGNAL( CretarionChanged( const int, const int ) ),
1645                     SLOT( onCriterionChanged( const int, const int ) ) );
1646
1647   connect( myTable, SIGNAL( CurrentChanged( int, int ) ),
1648                     SLOT( onCurrentChanged( int, int ) ) );                    
1649
1650   return aMainFrame;
1651 }
1652
1653 //=======================================================================
1654 // name    : SMESHGUI_FilterDlg::createSourceFrame
1655 // Purpose : Create frame containing source radio button
1656 //=======================================================================
1657 QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup( QWidget* theParent )
1658 {
1659   QButtonGroup* aGrp = new QButtonGroup( 1, Qt::Vertical, tr( "SOURCE" ), theParent );
1660
1661   QRadioButton* aMeshBtn = new QRadioButton( tr( "MESH" ), aGrp );
1662   QRadioButton* aSelBtn  = new QRadioButton( tr( "SELECTION" ), aGrp );
1663   QRadioButton* aGrpBtn  = new QRadioButton( tr( "CURRENT_GROUP" ), aGrp );
1664
1665   aGrp->insert( aMeshBtn, Mesh );
1666   aGrp->insert( aSelBtn, Selection );
1667   aGrp->insert( aGrpBtn, Dialog );
1668
1669   aGrp->setButton( Selection );
1670
1671   return aGrp;
1672 }
1673
1674 //=======================================================================
1675 // name    : SMESHGUI_FilterDlg::updateMainButtons
1676 // Purpose : Update visibility of main buttons ( OK, Cancel, Close ... )
1677 //=======================================================================
1678 void SMESHGUI_FilterDlg::updateMainButtons()
1679 {
1680   if ( myTypes.count() == 1 )
1681   {
1682     myButtons[ BTN_Cancel ]->show();
1683     myButtons[ BTN_Apply  ]->hide();
1684     myButtons[ BTN_Close  ]->hide();
1685   }
1686   else
1687   {
1688     myButtons[ BTN_Cancel ]->hide();
1689     myButtons[ BTN_Apply  ]->show();
1690     myButtons[ BTN_Close  ]->show();
1691   }
1692
1693 //  updateGeometry();
1694 }
1695
1696 //=======================================================================
1697 // name    : SMESHGUI_FilterDlg::createButtonFrame
1698 // Purpose : Create frame containing buttons
1699 //=======================================================================
1700 QFrame* SMESHGUI_FilterDlg::createButtonFrame( QWidget* theParent )
1701 {
1702   QGroupBox* aGrp = new QGroupBox( 1, Qt::Vertical, theParent );
1703
1704   myButtons[ BTN_OK    ] = new QPushButton( tr( "SMESH_BUT_OK"    ), aGrp );
1705   myButtons[ BTN_Apply ] = new QPushButton( tr( "SMESH_BUT_APPLY" ), aGrp );
1706
1707   QLabel* aLbl = new QLabel( aGrp );
1708   aLbl->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1709
1710   myButtons[ BTN_Cancel ] = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aGrp );
1711   myButtons[ BTN_Close  ] = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aGrp );
1712
1713   connect( myButtons[ BTN_OK     ], SIGNAL( clicked() ), SLOT( onOk() ) );
1714   connect( myButtons[ BTN_Cancel ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1715   connect( myButtons[ BTN_Close  ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1716   connect( myButtons[ BTN_Apply  ], SIGNAL( clicked() ), SLOT( onApply() ) );
1717
1718   updateMainButtons();
1719
1720   return aGrp;
1721 }
1722
1723 //=======================================================================
1724 // name    : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
1725 // Purpose : Destructor
1726 //=======================================================================
1727 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
1728 {
1729 }
1730
1731 //=======================================================================
1732 // name    : SMESHGUI_FilterDlg::Init
1733 // Purpose : Init dialog fields, connect signals and slots, show dialog
1734 //=======================================================================
1735 void SMESHGUI_FilterDlg::Init( const int type )
1736 {
1737   QValueList<int> aTypes;
1738   aTypes.append( type );
1739   Init( aTypes );
1740 }
1741
1742 //=======================================================================
1743 // name    : SMESHGUI_FilterDlg::Init
1744 // Purpose : Init dialog fields, connect signals and slots, show dialog
1745 //=======================================================================
1746 void SMESHGUI_FilterDlg::Init( const QValueList<int>& theTypes )
1747 {
1748   mySourceWg  = 0;
1749   mySelection = 0;
1750   myTypes     = theTypes;
1751   myMesh      = SMESH::SMESH_Mesh::_nil();
1752   myIObjects.Clear();
1753   myIsSelectionChanged = false;
1754
1755   myTable->Init( theTypes );
1756
1757   // set caption
1758   if ( theTypes.count() == 1 )
1759   {
1760     int aType = theTypes.first();
1761     if      ( aType == SMESH::NODE   ) setCaption( tr( "NODES_TLT" ) );
1762     else if ( aType == SMESH::EDGE   ) setCaption( tr( "EDGES_TLT" ) );
1763     else if ( aType == SMESH::FACE   ) setCaption( tr( "FACES_TLT" ) );
1764     else if ( aType == SMESH::VOLUME ) setCaption( tr( "VOLUMES_TLT" ) );
1765   }
1766   else
1767     setCaption( tr( "TLT" ) );
1768
1769   qApp->processEvents();
1770   updateGeometry();
1771   adjustSize();
1772   setEnabled( true );
1773
1774   mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
1775   mySMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
1776
1777   connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
1778   connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
1779
1780   int x, y ;
1781   mySMESHGUI->DefineDlgPosition( this, x, y );
1782   this->move( x, y );
1783
1784   updateMainButtons();
1785   updateSelection();
1786
1787   // Initialise filter table with values of previous filter
1788   QValueList<int>::const_iterator anIter;
1789   for ( anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter )
1790   {
1791     myTable->Clear( *anIter );
1792     if ( !myFilter[ *anIter ]->_is_nil() )
1793     {
1794       SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1795       if ( myFilter[ *anIter ]->GetCriteria( aCriteria ) )
1796       {
1797         for ( int i = 0, n = aCriteria->length(); i < n; i++ )
1798           myTable->AddCriterion( aCriteria[ i ], *anIter );
1799       }
1800     }
1801   }
1802
1803   if ( myInsertState.contains( theTypes.first() ) )
1804     mySetInViewer->setChecked( myInsertState[ theTypes.first() ] );
1805   else
1806     mySetInViewer->setChecked( true );
1807   if ( myApplyToState.contains( theTypes.first() ) )
1808     mySourceGrp->setButton( myApplyToState[ theTypes.first() ] );
1809   else
1810     mySourceGrp->setButton( Selection ); 
1811 }
1812
1813 //=======================================================================
1814 // name    : SMESHGUI_FilterDlg::onOk
1815 // Purpose : SLOT called when "Ok" button pressed.
1816 //           Assign filters VTK viewer and close dialog
1817 //=======================================================================
1818 void SMESHGUI_FilterDlg::onOk()
1819 {
1820   if ( onApply() )
1821   {
1822     mySelection->ClearFilters();
1823     disconnect( mySMESHGUI, 0, this, 0 );
1824     disconnect( mySelection, 0, this, 0 );
1825     mySMESHGUI->ResetState() ;
1826     accept();
1827     emit Accepted();
1828   }
1829 }
1830
1831 //=======================================================================
1832 // name    : SMESHGUI_FilterDlg::onClose
1833 // Purpose : SLOT called when "Close" button pressed. Close dialog
1834 //=======================================================================
1835 void SMESHGUI_FilterDlg::onClose()
1836 {
1837   // Restore previously selected object
1838   if ( mySelection )
1839   {
1840     mySelection->ClearFilters();
1841     mySelection->Clear();
1842     SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
1843     for ( ; anIter.More(); anIter.Next() )
1844     {
1845       mySelection->AddIObject( anIter.Key() );
1846
1847       TColStd_MapOfInteger aResMap;
1848       const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
1849       for ( int i = 1, n = anIndMap.Extent(); i <= n; i++ )
1850         aResMap.Add( anIndMap( i ) );
1851       
1852       mySelection->AddOrRemoveIndex( anIter.Key(), aResMap, false );
1853     }
1854   }
1855
1856   disconnect( mySMESHGUI, 0, this, 0 );
1857   disconnect( mySelection, 0, this, 0 );
1858   mySMESHGUI->ResetState() ;
1859   reject() ;
1860   return ;
1861 }
1862
1863 //=======================================================================
1864 // name    : SMESHGUI_FilterDlg::onDeactivate
1865 // Purpose : SLOT called when dialog must be deativated
1866 //=======================================================================
1867 void SMESHGUI_FilterDlg::onDeactivate()
1868 {
1869   setEnabled( false );
1870 }
1871
1872 //=======================================================================
1873 // name    : SMESHGUI_FilterDlg::enterEvent
1874 // Purpose : Event filter
1875 //=======================================================================
1876 void SMESHGUI_FilterDlg::enterEvent( QEvent* )
1877 {
1878 //  mySMESHGUI->EmitSignalDeactivateDialog();
1879   setEnabled( true );
1880 }
1881
1882
1883 //=================================================================================
1884 // function : closeEvent()
1885 // purpose  :
1886 //=================================================================================
1887 void SMESHGUI_FilterDlg::closeEvent( QCloseEvent* e )
1888 {
1889   onClose() ;
1890 }
1891
1892 //=======================================================================
1893 // name    : SMESHGUI_FilterDlg::getIdsFromWg
1894 // Purpose : Retrieve list of ids from given widget
1895 //=======================================================================
1896 void SMESHGUI_FilterDlg::getIdsFromWg( const QWidget* theWg, QValueList<int>& theRes ) const
1897 {
1898   theRes.clear();
1899   if ( theWg == 0 )
1900     return;
1901
1902   if ( theWg->inherits( "QListBox" ) )
1903   {
1904     QListBox* aListBox = ( QListBox* )theWg;
1905     bool b;
1906     for ( int i = 0, n = aListBox->count(); i < n; i++ )
1907     {
1908       int anId = aListBox->text( i ).toInt( &b );
1909       if ( b )
1910         theRes.append( anId );
1911     }
1912   }
1913   else if ( theWg->inherits( "QLineEdit" ) )
1914   {
1915     QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1916     QString aStr = aLineEdit->text();
1917     QRegExp aRegExp( "(\\d+)" );
1918     bool b;
1919     int aPos = 0;
1920     while ( aPos >= 0 )
1921     {
1922       aPos = aRegExp.search( aStr, aPos );
1923       if ( aPos > -1 )
1924       {
1925         int anId = aRegExp.cap( 1 ).toInt( &b );
1926         if ( b )
1927           theRes.append( anId );
1928         aPos += aRegExp.matchedLength();
1929       }
1930     }
1931   }
1932 }
1933
1934 //=======================================================================
1935 // name    : SMESHGUI_FilterDlg::getSelMode
1936 // Purpose : Get selection mode of specified type
1937 //=======================================================================
1938 Selection_Mode SMESHGUI_FilterDlg::getSelMode( const int theType ) const
1939 {
1940   switch ( theType )
1941   {
1942     case SMESH::NODE   : return NodeSelection;
1943     case SMESH::EDGE   : return EdgeSelection;
1944     case SMESH::FACE   : return FaceSelection;
1945     case SMESH::VOLUME : return VolumeSelection;
1946     default            : return ActorSelection;
1947   }
1948
1949 }
1950
1951 //=======================================================================
1952 // name    : SMESHGUI_FilterDlg::setIdsToWg
1953 // Purpose : Insert identifiers in specified widgets
1954 //=======================================================================
1955 void SMESHGUI_FilterDlg::setIdsToWg( QWidget* theWg, const QValueList<int>& theIds )
1956 {
1957   if ( theWg == 0 )
1958     return;
1959
1960   if ( theWg->inherits( "QListBox" ) )
1961   {
1962     QListBox* aListBox = ( QListBox* )theWg;
1963     aListBox->clear();
1964
1965     QStringList aStrList;
1966     QValueList<int>::const_iterator anIter;
1967     for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
1968       aStrList.append( QString( "%1" ).arg( *anIter ) );
1969
1970     aListBox->insertStringList( aStrList );
1971   }
1972   else if ( theWg->inherits( "QLineEdit" ) )
1973   {
1974     QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1975     QString aStr;
1976     QValueList<int>::const_iterator anIter;
1977
1978     for ( anIter = theIds.begin(); anIter != theIds.end(); ++ anIter )
1979       aStr += QString( "%1 " ).arg( *anIter );
1980
1981     if ( !aStr.isEmpty() )
1982       aStr.remove( aStr.length() - 1, 1 );
1983
1984     aLineEdit->setText( aStr );
1985   }
1986 }
1987
1988 //=======================================================================
1989 // name    : SMESHGUI_FilterDlg::isValid
1990 // Purpose : Verify validity of input data
1991 //=======================================================================
1992 bool SMESHGUI_FilterDlg::isValid() const
1993 {
1994   if ( !myTable->IsValid() )
1995     return false;
1996     
1997   for ( int i = 0, n = myTable->NumRows(); i < n; i++ )
1998   {
1999     int aType = myTable->GetCriterionType( i );
2000     if ( aType == FT_BelongToGeom ||
2001          aType == FT_BelongToPlane ||
2002          aType == FT_BelongToCylinder  )
2003     {
2004       QString aName;
2005       myTable->GetThreshold( i, aName );
2006       
2007       SALOMEDS::Study::ListOfSObject_var aList = SMESHGUI::GetSMESHGUI()->GetActiveStudy()->
2008         getStudyDocument()->FindObjectByName( aName.latin1(), "GEOM" );
2009       if ( aList->length() == 0 )
2010       {
2011         QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2012           tr( "SMESH_INSUFFICIENT_DATA" ), tr( "BAD_SHAPE_NAME" ).arg( aName ), QMessageBox::Ok );
2013         return false;
2014       }
2015
2016       if ( aType == FT_BelongToCylinder || aType == FT_BelongToPlane )
2017       {
2018         GEOM::GEOM_Object_var aGeomObj =
2019           GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
2020         if ( !aGeomObj->_is_nil() )
2021         {
2022           TopoDS_Shape aFace;
2023           if ( !GEOMBase::GetShape( aGeomObj, aFace ) ||
2024                aFace.IsNull() ||
2025                aFace.ShapeType() != TopAbs_FACE )
2026           {
2027             QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2028               tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2029             return false;
2030           }
2031
2032           Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aFace ) );
2033           if ( aSurf.IsNull() )
2034           {
2035             QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2036               tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2037             return false;
2038           }
2039
2040           if ( aType == FT_BelongToPlane && !aSurf->IsKind( STANDARD_TYPE( Geom_Plane ) ) )
2041           {
2042             QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2043               tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_PLANE" ).arg( aName ), QMessageBox::Ok );
2044             return false;
2045           }
2046
2047           if ( aType == FT_BelongToCylinder && !aSurf->IsKind( STANDARD_TYPE( Geom_CylindricalSurface ) ) )
2048           {
2049             QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2050               tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_CYLINDER" ).arg( aName ), QMessageBox::Ok );
2051             return false;
2052           }
2053         }
2054       }
2055     }
2056   }
2057
2058   return true;
2059 }
2060
2061 //=======================================================================
2062 // name    : SMESHGUI_FilterDlg::SetSourceWg
2063 // Purpose : Set widget of parent dialog containing idsto be filtered if
2064 //           user select corresponding source radio button
2065 //=======================================================================
2066 void SMESHGUI_FilterDlg::SetSourceWg( QWidget* theWg )
2067 {
2068   mySourceWg = theWg;
2069 }
2070
2071 //=======================================================================
2072 // name    : SMESHGUI_FilterDlg::SetGroupIds
2073 // Purpose : Set mesh
2074 //=======================================================================
2075 void SMESHGUI_FilterDlg::SetMesh( SMESH::SMESH_Mesh_ptr theMesh )
2076 {
2077   myMesh = theMesh;
2078 }
2079
2080 //=======================================================================
2081 // name    : SMESHGUI_FilterDlg::SetSelection
2082 // Purpose : Get filtered ids
2083 //=======================================================================
2084 void SMESHGUI_FilterDlg::SetSelection( SALOME_Selection* theSel )
2085 {
2086   if ( mySelection )
2087     disconnect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
2088     
2089   mySelection = theSel;
2090
2091   if ( mySelection )
2092   {
2093     myIObjects.Clear();
2094     const SALOME_ListIO& anObjs = mySelection->StoredIObjects();
2095     SALOME_ListIteratorOfListIO anIter( anObjs );
2096     for ( ;anIter.More(); anIter.Next() )
2097     {
2098       TColStd_IndexedMapOfInteger aMap;
2099       mySelection->GetIndex( anIter.Value(), aMap );
2100       myIObjects.Bind( anIter.Value(), aMap );
2101     }
2102     
2103     connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
2104
2105     updateSelection();
2106   }
2107   else
2108     myIObjects.Clear();
2109 }
2110
2111 //=======================================================================
2112 // name    : SMESHGUI_FilterDlg::onApply
2113 // Purpose : SLOT called when "Apply" button pressed.
2114 //           Assign filters to VTK viewer
2115 //=======================================================================
2116 bool SMESHGUI_FilterDlg::onApply()
2117 {
2118   if ( !isValid() )
2119     return false;
2120
2121   try
2122   {
2123     int aCurrType = myTable->GetType();
2124
2125     if ( !createFilter( aCurrType ) )
2126       return false;
2127
2128     insertFilterInViewer();
2129
2130     if ( !myFilter[ aCurrType ]->GetPredicate()->_is_nil() )
2131     {
2132       QValueList<int> aResultIds;
2133       filterSource( aCurrType, aResultIds );
2134       selectInViewer( aCurrType, aResultIds );
2135     }
2136
2137     myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2138     myApplyToState[ aCurrType ] = mySourceGrp->id( mySourceGrp->selected() );
2139     
2140   }
2141   catch( const SALOME::SALOME_Exception& S_ex )
2142   {
2143     QtCatchCorbaException( S_ex );
2144   }
2145   catch( ... )
2146   {
2147   }
2148
2149   return true;
2150 }
2151
2152 //=======================================================================
2153 // name    : SMESHGUI_FilterDlg::createFilter
2154 // Purpose : Create predicate for given type
2155 //=======================================================================
2156 bool SMESHGUI_FilterDlg::createFilter( const int theType )
2157 {
2158   SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2159   if ( aFilterMgr->_is_nil() )
2160     return false;
2161
2162   int n = myTable->NumRows();
2163
2164   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2165   aCriteria->length( n );
2166
2167   long aPrecision = -1;
2168   if ( QAD_CONFIG->hasSetting( "SMESH:ControlsPrecision" ) )
2169   {
2170     QString aStr = QAD_CONFIG->getSetting( "SMESH:ControlsPrecision" );
2171     bool isOk = false;
2172     int aVal = aStr.toInt( &isOk );
2173     if ( isOk )
2174       aPrecision = aVal;
2175   }
2176   
2177   for ( CORBA::ULong i = 0; i < n; i++ )
2178   {
2179     SMESH::Filter::Criterion aCriterion = createCriterion();
2180     myTable->GetCriterion( i, aCriterion );
2181     aCriterion.Precision = aPrecision;
2182     aCriteria[ i ] = aCriterion;
2183   }
2184
2185   myFilter[ theType ] = aFilterMgr->CreateFilter();
2186   myFilter[ theType ]->SetCriteria( aCriteria.inout() );
2187
2188   return true;
2189 }
2190
2191 //=======================================================================
2192 // name    : SMESHGUI_FilterDlg::insertFilterInViewer
2193 // Purpose : Insert filter in viewer
2194 //=======================================================================
2195 void SMESHGUI_FilterDlg::insertFilterInViewer()
2196 {
2197   if ( VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle() )
2198   {
2199     SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2200
2201     if ( myFilter[ myTable->GetType() ]->_is_nil() ||
2202          myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2203          !mySetInViewer->isChecked() )
2204       SMESH::RemoveFilter( getFilterId( anEntType ), aStyle );
2205     else
2206     {
2207       Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2208       aFilter->SetPredicate( myFilter[ myTable->GetType() ]->GetPredicate() );
2209       SMESH::SetFilter( aFilter, aStyle );
2210     }
2211   }
2212 }
2213
2214 //=======================================================================
2215 // name    : SMESHGUI_FilterDlg::filterSource
2216 // Purpose : Filter source ids
2217 //=======================================================================
2218 void SMESHGUI_FilterDlg::filterSource( const int theType,
2219                                        QValueList<int>& theResIds )
2220 {
2221   theResIds.clear();
2222   if ( myFilter[ theType ]->_is_nil() )
2223     return;
2224
2225   int aSourceId = mySourceGrp->id( mySourceGrp->selected() );
2226
2227   if ( aSourceId == Mesh )
2228   {
2229     if ( myMesh->_is_nil() )
2230       return;
2231     SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId( myMesh );
2232     for ( int i = 0, n = anIds->length(); i < n; i++ )
2233       theResIds.append( anIds[ i ] );
2234   }
2235   else if ( aSourceId == Selection )
2236   {
2237     filterSelectionSource( theType, theResIds );
2238   }
2239   else if ( aSourceId == Dialog )
2240   {
2241     // retrieve ids from dialog
2242     QValueList<int> aDialogIds;
2243     getIdsFromWg( mySourceWg, aDialogIds );
2244
2245     if ( myMesh->_is_nil() )
2246     {
2247       theResIds = aDialogIds;
2248       return;
2249     }
2250
2251     // filter ids
2252     SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2253     aPred->SetMesh( myMesh );
2254     QValueList<int>::const_iterator anIter;
2255     for ( anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter )
2256       if ( aPred->IsSatisfy( *anIter ) )
2257         theResIds.append( *anIter );
2258
2259     // set ids to the dialog
2260     setIdsToWg( mySourceWg, theResIds );
2261   }
2262 }
2263
2264 //=======================================================================
2265 // name    : SMESHGUI_FilterDlg::filterSelectionSource
2266 // Purpose : Filter source selection
2267 //=======================================================================
2268 void SMESHGUI_FilterDlg::filterSelectionSource( const int theType,
2269                                                 QValueList<int>& theResIds )
2270 {
2271   theResIds.clear();
2272   if ( myMesh->_is_nil() || mySelection == 0 )
2273     return;
2274
2275   // Create map of entities to be filtered
2276   TColStd_MapOfInteger aToBeFiltered;
2277   SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
2278
2279   for ( ; anIter.More(); anIter.Next() )
2280   {
2281     // process sub mesh
2282     SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIter.Key() );
2283     if ( !aSubMesh->_is_nil() )
2284     {
2285       if ( aSubMesh->GetFather()->GetId() == myMesh->GetId() )
2286       {
2287         SMESH::long_array_var anIds =
2288           theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2289         for ( int i = 0, n = anIds->length(); i < n; i++ )
2290           aToBeFiltered.Add( anIds[ i ] );
2291       }
2292     }
2293
2294     // process group
2295     SMESH::SMESH_Group_var aGroup = SMESH::IObjectToInterface<SMESH::SMESH_Group>( anIter.Key() );
2296     if ( !aGroup->_is_nil() )
2297     {
2298       if ( aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId() )
2299       {
2300         SMESH::long_array_var anIds = aGroup->GetListOfID();
2301         for ( int i = 0, n = anIds->length(); i < n; i++ )
2302           aToBeFiltered.Add( anIds[ i ] );
2303       }
2304     }
2305
2306     // process mesh
2307     SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIter.Key() );
2308     if ( !aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId() )
2309     {
2310       const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2311
2312       if ( aSelMap.Extent() > 0 )
2313       {
2314         if(SMESH_Actor *anActor = SMESH::FindActorByEntry( anIter.Key()->getEntry() ) )
2315         {
2316           for ( int i = 1; i <= aSelMap.Extent(); i++ )
2317             aToBeFiltered.Add( aSelMap(i) );
2318         }
2319       }
2320     }
2321   }
2322
2323   // Filter entities
2324   SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2325   aPred->SetMesh( myMesh );
2326   TColStd_MapIteratorOfMapOfInteger aResIter( aToBeFiltered );
2327   for ( ; aResIter.More(); aResIter.Next() )
2328     if ( aPred->IsSatisfy( aResIter.Key() ) )
2329       theResIds.append( aResIter.Key() );
2330 }
2331
2332 //=======================================================================
2333 // name    : SMESHGUI_FilterDlg::selectInViewer
2334 // Purpose : Select given entities in viewer
2335 //=======================================================================
2336 void SMESHGUI_FilterDlg::selectInViewer( const int theType, const QValueList<int>& theIds )
2337 {
2338   if ( mySelection == 0 || myMesh->_is_nil() )
2339     return;
2340
2341   mySelection->ClearFilters();
2342
2343   // Set new selection mode if necessary
2344   Selection_Mode aSelMode = getSelMode( theType );
2345   if ( aSelMode != mySelection->SelectionMode() )
2346   {
2347     mySelection->ClearIObjects();
2348     mySelection->ClearFilters();
2349     if ( aSelMode == NodeSelection )
2350       SMESH::SetPointRepresentation(true);
2351     QAD_Application::getDesktop()->SetSelectionMode( aSelMode );
2352   }
2353
2354   // Clear selection
2355   SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2356   if ( !anActor || !anActor->hasIO() )
2357     return;
2358
2359   Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2360   mySelection->ClearIObjects();
2361   mySelection->AddIObject( anIO, false );
2362
2363   // Remove filter corresponding to the current type from viewer
2364   int aType = myTable->GetType();
2365   int aFilterId = SMESHGUI_UnknownFilter;
2366   if      ( aType == SMESH::EDGE   ) aFilterId = SMESHGUI_EdgeFilter;
2367   else if ( aType == SMESH::FACE   ) aFilterId = SMESHGUI_FaceFilter;
2368   else if ( aType == SMESH::VOLUME ) aFilterId = SMESHGUI_VolumeFilter;
2369   Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter( aFilterId );
2370   SMESH::RemoveFilter( aFilterId );
2371
2372   // get vtk ids
2373   TColStd_MapOfInteger aMap;
2374   QValueList<int>::const_iterator anIter;
2375   for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
2376   {
2377     aMap.Add( *anIter );
2378   }
2379
2380   // Set new selection
2381   mySelection->AddOrRemoveIndex( anIO, aMap, false, true );
2382
2383   // insert previously stored filter in viewer if necessary
2384   if ( !aFilter.IsNull() )
2385     SMESH::SetFilter( aFilter );
2386 }
2387
2388 //=======================================================================
2389 // name    : SMESHGUI_FilterDlg::createCriterion
2390 // Purpose : Create criterion structure with default values
2391 //=======================================================================
2392 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2393 {
2394    SMESH::Filter::Criterion aCriterion;
2395
2396   aCriterion.Type          = FT_Undefined;
2397   aCriterion.Compare       = FT_Undefined;
2398   aCriterion.Threshold     = 0;
2399   aCriterion.UnaryOp       = FT_Undefined;
2400   aCriterion.BinaryOp      = FT_Undefined;
2401   aCriterion.ThresholdStr  = "";
2402   aCriterion.TypeOfElement = SMESH::ALL;
2403
2404   return aCriterion;
2405 }
2406
2407 //=======================================================================
2408 // name    : SMESHGUI_FilterDlg::onSelectionDone
2409 // Purpose : SLOT called when selection changed.
2410 //           If current cell corresponds to the threshold value of
2411 //           BelongToGeom criterion name of selected object is set in this cell
2412 //=======================================================================
2413 void SMESHGUI_FilterDlg::onSelectionDone()
2414 {
2415   int aRow, aCol;
2416   if (  mySelection->IObjectCount() != 1 ||
2417         !myTable->CurrentCell( aRow, aCol ) ||
2418         myTable->GetCriterionType( aRow ) != FT_BelongToGeom &&
2419         myTable->GetCriterionType( aRow ) != FT_BelongToPlane &&
2420         myTable->GetCriterionType( aRow ) != FT_BelongToCylinder)
2421     return;
2422
2423   Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject() ;
2424   GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO ) ;
2425   if ( !anObj->_is_nil() )
2426     myTable->SetThreshold( aRow, anIO->getName() );
2427 }
2428
2429 //=======================================================================
2430 // name    : SMESHGUI_FilterDlg::onCriterionChanged
2431 // Purpose : SLOT called when cretarion of current row changed. Update selection
2432 //=======================================================================
2433 void SMESHGUI_FilterDlg::onCriterionChanged( const int , const int )
2434 {
2435   updateSelection();
2436 }
2437
2438 //=======================================================================
2439 // name    : SMESHGUI_FilterDlg::onCurrentChanged
2440 // Purpose : SLOT called when current row changed. Update selection
2441 //=======================================================================
2442 void SMESHGUI_FilterDlg::onCurrentChanged( int, int )
2443 {
2444   updateSelection();
2445 }
2446
2447 //=======================================================================
2448 // name    : SMESHGUI_FilterDlg::updateSelection
2449 // Purpose : UpdateSelection in accordance with current row
2450 //=======================================================================
2451 void SMESHGUI_FilterDlg::updateSelection()
2452 {
2453   if ( mySelection == 0 )
2454     return;
2455   
2456   mySelection->ClearFilters();
2457
2458   int aRow, aCol;
2459   
2460   if ( myTable->CurrentCell( aRow, aCol ) &&
2461        ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom ||
2462          myTable->GetCriterionType( aRow ) == FT_BelongToPlane ||
2463          myTable->GetCriterionType( aRow ) == FT_BelongToCylinder ) )
2464   {
2465     if ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom )
2466       mySelection->AddFilter( new SALOME_TypeFilter( "GEOM" ) );
2467     else if ( myTable->GetCriterionType( aRow ) == FT_BelongToPlane )
2468       mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Plane ) );
2469     else if ( myTable->GetCriterionType( aRow ) == FT_BelongToCylinder )
2470       mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Cylinder ) );
2471
2472     myIsSelectionChanged = true;
2473   }
2474   else
2475   {
2476     if ( myIsSelectionChanged )
2477       mySelection->AddFilter( new SALOME_TypeFilter( "This filter deactivate selection" ) );
2478   }
2479 }
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503