Salome HOME
Merge from V6_5_BR 05/06/2012
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28 #include "SMESHGUI_FilterDlg.h"
29
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Filter.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_FilterLibraryDlg.h"
36 #include "SMESHGUI_SpinBox.h"
37
38 #include <SMESH_Actor.h>
39 #include <SMESH_NumberFilter.hxx>
40 #include <SMESH_TypeFilter.hxx>
41
42 // SALOME GEOM includes
43 #include <GEOMBase.h>
44 #include <GEOM_FaceFilter.h>
45 #include <GEOM_TypeFilter.h>
46
47 // SALOME GUI includes
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_MessageBox.h>
52 #include <QtxColorButton.h>
53
54 #include <LightApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_IntSpinBox.h>
59 #include <SalomeApp_DoubleSpinBox.h>
60
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
64
65 #include <SVTK_ViewWindow.h>
66
67 // SALOME KERNEL includes
68 #include <SALOMEDSClient_Study.hxx>
69
70 // OCCT includes
71 #include <StdSelect_TypeOfFace.hxx>
72 #include <BRep_Tool.hxx>
73 #include <TopoDS.hxx>
74 #include <TopoDS_Shape.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_CylindricalSurface.hxx>
77 #include <Precision.hxx>
78 #include <TColStd_MapOfInteger.hxx>
79 #include <TColStd_IndexedMapOfInteger.hxx>
80 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
81
82 // Qt includes
83 #include <QFrame>
84 #include <QLineEdit>
85 #include <QPushButton>
86 #include <QGroupBox>
87 #include <QTableWidget>
88 #include <QStringList>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QGridLayout>
92 #include <QStackedWidget>
93 #include <QApplication>
94 #include <QComboBox>
95 #include <QFontMetrics>
96 #include <QLabel>
97 #include <QButtonGroup>
98 #include <QRadioButton>
99 #include <QRegExp>
100 #include <QListWidget>
101 #include <QCheckBox>
102 #include <QItemDelegate>
103 #include <QDoubleValidator>
104 #include <QKeyEvent>
105 #include <QHeaderView>
106
107 // IDL includes
108 #include <SALOMEconfig.h>
109 #include CORBA_SERVER_HEADER(SMESH_Group)
110
111 #define SPACING 6
112 #define MARGIN  11
113
114 //---------------------------------------
115 // maxLength
116 //---------------------------------------
117 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
118 {
119   int aRes = 0;
120   QMap<int, QString>::const_iterator anIter;
121   for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
122     aRes = qMax(aRes, theMetrics.width(anIter.value()));
123   return aRes;
124 }
125
126 //---------------------------------------
127 // getFilterId
128 //---------------------------------------
129 static int getFilterId (SMESH::ElementType theType)
130 {
131   switch (theType)
132   {
133     case SMESH::NODE   : return SMESH::NodeFilter;
134     case SMESH::EDGE   : return SMESH::EdgeFilter;
135     case SMESH::FACE   : return SMESH::FaceFilter;
136     case SMESH::VOLUME : return SMESH::VolumeFilter;
137     case SMESH::ALL    : return SMESH::AllElementsFilter;
138     default            : return SMESH::UnknownFilter;
139   }
140 }
141
142 /*
143   Class       : SMESHGUI_FilterTable::AdditionalWidget
144   Description : Class for storing additional parameters of criterion
145 */
146
147 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
148 {
149 public:
150   enum { Tolerance };
151
152 public:
153   AdditionalWidget(QWidget* theParent);
154   virtual ~AdditionalWidget();
155
156   virtual QList<int>      GetParameters() const;
157   virtual bool            IsValid(const bool = true) const;
158   virtual double          GetDouble(const int) const;
159   virtual int             GetInteger(const int) const;
160   virtual QString         GetString(const int) const;
161   virtual void            SetDouble(const int, const double);
162   virtual void            SetInteger(const int, const int);
163   virtual void            SetString(const int, const QString&);
164   void                    SetEditable(const int, const bool);
165   void                    SetEditable(const bool);
166   void                    SetPrecision(const int, const char* = 0);
167
168 private:
169   QMap< int, QWidget* > myWidgets;
170 };
171
172 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
173   : QWidget(theParent)
174 {
175   QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
176
177   SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
178   sb->setAcceptNames( false ); // No Notebook variables allowed
179   sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180   sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
181   myWidgets[ Tolerance ] = sb;
182
183   QHBoxLayout* aLay = new QHBoxLayout(this);
184   aLay->setSpacing(SPACING);
185   aLay->setMargin(0);
186
187   aLay->addWidget(aLabel);
188   aLay->addWidget(myWidgets[ Tolerance ]);
189   aLay->addStretch();
190
191   SetDouble( Tolerance, Precision::Confusion() );
192 }
193
194 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
195 {
196 }
197
198 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
199 {
200   QList<int> theList;
201   theList.append(Tolerance);
202   return theList;
203 }
204
205 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
206 {
207   if (!isEnabled())
208     return true;
209
210   QList<int> aParams = GetParameters();
211   QList<int>::const_iterator anIter;
212   for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
213     if ( !myWidgets.contains( *anIter ) ) continue;
214     bool valid = true;
215     if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
216       valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
217     }
218     else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
219       QString foo;
220       valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
221     }
222     if (!valid && theMsg) {
223       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
224                                    tr("SMESHGUI_INVALID_PARAMETERS"));
225       return false;
226     }
227   }
228
229   return true;
230 }
231
232 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
233 {
234   double retval = 0;
235   if ( myWidgets.contains( theId ) ) {
236     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
237       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
238     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
239       retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
240   }
241   return retval;
242 }
243
244 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
245 {
246   int retval = 0;
247   if ( myWidgets.contains( theId ) ) {
248     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
249       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
250     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
251       retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
252   }
253   return retval;
254 }
255
256 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
257 {
258   QString retval = "";
259   if ( myWidgets.contains( theId ) ) {
260     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
261       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
262     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
263       retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
264   }
265   return retval;
266 }
267
268 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
269 {
270   if ( myWidgets.contains( theId ) ) {
271     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
272       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
273     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
274       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
275   }
276 }
277
278 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
279 {
280   if ( myWidgets.contains( theId ) ) {
281     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
282       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
283     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
284       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
285   }
286 }
287
288 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
289 {
290   if ( myWidgets.contains( theId ) ) {
291     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
292       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
293     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
294       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
295   }
296 }
297
298 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
299 {
300   if ( myWidgets.contains( theId ) ) {
301     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
302       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
303     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
304       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
305   }
306 }
307
308 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
309 {
310   QList<int> aParams = GetParameters();
311   QList<int>::const_iterator anIter;
312   for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
313     SetEditable( *anIter,  isEditable );
314 }
315
316 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
317 {
318   if ( myWidgets.contains( theId ) ) {
319     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
320       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
321       double val = sb->GetValue();
322       double min = pow(10.0, -(sb->decimals()));
323       sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
324       sb->SetValue( qMax( val, min ) );
325     }
326   }
327 }
328
329 /*
330   Class       : SMESHGUI_FilterTable::ComboItem
331   Description : Combo table item. Identificator corresponding to string may be assigned
332 */
333
334 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
335 {
336 public:
337   static int     Type();
338
339   ComboItem( const QMap<int, QString>& );
340
341   void           setItems( const QMap<int, QString>& );
342   void           clear();
343   int            count() const;
344
345   int            value() const;
346   void           setValue( const int );
347
348 private:
349   int            id( int ) const;
350   int            index( int ) const;
351
352 private:
353   QMap<int, int> myIdToIdx;
354 };
355
356 int SMESHGUI_FilterTable::ComboItem::Type()
357 {
358   return QTableWidgetItem::UserType + 1;
359 }
360
361 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
362  : QTableWidgetItem( Type() )
363 {
364   setItems( theIds );
365 }
366
367 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
368 {
369   myIdToIdx.clear();
370   QMap<int, QString>::const_iterator it;
371   QStringList items;
372   for ( it = theIds.begin(); it != theIds.end(); ++it ) {
373     myIdToIdx[it.key()] = items.count();
374     items.append( it.value() );
375   }
376   setData( Qt::UserRole, items );
377   setValue( id( 0 ) ); 
378 }
379
380 void SMESHGUI_FilterTable::ComboItem::clear()
381 {
382   QMap<int, QString> empty;
383   setItems( empty );
384 }
385
386 int SMESHGUI_FilterTable::ComboItem::count() const
387 {
388   return myIdToIdx.count();
389 }
390
391 int SMESHGUI_FilterTable::ComboItem::value() const
392 {
393   return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) ); 
394 }
395
396 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
397 {
398   int idx = index( theId );
399   QStringList items = data( Qt::UserRole ).toStringList();
400   setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
401 }
402
403 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
404 {
405   QMap<int,int>::const_iterator it;
406   for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
407     if ( it.value() == idx ) return it.key();
408   return -1;
409 }
410
411 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
412 {
413   return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
414 }
415 /*
416   Class       : SMESHGUI_FilterTable::CheckItem
417   Description : Check table item.
418 */
419
420 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
421 {
422 public:
423   static int     Type();
424
425   CheckItem( bool = false );
426   CheckItem( const QString&, bool = false );
427   ~CheckItem();
428
429   void  setChecked( bool );
430   bool  checked() const;
431 };
432
433 int SMESHGUI_FilterTable::CheckItem::Type()
434 {
435   return QTableWidgetItem::UserType + 2;
436 }
437
438 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
439  : QTableWidgetItem( Type() )
440 {
441   Qt::ItemFlags f = flags();
442   f = f | Qt::ItemIsUserCheckable;
443   f = f & ~Qt::ItemIsTristate;
444   f = f & ~Qt::ItemIsEditable;
445   setFlags( f );
446   setChecked(value);
447 }
448
449 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
450  : QTableWidgetItem( Type() )
451 {
452   Qt::ItemFlags f = flags();
453   f = f | Qt::ItemIsUserCheckable;
454   f = f & ~Qt::ItemIsTristate;
455   f = f & ~Qt::ItemIsEditable;
456   setFlags( f );
457   setChecked( value );
458   setText( text );
459 }
460
461 SMESHGUI_FilterTable::CheckItem::~CheckItem()
462 {
463 }
464
465 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
466 {
467   setCheckState( value ? Qt::Checked : Qt::Unchecked );
468 }
469
470 bool SMESHGUI_FilterTable::CheckItem::checked() const
471 {
472   return checkState() == Qt::Checked;
473 }
474
475 /*
476   Class       : SMESHGUI_FilterTable::IntSpinItem
477   Description : Integer spin table item.
478 */
479
480 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
481 {
482 public:
483   static int     Type();
484
485   IntSpinItem( const int theValue );
486
487   int            value() const;
488   void           setValue( const int theValue );
489
490   void           clear();
491 };
492
493 int SMESHGUI_FilterTable::IntSpinItem::Type()
494 {
495   return QTableWidgetItem::UserType + 3;
496 }
497
498 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
499  : QTableWidgetItem( Type() )
500 {
501   setValue( theValue );
502 }
503
504 int SMESHGUI_FilterTable::IntSpinItem::value() const
505 {
506   bool ok = false;
507   int value = data( Qt::UserRole ).toInt( &ok );
508   return ok ? value : 0; 
509 }
510
511 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
512 {
513   setData( Qt::UserRole, theValue );
514   setText( QString::number( theValue ) ); 
515 }
516
517 void SMESHGUI_FilterTable::IntSpinItem::clear()
518 {
519   setText( "" );
520 }
521
522 /*
523   Class       : SMESHGUI_FilterTable::DoubleSpinItem
524   Description : Double spin table item.
525 */
526
527 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
528 {
529 public:
530   static int     Type();
531
532   DoubleSpinItem( const double theValue );
533
534   double         value() const;
535   void           setValue( const double theValue );
536
537   int            precision() const;
538   void           setPrecision( const int thePrecision );
539
540   void           clear();
541 };
542
543 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
544 {
545   return QTableWidgetItem::UserType + 4;
546 }
547
548 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
549  : QTableWidgetItem( Type() )
550 {
551   setValue( theValue );
552 }
553
554 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
555 {
556   bool ok = false;
557   double value = data( Qt::UserRole ).toDouble( &ok );
558   return ok ? value : 0; 
559 }
560
561 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
562 {
563   setData( Qt::UserRole, theValue );
564   setText( QString::number( theValue ) ); 
565 }
566
567 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
568 {
569   bool ok = false;
570   int precision = data( Qt::UserRole + 1 ).toInt( &ok );
571   return ok ? precision : 0; 
572 }
573
574 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
575 {
576   setData( Qt::UserRole + 1, thePrecision );
577 }
578
579 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
580 {
581   setText( "" );
582 }
583
584 /*
585   Class       : SMESHGUI_FilterTable::ComboDelegate
586   Description : Table used by this widget
587 */
588
589 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
590 {
591 public:
592   ComboDelegate( QObject* = 0 );
593   ~ComboDelegate();
594   
595   QWidget*      createEditor( QWidget*, const QStyleOptionViewItem&,
596                               const QModelIndex& ) const;
597   
598   void          setEditorData( QWidget*, const QModelIndex& ) const;
599   void          setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
600   
601   void          updateEditorGeometry( QWidget*, const QStyleOptionViewItem&, 
602                                       const QModelIndex& ) const;
603 private:
604   QTableWidget* myTable;
605 };
606
607 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
608   : QItemDelegate( parent ), 
609     myTable( qobject_cast<QTableWidget*>( parent ) )
610 {
611 }
612   
613 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
614 {
615 }
616
617 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
618                                                             const QStyleOptionViewItem& option,
619                                                             const QModelIndex& index ) const
620 {
621   QVariant aData = index.data( Qt::UserRole );
622   QVariant::Type aDataType = aData.type();
623   if( aDataType == QVariant::StringList ) {
624     QStringList l = aData.toStringList();
625     if ( !l.isEmpty() ) {
626       QComboBox* cb = new QComboBox( parent );
627       cb->setFrame( false );
628       cb->addItems( l );
629       return cb;
630     }
631   }
632   else if( aDataType == QVariant::Int ) {
633     bool ok = false;
634     int aValue = aData.toInt( &ok );
635     if ( ok ) {
636       SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
637       intSpin->setFrame( false );
638       intSpin->setValue( aValue );
639       return intSpin;
640     }
641   }
642   else if( aDataType == QVariant::Double ) {
643     bool ok = false;
644     double aValue = aData.toDouble( &ok );
645     if ( ok ) {
646       int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
647       if ( !ok )
648         aPrecision = 0;
649
650       SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
651       dblSpin->setFrame( false );
652       dblSpin->setValue( aValue );
653       return dblSpin;
654     }
655   }
656   return QItemDelegate::createEditor( parent, option, index );
657 }
658
659 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor, 
660                                                          const QModelIndex& index ) const
661 {
662   QVariant data = index.model()->data( index, Qt::DisplayRole );
663   QString value = data.toString();
664   bool bOk = false;
665   if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
666     int i = cb->findText( value );
667     if ( i >= 0 ) {
668       cb->setCurrentIndex( i );
669       bOk = true;
670     }
671   }
672   else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
673     if( data.type() == QVariant::Double ) {
674       double valueDouble = data.toDouble( &bOk );
675       if( bOk )
676         dblSpin->setValue( valueDouble );
677     }
678   }
679   if ( !bOk ) QItemDelegate::setEditorData( editor, index );
680 }
681
682 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
683                                                         QAbstractItemModel* model,
684                                                         const QModelIndex& index) const
685 {
686   if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
687     model->setData( index, cb->currentText(), Qt::DisplayRole );
688   else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
689     model->setData( index, intSpin->value(), Qt::DisplayRole );
690   else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
691     model->setData( index, dblSpin->value(), Qt::DisplayRole );
692   else QItemDelegate::setModelData( editor, model, index );
693 }
694
695 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
696                                                                 const QStyleOptionViewItem& option, 
697                                                                 const QModelIndex& index ) const
698 {
699   editor->setGeometry( option.rect );
700 }
701
702 /*
703   Class       : SMESHGUI_FilterTable::Table
704   Description : Table used by this widget
705 */
706
707 class SMESHGUI_FilterTable::Table : public QTableWidget
708 {
709 public:
710   Table( QWidget* = 0 );
711   Table( int, int, QWidget* = 0 );
712   virtual ~Table();
713
714   QSize                   minimumSizeHint() const;
715
716   void                    setEditable( bool, int, int );
717   bool                    isEditable( int, int ) const;
718
719   void                    setReadOnly( bool );
720   bool                    isReadOnly() const;
721
722   void                    insertRows( int, int = 1 );
723   QString                 text( int, int );
724
725   QList<int>              selectedRows();
726 };
727
728 //=======================================================================
729 // name    : SMESHGUI_FilterTable::Table::Table
730 // Purpose : Constructor
731 //=======================================================================
732 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
733 : QTableWidget(parent)
734 {
735   // set custom item delegate
736   setItemDelegate( new ComboDelegate(this) );
737   // set edit triggers by default
738   setReadOnly( false );
739 }
740
741 //=======================================================================
742 // name    : SMESHGUI_FilterTable::Table::Table
743 // Purpose : Constructor
744 //=======================================================================
745 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
746 : QTableWidget(numRows, numCols, parent)
747 {
748   // set custom item delegate
749   setItemDelegate( new ComboDelegate(this) );
750   // set edit triggers by default
751   setReadOnly( false );
752 }
753
754 //=======================================================================
755 // name    : SMESHGUI_FilterTable::Table::~Table
756 // Purpose : Destructor
757 //=======================================================================
758 SMESHGUI_FilterTable::Table::~Table()
759 {
760 }
761
762 //=======================================================================
763 // name    : SMESHGUI_FilterTable::Table::minimumSizeHint
764 // Purpose : Get minimum size for the table
765 //=======================================================================
766 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
767 {
768   QSize s = QTableWidget::minimumSizeHint();
769   QHeaderView* hv = horizontalHeader();
770   if ( hv )
771     s.setWidth( qMax( s.width(), hv->length() ) );
772   return s;
773 }
774
775 //=======================================================================
776 // name    : SMESHGUI_FilterTable::Table::setEditable
777 // Purpose : Set editable of specified cell
778 //=======================================================================
779 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
780                                                int row, int col)
781 {
782   QTableWidgetItem* anItem = item( row, col );
783   if ( anItem ) {
784     bool isSignalsBlocked = signalsBlocked();
785     blockSignals( true );
786
787     Qt::ItemFlags f = anItem->flags();
788     if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
789     else f = f | Qt::ItemIsEditable;
790     anItem->setFlags( f );
791     
792     blockSignals( isSignalsBlocked );
793   }
794 }
795
796 //=======================================================================
797 // name    : SMESHGUI_FilterTable::Table::isEditable
798 // Purpose : Verify wheter cell is editable
799 //=======================================================================
800 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
801 {
802   QTableWidgetItem* anItem = item( row, col );
803   return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
804 }
805
806 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
807 {
808   setEditTriggers( on ? 
809                    QAbstractItemView::NoEditTriggers  :
810                    QAbstractItemView::AllEditTriggers );
811 }
812
813 bool SMESHGUI_FilterTable::Table::isReadOnly() const
814 {
815   return editTriggers() == QAbstractItemView::NoEditTriggers;
816 }
817
818 //=======================================================================
819 // name    : SMESHGUI_FilterTable::Table::insertRows
820 // Purpose : Insert rows (virtual redefined)
821 //=======================================================================
822 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
823 {
824   closePersistentEditor( currentItem() );
825   while ( count-- ) insertRow( row );
826 }
827
828 //=======================================================================
829 // name    : SMESHGUI_FilterTable::Table::text
830 // Purpose : Get text from cell (virtual redefined)
831 //=======================================================================
832 QString SMESHGUI_FilterTable::Table::text (int row, int col)
833 {
834   closePersistentEditor( currentItem() );
835   QTableWidgetItem* anItem = item( row, col );
836   return anItem ? anItem->text() : QString();
837 }
838
839 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
840 {
841   QList<QTableWidgetItem*> selItems = selectedItems();
842   QTableWidgetItem* anItem;
843   QList<int> rows;
844
845   foreach( anItem, selItems ) {
846     int r = row( anItem );
847     if ( !rows.contains( r ) ) rows.append( r );
848   }
849
850   qSort( rows );
851   return rows;
852 }
853
854 /*
855   Class       : SMESHGUI_FilterTable
856   Description : Frame containig
857                   - Button group for switching entity type
858                   - Table for displaying filter criterions
859                   - Buttons for editing table and filter libraries
860 */
861
862 //=======================================================================
863 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
864 // Purpose : Constructor
865 //=======================================================================
866 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
867                                             QWidget* parent,
868                                             const int type )
869 : QWidget( parent ),
870   myIsLocked( false ),
871   mySMESHGUI( theModule )
872 {
873   myEntityType = -1;
874
875   QList<int> aTypes;
876   aTypes.append(type);
877   Init(aTypes);
878 }
879
880 //=======================================================================
881 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
882 // Purpose : Constructor
883 //=======================================================================
884 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
885                                             QWidget* parent,
886                                             const QList<int>& types )
887 : QWidget( parent ),
888   myIsLocked( false ),
889   mySMESHGUI( theModule )
890 {
891   myEntityType = -1;
892   Init(types);
893 }
894
895 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
896 {
897 }
898
899 //=======================================================================
900 // name    : SMESHGUI_FilterTable::Init
901 // Purpose : Create table corresponding to the specified type
902 //=======================================================================
903 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
904 {
905   if (theTypes.isEmpty())
906     return;
907
908   // Create buttons if necessary
909
910   if (myTables.isEmpty())
911   {
912     // create main layout
913     QVBoxLayout* aMainLay = new QVBoxLayout(this);
914     aMainLay->setMargin( 0 );
915     aMainLay->setSpacing( SPACING );
916
917     // create switch of entity types
918     myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
919     QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
920     myEntityTypeBoxLayout->setMargin( MARGIN );
921     myEntityTypeBoxLayout->setSpacing( SPACING );
922     myEntityTypeGrp = new QButtonGroup(this);
923
924     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
925     QMap<int, QString>::const_iterator anIter;
926     for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
927     {
928       QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
929       myEntityTypeGrp->addButton(aBtn, anIter.key());
930       myEntityTypeBoxLayout->addWidget(aBtn);
931     }
932
933     myTableGrp = new QGroupBox(tr("FILTER"), this );
934
935     // create table
936     mySwitchTableGrp = new QWidget(myTableGrp);
937     QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
938     mySwitchTableGrpLayout->setMargin(0);
939     mySwitchTableGrpLayout->setSpacing(0);
940
941     QList<int>::const_iterator typeIt = theTypes.begin();
942     for ( ; typeIt != theTypes.end(); ++typeIt ) {
943       Table* aTable = createTable(mySwitchTableGrp, *typeIt);
944       myTables[ *typeIt ] = aTable;
945       mySwitchTableGrpLayout->addWidget(aTable);
946       if ( typeIt != theTypes.begin() )
947         aTable->hide();
948     }
949
950     // create buttons
951     myAddBtn      = new QPushButton(tr("ADD"),       myTableGrp);
952     myRemoveBtn   = new QPushButton(tr("REMOVE"),    myTableGrp);
953     myClearBtn    = new QPushButton(tr("CLEAR"),     myTableGrp);
954     myInsertBtn   = new QPushButton(tr("INSERT"),    myTableGrp);
955     myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
956     myAddToBtn    = new QPushButton(tr("ADD_TO"),    myTableGrp);
957
958     myAddBtn->setAutoDefault(false);
959     myRemoveBtn->setAutoDefault(false);
960     myClearBtn->setAutoDefault(false);
961     myInsertBtn->setAutoDefault(false);
962     myCopyFromBtn->setAutoDefault(false);
963     myAddToBtn->setAutoDefault(false);
964
965     myCopyFromBtn->hide();
966     myAddToBtn->hide();
967
968     // layout widgets
969     QGridLayout* aLay = new QGridLayout(myTableGrp);
970     aLay->setMargin(MARGIN);
971     aLay->setSpacing(SPACING);
972
973     aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
974     aLay->addWidget(myAddBtn,         0, 1);
975     aLay->addWidget(myInsertBtn,      1, 1);
976     aLay->addWidget(myRemoveBtn,      2, 1);
977     aLay->addWidget(myClearBtn,       3, 1);
978     aLay->addWidget(myCopyFromBtn,    5, 1);
979     aLay->addWidget(myAddToBtn,       6, 1);
980     aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
981
982     aLay->setRowMinimumHeight(4, 10);
983     aLay->setRowStretch(4, 1);
984     aLay->setColumnStretch(0, 1);
985     aLay->setColumnStretch(1, 0);
986
987     // layout 
988     aMainLay->addWidget(myEntityTypeBox);
989     aMainLay->addWidget(myTableGrp);
990     
991     // signals and slots
992     connect(myAddBtn,    SIGNAL(clicked()), this, SLOT(onAddBtn()));
993     connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
994     connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
995     connect(myClearBtn,  SIGNAL(clicked()), this, SLOT(onClearBtn()));
996
997     connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
998     connect(myAddToBtn,    SIGNAL(clicked()), this, SLOT(onAddToBtn()));
999
1000     connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1001
1002     myLibDlg = 0;
1003   }
1004
1005   // Hide buttons of entity types if necessary
1006   const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1007   QMap<int, QString>::const_iterator anIt;
1008   for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1009   {
1010     QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1011     if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1012   }
1013
1014   // select first button if there is no selected buttons or it is hidden
1015   int aBtnId = myEntityTypeGrp->checkedId();
1016   if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1017     QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1018     if ( aBtn ) aBtn->setChecked(true);
1019   }
1020
1021   myEntityTypeBox->setVisible(theTypes.count() > 1);
1022
1023   myTableGrp->updateGeometry();
1024   int cType = myEntityTypeGrp->checkedId();
1025   onEntityType(cType);
1026 }
1027
1028 //=======================================================================
1029 // name    : SMESHGUI_FilterTable::createAdditionalFrame
1030 // Purpose : Get group box containing table. May be used for adding new widgets in it
1031 //=======================================================================
1032 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1033 {
1034   QWidget* aFrame = new QWidget(theParent);
1035
1036   QFrame* aLine1 = new QFrame(aFrame);
1037   QFrame* aLine2 = new QFrame(aFrame);
1038   aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1039   aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1040   aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1041   aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1042
1043   QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1044
1045   myWgStack = new QStackedWidget(aFrame);
1046
1047   QGridLayout* aLay = new QGridLayout(aFrame);
1048   aLay->setMargin(0);
1049   aLay->setSpacing(SPACING);
1050   aLay->addWidget(aLine1,    0, 0);
1051   aLay->addWidget(aLabel,    0, 1);
1052   aLay->addWidget(aLine2,    0, 2);
1053   aLay->addWidget(myWgStack, 1, 0, 1, 3);
1054
1055   return aFrame;
1056 }
1057
1058 //=======================================================================
1059 // name    : SMESHGUI_FilterTable::GetTableGrp
1060 // Purpose : Get group box containing table. May be used for adding new widgets in it
1061 //=======================================================================
1062 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1063 {
1064   return myTableGrp;
1065 }
1066
1067 //=======================================================================
1068 // name    : SMESHGUI_FilterTable::onEntityType
1069 // Purpose : SLOT. Called when entity type changed.
1070 //           Display corresponding table
1071 //=======================================================================
1072 void SMESHGUI_FilterTable::onEntityType (int theType)
1073 {
1074   if (myEntityType == theType)
1075     return;
1076
1077   myIsValid = true;
1078   emit NeedValidation();
1079   if (!myIsValid)
1080   {
1081     myEntityTypeGrp->button(myEntityType)->setChecked(true);
1082     return;
1083   }
1084
1085   myEntityType = theType;
1086
1087   if (!myTables.contains(theType)) {
1088     myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1089     ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1090   }
1091
1092   TableMap::iterator anIter;
1093   for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1094      anIter.value()->setVisible( myEntityType == anIter.key() );
1095
1096   updateBtnState();
1097   qApp->processEvents();
1098   myTables[ myEntityType ]->updateGeometry();
1099   adjustSize();
1100
1101   emit EntityTypeChanged(theType);
1102 }
1103
1104 //=======================================================================
1105 // name    : SMESHGUI_FilterTable::IsValid
1106 // Purpose : Verify validity of entered data
1107 //=======================================================================
1108 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1109 {
1110   int aType = theEntityType == -1 ? GetType() : theEntityType;
1111
1112   Table* aTable = myTables[ aType ];
1113   for (int i = 0, n = aTable->rowCount(); i < n; i++)
1114   {
1115     int aCriterion = GetCriterionType(i, aType);
1116     QString errMsg;
1117     if (aCriterion == SMESH::FT_GroupColor ) {
1118       QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1119       if (clrBtn && !clrBtn->color().isValid())
1120         errMsg = tr( "GROUPCOLOR_ERROR" );
1121     }
1122     else if (aCriterion == SMESH::FT_RangeOfIds ||
1123              aCriterion == SMESH::FT_BelongToGeom ||
1124              aCriterion == SMESH::FT_BelongToPlane ||
1125              aCriterion == SMESH::FT_BelongToCylinder ||
1126              aCriterion == SMESH::FT_BelongToGenSurface ||
1127              aCriterion == SMESH::FT_ElemGeomType ||
1128              aCriterion == SMESH::FT_CoplanarFaces ||
1129              aCriterion == SMESH::FT_LyingOnGeom)
1130     {
1131       if (aTable->text(i, 2).isEmpty())
1132         errMsg = tr( "ERROR" );
1133     }
1134     else {
1135       bool aRes = false;
1136       bool isSignalsBlocked = aTable->signalsBlocked();
1137       aTable->blockSignals(true);
1138       double  aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1139       aTable->blockSignals(isSignalsBlocked);
1140
1141       if (!aRes && aTable->isEditable(i, 2))
1142         errMsg = tr( "ERROR" );
1143       else if (aType == SMESH::EDGE &&
1144                GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1145                aThreshold == 1)
1146         errMsg = tr( "MULTIEDGES_ERROR" );
1147     }
1148
1149     if (!errMsg.isEmpty()) {
1150       if (theMess)
1151         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1152       return false;
1153     }
1154
1155     QTableWidgetItem* anItem = aTable->item(i, 0);
1156     if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1157       return false;
1158   }
1159
1160   return true;
1161 }
1162
1163 //=======================================================================
1164 // name    : SMESHGUI_FilterTable::SetValidity
1165 // Purpose : Set validity of the table
1166 //=======================================================================
1167 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1168 {
1169   myIsValid = isValid;
1170 }
1171
1172 //=======================================================================
1173 // name    : SMESHGUI_FilterTable::GetType
1174 // Purpose : Get current entity type
1175 //=======================================================================
1176 int SMESHGUI_FilterTable::GetType() const
1177 {
1178   return myEntityType;
1179 }
1180
1181 //=======================================================================
1182 // name    : SMESHGUI_FilterTable::SetType
1183 // Purpose : Set current entity type
1184 //=======================================================================
1185 void SMESHGUI_FilterTable::SetType (const int type)
1186 {
1187   myEntityTypeGrp->button(type)->setChecked(true);
1188   onEntityType(type);
1189 }
1190
1191 //=======================================================================
1192 // name    : SMESHGUI_FilterTable::RestorePreviousEntityType
1193 // Purpose : Restore previous entity type
1194 //=======================================================================
1195 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1196 {
1197   SetType(myEntityType);
1198 }
1199
1200 //=======================================================================
1201 // name    : SMESHGUI_FilterTable::GetCriterionType
1202 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1203 //=======================================================================
1204 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1205 {
1206   int aType = theType == -1 ? GetType() : theType;
1207   Table* aTable = myTables[ aType ];
1208   ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1209   return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1210 }
1211
1212 //=======================================================================
1213 // name    : SMESHGUI_FilterTable::GetCriterion
1214 // Purpose : Get parameters of criterion from specified row
1215 //=======================================================================
1216 void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
1217                                          SMESH::Filter::Criterion& theCriterion,
1218                                          const int                 theEntityType) const
1219 {
1220   int aType = theEntityType == -1 ? GetType() : theEntityType;
1221   Table* aTable = myTables[ aType ];
1222
1223   theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1224   theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1225   theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1226     ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1227   theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1228
1229   int aCriterionType = GetCriterionType(theRow, aType);
1230
1231   if ( aCriterionType == SMESH::FT_GroupColor )
1232   {
1233     QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1234     if ( clrBtn )
1235     {
1236       const QColor qClr = clrBtn->color();
1237       QString clrStr = QString( "%1;%2;%3" ).
1238         arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1239       theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1240     }
1241   }
1242   else if ( aCriterionType == SMESH::FT_ElemGeomType )
1243     theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1244   else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1245     theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1246   else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1247             aCriterionType != SMESH::FT_BelongToGeom &&
1248             aCriterionType != SMESH::FT_BelongToPlane &&
1249             aCriterionType != SMESH::FT_BelongToCylinder &&
1250             aCriterionType != SMESH::FT_BelongToGenSurface &&
1251             aCriterionType != SMESH::FT_LyingOnGeom )
1252   {
1253     theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1254     theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1255   }
1256   else
1257   {
1258     theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1259     if ( aCriterionType != SMESH::FT_RangeOfIds )
1260       theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1261   }
1262
1263   QTableWidgetItem* anItem = aTable->item(theRow, 0);
1264   if (myAddWidgets.contains(anItem))
1265     theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1266 }
1267
1268 //=======================================================================
1269 // name    : SMESHGUI_FilterTable::SetCriterion
1270 // Purpose : Set parameters of criterion of specified row
1271 //=======================================================================
1272 void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
1273                                          const SMESH::Filter::Criterion& theCriterion,
1274                                          const int                       theEntityType)
1275 {
1276   int aType = theEntityType == -1 ? GetType() : theEntityType;
1277
1278   Table* aTable = myTables[ aType ];
1279
1280   if (theRow > aTable->rowCount() - 1)
1281     return;
1282
1283   ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1284   onCriterionChanged(theRow, 0, aType);
1285   if ( theCriterion.Compare == SMESH::FT_Undefined )
1286     ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
1287   else
1288     ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1289   ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1290
1291   if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1292   {
1293     if (!aTable->isEditable(theRow, 4))
1294       aTable->setItem(theRow, 4, getBinaryItem());
1295     ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1296   }
1297   else
1298     aTable->setEditable(false, theRow, 4);
1299
1300   if (theCriterion.Type == SMESH::FT_GroupColor )
1301   {
1302     QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1303     if ( clrBtn )
1304     {
1305       QColor qClr;
1306       QString clrStr( theCriterion.ThresholdStr );
1307       QStringList clrVals = clrStr.split( ";" );
1308       if ( clrVals.count() > 2 )
1309         qClr.setRgb( (int)256*clrVals[0].toDouble(),
1310                      (int)256*clrVals[1].toDouble(),
1311                      (int)256*clrVals[2].toDouble() );
1312       clrBtn->setColor( qClr );
1313     }
1314   }
1315   else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1316   {
1317     ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1318     typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1319   }
1320   else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1321   {
1322     aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1323   }
1324   else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1325            theCriterion.Type != SMESH::FT_BelongToGeom &&
1326            theCriterion.Type != SMESH::FT_BelongToPlane &&
1327            theCriterion.Type != SMESH::FT_BelongToCylinder &&
1328            theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1329            theCriterion.Type != SMESH::FT_LyingOnGeom &&
1330            theCriterion.Type != SMESH::FT_CoplanarFaces &&
1331            theCriterion.Type != SMESH::FT_FreeBorders &&
1332            theCriterion.Type != SMESH::FT_FreeEdges &&
1333            theCriterion.Type != SMESH::FT_FreeNodes &&
1334            theCriterion.Type != SMESH::FT_FreeFaces &&
1335            theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1336            theCriterion.Type != SMESH::FT_BareBorderFace &&
1337            theCriterion.Type != SMESH::FT_BareBorderVolume &&
1338            theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1339            theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1340            theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1341   {
1342     aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1343   }
1344   else
1345   {
1346     aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1347     if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1348       aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1349   }
1350
1351   if (theCriterion.Compare == SMESH::FT_EqualTo ||
1352       theCriterion.Type    == SMESH::FT_BelongToPlane ||
1353       theCriterion.Type    == SMESH::FT_BelongToCylinder ||
1354       theCriterion.Type    == SMESH::FT_BelongToGenSurface ||
1355       theCriterion.Type    == SMESH::FT_BelongToGeom ||
1356       theCriterion.Type    == SMESH::FT_LyingOnGeom ||
1357       theCriterion.Type    == SMESH::FT_CoplanarFaces ||
1358       theCriterion.Type    == SMESH::FT_EqualNodes)
1359   {
1360     QTableWidgetItem* anItem = aTable->item(theRow, 0);
1361     if (!myAddWidgets.contains(anItem))
1362     {
1363       myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1364       myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1365       myWgStack->addWidget(myAddWidgets[ anItem ]);
1366     }
1367     myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1368   }
1369
1370   emit CriterionChanged(theRow, aType);
1371 }
1372
1373 //=======================================================================
1374 // name    : SMESHGUI_FilterTable::Update
1375 // Purpose : Update table
1376 //=======================================================================
1377 void SMESHGUI_FilterTable::Update()
1378 {
1379   Table* aTable = myTables[ GetType() ];
1380   int aCurrRow = aTable->currentRow();
1381   int numRows = aTable->rowCount();
1382   if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1383     aTable->setCurrentCell(0, 0);
1384   updateAdditionalWidget();
1385 }
1386
1387 //=======================================================================
1388 // name    : SMESHGUI_FilterTable::AddCriterion
1389 // Purpose : Add criterion with parameters
1390 //=======================================================================
1391 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1392                                          const int                       theEntityType)
1393 {
1394   int aType = theEntityType == -1 ? GetType() : theEntityType;
1395   Table* aTable = myTables[ aType ];
1396   addRow(aTable, aType);
1397   SetCriterion(aTable->rowCount() - 1, theCriterion);
1398 }
1399
1400 //=======================================================================
1401 // name    : SMESHGUI_FilterTable::NumRows
1402 // Purpose : Get number of criterions of current type
1403 //=======================================================================
1404 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1405 {
1406   return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1407 }
1408
1409 //=======================================================================
1410 // name    : SMESHGUI_FilterTable::Clear
1411 // Purpose : Clear current table
1412 //=======================================================================
1413 void SMESHGUI_FilterTable::Clear (const int theType)
1414 {
1415   int aType = theType == -1 ? GetType() : theType;
1416   Table* aTable = myTables[ aType ];
1417
1418   if (aTable->rowCount() == 0)
1419     return;
1420
1421   while (aTable->rowCount() > 0)
1422   {
1423     removeAdditionalWidget(aTable, 0);
1424     aTable->removeRow(0);
1425   }
1426
1427   updateBtnState();
1428 }
1429
1430 //=======================================================================
1431 // name    : SMESHGUI_FilterTable::onAddBtn
1432 // Purpose : SLOT. Called then "Add" button pressed.
1433 //           Adds new string to table
1434 //=======================================================================
1435 void SMESHGUI_FilterTable::onAddBtn()
1436 {
1437   int aType = GetType();
1438   addRow(myTables[ aType ], aType);
1439
1440   Update();
1441 }
1442
1443 //=======================================================================
1444 // name    : SMESHGUI_FilterTable::onInsertBtn
1445 // Purpose : SLOT. Called then "Insert" button pressed.
1446 //           Inserts new string before current one
1447 //=======================================================================
1448 void SMESHGUI_FilterTable::onInsertBtn()
1449 {
1450   addRow(myTables[ GetType() ], GetType(), false);
1451 }
1452
1453 //=======================================================================
1454 // name    : SMESHGUI_FilterTable::onRemoveBtn
1455 // Purpose : SLOT. Called then "Remove" button pressed.
1456 //           Removes current string from table
1457 //=======================================================================
1458 void SMESHGUI_FilterTable::onRemoveBtn()
1459 {
1460   Table* aTable = myTables[ GetType() ];
1461
1462   if (aTable->rowCount() == 0)
1463     return;
1464
1465   QList<QTableWidgetItem*> items = aTable->selectedItems();
1466   
1467   QList<int> aRows = aTable->selectedRows(); // already sorted
1468   int i;
1469   foreach( i, aRows )
1470   {
1471     removeAdditionalWidget(aTable, i);
1472     aTable->removeRow(i);
1473   }
1474
1475   // remove control of binary logical operation from last row
1476   if (aTable->rowCount() > 0)
1477     aTable->setEditable(false, aTable->rowCount() - 1, 4);
1478
1479   updateBtnState();
1480 }
1481
1482 //=======================================================================
1483 // name    : SMESHGUI_FilterTable::updateAdditionalWidget
1484 // Purpose : Enable/Disable widget with additonal parameters
1485 //=======================================================================
1486 void SMESHGUI_FilterTable::updateAdditionalWidget()
1487 {
1488   Table* aTable = myTables[ GetType() ];
1489   int aRow = aTable->currentRow();
1490   if (aRow < 0 || aRow >= aTable->rowCount())
1491   {
1492     myWgStack->setEnabled(false);
1493     return;
1494   }
1495
1496   ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1497   int aCriterion = GetCriterionType(aRow);
1498   bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1499                    aCriterion != SMESH::FT_RangeOfIds &&
1500                    aCriterion != SMESH::FT_FreeEdges &&
1501                    aCriterion != SMESH::FT_FreeFaces &&
1502                    aCriterion != SMESH::FT_BadOrientedVolume &&
1503                    aCriterion != SMESH::FT_BareBorderFace &&
1504                    aCriterion != SMESH::FT_BareBorderVolume &&
1505                    aCriterion != SMESH::FT_OverConstrainedFace &&
1506                    aCriterion != SMESH::FT_OverConstrainedVolume)
1507                    ||
1508                    aCriterion == SMESH::FT_CoplanarFaces);
1509   
1510   if (!myAddWidgets.contains(anItem))
1511   {
1512     myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1513     myWgStack->addWidget(myAddWidgets[ anItem ]);
1514   }
1515
1516   myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1517   myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1518   myWgStack->setEnabled(toEnable);
1519 }
1520
1521 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1522 {
1523   const char* retval = 0;
1524   switch ( aType ) {
1525   case SMESH::FT_AspectRatio:
1526   case SMESH::FT_AspectRatio3D:
1527   case SMESH::FT_Taper:
1528     retval = "parametric_precision"; break;
1529   case SMESH::FT_Warping:
1530   case SMESH::FT_MinimumAngle:
1531   case SMESH::FT_Skew:
1532   case SMESH::FT_CoplanarFaces:
1533     retval = "angle_precision"; break;
1534   case SMESH::FT_Area:
1535     retval = "area_precision"; break;
1536   case SMESH::FT_BelongToGeom:
1537   case SMESH::FT_BelongToPlane:
1538   case SMESH::FT_BelongToCylinder:
1539   case SMESH::FT_BelongToGenSurface:
1540   case SMESH::FT_LyingOnGeom:
1541   case SMESH::FT_EqualNodes:
1542     retval = "len_tol_precision"; break;
1543   case SMESH::FT_Length:
1544   case SMESH::FT_Length2D:
1545   case SMESH::FT_MaxElementLength2D:
1546   case SMESH::FT_MaxElementLength3D:
1547     retval = "length_precision"; break;
1548   case SMESH::FT_Volume3D:
1549     retval = "vol_precision"; break;
1550   default:
1551     break;
1552   }
1553   return retval;
1554 }
1555
1556 //=======================================================================
1557 // name    : SMESHGUI_FilterTable::removeAdditionalWidget
1558 // Purpose : Remove widgets containing additional parameters from widget
1559 //           stack and internal map
1560 //=======================================================================
1561 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1562 {
1563   QTableWidgetItem* anItem = theTable->item(theRow, 0);
1564   if (myAddWidgets.contains(anItem))
1565   {
1566     myWgStack->removeWidget(myAddWidgets[ anItem ]);
1567     myAddWidgets[ anItem ]->setParent(0);
1568     delete myAddWidgets[ anItem ];
1569     myAddWidgets.remove(anItem);
1570   }
1571 }
1572
1573 //=======================================================================
1574 // name    : SMESHGUI_FilterTable::onClearBtn
1575 // Purpose : SLOT. Called then "Clear" button pressed.
1576 //           Removes all strings from table
1577 //=======================================================================
1578 void SMESHGUI_FilterTable::onClearBtn()
1579 {
1580   Table* aTable = myTables[ GetType() ];
1581
1582   if (aTable->rowCount() == 0)
1583     return;
1584
1585   while (aTable->rowCount() > 0)
1586   {
1587     removeAdditionalWidget(aTable, 0);
1588     aTable->removeRow(0);
1589   }
1590
1591   updateBtnState();
1592 }
1593
1594 //=======================================================================
1595 // name    : SMESHGUI_FilterTable::onCurrentChanged()
1596 // Purpose : SLOT. Called when current cell changed
1597 //=======================================================================
1598 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1599 {
1600   if( !myIsLocked )
1601     updateAdditionalWidget();
1602   emit CurrentChanged(theRow, theCol);
1603 }
1604
1605 //=======================================================================
1606 // name    : geomTypes
1607 // Purpose : returns available geometry types of elements
1608 //=======================================================================
1609 static QList<int> geomTypes( const int theType )
1610 {
1611   QList<int> typeIds;
1612   if ( theType == SMESH::NODE )
1613     typeIds.append( SMESH::Geom_POINT );
1614   if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1615     typeIds.append( SMESH::Geom_EDGE );
1616   if ( theType == SMESH::ALL || theType == SMESH::FACE )
1617   {
1618     typeIds.append( SMESH::Geom_TRIANGLE );
1619     typeIds.append( SMESH::Geom_QUADRANGLE );
1620     typeIds.append( SMESH::Geom_POLYGON );
1621   }
1622   if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1623   {
1624     typeIds.append( SMESH::Geom_TETRA );
1625     typeIds.append( SMESH::Geom_PYRAMID );
1626     typeIds.append( SMESH::Geom_HEXA );
1627     typeIds.append( SMESH::Geom_PENTA );
1628     typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1629     typeIds.append( SMESH::Geom_POLYHEDRA );
1630   }
1631   return typeIds;
1632 }
1633
1634 //=======================================================================
1635 // name    : SMESHGUI_FilterTable::onCriterionChanged()
1636 // Purpose : Provides reaction on change of criterion
1637 //=======================================================================
1638 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1639 {
1640   int aType = entityType == -1 ? GetType() : entityType;
1641   Table* aTable = myTables[ aType ];
1642   ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1643
1644   int aCriterionType = GetCriterionType(row);
1645   QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1646   int aComboType = ComboItem::Type();
1647   int aIntSpinType = IntSpinItem::Type();
1648   int aDoubleSpinType = DoubleSpinItem::Type();
1649   QTableWidgetItem* aTableItem = aTable->item(row, 2);
1650   bool isComboItem = false;
1651   bool isIntSpinItem = false;
1652   bool isDoubleSpinItem = false;
1653   if (aTableItem) {
1654     int aTableType = aTable->item(row, 2)->type();
1655     isComboItem = ( aTableType == aComboType );
1656     isIntSpinItem = ( aTableType == aIntSpinType );
1657     isDoubleSpinItem = ( aTableType == aDoubleSpinType );
1658   }
1659   
1660   bool anIsDoubleCriterion =
1661     aCriterionType == SMESH::FT_AspectRatio ||
1662     aCriterionType == SMESH::FT_AspectRatio3D ||
1663     aCriterionType == SMESH::FT_Taper ||
1664     aCriterionType == SMESH::FT_Warping ||
1665     aCriterionType == SMESH::FT_MinimumAngle ||
1666     aCriterionType == SMESH::FT_Skew ||
1667     aCriterionType == SMESH::FT_Area ||
1668     aCriterionType == SMESH::FT_Length ||
1669     aCriterionType == SMESH::FT_Length2D ||
1670     aCriterionType == SMESH::FT_MaxElementLength2D ||
1671     aCriterionType == SMESH::FT_MaxElementLength3D ||
1672     aCriterionType == SMESH::FT_Volume3D;
1673
1674   int aPrecision = 0;
1675   if ( anIsDoubleCriterion ) {
1676     const char* aPrecisionType = getPrecision( aCriterionType );
1677     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1678     if( aPrecisionType && aResourceMgr )
1679       aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1680   }
1681
1682   // if the precision is to be changed we should remove the existing
1683   // spin item and create another one with new precision
1684   bool anIsPrecisionChanged = false;
1685   if ( anIsDoubleCriterion && isDoubleSpinItem ) {
1686     if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
1687       anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
1688     }
1689   }
1690
1691   if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1692        (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
1693        (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
1694        (!anIsDoubleCriterion && isDoubleSpinItem) ||
1695        anIsPrecisionChanged )
1696   {
1697     bool isSignalsBlocked = aTable->signalsBlocked();
1698     aTable->blockSignals( true );
1699     aTable->removeCellWidget( row, 2 );
1700     aTable->setItem( row, 2, new QTableWidgetItem() );
1701     aTable->blockSignals( isSignalsBlocked );
1702   }
1703   if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1704        (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
1705        (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
1706        (anIsDoubleCriterion && !isDoubleSpinItem) ||
1707        anIsPrecisionChanged )
1708   {
1709     bool isSignalsBlocked = aTable->signalsBlocked();
1710     aTable->blockSignals( true );
1711     if ( aCriterionType == SMESH::FT_GroupColor )
1712       aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1713     else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
1714       QList<int> typeIds = geomTypes( aType );
1715       QMap<int, QString> typeNames;
1716       QList<int>::const_iterator anIter = typeIds.begin();
1717       for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1718       {
1719         QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1720         typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1721       }
1722       ComboItem* typeBox = new ComboItem( typeNames );
1723       aTable->setItem( row, 2, typeBox );
1724     }
1725     else if ( aCriterionType == SMESH::FT_MultiConnection ) {
1726       IntSpinItem* intSpin = new IntSpinItem( 0 );
1727       aTable->setItem( row, 2, intSpin );
1728     }
1729     else if ( anIsDoubleCriterion ) {
1730       DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1731       dblSpin->setPrecision( aPrecision );
1732       aTable->setItem( row, 2, dblSpin );
1733     }
1734     aTable->blockSignals( isSignalsBlocked );
1735   }
1736
1737   if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes               ||
1738                                 aCriterionType == SMESH::FT_EqualNodes ))           ||
1739       (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders             ||
1740                                 aCriterionType == SMESH::FT_EqualEdges ))           ||
1741       (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace          ||
1742                                 aCriterionType == SMESH::FT_OverConstrainedFace     ||
1743                                 aCriterionType == SMESH::FT_FreeEdges               ||
1744                                 aCriterionType == SMESH::FT_FreeFaces               ||
1745                                 aCriterionType == SMESH::FT_EqualFaces))            ||
1746       (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume     ||
1747                                   aCriterionType == SMESH::FT_OverConstrainedVolume ||
1748                                   aCriterionType == SMESH::FT_BareBorderVolume      ||
1749                                   aCriterionType == SMESH::FT_EqualVolumes ))       ||
1750       aCriterionType == SMESH::FT_LinearOrQuadratic ||
1751       aCriterionType == SMESH::FT_GroupColor ||
1752       aCriterionType == SMESH::FT_ElemGeomType ||
1753       aCriterionType == SMESH::FT_CoplanarFaces
1754       )
1755   {
1756     bool isSignalsBlocked = aTable->signalsBlocked();
1757     aTable->blockSignals( true );
1758
1759     if (aCompareItem->count() > 0)
1760       aCompareItem->clear();
1761     aTable->setEditable(false, row, 1);
1762     aTable->item(row, 2)->setText( QString("") );
1763     aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1764                         aCriterionType == SMESH::FT_ElemGeomType ||
1765                         aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
1766     aTable->blockSignals( isSignalsBlocked );
1767   }
1768   else if (aCriterionType == SMESH::FT_RangeOfIds ||
1769            aCriterionType == SMESH::FT_BelongToGeom ||
1770            aCriterionType == SMESH::FT_BelongToPlane ||
1771            aCriterionType == SMESH::FT_BelongToCylinder ||
1772            aCriterionType == SMESH::FT_BelongToGenSurface ||
1773            aCriterionType == SMESH::FT_LyingOnGeom)
1774   {
1775     QMap<int, QString> aMap;
1776     aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1777     aCompareItem->setItems(aMap);
1778     if (!aTable->isEditable(row, 2))
1779       aTable->setEditable(true, row, 1);
1780     if (!aTable->isEditable(row, 2))
1781       aTable->setEditable(true, row, 2);
1782   }
1783   else if (aCriterionType == SMESH::FT_GroupColor ||
1784            aCriterionType == SMESH::FT_ElemGeomType)
1785   {
1786     if (!aTable->isEditable(row, 2))
1787       aTable->setEditable(true, row, 2);
1788   }
1789   else
1790   {
1791     if (aCompareItem && aCompareItem->count() != 3)
1792     {
1793       aCompareItem->setItems(getCompare());
1794     }
1795
1796     if (aTable->item( row, 2 )) {
1797       QString aText = aTable->text(row, 2);
1798       bool isOk = false;
1799       aText.toDouble(&isOk);
1800       aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1801       if (!aTable->isEditable(row, 1))
1802         aTable->setEditable(true, row, 1);
1803       if (!aTable->isEditable(row, 2))
1804         aTable->setEditable(true, row, 2);
1805     }
1806   }
1807
1808   updateAdditionalWidget();
1809
1810   emit CriterionChanged(row, entityType);
1811 }
1812
1813 //=======================================================================
1814 // name    : SMESHGUI_FilterTable::onCriterionChanged()
1815 // Purpose : SLOT. Called then contents of table changed
1816 //           Provides reaction on change of criterion
1817 //=======================================================================
1818 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1819 {
1820   if( col == 0 )
1821     onCriterionChanged(row, col, -1);
1822 }
1823
1824 //=======================================================================
1825 // name    : SMESHGUI_FilterTable::getFirstSelectedRow
1826 // Purpose : Get first selected row
1827 //=======================================================================
1828 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1829 {
1830   Table* aTable = myTables[ GetType() ];
1831
1832   QList<int> selRows = aTable->selectedRows(); // already sorted
1833   int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1834
1835   return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1836 }
1837
1838 //=======================================================================
1839 // name    : SMESHGUI_FilterTable::addRow
1840 // Purpose : Add row at the end of table
1841 //=======================================================================
1842 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1843 {
1844   int aCurrRow = 0;
1845   int aSelectedRow = getFirstSelectedRow();
1846   int aCurrCol = theTable->currentColumn();
1847
1848   myIsLocked = true;
1849   if (toTheEnd || aSelectedRow == -1)
1850   {
1851     theTable->insertRows(theTable->rowCount());
1852     aCurrRow = theTable->rowCount() - 1;
1853   }
1854   else
1855   {
1856     theTable->insertRows(aSelectedRow);
1857     aCurrRow = aSelectedRow;
1858   }
1859   myIsLocked = false;
1860
1861   // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1862   bool isSignalsBlocked = theTable->signalsBlocked();
1863   theTable->blockSignals( true );
1864
1865   // Criteria
1866   theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1867
1868   // Compare
1869   theTable->setItem(aCurrRow, 1, getCompareItem());
1870
1871   // Threshold
1872   theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1873
1874   // Logical operation NOT
1875   theTable->setItem(aCurrRow, 3, getUnaryItem());
1876
1877   // Logical operation AND / OR
1878   theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1879
1880   theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1881     
1882   theTable->blockSignals( isSignalsBlocked );
1883
1884   // Logical binary operation for previous value
1885   int anAddBinOpStr = -1;
1886   if (aCurrRow == theTable->rowCount() - 1)
1887     anAddBinOpStr = aCurrRow - 1;
1888   else if (aCurrRow >= 0 )
1889     anAddBinOpStr = aCurrRow;
1890
1891   if (theTable->item(aCurrRow, 4) == 0 ||
1892        theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1893   {
1894     if (anAddBinOpStr >= 0 &&
1895          (theTable->item(anAddBinOpStr, 4) == 0 ||
1896            theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1897       theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1898   }
1899
1900   theTable->setEditable(false, theTable->rowCount() - 1, 4);
1901   
1902   if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1903        aCurrCol >=0 && aCurrCol < theTable->rowCount())
1904   theTable->setCurrentCell(aCurrRow, aCurrCol);
1905
1906   onCriterionChanged(aCurrRow, 0);
1907
1908   updateBtnState();
1909 }
1910
1911 //=======================================================================
1912 // name    : SMESHGUI_FilterTable::getCriterionItem
1913 // Purpose : Get combo table item for criteria of specified type
1914 //=======================================================================
1915 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1916 {
1917   return new ComboItem(getCriteria(theType));
1918 }
1919
1920 //=======================================================================
1921 // name    : SMESHGUI_FilterTable::getCompareItem
1922 // Purpose : Get combo table item for operation of comparision
1923 //=======================================================================
1924 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1925 {
1926   return new ComboItem(getCompare());
1927 }
1928
1929 //=======================================================================
1930 // name    : SMESHGUI_FilterTable::getBinaryItem
1931 // Purpose :
1932 //=======================================================================
1933 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1934 {
1935   static QMap<int, QString> aMap;
1936   if (aMap.isEmpty())
1937   {
1938     aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1939     aMap[ SMESH::FT_LogicalOR  ] = tr("OR");
1940   }
1941
1942   return new ComboItem(aMap);
1943 }
1944
1945 //=======================================================================
1946 // name    : SMESHGUI_FilterTable::getUnaryItem
1947 // Purpose : Get check table item
1948 //=======================================================================
1949 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1950 {
1951   return new CheckItem(tr("NOT"));
1952 }
1953
1954 //=======================================================================
1955 // name    : SMESHGUI_FilterTable::getSupportedTypes
1956 // Purpose : Get all supported type
1957 //=======================================================================
1958 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1959 {
1960   static QMap<int, QString> aTypes;
1961   if (aTypes.isEmpty())
1962   {
1963     aTypes[ SMESH::NODE   ] = tr("NODES");
1964     aTypes[ SMESH::EDGE   ] = tr("EDGES");
1965     aTypes[ SMESH::FACE   ] = tr("FACES");
1966     aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1967     aTypes[ SMESH::ALL ]    = tr("ELEMENTS");
1968   }
1969
1970   return aTypes;
1971 }
1972
1973 //=======================================================================
1974 // name    : SMESHGUI_FilterTable::getCriteria
1975 // Purpose : Get criteria for specified type
1976 //=======================================================================
1977 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1978 {
1979   if (theType == SMESH::NODE)
1980   {
1981     static QMap<int, QString> aCriteria;
1982     if (aCriteria.isEmpty())
1983     {
1984       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
1985       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
1986       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
1987       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
1988       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1989       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
1990       aCriteria[ SMESH::FT_FreeNodes          ] = tr("FREE_NODES");
1991       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
1992       aCriteria[ SMESH::FT_EqualNodes         ] = tr("EQUAL_NODE");
1993     }
1994     return aCriteria;
1995   }
1996   else if (theType == SMESH::EDGE)
1997   {
1998     static QMap<int, QString> aCriteria;
1999     if (aCriteria.isEmpty())
2000     {
2001       aCriteria[ SMESH::FT_FreeBorders        ] = tr("FREE_BORDERS");
2002       aCriteria[ SMESH::FT_MultiConnection    ] = tr("MULTI_BORDERS");
2003       aCriteria[ SMESH::FT_Length             ] = tr("LENGTH");
2004       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
2005       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
2006       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
2007       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
2008       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2009       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
2010       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
2011       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
2012       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
2013       aCriteria[ SMESH::FT_EqualEdges         ] = tr("EQUAL_EDGE");
2014     }
2015     return aCriteria;
2016   }
2017   else if (theType == SMESH::FACE)
2018   {
2019     static QMap<int, QString> aCriteria;
2020     if (aCriteria.isEmpty())
2021     {
2022       aCriteria[ SMESH::FT_AspectRatio        ] = tr("ASPECT_RATIO");
2023       aCriteria[ SMESH::FT_Warping            ] = tr("WARPING");
2024       aCriteria[ SMESH::FT_MinimumAngle       ] = tr("MINIMUM_ANGLE");
2025       aCriteria[ SMESH::FT_Taper              ] = tr("TAPER");
2026       aCriteria[ SMESH::FT_Skew               ] = tr("SKEW");
2027       aCriteria[ SMESH::FT_Area               ] = tr("AREA");
2028       aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2029       aCriteria[ SMESH::FT_FreeEdges          ] = tr("FREE_EDGES");
2030       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
2031       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
2032       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
2033       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
2034       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2035       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
2036       aCriteria[ SMESH::FT_Length2D           ] = tr("LENGTH2D");
2037       aCriteria[ SMESH::FT_MultiConnection2D  ] = tr("MULTI2D_BORDERS");
2038       aCriteria[ SMESH::FT_FreeFaces          ] = tr("FREE_FACES");
2039       aCriteria[ SMESH::FT_BareBorderFace     ] = tr("BARE_BORDER_FACE");
2040       aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2041       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
2042       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
2043       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
2044       aCriteria[ SMESH::FT_CoplanarFaces      ] = tr("COPLANAR_FACES");
2045       aCriteria[ SMESH::FT_EqualFaces         ] = tr("EQUAL_FACE");
2046     }
2047     return aCriteria;
2048   }
2049   else if (theType == SMESH::VOLUME)
2050   {
2051     static QMap<int, QString> aCriteria;
2052     if (aCriteria.isEmpty())
2053     {
2054       aCriteria[ SMESH::FT_AspectRatio3D        ] = tr("ASPECT_RATIO_3D");
2055       aCriteria[ SMESH::FT_RangeOfIds           ] = tr("RANGE_OF_IDS");
2056       aCriteria[ SMESH::FT_BelongToGeom         ] = tr("BELONG_TO_GEOM");
2057       aCriteria[ SMESH::FT_LyingOnGeom          ] = tr("LYING_ON_GEOM");
2058       aCriteria[ SMESH::FT_BadOrientedVolume    ] = tr("BAD_ORIENTED_VOLUME");
2059       aCriteria[ SMESH::FT_BareBorderVolume     ] = tr("BARE_BORDER_VOLUME");
2060       aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2061       aCriteria[ SMESH::FT_Volume3D             ] = tr("VOLUME_3D");
2062       aCriteria[ SMESH::FT_MaxElementLength3D   ] = tr("MAX_ELEMENT_LENGTH_3D");
2063       aCriteria[ SMESH::FT_LinearOrQuadratic    ] = tr("LINEAR");
2064       aCriteria[ SMESH::FT_GroupColor           ] = tr("GROUP_COLOR");
2065       aCriteria[ SMESH::FT_ElemGeomType         ] = tr("GEOM_TYPE");
2066       aCriteria[ SMESH::FT_EqualVolumes         ] = tr("EQUAL_VOLUME");
2067     }
2068     return aCriteria;
2069   }
2070   else // SMESH::ALL
2071   {
2072     static QMap<int, QString> aCriteria;
2073     if (aCriteria.isEmpty())
2074     {
2075       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
2076       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
2077       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
2078       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
2079       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
2080       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
2081     }
2082
2083     return aCriteria;
2084   }
2085 }
2086
2087
2088 //=======================================================================
2089 // name    : SMESHGUI_FilterTable::getCompare
2090 // Purpose : Get operation of comparison
2091 //=======================================================================
2092 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2093 {
2094   static QMap<int, QString> aMap;
2095
2096   if (aMap.isEmpty())
2097   {
2098     aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2099     aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2100     aMap[ SMESH::FT_EqualTo  ] = tr("EQUAL_TO" );
2101   }
2102
2103   return aMap;
2104 }
2105
2106 //=======================================================================
2107 // name    : SMESHGUI_FilterTable::createTable
2108 // Purpose : Create table
2109 //=======================================================================
2110 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget*  theParent,
2111                                                                 const int theType)
2112 {
2113   // create table
2114   Table* aTable= new Table(0, 6, theParent);
2115
2116   QHeaderView* aHeaders = aTable->horizontalHeader();
2117
2118   QFontMetrics aMetrics(aHeaders->font());
2119
2120   // append spaces to the header of criteria in order to
2121   // provide visibility of criterion inside comboboxes
2122   static int aMaxLenCr = 0;
2123
2124   if (aMaxLenCr == 0)
2125   {
2126     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2127     QMap<int, QString>::const_iterator anIter;
2128     for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2129       aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2130   }
2131
2132   static int aLenCr = qAbs( aMaxLenCr -
2133                             aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2134
2135   QString aCrStr;
2136   aCrStr.fill(' ', aLenCr);
2137   QString aCoStr;
2138   aCoStr.fill(' ', 10);
2139
2140   QStringList aHeaderLabels;
2141   aHeaderLabels.append( tr("CRITERION") + aCrStr );
2142   aHeaderLabels.append( tr("COMPARE")   + aCoStr );
2143   aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2144   aHeaderLabels.append( tr("UNARY") );
2145   aHeaderLabels.append( tr("BINARY") + "  " );
2146   aHeaderLabels.append( tr("ID") );
2147   aTable->setHorizontalHeaderLabels( aHeaderLabels );
2148   
2149   // set geometry of the table
2150   for (int i = 0; i <= 4; i++)
2151     aTable->resizeColumnToContents(i);
2152
2153   // set the ID column invisible
2154   aTable->hideColumn( 5 );
2155
2156   aTable->updateGeometry();
2157   QSize aSize = aTable->sizeHint();
2158   int aWidth = aSize.width();
2159   aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2160   aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2161
2162   connect(aTable, SIGNAL(cellChanged(int, int)),
2163           this,   SLOT(onCriterionChanged(int, int)));
2164
2165   connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2166           this,   SLOT(onCurrentChanged(int, int)));
2167   
2168   return aTable;
2169 }
2170
2171 //=======================================================================
2172 // name    : SMESHGUI_FilterTable::updateBtnState
2173 // Purpose : Update button state
2174 //=======================================================================
2175 void SMESHGUI_FilterTable::updateBtnState()
2176 {
2177   myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2178   myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2179 }
2180
2181 //=======================================================================
2182 // name    : SMESHGUI_FilterTable::SetEditable
2183 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2184 //=======================================================================
2185 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2186 {
2187   TableMap::iterator anIter;
2188   for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2189   {
2190     anIter.value()->setReadOnly(!isEditable);
2191
2192     // Set Flags for CheckItems directly IPAL 19974
2193     Table* aTable = anIter.value();
2194     for (int i = 0, n = aTable->rowCount(); i < n; i++)
2195       for (int j = 0, m = aTable->columnCount(); j < m; j++)
2196         {
2197           QTableWidgetItem* anItem = aTable->item(i, j);
2198           if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2199             Qt::ItemFlags f = anItem->flags();
2200             if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2201             else f = f | Qt::ItemIsUserCheckable;
2202             anItem->setFlags( f );
2203           }
2204         }
2205     //end of IPAL19974
2206
2207     if (isEditable)
2208     {
2209       myAddBtn->show();
2210       myInsertBtn->show();
2211       myRemoveBtn->show();
2212       myClearBtn->show();
2213     }
2214     else
2215     {
2216       myAddBtn->hide();
2217       myInsertBtn->hide();
2218       myRemoveBtn->hide();
2219       myClearBtn->hide();
2220     }
2221   }
2222
2223   QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2224   for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2225     anIter2.value()->SetEditable(isEditable);
2226 }
2227
2228 //=======================================================================
2229 // name    : SMESHGUI_FilterTable::SetEnabled
2230 // Purpose : Enable/Disable table. Switching type of elements already enabled
2231 //=======================================================================
2232 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2233 {
2234   myAddBtn->setEnabled(isEnabled);
2235   myInsertBtn->setEnabled(isEnabled);
2236   myRemoveBtn->setEnabled(isEnabled);
2237   myClearBtn->setEnabled(isEnabled);
2238
2239   if (isEnabled)
2240     updateBtnState();
2241
2242   QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2243   for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2244     anIter2.value()->setEnabled(isEnabled);
2245 }
2246
2247 //=======================================================================
2248 // name    : SMESHGUI_FilterTable::IsEditable
2249 // Purpose : Verify whether table is editable
2250 //=======================================================================
2251 bool SMESHGUI_FilterTable::IsEditable() const
2252 {
2253   return !myTables[ GetType() ]->isReadOnly();
2254 }
2255
2256 //=======================================================================
2257 // name    : SMESHGUI_FilterTable::SetLibsEnabled
2258 // Purpose : Show/hide buttons for work with libraries
2259 //=======================================================================
2260 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2261 {
2262   if (isEnabled)
2263   {
2264     myCopyFromBtn->show();
2265     myAddToBtn->show();
2266   }
2267   else
2268   {
2269     myCopyFromBtn->hide();
2270     myAddToBtn->hide();
2271   }
2272 }
2273
2274 //=======================================================================
2275 // name    : SMESHGUI_FilterTable::onCopyFromBtn
2276 // Purpose : SLOT. Called the "Copy from ..." button clicked
2277 //           Display filter library dialog
2278 //=======================================================================
2279 void SMESHGUI_FilterTable::onCopyFromBtn()
2280 {
2281   if (myLibDlg == 0)
2282     myLibDlg = new SMESHGUI_FilterLibraryDlg(
2283       mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2284   else
2285     myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2286
2287   if (myLibDlg->exec() == QDialog::Accepted)
2288   {
2289     Copy(myLibDlg->GetTable());
2290     Update();
2291   }
2292 }
2293
2294 //=======================================================================
2295 // name    : SMESHGUI_FilterTable::onAddToBtn
2296 // Purpose : SLOT. Called the "Add to ..." button clicked
2297 //           Display filter library dialog
2298 //=======================================================================
2299 void SMESHGUI_FilterTable::onAddToBtn()
2300 {
2301   if (!IsValid(true))
2302     return;
2303   if (myLibDlg == 0)
2304     myLibDlg = new SMESHGUI_FilterLibraryDlg(
2305       mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2306   else
2307     myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2308
2309   myLibDlg->SetTable(this);
2310
2311   myLibDlg->exec();
2312 }
2313
2314 //=======================================================================
2315 // name    : SMESHGUI_FilterTable::Copy
2316 // Purpose : Initialise table with values of other table
2317 //=======================================================================
2318 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2319 {
2320   Clear();
2321
2322   for (int i = 0, n = theTable->NumRows(); i < n; i++)
2323   {
2324     SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2325     theTable->GetCriterion(i, aCriterion);
2326     AddCriterion(aCriterion);
2327   }
2328 }
2329
2330 //=======================================================================
2331 // name    : SMESHGUI_FilterTable::CurrentCell
2332 // Purpose : Returns current cell
2333 //=======================================================================
2334 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2335 {
2336   theRow = myTables[ GetType() ]->currentRow();
2337   theCol = myTables[ GetType() ]->currentColumn();
2338   return theRow >= 0 && theCol >= 0;
2339 }
2340
2341 //=======================================================================
2342 // name    : SMESHGUI_FilterTable::SetText
2343 // Purpose : Set text and internal value in cell of threshold value
2344 //=======================================================================
2345 void SMESHGUI_FilterTable::SetThreshold (const int      theRow,
2346                                          const QString& theText,
2347                                          const int      theEntityType)
2348 {
2349   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2350   aTable->item( theRow, 2 )->setText(theText);
2351 }
2352
2353 //=======================================================================
2354 // name    : SMESHGUI_FilterTable::SetText
2355 // Purpose : Get text and internal value from cell of threshold value
2356 //=======================================================================
2357 bool SMESHGUI_FilterTable::GetThreshold (const int      theRow,
2358                                          QString&       theText,
2359                                          const int      theEntityType)
2360 {
2361   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2362   QTableWidgetItem* anItem = aTable->item(theRow, 2);
2363   if (anItem != 0)
2364   {
2365     theText = anItem->text();
2366     return true;
2367   }
2368   else
2369    return false;
2370 }
2371
2372 //=======================================================================
2373 // name    : SMESHGUI_FilterTable::SetID
2374 // Purpose : Set text and internal value in cell of ID value 
2375 //=======================================================================
2376 void SMESHGUI_FilterTable::SetID( const int      theRow,
2377                                   const QString& theText,
2378                                   const int      theEntityType )
2379 {
2380   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2381   aTable->item( theRow, 5 )->setText( theText );
2382 }
2383
2384 //=======================================================================
2385 // name    : SMESHGUI_FilterTable::GetID
2386 // Purpose : Get text and internal value from cell of ID value
2387 //=======================================================================
2388 bool SMESHGUI_FilterTable::GetID( const int      theRow,
2389                                   QString&       theText,
2390                                   const int      theEntityType )
2391 {
2392   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2393   QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2394   if ( anItem != 0 )
2395     {
2396       theText = anItem->text();
2397       return true;    
2398     }
2399   else
2400     return false;
2401
2402
2403 /*
2404   Class       : SMESHGUI_FilterDlg
2405   Description : Dialog to specify filters for VTK viewer
2406 */
2407
2408
2409 //=======================================================================
2410 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2411 // Purpose : Constructor
2412 //=======================================================================
2413 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI*         theModule,
2414                                         const QList<int>& theTypes )
2415 : QDialog( SMESH::GetDesktop( theModule ) ),
2416   mySMESHGUI( theModule ),
2417   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2418   myInitSourceWgOnApply( true )
2419 {
2420   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2421     mySelector = aViewWindow->GetSelector();
2422
2423   construct(theTypes);
2424 }
2425
2426 //=======================================================================
2427 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2428 // Purpose : Constructor
2429 //=======================================================================
2430 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI*   theModule,
2431                                         const int   theType )
2432 : QDialog( SMESH::GetDesktop( theModule ) ),
2433   mySMESHGUI( theModule ),
2434   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2435   myInitSourceWgOnApply( true )
2436 {
2437   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2438     mySelector = aViewWindow->GetSelector();
2439   QList<int> aTypes;
2440   aTypes.append(theType);
2441   construct(aTypes);
2442 }
2443
2444 //=======================================================================
2445 // name    : SMESHGUI_FilterDlg::construct
2446 // Purpose : Construct dialog (called by constructor)
2447 //=======================================================================
2448 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2449 {
2450   myTypes = theTypes;
2451
2452   setModal(false);
2453   //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2454   setWindowTitle(tr("CAPTION"));
2455
2456   QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2457   aDlgLay->setMargin(MARGIN);
2458   aDlgLay->setSpacing(SPACING);
2459
2460   myMainFrame         = createMainFrame  (this);
2461   QWidget* aBtnFrame  = createButtonFrame(this);
2462
2463   aDlgLay->addWidget(myMainFrame);
2464   aDlgLay->addWidget(aBtnFrame);
2465
2466   aDlgLay->setStretchFactor(myMainFrame, 1);
2467
2468   myHelpFileName = "selection_filter_library_page.html";
2469
2470   Init(myTypes);
2471 }
2472
2473 //=======================================================================
2474 // name    : SMESHGUI_FilterDlg::createMainFrame
2475 // Purpose : Create frame containing dialog's input fields
2476 //=======================================================================
2477 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2478 {
2479   QWidget* aMainFrame = new QWidget(theParent);
2480   QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2481   aMainLay->setMargin(0);
2482   aMainLay->setSpacing(SPACING);
2483
2484   // filter frame
2485
2486   myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2487   myTable->SetLibsEnabled(true);
2488
2489   QGroupBox* aGrp = myTable->GetTableGrp();
2490   QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2491   int rows = aLay->rowCount();
2492   int cols = aLay->columnCount();
2493
2494   QFrame* aLine = new QFrame(aGrp);
2495   aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2496   aLay->addWidget(aLine, rows++, 0, 1, cols);
2497
2498   mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2499   mySetInViewer->setChecked(true);
2500   aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2501
2502   // other controls
2503   QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2504
2505   connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2506                     SLOT(onCriterionChanged(const int, const int)));
2507
2508   connect(myTable, SIGNAL(CurrentChanged(int, int)),
2509                     SLOT(onCurrentChanged(int, int)));
2510
2511   aMainLay->addWidget(myTable);
2512   aMainLay->addWidget(aSourceGrp);
2513   
2514   return aMainFrame;
2515 }
2516
2517 //=======================================================================
2518 // name    : SMESHGUI_FilterDlg::createSourceFrame
2519 // Purpose : Create frame containing source radio button
2520 //=======================================================================
2521 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2522 {
2523   QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2524   QHBoxLayout* aLay = new QHBoxLayout(aBox);
2525   aLay->setMargin(MARGIN);
2526   aLay->setSpacing(SPACING);
2527
2528   mySourceGrp = new QButtonGroup(theParent);
2529
2530   QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"),          aBox);
2531   QRadioButton* aSelBtn  = new QRadioButton(tr("SELECTION"),     aBox);
2532   QRadioButton* aDlgBtn  = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2533
2534   aLay->addWidget(aMeshBtn);
2535   aLay->addWidget(aSelBtn);
2536   aLay->addWidget(aDlgBtn);
2537
2538   mySourceGrp->addButton(aMeshBtn, Mesh);
2539   mySourceGrp->addButton(aSelBtn,  Selection);
2540   mySourceGrp->addButton(aDlgBtn,  Dialog);
2541
2542   aMeshBtn->setChecked(true);
2543
2544   return aBox;
2545 }
2546
2547 //=======================================================================
2548 // name    : SMESHGUI_FilterDlg::updateMainButtons
2549 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2550 //=======================================================================
2551 void SMESHGUI_FilterDlg::updateMainButtons()
2552 {
2553   myButtons[ BTN_Close  ]->show();
2554   if (myTypes.count() == 1)
2555   {
2556     myButtons[ BTN_Apply  ]->hide();
2557   }
2558   else
2559   {
2560     myButtons[ BTN_Apply  ]->show();
2561   }
2562 //  updateGeometry();
2563 }
2564
2565 //=======================================================================
2566 // name    : SMESHGUI_FilterDlg::createButtonFrame
2567 // Purpose : Create frame containing buttons
2568 //=======================================================================
2569 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2570 {
2571   QGroupBox* aGrp = new QGroupBox(theParent);
2572   QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2573   aLay->setMargin(MARGIN);
2574   aLay->setSpacing(SPACING);
2575
2576   myButtons[ BTN_OK     ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2577   myButtons[ BTN_Apply  ] = new QPushButton(tr("SMESH_BUT_APPLY"),           aGrp);
2578   myButtons[ BTN_Close  ] = new QPushButton(tr("SMESH_BUT_CLOSE"),           aGrp);
2579   myButtons[ BTN_Help   ] = new QPushButton(tr("SMESH_BUT_HELP"),            aGrp);
2580
2581   aLay->addWidget(myButtons[ BTN_OK     ]);
2582   aLay->addSpacing(10);
2583   aLay->addWidget(myButtons[ BTN_Apply  ]);
2584   aLay->addSpacing(10);
2585   aLay->addStretch();
2586   aLay->addWidget(myButtons[ BTN_Close  ]);
2587   aLay->addWidget(myButtons[ BTN_Help   ]);
2588
2589   connect(myButtons[ BTN_OK     ], SIGNAL(clicked()), SLOT(onOk()));
2590   connect(myButtons[ BTN_Close  ], SIGNAL(clicked()), SLOT(onClose()));
2591   connect(myButtons[ BTN_Apply  ], SIGNAL(clicked()), SLOT(onApply()));
2592   connect(myButtons[ BTN_Help   ], SIGNAL(clicked()), SLOT(onHelp()));
2593
2594   updateMainButtons();
2595
2596   return aGrp;
2597 }
2598
2599 //=======================================================================
2600 // name    : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2601 // Purpose : Destructor
2602 //=======================================================================
2603 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2604 {
2605 }
2606
2607 //=======================================================================
2608 // name    : SMESHGUI_FilterDlg::Init
2609 // Purpose : Init dialog fields, connect signals and slots, show dialog
2610 //=======================================================================
2611 void SMESHGUI_FilterDlg::Init (const int type)
2612 {
2613   QList<int> aTypes;
2614   aTypes.append(type);
2615   Init(aTypes);
2616 }
2617
2618 //=======================================================================
2619 // name    : SMESHGUI_FilterDlg::Init
2620 // Purpose : Init dialog fields, connect signals and slots, show dialog
2621 //=======================================================================
2622 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2623 {
2624   mySourceWg  = 0;
2625   myTypes     = theTypes;
2626   myMesh      = SMESH::SMESH_Mesh::_nil();
2627   myIObjects.Clear();
2628   myIsSelectionChanged = false;
2629
2630   myTable->Init(theTypes);
2631
2632   // set caption
2633   if (theTypes.count() == 1)
2634   {
2635     int aType = theTypes.first();
2636     if      (aType == SMESH::NODE  ) setWindowTitle(tr("NODES_TLT"));
2637     else if (aType == SMESH::EDGE  ) setWindowTitle(tr("EDGES_TLT"));
2638     else if (aType == SMESH::FACE  ) setWindowTitle(tr("FACES_TLT"));
2639     else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2640     else if (aType == SMESH::ALL)    setWindowTitle(tr("TLT"));
2641   }
2642   else
2643     setWindowTitle(tr("TLT"));
2644
2645   qApp->processEvents();
2646   updateGeometry();
2647   adjustSize();
2648   setEnabled(true);
2649
2650   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2651
2652   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2653   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2654   
2655   updateMainButtons();
2656   updateSelection();
2657
2658   // Initialise filter table with values of previous filter
2659   QList<int>::const_iterator anIter;
2660   for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2661   {
2662     myTable->Clear(*anIter);
2663     if (!myFilter[ *anIter ]->_is_nil())
2664     {
2665       SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2666       if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2667       {
2668         for (int i = 0, n = aCriteria->length(); i < n; i++)
2669           myTable->AddCriterion(aCriteria[ i ], *anIter);
2670       }
2671     }
2672   }
2673
2674   if (myInsertState.contains(theTypes.first()))
2675     mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2676   else
2677     mySetInViewer->setChecked(true);
2678
2679   mySourceGrp->button(myApplyToState.contains(theTypes.first()) ? 
2680                       myApplyToState[ theTypes.first() ] :
2681                       Mesh)->setChecked(true);
2682 }
2683
2684 //=======================================================================
2685 // name    : SMESHGUI_FilterDlg::onOk
2686 // Purpose : SLOT called when "Ok" button pressed.
2687 //           Assign filters VTK viewer and close dialog
2688 //=======================================================================
2689 void SMESHGUI_FilterDlg::onOk()
2690 {
2691   if (onApply())
2692   {
2693     mySelectionMgr->clearFilters();
2694     disconnect(mySMESHGUI, 0, this, 0);
2695     disconnect(mySelectionMgr, 0, this, 0);
2696     mySMESHGUI->ResetState();
2697     accept();
2698     emit Accepted();
2699   }
2700 }
2701
2702 //=======================================================================
2703 // name    : SMESHGUI_FilterDlg::onClose
2704 // Purpose : SLOT called when "Close" button pressed. Close dialog
2705 //=======================================================================
2706 void SMESHGUI_FilterDlg::onClose()
2707 {
2708   // Restore previously selected object
2709   if (mySelectionMgr)
2710   {
2711     SALOME_ListIO aList;
2712     mySelectionMgr->clearFilters();
2713     mySelectionMgr->clearSelected();
2714     SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2715     for ( ; anIter.More(); anIter.Next())
2716     {
2717       aList.Append(anIter.Key());
2718
2719       TColStd_MapOfInteger aResMap;
2720       const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2721       for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2722         aResMap.Add(anIndMap(i));
2723
2724       mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2725       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2726         aViewWindow->highlight( anIter.Key(), true, true );
2727     }
2728     mySelectionMgr->setSelectedObjects(aList, false);
2729   }
2730
2731   disconnect(mySMESHGUI, 0, this, 0);
2732   disconnect(mySelectionMgr, 0, this, 0);
2733   mySMESHGUI->ResetState();
2734   reject();
2735   return;
2736 }
2737
2738 //=================================================================================
2739 // function : onHelp()
2740 // purpose  :
2741 //=================================================================================
2742 void SMESHGUI_FilterDlg::onHelp()
2743 {
2744   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2745   if (app) 
2746     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2747   else {
2748     QString platform;
2749 #ifdef WIN32
2750     platform = "winapplication";
2751 #else
2752     platform = "application";
2753 #endif
2754     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2755                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2756                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
2757                                                                  platform)).
2758                              arg(myHelpFileName));
2759   }
2760 }
2761
2762 //=======================================================================
2763 // name    : SMESHGUI_FilterDlg::onDeactivate
2764 // Purpose : SLOT called when dialog must be deativated
2765 //=======================================================================
2766 void SMESHGUI_FilterDlg::onDeactivate()
2767 {
2768   setEnabled(false);
2769 }
2770
2771 //=======================================================================
2772 // name    : SMESHGUI_FilterDlg::enterEvent
2773 // Purpose : Event filter
2774 //=======================================================================
2775 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2776 {
2777 //  mySMESHGUI->EmitSignalDeactivateDialog();
2778   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2779   mySMESHGUI->ResetState();
2780   setEnabled(true);
2781 }
2782
2783 //=======================================================================
2784 // name    : closeEvent()
2785 // Purpose :
2786 //=======================================================================
2787 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2788 {
2789   onClose();
2790 }
2791
2792 //=======================================================================
2793 // name    : SMESHGUI_FilterDlg::getIdsFromWg
2794 // Purpose : Retrieve list of ids from given widget
2795 //=======================================================================
2796 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2797 {
2798   theRes.clear();
2799   if (theWg == 0)
2800     return;
2801
2802   if (theWg->inherits("QListWidget"))
2803   {
2804     const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2805     bool b;
2806     for (int i = 0, n = aListBox->count(); i < n; i++)
2807     {
2808       int anId = aListBox->item(i)->text().toInt(&b);
2809       if (b)
2810         theRes.append(anId);
2811     }
2812   }
2813   else if (theWg->inherits("QLineEdit"))
2814   {
2815     const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2816     QString aStr = aLineEdit->text();
2817     QRegExp aRegExp("(\\d+)");
2818     bool b;
2819     int aPos = 0;
2820     while (aPos >= 0)
2821     {
2822       aPos = aRegExp.indexIn(aStr, aPos);
2823       if (aPos > -1)
2824       {
2825         int anId = aRegExp.cap(1).toInt(&b);
2826         if (b)
2827           theRes.append(anId);
2828         aPos += aRegExp.matchedLength();
2829       }
2830     }
2831   }
2832 }
2833
2834 //=======================================================================
2835 // name    : SMESHGUI_FilterDlg::getSelMode
2836 // Purpose : Get selection mode of specified type
2837 //=======================================================================
2838 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2839 {
2840   switch (theType)
2841   {
2842     case SMESH::NODE   : return NodeSelection;
2843     case SMESH::EDGE   : return EdgeSelection;
2844     case SMESH::FACE   : return FaceSelection;
2845     case SMESH::VOLUME : return VolumeSelection;
2846     case SMESH::ALL    : return CellSelection;
2847     default            : return ActorSelection;
2848   }
2849
2850 }
2851
2852 //=======================================================================
2853 // name    : SMESHGUI_FilterDlg::setIdsToWg
2854 // Purpose : Insert identifiers in specified widgets
2855 //=======================================================================
2856 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2857 {
2858   if (theWg == 0)
2859     return;
2860
2861   QStringList aStrList;
2862   foreach(int id, theIds)
2863     aStrList << QString::number(id);
2864
2865   if (theWg->inherits("QListWidget"))
2866   {
2867     qobject_cast<QListWidget*>(theWg)->clear();
2868     qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2869   }
2870   else if (theWg->inherits("QLineEdit"))
2871   {
2872     qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2873   }
2874 }
2875
2876 //=======================================================================
2877 // name    : SMESHGUI_FilterDlg::isValid
2878 // Purpose : Verify validity of input data
2879 //=======================================================================
2880 bool SMESHGUI_FilterDlg::isValid() const
2881 {
2882   if (!myTable->IsValid())
2883     return false;
2884
2885   for (int i = 0, n = myTable->NumRows(); i < n; i++)
2886   {
2887     int aType = myTable->GetCriterionType(i);
2888     if (aType == SMESH::FT_BelongToGeom ||
2889         aType == SMESH::FT_BelongToPlane ||
2890         aType == SMESH::FT_BelongToCylinder ||
2891         aType == SMESH::FT_BelongToGenSurface ||
2892         aType == SMESH::FT_LyingOnGeom)
2893     {
2894       QString aName;
2895       myTable->GetThreshold(i, aName);
2896
2897       std::vector<_PTR(SObject)> aList =
2898         SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2899       if (aList.size() == 0) {
2900         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2901                                      tr("BAD_SHAPE_NAME").arg(aName));
2902         return false;
2903       }
2904
2905       if (aType == SMESH::FT_BelongToCylinder ||
2906           aType == SMESH::FT_BelongToPlane    ||
2907           aType == SMESH::FT_BelongToGenSurface ) {
2908         CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2909         //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2910         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2911         if (!aGeomObj->_is_nil()) {
2912           TopoDS_Shape aFace;
2913           if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2914                aFace.IsNull() ||
2915                aFace.ShapeType() != TopAbs_FACE) {
2916             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2917                                          tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2918             return false;
2919           }
2920
2921           Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2922           if (aSurf.IsNull()) {
2923             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2924                                          tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2925             return false;
2926           }
2927
2928           if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2929             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2930                                          tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2931             return false;
2932           }
2933
2934           if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2935             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2936                                          tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2937             return false;
2938           }
2939         }
2940       }
2941     }
2942     else if (aType == SMESH::FT_CoplanarFaces)
2943     {
2944       QString faceID;
2945       myTable->GetThreshold(i, faceID);
2946       if ( faceID.isEmpty() )
2947       {
2948         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2949                                      tr("FACE_ID_NOT_SELECTED"));
2950         return false;
2951       }
2952       if ( myMesh->_is_nil() )
2953       {
2954         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2955                                      tr("MESH_IS_NOT_SELECTED"));
2956         return false;
2957       }
2958       if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
2959       {
2960         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2961                                      tr("NOT_FACE_ID").arg(faceID));
2962         return false;
2963       }
2964     }
2965   }
2966
2967   return true;
2968 }
2969
2970 //=======================================================================
2971 // name    : SMESHGUI_FilterDlg::SetSourceWg
2972 // Purpose : Set widget of parent dialog containing idsto be filtered if
2973 //           user select corresponding source radio button
2974 //=======================================================================
2975 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
2976                                       const bool initOnApply)
2977 {
2978   mySourceWg = theWg;
2979   myInitSourceWgOnApply = initOnApply;
2980 }
2981
2982 //=======================================================================
2983 // name    : SMESHGUI_FilterDlg::SetMesh
2984 // Purpose : Set mesh
2985 //=======================================================================
2986 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2987 {
2988   if ( !theMesh->_is_nil() ) {
2989     myMesh = theMesh;
2990     if ( !myFilter[ myTable->GetType() ]->_is_nil())
2991       myFilter[ myTable->GetType() ]->SetMesh( theMesh );
2992   }
2993   const bool isEnable = !(myMesh->_is_nil());
2994   myButtons[BTN_OK]->setEnabled(isEnable);
2995   myButtons[BTN_Apply]->setEnabled(isEnable);
2996 }
2997
2998 //=======================================================================
2999 // name    : SMESHGUI_FilterDlg::SetSelection
3000 // Purpose : Get filtered ids
3001 //=======================================================================
3002 void SMESHGUI_FilterDlg::SetSelection()
3003 {
3004   if (mySelectionMgr)
3005     disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3006
3007   if (mySelectionMgr) {
3008     myIObjects.Clear();
3009     const SALOME_ListIO& anObjs = mySelector->StoredIObjects(); 
3010     SALOME_ListIteratorOfListIO anIter (anObjs);
3011     for ( ; anIter.More(); anIter.Next()) {
3012       TColStd_IndexedMapOfInteger aMap;
3013       mySelector->GetIndex(anIter.Value(), aMap);
3014       myIObjects.Bind(anIter.Value(), aMap);
3015     }
3016
3017     connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3018
3019     updateSelection();
3020   }
3021   else
3022     myIObjects.Clear();
3023 }
3024
3025 //=======================================================================
3026 // name    : SMESHGUI_FilterDlg::onApply
3027 // Purpose : SLOT called when "Apply" button pressed.
3028 //           Assign filters to VTK viewer
3029 //=======================================================================
3030 bool SMESHGUI_FilterDlg::onApply()
3031 {
3032   if (!isValid())
3033     return false;
3034
3035   try {
3036     int aCurrType = myTable->GetType();
3037
3038     if (!createFilter(aCurrType))
3039       return false;
3040
3041     insertFilterInViewer();
3042
3043     if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3044       QList<int> aResultIds;
3045       filterSource(aCurrType, aResultIds);
3046       // select in viewer
3047       selectInViewer(aCurrType, aResultIds);
3048     }
3049
3050
3051     myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3052     myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3053   }
3054   catch(const SALOME::SALOME_Exception& S_ex)
3055   {
3056     SalomeApp_Tools::QtCatchCorbaException(S_ex);
3057   }
3058   catch(...)
3059   {
3060   }
3061
3062   return true;
3063 }
3064
3065 //=======================================================================
3066 // name    : SMESHGUI_FilterDlg::createFilter
3067 // Purpose : Create predicate for given type
3068 //=======================================================================
3069 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3070 {
3071   SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3072   if (aFilterMgr->_is_nil())
3073     return false;
3074
3075   int n = myTable->NumRows();
3076
3077   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3078   aCriteria->length(n);
3079
3080   long aPrecision = -1;
3081   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3082
3083   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3084     aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3085
3086   for (CORBA::ULong i = 0; i < n; i++) {
3087     SMESH::Filter::Criterion aCriterion = createCriterion();
3088     myTable->GetCriterion(i, aCriterion);
3089     aCriterion.Precision = aPrecision;
3090     aCriteria[ i ] = aCriterion;
3091   }
3092
3093   myFilter[ theType ] = aFilterMgr->CreateFilter();
3094   myFilter[ theType ]->SetCriteria(aCriteria.inout());
3095
3096   return true;
3097 }
3098
3099 //================================================================================
3100 /*!
3101  * \brief Return the current filter
3102  */
3103 //================================================================================
3104
3105 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3106 {
3107   SMESH::Filter_var filter;
3108   try {
3109     int aCurrType = myTable->GetType();
3110     filter = myFilter[ aCurrType ];
3111   }
3112   catch(...)
3113   {
3114   }
3115   return filter._retn();
3116 }
3117
3118 //================================================================================
3119 /*!
3120  * \brief Sets a filter to the table
3121  */
3122 //================================================================================
3123
3124 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3125 {
3126   myFilter[ type ] = filter;
3127 }
3128
3129 //=======================================================================
3130 // name    : SMESHGUI_FilterDlg::insertFilterInViewer
3131 // Purpose : Insert filter in viewer
3132 //=======================================================================
3133 void SMESHGUI_FilterDlg::insertFilterInViewer()
3134 {
3135   if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3136     SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3137
3138     if (myFilter[ myTable->GetType() ]->_is_nil() ||
3139          myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3140          !mySetInViewer->isChecked()) {
3141       SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3142     }
3143     else {
3144       Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3145       aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3146       SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3147       SMESH::SetFilter(aFilter, aSelector);
3148     }
3149   }
3150 }
3151
3152 //=======================================================================
3153 // name    : SMESHGUI_FilterDlg::filterSource
3154 // Purpose : Filter source ids
3155 //=======================================================================
3156 void SMESHGUI_FilterDlg::filterSource (const int theType,
3157                                        QList<int>& theResIds)
3158 {
3159   theResIds.clear();
3160   if (myFilter[ theType ]->_is_nil())
3161     return;
3162
3163   int aSourceId = mySourceGrp->checkedId();
3164
3165   if (aSourceId == Mesh)
3166   {
3167     if (myMesh->_is_nil())
3168       return;
3169     SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3170     for (int i = 0, n = anIds->length(); i < n; i++)
3171       theResIds.append(anIds[ i ]);
3172   }
3173   else if (aSourceId == Selection)
3174   {
3175     filterSelectionSource(theType, theResIds);
3176   }
3177   else if (aSourceId == Dialog)
3178   {
3179     // retrieve ids from dialog
3180     QList<int> aDialogIds;
3181     getIdsFromWg(mySourceWg, aDialogIds);
3182
3183     if (myMesh->_is_nil())
3184     {
3185       theResIds = aDialogIds;
3186       return;
3187     }
3188
3189     // filter ids
3190     SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3191     myFilter[ theType ]->SetMesh(myMesh);
3192     QList<int>::const_iterator anIter;
3193     for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3194       if (aPred->IsSatisfy(*anIter))
3195         theResIds.append(*anIter);
3196   }
3197   // set ids to the dialog
3198   if (myInitSourceWgOnApply || aSourceId == Dialog)
3199     setIdsToWg(mySourceWg, theResIds);
3200 }
3201
3202 //=======================================================================
3203 // name    : SMESHGUI_FilterDlg::filterSelectionSource
3204 // Purpose : Filter source selection
3205 //=======================================================================
3206 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3207                                                 QList<int>& theResIds)
3208 {
3209   theResIds.clear();
3210   if (myMesh->_is_nil() || mySelectionMgr == 0)
3211     return;
3212
3213   // Create map of entities to be filtered
3214   TColStd_MapOfInteger aToBeFiltered;
3215   SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3216
3217   for ( ; anIter.More(); anIter.Next())
3218   {
3219     // process sub mesh
3220     SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3221     if (!aSubMesh->_is_nil())
3222     {
3223       if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3224       {
3225         SMESH::long_array_var anIds =
3226           theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3227         for (int i = 0, n = anIds->length(); i < n; i++)
3228           aToBeFiltered.Add(anIds[ i ]);
3229       }
3230     }
3231
3232     // process group
3233     SMESH::SMESH_GroupBase_var aGroup =
3234       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3235     if (!aGroup->_is_nil())
3236     {
3237       if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3238       {
3239         SMESH::long_array_var anIds = aGroup->GetListOfID();
3240         for (int i = 0, n = anIds->length(); i < n; i++)
3241           aToBeFiltered.Add(anIds[ i ]);
3242       }
3243     }
3244
3245     // process mesh
3246     SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3247     if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3248     {
3249       const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3250
3251       if (aSelMap.Extent() > 0)
3252       {
3253         if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3254         {
3255           for (int i = 1; i <= aSelMap.Extent(); i++)
3256             aToBeFiltered.Add(aSelMap(i));
3257         }
3258       }
3259     }
3260   }
3261
3262   // Filter entities
3263   SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3264   myFilter[ theType ]->SetMesh(myMesh);
3265   TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3266   for ( ; aResIter.More(); aResIter.Next())
3267     if (aPred->IsSatisfy(aResIter.Key()))
3268       theResIds.append(aResIter.Key());
3269 }
3270
3271 //=======================================================================
3272 // name    : SMESHGUI_FilterDlg::selectInViewer
3273 // Purpose : Select given entities in viewer
3274 //=======================================================================
3275 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3276 {
3277   if (mySelectionMgr == 0 || myMesh->_is_nil())
3278     return;
3279
3280   mySelectionMgr->clearFilters();
3281
3282   // Set new selection mode if necessary
3283   Selection_Mode aSelMode = getSelMode(theType);
3284   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3285   if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3286     mySelectionMgr->clearSelected();
3287     mySelectionMgr->clearFilters();
3288     if (aSelMode == NodeSelection)
3289       SMESH::SetPointRepresentation(true);
3290     aViewWindow->SetSelectionMode(aSelMode);
3291   }
3292
3293   // Clear selection
3294   SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3295   if (!anActor || !anActor->hasIO())
3296     return;
3297
3298   Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3299   //mySelectionMgr->clearSelected();
3300   //mySelectionMgr->AddIObject(anIO, false);
3301   SALOME_ListIO aList;
3302   aList.Append(anIO);
3303   mySelectionMgr->setSelectedObjects(aList, false);
3304
3305   // Remove filter corresponding to the current type from viewer
3306   int aType = myTable->GetType();
3307   int aFilterId = SMESH::UnknownFilter;
3308   if      (aType == SMESH::EDGE  ) aFilterId = SMESH::EdgeFilter;
3309   else if (aType == SMESH::FACE  ) aFilterId = SMESH::FaceFilter;
3310   else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3311   Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3312   SMESH::RemoveFilter(aFilterId);
3313
3314   // get vtk ids
3315   TColStd_MapOfInteger aMap;
3316   QList<int>::const_iterator anIter;
3317   for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3318     aMap.Add(*anIter);
3319   }
3320
3321   // Set new selection
3322   mySelector->AddOrRemoveIndex(anIO, aMap, false);
3323   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3324     aViewWindow->highlight( anIO, true, true );
3325
3326   // insert previously stored filter in viewer if necessary
3327   if (!aFilter.IsNull())
3328     SMESH::SetFilter(aFilter);
3329 }
3330
3331 //=======================================================================
3332 // name    : SMESHGUI_FilterDlg::createCriterion
3333 // Purpose : Create criterion structure with default values
3334 //=======================================================================
3335 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3336 {
3337    SMESH::Filter::Criterion aCriterion;
3338
3339   aCriterion.Type          = SMESH::FT_Undefined;
3340   aCriterion.Compare       = SMESH::FT_Undefined;
3341   aCriterion.Threshold     = 0;
3342   aCriterion.UnaryOp       = SMESH::FT_Undefined;
3343   aCriterion.BinaryOp      = SMESH::FT_Undefined;
3344   aCriterion.ThresholdStr  = "";
3345   aCriterion.ThresholdID   = "";
3346   aCriterion.TypeOfElement = SMESH::ALL;
3347
3348   return aCriterion;
3349 }
3350
3351 //=======================================================================
3352 // name    : SMESHGUI_FilterDlg::onSelectionDone
3353 // Purpose : SLOT called when selection changed.
3354 //           If current cell corresponds to the threshold value of
3355 //           BelongToGeom criterion name of selected object is set in this cell
3356 //=======================================================================
3357 void SMESHGUI_FilterDlg::onSelectionDone()
3358 {
3359   int aRow, aCol;
3360   const SALOME_ListIO& aList = mySelector->StoredIObjects();
3361
3362   if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3363     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3364     if ( !(myMesh->_is_nil()) ) {
3365       myButtons[BTN_OK]->setEnabled(true);
3366       myButtons[BTN_Apply]->setEnabled(true);
3367     }
3368   }
3369
3370   QList<int> types; 
3371   types << SMESH::FT_BelongToGeom     << SMESH::FT_BelongToPlane 
3372         << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3373         << SMESH::FT_LyingOnGeom      << SMESH::FT_CoplanarFaces;
3374   if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) || 
3375       !types.contains(myTable->GetCriterionType(aRow)))
3376     return;
3377
3378   if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
3379   {
3380     QString aString;
3381     int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
3382                                                    aList.First(), aString);
3383     if (nbElems == 1)
3384       myTable->SetThreshold(aRow, aString);
3385   }
3386   else
3387   {
3388     Handle(SALOME_InteractiveObject) anIO = aList.First();
3389     GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3390     if (!anObj->_is_nil())
3391     {
3392       myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3393       //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3394       myTable->SetID(aRow, anIO->getEntry());
3395     }
3396   }
3397 }
3398
3399
3400 //=======================================================================
3401 // name    : SMESHGUI_FilterDlg::onCriterionChanged
3402 // Purpose : SLOT called when cretarion of current row changed. Update selection
3403 //=======================================================================
3404 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3405 {
3406   updateSelection();
3407 }
3408
3409 //=======================================================================
3410 // name    : SMESHGUI_FilterDlg::onCurrentChanged
3411 // Purpose : SLOT called when current row changed. Update selection
3412 //=======================================================================
3413 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3414 {
3415   updateSelection();
3416 }
3417
3418 //=======================================================================
3419 // name    : SMESHGUI_FilterDlg::updateSelection
3420 // Purpose : UpdateSelection in accordance with current row
3421 //=======================================================================
3422 void SMESHGUI_FilterDlg::updateSelection()
3423 {
3424   if (mySelectionMgr == 0)
3425     return;
3426
3427 //   TColStd_MapOfInteger allTypes;
3428 //   for( int i=0; i<10; i++ )
3429 //     allTypes.Add( i );
3430   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3431   if( !aStudy )
3432     return;
3433
3434
3435   mySelectionMgr->clearFilters();
3436
3437   int aRow, aCol;
3438   
3439   bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3440   int aCriterionType = myTable->GetCriterionType(aRow);
3441   if ( isCurrentCell &&
3442       (aCriterionType == SMESH::FT_BelongToGeom ||
3443        aCriterionType == SMESH::FT_BelongToPlane ||
3444        aCriterionType == SMESH::FT_BelongToCylinder ||
3445        aCriterionType == SMESH::FT_BelongToGenSurface ||
3446        aCriterionType == SMESH::FT_LyingOnGeom))
3447   {
3448     if (aCriterionType == SMESH::FT_BelongToGeom ||
3449         aCriterionType == SMESH::FT_BelongToGenSurface ||
3450         aCriterionType == SMESH::FT_LyingOnGeom) {
3451
3452       mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3453
3454     } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3455       mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3456
3457     } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3458       mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3459     }
3460     myIsSelectionChanged = true;
3461
3462   }
3463   else
3464   {
3465     if (myIsSelectionChanged) {
3466       // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3467       // Impossible to select any object in the OB on the second opening of FilterDlg
3468     }
3469   }
3470 }
3471
3472 //=================================================================================
3473 // function : keyPressEvent()
3474 // purpose  :
3475 //=================================================================================
3476 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3477 {
3478   QDialog::keyPressEvent( e );
3479   if ( e->isAccepted() )
3480     return;
3481
3482   if ( e->key() == Qt::Key_F1 ) {
3483     e->accept();
3484     onHelp();
3485   }
3486 }