00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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
00043 #include <GEOMBase.h>
00044 #include <GEOM_FaceFilter.h>
00045 #include <GEOM_TypeFilter.h>
00046
00047
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
00068 #include <SALOMEDSClient_Study.hxx>
00069
00070
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
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
00108 #include <SALOMEconfig.h>
00109 #include CORBA_SERVER_HEADER(SMESH_Group)
00110
00111 #define SPACING 6
00112 #define MARGIN 11
00113
00114
00115
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
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
00144
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 );
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
00331
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
00417
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
00477
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
00524
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
00586
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
00704
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
00730
00731
00732 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
00733 : QTableWidget(parent)
00734 {
00735
00736 setItemDelegate( new ComboDelegate(this) );
00737
00738 setReadOnly( false );
00739 }
00740
00741
00742
00743
00744
00745 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
00746 : QTableWidget(numRows, numCols, parent)
00747 {
00748
00749 setItemDelegate( new ComboDelegate(this) );
00750
00751 setReadOnly( false );
00752 }
00753
00754
00755
00756
00757
00758 SMESHGUI_FilterTable::Table::~Table()
00759 {
00760 }
00761
00762
00763
00764
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
00777
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
00798
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
00820
00821
00822 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
00823 {
00824 closePersistentEditor( currentItem() );
00825 while ( count-- ) insertRow( row );
00826 }
00827
00828
00829
00830
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
00856
00857
00858
00859
00860
00861
00862
00863
00864
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
00882
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
00901
00902
00903 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
00904 {
00905 if (theTypes.isEmpty())
00906 return;
00907
00908
00909
00910 if (myTables.isEmpty())
00911 {
00912
00913 QVBoxLayout* aMainLay = new QVBoxLayout(this);
00914 aMainLay->setMargin( 0 );
00915 aMainLay->setSpacing( SPACING );
00916
00917
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
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
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
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
00988 aMainLay->addWidget(myEntityTypeBox);
00989 aMainLay->addWidget(myTableGrp);
00990
00991
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
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
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
01030
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
01060
01061
01062 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
01063 {
01064 return myTableGrp;
01065 }
01066
01067
01068
01069
01070
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
01106
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
01165
01166
01167 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
01168 {
01169 myIsValid = isValid;
01170 }
01171
01172
01173
01174
01175
01176 int SMESHGUI_FilterTable::GetType() const
01177 {
01178 return myEntityType;
01179 }
01180
01181
01182
01183
01184
01185 void SMESHGUI_FilterTable::SetType (const int type)
01186 {
01187 myEntityTypeGrp->button(type)->setChecked(true);
01188 onEntityType(type);
01189 }
01190
01191
01192
01193
01194
01195 void SMESHGUI_FilterTable::RestorePreviousEntityType()
01196 {
01197 SetType(myEntityType);
01198 }
01199
01200
01201
01202
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
01214
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
01270
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 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
01286 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
01287
01288 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
01289 {
01290 if (!aTable->isEditable(theRow, 4))
01291 aTable->setItem(theRow, 4, getBinaryItem());
01292 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
01293 }
01294 else
01295 aTable->setEditable(false, theRow, 4);
01296
01297 if (theCriterion.Type == SMESH::FT_GroupColor )
01298 {
01299 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
01300 if ( clrBtn )
01301 {
01302 QColor qClr;
01303 QString clrStr( theCriterion.ThresholdStr );
01304 QStringList clrVals = clrStr.split( ";" );
01305 if ( clrVals.count() > 2 )
01306 qClr.setRgb( (int)256*clrVals[0].toDouble(),
01307 (int)256*clrVals[1].toDouble(),
01308 (int)256*clrVals[2].toDouble() );
01309 clrBtn->setColor( qClr );
01310 }
01311 }
01312 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
01313 {
01314 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
01315 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
01316 }
01317 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
01318 {
01319 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
01320 }
01321 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
01322 theCriterion.Type != SMESH::FT_BelongToGeom &&
01323 theCriterion.Type != SMESH::FT_BelongToPlane &&
01324 theCriterion.Type != SMESH::FT_BelongToCylinder &&
01325 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
01326 theCriterion.Type != SMESH::FT_LyingOnGeom &&
01327 theCriterion.Type != SMESH::FT_CoplanarFaces &&
01328 theCriterion.Type != SMESH::FT_FreeBorders &&
01329 theCriterion.Type != SMESH::FT_FreeEdges &&
01330 theCriterion.Type != SMESH::FT_FreeNodes &&
01331 theCriterion.Type != SMESH::FT_FreeFaces &&
01332 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
01333 theCriterion.Type != SMESH::FT_BareBorderFace &&
01334 theCriterion.Type != SMESH::FT_BareBorderVolume &&
01335 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
01336 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
01337 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
01338 {
01339 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
01340 }
01341 else
01342 {
01343 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
01344 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
01345 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
01346 }
01347
01348 if (theCriterion.Compare == SMESH::FT_EqualTo ||
01349 theCriterion.Type == SMESH::FT_BelongToPlane ||
01350 theCriterion.Type == SMESH::FT_BelongToCylinder ||
01351 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
01352 theCriterion.Type == SMESH::FT_BelongToGeom ||
01353 theCriterion.Type == SMESH::FT_LyingOnGeom ||
01354 theCriterion.Type == SMESH::FT_CoplanarFaces)
01355 {
01356 QTableWidgetItem* anItem = aTable->item(theRow, 0);
01357 if (!myAddWidgets.contains(anItem))
01358 {
01359 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
01360 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
01361 myWgStack->addWidget(myAddWidgets[ anItem ]);
01362 }
01363 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
01364 }
01365
01366 emit CriterionChanged(theRow, aType);
01367 }
01368
01369
01370
01371
01372
01373 void SMESHGUI_FilterTable::Update()
01374 {
01375 Table* aTable = myTables[ GetType() ];
01376 int aCurrRow = aTable->currentRow();
01377 int numRows = aTable->rowCount();
01378 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
01379 aTable->setCurrentCell(0, 0);
01380 updateAdditionalWidget();
01381 }
01382
01383
01384
01385
01386
01387 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
01388 const int theEntityType)
01389 {
01390 int aType = theEntityType == -1 ? GetType() : theEntityType;
01391 Table* aTable = myTables[ aType ];
01392 addRow(aTable, aType);
01393 SetCriterion(aTable->rowCount() - 1, theCriterion);
01394 }
01395
01396
01397
01398
01399
01400 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
01401 {
01402 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
01403 }
01404
01405
01406
01407
01408
01409 void SMESHGUI_FilterTable::Clear (const int theType)
01410 {
01411 int aType = theType == -1 ? GetType() : theType;
01412 Table* aTable = myTables[ aType ];
01413
01414 if (aTable->rowCount() == 0)
01415 return;
01416
01417 while (aTable->rowCount() > 0)
01418 {
01419 removeAdditionalWidget(aTable, 0);
01420 aTable->removeRow(0);
01421 }
01422
01423 updateBtnState();
01424 }
01425
01426
01427
01428
01429
01430
01431 void SMESHGUI_FilterTable::onAddBtn()
01432 {
01433 int aType = GetType();
01434 addRow(myTables[ aType ], aType);
01435
01436 Update();
01437 }
01438
01439
01440
01441
01442
01443
01444 void SMESHGUI_FilterTable::onInsertBtn()
01445 {
01446 addRow(myTables[ GetType() ], GetType(), false);
01447 }
01448
01449
01450
01451
01452
01453
01454 void SMESHGUI_FilterTable::onRemoveBtn()
01455 {
01456 Table* aTable = myTables[ GetType() ];
01457
01458 if (aTable->rowCount() == 0)
01459 return;
01460
01461 QList<QTableWidgetItem*> items = aTable->selectedItems();
01462
01463 QList<int> aRows = aTable->selectedRows();
01464 int i;
01465 foreach( i, aRows )
01466 {
01467 removeAdditionalWidget(aTable, i);
01468 aTable->removeRow(i);
01469 }
01470
01471
01472 if (aTable->rowCount() > 0)
01473 aTable->setEditable(false, aTable->rowCount() - 1, 4);
01474
01475 updateBtnState();
01476 }
01477
01478
01479
01480
01481
01482 void SMESHGUI_FilterTable::updateAdditionalWidget()
01483 {
01484 Table* aTable = myTables[ GetType() ];
01485 int aRow = aTable->currentRow();
01486 if (aRow < 0 || aRow >= aTable->rowCount())
01487 {
01488 myWgStack->setEnabled(false);
01489 return;
01490 }
01491
01492 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
01493 int aCriterion = GetCriterionType(aRow);
01494 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
01495 aCriterion != SMESH::FT_RangeOfIds &&
01496 aCriterion != SMESH::FT_FreeEdges &&
01497 aCriterion != SMESH::FT_FreeFaces &&
01498 aCriterion != SMESH::FT_BadOrientedVolume &&
01499 aCriterion != SMESH::FT_BareBorderFace &&
01500 aCriterion != SMESH::FT_BareBorderVolume &&
01501 aCriterion != SMESH::FT_OverConstrainedFace &&
01502 aCriterion != SMESH::FT_OverConstrainedVolume)
01503 ||
01504 aCriterion == SMESH::FT_CoplanarFaces);
01505
01506 if (!myAddWidgets.contains(anItem))
01507 {
01508 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
01509 myWgStack->addWidget(myAddWidgets[ anItem ]);
01510 }
01511
01512 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
01513 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
01514 myWgStack->setEnabled(toEnable);
01515 }
01516
01517 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
01518 {
01519 const char* retval = 0;
01520 switch ( aType ) {
01521 case SMESH::FT_AspectRatio:
01522 case SMESH::FT_AspectRatio3D:
01523 case SMESH::FT_Taper:
01524 retval = "parametric_precision"; break;
01525 case SMESH::FT_Warping:
01526 case SMESH::FT_MinimumAngle:
01527 case SMESH::FT_Skew:
01528 case SMESH::FT_CoplanarFaces:
01529 retval = "angle_precision"; break;
01530 case SMESH::FT_Area:
01531 retval = "area_precision"; break;
01532 case SMESH::FT_BelongToGeom:
01533 case SMESH::FT_BelongToPlane:
01534 case SMESH::FT_BelongToCylinder:
01535 case SMESH::FT_BelongToGenSurface:
01536 case SMESH::FT_LyingOnGeom:
01537 retval = "len_tol_precision"; break;
01538 case SMESH::FT_Length:
01539 case SMESH::FT_Length2D:
01540 case SMESH::FT_MaxElementLength2D:
01541 case SMESH::FT_MaxElementLength3D:
01542 retval = "length_precision"; break;
01543 case SMESH::FT_Volume3D:
01544 retval = "vol_precision"; break;
01545 default:
01546 break;
01547 }
01548 return retval;
01549 }
01550
01551
01552
01553
01554
01555
01556 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
01557 {
01558 QTableWidgetItem* anItem = theTable->item(theRow, 0);
01559 if (myAddWidgets.contains(anItem))
01560 {
01561 myWgStack->removeWidget(myAddWidgets[ anItem ]);
01562 myAddWidgets[ anItem ]->setParent(0);
01563 delete myAddWidgets[ anItem ];
01564 myAddWidgets.remove(anItem);
01565 }
01566 }
01567
01568
01569
01570
01571
01572
01573 void SMESHGUI_FilterTable::onClearBtn()
01574 {
01575 Table* aTable = myTables[ GetType() ];
01576
01577 if (aTable->rowCount() == 0)
01578 return;
01579
01580 while (aTable->rowCount() > 0)
01581 {
01582 removeAdditionalWidget(aTable, 0);
01583 aTable->removeRow(0);
01584 }
01585
01586 updateBtnState();
01587 }
01588
01589
01590
01591
01592
01593 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
01594 {
01595 if( !myIsLocked )
01596 updateAdditionalWidget();
01597 emit CurrentChanged(theRow, theCol);
01598 }
01599
01600
01601
01602
01603
01604 static QList<int> geomTypes( const int theType )
01605 {
01606 QList<int> typeIds;
01607 if ( theType == SMESH::NODE )
01608 typeIds.append( SMESH::Geom_POINT );
01609 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
01610 typeIds.append( SMESH::Geom_EDGE );
01611 if ( theType == SMESH::ALL || theType == SMESH::FACE )
01612 {
01613 typeIds.append( SMESH::Geom_TRIANGLE );
01614 typeIds.append( SMESH::Geom_QUADRANGLE );
01615 typeIds.append( SMESH::Geom_POLYGON );
01616 }
01617 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
01618 {
01619 typeIds.append( SMESH::Geom_TETRA );
01620 typeIds.append( SMESH::Geom_PYRAMID );
01621 typeIds.append( SMESH::Geom_HEXA );
01622 typeIds.append( SMESH::Geom_PENTA );
01623 typeIds.append( SMESH::Geom_POLYHEDRA );
01624 }
01625 return typeIds;
01626 }
01627
01628
01629
01630
01631
01632 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
01633 {
01634 int aType = entityType == -1 ? GetType() : entityType;
01635 Table* aTable = myTables[ aType ];
01636 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
01637
01638 int aCriterionType = GetCriterionType(row);
01639 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
01640 int aComboType = ComboItem::Type();
01641 int aIntSpinType = IntSpinItem::Type();
01642 int aDoubleSpinType = DoubleSpinItem::Type();
01643 QTableWidgetItem* aTableItem = aTable->item(row, 2);
01644 bool isComboItem = false;
01645 bool isIntSpinItem = false;
01646 bool isDoubleSpinItem = false;
01647 if (aTableItem) {
01648 int aTableType = aTable->item(row, 2)->type();
01649 isComboItem = ( aTableType == aComboType );
01650 isIntSpinItem = ( aTableType == aIntSpinType );
01651 isDoubleSpinItem = ( aTableType == aDoubleSpinType );
01652 }
01653
01654 bool anIsDoubleCriterion =
01655 aCriterionType == SMESH::FT_AspectRatio ||
01656 aCriterionType == SMESH::FT_AspectRatio3D ||
01657 aCriterionType == SMESH::FT_Taper ||
01658 aCriterionType == SMESH::FT_Warping ||
01659 aCriterionType == SMESH::FT_MinimumAngle ||
01660 aCriterionType == SMESH::FT_Skew ||
01661 aCriterionType == SMESH::FT_Area ||
01662 aCriterionType == SMESH::FT_Length ||
01663 aCriterionType == SMESH::FT_Length2D ||
01664 aCriterionType == SMESH::FT_MaxElementLength2D ||
01665 aCriterionType == SMESH::FT_MaxElementLength3D ||
01666 aCriterionType == SMESH::FT_Volume3D;
01667
01668 int aPrecision = 0;
01669 if ( anIsDoubleCriterion ) {
01670 const char* aPrecisionType = getPrecision( aCriterionType );
01671 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
01672 if( aPrecisionType && aResourceMgr )
01673 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
01674 }
01675
01676
01677
01678 bool anIsPrecisionChanged = false;
01679 if ( anIsDoubleCriterion && isDoubleSpinItem ) {
01680 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
01681 anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
01682 }
01683 }
01684
01685 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
01686 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
01687 (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
01688 (!anIsDoubleCriterion && isDoubleSpinItem) ||
01689 anIsPrecisionChanged )
01690 {
01691 bool isSignalsBlocked = aTable->signalsBlocked();
01692 aTable->blockSignals( true );
01693 aTable->removeCellWidget( row, 2 );
01694 aTable->setItem( row, 2, new QTableWidgetItem() );
01695 aTable->blockSignals( isSignalsBlocked );
01696 }
01697 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
01698 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
01699 (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
01700 (anIsDoubleCriterion && !isDoubleSpinItem) ||
01701 anIsPrecisionChanged )
01702 {
01703 bool isSignalsBlocked = aTable->signalsBlocked();
01704 aTable->blockSignals( true );
01705 if ( aCriterionType == SMESH::FT_GroupColor )
01706 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
01707 else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
01708 QList<int> typeIds = geomTypes( aType );
01709 QMap<int, QString> typeNames;
01710 QList<int>::const_iterator anIter = typeIds.begin();
01711 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
01712 {
01713 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
01714 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
01715 }
01716 ComboItem* typeBox = new ComboItem( typeNames );
01717 aTable->setItem( row, 2, typeBox );
01718 }
01719 else if ( aCriterionType == SMESH::FT_MultiConnection ) {
01720 IntSpinItem* intSpin = new IntSpinItem( 0 );
01721 aTable->setItem( row, 2, intSpin );
01722 }
01723 else if ( anIsDoubleCriterion ) {
01724 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
01725 dblSpin->setPrecision( aPrecision );
01726 aTable->setItem( row, 2, dblSpin );
01727 }
01728 aTable->blockSignals( isSignalsBlocked );
01729 }
01730
01731 if ((aType == SMESH::NODE && aCriterionType == SMESH::FT_FreeNodes ) ||
01732 (aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ) ||
01733 (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace ||
01734 aCriterionType == SMESH::FT_OverConstrainedFace ||
01735 aCriterionType == SMESH::FT_FreeEdges ||
01736 aCriterionType == SMESH::FT_FreeFaces)) ||
01737 (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume ||
01738 aCriterionType == SMESH::FT_OverConstrainedVolume ||
01739 aCriterionType == SMESH::FT_BareBorderVolume)) ||
01740 aCriterionType == SMESH::FT_LinearOrQuadratic ||
01741 aCriterionType == SMESH::FT_GroupColor ||
01742 aCriterionType == SMESH::FT_ElemGeomType ||
01743 aCriterionType == SMESH::FT_CoplanarFaces
01744 )
01745 {
01746 bool isSignalsBlocked = aTable->signalsBlocked();
01747 aTable->blockSignals( true );
01748
01749 if (aCompareItem->count() > 0)
01750 aCompareItem->clear();
01751 aTable->setEditable(false, row, 1);
01752 aTable->item(row, 2)->setText( QString("") );
01753 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
01754 aCriterionType == SMESH::FT_ElemGeomType ||
01755 aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
01756 aTable->blockSignals( isSignalsBlocked );
01757 }
01758 else if (aCriterionType == SMESH::FT_RangeOfIds ||
01759 aCriterionType == SMESH::FT_BelongToGeom ||
01760 aCriterionType == SMESH::FT_BelongToPlane ||
01761 aCriterionType == SMESH::FT_BelongToCylinder ||
01762 aCriterionType == SMESH::FT_BelongToGenSurface ||
01763 aCriterionType == SMESH::FT_LyingOnGeom)
01764 {
01765 QMap<int, QString> aMap;
01766 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
01767 aCompareItem->setItems(aMap);
01768 if (!aTable->isEditable(row, 2))
01769 aTable->setEditable(true, row, 1);
01770 if (!aTable->isEditable(row, 2))
01771 aTable->setEditable(true, row, 2);
01772 }
01773 else if (aCriterionType == SMESH::FT_GroupColor ||
01774 aCriterionType == SMESH::FT_ElemGeomType)
01775 {
01776 if (!aTable->isEditable(row, 2))
01777 aTable->setEditable(true, row, 2);
01778 }
01779 else
01780 {
01781 if (aCompareItem && aCompareItem->count() != 3)
01782 {
01783 aCompareItem->setItems(getCompare());
01784 }
01785
01786 if (aTable->item( row, 2 )) {
01787 QString aText = aTable->text(row, 2);
01788 bool isOk = false;
01789 aText.toDouble(&isOk);
01790 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
01791 if (!aTable->isEditable(row, 1))
01792 aTable->setEditable(true, row, 1);
01793 if (!aTable->isEditable(row, 2))
01794 aTable->setEditable(true, row, 2);
01795 }
01796 }
01797
01798 updateAdditionalWidget();
01799
01800 emit CriterionChanged(row, entityType);
01801 }
01802
01803
01804
01805
01806
01807
01808 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
01809 {
01810 if( col == 0 )
01811 onCriterionChanged(row, col, -1);
01812 }
01813
01814
01815
01816
01817
01818 int SMESHGUI_FilterTable::getFirstSelectedRow() const
01819 {
01820 Table* aTable = myTables[ GetType() ];
01821
01822 QList<int> selRows = aTable->selectedRows();
01823 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
01824
01825 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
01826 }
01827
01828
01829
01830
01831
01832 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
01833 {
01834 int aCurrRow = 0;
01835 int aSelectedRow = getFirstSelectedRow();
01836 int aCurrCol = theTable->currentColumn();
01837
01838 myIsLocked = true;
01839 if (toTheEnd || aSelectedRow == -1)
01840 {
01841 theTable->insertRows(theTable->rowCount());
01842 aCurrRow = theTable->rowCount() - 1;
01843 }
01844 else
01845 {
01846 theTable->insertRows(aSelectedRow);
01847 aCurrRow = aSelectedRow;
01848 }
01849 myIsLocked = false;
01850
01851
01852 bool isSignalsBlocked = theTable->signalsBlocked();
01853 theTable->blockSignals( true );
01854
01855
01856 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
01857
01858
01859 theTable->setItem(aCurrRow, 1, getCompareItem());
01860
01861
01862 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
01863
01864
01865 theTable->setItem(aCurrRow, 3, getUnaryItem());
01866
01867
01868 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
01869
01870 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
01871
01872 theTable->blockSignals( isSignalsBlocked );
01873
01874
01875 int anAddBinOpStr = -1;
01876 if (aCurrRow == theTable->rowCount() - 1)
01877 anAddBinOpStr = aCurrRow - 1;
01878 else if (aCurrRow >= 0 )
01879 anAddBinOpStr = aCurrRow;
01880
01881 if (theTable->item(aCurrRow, 4) == 0 ||
01882 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
01883 {
01884 if (anAddBinOpStr >= 0 &&
01885 (theTable->item(anAddBinOpStr, 4) == 0 ||
01886 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
01887 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
01888 }
01889
01890 theTable->setEditable(false, theTable->rowCount() - 1, 4);
01891
01892 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
01893 aCurrCol >=0 && aCurrCol < theTable->rowCount())
01894 theTable->setCurrentCell(aCurrRow, aCurrCol);
01895
01896 onCriterionChanged(aCurrRow, 0);
01897
01898 updateBtnState();
01899 }
01900
01901
01902
01903
01904
01905 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
01906 {
01907 return new ComboItem(getCriteria(theType));
01908 }
01909
01910
01911
01912
01913
01914 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
01915 {
01916 return new ComboItem(getCompare());
01917 }
01918
01919
01920
01921
01922
01923 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
01924 {
01925 static QMap<int, QString> aMap;
01926 if (aMap.isEmpty())
01927 {
01928 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
01929 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
01930 }
01931
01932 return new ComboItem(aMap);
01933 }
01934
01935
01936
01937
01938
01939 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
01940 {
01941 return new CheckItem(tr("NOT"));
01942 }
01943
01944
01945
01946
01947
01948 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
01949 {
01950 static QMap<int, QString> aTypes;
01951 if (aTypes.isEmpty())
01952 {
01953 aTypes[ SMESH::NODE ] = tr("NODES");
01954 aTypes[ SMESH::EDGE ] = tr("EDGES");
01955 aTypes[ SMESH::FACE ] = tr("FACES");
01956 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
01957 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
01958 }
01959
01960 return aTypes;
01961 }
01962
01963
01964
01965
01966
01967 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
01968 {
01969 if (theType == SMESH::NODE)
01970 {
01971 static QMap<int, QString> aCriteria;
01972 if (aCriteria.isEmpty())
01973 {
01974 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
01975 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
01976 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
01977 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
01978 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
01979 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
01980 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
01981 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
01982 }
01983 return aCriteria;
01984 }
01985 else if (theType == SMESH::EDGE)
01986 {
01987 static QMap<int, QString> aCriteria;
01988 if (aCriteria.isEmpty())
01989 {
01990 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
01991 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
01992 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
01993 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
01994 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
01995 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
01996 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
01997 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
01998 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
01999 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
02000 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
02001 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
02002 }
02003 return aCriteria;
02004 }
02005 else if (theType == SMESH::FACE)
02006 {
02007 static QMap<int, QString> aCriteria;
02008 if (aCriteria.isEmpty())
02009 {
02010 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
02011 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
02012 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
02013 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
02014 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
02015 aCriteria[ SMESH::FT_Area ] = tr("AREA");
02016 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
02017 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
02018 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
02019 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
02020 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
02021 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
02022 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
02023 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
02024 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
02025 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
02026 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
02027 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
02028 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
02029 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
02030 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
02031 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
02032 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
02033 }
02034 return aCriteria;
02035 }
02036 else if (theType == SMESH::VOLUME)
02037 {
02038 static QMap<int, QString> aCriteria;
02039 if (aCriteria.isEmpty())
02040 {
02041 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
02042 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
02043 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
02044 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
02045 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
02046 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
02047 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
02048 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
02049 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
02050 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
02051 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
02052 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
02053 }
02054 return aCriteria;
02055 }
02056 else
02057 {
02058 static QMap<int, QString> aCriteria;
02059 if (aCriteria.isEmpty())
02060 {
02061 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
02062 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
02063 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
02064 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
02065 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
02066 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
02067 }
02068
02069 return aCriteria;
02070 }
02071 }
02072
02073
02074
02075
02076
02077
02078 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
02079 {
02080 static QMap<int, QString> aMap;
02081
02082 if (aMap.isEmpty())
02083 {
02084 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
02085 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
02086 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
02087 }
02088
02089 return aMap;
02090 }
02091
02092
02093
02094
02095
02096 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
02097 const int theType)
02098 {
02099
02100 Table* aTable= new Table(0, 6, theParent);
02101
02102 QHeaderView* aHeaders = aTable->horizontalHeader();
02103
02104 QFontMetrics aMetrics(aHeaders->font());
02105
02106
02107
02108 static int aMaxLenCr = 0;
02109
02110 if (aMaxLenCr == 0)
02111 {
02112 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
02113 QMap<int, QString>::const_iterator anIter;
02114 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
02115 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
02116 }
02117
02118 static int aLenCr = qAbs( aMaxLenCr -
02119 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
02120
02121 QString aCrStr;
02122 aCrStr.fill(' ', aLenCr);
02123 QString aCoStr;
02124 aCoStr.fill(' ', 10);
02125
02126 QStringList aHeaderLabels;
02127 aHeaderLabels.append( tr("CRITERION") + aCrStr );
02128 aHeaderLabels.append( tr("COMPARE") + aCoStr );
02129 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
02130 aHeaderLabels.append( tr("UNARY") );
02131 aHeaderLabels.append( tr("BINARY") + " " );
02132 aHeaderLabels.append( tr("ID") );
02133 aTable->setHorizontalHeaderLabels( aHeaderLabels );
02134
02135
02136 for (int i = 0; i <= 4; i++)
02137 aTable->resizeColumnToContents(i);
02138
02139
02140 aTable->hideColumn( 5 );
02141
02142 aTable->updateGeometry();
02143 QSize aSize = aTable->sizeHint();
02144 int aWidth = aSize.width();
02145 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
02146 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
02147
02148 connect(aTable, SIGNAL(cellChanged(int, int)),
02149 this, SLOT(onCriterionChanged(int, int)));
02150
02151 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
02152 this, SLOT(onCurrentChanged(int, int)));
02153
02154 return aTable;
02155 }
02156
02157
02158
02159
02160
02161 void SMESHGUI_FilterTable::updateBtnState()
02162 {
02163 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
02164 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
02165 }
02166
02167
02168
02169
02170
02171 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
02172 {
02173 TableMap::iterator anIter;
02174 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
02175 {
02176 anIter.value()->setReadOnly(!isEditable);
02177
02178
02179 Table* aTable = anIter.value();
02180 for (int i = 0, n = aTable->rowCount(); i < n; i++)
02181 for (int j = 0, m = aTable->columnCount(); j < m; j++)
02182 {
02183 QTableWidgetItem* anItem = aTable->item(i, j);
02184 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
02185 Qt::ItemFlags f = anItem->flags();
02186 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
02187 else f = f | Qt::ItemIsUserCheckable;
02188 anItem->setFlags( f );
02189 }
02190 }
02191
02192
02193 if (isEditable)
02194 {
02195 myAddBtn->show();
02196 myInsertBtn->show();
02197 myRemoveBtn->show();
02198 myClearBtn->show();
02199 }
02200 else
02201 {
02202 myAddBtn->hide();
02203 myInsertBtn->hide();
02204 myRemoveBtn->hide();
02205 myClearBtn->hide();
02206 }
02207 }
02208
02209 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
02210 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
02211 anIter2.value()->SetEditable(isEditable);
02212 }
02213
02214
02215
02216
02217
02218 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
02219 {
02220 myAddBtn->setEnabled(isEnabled);
02221 myInsertBtn->setEnabled(isEnabled);
02222 myRemoveBtn->setEnabled(isEnabled);
02223 myClearBtn->setEnabled(isEnabled);
02224
02225 if (isEnabled)
02226 updateBtnState();
02227
02228 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
02229 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
02230 anIter2.value()->setEnabled(isEnabled);
02231 }
02232
02233
02234
02235
02236
02237 bool SMESHGUI_FilterTable::IsEditable() const
02238 {
02239 return !myTables[ GetType() ]->isReadOnly();
02240 }
02241
02242
02243
02244
02245
02246 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
02247 {
02248 if (isEnabled)
02249 {
02250 myCopyFromBtn->show();
02251 myAddToBtn->show();
02252 }
02253 else
02254 {
02255 myCopyFromBtn->hide();
02256 myAddToBtn->hide();
02257 }
02258 }
02259
02260
02261
02262
02263
02264
02265 void SMESHGUI_FilterTable::onCopyFromBtn()
02266 {
02267 if (myLibDlg == 0)
02268 myLibDlg = new SMESHGUI_FilterLibraryDlg(
02269 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
02270 else
02271 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
02272
02273 if (myLibDlg->exec() == QDialog::Accepted)
02274 {
02275 Copy(myLibDlg->GetTable());
02276 Update();
02277 }
02278 }
02279
02280
02281
02282
02283
02284
02285 void SMESHGUI_FilterTable::onAddToBtn()
02286 {
02287 if (!IsValid(true))
02288 return;
02289 if (myLibDlg == 0)
02290 myLibDlg = new SMESHGUI_FilterLibraryDlg(
02291 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
02292 else
02293 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
02294
02295 myLibDlg->SetTable(this);
02296
02297 myLibDlg->exec();
02298 }
02299
02300
02301
02302
02303
02304 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
02305 {
02306 Clear();
02307
02308 for (int i = 0, n = theTable->NumRows(); i < n; i++)
02309 {
02310 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
02311 theTable->GetCriterion(i, aCriterion);
02312 AddCriterion(aCriterion);
02313 }
02314 }
02315
02316
02317
02318
02319
02320 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
02321 {
02322 theRow = myTables[ GetType() ]->currentRow();
02323 theCol = myTables[ GetType() ]->currentColumn();
02324 return theRow >= 0 && theCol >= 0;
02325 }
02326
02327
02328
02329
02330
02331 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
02332 const QString& theText,
02333 const int theEntityType)
02334 {
02335 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02336 aTable->item( theRow, 2 )->setText(theText);
02337 }
02338
02339
02340
02341
02342
02343 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
02344 QString& theText,
02345 const int theEntityType)
02346 {
02347 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02348 QTableWidgetItem* anItem = aTable->item(theRow, 2);
02349 if (anItem != 0)
02350 {
02351 theText = anItem->text();
02352 return true;
02353 }
02354 else
02355 return false;
02356 }
02357
02358
02359
02360
02361
02362 void SMESHGUI_FilterTable::SetID( const int theRow,
02363 const QString& theText,
02364 const int theEntityType )
02365 {
02366 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02367 aTable->item( theRow, 5 )->setText( theText );
02368 }
02369
02370
02371
02372
02373
02374 bool SMESHGUI_FilterTable::GetID( const int theRow,
02375 QString& theText,
02376 const int theEntityType )
02377 {
02378 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
02379 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
02380 if ( anItem != 0 )
02381 {
02382 theText = anItem->text();
02383 return true;
02384 }
02385 else
02386 return false;
02387 }
02388
02389
02390
02391
02392
02393
02394
02395
02396
02397
02398
02399 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
02400 const QList<int>& theTypes )
02401 : QDialog( SMESH::GetDesktop( theModule ) ),
02402 mySMESHGUI( theModule ),
02403 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
02404 myInitSourceWgOnApply( true )
02405 {
02406 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02407 mySelector = aViewWindow->GetSelector();
02408
02409 construct(theTypes);
02410 }
02411
02412
02413
02414
02415
02416 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
02417 const int theType )
02418 : QDialog( SMESH::GetDesktop( theModule ) ),
02419 mySMESHGUI( theModule ),
02420 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
02421 myInitSourceWgOnApply( true )
02422 {
02423 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02424 mySelector = aViewWindow->GetSelector();
02425 QList<int> aTypes;
02426 aTypes.append(theType);
02427 construct(aTypes);
02428 }
02429
02430
02431
02432
02433
02434 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
02435 {
02436 myTypes = theTypes;
02437
02438 setModal(false);
02439
02440 setWindowTitle(tr("CAPTION"));
02441
02442 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
02443 aDlgLay->setMargin(MARGIN);
02444 aDlgLay->setSpacing(SPACING);
02445
02446 myMainFrame = createMainFrame (this);
02447 QWidget* aBtnFrame = createButtonFrame(this);
02448
02449 aDlgLay->addWidget(myMainFrame);
02450 aDlgLay->addWidget(aBtnFrame);
02451
02452 aDlgLay->setStretchFactor(myMainFrame, 1);
02453
02454 myHelpFileName = "selection_filter_library_page.html";
02455
02456 Init(myTypes);
02457 }
02458
02459
02460
02461
02462
02463 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
02464 {
02465 QWidget* aMainFrame = new QWidget(theParent);
02466 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
02467 aMainLay->setMargin(0);
02468 aMainLay->setSpacing(SPACING);
02469
02470
02471
02472 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
02473 myTable->SetLibsEnabled(true);
02474
02475 QGroupBox* aGrp = myTable->GetTableGrp();
02476 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
02477 int rows = aLay->rowCount();
02478 int cols = aLay->columnCount();
02479
02480 QFrame* aLine = new QFrame(aGrp);
02481 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
02482 aLay->addWidget(aLine, rows++, 0, 1, cols);
02483
02484 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
02485 mySetInViewer->setChecked(true);
02486 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
02487
02488
02489 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
02490
02491 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
02492 SLOT(onCriterionChanged(const int, const int)));
02493
02494 connect(myTable, SIGNAL(CurrentChanged(int, int)),
02495 SLOT(onCurrentChanged(int, int)));
02496
02497 aMainLay->addWidget(myTable);
02498 aMainLay->addWidget(aSourceGrp);
02499
02500 return aMainFrame;
02501 }
02502
02503
02504
02505
02506
02507 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
02508 {
02509 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
02510 QHBoxLayout* aLay = new QHBoxLayout(aBox);
02511 aLay->setMargin(MARGIN);
02512 aLay->setSpacing(SPACING);
02513
02514 mySourceGrp = new QButtonGroup(theParent);
02515
02516 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
02517 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
02518 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
02519
02520 aLay->addWidget(aMeshBtn);
02521 aLay->addWidget(aSelBtn);
02522 aLay->addWidget(aDlgBtn);
02523
02524 mySourceGrp->addButton(aMeshBtn, Mesh);
02525 mySourceGrp->addButton(aSelBtn, Selection);
02526 mySourceGrp->addButton(aDlgBtn, Dialog);
02527
02528 aSelBtn->setChecked(true);
02529
02530 return aBox;
02531 }
02532
02533
02534
02535
02536
02537 void SMESHGUI_FilterDlg::updateMainButtons()
02538 {
02539 myButtons[ BTN_Close ]->show();
02540 if (myTypes.count() == 1)
02541 {
02542 myButtons[ BTN_Apply ]->hide();
02543 }
02544 else
02545 {
02546 myButtons[ BTN_Apply ]->show();
02547 }
02548
02549 }
02550
02551
02552
02553
02554
02555 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
02556 {
02557 QGroupBox* aGrp = new QGroupBox(theParent);
02558 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
02559 aLay->setMargin(MARGIN);
02560 aLay->setSpacing(SPACING);
02561
02562 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
02563 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
02564 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
02565 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
02566
02567 aLay->addWidget(myButtons[ BTN_OK ]);
02568 aLay->addSpacing(10);
02569 aLay->addWidget(myButtons[ BTN_Apply ]);
02570 aLay->addSpacing(10);
02571 aLay->addStretch();
02572 aLay->addWidget(myButtons[ BTN_Close ]);
02573 aLay->addWidget(myButtons[ BTN_Help ]);
02574
02575 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
02576 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
02577 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
02578 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
02579
02580 updateMainButtons();
02581
02582 return aGrp;
02583 }
02584
02585
02586
02587
02588
02589 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
02590 {
02591 }
02592
02593
02594
02595
02596
02597 void SMESHGUI_FilterDlg::Init (const int type)
02598 {
02599 QList<int> aTypes;
02600 aTypes.append(type);
02601 Init(aTypes);
02602 }
02603
02604
02605
02606
02607
02608 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
02609 {
02610 mySourceWg = 0;
02611 myTypes = theTypes;
02612 myMesh = SMESH::SMESH_Mesh::_nil();
02613 myIObjects.Clear();
02614 myIsSelectionChanged = false;
02615
02616 myTable->Init(theTypes);
02617
02618
02619 if (theTypes.count() == 1)
02620 {
02621 int aType = theTypes.first();
02622 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
02623 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
02624 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
02625 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
02626 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
02627 }
02628 else
02629 setWindowTitle(tr("TLT"));
02630
02631 qApp->processEvents();
02632 updateGeometry();
02633 adjustSize();
02634 setEnabled(true);
02635
02636 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
02637
02638 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
02639 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
02640
02641 updateMainButtons();
02642 updateSelection();
02643
02644
02645 QList<int>::const_iterator anIter;
02646 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
02647 {
02648 myTable->Clear(*anIter);
02649 if (!myFilter[ *anIter ]->_is_nil())
02650 {
02651 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
02652 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
02653 {
02654 for (int i = 0, n = aCriteria->length(); i < n; i++)
02655 myTable->AddCriterion(aCriteria[ i ], *anIter);
02656 }
02657 }
02658 }
02659
02660 if (myInsertState.contains(theTypes.first()))
02661 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
02662 else
02663 mySetInViewer->setChecked(true);
02664
02665 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
02666 myApplyToState[ theTypes.first() ] :
02667 Selection)->setChecked(true);
02668 }
02669
02670
02671
02672
02673
02674
02675 void SMESHGUI_FilterDlg::onOk()
02676 {
02677 if (onApply())
02678 {
02679 mySelectionMgr->clearFilters();
02680 disconnect(mySMESHGUI, 0, this, 0);
02681 disconnect(mySelectionMgr, 0, this, 0);
02682 mySMESHGUI->ResetState();
02683 accept();
02684 emit Accepted();
02685 }
02686 }
02687
02688
02689
02690
02691
02692 void SMESHGUI_FilterDlg::onClose()
02693 {
02694
02695 if (mySelectionMgr)
02696 {
02697 SALOME_ListIO aList;
02698 mySelectionMgr->clearFilters();
02699 mySelectionMgr->clearSelected();
02700 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
02701 for ( ; anIter.More(); anIter.Next())
02702 {
02703 aList.Append(anIter.Key());
02704
02705 TColStd_MapOfInteger aResMap;
02706 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
02707 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
02708 aResMap.Add(anIndMap(i));
02709
02710 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
02711 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
02712 aViewWindow->highlight( anIter.Key(), true, true );
02713 }
02714 mySelectionMgr->setSelectedObjects(aList, false);
02715 }
02716
02717 disconnect(mySMESHGUI, 0, this, 0);
02718 disconnect(mySelectionMgr, 0, this, 0);
02719 mySMESHGUI->ResetState();
02720 reject();
02721 return;
02722 }
02723
02724
02725
02726
02727
02728 void SMESHGUI_FilterDlg::onHelp()
02729 {
02730 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
02731 if (app)
02732 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
02733 else {
02734 QString platform;
02735 #ifdef WIN32
02736 platform = "winapplication";
02737 #else
02738 platform = "application";
02739 #endif
02740 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
02741 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
02742 arg(app->resourceMgr()->stringValue("ExternalBrowser",
02743 platform)).
02744 arg(myHelpFileName));
02745 }
02746 }
02747
02748
02749
02750
02751
02752 void SMESHGUI_FilterDlg::onDeactivate()
02753 {
02754 setEnabled(false);
02755 }
02756
02757
02758
02759
02760
02761 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
02762 {
02763
02764 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
02765 mySMESHGUI->ResetState();
02766 setEnabled(true);
02767 }
02768
02769
02770
02771
02772
02773 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
02774 {
02775 onClose();
02776 }
02777
02778
02779
02780
02781
02782 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
02783 {
02784 theRes.clear();
02785 if (theWg == 0)
02786 return;
02787
02788 if (theWg->inherits("QListWidget"))
02789 {
02790 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
02791 bool b;
02792 for (int i = 0, n = aListBox->count(); i < n; i++)
02793 {
02794 int anId = aListBox->item(i)->text().toInt(&b);
02795 if (b)
02796 theRes.append(anId);
02797 }
02798 }
02799 else if (theWg->inherits("QLineEdit"))
02800 {
02801 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
02802 QString aStr = aLineEdit->text();
02803 QRegExp aRegExp("(\\d+)");
02804 bool b;
02805 int aPos = 0;
02806 while (aPos >= 0)
02807 {
02808 aPos = aRegExp.indexIn(aStr, aPos);
02809 if (aPos > -1)
02810 {
02811 int anId = aRegExp.cap(1).toInt(&b);
02812 if (b)
02813 theRes.append(anId);
02814 aPos += aRegExp.matchedLength();
02815 }
02816 }
02817 }
02818 }
02819
02820
02821
02822
02823
02824 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
02825 {
02826 switch (theType)
02827 {
02828 case SMESH::NODE : return NodeSelection;
02829 case SMESH::EDGE : return EdgeSelection;
02830 case SMESH::FACE : return FaceSelection;
02831 case SMESH::VOLUME : return VolumeSelection;
02832 case SMESH::ALL : return CellSelection;
02833 default : return ActorSelection;
02834 }
02835
02836 }
02837
02838
02839
02840
02841
02842 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
02843 {
02844 if (theWg == 0)
02845 return;
02846
02847 QStringList aStrList;
02848 foreach(int id, theIds)
02849 aStrList << QString::number(id);
02850
02851 if (theWg->inherits("QListWidget"))
02852 {
02853 qobject_cast<QListWidget*>(theWg)->clear();
02854 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
02855 }
02856 else if (theWg->inherits("QLineEdit"))
02857 {
02858 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
02859 }
02860 }
02861
02862
02863
02864
02865
02866 bool SMESHGUI_FilterDlg::isValid() const
02867 {
02868 if (!myTable->IsValid())
02869 return false;
02870
02871 for (int i = 0, n = myTable->NumRows(); i < n; i++)
02872 {
02873 int aType = myTable->GetCriterionType(i);
02874 if (aType == SMESH::FT_BelongToGeom ||
02875 aType == SMESH::FT_BelongToPlane ||
02876 aType == SMESH::FT_BelongToCylinder ||
02877 aType == SMESH::FT_BelongToGenSurface ||
02878 aType == SMESH::FT_LyingOnGeom)
02879 {
02880 QString aName;
02881 myTable->GetThreshold(i, aName);
02882
02883 std::vector<_PTR(SObject)> aList =
02884 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
02885 if (aList.size() == 0) {
02886 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02887 tr("BAD_SHAPE_NAME").arg(aName));
02888 return false;
02889 }
02890
02891 if (aType == SMESH::FT_BelongToCylinder ||
02892 aType == SMESH::FT_BelongToPlane ||
02893 aType == SMESH::FT_BelongToGenSurface ) {
02894 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
02895
02896 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
02897 if (!aGeomObj->_is_nil()) {
02898 TopoDS_Shape aFace;
02899 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
02900 aFace.IsNull() ||
02901 aFace.ShapeType() != TopAbs_FACE) {
02902 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02903 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
02904 return false;
02905 }
02906
02907 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
02908 if (aSurf.IsNull()) {
02909 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02910 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
02911 return false;
02912 }
02913
02914 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
02915 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02916 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
02917 return false;
02918 }
02919
02920 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
02921 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02922 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
02923 return false;
02924 }
02925 }
02926 }
02927 }
02928 else if (aType == SMESH::FT_CoplanarFaces)
02929 {
02930 QString faceID;
02931 myTable->GetThreshold(i, faceID);
02932 if ( faceID.isEmpty() )
02933 {
02934 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02935 tr("FACE_ID_NOT_SELECTED"));
02936 return false;
02937 }
02938 if ( myMesh->_is_nil() )
02939 {
02940 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02941 tr("MESH_IS_NOT_SELECTED"));
02942 return false;
02943 }
02944 if ( myMesh->GetElementType( faceID.toLong(), true) != SMESH::FACE )
02945 {
02946 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
02947 tr("NOT_FACE_ID").arg(faceID));
02948 return false;
02949 }
02950 }
02951 }
02952
02953 return true;
02954 }
02955
02956
02957
02958
02959
02960
02961 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
02962 const bool initOnApply)
02963 {
02964 mySourceWg = theWg;
02965 myInitSourceWgOnApply = initOnApply;
02966 }
02967
02968
02969
02970
02971
02972 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
02973 {
02974 if ( !theMesh->_is_nil() ) {
02975 myMesh = theMesh;
02976 if ( !myFilter[ myTable->GetType() ]->_is_nil() && !myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ) {
02977 SMESH::Predicate_ptr aPred = myFilter[ myTable->GetType() ]->GetPredicate();
02978 aPred->SetMesh(myMesh);
02979 }
02980 }
02981 const bool isEnable = !(myMesh->_is_nil());
02982 myButtons[BTN_OK]->setEnabled(isEnable);
02983 myButtons[BTN_Apply]->setEnabled(isEnable);
02984 }
02985
02986
02987
02988
02989
02990 void SMESHGUI_FilterDlg::SetSelection()
02991 {
02992 if (mySelectionMgr)
02993 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
02994
02995 if (mySelectionMgr) {
02996 myIObjects.Clear();
02997 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
02998 SALOME_ListIteratorOfListIO anIter (anObjs);
02999 for ( ; anIter.More(); anIter.Next()) {
03000 TColStd_IndexedMapOfInteger aMap;
03001 mySelector->GetIndex(anIter.Value(), aMap);
03002 myIObjects.Bind(anIter.Value(), aMap);
03003 }
03004
03005 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
03006
03007 updateSelection();
03008 }
03009 else
03010 myIObjects.Clear();
03011 }
03012
03013
03014
03015
03016
03017
03018 bool SMESHGUI_FilterDlg::onApply()
03019 {
03020 if (!isValid())
03021 return false;
03022
03023 try {
03024 int aCurrType = myTable->GetType();
03025
03026 if (!createFilter(aCurrType))
03027 return false;
03028
03029 insertFilterInViewer();
03030
03031 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
03032 QList<int> aResultIds;
03033 filterSource(aCurrType, aResultIds);
03034
03035 selectInViewer(aCurrType, aResultIds);
03036 }
03037
03038
03039 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
03040 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
03041 }
03042 catch(const SALOME::SALOME_Exception& S_ex)
03043 {
03044 SalomeApp_Tools::QtCatchCorbaException(S_ex);
03045 }
03046 catch(...)
03047 {
03048 }
03049
03050 return true;
03051 }
03052
03053
03054
03055
03056
03057 bool SMESHGUI_FilterDlg::createFilter (const int theType)
03058 {
03059 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
03060 if (aFilterMgr->_is_nil())
03061 return false;
03062
03063 int n = myTable->NumRows();
03064
03065 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
03066 aCriteria->length(n);
03067
03068 long aPrecision = -1;
03069 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
03070
03071 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
03072 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
03073
03074 for (CORBA::ULong i = 0; i < n; i++) {
03075 SMESH::Filter::Criterion aCriterion = createCriterion();
03076 myTable->GetCriterion(i, aCriterion);
03077 aCriterion.Precision = aPrecision;
03078 aCriteria[ i ] = aCriterion;
03079 }
03080
03081 myFilter[ theType ] = aFilterMgr->CreateFilter();
03082 myFilter[ theType ]->SetCriteria(aCriteria.inout());
03083
03084 return true;
03085 }
03086
03087
03088
03089
03090
03091 void SMESHGUI_FilterDlg::insertFilterInViewer()
03092 {
03093 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
03094 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
03095
03096 if (myFilter[ myTable->GetType() ]->_is_nil() ||
03097 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
03098 !mySetInViewer->isChecked()) {
03099 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
03100 }
03101 else {
03102 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
03103 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
03104 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
03105 SMESH::SetFilter(aFilter, aSelector);
03106 }
03107 }
03108 }
03109
03110
03111
03112
03113
03114 void SMESHGUI_FilterDlg::filterSource (const int theType,
03115 QList<int>& theResIds)
03116 {
03117 theResIds.clear();
03118 if (myFilter[ theType ]->_is_nil())
03119 return;
03120
03121 int aSourceId = mySourceGrp->checkedId();
03122
03123 if (aSourceId == Mesh)
03124 {
03125 if (myMesh->_is_nil())
03126 return;
03127 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
03128 for (int i = 0, n = anIds->length(); i < n; i++)
03129 theResIds.append(anIds[ i ]);
03130 }
03131 else if (aSourceId == Selection)
03132 {
03133 filterSelectionSource(theType, theResIds);
03134 }
03135 else if (aSourceId == Dialog)
03136 {
03137
03138 QList<int> aDialogIds;
03139 getIdsFromWg(mySourceWg, aDialogIds);
03140
03141 if (myMesh->_is_nil())
03142 {
03143 theResIds = aDialogIds;
03144 return;
03145 }
03146
03147
03148 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
03149 aPred->SetMesh(myMesh);
03150 QList<int>::const_iterator anIter;
03151 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
03152 if (aPred->IsSatisfy(*anIter))
03153 theResIds.append(*anIter);
03154 }
03155
03156 if (myInitSourceWgOnApply || aSourceId == Dialog)
03157 setIdsToWg(mySourceWg, theResIds);
03158 }
03159
03160
03161
03162
03163
03164 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
03165 QList<int>& theResIds)
03166 {
03167 theResIds.clear();
03168 if (myMesh->_is_nil() || mySelectionMgr == 0)
03169 return;
03170
03171
03172 TColStd_MapOfInteger aToBeFiltered;
03173 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
03174
03175 for ( ; anIter.More(); anIter.Next())
03176 {
03177
03178 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
03179 if (!aSubMesh->_is_nil())
03180 {
03181 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
03182 {
03183 SMESH::long_array_var anIds =
03184 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
03185 for (int i = 0, n = anIds->length(); i < n; i++)
03186 aToBeFiltered.Add(anIds[ i ]);
03187 }
03188 }
03189
03190
03191 SMESH::SMESH_GroupBase_var aGroup =
03192 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
03193 if (!aGroup->_is_nil())
03194 {
03195 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
03196 {
03197 SMESH::long_array_var anIds = aGroup->GetListOfID();
03198 for (int i = 0, n = anIds->length(); i < n; i++)
03199 aToBeFiltered.Add(anIds[ i ]);
03200 }
03201 }
03202
03203
03204 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
03205 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
03206 {
03207 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
03208
03209 if (aSelMap.Extent() > 0)
03210 {
03211 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
03212 {
03213 for (int i = 1; i <= aSelMap.Extent(); i++)
03214 aToBeFiltered.Add(aSelMap(i));
03215 }
03216 }
03217 }
03218 }
03219
03220
03221 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
03222 aPred->SetMesh(myMesh);
03223 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
03224 for ( ; aResIter.More(); aResIter.Next())
03225 if (aPred->IsSatisfy(aResIter.Key()))
03226 theResIds.append(aResIter.Key());
03227 }
03228
03229
03230
03231
03232
03233 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
03234 {
03235 if (mySelectionMgr == 0 || myMesh->_is_nil())
03236 return;
03237
03238 mySelectionMgr->clearFilters();
03239
03240
03241 Selection_Mode aSelMode = getSelMode(theType);
03242 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
03243 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
03244 mySelectionMgr->clearSelected();
03245 mySelectionMgr->clearFilters();
03246 if (aSelMode == NodeSelection)
03247 SMESH::SetPointRepresentation(true);
03248 aViewWindow->SetSelectionMode(aSelMode);
03249 }
03250
03251
03252 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
03253 if (!anActor || !anActor->hasIO())
03254 return;
03255
03256 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
03257
03258
03259 SALOME_ListIO aList;
03260 aList.Append(anIO);
03261 mySelectionMgr->setSelectedObjects(aList, false);
03262
03263
03264 int aType = myTable->GetType();
03265 int aFilterId = SMESH::UnknownFilter;
03266 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
03267 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
03268 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
03269 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
03270 SMESH::RemoveFilter(aFilterId);
03271
03272
03273 TColStd_MapOfInteger aMap;
03274 QList<int>::const_iterator anIter;
03275 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
03276 aMap.Add(*anIter);
03277 }
03278
03279
03280 mySelector->AddOrRemoveIndex(anIO, aMap, false);
03281 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
03282 aViewWindow->highlight( anIO, true, true );
03283
03284
03285 if (!aFilter.IsNull())
03286 SMESH::SetFilter(aFilter);
03287 }
03288
03289
03290
03291
03292
03293 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
03294 {
03295 SMESH::Filter::Criterion aCriterion;
03296
03297 aCriterion.Type = SMESH::FT_Undefined;
03298 aCriterion.Compare = SMESH::FT_Undefined;
03299 aCriterion.Threshold = 0;
03300 aCriterion.UnaryOp = SMESH::FT_Undefined;
03301 aCriterion.BinaryOp = SMESH::FT_Undefined;
03302 aCriterion.ThresholdStr = "";
03303 aCriterion.ThresholdID = "";
03304 aCriterion.TypeOfElement = SMESH::ALL;
03305
03306 return aCriterion;
03307 }
03308
03309
03310
03311
03312
03313
03314
03315 void SMESHGUI_FilterDlg::onSelectionDone()
03316 {
03317 int aRow, aCol;
03318 const SALOME_ListIO& aList = mySelector->StoredIObjects();
03319
03320 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
03321 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
03322 if ( !(myMesh->_is_nil()) ) {
03323 myButtons[BTN_OK]->setEnabled(true);
03324 myButtons[BTN_Apply]->setEnabled(true);
03325 }
03326 }
03327
03328 QList<int> types;
03329 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
03330 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
03331 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces;
03332 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
03333 !types.contains(myTable->GetCriterionType(aRow)))
03334 return;
03335
03336 if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
03337 {
03338 QString aString;
03339 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,
03340 aList.First(), aString);
03341 if (nbElems == 1)
03342 myTable->SetThreshold(aRow, aString);
03343 }
03344 else
03345 {
03346 Handle(SALOME_InteractiveObject) anIO = aList.First();
03347 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
03348 if (!anObj->_is_nil())
03349 {
03350 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
03351
03352 myTable->SetID(aRow, anIO->getEntry());
03353 }
03354 }
03355 }
03356
03357
03358
03359
03360
03361
03362 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
03363 {
03364 updateSelection();
03365 }
03366
03367
03368
03369
03370
03371 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
03372 {
03373 updateSelection();
03374 }
03375
03376
03377
03378
03379
03380 void SMESHGUI_FilterDlg::updateSelection()
03381 {
03382 if (mySelectionMgr == 0)
03383 return;
03384
03385
03386
03387
03388 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
03389 if( !aStudy )
03390 return;
03391
03392
03393 mySelectionMgr->clearFilters();
03394
03395 int aRow, aCol;
03396
03397 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
03398 int aCriterionType = myTable->GetCriterionType(aRow);
03399 if ( isCurrentCell &&
03400 (aCriterionType == SMESH::FT_BelongToGeom ||
03401 aCriterionType == SMESH::FT_BelongToPlane ||
03402 aCriterionType == SMESH::FT_BelongToCylinder ||
03403 aCriterionType == SMESH::FT_BelongToGenSurface ||
03404 aCriterionType == SMESH::FT_LyingOnGeom))
03405 {
03406 if (aCriterionType == SMESH::FT_BelongToGeom ||
03407 aCriterionType == SMESH::FT_BelongToGenSurface ||
03408 aCriterionType == SMESH::FT_LyingOnGeom) {
03409
03410 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
03411
03412 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
03413 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
03414
03415 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
03416 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
03417 }
03418 myIsSelectionChanged = true;
03419
03420 }
03421 else
03422 {
03423 if (myIsSelectionChanged) {
03424
03425
03426 }
03427 }
03428 }
03429
03430
03431
03432
03433
03434 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
03435 {
03436 QDialog::keyPressEvent( e );
03437 if ( e->isAccepted() )
03438 return;
03439
03440 if ( e->key() == Qt::Key_F1 ) {
03441 e->accept();
03442 onHelp();
03443 }
03444 }