Back to index

salome-smesh  6.5.0
SMESHGUI_FilterDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // SMESH SMESHGUI : GUI for SMESH component
00024 // File   : SMESHGUI_FilterDlg.cxx
00025 // Author : Sergey LITONIN, Open CASCADE S.A.S.
00026 // SMESH includes
00027 //
00028 #include "SMESHGUI_FilterDlg.h"
00029 
00030 #include "SMESHGUI.h"
00031 #include "SMESHGUI_Utils.h"
00032 #include "SMESHGUI_VTKUtils.h"
00033 #include "SMESHGUI_Filter.h"
00034 #include "SMESHGUI_FilterUtils.h"
00035 #include "SMESHGUI_FilterLibraryDlg.h"
00036 #include "SMESHGUI_SpinBox.h"
00037 
00038 #include <SMESH_Actor.h>
00039 #include <SMESH_NumberFilter.hxx>
00040 #include <SMESH_TypeFilter.hxx>
00041 
00042 // SALOME GEOM includes
00043 #include <GEOMBase.h>
00044 #include <GEOM_FaceFilter.h>
00045 #include <GEOM_TypeFilter.h>
00046 
00047 // SALOME GUI includes
00048 #include <SUIT_Desktop.h>
00049 #include <SUIT_ResourceMgr.h>
00050 #include <SUIT_Session.h>
00051 #include <SUIT_MessageBox.h>
00052 #include <QtxColorButton.h>
00053 
00054 #include <LightApp_Application.h>
00055 #include <LightApp_SelectionMgr.h>
00056 #include <SalomeApp_Tools.h>
00057 #include <SalomeApp_Study.h>
00058 #include <SalomeApp_IntSpinBox.h>
00059 #include <SalomeApp_DoubleSpinBox.h>
00060 
00061 #include <SALOME_ListIO.hxx>
00062 #include <SALOME_ListIteratorOfListIO.hxx>
00063 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
00064 
00065 #include <SVTK_ViewWindow.h>
00066 
00067 // SALOME KERNEL includes
00068 #include <SALOMEDSClient_Study.hxx>
00069 
00070 // OCCT includes
00071 #include <StdSelect_TypeOfFace.hxx>
00072 #include <BRep_Tool.hxx>
00073 #include <TopoDS.hxx>
00074 #include <TopoDS_Shape.hxx>
00075 #include <Geom_Plane.hxx>
00076 #include <Geom_CylindricalSurface.hxx>
00077 #include <Precision.hxx>
00078 #include <TColStd_MapOfInteger.hxx>
00079 #include <TColStd_IndexedMapOfInteger.hxx>
00080 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
00081 
00082 // Qt includes
00083 #include <QFrame>
00084 #include <QLineEdit>
00085 #include <QPushButton>
00086 #include <QGroupBox>
00087 #include <QTableWidget>
00088 #include <QStringList>
00089 #include <QHBoxLayout>
00090 #include <QVBoxLayout>
00091 #include <QGridLayout>
00092 #include <QStackedWidget>
00093 #include <QApplication>
00094 #include <QComboBox>
00095 #include <QFontMetrics>
00096 #include <QLabel>
00097 #include <QButtonGroup>
00098 #include <QRadioButton>
00099 #include <QRegExp>
00100 #include <QListWidget>
00101 #include <QCheckBox>
00102 #include <QItemDelegate>
00103 #include <QDoubleValidator>
00104 #include <QKeyEvent>
00105 #include <QHeaderView>
00106 
00107 // IDL includes
00108 #include <SALOMEconfig.h>
00109 #include CORBA_SERVER_HEADER(SMESH_Group)
00110 
00111 #define SPACING 6
00112 #define MARGIN  11
00113 
00114 //---------------------------------------
00115 // maxLength
00116 //---------------------------------------
00117 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
00118 {
00119   int aRes = 0;
00120   QMap<int, QString>::const_iterator anIter;
00121   for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
00122     aRes = qMax(aRes, theMetrics.width(anIter.value()));
00123   return aRes;
00124 }
00125 
00126 //---------------------------------------
00127 // getFilterId
00128 //---------------------------------------
00129 static int getFilterId (SMESH::ElementType theType)
00130 {
00131   switch (theType)
00132   {
00133     case SMESH::NODE   : return SMESH::NodeFilter;
00134     case SMESH::EDGE   : return SMESH::EdgeFilter;
00135     case SMESH::FACE   : return SMESH::FaceFilter;
00136     case SMESH::VOLUME : return SMESH::VolumeFilter;
00137     case SMESH::ALL    : return SMESH::AllElementsFilter;
00138     default            : return SMESH::UnknownFilter;
00139   }
00140 }
00141 
00142 /*
00143   Class       : SMESHGUI_FilterTable::AdditionalWidget
00144   Description : Class for storing additional parameters of criterion
00145 */
00146 
00147 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
00148 {
00149 public:
00150   enum { Tolerance };
00151 
00152 public:
00153   AdditionalWidget(QWidget* theParent);
00154   virtual ~AdditionalWidget();
00155 
00156   virtual QList<int>      GetParameters() const;
00157   virtual bool            IsValid(const bool = true) const;
00158   virtual double          GetDouble(const int) const;
00159   virtual int             GetInteger(const int) const;
00160   virtual QString         GetString(const int) const;
00161   virtual void            SetDouble(const int, const double);
00162   virtual void            SetInteger(const int, const int);
00163   virtual void            SetString(const int, const QString&);
00164   void                    SetEditable(const int, const bool);
00165   void                    SetEditable(const bool);
00166   void                    SetPrecision(const int, const char* = 0);
00167 
00168 private:
00169   QMap< int, QWidget* > myWidgets;
00170 };
00171 
00172 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
00173   : QWidget(theParent)
00174 {
00175   QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
00176 
00177   SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
00178   sb->setAcceptNames( false ); // No Notebook variables allowed
00179   sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
00180   sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
00181   myWidgets[ Tolerance ] = sb;
00182 
00183   QHBoxLayout* aLay = new QHBoxLayout(this);
00184   aLay->setSpacing(SPACING);
00185   aLay->setMargin(0);
00186 
00187   aLay->addWidget(aLabel);
00188   aLay->addWidget(myWidgets[ Tolerance ]);
00189   aLay->addStretch();
00190 
00191   SetDouble( Tolerance, Precision::Confusion() );
00192 }
00193 
00194 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
00195 {
00196 }
00197 
00198 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
00199 {
00200   QList<int> theList;
00201   theList.append(Tolerance);
00202   return theList;
00203 }
00204 
00205 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
00206 {
00207   if (!isEnabled())
00208     return true;
00209 
00210   QList<int> aParams = GetParameters();
00211   QList<int>::const_iterator anIter;
00212   for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
00213     if ( !myWidgets.contains( *anIter ) ) continue;
00214     bool valid = true;
00215     if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
00216       valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
00217     }
00218     else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
00219       QString foo;
00220       valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
00221     }
00222     if (!valid && theMsg) {
00223       SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
00224                                    tr("SMESHGUI_INVALID_PARAMETERS"));
00225       return false;
00226     }
00227   }
00228 
00229   return true;
00230 }
00231 
00232 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
00233 {
00234   double retval = 0;
00235   if ( myWidgets.contains( theId ) ) {
00236     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00237       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
00238     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00239       retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
00240   }
00241   return retval;
00242 }
00243 
00244 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
00245 {
00246   int retval = 0;
00247   if ( myWidgets.contains( theId ) ) {
00248     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00249       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
00250     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00251       retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
00252   }
00253   return retval;
00254 }
00255 
00256 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
00257 {
00258   QString retval = "";
00259   if ( myWidgets.contains( theId ) ) {
00260     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00261       retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
00262     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00263       retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
00264   }
00265   return retval;
00266 }
00267 
00268 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
00269 {
00270   if ( myWidgets.contains( theId ) ) {
00271     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00272       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
00273     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00274       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
00275   }
00276 }
00277 
00278 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
00279 {
00280   if ( myWidgets.contains( theId ) ) {
00281     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00282       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
00283     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00284       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
00285   }
00286 }
00287 
00288 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
00289 {
00290   if ( myWidgets.contains( theId ) ) {
00291     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00292       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
00293     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00294       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
00295   }
00296 }
00297 
00298 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
00299 {
00300   if ( myWidgets.contains( theId ) ) {
00301     if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
00302       qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
00303     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
00304       qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
00305   }
00306 }
00307 
00308 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
00309 {
00310   QList<int> aParams = GetParameters();
00311   QList<int>::const_iterator anIter;
00312   for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
00313     SetEditable( *anIter,  isEditable );
00314 }
00315 
00316 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
00317 {
00318   if ( myWidgets.contains( theId ) ) {
00319     if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
00320       SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
00321       double val = sb->GetValue();
00322       double min = pow(10.0, -(sb->decimals()));
00323       sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
00324       sb->SetValue( qMax( val, min ) );
00325     }
00326   }
00327 }
00328 
00329 /*
00330   Class       : SMESHGUI_FilterTable::ComboItem
00331   Description : Combo table item. Identificator corresponding to string may be assigned
00332 */
00333 
00334 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
00335 {
00336 public:
00337   static int     Type();
00338 
00339   ComboItem( const QMap<int, QString>& );
00340 
00341   void           setItems( const QMap<int, QString>& );
00342   void           clear();
00343   int            count() const;
00344 
00345   int            value() const;
00346   void           setValue( const int );
00347 
00348 private:
00349   int            id( int ) const;
00350   int            index( int ) const;
00351 
00352 private:
00353   QMap<int, int> myIdToIdx;
00354 };
00355 
00356 int SMESHGUI_FilterTable::ComboItem::Type()
00357 {
00358   return QTableWidgetItem::UserType + 1;
00359 }
00360 
00361 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
00362  : QTableWidgetItem( Type() )
00363 {
00364   setItems( theIds );
00365 }
00366 
00367 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
00368 {
00369   myIdToIdx.clear();
00370   QMap<int, QString>::const_iterator it;
00371   QStringList items;
00372   for ( it = theIds.begin(); it != theIds.end(); ++it ) {
00373     myIdToIdx[it.key()] = items.count();
00374     items.append( it.value() );
00375   }
00376   setData( Qt::UserRole, items );
00377   setValue( id( 0 ) ); 
00378 }
00379 
00380 void SMESHGUI_FilterTable::ComboItem::clear()
00381 {
00382   QMap<int, QString> empty;
00383   setItems( empty );
00384 }
00385 
00386 int SMESHGUI_FilterTable::ComboItem::count() const
00387 {
00388   return myIdToIdx.count();
00389 }
00390 
00391 int SMESHGUI_FilterTable::ComboItem::value() const
00392 {
00393   return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) ); 
00394 }
00395 
00396 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
00397 {
00398   int idx = index( theId );
00399   QStringList items = data( Qt::UserRole ).toStringList();
00400   setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
00401 }
00402 
00403 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
00404 {
00405   QMap<int,int>::const_iterator it;
00406   for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
00407     if ( it.value() == idx ) return it.key();
00408   return -1;
00409 }
00410 
00411 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
00412 {
00413   return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
00414 }
00415 /*
00416   Class       : SMESHGUI_FilterTable::CheckItem
00417   Description : Check table item.
00418 */
00419 
00420 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
00421 {
00422 public:
00423   static int     Type();
00424 
00425   CheckItem( bool = false );
00426   CheckItem( const QString&, bool = false );
00427   ~CheckItem();
00428 
00429   void  setChecked( bool );
00430   bool  checked() const;
00431 };
00432 
00433 int SMESHGUI_FilterTable::CheckItem::Type()
00434 {
00435   return QTableWidgetItem::UserType + 2;
00436 }
00437 
00438 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
00439  : QTableWidgetItem( Type() )
00440 {
00441   Qt::ItemFlags f = flags();
00442   f = f | Qt::ItemIsUserCheckable;
00443   f = f & ~Qt::ItemIsTristate;
00444   f = f & ~Qt::ItemIsEditable;
00445   setFlags( f );
00446   setChecked(value);
00447 }
00448 
00449 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
00450  : QTableWidgetItem( Type() )
00451 {
00452   Qt::ItemFlags f = flags();
00453   f = f | Qt::ItemIsUserCheckable;
00454   f = f & ~Qt::ItemIsTristate;
00455   f = f & ~Qt::ItemIsEditable;
00456   setFlags( f );
00457   setChecked( value );
00458   setText( text );
00459 }
00460 
00461 SMESHGUI_FilterTable::CheckItem::~CheckItem()
00462 {
00463 }
00464 
00465 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
00466 {
00467   setCheckState( value ? Qt::Checked : Qt::Unchecked );
00468 }
00469 
00470 bool SMESHGUI_FilterTable::CheckItem::checked() const
00471 {
00472   return checkState() == Qt::Checked;
00473 }
00474 
00475 /*
00476   Class       : SMESHGUI_FilterTable::IntSpinItem
00477   Description : Integer spin table item.
00478 */
00479 
00480 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
00481 {
00482 public:
00483   static int     Type();
00484 
00485   IntSpinItem( const int theValue );
00486 
00487   int            value() const;
00488   void           setValue( const int theValue );
00489 
00490   void           clear();
00491 };
00492 
00493 int SMESHGUI_FilterTable::IntSpinItem::Type()
00494 {
00495   return QTableWidgetItem::UserType + 3;
00496 }
00497 
00498 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
00499  : QTableWidgetItem( Type() )
00500 {
00501   setValue( theValue );
00502 }
00503 
00504 int SMESHGUI_FilterTable::IntSpinItem::value() const
00505 {
00506   bool ok = false;
00507   int value = data( Qt::UserRole ).toInt( &ok );
00508   return ok ? value : 0; 
00509 }
00510 
00511 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
00512 {
00513   setData( Qt::UserRole, theValue );
00514   setText( QString::number( theValue ) ); 
00515 }
00516 
00517 void SMESHGUI_FilterTable::IntSpinItem::clear()
00518 {
00519   setText( "" );
00520 }
00521 
00522 /*
00523   Class       : SMESHGUI_FilterTable::DoubleSpinItem
00524   Description : Double spin table item.
00525 */
00526 
00527 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
00528 {
00529 public:
00530   static int     Type();
00531 
00532   DoubleSpinItem( const double theValue );
00533 
00534   double         value() const;
00535   void           setValue( const double theValue );
00536 
00537   int            precision() const;
00538   void           setPrecision( const int thePrecision );
00539 
00540   void           clear();
00541 };
00542 
00543 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
00544 {
00545   return QTableWidgetItem::UserType + 4;
00546 }
00547 
00548 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
00549  : QTableWidgetItem( Type() )
00550 {
00551   setValue( theValue );
00552 }
00553 
00554 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
00555 {
00556   bool ok = false;
00557   double value = data( Qt::UserRole ).toDouble( &ok );
00558   return ok ? value : 0; 
00559 }
00560 
00561 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
00562 {
00563   setData( Qt::UserRole, theValue );
00564   setText( QString::number( theValue ) ); 
00565 }
00566 
00567 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
00568 {
00569   bool ok = false;
00570   int precision = data( Qt::UserRole + 1 ).toInt( &ok );
00571   return ok ? precision : 0; 
00572 }
00573 
00574 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
00575 {
00576   setData( Qt::UserRole + 1, thePrecision );
00577 }
00578 
00579 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
00580 {
00581   setText( "" );
00582 }
00583 
00584 /*
00585   Class       : SMESHGUI_FilterTable::ComboDelegate
00586   Description : Table used by this widget
00587 */
00588 
00589 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
00590 {
00591 public:
00592   ComboDelegate( QObject* = 0 );
00593   ~ComboDelegate();
00594   
00595   QWidget*      createEditor( QWidget*, const QStyleOptionViewItem&,
00596                               const QModelIndex& ) const;
00597   
00598   void          setEditorData( QWidget*, const QModelIndex& ) const;
00599   void          setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
00600   
00601   void          updateEditorGeometry( QWidget*, const QStyleOptionViewItem&, 
00602                                       const QModelIndex& ) const;
00603 private:
00604   QTableWidget* myTable;
00605 };
00606 
00607 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
00608   : QItemDelegate( parent ), 
00609     myTable( qobject_cast<QTableWidget*>( parent ) )
00610 {
00611 }
00612   
00613 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
00614 {
00615 }
00616 
00617 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
00618                                                             const QStyleOptionViewItem& option,
00619                                                             const QModelIndex& index ) const
00620 {
00621   QVariant aData = index.data( Qt::UserRole );
00622   QVariant::Type aDataType = aData.type();
00623   if( aDataType == QVariant::StringList ) {
00624     QStringList l = aData.toStringList();
00625     if ( !l.isEmpty() ) {
00626       QComboBox* cb = new QComboBox( parent );
00627       cb->setFrame( false );
00628       cb->addItems( l );
00629       return cb;
00630     }
00631   }
00632   else if( aDataType == QVariant::Int ) {
00633     bool ok = false;
00634     int aValue = aData.toInt( &ok );
00635     if ( ok ) {
00636       SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
00637       intSpin->setFrame( false );
00638       intSpin->setValue( aValue );
00639       return intSpin;
00640     }
00641   }
00642   else if( aDataType == QVariant::Double ) {
00643     bool ok = false;
00644     double aValue = aData.toDouble( &ok );
00645     if ( ok ) {
00646       int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
00647       if ( !ok )
00648         aPrecision = 0;
00649 
00650       SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
00651       dblSpin->setFrame( false );
00652       dblSpin->setValue( aValue );
00653       return dblSpin;
00654     }
00655   }
00656   return QItemDelegate::createEditor( parent, option, index );
00657 }
00658 
00659 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor, 
00660                                                          const QModelIndex& index ) const
00661 {
00662   QVariant data = index.model()->data( index, Qt::DisplayRole );
00663   QString value = data.toString();
00664   bool bOk = false;
00665   if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
00666     int i = cb->findText( value );
00667     if ( i >= 0 ) {
00668       cb->setCurrentIndex( i );
00669       bOk = true;
00670     }
00671   }
00672   else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
00673     if( data.type() == QVariant::Double ) {
00674       double valueDouble = data.toDouble( &bOk );
00675       if( bOk )
00676         dblSpin->setValue( valueDouble );
00677     }
00678   }
00679   if ( !bOk ) QItemDelegate::setEditorData( editor, index );
00680 }
00681 
00682 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
00683                                                         QAbstractItemModel* model,
00684                                                         const QModelIndex& index) const
00685 {
00686   if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
00687     model->setData( index, cb->currentText(), Qt::DisplayRole );
00688   else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
00689     model->setData( index, intSpin->value(), Qt::DisplayRole );
00690   else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
00691     model->setData( index, dblSpin->value(), Qt::DisplayRole );
00692   else QItemDelegate::setModelData( editor, model, index );
00693 }
00694 
00695 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
00696                                                                 const QStyleOptionViewItem& option, 
00697                                                                 const QModelIndex& index ) const
00698 {
00699   editor->setGeometry( option.rect );
00700 }
00701 
00702 /*
00703   Class       : SMESHGUI_FilterTable::Table
00704   Description : Table used by this widget
00705 */
00706 
00707 class SMESHGUI_FilterTable::Table : public QTableWidget
00708 {
00709 public:
00710   Table( QWidget* = 0 );
00711   Table( int, int, QWidget* = 0 );
00712   virtual ~Table();
00713 
00714   QSize                   minimumSizeHint() const;
00715 
00716   void                    setEditable( bool, int, int );
00717   bool                    isEditable( int, int ) const;
00718 
00719   void                    setReadOnly( bool );
00720   bool                    isReadOnly() const;
00721 
00722   void                    insertRows( int, int = 1 );
00723   QString                 text( int, int );
00724 
00725   QList<int>              selectedRows();
00726 };
00727 
00728 //=======================================================================
00729 // name    : SMESHGUI_FilterTable::Table::Table
00730 // Purpose : Constructor
00731 //=======================================================================
00732 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
00733 : QTableWidget(parent)
00734 {
00735   // set custom item delegate
00736   setItemDelegate( new ComboDelegate(this) );
00737   // set edit triggers by default
00738   setReadOnly( false );
00739 }
00740 
00741 //=======================================================================
00742 // name    : SMESHGUI_FilterTable::Table::Table
00743 // Purpose : Constructor
00744 //=======================================================================
00745 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
00746 : QTableWidget(numRows, numCols, parent)
00747 {
00748   // set custom item delegate
00749   setItemDelegate( new ComboDelegate(this) );
00750   // set edit triggers by default
00751   setReadOnly( false );
00752 }
00753 
00754 //=======================================================================
00755 // name    : SMESHGUI_FilterTable::Table::~Table
00756 // Purpose : Destructor
00757 //=======================================================================
00758 SMESHGUI_FilterTable::Table::~Table()
00759 {
00760 }
00761 
00762 //=======================================================================
00763 // name    : SMESHGUI_FilterTable::Table::minimumSizeHint
00764 // Purpose : Get minimum size for the table
00765 //=======================================================================
00766 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
00767 {
00768   QSize s = QTableWidget::minimumSizeHint();
00769   QHeaderView* hv = horizontalHeader();
00770   if ( hv )
00771     s.setWidth( qMax( s.width(), hv->length() ) );
00772   return s;
00773 }
00774 
00775 //=======================================================================
00776 // name    : SMESHGUI_FilterTable::Table::setEditable
00777 // Purpose : Set editable of specified cell
00778 //=======================================================================
00779 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
00780                                                int row, int col)
00781 {
00782   QTableWidgetItem* anItem = item( row, col );
00783   if ( anItem ) {
00784     bool isSignalsBlocked = signalsBlocked();
00785     blockSignals( true );
00786 
00787     Qt::ItemFlags f = anItem->flags();
00788     if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
00789     else f = f | Qt::ItemIsEditable;
00790     anItem->setFlags( f );
00791     
00792     blockSignals( isSignalsBlocked );
00793   }
00794 }
00795 
00796 //=======================================================================
00797 // name    : SMESHGUI_FilterTable::Table::isEditable
00798 // Purpose : Verify wheter cell is editable
00799 //=======================================================================
00800 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
00801 {
00802   QTableWidgetItem* anItem = item( row, col );
00803   return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
00804 }
00805 
00806 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
00807 {
00808   setEditTriggers( on ? 
00809                    QAbstractItemView::NoEditTriggers  :
00810                    QAbstractItemView::AllEditTriggers );
00811 }
00812 
00813 bool SMESHGUI_FilterTable::Table::isReadOnly() const
00814 {
00815   return editTriggers() == QAbstractItemView::NoEditTriggers;
00816 }
00817 
00818 //=======================================================================
00819 // name    : SMESHGUI_FilterTable::Table::insertRows
00820 // Purpose : Insert rows (virtual redefined)
00821 //=======================================================================
00822 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
00823 {
00824   closePersistentEditor( currentItem() );
00825   while ( count-- ) insertRow( row );
00826 }
00827 
00828 //=======================================================================
00829 // name    : SMESHGUI_FilterTable::Table::text
00830 // Purpose : Get text from cell (virtual redefined)
00831 //=======================================================================
00832 QString SMESHGUI_FilterTable::Table::text (int row, int col)
00833 {
00834   closePersistentEditor( currentItem() );
00835   QTableWidgetItem* anItem = item( row, col );
00836   return anItem ? anItem->text() : QString();
00837 }
00838 
00839 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
00840 {
00841   QList<QTableWidgetItem*> selItems = selectedItems();
00842   QTableWidgetItem* anItem;
00843   QList<int> rows;
00844 
00845   foreach( anItem, selItems ) {
00846     int r = row( anItem );
00847     if ( !rows.contains( r ) ) rows.append( r );
00848   }
00849 
00850   qSort( rows );
00851   return rows;
00852 }
00853 
00854 /*
00855   Class       : SMESHGUI_FilterTable
00856   Description : Frame containig
00857                   - Button group for switching entity type
00858                   - Table for displaying filter criterions
00859                   - Buttons for editing table and filter libraries
00860 */
00861 
00862 //=======================================================================
00863 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
00864 // Purpose : Constructor
00865 //=======================================================================
00866 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
00867                                             QWidget* parent,
00868                                             const int type )
00869 : QWidget( parent ),
00870   myIsLocked( false ),
00871   mySMESHGUI( theModule )
00872 {
00873   myEntityType = -1;
00874 
00875   QList<int> aTypes;
00876   aTypes.append(type);
00877   Init(aTypes);
00878 }
00879 
00880 //=======================================================================
00881 // name    : SMESHGUI_FilterTable::SMESHGUI_FilterTable
00882 // Purpose : Constructor
00883 //=======================================================================
00884 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
00885                                             QWidget* parent,
00886                                             const QList<int>& types )
00887 : QWidget( parent ),
00888   myIsLocked( false ),
00889   mySMESHGUI( theModule )
00890 {
00891   myEntityType = -1;
00892   Init(types);
00893 }
00894 
00895 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
00896 {
00897 }
00898 
00899 //=======================================================================
00900 // name    : SMESHGUI_FilterTable::Init
00901 // Purpose : Create table corresponding to the specified type
00902 //=======================================================================
00903 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
00904 {
00905   if (theTypes.isEmpty())
00906     return;
00907 
00908   // Create buttons if necessary
00909 
00910   if (myTables.isEmpty())
00911   {
00912     // create main layout
00913     QVBoxLayout* aMainLay = new QVBoxLayout(this);
00914     aMainLay->setMargin( 0 );
00915     aMainLay->setSpacing( SPACING );
00916 
00917     // create switch of entity types
00918     myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
00919     QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
00920     myEntityTypeBoxLayout->setMargin( MARGIN );
00921     myEntityTypeBoxLayout->setSpacing( SPACING );
00922     myEntityTypeGrp = new QButtonGroup(this);
00923 
00924     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
00925     QMap<int, QString>::const_iterator anIter;
00926     for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
00927     {
00928       QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
00929       myEntityTypeGrp->addButton(aBtn, anIter.key());
00930       myEntityTypeBoxLayout->addWidget(aBtn);
00931     }
00932 
00933     myTableGrp = new QGroupBox(tr("FILTER"), this );
00934 
00935     // create table
00936     mySwitchTableGrp = new QWidget(myTableGrp);
00937     QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
00938     mySwitchTableGrpLayout->setMargin(0);
00939     mySwitchTableGrpLayout->setSpacing(0);
00940 
00941     QList<int>::const_iterator typeIt = theTypes.begin();
00942     for ( ; typeIt != theTypes.end(); ++typeIt ) {
00943       Table* aTable = createTable(mySwitchTableGrp, *typeIt);
00944       myTables[ *typeIt ] = aTable;
00945       mySwitchTableGrpLayout->addWidget(aTable);
00946       if ( typeIt != theTypes.begin() )
00947         aTable->hide();
00948     }
00949 
00950     // create buttons
00951     myAddBtn      = new QPushButton(tr("ADD"),       myTableGrp);
00952     myRemoveBtn   = new QPushButton(tr("REMOVE"),    myTableGrp);
00953     myClearBtn    = new QPushButton(tr("CLEAR"),     myTableGrp);
00954     myInsertBtn   = new QPushButton(tr("INSERT"),    myTableGrp);
00955     myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
00956     myAddToBtn    = new QPushButton(tr("ADD_TO"),    myTableGrp);
00957 
00958     myAddBtn->setAutoDefault(false);
00959     myRemoveBtn->setAutoDefault(false);
00960     myClearBtn->setAutoDefault(false);
00961     myInsertBtn->setAutoDefault(false);
00962     myCopyFromBtn->setAutoDefault(false);
00963     myAddToBtn->setAutoDefault(false);
00964 
00965     myCopyFromBtn->hide();
00966     myAddToBtn->hide();
00967 
00968     // layout widgets
00969     QGridLayout* aLay = new QGridLayout(myTableGrp);
00970     aLay->setMargin(MARGIN);
00971     aLay->setSpacing(SPACING);
00972 
00973     aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
00974     aLay->addWidget(myAddBtn,         0, 1);
00975     aLay->addWidget(myInsertBtn,      1, 1);
00976     aLay->addWidget(myRemoveBtn,      2, 1);
00977     aLay->addWidget(myClearBtn,       3, 1);
00978     aLay->addWidget(myCopyFromBtn,    5, 1);
00979     aLay->addWidget(myAddToBtn,       6, 1);
00980     aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
00981 
00982     aLay->setRowMinimumHeight(4, 10);
00983     aLay->setRowStretch(4, 1);
00984     aLay->setColumnStretch(0, 1);
00985     aLay->setColumnStretch(1, 0);
00986 
00987     // layout 
00988     aMainLay->addWidget(myEntityTypeBox);
00989     aMainLay->addWidget(myTableGrp);
00990     
00991     // signals and slots
00992     connect(myAddBtn,    SIGNAL(clicked()), this, SLOT(onAddBtn()));
00993     connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
00994     connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
00995     connect(myClearBtn,  SIGNAL(clicked()), this, SLOT(onClearBtn()));
00996 
00997     connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
00998     connect(myAddToBtn,    SIGNAL(clicked()), this, SLOT(onAddToBtn()));
00999 
01000     connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
01001 
01002     myLibDlg = 0;
01003   }
01004 
01005   // Hide buttons of entity types if necessary
01006   const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
01007   QMap<int, QString>::const_iterator anIt;
01008   for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
01009   {
01010     QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
01011     if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
01012   }
01013 
01014   // select first button if there is no selected buttons or it is hidden
01015   int aBtnId = myEntityTypeGrp->checkedId();
01016   if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
01017     QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
01018     if ( aBtn ) aBtn->setChecked(true);
01019   }
01020 
01021   myEntityTypeBox->setVisible(theTypes.count() > 1);
01022 
01023   myTableGrp->updateGeometry();
01024   int cType = myEntityTypeGrp->checkedId();
01025   onEntityType(cType);
01026 }
01027 
01028 //=======================================================================
01029 // name    : SMESHGUI_FilterTable::createAdditionalFrame
01030 // Purpose : Get group box containing table. May be used for adding new widgets in it
01031 //=======================================================================
01032 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
01033 {
01034   QWidget* aFrame = new QWidget(theParent);
01035 
01036   QFrame* aLine1 = new QFrame(aFrame);
01037   QFrame* aLine2 = new QFrame(aFrame);
01038   aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
01039   aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
01040   aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
01041   aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
01042 
01043   QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
01044 
01045   myWgStack = new QStackedWidget(aFrame);
01046 
01047   QGridLayout* aLay = new QGridLayout(aFrame);
01048   aLay->setMargin(0);
01049   aLay->setSpacing(SPACING);
01050   aLay->addWidget(aLine1,    0, 0);
01051   aLay->addWidget(aLabel,    0, 1);
01052   aLay->addWidget(aLine2,    0, 2);
01053   aLay->addWidget(myWgStack, 1, 0, 1, 3);
01054 
01055   return aFrame;
01056 }
01057 
01058 //=======================================================================
01059 // name    : SMESHGUI_FilterTable::GetTableGrp
01060 // Purpose : Get group box containing table. May be used for adding new widgets in it
01061 //=======================================================================
01062 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
01063 {
01064   return myTableGrp;
01065 }
01066 
01067 //=======================================================================
01068 // name    : SMESHGUI_FilterTable::onEntityType
01069 // Purpose : SLOT. Called when entity type changed.
01070 //           Display corresponding table
01071 //=======================================================================
01072 void SMESHGUI_FilterTable::onEntityType (int theType)
01073 {
01074   if (myEntityType == theType)
01075     return;
01076 
01077   myIsValid = true;
01078   emit NeedValidation();
01079   if (!myIsValid)
01080   {
01081     myEntityTypeGrp->button(myEntityType)->setChecked(true);
01082     return;
01083   }
01084 
01085   myEntityType = theType;
01086 
01087   if (!myTables.contains(theType)) {
01088     myTables[ theType ] = createTable(mySwitchTableGrp, theType);
01089     ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
01090   }
01091 
01092   TableMap::iterator anIter;
01093   for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
01094      anIter.value()->setVisible( myEntityType == anIter.key() );
01095 
01096   updateBtnState();
01097   qApp->processEvents();
01098   myTables[ myEntityType ]->updateGeometry();
01099   adjustSize();
01100 
01101   emit EntityTypeChanged(theType);
01102 }
01103 
01104 //=======================================================================
01105 // name    : SMESHGUI_FilterTable::IsValid
01106 // Purpose : Verify validity of entered data
01107 //=======================================================================
01108 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
01109 {
01110   int aType = theEntityType == -1 ? GetType() : theEntityType;
01111 
01112   Table* aTable = myTables[ aType ];
01113   for (int i = 0, n = aTable->rowCount(); i < n; i++)
01114   {
01115     int aCriterion = GetCriterionType(i, aType);
01116     QString errMsg;
01117     if (aCriterion == SMESH::FT_GroupColor ) {
01118       QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
01119       if (clrBtn && !clrBtn->color().isValid())
01120         errMsg = tr( "GROUPCOLOR_ERROR" );
01121     }
01122     else if (aCriterion == SMESH::FT_RangeOfIds ||
01123              aCriterion == SMESH::FT_BelongToGeom ||
01124              aCriterion == SMESH::FT_BelongToPlane ||
01125              aCriterion == SMESH::FT_BelongToCylinder ||
01126              aCriterion == SMESH::FT_BelongToGenSurface ||
01127              aCriterion == SMESH::FT_ElemGeomType ||
01128              aCriterion == SMESH::FT_CoplanarFaces ||
01129              aCriterion == SMESH::FT_LyingOnGeom)
01130     {
01131       if (aTable->text(i, 2).isEmpty())
01132         errMsg = tr( "ERROR" );
01133     }
01134     else {
01135       bool aRes = false;
01136       bool isSignalsBlocked = aTable->signalsBlocked();
01137       aTable->blockSignals(true);
01138       double  aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
01139       aTable->blockSignals(isSignalsBlocked);
01140 
01141       if (!aRes && aTable->isEditable(i, 2))
01142         errMsg = tr( "ERROR" );
01143       else if (aType == SMESH::EDGE &&
01144                GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
01145                aThreshold == 1)
01146         errMsg = tr( "MULTIEDGES_ERROR" );
01147     }
01148 
01149     if (!errMsg.isEmpty()) {
01150       if (theMess)
01151         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
01152       return false;
01153     }
01154 
01155     QTableWidgetItem* anItem = aTable->item(i, 0);
01156     if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
01157       return false;
01158   }
01159 
01160   return true;
01161 }
01162 
01163 //=======================================================================
01164 // name    : SMESHGUI_FilterTable::SetValidity
01165 // Purpose : Set validity of the table
01166 //=======================================================================
01167 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
01168 {
01169   myIsValid = isValid;
01170 }
01171 
01172 //=======================================================================
01173 // name    : SMESHGUI_FilterTable::GetType
01174 // Purpose : Get current entity type
01175 //=======================================================================
01176 int SMESHGUI_FilterTable::GetType() const
01177 {
01178   return myEntityType;
01179 }
01180 
01181 //=======================================================================
01182 // name    : SMESHGUI_FilterTable::SetType
01183 // Purpose : Set current entity type
01184 //=======================================================================
01185 void SMESHGUI_FilterTable::SetType (const int type)
01186 {
01187   myEntityTypeGrp->button(type)->setChecked(true);
01188   onEntityType(type);
01189 }
01190 
01191 //=======================================================================
01192 // name    : SMESHGUI_FilterTable::RestorePreviousEntityType
01193 // Purpose : Restore previous entity type
01194 //=======================================================================
01195 void SMESHGUI_FilterTable::RestorePreviousEntityType()
01196 {
01197   SetType(myEntityType);
01198 }
01199 
01200 //=======================================================================
01201 // name    : SMESHGUI_FilterTable::GetCriterionType
01202 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
01203 //=======================================================================
01204 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
01205 {
01206   int aType = theType == -1 ? GetType() : theType;
01207   Table* aTable = myTables[ aType ];
01208   ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
01209   return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
01210 }
01211 
01212 //=======================================================================
01213 // name    : SMESHGUI_FilterTable::GetCriterion
01214 // Purpose : Get parameters of criterion from specified row
01215 //=======================================================================
01216 void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
01217                                          SMESH::Filter::Criterion& theCriterion,
01218                                          const int                 theEntityType) const
01219 {
01220   int aType = theEntityType == -1 ? GetType() : theEntityType;
01221   Table* aTable = myTables[ aType ];
01222 
01223   theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
01224   theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
01225   theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
01226     ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
01227   theCriterion.TypeOfElement = (SMESH::ElementType)aType;
01228 
01229   int aCriterionType = GetCriterionType(theRow, aType);
01230 
01231   if ( aCriterionType == SMESH::FT_GroupColor )
01232   {
01233     QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
01234     if ( clrBtn )
01235     {
01236       const QColor qClr = clrBtn->color();
01237       QString clrStr = QString( "%1;%2;%3" ).
01238         arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
01239       theCriterion.ThresholdStr = clrStr.toLatin1().constData();
01240     }
01241   }
01242   else if ( aCriterionType == SMESH::FT_ElemGeomType )
01243     theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
01244   else if ( aCriterionType == SMESH::FT_CoplanarFaces )
01245     theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
01246   else if ( aCriterionType != SMESH::FT_RangeOfIds &&
01247             aCriterionType != SMESH::FT_BelongToGeom &&
01248             aCriterionType != SMESH::FT_BelongToPlane &&
01249             aCriterionType != SMESH::FT_BelongToCylinder &&
01250             aCriterionType != SMESH::FT_BelongToGenSurface &&
01251             aCriterionType != SMESH::FT_LyingOnGeom )
01252   {
01253     theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
01254     theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
01255   }
01256   else
01257   {
01258     theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
01259     if ( aCriterionType != SMESH::FT_RangeOfIds )
01260       theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
01261   }
01262 
01263   QTableWidgetItem* anItem = aTable->item(theRow, 0);
01264   if (myAddWidgets.contains(anItem))
01265     theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
01266 }
01267 
01268 //=======================================================================
01269 // name    : SMESHGUI_FilterTable::SetCriterion
01270 // Purpose : Set parameters of criterion of specified row
01271 //=======================================================================
01272 void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
01273                                          const SMESH::Filter::Criterion& theCriterion,
01274                                          const int                       theEntityType)
01275 {
01276   int aType = theEntityType == -1 ? GetType() : theEntityType;
01277 
01278   Table* aTable = myTables[ aType ];
01279 
01280   if (theRow > aTable->rowCount() - 1)
01281     return;
01282 
01283   ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
01284   onCriterionChanged(theRow, 0, aType);
01285   if ( theCriterion.Compare == SMESH::FT_Undefined )
01286     ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
01287   else
01288     ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
01289   ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
01290 
01291   if (theCriterion.BinaryOp != SMESH::FT_Undefined)
01292   {
01293     if (!aTable->isEditable(theRow, 4))
01294       aTable->setItem(theRow, 4, getBinaryItem());
01295     ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
01296   }
01297   else
01298     aTable->setEditable(false, theRow, 4);
01299 
01300   if (theCriterion.Type == SMESH::FT_GroupColor )
01301   {
01302     QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
01303     if ( clrBtn )
01304     {
01305       QColor qClr;
01306       QString clrStr( theCriterion.ThresholdStr );
01307       QStringList clrVals = clrStr.split( ";" );
01308       if ( clrVals.count() > 2 )
01309         qClr.setRgb( (int)256*clrVals[0].toDouble(),
01310                      (int)256*clrVals[1].toDouble(),
01311                      (int)256*clrVals[2].toDouble() );
01312       clrBtn->setColor( qClr );
01313     }
01314   }
01315   else if (theCriterion.Type == SMESH::FT_ElemGeomType )
01316   {
01317     ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
01318     typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
01319   }
01320   else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
01321   {
01322     aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
01323   }
01324   else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
01325            theCriterion.Type != SMESH::FT_BelongToGeom &&
01326            theCriterion.Type != SMESH::FT_BelongToPlane &&
01327            theCriterion.Type != SMESH::FT_BelongToCylinder &&
01328            theCriterion.Type != SMESH::FT_BelongToGenSurface &&
01329            theCriterion.Type != SMESH::FT_LyingOnGeom &&
01330            theCriterion.Type != SMESH::FT_CoplanarFaces &&
01331            theCriterion.Type != SMESH::FT_FreeBorders &&
01332            theCriterion.Type != SMESH::FT_FreeEdges &&
01333            theCriterion.Type != SMESH::FT_FreeNodes &&
01334            theCriterion.Type != SMESH::FT_FreeFaces &&
01335            theCriterion.Type != SMESH::FT_BadOrientedVolume &&
01336            theCriterion.Type != SMESH::FT_BareBorderFace &&
01337            theCriterion.Type != SMESH::FT_BareBorderVolume &&
01338            theCriterion.Type != SMESH::FT_OverConstrainedFace &&
01339            theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
01340            theCriterion.Type != SMESH::FT_LinearOrQuadratic)
01341   {
01342     aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
01343   }
01344   else
01345   {
01346     aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
01347     if ( theCriterion.Type != SMESH::FT_RangeOfIds )
01348       aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
01349   }
01350 
01351   if (theCriterion.Compare == SMESH::FT_EqualTo ||
01352       theCriterion.Type    == SMESH::FT_BelongToPlane ||
01353       theCriterion.Type    == SMESH::FT_BelongToCylinder ||
01354       theCriterion.Type    == SMESH::FT_BelongToGenSurface ||
01355       theCriterion.Type    == SMESH::FT_BelongToGeom ||
01356       theCriterion.Type    == SMESH::FT_LyingOnGeom ||
01357       theCriterion.Type    == SMESH::FT_CoplanarFaces ||
01358       theCriterion.Type    == SMESH::FT_EqualNodes)
01359   {
01360     QTableWidgetItem* anItem = aTable->item(theRow, 0);
01361     if (!myAddWidgets.contains(anItem))
01362     {
01363       myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
01364       myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
01365       myWgStack->addWidget(myAddWidgets[ anItem ]);
01366     }
01367     myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
01368   }
01369 
01370   emit CriterionChanged(theRow, aType);
01371 }
01372 
01373 //=======================================================================
01374 // name    : SMESHGUI_FilterTable::Update
01375 // Purpose : Update table
01376 //=======================================================================
01377 void SMESHGUI_FilterTable::Update()
01378 {
01379   Table* aTable = myTables[ GetType() ];
01380   int aCurrRow = aTable->currentRow();
01381   int numRows = aTable->rowCount();
01382   if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
01383     aTable->setCurrentCell(0, 0);
01384   updateAdditionalWidget();
01385 }
01386 
01387 //=======================================================================
01388 // name    : SMESHGUI_FilterTable::AddCriterion
01389 // Purpose : Add criterion with parameters
01390 //=======================================================================
01391 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
01392                                          const int                       theEntityType)
01393 {
01394   int aType = theEntityType == -1 ? GetType() : theEntityType;
01395   Table* aTable = myTables[ aType ];
01396   addRow(aTable, aType);
01397   SetCriterion(aTable->rowCount() - 1, theCriterion);
01398 }
01399 
01400 //=======================================================================
01401 // name    : SMESHGUI_FilterTable::NumRows
01402 // Purpose : Get number of criterions of current type
01403 //=======================================================================
01404 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
01405 {
01406   return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
01407 }
01408 
01409 //=======================================================================
01410 // name    : SMESHGUI_FilterTable::Clear
01411 // Purpose : Clear current table
01412 //=======================================================================
01413 void SMESHGUI_FilterTable::Clear (const int theType)
01414 {
01415   int aType = theType == -1 ? GetType() : theType;
01416   Table* aTable = myTables[ aType ];
01417 
01418   if (aTable->rowCount() == 0)
01419     return;
01420 
01421   while (aTable->rowCount() > 0)
01422   {
01423     removeAdditionalWidget(aTable, 0);
01424     aTable->removeRow(0);
01425   }
01426 
01427   updateBtnState();
01428 }
01429 
01430 //=======================================================================
01431 // name    : SMESHGUI_FilterTable::onAddBtn
01432 // Purpose : SLOT. Called then "Add" button pressed.
01433 //           Adds new string to table
01434 //=======================================================================
01435 void SMESHGUI_FilterTable::onAddBtn()
01436 {
01437   int aType = GetType();
01438   addRow(myTables[ aType ], aType);
01439 
01440   Update();
01441 }
01442 
01443 //=======================================================================
01444 // name    : SMESHGUI_FilterTable::onInsertBtn
01445 // Purpose : SLOT. Called then "Insert" button pressed.
01446 //           Inserts new string before current one
01447 //=======================================================================
01448 void SMESHGUI_FilterTable::onInsertBtn()
01449 {
01450   addRow(myTables[ GetType() ], GetType(), false);
01451 }
01452 
01453 //=======================================================================
01454 // name    : SMESHGUI_FilterTable::onRemoveBtn
01455 // Purpose : SLOT. Called then "Remove" button pressed.
01456 //           Removes current string from table
01457 //=======================================================================
01458 void SMESHGUI_FilterTable::onRemoveBtn()
01459 {
01460   Table* aTable = myTables[ GetType() ];
01461 
01462   if (aTable->rowCount() == 0)
01463     return;
01464 
01465   QList<QTableWidgetItem*> items = aTable->selectedItems();
01466   
01467   QList<int> aRows = aTable->selectedRows(); // already sorted
01468   int i;
01469   foreach( i, aRows )
01470   {
01471     removeAdditionalWidget(aTable, i);
01472     aTable->removeRow(i);
01473   }
01474 
01475   // remove control of binary logical operation from last row
01476   if (aTable->rowCount() > 0)
01477     aTable->setEditable(false, aTable->rowCount() - 1, 4);
01478 
01479   updateBtnState();
01480 }
01481 
01482 //=======================================================================
01483 // name    : SMESHGUI_FilterTable::updateAdditionalWidget
01484 // Purpose : Enable/Disable widget with additonal parameters
01485 //=======================================================================
01486 void SMESHGUI_FilterTable::updateAdditionalWidget()
01487 {
01488   Table* aTable = myTables[ GetType() ];
01489   int aRow = aTable->currentRow();
01490   if (aRow < 0 || aRow >= aTable->rowCount())
01491   {
01492     myWgStack->setEnabled(false);
01493     return;
01494   }
01495 
01496   ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
01497   int aCriterion = GetCriterionType(aRow);
01498   bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
01499                    aCriterion != SMESH::FT_RangeOfIds &&
01500                    aCriterion != SMESH::FT_FreeEdges &&
01501                    aCriterion != SMESH::FT_FreeFaces &&
01502                    aCriterion != SMESH::FT_BadOrientedVolume &&
01503                    aCriterion != SMESH::FT_BareBorderFace &&
01504                    aCriterion != SMESH::FT_BareBorderVolume &&
01505                    aCriterion != SMESH::FT_OverConstrainedFace &&
01506                    aCriterion != SMESH::FT_OverConstrainedVolume)
01507                    ||
01508                    aCriterion == SMESH::FT_CoplanarFaces);
01509   
01510   if (!myAddWidgets.contains(anItem))
01511   {
01512     myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
01513     myWgStack->addWidget(myAddWidgets[ anItem ]);
01514   }
01515 
01516   myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
01517   myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
01518   myWgStack->setEnabled(toEnable);
01519 }
01520 
01521 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
01522 {
01523   const char* retval = 0;
01524   switch ( aType ) {
01525   case SMESH::FT_AspectRatio:
01526   case SMESH::FT_AspectRatio3D:
01527   case SMESH::FT_Taper:
01528     retval = "parametric_precision"; break;
01529   case SMESH::FT_Warping:
01530   case SMESH::FT_MinimumAngle:
01531   case SMESH::FT_Skew:
01532   case SMESH::FT_CoplanarFaces:
01533     retval = "angle_precision"; break;
01534   case SMESH::FT_Area:
01535     retval = "area_precision"; break;
01536   case SMESH::FT_BelongToGeom:
01537   case SMESH::FT_BelongToPlane:
01538   case SMESH::FT_BelongToCylinder:
01539   case SMESH::FT_BelongToGenSurface:
01540   case SMESH::FT_LyingOnGeom:
01541   case SMESH::FT_EqualNodes:
01542     retval = "len_tol_precision"; break;
01543   case SMESH::FT_Length:
01544   case SMESH::FT_Length2D:
01545   case SMESH::FT_MaxElementLength2D:
01546   case SMESH::FT_MaxElementLength3D:
01547     retval = "length_precision"; break;
01548   case SMESH::FT_Volume3D:
01549     retval = "vol_precision"; break;
01550   default:
01551     break;
01552   }
01553   return retval;
01554 }
01555 
01556 //=======================================================================
01557 // name    : SMESHGUI_FilterTable::removeAdditionalWidget
01558 // Purpose : Remove widgets containing additional parameters from widget
01559 //           stack and internal map
01560 //=======================================================================
01561 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
01562 {
01563   QTableWidgetItem* anItem = theTable->item(theRow, 0);
01564   if (myAddWidgets.contains(anItem))
01565   {
01566     myWgStack->removeWidget(myAddWidgets[ anItem ]);
01567     myAddWidgets[ anItem ]->setParent(0);
01568     delete myAddWidgets[ anItem ];
01569     myAddWidgets.remove(anItem);
01570   }
01571 }
01572 
01573 //=======================================================================
01574 // name    : SMESHGUI_FilterTable::onClearBtn
01575 // Purpose : SLOT. Called then "Clear" button pressed.
01576 //           Removes all strings from table
01577 //=======================================================================
01578 void SMESHGUI_FilterTable::onClearBtn()
01579 {
01580   Table* aTable = myTables[ GetType() ];
01581 
01582   if (aTable->rowCount() == 0)
01583     return;
01584 
01585   while (aTable->rowCount() > 0)
01586   {
01587     removeAdditionalWidget(aTable, 0);
01588     aTable->removeRow(0);
01589   }
01590 
01591   updateBtnState();
01592 }
01593 
01594 //=======================================================================
01595 // name    : SMESHGUI_FilterTable::onCurrentChanged()
01596 // Purpose : SLOT. Called when current cell changed
01597 //=======================================================================
01598 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
01599 {
01600   if( !myIsLocked )
01601     updateAdditionalWidget();
01602   emit CurrentChanged(theRow, theCol);
01603 }
01604 
01605 //=======================================================================
01606 // name    : geomTypes
01607 // Purpose : returns available geometry types of elements
01608 //=======================================================================
01609 static QList<int> geomTypes( const int theType )
01610 {
01611   QList<int> typeIds;
01612   if ( theType == SMESH::NODE )
01613     typeIds.append( SMESH::Geom_POINT );
01614   if ( theType == SMESH::ALL || theType == SMESH::EDGE )
01615     typeIds.append( SMESH::Geom_EDGE );
01616   if ( theType == SMESH::ALL || theType == SMESH::FACE )
01617   {
01618     typeIds.append( SMESH::Geom_TRIANGLE );
01619     typeIds.append( SMESH::Geom_QUADRANGLE );
01620     typeIds.append( SMESH::Geom_POLYGON );
01621   }
01622   if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
01623   {
01624     typeIds.append( SMESH::Geom_TETRA );
01625     typeIds.append( SMESH::Geom_PYRAMID );
01626     typeIds.append( SMESH::Geom_HEXA );
01627     typeIds.append( SMESH::Geom_PENTA );
01628     typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
01629     typeIds.append( SMESH::Geom_POLYHEDRA );
01630   }
01631   return typeIds;
01632 }
01633 
01634 //=======================================================================
01635 // name    : SMESHGUI_FilterTable::onCriterionChanged()
01636 // Purpose : Provides reaction on change of criterion
01637 //=======================================================================
01638 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
01639 {
01640   int aType = entityType == -1 ? GetType() : entityType;
01641   Table* aTable = myTables[ aType ];
01642   ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
01643 
01644   int aCriterionType = GetCriterionType(row);
01645   QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
01646   int aComboType = ComboItem::Type();
01647   int aIntSpinType = IntSpinItem::Type();
01648   int aDoubleSpinType = DoubleSpinItem::Type();
01649   QTableWidgetItem* aTableItem = aTable->item(row, 2);
01650   bool isComboItem = false;
01651   bool isIntSpinItem = false;
01652   bool isDoubleSpinItem = false;
01653   if (aTableItem) {
01654     int aTableType = aTable->item(row, 2)->type();
01655     isComboItem = ( aTableType == aComboType );
01656     isIntSpinItem = ( aTableType == aIntSpinType );
01657     isDoubleSpinItem = ( aTableType == aDoubleSpinType );
01658   }
01659   
01660   bool anIsDoubleCriterion =
01661     aCriterionType == SMESH::FT_AspectRatio ||
01662     aCriterionType == SMESH::FT_AspectRatio3D ||
01663     aCriterionType == SMESH::FT_Taper ||
01664     aCriterionType == SMESH::FT_Warping ||
01665     aCriterionType == SMESH::FT_MinimumAngle ||
01666     aCriterionType == SMESH::FT_Skew ||
01667     aCriterionType == SMESH::FT_Area ||
01668     aCriterionType == SMESH::FT_Length ||
01669     aCriterionType == SMESH::FT_Length2D ||
01670     aCriterionType == SMESH::FT_MaxElementLength2D ||
01671     aCriterionType == SMESH::FT_MaxElementLength3D ||
01672     aCriterionType == SMESH::FT_Volume3D;
01673 
01674   int aPrecision = 0;
01675   if ( anIsDoubleCriterion ) {
01676     const char* aPrecisionType = getPrecision( aCriterionType );
01677     SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
01678     if( aPrecisionType && aResourceMgr )
01679       aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
01680   }
01681 
01682   // if the precision is to be changed we should remove the existing
01683   // spin item and create another one with new precision
01684   bool anIsPrecisionChanged = false;
01685   if ( anIsDoubleCriterion && isDoubleSpinItem ) {
01686     if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
01687       anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
01688     }
01689   }
01690 
01691   if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
01692        (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
01693        (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
01694        (!anIsDoubleCriterion && isDoubleSpinItem) ||
01695        anIsPrecisionChanged )
01696   {
01697     bool isSignalsBlocked = aTable->signalsBlocked();
01698     aTable->blockSignals( true );
01699     aTable->removeCellWidget( row, 2 );
01700     aTable->setItem( row, 2, new QTableWidgetItem() );
01701     aTable->blockSignals( isSignalsBlocked );
01702   }
01703   if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
01704        (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
01705        (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
01706        (anIsDoubleCriterion && !isDoubleSpinItem) ||
01707        anIsPrecisionChanged )
01708   {
01709     bool isSignalsBlocked = aTable->signalsBlocked();
01710     aTable->blockSignals( true );
01711     if ( aCriterionType == SMESH::FT_GroupColor )
01712       aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
01713     else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
01714       QList<int> typeIds = geomTypes( aType );
01715       QMap<int, QString> typeNames;
01716       QList<int>::const_iterator anIter = typeIds.begin();
01717       for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
01718       {
01719         QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
01720         typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
01721       }
01722       ComboItem* typeBox = new ComboItem( typeNames );
01723       aTable->setItem( row, 2, typeBox );
01724     }
01725     else if ( aCriterionType == SMESH::FT_MultiConnection ) {
01726       IntSpinItem* intSpin = new IntSpinItem( 0 );
01727       aTable->setItem( row, 2, intSpin );
01728     }
01729     else if ( anIsDoubleCriterion ) {
01730       DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
01731       dblSpin->setPrecision( aPrecision );
01732       aTable->setItem( row, 2, dblSpin );
01733     }
01734     aTable->blockSignals( isSignalsBlocked );
01735   }
01736 
01737   if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes               ||
01738                                 aCriterionType == SMESH::FT_EqualNodes ))           ||
01739       (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders             ||
01740                                 aCriterionType == SMESH::FT_EqualEdges ))           ||
01741       (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace          ||
01742                                 aCriterionType == SMESH::FT_OverConstrainedFace     ||
01743                                 aCriterionType == SMESH::FT_FreeEdges               ||
01744                                 aCriterionType == SMESH::FT_FreeFaces               ||
01745                                 aCriterionType == SMESH::FT_EqualFaces))            ||
01746       (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume     ||
01747                                   aCriterionType == SMESH::FT_OverConstrainedVolume ||
01748                                   aCriterionType == SMESH::FT_BareBorderVolume      ||
01749                                   aCriterionType == SMESH::FT_EqualVolumes ))       ||
01750       aCriterionType == SMESH::FT_LinearOrQuadratic ||
01751       aCriterionType == SMESH::FT_GroupColor ||
01752       aCriterionType == SMESH::FT_ElemGeomType ||
01753       aCriterionType == SMESH::FT_CoplanarFaces
01754       )
01755   {
01756     bool isSignalsBlocked = aTable->signalsBlocked();
01757     aTable->blockSignals( true );
01758 
01759     if (aCompareItem->count() > 0)
01760       aCompareItem->clear();
01761     aTable->setEditable(false, row, 1);
01762     aTable->item(row, 2)->setText( QString("") );
01763     aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
01764                         aCriterionType == SMESH::FT_ElemGeomType ||
01765                         aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
01766     aTable->blockSignals( isSignalsBlocked );
01767   }
01768   else if (aCriterionType == SMESH::FT_RangeOfIds ||
01769            aCriterionType == SMESH::FT_BelongToGeom ||
01770            aCriterionType == SMESH::FT_BelongToPlane ||
01771            aCriterionType == SMESH::FT_BelongToCylinder ||
01772            aCriterionType == SMESH::FT_BelongToGenSurface ||
01773            aCriterionType == SMESH::FT_LyingOnGeom)
01774   {
01775     QMap<int, QString> aMap;
01776     aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
01777     aCompareItem->setItems(aMap);
01778     if (!aTable->isEditable(row, 2))
01779       aTable->setEditable(true, row, 1);
01780     if (!aTable->isEditable(row, 2))
01781       aTable->setEditable(true, row, 2);
01782   }
01783   else if (aCriterionType == SMESH::FT_GroupColor ||
01784            aCriterionType == SMESH::FT_ElemGeomType)
01785   {
01786     if (!aTable->isEditable(row, 2))
01787       aTable->setEditable(true, row, 2);
01788   }
01789   else
01790   {
01791     if (aCompareItem && aCompareItem->count() != 3)
01792     {
01793       aCompareItem->setItems(getCompare());
01794     }
01795 
01796     if (aTable->item( row, 2 )) {
01797       QString aText = aTable->text(row, 2);
01798       bool isOk = false;
01799       aText.toDouble(&isOk);
01800       aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
01801       if (!aTable->isEditable(row, 1))
01802         aTable->setEditable(true, row, 1);
01803       if (!aTable->isEditable(row, 2))
01804         aTable->setEditable(true, row, 2);
01805     }
01806   }
01807 
01808   updateAdditionalWidget();
01809 
01810   emit CriterionChanged(row, entityType);
01811 }
01812 
01813 //=======================================================================
01814 // name    : SMESHGUI_FilterTable::onCriterionChanged()
01815 // Purpose : SLOT. Called then contents of table changed
01816 //           Provides reaction on change of criterion
01817 //=======================================================================
01818 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
01819 {
01820   if( col == 0 )
01821     onCriterionChanged(row, col, -1);
01822 }
01823 
01824 //=======================================================================
01825 // name    : SMESHGUI_FilterTable::getFirstSelectedRow
01826 // Purpose : Get first selected row
01827 //=======================================================================
01828 int SMESHGUI_FilterTable::getFirstSelectedRow() const
01829 {
01830   Table* aTable = myTables[ GetType() ];
01831 
01832   QList<int> selRows = aTable->selectedRows(); // already sorted
01833   int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
01834 
01835   return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
01836 }
01837 
01838 //=======================================================================
01839 // name    : SMESHGUI_FilterTable::addRow
01840 // Purpose : Add row at the end of table
01841 //=======================================================================
01842 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
01843 {
01844   int aCurrRow = 0;
01845   int aSelectedRow = getFirstSelectedRow();
01846   int aCurrCol = theTable->currentColumn();
01847 
01848   myIsLocked = true;
01849   if (toTheEnd || aSelectedRow == -1)
01850   {
01851     theTable->insertRows(theTable->rowCount());
01852     aCurrRow = theTable->rowCount() - 1;
01853   }
01854   else
01855   {
01856     theTable->insertRows(aSelectedRow);
01857     aCurrRow = aSelectedRow;
01858   }
01859   myIsLocked = false;
01860 
01861   // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
01862   bool isSignalsBlocked = theTable->signalsBlocked();
01863   theTable->blockSignals( true );
01864 
01865   // Criteria
01866   theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
01867 
01868   // Compare
01869   theTable->setItem(aCurrRow, 1, getCompareItem());
01870 
01871   // Threshold
01872   theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
01873 
01874   // Logical operation NOT
01875   theTable->setItem(aCurrRow, 3, getUnaryItem());
01876 
01877   // Logical operation AND / OR
01878   theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
01879 
01880   theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
01881     
01882   theTable->blockSignals( isSignalsBlocked );
01883 
01884   // Logical binary operation for previous value
01885   int anAddBinOpStr = -1;
01886   if (aCurrRow == theTable->rowCount() - 1)
01887     anAddBinOpStr = aCurrRow - 1;
01888   else if (aCurrRow >= 0 )
01889     anAddBinOpStr = aCurrRow;
01890 
01891   if (theTable->item(aCurrRow, 4) == 0 ||
01892        theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
01893   {
01894     if (anAddBinOpStr >= 0 &&
01895          (theTable->item(anAddBinOpStr, 4) == 0 ||
01896            theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
01897       theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
01898   }
01899 
01900   theTable->setEditable(false, theTable->rowCount() - 1, 4);
01901   
01902   if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
01903        aCurrCol >=0 && aCurrCol < theTable->rowCount())
01904   theTable->setCurrentCell(aCurrRow, aCurrCol);
01905 
01906   onCriterionChanged(aCurrRow, 0);
01907 
01908   updateBtnState();
01909 }
01910 
01911 //=======================================================================
01912 // name    : SMESHGUI_FilterTable::getCriterionItem
01913 // Purpose : Get combo table item for criteria of specified type
01914 //=======================================================================
01915 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
01916 {
01917   return new ComboItem(getCriteria(theType));
01918 }
01919 
01920 //=======================================================================
01921 // name    : SMESHGUI_FilterTable::getCompareItem
01922 // Purpose : Get combo table item for operation of comparision
01923 //=======================================================================
01924 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
01925 {
01926   return new ComboItem(getCompare());
01927 }
01928 
01929 //=======================================================================
01930 // name    : SMESHGUI_FilterTable::getBinaryItem
01931 // Purpose :
01932 //=======================================================================
01933 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
01934 {
01935   static QMap<int, QString> aMap;
01936   if (aMap.isEmpty())
01937   {
01938     aMap[ SMESH::FT_LogicalAND ] = tr("AND");
01939     aMap[ SMESH::FT_LogicalOR  ] = tr("OR");
01940   }
01941 
01942   return new ComboItem(aMap);
01943 }
01944 
01945 //=======================================================================
01946 // name    : SMESHGUI_FilterTable::getUnaryItem
01947 // Purpose : Get check table item
01948 //=======================================================================
01949 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
01950 {
01951   return new CheckItem(tr("NOT"));
01952 }
01953 
01954 //=======================================================================
01955 // name    : SMESHGUI_FilterTable::getSupportedTypes
01956 // Purpose : Get all supported type
01957 //=======================================================================
01958 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
01959 {
01960   static QMap<int, QString> aTypes;
01961   if (aTypes.isEmpty())
01962   {
01963     aTypes[ SMESH::NODE   ] = tr("NODES");
01964     aTypes[ SMESH::EDGE   ] = tr("EDGES");
01965     aTypes[ SMESH::FACE   ] = tr("FACES");
01966     aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
01967     aTypes[ SMESH::ALL ]    = tr("ELEMENTS");
01968   }
01969 
01970   return aTypes;
01971 }
01972 
01973 //=======================================================================
01974 // name    : SMESHGUI_FilterTable::getCriteria
01975 // Purpose : Get criteria for specified type
01976 //=======================================================================
01977 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
01978 {
01979   if (theType == SMESH::NODE)
01980   {
01981     static QMap<int, QString> aCriteria;
01982     if (aCriteria.isEmpty())
01983     {
01984       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
01985       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
01986       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
01987       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
01988       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
01989       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
01990       aCriteria[ SMESH::FT_FreeNodes          ] = tr("FREE_NODES");
01991       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
01992       aCriteria[ SMESH::FT_EqualNodes         ] = tr("EQUAL_NODE");
01993     }
01994     return aCriteria;
01995   }
01996   else if (theType == SMESH::EDGE)
01997   {
01998     static QMap<int, QString> aCriteria;
01999     if (aCriteria.isEmpty())
02000     {
02001       aCriteria[ SMESH::FT_FreeBorders        ] = tr("FREE_BORDERS");
02002       aCriteria[ SMESH::FT_MultiConnection    ] = tr("MULTI_BORDERS");
02003       aCriteria[ SMESH::FT_Length             ] = tr("LENGTH");
02004       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
02005       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
02006       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
02007       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
02008       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
02009       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
02010       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
02011       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
02012       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
02013       aCriteria[ SMESH::FT_EqualEdges         ] = tr("EQUAL_EDGE");
02014     }
02015     return aCriteria;
02016   }
02017   else if (theType == SMESH::FACE)
02018   {
02019     static QMap<int, QString> aCriteria;
02020     if (aCriteria.isEmpty())
02021     {
02022       aCriteria[ SMESH::FT_AspectRatio        ] = tr("ASPECT_RATIO");
02023       aCriteria[ SMESH::FT_Warping            ] = tr("WARPING");
02024       aCriteria[ SMESH::FT_MinimumAngle       ] = tr("MINIMUM_ANGLE");
02025       aCriteria[ SMESH::FT_Taper              ] = tr("TAPER");
02026       aCriteria[ SMESH::FT_Skew               ] = tr("SKEW");
02027       aCriteria[ SMESH::FT_Area               ] = tr("AREA");
02028       aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
02029       aCriteria[ SMESH::FT_FreeEdges          ] = tr("FREE_EDGES");
02030       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
02031       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
02032       aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
02033       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
02034       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
02035       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
02036       aCriteria[ SMESH::FT_Length2D           ] = tr("LENGTH2D");
02037       aCriteria[ SMESH::FT_MultiConnection2D  ] = tr("MULTI2D_BORDERS");
02038       aCriteria[ SMESH::FT_FreeFaces          ] = tr("FREE_FACES");
02039       aCriteria[ SMESH::FT_BareBorderFace     ] = tr("BARE_BORDER_FACE");
02040       aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
02041       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
02042       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
02043       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
02044       aCriteria[ SMESH::FT_CoplanarFaces      ] = tr("COPLANAR_FACES");
02045       aCriteria[ SMESH::FT_EqualFaces         ] = tr("EQUAL_FACE");
02046     }
02047     return aCriteria;
02048   }
02049   else if (theType == SMESH::VOLUME)
02050   {
02051     static QMap<int, QString> aCriteria;
02052     if (aCriteria.isEmpty())
02053     {
02054       aCriteria[ SMESH::FT_AspectRatio3D        ] = tr("ASPECT_RATIO_3D");
02055       aCriteria[ SMESH::FT_RangeOfIds           ] = tr("RANGE_OF_IDS");
02056       aCriteria[ SMESH::FT_BelongToGeom         ] = tr("BELONG_TO_GEOM");
02057       aCriteria[ SMESH::FT_LyingOnGeom          ] = tr("LYING_ON_GEOM");
02058       aCriteria[ SMESH::FT_BadOrientedVolume    ] = tr("BAD_ORIENTED_VOLUME");
02059       aCriteria[ SMESH::FT_BareBorderVolume     ] = tr("BARE_BORDER_VOLUME");
02060       aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
02061       aCriteria[ SMESH::FT_Volume3D             ] = tr("VOLUME_3D");
02062       aCriteria[ SMESH::FT_MaxElementLength3D   ] = tr("MAX_ELEMENT_LENGTH_3D");
02063       aCriteria[ SMESH::FT_LinearOrQuadratic    ] = tr("LINEAR");
02064       aCriteria[ SMESH::FT_GroupColor           ] = tr("GROUP_COLOR");
02065       aCriteria[ SMESH::FT_ElemGeomType         ] = tr("GEOM_TYPE");
02066       aCriteria[ SMESH::FT_EqualVolumes         ] = tr("EQUAL_VOLUME");
02067     }
02068     return aCriteria;
02069   }
02070   else // SMESH::ALL
02071   {
02072     static QMap<int, QString> aCriteria;
02073     if (aCriteria.isEmpty())
02074     {
02075       aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
02076       aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
02077       aCriteria[ SMESH::FT_LyingOnGeom        ] = tr("LYING_ON_GEOM");
02078       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
02079       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
02080       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
02081     }
02082 
02083     return aCriteria;
02084   }
02085 }
02086 
02087 
02088 //=======================================================================
02089 // name    : SMESHGUI_FilterTable::getCompare
02090 // Purpose : Get operation of comparison
02091 //=======================================================================
02092 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
02093 {
02094   static QMap<int, QString> aMap;
02095 
02096   if (aMap.isEmpty())
02097   {
02098     aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
02099     aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
02100     aMap[ SMESH::FT_EqualTo  ] = tr("EQUAL_TO" );
02101   }
02102 
02103   return aMap;
02104 }
02105 
02106 //=======================================================================
02107 // name    : SMESHGUI_FilterTable::createTable
02108 // Purpose : Create table
02109 //=======================================================================
02110 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget*  theParent,
02111                                                                 const int theType)
02112 {
02113   // create table
02114   Table* aTable= new Table(0, 6, theParent);
02115 
02116   QHeaderView* aHeaders = aTable->horizontalHeader();
02117 
02118   QFontMetrics aMetrics(aHeaders->font());
02119 
02120   // append spaces to the header of criteria in order to
02121   // provide visibility of criterion inside comboboxes
02122   static int aMaxLenCr = 0;
02123 
02124   if (aMaxLenCr == 0)
02125   {
02126     const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
02127     QMap<int, QString>::const_iterator anIter;
02128     for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
02129       aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
02130   }
02131 
02132   static int aLenCr = qAbs( aMaxLenCr -
02133                             aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
02134 
02135   QString aCrStr;
02136   aCrStr.fill(' ', aLenCr);
02137   QString aCoStr;
02138   aCoStr.fill(' ', 10);
02139 
02140   QStringList aHeaderLabels;
02141   aHeaderLabels.append( tr("CRITERION") + aCrStr );
02142   aHeaderLabels.append( tr("COMPARE")   + aCoStr );
02143   aHeaderLabels.append( tr("THRESHOLD_VALUE") );
02144   aHeaderLabels.append( tr("UNARY") );
02145   aHeaderLabels.append( tr("BINARY") + "  " );
02146   aHeaderLabels.append( tr("ID") );
02147   aTable->setHorizontalHeaderLabels( aHeaderLabels );
02148   
02149   // set geometry of the table
02150   for (int i = 0; i <= 4; i++)
02151     aTable->resizeColumnToContents(i);
02152 
02153   // set the ID column invisible
02154   aTable->hideColumn( 5 );
02155 
02156   aTable->updateGeometry();
02157   QSize aSize = aTable->sizeHint();
02158   int aWidth = aSize.width();
02159   aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
02160   aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
02161 
02162   connect(aTable, SIGNAL(cellChanged(int, int)),
02163           this,   SLOT(onCriterionChanged(int, int)));
02164 
02165   connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
02166           this,   SLOT(onCurrentChanged(int, int)));
02167   
02168   return aTable;
02169 }
02170 
02171 //=======================================================================
02172 // name    : SMESHGUI_FilterTable::updateBtnState
02173 // Purpose : Update button state
02174 //=======================================================================
02175 void SMESHGUI_FilterTable::updateBtnState()
02176 {
02177   myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
02178   myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
02179 }
02180 
02181 //=======================================================================
02182 // name    : SMESHGUI_FilterTable::SetEditable
02183 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
02184 //=======================================================================
02185 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
02186 {
02187   TableMap::iterator anIter;
02188   for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
02189   {
02190     anIter.value()->setReadOnly(!isEditable);
02191 
02192     // Set Flags for CheckItems directly IPAL 19974
02193     Table* aTable = anIter.value();
02194     for (int i = 0, n = aTable->rowCount(); i < n; i++)
02195       for (int j = 0, m = aTable->columnCount(); j < m; j++)
02196         {
02197           QTableWidgetItem* anItem = aTable->item(i, j);
02198           if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
02199             Qt::ItemFlags f = anItem->flags();
02200             if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
02201             else f = f | Qt::ItemIsUserCheckable;
02202             anItem->setFlags( f );
02203           }
02204         }
02205     //end of IPAL19974
02206 
02207     if (isEditable)
02208     {
02209       myAddBtn->show();
02210       myInsertBtn->show();
02211       myRemoveBtn->show();
02212       myClearBtn->show();
02213     }
02214     else
02215     {
02216       myAddBtn->hide();
02217       myInsertBtn->hide();
02218       myRemoveBtn->hide();
02219       myClearBtn->hide();
02220     }
02221   }
02222 
02223   QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
02224   for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
02225     anIter2.value()->SetEditable(isEditable);
02226 }
02227 
02228 //=======================================================================
02229 // name    : SMESHGUI_FilterTable::SetEnabled
02230 // Purpose : Enable/Disable table. Switching type of elements already enabled
02231 //=======================================================================
02232 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
02233 {
02234   myAddBtn->setEnabled(isEnabled);
02235   myInsertBtn->setEnabled(isEnabled);
02236   myRemoveBtn->setEnabled(isEnabled);
02237   myClearBtn->setEnabled(isEnabled);
02238 
02239   if (isEnabled)
02240     updateBtnState();
02241 
02242   QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
02243   for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
02244     anIter2.value()->setEnabled(isEnabled);
02245 }
02246 
02247 //=======================================================================
02248 // name    : SMESHGUI_FilterTable::IsEditable
02249 // Purpose : Verify whether table is editable
02250 //=======================================================================
02251 bool SMESHGUI_FilterTable::IsEditable() const
02252 {
02253   return !myTables[ GetType() ]->isReadOnly();
02254 }
02255 
02256 //=======================================================================
02257 // name    : SMESHGUI_FilterTable::SetLibsEnabled
02258 // Purpose : Show/hide buttons for work with libraries
02259 //=======================================================================
02260 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
02261 {
02262   if (isEnabled)
02263   {
02264     myCopyFromBtn->show();
02265     myAddToBtn->show();
02266   }
02267   else
02268   {
02269     myCopyFromBtn->hide();
02270     myAddToBtn->hide();
02271   }
02272 }
02273 
02274 //=======================================================================
02275 // name    : SMESHGUI_FilterTable::onCopyFromBtn
02276 // Purpose : SLOT. Called the "Copy from ..." button clicked
02277 //           Display filter library dialog
02278 //=======================================================================
02279 void SMESHGUI_FilterTable::onCopyFromBtn()
02280 {
02281   if (myLibDlg == 0)
02282     myLibDlg = new SMESHGUI_FilterLibraryDlg(
02283       mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
02284   else
02285     myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
02286 
02287   if (myLibDlg->exec() == QDialog::Accepted)
02288   {
02289     Copy(myLibDlg->GetTable());
02290     Update();
02291   }
02292 }
02293 
02294 //=======================================================================
02295 // name    : SMESHGUI_FilterTable::onAddToBtn
02296 // Purpose : SLOT. Called the "Add to ..." button clicked
02297 //           Display filter library dialog
02298 //=======================================================================
02299 void SMESHGUI_FilterTable::onAddToBtn()
02300 {
02301   if (!IsValid(true))
02302     return;
02303   if (myLibDlg == 0)
02304     myLibDlg = new SMESHGUI_FilterLibraryDlg(
02305       mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
02306   else
02307     myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
02308 
02309   myLibDlg->SetTable(this);
02310 
02311   myLibDlg->exec();
02312 }
02313 
02314 //=======================================================================
02315 // name    : SMESHGUI_FilterTable::Copy
02316 // Purpose : Initialise table with values of other table
02317 //=======================================================================
02318 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
02319 {
02320   Clear();
02321 
02322   for (int i = 0, n = theTable->NumRows(); i < n; i++)
02323   {
02324     SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
02325     theTable->GetCriterion(i, aCriterion);
02326     AddCriterion(aCriterion);
02327   }
02328 }
02329 
02330 //=======================================================================
02331 // name    : SMESHGUI_FilterTable::CurrentCell
02332 // Purpose : Returns current cell
02333 //=======================================================================
02334 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
02335 {
02336   theRow = myTables[ GetType() ]->currentRow();
02337   theCol = myTables[ GetType() ]->currentColumn();
02338   return theRow >= 0 && theCol >= 0;
02339 }
02340 
02341 //=======================================================================
02342 // name    : SMESHGUI_FilterTable::SetText
02343 // Purpose : Set text and internal value in cell of threshold value
02344 //=======================================================================
02345 void SMESHGUI_FilterTable::SetThreshold (const int      theRow,
02346                                          const QString& theText,
02347                                          const int      theEntityType)
02348 {
02349   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02350   aTable->item( theRow, 2 )->setText(theText);
02351 }
02352 
02353 //=======================================================================
02354 // name    : SMESHGUI_FilterTable::SetText
02355 // Purpose : Get text and internal value from cell of threshold value
02356 //=======================================================================
02357 bool SMESHGUI_FilterTable::GetThreshold (const int      theRow,
02358                                          QString&       theText,
02359                                          const int      theEntityType)
02360 {
02361   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02362   QTableWidgetItem* anItem = aTable->item(theRow, 2);
02363   if (anItem != 0)
02364   {
02365     theText = anItem->text();
02366     return true;
02367   }
02368   else
02369    return false;
02370 }
02371 
02372 //=======================================================================
02373 // name    : SMESHGUI_FilterTable::SetID
02374 // Purpose : Set text and internal value in cell of ID value 
02375 //=======================================================================
02376 void SMESHGUI_FilterTable::SetID( const int      theRow,
02377                                   const QString& theText,
02378                                   const int      theEntityType )
02379 {
02380   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02381   aTable->item( theRow, 5 )->setText( theText );
02382 }
02383 
02384 //=======================================================================
02385 // name    : SMESHGUI_FilterTable::GetID
02386 // Purpose : Get text and internal value from cell of ID value
02387 //=======================================================================
02388 bool SMESHGUI_FilterTable::GetID( const int      theRow,
02389                                   QString&       theText,
02390                                   const int      theEntityType )
02391 {
02392   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02393   QTableWidgetItem* anItem = aTable->item( theRow, 5 );
02394   if ( anItem != 0 )
02395     {
02396       theText = anItem->text();
02397       return true;    
02398     }
02399   else
02400     return false;
02401 } 
02402 
02403 /*
02404   Class       : SMESHGUI_FilterDlg
02405   Description : Dialog to specify filters for VTK viewer
02406 */
02407 
02408 
02409 //=======================================================================
02410 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
02411 // Purpose : Constructor
02412 //=======================================================================
02413 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI*         theModule,
02414                                         const QList<int>& theTypes )
02415 : QDialog( SMESH::GetDesktop( theModule ) ),
02416   mySMESHGUI( theModule ),
02417   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
02418   myInitSourceWgOnApply( true )
02419 {
02420   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02421     mySelector = aViewWindow->GetSelector();
02422 
02423   construct(theTypes);
02424 }
02425 
02426 //=======================================================================
02427 // name    : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
02428 // Purpose : Constructor
02429 //=======================================================================
02430 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI*   theModule,
02431                                         const int   theType )
02432 : QDialog( SMESH::GetDesktop( theModule ) ),
02433   mySMESHGUI( theModule ),
02434   mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
02435   myInitSourceWgOnApply( true )
02436 {
02437   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02438     mySelector = aViewWindow->GetSelector();
02439   QList<int> aTypes;
02440   aTypes.append(theType);
02441   construct(aTypes);
02442 }
02443 
02444 //=======================================================================
02445 // name    : SMESHGUI_FilterDlg::construct
02446 // Purpose : Construct dialog (called by constructor)
02447 //=======================================================================
02448 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
02449 {
02450   myTypes = theTypes;
02451 
02452   setModal(false);
02453   //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
02454   setWindowTitle(tr("CAPTION"));
02455 
02456   QVBoxLayout* aDlgLay = new QVBoxLayout (this);
02457   aDlgLay->setMargin(MARGIN);
02458   aDlgLay->setSpacing(SPACING);
02459 
02460   myMainFrame         = createMainFrame  (this);
02461   QWidget* aBtnFrame  = createButtonFrame(this);
02462 
02463   aDlgLay->addWidget(myMainFrame);
02464   aDlgLay->addWidget(aBtnFrame);
02465 
02466   aDlgLay->setStretchFactor(myMainFrame, 1);
02467 
02468   myHelpFileName = "selection_filter_library_page.html";
02469 
02470   Init(myTypes);
02471 }
02472 
02473 //=======================================================================
02474 // name    : SMESHGUI_FilterDlg::createMainFrame
02475 // Purpose : Create frame containing dialog's input fields
02476 //=======================================================================
02477 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
02478 {
02479   QWidget* aMainFrame = new QWidget(theParent);
02480   QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
02481   aMainLay->setMargin(0);
02482   aMainLay->setSpacing(SPACING);
02483 
02484   // filter frame
02485 
02486   myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
02487   myTable->SetLibsEnabled(true);
02488 
02489   QGroupBox* aGrp = myTable->GetTableGrp();
02490   QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
02491   int rows = aLay->rowCount();
02492   int cols = aLay->columnCount();
02493 
02494   QFrame* aLine = new QFrame(aGrp);
02495   aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
02496   aLay->addWidget(aLine, rows++, 0, 1, cols);
02497 
02498   mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
02499   mySetInViewer->setChecked(true);
02500   aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
02501 
02502   // other controls
02503   QWidget* aSourceGrp = createSourceGroup(aMainFrame);
02504 
02505   connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
02506                     SLOT(onCriterionChanged(const int, const int)));
02507 
02508   connect(myTable, SIGNAL(CurrentChanged(int, int)),
02509                     SLOT(onCurrentChanged(int, int)));
02510 
02511   aMainLay->addWidget(myTable);
02512   aMainLay->addWidget(aSourceGrp);
02513   
02514   return aMainFrame;
02515 }
02516 
02517 //=======================================================================
02518 // name    : SMESHGUI_FilterDlg::createSourceFrame
02519 // Purpose : Create frame containing source radio button
02520 //=======================================================================
02521 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
02522 {
02523   QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
02524   QHBoxLayout* aLay = new QHBoxLayout(aBox);
02525   aLay->setMargin(MARGIN);
02526   aLay->setSpacing(SPACING);
02527 
02528   mySourceGrp = new QButtonGroup(theParent);
02529 
02530   QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"),          aBox);
02531   QRadioButton* aSelBtn  = new QRadioButton(tr("SELECTION"),     aBox);
02532   QRadioButton* aDlgBtn  = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
02533 
02534   aLay->addWidget(aMeshBtn);
02535   aLay->addWidget(aSelBtn);
02536   aLay->addWidget(aDlgBtn);
02537 
02538   mySourceGrp->addButton(aMeshBtn, Mesh);
02539   mySourceGrp->addButton(aSelBtn,  Selection);
02540   mySourceGrp->addButton(aDlgBtn,  Dialog);
02541 
02542   aMeshBtn->setChecked(true);
02543 
02544   return aBox;
02545 }
02546 
02547 //=======================================================================
02548 // name    : SMESHGUI_FilterDlg::updateMainButtons
02549 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
02550 //=======================================================================
02551 void SMESHGUI_FilterDlg::updateMainButtons()
02552 {
02553   myButtons[ BTN_Close  ]->show();
02554   if (myTypes.count() == 1)
02555   {
02556     myButtons[ BTN_Apply  ]->hide();
02557   }
02558   else
02559   {
02560     myButtons[ BTN_Apply  ]->show();
02561   }
02562 //  updateGeometry();
02563 }
02564 
02565 //=======================================================================
02566 // name    : SMESHGUI_FilterDlg::createButtonFrame
02567 // Purpose : Create frame containing buttons
02568 //=======================================================================
02569 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
02570 {
02571   QGroupBox* aGrp = new QGroupBox(theParent);
02572   QHBoxLayout* aLay = new QHBoxLayout(aGrp);
02573   aLay->setMargin(MARGIN);
02574   aLay->setSpacing(SPACING);
02575 
02576   myButtons[ BTN_OK     ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
02577   myButtons[ BTN_Apply  ] = new QPushButton(tr("SMESH_BUT_APPLY"),           aGrp);
02578   myButtons[ BTN_Close  ] = new QPushButton(tr("SMESH_BUT_CLOSE"),           aGrp);
02579   myButtons[ BTN_Help   ] = new QPushButton(tr("SMESH_BUT_HELP"),            aGrp);
02580 
02581   aLay->addWidget(myButtons[ BTN_OK     ]);
02582   aLay->addSpacing(10);
02583   aLay->addWidget(myButtons[ BTN_Apply  ]);
02584   aLay->addSpacing(10);
02585   aLay->addStretch();
02586   aLay->addWidget(myButtons[ BTN_Close  ]);
02587   aLay->addWidget(myButtons[ BTN_Help   ]);
02588 
02589   connect(myButtons[ BTN_OK     ], SIGNAL(clicked()), SLOT(onOk()));
02590   connect(myButtons[ BTN_Close  ], SIGNAL(clicked()), SLOT(onClose()));
02591   connect(myButtons[ BTN_Apply  ], SIGNAL(clicked()), SLOT(onApply()));
02592   connect(myButtons[ BTN_Help   ], SIGNAL(clicked()), SLOT(onHelp()));
02593 
02594   updateMainButtons();
02595 
02596   return aGrp;
02597 }
02598 
02599 //=======================================================================
02600 // name    : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
02601 // Purpose : Destructor
02602 //=======================================================================
02603 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
02604 {
02605 }
02606 
02607 //=======================================================================
02608 // name    : SMESHGUI_FilterDlg::Init
02609 // Purpose : Init dialog fields, connect signals and slots, show dialog
02610 //=======================================================================
02611 void SMESHGUI_FilterDlg::Init (const int type)
02612 {
02613   QList<int> aTypes;
02614   aTypes.append(type);
02615   Init(aTypes);
02616 }
02617 
02618 //=======================================================================
02619 // name    : SMESHGUI_FilterDlg::Init
02620 // Purpose : Init dialog fields, connect signals and slots, show dialog
02621 //=======================================================================
02622 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
02623 {
02624   mySourceWg  = 0;
02625   myTypes     = theTypes;
02626   myMesh      = SMESH::SMESH_Mesh::_nil();
02627   myIObjects.Clear();
02628   myIsSelectionChanged = false;
02629 
02630   myTable->Init(theTypes);
02631 
02632   // set caption
02633   if (theTypes.count() == 1)
02634   {
02635     int aType = theTypes.first();
02636     if      (aType == SMESH::NODE  ) setWindowTitle(tr("NODES_TLT"));
02637     else if (aType == SMESH::EDGE  ) setWindowTitle(tr("EDGES_TLT"));
02638     else if (aType == SMESH::FACE  ) setWindowTitle(tr("FACES_TLT"));
02639     else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
02640     else if (aType == SMESH::ALL)    setWindowTitle(tr("TLT"));
02641   }
02642   else
02643     setWindowTitle(tr("TLT"));
02644 
02645   qApp->processEvents();
02646   updateGeometry();
02647   adjustSize();
02648   setEnabled(true);
02649 
02650   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
02651 
02652   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
02653   connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
02654   
02655   updateMainButtons();
02656   updateSelection();
02657 
02658   // Initialise filter table with values of previous filter
02659   QList<int>::const_iterator anIter;
02660   for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
02661   {
02662     myTable->Clear(*anIter);
02663     if (!myFilter[ *anIter ]->_is_nil())
02664     {
02665       SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
02666       if (myFilter[ *anIter ]->GetCriteria(aCriteria))
02667       {
02668         for (int i = 0, n = aCriteria->length(); i < n; i++)
02669           myTable->AddCriterion(aCriteria[ i ], *anIter);
02670       }
02671     }
02672   }
02673 
02674   if (myInsertState.contains(theTypes.first()))
02675     mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
02676   else
02677     mySetInViewer->setChecked(true);
02678 
02679   mySourceGrp->button(myApplyToState.contains(theTypes.first()) ? 
02680                       myApplyToState[ theTypes.first() ] :
02681                       Mesh)->setChecked(true);
02682 }
02683 
02684 //=======================================================================
02685 // name    : SMESHGUI_FilterDlg::onOk
02686 // Purpose : SLOT called when "Ok" button pressed.
02687 //           Assign filters VTK viewer and close dialog
02688 //=======================================================================
02689 void SMESHGUI_FilterDlg::onOk()
02690 {
02691   if (onApply())
02692   {
02693     mySelectionMgr->clearFilters();
02694     disconnect(mySMESHGUI, 0, this, 0);
02695     disconnect(mySelectionMgr, 0, this, 0);
02696     mySMESHGUI->ResetState();
02697     accept();
02698     emit Accepted();
02699   }
02700 }
02701 
02702 //=======================================================================
02703 // name    : SMESHGUI_FilterDlg::onClose
02704 // Purpose : SLOT called when "Close" button pressed. Close dialog
02705 //=======================================================================
02706 void SMESHGUI_FilterDlg::onClose()
02707 {
02708   // Restore previously selected object
02709   if (mySelectionMgr)
02710   {
02711     SALOME_ListIO aList;
02712     mySelectionMgr->clearFilters();
02713     mySelectionMgr->clearSelected();
02714     SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
02715     for ( ; anIter.More(); anIter.Next())
02716     {
02717       aList.Append(anIter.Key());
02718 
02719       TColStd_MapOfInteger aResMap;
02720       const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
02721       for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
02722         aResMap.Add(anIndMap(i));
02723 
02724       mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
02725       if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02726         aViewWindow->highlight( anIter.Key(), true, true );
02727     }
02728     mySelectionMgr->setSelectedObjects(aList, false);
02729   }
02730 
02731   disconnect(mySMESHGUI, 0, this, 0);
02732   disconnect(mySelectionMgr, 0, this, 0);
02733   mySMESHGUI->ResetState();
02734   reject();
02735   return;
02736 }
02737 
02738 //=================================================================================
02739 // function : onHelp()
02740 // purpose  :
02741 //=================================================================================
02742 void SMESHGUI_FilterDlg::onHelp()
02743 {
02744   LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
02745   if (app) 
02746     app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
02747   else {
02748     QString platform;
02749 #ifdef WIN32
02750     platform = "winapplication";
02751 #else
02752     platform = "application";
02753 #endif
02754     SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
02755                              tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
02756                              arg(app->resourceMgr()->stringValue("ExternalBrowser", 
02757                                                                  platform)).
02758                              arg(myHelpFileName));
02759   }
02760 }
02761 
02762 //=======================================================================
02763 // name    : SMESHGUI_FilterDlg::onDeactivate
02764 // Purpose : SLOT called when dialog must be deativated
02765 //=======================================================================
02766 void SMESHGUI_FilterDlg::onDeactivate()
02767 {
02768   setEnabled(false);
02769 }
02770 
02771 //=======================================================================
02772 // name    : SMESHGUI_FilterDlg::enterEvent
02773 // Purpose : Event filter
02774 //=======================================================================
02775 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
02776 {
02777 //  mySMESHGUI->EmitSignalDeactivateDialog();
02778   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
02779   mySMESHGUI->ResetState();
02780   setEnabled(true);
02781 }
02782 
02783 //=======================================================================
02784 // name    : closeEvent()
02785 // Purpose :
02786 //=======================================================================
02787 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
02788 {
02789   onClose();
02790 }
02791 
02792 //=======================================================================
02793 // name    : SMESHGUI_FilterDlg::getIdsFromWg
02794 // Purpose : Retrieve list of ids from given widget
02795 //=======================================================================
02796 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
02797 {
02798   theRes.clear();
02799   if (theWg == 0)
02800     return;
02801 
02802   if (theWg->inherits("QListWidget"))
02803   {
02804     const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
02805     bool b;
02806     for (int i = 0, n = aListBox->count(); i < n; i++)
02807     {
02808       int anId = aListBox->item(i)->text().toInt(&b);
02809       if (b)
02810         theRes.append(anId);
02811     }
02812   }
02813   else if (theWg->inherits("QLineEdit"))
02814   {
02815     const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
02816     QString aStr = aLineEdit->text();
02817     QRegExp aRegExp("(\\d+)");
02818     bool b;
02819     int aPos = 0;
02820     while (aPos >= 0)
02821     {
02822       aPos = aRegExp.indexIn(aStr, aPos);
02823       if (aPos > -1)
02824       {
02825         int anId = aRegExp.cap(1).toInt(&b);
02826         if (b)
02827           theRes.append(anId);
02828         aPos += aRegExp.matchedLength();
02829       }
02830     }
02831   }
02832 }
02833 
02834 //=======================================================================
02835 // name    : SMESHGUI_FilterDlg::getSelMode
02836 // Purpose : Get selection mode of specified type
02837 //=======================================================================
02838 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
02839 {
02840   switch (theType)
02841   {
02842     case SMESH::NODE   : return NodeSelection;
02843     case SMESH::EDGE   : return EdgeSelection;
02844     case SMESH::FACE   : return FaceSelection;
02845     case SMESH::VOLUME : return VolumeSelection;
02846     case SMESH::ALL    : return CellSelection;
02847     default            : return ActorSelection;
02848   }
02849 
02850 }
02851 
02852 //=======================================================================
02853 // name    : SMESHGUI_FilterDlg::setIdsToWg
02854 // Purpose : Insert identifiers in specified widgets
02855 //=======================================================================
02856 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
02857 {
02858   if (theWg == 0)
02859     return;
02860 
02861   QStringList aStrList;
02862   foreach(int id, theIds)
02863     aStrList << QString::number(id);
02864 
02865   if (theWg->inherits("QListWidget"))
02866   {
02867     qobject_cast<QListWidget*>(theWg)->clear();
02868     qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
02869   }
02870   else if (theWg->inherits("QLineEdit"))
02871   {
02872     qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
02873   }
02874 }
02875 
02876 //=======================================================================
02877 // name    : SMESHGUI_FilterDlg::isValid
02878 // Purpose : Verify validity of input data
02879 //=======================================================================
02880 bool SMESHGUI_FilterDlg::isValid() const
02881 {
02882   if (!myTable->IsValid())
02883     return false;
02884 
02885   for (int i = 0, n = myTable->NumRows(); i < n; i++)
02886   {
02887     int aType = myTable->GetCriterionType(i);
02888     if (aType == SMESH::FT_BelongToGeom ||
02889         aType == SMESH::FT_BelongToPlane ||
02890         aType == SMESH::FT_BelongToCylinder ||
02891         aType == SMESH::FT_BelongToGenSurface ||
02892         aType == SMESH::FT_LyingOnGeom)
02893     {
02894       QString aName;
02895       myTable->GetThreshold(i, aName);
02896 
02897       std::vector<_PTR(SObject)> aList =
02898         SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
02899       if (aList.size() == 0) {
02900         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02901                                      tr("BAD_SHAPE_NAME").arg(aName));
02902         return false;
02903       }
02904 
02905       if (aType == SMESH::FT_BelongToCylinder ||
02906           aType == SMESH::FT_BelongToPlane    ||
02907           aType == SMESH::FT_BelongToGenSurface ) {
02908         CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
02909         //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
02910         GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
02911         if (!aGeomObj->_is_nil()) {
02912           TopoDS_Shape aFace;
02913           if (!GEOMBase::GetShape(aGeomObj, aFace) ||
02914                aFace.IsNull() ||
02915                aFace.ShapeType() != TopAbs_FACE) {
02916             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02917                                          tr("SHAPE_IS_NOT_A_FACE").arg(aName));
02918             return false;
02919           }
02920 
02921           Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
02922           if (aSurf.IsNull()) {
02923             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02924                                          tr("SHAPE_IS_NOT_A_FACE").arg(aName));
02925             return false;
02926           }
02927 
02928           if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
02929             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02930                                          tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
02931             return false;
02932           }
02933 
02934           if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
02935             SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02936                                          tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
02937             return false;
02938           }
02939         }
02940       }
02941     }
02942     else if (aType == SMESH::FT_CoplanarFaces)
02943     {
02944       QString faceID;
02945       myTable->GetThreshold(i, faceID);
02946       if ( faceID.isEmpty() )
02947       {
02948         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02949                                      tr("FACE_ID_NOT_SELECTED"));
02950         return false;
02951       }
02952       if ( myMesh->_is_nil() )
02953       {
02954         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02955                                      tr("MESH_IS_NOT_SELECTED"));
02956         return false;
02957       }
02958       if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
02959       {
02960         SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02961                                      tr("NOT_FACE_ID").arg(faceID));
02962         return false;
02963       }
02964     }
02965   }
02966 
02967   return true;
02968 }
02969 
02970 //=======================================================================
02971 // name    : SMESHGUI_FilterDlg::SetSourceWg
02972 // Purpose : Set widget of parent dialog containing idsto be filtered if
02973 //           user select corresponding source radio button
02974 //=======================================================================
02975 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
02976                                       const bool initOnApply)
02977 {
02978   mySourceWg = theWg;
02979   myInitSourceWgOnApply = initOnApply;
02980 }
02981 
02982 //=======================================================================
02983 // name    : SMESHGUI_FilterDlg::SetMesh
02984 // Purpose : Set mesh
02985 //=======================================================================
02986 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
02987 {
02988   if ( !theMesh->_is_nil() ) {
02989     myMesh = theMesh;
02990     if ( !myFilter[ myTable->GetType() ]->_is_nil())
02991       myFilter[ myTable->GetType() ]->SetMesh( theMesh );
02992   }
02993   const bool isEnable = !(myMesh->_is_nil());
02994   myButtons[BTN_OK]->setEnabled(isEnable);
02995   myButtons[BTN_Apply]->setEnabled(isEnable);
02996 }
02997 
02998 //=======================================================================
02999 // name    : SMESHGUI_FilterDlg::SetSelection
03000 // Purpose : Get filtered ids
03001 //=======================================================================
03002 void SMESHGUI_FilterDlg::SetSelection()
03003 {
03004   if (mySelectionMgr)
03005     disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
03006 
03007   if (mySelectionMgr) {
03008     myIObjects.Clear();
03009     const SALOME_ListIO& anObjs = mySelector->StoredIObjects(); 
03010     SALOME_ListIteratorOfListIO anIter (anObjs);
03011     for ( ; anIter.More(); anIter.Next()) {
03012       TColStd_IndexedMapOfInteger aMap;
03013       mySelector->GetIndex(anIter.Value(), aMap);
03014       myIObjects.Bind(anIter.Value(), aMap);
03015     }
03016 
03017     connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
03018 
03019     updateSelection();
03020   }
03021   else
03022     myIObjects.Clear();
03023 }
03024 
03025 //=======================================================================
03026 // name    : SMESHGUI_FilterDlg::onApply
03027 // Purpose : SLOT called when "Apply" button pressed.
03028 //           Assign filters to VTK viewer
03029 //=======================================================================
03030 bool SMESHGUI_FilterDlg::onApply()
03031 {
03032   if (!isValid())
03033     return false;
03034 
03035   try {
03036     int aCurrType = myTable->GetType();
03037 
03038     if (!createFilter(aCurrType))
03039       return false;
03040 
03041     insertFilterInViewer();
03042 
03043     if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
03044       QList<int> aResultIds;
03045       filterSource(aCurrType, aResultIds);
03046       // select in viewer
03047       selectInViewer(aCurrType, aResultIds);
03048     }
03049 
03050 
03051     myInsertState[ aCurrType ] = mySetInViewer->isChecked();
03052     myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
03053   }
03054   catch(const SALOME::SALOME_Exception& S_ex)
03055   {
03056     SalomeApp_Tools::QtCatchCorbaException(S_ex);
03057   }
03058   catch(...)
03059   {
03060   }
03061 
03062   return true;
03063 }
03064 
03065 //=======================================================================
03066 // name    : SMESHGUI_FilterDlg::createFilter
03067 // Purpose : Create predicate for given type
03068 //=======================================================================
03069 bool SMESHGUI_FilterDlg::createFilter (const int theType)
03070 {
03071   SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
03072   if (aFilterMgr->_is_nil())
03073     return false;
03074 
03075   int n = myTable->NumRows();
03076 
03077   SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
03078   aCriteria->length(n);
03079 
03080   long aPrecision = -1;
03081   SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
03082 
03083   if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
03084     aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
03085 
03086   for (CORBA::ULong i = 0; i < n; i++) {
03087     SMESH::Filter::Criterion aCriterion = createCriterion();
03088     myTable->GetCriterion(i, aCriterion);
03089     aCriterion.Precision = aPrecision;
03090     aCriteria[ i ] = aCriterion;
03091   }
03092 
03093   myFilter[ theType ] = aFilterMgr->CreateFilter();
03094   myFilter[ theType ]->SetCriteria(aCriteria.inout());
03095 
03096   return true;
03097 }
03098 
03099 //================================================================================
03103 //================================================================================
03104 
03105 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
03106 {
03107   SMESH::Filter_var filter;
03108   try {
03109     int aCurrType = myTable->GetType();
03110     filter = myFilter[ aCurrType ];
03111   }
03112   catch(...)
03113   {
03114   }
03115   return filter._retn();
03116 }
03117 
03118 //================================================================================
03122 //================================================================================
03123 
03124 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
03125 {
03126   myFilter[ type ] = filter;
03127 }
03128 
03129 //=======================================================================
03130 // name    : SMESHGUI_FilterDlg::insertFilterInViewer
03131 // Purpose : Insert filter in viewer
03132 //=======================================================================
03133 void SMESHGUI_FilterDlg::insertFilterInViewer()
03134 {
03135   if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
03136     SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
03137 
03138     if (myFilter[ myTable->GetType() ]->_is_nil() ||
03139          myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
03140          !mySetInViewer->isChecked()) {
03141       SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
03142     }
03143     else {
03144       Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
03145       aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
03146       SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
03147       SMESH::SetFilter(aFilter, aSelector);
03148     }
03149   }
03150 }
03151 
03152 //=======================================================================
03153 // name    : SMESHGUI_FilterDlg::filterSource
03154 // Purpose : Filter source ids
03155 //=======================================================================
03156 void SMESHGUI_FilterDlg::filterSource (const int theType,
03157                                        QList<int>& theResIds)
03158 {
03159   theResIds.clear();
03160   if (myFilter[ theType ]->_is_nil())
03161     return;
03162 
03163   int aSourceId = mySourceGrp->checkedId();
03164 
03165   if (aSourceId == Mesh)
03166   {
03167     if (myMesh->_is_nil())
03168       return;
03169     SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
03170     for (int i = 0, n = anIds->length(); i < n; i++)
03171       theResIds.append(anIds[ i ]);
03172   }
03173   else if (aSourceId == Selection)
03174   {
03175     filterSelectionSource(theType, theResIds);
03176   }
03177   else if (aSourceId == Dialog)
03178   {
03179     // retrieve ids from dialog
03180     QList<int> aDialogIds;
03181     getIdsFromWg(mySourceWg, aDialogIds);
03182 
03183     if (myMesh->_is_nil())
03184     {
03185       theResIds = aDialogIds;
03186       return;
03187     }
03188 
03189     // filter ids
03190     SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
03191     myFilter[ theType ]->SetMesh(myMesh);
03192     QList<int>::const_iterator anIter;
03193     for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
03194       if (aPred->IsSatisfy(*anIter))
03195         theResIds.append(*anIter);
03196   }
03197   // set ids to the dialog
03198   if (myInitSourceWgOnApply || aSourceId == Dialog)
03199     setIdsToWg(mySourceWg, theResIds);
03200 }
03201 
03202 //=======================================================================
03203 // name    : SMESHGUI_FilterDlg::filterSelectionSource
03204 // Purpose : Filter source selection
03205 //=======================================================================
03206 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
03207                                                 QList<int>& theResIds)
03208 {
03209   theResIds.clear();
03210   if (myMesh->_is_nil() || mySelectionMgr == 0)
03211     return;
03212 
03213   // Create map of entities to be filtered
03214   TColStd_MapOfInteger aToBeFiltered;
03215   SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
03216 
03217   for ( ; anIter.More(); anIter.Next())
03218   {
03219     // process sub mesh
03220     SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
03221     if (!aSubMesh->_is_nil())
03222     {
03223       if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
03224       {
03225         SMESH::long_array_var anIds =
03226           theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
03227         for (int i = 0, n = anIds->length(); i < n; i++)
03228           aToBeFiltered.Add(anIds[ i ]);
03229       }
03230     }
03231 
03232     // process group
03233     SMESH::SMESH_GroupBase_var aGroup =
03234       SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
03235     if (!aGroup->_is_nil())
03236     {
03237       if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
03238       {
03239         SMESH::long_array_var anIds = aGroup->GetListOfID();
03240         for (int i = 0, n = anIds->length(); i < n; i++)
03241           aToBeFiltered.Add(anIds[ i ]);
03242       }
03243     }
03244 
03245     // process mesh
03246     SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
03247     if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
03248     {
03249       const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
03250 
03251       if (aSelMap.Extent() > 0)
03252       {
03253         if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
03254         {
03255           for (int i = 1; i <= aSelMap.Extent(); i++)
03256             aToBeFiltered.Add(aSelMap(i));
03257         }
03258       }
03259     }
03260   }
03261 
03262   // Filter entities
03263   SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
03264   myFilter[ theType ]->SetMesh(myMesh);
03265   TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
03266   for ( ; aResIter.More(); aResIter.Next())
03267     if (aPred->IsSatisfy(aResIter.Key()))
03268       theResIds.append(aResIter.Key());
03269 }
03270 
03271 //=======================================================================
03272 // name    : SMESHGUI_FilterDlg::selectInViewer
03273 // Purpose : Select given entities in viewer
03274 //=======================================================================
03275 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
03276 {
03277   if (mySelectionMgr == 0 || myMesh->_is_nil())
03278     return;
03279 
03280   mySelectionMgr->clearFilters();
03281 
03282   // Set new selection mode if necessary
03283   Selection_Mode aSelMode = getSelMode(theType);
03284   SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
03285   if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
03286     mySelectionMgr->clearSelected();
03287     mySelectionMgr->clearFilters();
03288     if (aSelMode == NodeSelection)
03289       SMESH::SetPointRepresentation(true);
03290     aViewWindow->SetSelectionMode(aSelMode);
03291   }
03292 
03293   // Clear selection
03294   SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
03295   if (!anActor || !anActor->hasIO())
03296     return;
03297 
03298   Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
03299   //mySelectionMgr->clearSelected();
03300   //mySelectionMgr->AddIObject(anIO, false);
03301   SALOME_ListIO aList;
03302   aList.Append(anIO);
03303   mySelectionMgr->setSelectedObjects(aList, false);
03304 
03305   // Remove filter corresponding to the current type from viewer
03306   int aType = myTable->GetType();
03307   int aFilterId = SMESH::UnknownFilter;
03308   if      (aType == SMESH::EDGE  ) aFilterId = SMESH::EdgeFilter;
03309   else if (aType == SMESH::FACE  ) aFilterId = SMESH::FaceFilter;
03310   else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
03311   Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
03312   SMESH::RemoveFilter(aFilterId);
03313 
03314   // get vtk ids
03315   TColStd_MapOfInteger aMap;
03316   QList<int>::const_iterator anIter;
03317   for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
03318     aMap.Add(*anIter);
03319   }
03320 
03321   // Set new selection
03322   mySelector->AddOrRemoveIndex(anIO, aMap, false);
03323   if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
03324     aViewWindow->highlight( anIO, true, true );
03325 
03326   // insert previously stored filter in viewer if necessary
03327   if (!aFilter.IsNull())
03328     SMESH::SetFilter(aFilter);
03329 }
03330 
03331 //=======================================================================
03332 // name    : SMESHGUI_FilterDlg::createCriterion
03333 // Purpose : Create criterion structure with default values
03334 //=======================================================================
03335 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
03336 {
03337    SMESH::Filter::Criterion aCriterion;
03338 
03339   aCriterion.Type          = SMESH::FT_Undefined;
03340   aCriterion.Compare       = SMESH::FT_Undefined;
03341   aCriterion.Threshold     = 0;
03342   aCriterion.UnaryOp       = SMESH::FT_Undefined;
03343   aCriterion.BinaryOp      = SMESH::FT_Undefined;
03344   aCriterion.ThresholdStr  = "";
03345   aCriterion.ThresholdID   = "";
03346   aCriterion.TypeOfElement = SMESH::ALL;
03347 
03348   return aCriterion;
03349 }
03350 
03351 //=======================================================================
03352 // name    : SMESHGUI_FilterDlg::onSelectionDone
03353 // Purpose : SLOT called when selection changed.
03354 //           If current cell corresponds to the threshold value of
03355 //           BelongToGeom criterion name of selected object is set in this cell
03356 //=======================================================================
03357 void SMESHGUI_FilterDlg::onSelectionDone()
03358 {
03359   int aRow, aCol;
03360   const SALOME_ListIO& aList = mySelector->StoredIObjects();
03361 
03362   if ( myMesh->_is_nil() && aList.Extent()>0 ) {
03363     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
03364     if ( !(myMesh->_is_nil()) ) {
03365       myButtons[BTN_OK]->setEnabled(true);
03366       myButtons[BTN_Apply]->setEnabled(true);
03367     }
03368   }
03369 
03370   QList<int> types; 
03371   types << SMESH::FT_BelongToGeom     << SMESH::FT_BelongToPlane 
03372         << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
03373         << SMESH::FT_LyingOnGeom      << SMESH::FT_CoplanarFaces;
03374   if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) || 
03375       !types.contains(myTable->GetCriterionType(aRow)))
03376     return;
03377 
03378   if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
03379   {
03380     QString aString;
03381     int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
03382                                                    aList.First(), aString);
03383     if (nbElems == 1)
03384       myTable->SetThreshold(aRow, aString);
03385   }
03386   else
03387   {
03388     Handle(SALOME_InteractiveObject) anIO = aList.First();
03389     GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
03390     if (!anObj->_is_nil())
03391     {
03392       myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
03393       //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
03394       myTable->SetID(aRow, anIO->getEntry());
03395     }
03396   }
03397 }
03398 
03399 
03400 //=======================================================================
03401 // name    : SMESHGUI_FilterDlg::onCriterionChanged
03402 // Purpose : SLOT called when cretarion of current row changed. Update selection
03403 //=======================================================================
03404 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
03405 {
03406   updateSelection();
03407 }
03408 
03409 //=======================================================================
03410 // name    : SMESHGUI_FilterDlg::onCurrentChanged
03411 // Purpose : SLOT called when current row changed. Update selection
03412 //=======================================================================
03413 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
03414 {
03415   updateSelection();
03416 }
03417 
03418 //=======================================================================
03419 // name    : SMESHGUI_FilterDlg::updateSelection
03420 // Purpose : UpdateSelection in accordance with current row
03421 //=======================================================================
03422 void SMESHGUI_FilterDlg::updateSelection()
03423 {
03424   if (mySelectionMgr == 0)
03425     return;
03426 
03427 //   TColStd_MapOfInteger allTypes;
03428 //   for( int i=0; i<10; i++ )
03429 //     allTypes.Add( i );
03430   SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
03431   if( !aStudy )
03432     return;
03433 
03434 
03435   mySelectionMgr->clearFilters();
03436 
03437   int aRow, aCol;
03438   
03439   bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
03440   int aCriterionType = myTable->GetCriterionType(aRow);
03441   if ( isCurrentCell &&
03442       (aCriterionType == SMESH::FT_BelongToGeom ||
03443        aCriterionType == SMESH::FT_BelongToPlane ||
03444        aCriterionType == SMESH::FT_BelongToCylinder ||
03445        aCriterionType == SMESH::FT_BelongToGenSurface ||
03446        aCriterionType == SMESH::FT_LyingOnGeom))
03447   {
03448     if (aCriterionType == SMESH::FT_BelongToGeom ||
03449         aCriterionType == SMESH::FT_BelongToGenSurface ||
03450         aCriterionType == SMESH::FT_LyingOnGeom) {
03451 
03452       mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
03453 
03454     } else if (aCriterionType == SMESH::FT_BelongToPlane) {
03455       mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
03456 
03457     } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
03458       mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
03459     }
03460     myIsSelectionChanged = true;
03461 
03462   }
03463   else
03464   {
03465     if (myIsSelectionChanged) {
03466       // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
03467       // Impossible to select any object in the OB on the second opening of FilterDlg
03468     }
03469   }
03470 }
03471 
03472 //=================================================================================
03473 // function : keyPressEvent()
03474 // purpose  :
03475 //=================================================================================
03476 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
03477 {
03478   QDialog::keyPressEvent( e );
03479   if ( e->isAccepted() )
03480     return;
03481 
03482   if ( e->key() == Qt::Key_F1 ) {
03483     e->accept();
03484     onHelp();
03485   }
03486 }