1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
28 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Filter.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_FilterLibraryDlg.h"
36 #include "SMESHGUI_SpinBox.h"
38 #include <SMESH_Actor.h>
39 #include <SMESH_NumberFilter.hxx>
40 #include <SMESH_TypeFilter.hxx>
42 // SALOME GEOM includes
44 #include <GEOM_FaceFilter.h>
45 #include <GEOM_TypeFilter.h>
47 // SALOME GUI includes
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_MessageBox.h>
52 #include <QtxColorButton.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Study.h>
58 #include <SalomeApp_IntSpinBox.h>
59 #include <SalomeApp_DoubleSpinBox.h>
61 #include <SALOME_ListIO.hxx>
62 #include <SALOME_ListIteratorOfListIO.hxx>
63 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
65 #include <SVTK_ViewWindow.h>
67 // SALOME KERNEL includes
68 #include <SALOMEDSClient_Study.hxx>
71 #include <StdSelect_TypeOfFace.hxx>
72 #include <BRep_Tool.hxx>
74 #include <TopoDS_Shape.hxx>
75 #include <Geom_Plane.hxx>
76 #include <Geom_CylindricalSurface.hxx>
77 #include <Precision.hxx>
78 #include <TColStd_MapOfInteger.hxx>
79 #include <TColStd_IndexedMapOfInteger.hxx>
80 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
85 #include <QPushButton>
87 #include <QTableWidget>
88 #include <QStringList>
89 #include <QHBoxLayout>
90 #include <QVBoxLayout>
91 #include <QGridLayout>
92 #include <QStackedWidget>
93 #include <QApplication>
95 #include <QFontMetrics>
97 #include <QButtonGroup>
98 #include <QRadioButton>
100 #include <QListWidget>
102 #include <QItemDelegate>
103 #include <QDoubleValidator>
105 #include <QHeaderView>
108 #include <SALOMEconfig.h>
109 #include CORBA_SERVER_HEADER(SMESH_Group)
114 //---------------------------------------
116 //---------------------------------------
117 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
120 QMap<int, QString>::const_iterator anIter;
121 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
122 aRes = qMax(aRes, theMetrics.width(anIter.value()));
126 //---------------------------------------
128 //---------------------------------------
129 static int getFilterId (SMESH::ElementType theType)
133 case SMESH::NODE : return SMESH::NodeFilter;
134 case SMESH::EDGE : return SMESH::EdgeFilter;
135 case SMESH::FACE : return SMESH::FaceFilter;
136 case SMESH::VOLUME : return SMESH::VolumeFilter;
137 case SMESH::ALL : return SMESH::AllElementsFilter;
138 default : return SMESH::UnknownFilter;
143 Class : SMESHGUI_FilterTable::AdditionalWidget
144 Description : Class for storing additional parameters of criterion
147 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
153 AdditionalWidget(QWidget* theParent);
154 virtual ~AdditionalWidget();
156 virtual QList<int> GetParameters() const;
157 virtual bool IsValid(const bool = true) const;
158 virtual double GetDouble(const int) const;
159 virtual int GetInteger(const int) const;
160 virtual QString GetString(const int) const;
161 virtual void SetDouble(const int, const double);
162 virtual void SetInteger(const int, const int);
163 virtual void SetString(const int, const QString&);
164 void SetEditable(const int, const bool);
165 void SetEditable(const bool);
166 void SetPrecision(const int, const char* = 0);
169 QMap< int, QWidget* > myWidgets;
172 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
175 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
177 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
178 sb->setAcceptNames( false ); // No Notebook variables allowed
179 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
180 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
181 myWidgets[ Tolerance ] = sb;
183 QHBoxLayout* aLay = new QHBoxLayout(this);
184 aLay->setSpacing(SPACING);
187 aLay->addWidget(aLabel);
188 aLay->addWidget(myWidgets[ Tolerance ]);
191 SetDouble( Tolerance, Precision::Confusion() );
194 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
198 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
201 theList.append(Tolerance);
205 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
210 QList<int> aParams = GetParameters();
211 QList<int>::const_iterator anIter;
212 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
213 if ( !myWidgets.contains( *anIter ) ) continue;
215 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
216 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
218 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
220 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
222 if (!valid && theMsg) {
223 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
224 tr("SMESHGUI_INVALID_PARAMETERS"));
232 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
235 if ( myWidgets.contains( theId ) ) {
236 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
237 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
238 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
239 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
244 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
247 if ( myWidgets.contains( theId ) ) {
248 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
249 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
250 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
251 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
256 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
259 if ( myWidgets.contains( theId ) ) {
260 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
261 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
262 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
263 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
268 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
270 if ( myWidgets.contains( theId ) ) {
271 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
272 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
273 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
274 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
278 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
280 if ( myWidgets.contains( theId ) ) {
281 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
282 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
283 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
284 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
288 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
290 if ( myWidgets.contains( theId ) ) {
291 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
292 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
293 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
294 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
298 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
300 if ( myWidgets.contains( theId ) ) {
301 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
302 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
303 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
304 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
308 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
310 QList<int> aParams = GetParameters();
311 QList<int>::const_iterator anIter;
312 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
313 SetEditable( *anIter, isEditable );
316 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
318 if ( myWidgets.contains( theId ) ) {
319 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
320 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
321 double val = sb->GetValue();
322 double min = pow(10.0, -(sb->decimals()));
323 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
324 sb->SetValue( qMax( val, min ) );
330 Class : SMESHGUI_FilterTable::ComboItem
331 Description : Combo table item. Identificator corresponding to string may be assigned
334 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
339 ComboItem( const QMap<int, QString>& );
341 void setItems( const QMap<int, QString>& );
346 void setValue( const int );
350 int index( int ) const;
353 QMap<int, int> myIdToIdx;
356 int SMESHGUI_FilterTable::ComboItem::Type()
358 return QTableWidgetItem::UserType + 1;
361 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
362 : QTableWidgetItem( Type() )
367 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
370 QMap<int, QString>::const_iterator it;
372 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
373 myIdToIdx[it.key()] = items.count();
374 items.append( it.value() );
376 setData( Qt::UserRole, items );
380 void SMESHGUI_FilterTable::ComboItem::clear()
382 QMap<int, QString> empty;
386 int SMESHGUI_FilterTable::ComboItem::count() const
388 return myIdToIdx.count();
391 int SMESHGUI_FilterTable::ComboItem::value() const
393 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
396 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
398 int idx = index( theId );
399 QStringList items = data( Qt::UserRole ).toStringList();
400 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
403 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
405 QMap<int,int>::const_iterator it;
406 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
407 if ( it.value() == idx ) return it.key();
411 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
413 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
416 Class : SMESHGUI_FilterTable::CheckItem
417 Description : Check table item.
420 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
425 CheckItem( bool = false );
426 CheckItem( const QString&, bool = false );
429 void setChecked( bool );
430 bool checked() const;
433 int SMESHGUI_FilterTable::CheckItem::Type()
435 return QTableWidgetItem::UserType + 2;
438 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
439 : QTableWidgetItem( Type() )
441 Qt::ItemFlags f = flags();
442 f = f | Qt::ItemIsUserCheckable;
443 f = f & ~Qt::ItemIsTristate;
444 f = f & ~Qt::ItemIsEditable;
449 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
450 : QTableWidgetItem( Type() )
452 Qt::ItemFlags f = flags();
453 f = f | Qt::ItemIsUserCheckable;
454 f = f & ~Qt::ItemIsTristate;
455 f = f & ~Qt::ItemIsEditable;
461 SMESHGUI_FilterTable::CheckItem::~CheckItem()
465 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
467 setCheckState( value ? Qt::Checked : Qt::Unchecked );
470 bool SMESHGUI_FilterTable::CheckItem::checked() const
472 return checkState() == Qt::Checked;
476 Class : SMESHGUI_FilterTable::IntSpinItem
477 Description : Integer spin table item.
480 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
485 IntSpinItem( const int theValue );
488 void setValue( const int theValue );
493 int SMESHGUI_FilterTable::IntSpinItem::Type()
495 return QTableWidgetItem::UserType + 3;
498 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
499 : QTableWidgetItem( Type() )
501 setValue( theValue );
504 int SMESHGUI_FilterTable::IntSpinItem::value() const
507 int value = data( Qt::UserRole ).toInt( &ok );
508 return ok ? value : 0;
511 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
513 setData( Qt::UserRole, theValue );
514 setText( QString::number( theValue ) );
517 void SMESHGUI_FilterTable::IntSpinItem::clear()
523 Class : SMESHGUI_FilterTable::DoubleSpinItem
524 Description : Double spin table item.
527 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
532 DoubleSpinItem( const double theValue );
534 double value() const;
535 void setValue( const double theValue );
537 int precision() const;
538 void setPrecision( const int thePrecision );
543 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
545 return QTableWidgetItem::UserType + 4;
548 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
549 : QTableWidgetItem( Type() )
551 setValue( theValue );
554 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
557 double value = data( Qt::UserRole ).toDouble( &ok );
558 return ok ? value : 0;
561 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
563 setData( Qt::UserRole, theValue );
564 setText( QString::number( theValue ) );
567 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
570 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
571 return ok ? precision : 0;
574 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
576 setData( Qt::UserRole + 1, thePrecision );
579 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
585 Class : SMESHGUI_FilterTable::ComboDelegate
586 Description : Table used by this widget
589 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
592 ComboDelegate( QObject* = 0 );
595 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
596 const QModelIndex& ) const;
598 void setEditorData( QWidget*, const QModelIndex& ) const;
599 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
601 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
602 const QModelIndex& ) const;
604 QTableWidget* myTable;
607 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
608 : QItemDelegate( parent ),
609 myTable( qobject_cast<QTableWidget*>( parent ) )
613 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
617 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
618 const QStyleOptionViewItem& option,
619 const QModelIndex& index ) const
621 QVariant aData = index.data( Qt::UserRole );
622 QVariant::Type aDataType = aData.type();
623 if( aDataType == QVariant::StringList ) {
624 QStringList l = aData.toStringList();
625 if ( !l.isEmpty() ) {
626 QComboBox* cb = new QComboBox( parent );
627 cb->setFrame( false );
632 else if( aDataType == QVariant::Int ) {
634 int aValue = aData.toInt( &ok );
636 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
637 intSpin->setFrame( false );
638 intSpin->setValue( aValue );
642 else if( aDataType == QVariant::Double ) {
644 double aValue = aData.toDouble( &ok );
646 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
650 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
651 dblSpin->setFrame( false );
652 dblSpin->setValue( aValue );
656 return QItemDelegate::createEditor( parent, option, index );
659 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
660 const QModelIndex& index ) const
662 QVariant data = index.model()->data( index, Qt::DisplayRole );
663 QString value = data.toString();
665 if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
666 int i = cb->findText( value );
668 cb->setCurrentIndex( i );
672 else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
673 if( data.type() == QVariant::Double ) {
674 double valueDouble = data.toDouble( &bOk );
676 dblSpin->setValue( valueDouble );
679 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
682 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
683 QAbstractItemModel* model,
684 const QModelIndex& index) const
686 if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
687 model->setData( index, cb->currentText(), Qt::DisplayRole );
688 else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
689 model->setData( index, intSpin->value(), Qt::DisplayRole );
690 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
691 model->setData( index, dblSpin->value(), Qt::DisplayRole );
692 else QItemDelegate::setModelData( editor, model, index );
695 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
696 const QStyleOptionViewItem& option,
697 const QModelIndex& index ) const
699 editor->setGeometry( option.rect );
703 Class : SMESHGUI_FilterTable::Table
704 Description : Table used by this widget
707 class SMESHGUI_FilterTable::Table : public QTableWidget
710 Table( QWidget* = 0 );
711 Table( int, int, QWidget* = 0 );
714 QSize minimumSizeHint() const;
716 void setEditable( bool, int, int );
717 bool isEditable( int, int ) const;
719 void setReadOnly( bool );
720 bool isReadOnly() const;
722 void insertRows( int, int = 1 );
723 QString text( int, int );
725 QList<int> selectedRows();
728 //=======================================================================
729 // name : SMESHGUI_FilterTable::Table::Table
730 // Purpose : Constructor
731 //=======================================================================
732 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
733 : QTableWidget(parent)
735 // set custom item delegate
736 setItemDelegate( new ComboDelegate(this) );
737 // set edit triggers by default
738 setReadOnly( false );
741 //=======================================================================
742 // name : SMESHGUI_FilterTable::Table::Table
743 // Purpose : Constructor
744 //=======================================================================
745 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
746 : QTableWidget(numRows, numCols, parent)
748 // set custom item delegate
749 setItemDelegate( new ComboDelegate(this) );
750 // set edit triggers by default
751 setReadOnly( false );
754 //=======================================================================
755 // name : SMESHGUI_FilterTable::Table::~Table
756 // Purpose : Destructor
757 //=======================================================================
758 SMESHGUI_FilterTable::Table::~Table()
762 //=======================================================================
763 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
764 // Purpose : Get minimum size for the table
765 //=======================================================================
766 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
768 QSize s = QTableWidget::minimumSizeHint();
769 QHeaderView* hv = horizontalHeader();
771 s.setWidth( qMax( s.width(), hv->length() ) );
775 //=======================================================================
776 // name : SMESHGUI_FilterTable::Table::setEditable
777 // Purpose : Set editable of specified cell
778 //=======================================================================
779 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
782 QTableWidgetItem* anItem = item( row, col );
784 bool isSignalsBlocked = signalsBlocked();
785 blockSignals( true );
787 Qt::ItemFlags f = anItem->flags();
788 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
789 else f = f | Qt::ItemIsEditable;
790 anItem->setFlags( f );
792 blockSignals( isSignalsBlocked );
796 //=======================================================================
797 // name : SMESHGUI_FilterTable::Table::isEditable
798 // Purpose : Verify wheter cell is editable
799 //=======================================================================
800 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
802 QTableWidgetItem* anItem = item( row, col );
803 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
806 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
808 setEditTriggers( on ?
809 QAbstractItemView::NoEditTriggers :
810 QAbstractItemView::AllEditTriggers );
813 bool SMESHGUI_FilterTable::Table::isReadOnly() const
815 return editTriggers() == QAbstractItemView::NoEditTriggers;
818 //=======================================================================
819 // name : SMESHGUI_FilterTable::Table::insertRows
820 // Purpose : Insert rows (virtual redefined)
821 //=======================================================================
822 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
824 closePersistentEditor( currentItem() );
825 while ( count-- ) insertRow( row );
828 //=======================================================================
829 // name : SMESHGUI_FilterTable::Table::text
830 // Purpose : Get text from cell (virtual redefined)
831 //=======================================================================
832 QString SMESHGUI_FilterTable::Table::text (int row, int col)
834 closePersistentEditor( currentItem() );
835 QTableWidgetItem* anItem = item( row, col );
836 return anItem ? anItem->text() : QString();
839 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
841 QList<QTableWidgetItem*> selItems = selectedItems();
842 QTableWidgetItem* anItem;
845 foreach( anItem, selItems ) {
846 int r = row( anItem );
847 if ( !rows.contains( r ) ) rows.append( r );
855 Class : SMESHGUI_FilterTable
856 Description : Frame containig
857 - Button group for switching entity type
858 - Table for displaying filter criterions
859 - Buttons for editing table and filter libraries
862 //=======================================================================
863 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
864 // Purpose : Constructor
865 //=======================================================================
866 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
871 mySMESHGUI( theModule )
880 //=======================================================================
881 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
882 // Purpose : Constructor
883 //=======================================================================
884 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
886 const QList<int>& types )
889 mySMESHGUI( theModule )
895 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
899 //=======================================================================
900 // name : SMESHGUI_FilterTable::Init
901 // Purpose : Create table corresponding to the specified type
902 //=======================================================================
903 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
905 if (theTypes.isEmpty())
908 // Create buttons if necessary
910 if (myTables.isEmpty())
912 // create main layout
913 QVBoxLayout* aMainLay = new QVBoxLayout(this);
914 aMainLay->setMargin( 0 );
915 aMainLay->setSpacing( SPACING );
917 // create switch of entity types
918 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
919 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
920 myEntityTypeBoxLayout->setMargin( MARGIN );
921 myEntityTypeBoxLayout->setSpacing( SPACING );
922 myEntityTypeGrp = new QButtonGroup(this);
924 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
925 QMap<int, QString>::const_iterator anIter;
926 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
928 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
929 myEntityTypeGrp->addButton(aBtn, anIter.key());
930 myEntityTypeBoxLayout->addWidget(aBtn);
933 myTableGrp = new QGroupBox(tr("FILTER"), this );
936 mySwitchTableGrp = new QWidget(myTableGrp);
937 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
938 mySwitchTableGrpLayout->setMargin(0);
939 mySwitchTableGrpLayout->setSpacing(0);
941 QList<int>::const_iterator typeIt = theTypes.begin();
942 for ( ; typeIt != theTypes.end(); ++typeIt ) {
943 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
944 myTables[ *typeIt ] = aTable;
945 mySwitchTableGrpLayout->addWidget(aTable);
946 if ( typeIt != theTypes.begin() )
951 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
952 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
953 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
954 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
955 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
956 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
958 myAddBtn->setAutoDefault(false);
959 myRemoveBtn->setAutoDefault(false);
960 myClearBtn->setAutoDefault(false);
961 myInsertBtn->setAutoDefault(false);
962 myCopyFromBtn->setAutoDefault(false);
963 myAddToBtn->setAutoDefault(false);
965 myCopyFromBtn->hide();
969 QGridLayout* aLay = new QGridLayout(myTableGrp);
970 aLay->setMargin(MARGIN);
971 aLay->setSpacing(SPACING);
973 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
974 aLay->addWidget(myAddBtn, 0, 1);
975 aLay->addWidget(myInsertBtn, 1, 1);
976 aLay->addWidget(myRemoveBtn, 2, 1);
977 aLay->addWidget(myClearBtn, 3, 1);
978 aLay->addWidget(myCopyFromBtn, 5, 1);
979 aLay->addWidget(myAddToBtn, 6, 1);
980 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
982 aLay->setRowMinimumHeight(4, 10);
983 aLay->setRowStretch(4, 1);
984 aLay->setColumnStretch(0, 1);
985 aLay->setColumnStretch(1, 0);
988 aMainLay->addWidget(myEntityTypeBox);
989 aMainLay->addWidget(myTableGrp);
992 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
993 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
994 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
995 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
997 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
998 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
1000 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1005 // Hide buttons of entity types if necessary
1006 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1007 QMap<int, QString>::const_iterator anIt;
1008 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1010 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1011 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1014 // select first button if there is no selected buttons or it is hidden
1015 int aBtnId = myEntityTypeGrp->checkedId();
1016 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1017 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1018 if ( aBtn ) aBtn->setChecked(true);
1021 myEntityTypeBox->setVisible(theTypes.count() > 1);
1023 myTableGrp->updateGeometry();
1024 int cType = myEntityTypeGrp->checkedId();
1025 onEntityType(cType);
1028 //=======================================================================
1029 // name : SMESHGUI_FilterTable::createAdditionalFrame
1030 // Purpose : Get group box containing table. May be used for adding new widgets in it
1031 //=======================================================================
1032 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1034 QWidget* aFrame = new QWidget(theParent);
1036 QFrame* aLine1 = new QFrame(aFrame);
1037 QFrame* aLine2 = new QFrame(aFrame);
1038 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1039 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1040 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1041 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1043 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1045 myWgStack = new QStackedWidget(aFrame);
1047 QGridLayout* aLay = new QGridLayout(aFrame);
1049 aLay->setSpacing(SPACING);
1050 aLay->addWidget(aLine1, 0, 0);
1051 aLay->addWidget(aLabel, 0, 1);
1052 aLay->addWidget(aLine2, 0, 2);
1053 aLay->addWidget(myWgStack, 1, 0, 1, 3);
1058 //=======================================================================
1059 // name : SMESHGUI_FilterTable::GetTableGrp
1060 // Purpose : Get group box containing table. May be used for adding new widgets in it
1061 //=======================================================================
1062 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1067 //=======================================================================
1068 // name : SMESHGUI_FilterTable::onEntityType
1069 // Purpose : SLOT. Called when entity type changed.
1070 // Display corresponding table
1071 //=======================================================================
1072 void SMESHGUI_FilterTable::onEntityType (int theType)
1074 if (myEntityType == theType)
1078 emit NeedValidation();
1081 myEntityTypeGrp->button(myEntityType)->setChecked(true);
1085 myEntityType = theType;
1087 if (!myTables.contains(theType)) {
1088 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1089 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1092 TableMap::iterator anIter;
1093 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1094 anIter.value()->setVisible( myEntityType == anIter.key() );
1097 qApp->processEvents();
1098 myTables[ myEntityType ]->updateGeometry();
1101 emit EntityTypeChanged(theType);
1104 //=======================================================================
1105 // name : SMESHGUI_FilterTable::IsValid
1106 // Purpose : Verify validity of entered data
1107 //=======================================================================
1108 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1110 int aType = theEntityType == -1 ? GetType() : theEntityType;
1112 Table* aTable = myTables[ aType ];
1113 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1115 int aCriterion = GetCriterionType(i, aType);
1117 if (aCriterion == SMESH::FT_GroupColor ) {
1118 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1119 if (clrBtn && !clrBtn->color().isValid())
1120 errMsg = tr( "GROUPCOLOR_ERROR" );
1122 else if (aCriterion == SMESH::FT_RangeOfIds ||
1123 aCriterion == SMESH::FT_BelongToGeom ||
1124 aCriterion == SMESH::FT_BelongToPlane ||
1125 aCriterion == SMESH::FT_BelongToCylinder ||
1126 aCriterion == SMESH::FT_BelongToGenSurface ||
1127 aCriterion == SMESH::FT_ElemGeomType ||
1128 aCriterion == SMESH::FT_CoplanarFaces ||
1129 aCriterion == SMESH::FT_LyingOnGeom)
1131 if (aTable->text(i, 2).isEmpty())
1132 errMsg = tr( "ERROR" );
1136 bool isSignalsBlocked = aTable->signalsBlocked();
1137 aTable->blockSignals(true);
1138 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1139 aTable->blockSignals(isSignalsBlocked);
1141 if (!aRes && aTable->isEditable(i, 2))
1142 errMsg = tr( "ERROR" );
1143 else if (aType == SMESH::EDGE &&
1144 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1146 errMsg = tr( "MULTIEDGES_ERROR" );
1149 if (!errMsg.isEmpty()) {
1151 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1155 QTableWidgetItem* anItem = aTable->item(i, 0);
1156 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1163 //=======================================================================
1164 // name : SMESHGUI_FilterTable::SetValidity
1165 // Purpose : Set validity of the table
1166 //=======================================================================
1167 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1169 myIsValid = isValid;
1172 //=======================================================================
1173 // name : SMESHGUI_FilterTable::GetType
1174 // Purpose : Get current entity type
1175 //=======================================================================
1176 int SMESHGUI_FilterTable::GetType() const
1178 return myEntityType;
1181 //=======================================================================
1182 // name : SMESHGUI_FilterTable::SetType
1183 // Purpose : Set current entity type
1184 //=======================================================================
1185 void SMESHGUI_FilterTable::SetType (const int type)
1187 myEntityTypeGrp->button(type)->setChecked(true);
1191 //=======================================================================
1192 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1193 // Purpose : Restore previous entity type
1194 //=======================================================================
1195 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1197 SetType(myEntityType);
1200 //=======================================================================
1201 // name : SMESHGUI_FilterTable::GetCriterionType
1202 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1203 //=======================================================================
1204 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1206 int aType = theType == -1 ? GetType() : theType;
1207 Table* aTable = myTables[ aType ];
1208 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1209 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1212 //=======================================================================
1213 // name : SMESHGUI_FilterTable::GetCriterion
1214 // Purpose : Get parameters of criterion from specified row
1215 //=======================================================================
1216 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1217 SMESH::Filter::Criterion& theCriterion,
1218 const int theEntityType) const
1220 int aType = theEntityType == -1 ? GetType() : theEntityType;
1221 Table* aTable = myTables[ aType ];
1223 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1224 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1225 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1226 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1227 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1229 int aCriterionType = GetCriterionType(theRow, aType);
1231 if ( aCriterionType == SMESH::FT_GroupColor )
1233 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1236 const QColor qClr = clrBtn->color();
1237 QString clrStr = QString( "%1;%2;%3" ).
1238 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1239 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1242 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1243 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1244 else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1245 theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1246 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1247 aCriterionType != SMESH::FT_BelongToGeom &&
1248 aCriterionType != SMESH::FT_BelongToPlane &&
1249 aCriterionType != SMESH::FT_BelongToCylinder &&
1250 aCriterionType != SMESH::FT_BelongToGenSurface &&
1251 aCriterionType != SMESH::FT_LyingOnGeom )
1253 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1254 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1258 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1259 if ( aCriterionType != SMESH::FT_RangeOfIds )
1260 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1263 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1264 if (myAddWidgets.contains(anItem))
1265 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1268 //=======================================================================
1269 // name : SMESHGUI_FilterTable::SetCriterion
1270 // Purpose : Set parameters of criterion of specified row
1271 //=======================================================================
1272 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1273 const SMESH::Filter::Criterion& theCriterion,
1274 const int theEntityType)
1276 int aType = theEntityType == -1 ? GetType() : theEntityType;
1278 Table* aTable = myTables[ aType ];
1280 if (theRow > aTable->rowCount() - 1)
1283 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1284 onCriterionChanged(theRow, 0, aType);
1285 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1286 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1288 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1290 if (!aTable->isEditable(theRow, 4))
1291 aTable->setItem(theRow, 4, getBinaryItem());
1292 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1295 aTable->setEditable(false, theRow, 4);
1297 if (theCriterion.Type == SMESH::FT_GroupColor )
1299 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1303 QString clrStr( theCriterion.ThresholdStr );
1304 QStringList clrVals = clrStr.split( ";" );
1305 if ( clrVals.count() > 2 )
1306 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1307 (int)256*clrVals[1].toDouble(),
1308 (int)256*clrVals[2].toDouble() );
1309 clrBtn->setColor( qClr );
1312 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1314 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1315 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1317 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1319 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1321 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1322 theCriterion.Type != SMESH::FT_BelongToGeom &&
1323 theCriterion.Type != SMESH::FT_BelongToPlane &&
1324 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1325 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1326 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1327 theCriterion.Type != SMESH::FT_CoplanarFaces &&
1328 theCriterion.Type != SMESH::FT_FreeBorders &&
1329 theCriterion.Type != SMESH::FT_FreeEdges &&
1330 theCriterion.Type != SMESH::FT_FreeNodes &&
1331 theCriterion.Type != SMESH::FT_FreeFaces &&
1332 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1333 theCriterion.Type != SMESH::FT_BareBorderFace &&
1334 theCriterion.Type != SMESH::FT_BareBorderVolume &&
1335 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1336 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1337 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1339 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1343 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1344 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1345 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1348 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1349 theCriterion.Type == SMESH::FT_BelongToPlane ||
1350 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1351 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1352 theCriterion.Type == SMESH::FT_BelongToGeom ||
1353 theCriterion.Type == SMESH::FT_LyingOnGeom ||
1354 theCriterion.Type == SMESH::FT_CoplanarFaces ||
1355 theCriterion.Type == SMESH::FT_EqualNodes)
1357 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1358 if (!myAddWidgets.contains(anItem))
1360 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1361 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1362 myWgStack->addWidget(myAddWidgets[ anItem ]);
1364 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1367 emit CriterionChanged(theRow, aType);
1370 //=======================================================================
1371 // name : SMESHGUI_FilterTable::Update
1372 // Purpose : Update table
1373 //=======================================================================
1374 void SMESHGUI_FilterTable::Update()
1376 Table* aTable = myTables[ GetType() ];
1377 int aCurrRow = aTable->currentRow();
1378 int numRows = aTable->rowCount();
1379 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1380 aTable->setCurrentCell(0, 0);
1381 updateAdditionalWidget();
1384 //=======================================================================
1385 // name : SMESHGUI_FilterTable::AddCriterion
1386 // Purpose : Add criterion with parameters
1387 //=======================================================================
1388 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1389 const int theEntityType)
1391 int aType = theEntityType == -1 ? GetType() : theEntityType;
1392 Table* aTable = myTables[ aType ];
1393 addRow(aTable, aType);
1394 SetCriterion(aTable->rowCount() - 1, theCriterion);
1397 //=======================================================================
1398 // name : SMESHGUI_FilterTable::NumRows
1399 // Purpose : Get number of criterions of current type
1400 //=======================================================================
1401 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1403 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1406 //=======================================================================
1407 // name : SMESHGUI_FilterTable::Clear
1408 // Purpose : Clear current table
1409 //=======================================================================
1410 void SMESHGUI_FilterTable::Clear (const int theType)
1412 int aType = theType == -1 ? GetType() : theType;
1413 Table* aTable = myTables[ aType ];
1415 if (aTable->rowCount() == 0)
1418 while (aTable->rowCount() > 0)
1420 removeAdditionalWidget(aTable, 0);
1421 aTable->removeRow(0);
1427 //=======================================================================
1428 // name : SMESHGUI_FilterTable::onAddBtn
1429 // Purpose : SLOT. Called then "Add" button pressed.
1430 // Adds new string to table
1431 //=======================================================================
1432 void SMESHGUI_FilterTable::onAddBtn()
1434 int aType = GetType();
1435 addRow(myTables[ aType ], aType);
1440 //=======================================================================
1441 // name : SMESHGUI_FilterTable::onInsertBtn
1442 // Purpose : SLOT. Called then "Insert" button pressed.
1443 // Inserts new string before current one
1444 //=======================================================================
1445 void SMESHGUI_FilterTable::onInsertBtn()
1447 addRow(myTables[ GetType() ], GetType(), false);
1450 //=======================================================================
1451 // name : SMESHGUI_FilterTable::onRemoveBtn
1452 // Purpose : SLOT. Called then "Remove" button pressed.
1453 // Removes current string from table
1454 //=======================================================================
1455 void SMESHGUI_FilterTable::onRemoveBtn()
1457 Table* aTable = myTables[ GetType() ];
1459 if (aTable->rowCount() == 0)
1462 QList<QTableWidgetItem*> items = aTable->selectedItems();
1464 QList<int> aRows = aTable->selectedRows(); // already sorted
1468 removeAdditionalWidget(aTable, i);
1469 aTable->removeRow(i);
1472 // remove control of binary logical operation from last row
1473 if (aTable->rowCount() > 0)
1474 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1479 //=======================================================================
1480 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1481 // Purpose : Enable/Disable widget with additonal parameters
1482 //=======================================================================
1483 void SMESHGUI_FilterTable::updateAdditionalWidget()
1485 Table* aTable = myTables[ GetType() ];
1486 int aRow = aTable->currentRow();
1487 if (aRow < 0 || aRow >= aTable->rowCount())
1489 myWgStack->setEnabled(false);
1493 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1494 int aCriterion = GetCriterionType(aRow);
1495 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1496 aCriterion != SMESH::FT_RangeOfIds &&
1497 aCriterion != SMESH::FT_FreeEdges &&
1498 aCriterion != SMESH::FT_FreeFaces &&
1499 aCriterion != SMESH::FT_BadOrientedVolume &&
1500 aCriterion != SMESH::FT_BareBorderFace &&
1501 aCriterion != SMESH::FT_BareBorderVolume &&
1502 aCriterion != SMESH::FT_OverConstrainedFace &&
1503 aCriterion != SMESH::FT_OverConstrainedVolume)
1505 aCriterion == SMESH::FT_CoplanarFaces);
1507 if (!myAddWidgets.contains(anItem))
1509 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1510 myWgStack->addWidget(myAddWidgets[ anItem ]);
1513 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1514 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1515 myWgStack->setEnabled(toEnable);
1518 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1520 const char* retval = 0;
1522 case SMESH::FT_AspectRatio:
1523 case SMESH::FT_AspectRatio3D:
1524 case SMESH::FT_Taper:
1525 retval = "parametric_precision"; break;
1526 case SMESH::FT_Warping:
1527 case SMESH::FT_MinimumAngle:
1528 case SMESH::FT_Skew:
1529 case SMESH::FT_CoplanarFaces:
1530 retval = "angle_precision"; break;
1531 case SMESH::FT_Area:
1532 retval = "area_precision"; break;
1533 case SMESH::FT_BelongToGeom:
1534 case SMESH::FT_BelongToPlane:
1535 case SMESH::FT_BelongToCylinder:
1536 case SMESH::FT_BelongToGenSurface:
1537 case SMESH::FT_LyingOnGeom:
1538 case SMESH::FT_EqualNodes:
1539 retval = "len_tol_precision"; break;
1540 case SMESH::FT_Length:
1541 case SMESH::FT_Length2D:
1542 case SMESH::FT_MaxElementLength2D:
1543 case SMESH::FT_MaxElementLength3D:
1544 retval = "length_precision"; break;
1545 case SMESH::FT_Volume3D:
1546 retval = "vol_precision"; break;
1553 //=======================================================================
1554 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1555 // Purpose : Remove widgets containing additional parameters from widget
1556 // stack and internal map
1557 //=======================================================================
1558 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1560 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1561 if (myAddWidgets.contains(anItem))
1563 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1564 myAddWidgets[ anItem ]->setParent(0);
1565 delete myAddWidgets[ anItem ];
1566 myAddWidgets.remove(anItem);
1570 //=======================================================================
1571 // name : SMESHGUI_FilterTable::onClearBtn
1572 // Purpose : SLOT. Called then "Clear" button pressed.
1573 // Removes all strings from table
1574 //=======================================================================
1575 void SMESHGUI_FilterTable::onClearBtn()
1577 Table* aTable = myTables[ GetType() ];
1579 if (aTable->rowCount() == 0)
1582 while (aTable->rowCount() > 0)
1584 removeAdditionalWidget(aTable, 0);
1585 aTable->removeRow(0);
1591 //=======================================================================
1592 // name : SMESHGUI_FilterTable::onCurrentChanged()
1593 // Purpose : SLOT. Called when current cell changed
1594 //=======================================================================
1595 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1598 updateAdditionalWidget();
1599 emit CurrentChanged(theRow, theCol);
1602 //=======================================================================
1604 // Purpose : returns available geometry types of elements
1605 //=======================================================================
1606 static QList<int> geomTypes( const int theType )
1609 if ( theType == SMESH::NODE )
1610 typeIds.append( SMESH::Geom_POINT );
1611 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1612 typeIds.append( SMESH::Geom_EDGE );
1613 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1615 typeIds.append( SMESH::Geom_TRIANGLE );
1616 typeIds.append( SMESH::Geom_QUADRANGLE );
1617 typeIds.append( SMESH::Geom_POLYGON );
1619 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1621 typeIds.append( SMESH::Geom_TETRA );
1622 typeIds.append( SMESH::Geom_PYRAMID );
1623 typeIds.append( SMESH::Geom_HEXA );
1624 typeIds.append( SMESH::Geom_PENTA );
1625 typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1626 typeIds.append( SMESH::Geom_POLYHEDRA );
1631 //=======================================================================
1632 // name : SMESHGUI_FilterTable::onCriterionChanged()
1633 // Purpose : Provides reaction on change of criterion
1634 //=======================================================================
1635 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1637 int aType = entityType == -1 ? GetType() : entityType;
1638 Table* aTable = myTables[ aType ];
1639 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1641 int aCriterionType = GetCriterionType(row);
1642 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1643 int aComboType = ComboItem::Type();
1644 int aIntSpinType = IntSpinItem::Type();
1645 int aDoubleSpinType = DoubleSpinItem::Type();
1646 QTableWidgetItem* aTableItem = aTable->item(row, 2);
1647 bool isComboItem = false;
1648 bool isIntSpinItem = false;
1649 bool isDoubleSpinItem = false;
1651 int aTableType = aTable->item(row, 2)->type();
1652 isComboItem = ( aTableType == aComboType );
1653 isIntSpinItem = ( aTableType == aIntSpinType );
1654 isDoubleSpinItem = ( aTableType == aDoubleSpinType );
1657 bool anIsDoubleCriterion =
1658 aCriterionType == SMESH::FT_AspectRatio ||
1659 aCriterionType == SMESH::FT_AspectRatio3D ||
1660 aCriterionType == SMESH::FT_Taper ||
1661 aCriterionType == SMESH::FT_Warping ||
1662 aCriterionType == SMESH::FT_MinimumAngle ||
1663 aCriterionType == SMESH::FT_Skew ||
1664 aCriterionType == SMESH::FT_Area ||
1665 aCriterionType == SMESH::FT_Length ||
1666 aCriterionType == SMESH::FT_Length2D ||
1667 aCriterionType == SMESH::FT_MaxElementLength2D ||
1668 aCriterionType == SMESH::FT_MaxElementLength3D ||
1669 aCriterionType == SMESH::FT_Volume3D;
1672 if ( anIsDoubleCriterion ) {
1673 const char* aPrecisionType = getPrecision( aCriterionType );
1674 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1675 if( aPrecisionType && aResourceMgr )
1676 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1679 // if the precision is to be changed we should remove the existing
1680 // spin item and create another one with new precision
1681 bool anIsPrecisionChanged = false;
1682 if ( anIsDoubleCriterion && isDoubleSpinItem ) {
1683 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
1684 anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
1688 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1689 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
1690 (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
1691 (!anIsDoubleCriterion && isDoubleSpinItem) ||
1692 anIsPrecisionChanged )
1694 bool isSignalsBlocked = aTable->signalsBlocked();
1695 aTable->blockSignals( true );
1696 aTable->removeCellWidget( row, 2 );
1697 aTable->setItem( row, 2, new QTableWidgetItem() );
1698 aTable->blockSignals( isSignalsBlocked );
1700 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1701 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
1702 (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
1703 (anIsDoubleCriterion && !isDoubleSpinItem) ||
1704 anIsPrecisionChanged )
1706 bool isSignalsBlocked = aTable->signalsBlocked();
1707 aTable->blockSignals( true );
1708 if ( aCriterionType == SMESH::FT_GroupColor )
1709 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1710 else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
1711 QList<int> typeIds = geomTypes( aType );
1712 QMap<int, QString> typeNames;
1713 QList<int>::const_iterator anIter = typeIds.begin();
1714 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1716 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1717 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1719 ComboItem* typeBox = new ComboItem( typeNames );
1720 aTable->setItem( row, 2, typeBox );
1722 else if ( aCriterionType == SMESH::FT_MultiConnection ) {
1723 IntSpinItem* intSpin = new IntSpinItem( 0 );
1724 aTable->setItem( row, 2, intSpin );
1726 else if ( anIsDoubleCriterion ) {
1727 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1728 dblSpin->setPrecision( aPrecision );
1729 aTable->setItem( row, 2, dblSpin );
1731 aTable->blockSignals( isSignalsBlocked );
1734 if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes ||
1735 aCriterionType == SMESH::FT_EqualNodes )) ||
1736 (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders ||
1737 aCriterionType == SMESH::FT_EqualEdges )) ||
1738 (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace ||
1739 aCriterionType == SMESH::FT_OverConstrainedFace ||
1740 aCriterionType == SMESH::FT_FreeEdges ||
1741 aCriterionType == SMESH::FT_FreeFaces ||
1742 aCriterionType == SMESH::FT_EqualFaces)) ||
1743 (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume ||
1744 aCriterionType == SMESH::FT_OverConstrainedVolume ||
1745 aCriterionType == SMESH::FT_BareBorderVolume ||
1746 aCriterionType == SMESH::FT_EqualVolumes )) ||
1747 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1748 aCriterionType == SMESH::FT_GroupColor ||
1749 aCriterionType == SMESH::FT_ElemGeomType ||
1750 aCriterionType == SMESH::FT_CoplanarFaces
1753 bool isSignalsBlocked = aTable->signalsBlocked();
1754 aTable->blockSignals( true );
1756 if (aCompareItem->count() > 0)
1757 aCompareItem->clear();
1758 aTable->setEditable(false, row, 1);
1759 aTable->item(row, 2)->setText( QString("") );
1760 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1761 aCriterionType == SMESH::FT_ElemGeomType ||
1762 aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
1763 aTable->blockSignals( isSignalsBlocked );
1765 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1766 aCriterionType == SMESH::FT_BelongToGeom ||
1767 aCriterionType == SMESH::FT_BelongToPlane ||
1768 aCriterionType == SMESH::FT_BelongToCylinder ||
1769 aCriterionType == SMESH::FT_BelongToGenSurface ||
1770 aCriterionType == SMESH::FT_LyingOnGeom)
1772 QMap<int, QString> aMap;
1773 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1774 aCompareItem->setItems(aMap);
1775 if (!aTable->isEditable(row, 2))
1776 aTable->setEditable(true, row, 1);
1777 if (!aTable->isEditable(row, 2))
1778 aTable->setEditable(true, row, 2);
1780 else if (aCriterionType == SMESH::FT_GroupColor ||
1781 aCriterionType == SMESH::FT_ElemGeomType)
1783 if (!aTable->isEditable(row, 2))
1784 aTable->setEditable(true, row, 2);
1788 if (aCompareItem && aCompareItem->count() != 3)
1790 aCompareItem->setItems(getCompare());
1793 if (aTable->item( row, 2 )) {
1794 QString aText = aTable->text(row, 2);
1796 aText.toDouble(&isOk);
1797 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1798 if (!aTable->isEditable(row, 1))
1799 aTable->setEditable(true, row, 1);
1800 if (!aTable->isEditable(row, 2))
1801 aTable->setEditable(true, row, 2);
1805 updateAdditionalWidget();
1807 emit CriterionChanged(row, entityType);
1810 //=======================================================================
1811 // name : SMESHGUI_FilterTable::onCriterionChanged()
1812 // Purpose : SLOT. Called then contents of table changed
1813 // Provides reaction on change of criterion
1814 //=======================================================================
1815 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1818 onCriterionChanged(row, col, -1);
1821 //=======================================================================
1822 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1823 // Purpose : Get first selected row
1824 //=======================================================================
1825 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1827 Table* aTable = myTables[ GetType() ];
1829 QList<int> selRows = aTable->selectedRows(); // already sorted
1830 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1832 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1835 //=======================================================================
1836 // name : SMESHGUI_FilterTable::addRow
1837 // Purpose : Add row at the end of table
1838 //=======================================================================
1839 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1842 int aSelectedRow = getFirstSelectedRow();
1843 int aCurrCol = theTable->currentColumn();
1846 if (toTheEnd || aSelectedRow == -1)
1848 theTable->insertRows(theTable->rowCount());
1849 aCurrRow = theTable->rowCount() - 1;
1853 theTable->insertRows(aSelectedRow);
1854 aCurrRow = aSelectedRow;
1858 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1859 bool isSignalsBlocked = theTable->signalsBlocked();
1860 theTable->blockSignals( true );
1863 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1866 theTable->setItem(aCurrRow, 1, getCompareItem());
1869 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1871 // Logical operation NOT
1872 theTable->setItem(aCurrRow, 3, getUnaryItem());
1874 // Logical operation AND / OR
1875 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1877 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1879 theTable->blockSignals( isSignalsBlocked );
1881 // Logical binary operation for previous value
1882 int anAddBinOpStr = -1;
1883 if (aCurrRow == theTable->rowCount() - 1)
1884 anAddBinOpStr = aCurrRow - 1;
1885 else if (aCurrRow >= 0 )
1886 anAddBinOpStr = aCurrRow;
1888 if (theTable->item(aCurrRow, 4) == 0 ||
1889 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1891 if (anAddBinOpStr >= 0 &&
1892 (theTable->item(anAddBinOpStr, 4) == 0 ||
1893 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1894 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1897 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1899 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1900 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1901 theTable->setCurrentCell(aCurrRow, aCurrCol);
1903 onCriterionChanged(aCurrRow, 0);
1908 //=======================================================================
1909 // name : SMESHGUI_FilterTable::getCriterionItem
1910 // Purpose : Get combo table item for criteria of specified type
1911 //=======================================================================
1912 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1914 return new ComboItem(getCriteria(theType));
1917 //=======================================================================
1918 // name : SMESHGUI_FilterTable::getCompareItem
1919 // Purpose : Get combo table item for operation of comparision
1920 //=======================================================================
1921 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1923 return new ComboItem(getCompare());
1926 //=======================================================================
1927 // name : SMESHGUI_FilterTable::getBinaryItem
1929 //=======================================================================
1930 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1932 static QMap<int, QString> aMap;
1935 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1936 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1939 return new ComboItem(aMap);
1942 //=======================================================================
1943 // name : SMESHGUI_FilterTable::getUnaryItem
1944 // Purpose : Get check table item
1945 //=======================================================================
1946 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1948 return new CheckItem(tr("NOT"));
1951 //=======================================================================
1952 // name : SMESHGUI_FilterTable::getSupportedTypes
1953 // Purpose : Get all supported type
1954 //=======================================================================
1955 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1957 static QMap<int, QString> aTypes;
1958 if (aTypes.isEmpty())
1960 aTypes[ SMESH::NODE ] = tr("NODES");
1961 aTypes[ SMESH::EDGE ] = tr("EDGES");
1962 aTypes[ SMESH::FACE ] = tr("FACES");
1963 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1964 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
1970 //=======================================================================
1971 // name : SMESHGUI_FilterTable::getCriteria
1972 // Purpose : Get criteria for specified type
1973 //=======================================================================
1974 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1976 if (theType == SMESH::NODE)
1978 static QMap<int, QString> aCriteria;
1979 if (aCriteria.isEmpty())
1981 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1982 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1983 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1984 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1985 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1986 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1987 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
1988 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1989 aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
1993 else if (theType == SMESH::EDGE)
1995 static QMap<int, QString> aCriteria;
1996 if (aCriteria.isEmpty())
1998 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1999 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
2000 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
2001 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2002 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2003 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2004 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2005 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2006 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2007 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2008 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2009 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2010 aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
2014 else if (theType == SMESH::FACE)
2016 static QMap<int, QString> aCriteria;
2017 if (aCriteria.isEmpty())
2019 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
2020 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
2021 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
2022 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
2023 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
2024 aCriteria[ SMESH::FT_Area ] = tr("AREA");
2025 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2026 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
2027 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2028 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2029 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2030 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2031 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2032 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2033 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
2034 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
2035 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
2036 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
2037 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2038 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2039 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2040 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2041 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
2042 aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
2046 else if (theType == SMESH::VOLUME)
2048 static QMap<int, QString> aCriteria;
2049 if (aCriteria.isEmpty())
2051 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
2052 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2053 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2054 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2055 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
2056 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
2057 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2058 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
2059 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
2060 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2061 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2062 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2063 aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
2069 static QMap<int, QString> aCriteria;
2070 if (aCriteria.isEmpty())
2072 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2073 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2074 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2075 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2076 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2077 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2085 //=======================================================================
2086 // name : SMESHGUI_FilterTable::getCompare
2087 // Purpose : Get operation of comparison
2088 //=======================================================================
2089 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2091 static QMap<int, QString> aMap;
2095 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2096 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2097 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
2103 //=======================================================================
2104 // name : SMESHGUI_FilterTable::createTable
2105 // Purpose : Create table
2106 //=======================================================================
2107 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
2111 Table* aTable= new Table(0, 6, theParent);
2113 QHeaderView* aHeaders = aTable->horizontalHeader();
2115 QFontMetrics aMetrics(aHeaders->font());
2117 // append spaces to the header of criteria in order to
2118 // provide visibility of criterion inside comboboxes
2119 static int aMaxLenCr = 0;
2123 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2124 QMap<int, QString>::const_iterator anIter;
2125 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2126 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2129 static int aLenCr = qAbs( aMaxLenCr -
2130 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2133 aCrStr.fill(' ', aLenCr);
2135 aCoStr.fill(' ', 10);
2137 QStringList aHeaderLabels;
2138 aHeaderLabels.append( tr("CRITERION") + aCrStr );
2139 aHeaderLabels.append( tr("COMPARE") + aCoStr );
2140 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2141 aHeaderLabels.append( tr("UNARY") );
2142 aHeaderLabels.append( tr("BINARY") + " " );
2143 aHeaderLabels.append( tr("ID") );
2144 aTable->setHorizontalHeaderLabels( aHeaderLabels );
2146 // set geometry of the table
2147 for (int i = 0; i <= 4; i++)
2148 aTable->resizeColumnToContents(i);
2150 // set the ID column invisible
2151 aTable->hideColumn( 5 );
2153 aTable->updateGeometry();
2154 QSize aSize = aTable->sizeHint();
2155 int aWidth = aSize.width();
2156 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2157 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2159 connect(aTable, SIGNAL(cellChanged(int, int)),
2160 this, SLOT(onCriterionChanged(int, int)));
2162 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2163 this, SLOT(onCurrentChanged(int, int)));
2168 //=======================================================================
2169 // name : SMESHGUI_FilterTable::updateBtnState
2170 // Purpose : Update button state
2171 //=======================================================================
2172 void SMESHGUI_FilterTable::updateBtnState()
2174 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2175 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2178 //=======================================================================
2179 // name : SMESHGUI_FilterTable::SetEditable
2180 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2181 //=======================================================================
2182 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2184 TableMap::iterator anIter;
2185 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2187 anIter.value()->setReadOnly(!isEditable);
2189 // Set Flags for CheckItems directly IPAL 19974
2190 Table* aTable = anIter.value();
2191 for (int i = 0, n = aTable->rowCount(); i < n; i++)
2192 for (int j = 0, m = aTable->columnCount(); j < m; j++)
2194 QTableWidgetItem* anItem = aTable->item(i, j);
2195 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2196 Qt::ItemFlags f = anItem->flags();
2197 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2198 else f = f | Qt::ItemIsUserCheckable;
2199 anItem->setFlags( f );
2207 myInsertBtn->show();
2208 myRemoveBtn->show();
2214 myInsertBtn->hide();
2215 myRemoveBtn->hide();
2220 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2221 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2222 anIter2.value()->SetEditable(isEditable);
2225 //=======================================================================
2226 // name : SMESHGUI_FilterTable::SetEnabled
2227 // Purpose : Enable/Disable table. Switching type of elements already enabled
2228 //=======================================================================
2229 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2231 myAddBtn->setEnabled(isEnabled);
2232 myInsertBtn->setEnabled(isEnabled);
2233 myRemoveBtn->setEnabled(isEnabled);
2234 myClearBtn->setEnabled(isEnabled);
2239 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2240 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2241 anIter2.value()->setEnabled(isEnabled);
2244 //=======================================================================
2245 // name : SMESHGUI_FilterTable::IsEditable
2246 // Purpose : Verify whether table is editable
2247 //=======================================================================
2248 bool SMESHGUI_FilterTable::IsEditable() const
2250 return !myTables[ GetType() ]->isReadOnly();
2253 //=======================================================================
2254 // name : SMESHGUI_FilterTable::SetLibsEnabled
2255 // Purpose : Show/hide buttons for work with libraries
2256 //=======================================================================
2257 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2261 myCopyFromBtn->show();
2266 myCopyFromBtn->hide();
2271 //=======================================================================
2272 // name : SMESHGUI_FilterTable::onCopyFromBtn
2273 // Purpose : SLOT. Called the "Copy from ..." button clicked
2274 // Display filter library dialog
2275 //=======================================================================
2276 void SMESHGUI_FilterTable::onCopyFromBtn()
2279 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2280 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2282 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2284 if (myLibDlg->exec() == QDialog::Accepted)
2286 Copy(myLibDlg->GetTable());
2291 //=======================================================================
2292 // name : SMESHGUI_FilterTable::onAddToBtn
2293 // Purpose : SLOT. Called the "Add to ..." button clicked
2294 // Display filter library dialog
2295 //=======================================================================
2296 void SMESHGUI_FilterTable::onAddToBtn()
2301 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2302 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2304 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2306 myLibDlg->SetTable(this);
2311 //=======================================================================
2312 // name : SMESHGUI_FilterTable::Copy
2313 // Purpose : Initialise table with values of other table
2314 //=======================================================================
2315 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2319 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2321 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2322 theTable->GetCriterion(i, aCriterion);
2323 AddCriterion(aCriterion);
2327 //=======================================================================
2328 // name : SMESHGUI_FilterTable::CurrentCell
2329 // Purpose : Returns current cell
2330 //=======================================================================
2331 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2333 theRow = myTables[ GetType() ]->currentRow();
2334 theCol = myTables[ GetType() ]->currentColumn();
2335 return theRow >= 0 && theCol >= 0;
2338 //=======================================================================
2339 // name : SMESHGUI_FilterTable::SetText
2340 // Purpose : Set text and internal value in cell of threshold value
2341 //=======================================================================
2342 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2343 const QString& theText,
2344 const int theEntityType)
2346 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2347 aTable->item( theRow, 2 )->setText(theText);
2350 //=======================================================================
2351 // name : SMESHGUI_FilterTable::SetText
2352 // Purpose : Get text and internal value from cell of threshold value
2353 //=======================================================================
2354 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2356 const int theEntityType)
2358 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2359 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2362 theText = anItem->text();
2369 //=======================================================================
2370 // name : SMESHGUI_FilterTable::SetID
2371 // Purpose : Set text and internal value in cell of ID value
2372 //=======================================================================
2373 void SMESHGUI_FilterTable::SetID( const int theRow,
2374 const QString& theText,
2375 const int theEntityType )
2377 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2378 aTable->item( theRow, 5 )->setText( theText );
2381 //=======================================================================
2382 // name : SMESHGUI_FilterTable::GetID
2383 // Purpose : Get text and internal value from cell of ID value
2384 //=======================================================================
2385 bool SMESHGUI_FilterTable::GetID( const int theRow,
2387 const int theEntityType )
2389 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2390 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2393 theText = anItem->text();
2401 Class : SMESHGUI_FilterDlg
2402 Description : Dialog to specify filters for VTK viewer
2406 //=======================================================================
2407 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2408 // Purpose : Constructor
2409 //=======================================================================
2410 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2411 const QList<int>& theTypes )
2412 : QDialog( SMESH::GetDesktop( theModule ) ),
2413 mySMESHGUI( theModule ),
2414 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2415 myInitSourceWgOnApply( true )
2417 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2418 mySelector = aViewWindow->GetSelector();
2420 construct(theTypes);
2423 //=======================================================================
2424 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2425 // Purpose : Constructor
2426 //=======================================================================
2427 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2429 : QDialog( SMESH::GetDesktop( theModule ) ),
2430 mySMESHGUI( theModule ),
2431 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2432 myInitSourceWgOnApply( true )
2434 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2435 mySelector = aViewWindow->GetSelector();
2437 aTypes.append(theType);
2441 //=======================================================================
2442 // name : SMESHGUI_FilterDlg::construct
2443 // Purpose : Construct dialog (called by constructor)
2444 //=======================================================================
2445 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2450 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2451 setWindowTitle(tr("CAPTION"));
2453 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2454 aDlgLay->setMargin(MARGIN);
2455 aDlgLay->setSpacing(SPACING);
2457 myMainFrame = createMainFrame (this);
2458 QWidget* aBtnFrame = createButtonFrame(this);
2460 aDlgLay->addWidget(myMainFrame);
2461 aDlgLay->addWidget(aBtnFrame);
2463 aDlgLay->setStretchFactor(myMainFrame, 1);
2465 myHelpFileName = "selection_filter_library_page.html";
2470 //=======================================================================
2471 // name : SMESHGUI_FilterDlg::createMainFrame
2472 // Purpose : Create frame containing dialog's input fields
2473 //=======================================================================
2474 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2476 QWidget* aMainFrame = new QWidget(theParent);
2477 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2478 aMainLay->setMargin(0);
2479 aMainLay->setSpacing(SPACING);
2483 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2484 myTable->SetLibsEnabled(true);
2486 QGroupBox* aGrp = myTable->GetTableGrp();
2487 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2488 int rows = aLay->rowCount();
2489 int cols = aLay->columnCount();
2491 QFrame* aLine = new QFrame(aGrp);
2492 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2493 aLay->addWidget(aLine, rows++, 0, 1, cols);
2495 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2496 mySetInViewer->setChecked(true);
2497 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2500 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2502 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2503 SLOT(onCriterionChanged(const int, const int)));
2505 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2506 SLOT(onCurrentChanged(int, int)));
2508 aMainLay->addWidget(myTable);
2509 aMainLay->addWidget(aSourceGrp);
2514 //=======================================================================
2515 // name : SMESHGUI_FilterDlg::createSourceFrame
2516 // Purpose : Create frame containing source radio button
2517 //=======================================================================
2518 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2520 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2521 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2522 aLay->setMargin(MARGIN);
2523 aLay->setSpacing(SPACING);
2525 mySourceGrp = new QButtonGroup(theParent);
2527 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2528 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2529 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2531 aLay->addWidget(aMeshBtn);
2532 aLay->addWidget(aSelBtn);
2533 aLay->addWidget(aDlgBtn);
2535 mySourceGrp->addButton(aMeshBtn, Mesh);
2536 mySourceGrp->addButton(aSelBtn, Selection);
2537 mySourceGrp->addButton(aDlgBtn, Dialog);
2539 aMeshBtn->setChecked(true);
2544 //=======================================================================
2545 // name : SMESHGUI_FilterDlg::updateMainButtons
2546 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2547 //=======================================================================
2548 void SMESHGUI_FilterDlg::updateMainButtons()
2550 myButtons[ BTN_Close ]->show();
2551 if (myTypes.count() == 1)
2553 myButtons[ BTN_Apply ]->hide();
2557 myButtons[ BTN_Apply ]->show();
2559 // updateGeometry();
2562 //=======================================================================
2563 // name : SMESHGUI_FilterDlg::createButtonFrame
2564 // Purpose : Create frame containing buttons
2565 //=======================================================================
2566 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2568 QGroupBox* aGrp = new QGroupBox(theParent);
2569 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2570 aLay->setMargin(MARGIN);
2571 aLay->setSpacing(SPACING);
2573 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2574 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2575 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2576 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2578 aLay->addWidget(myButtons[ BTN_OK ]);
2579 aLay->addSpacing(10);
2580 aLay->addWidget(myButtons[ BTN_Apply ]);
2581 aLay->addSpacing(10);
2583 aLay->addWidget(myButtons[ BTN_Close ]);
2584 aLay->addWidget(myButtons[ BTN_Help ]);
2586 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2587 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
2588 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2589 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2591 updateMainButtons();
2596 //=======================================================================
2597 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2598 // Purpose : Destructor
2599 //=======================================================================
2600 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2604 //=======================================================================
2605 // name : SMESHGUI_FilterDlg::Init
2606 // Purpose : Init dialog fields, connect signals and slots, show dialog
2607 //=======================================================================
2608 void SMESHGUI_FilterDlg::Init (const int type)
2611 aTypes.append(type);
2615 //=======================================================================
2616 // name : SMESHGUI_FilterDlg::Init
2617 // Purpose : Init dialog fields, connect signals and slots, show dialog
2618 //=======================================================================
2619 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2623 myMesh = SMESH::SMESH_Mesh::_nil();
2625 myIsSelectionChanged = false;
2627 myTable->Init(theTypes);
2630 if (theTypes.count() == 1)
2632 int aType = theTypes.first();
2633 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2634 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2635 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2636 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2637 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2640 setWindowTitle(tr("TLT"));
2642 qApp->processEvents();
2647 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2649 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2650 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2652 updateMainButtons();
2655 // Initialise filter table with values of previous filter
2656 QList<int>::const_iterator anIter;
2657 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2659 myTable->Clear(*anIter);
2660 if (!myFilter[ *anIter ]->_is_nil())
2662 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2663 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2665 for (int i = 0, n = aCriteria->length(); i < n; i++)
2666 myTable->AddCriterion(aCriteria[ i ], *anIter);
2671 if (myInsertState.contains(theTypes.first()))
2672 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2674 mySetInViewer->setChecked(true);
2676 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2677 myApplyToState[ theTypes.first() ] :
2678 Mesh)->setChecked(true);
2681 //=======================================================================
2682 // name : SMESHGUI_FilterDlg::onOk
2683 // Purpose : SLOT called when "Ok" button pressed.
2684 // Assign filters VTK viewer and close dialog
2685 //=======================================================================
2686 void SMESHGUI_FilterDlg::onOk()
2690 mySelectionMgr->clearFilters();
2691 disconnect(mySMESHGUI, 0, this, 0);
2692 disconnect(mySelectionMgr, 0, this, 0);
2693 mySMESHGUI->ResetState();
2699 //=======================================================================
2700 // name : SMESHGUI_FilterDlg::onClose
2701 // Purpose : SLOT called when "Close" button pressed. Close dialog
2702 //=======================================================================
2703 void SMESHGUI_FilterDlg::onClose()
2705 // Restore previously selected object
2708 SALOME_ListIO aList;
2709 mySelectionMgr->clearFilters();
2710 mySelectionMgr->clearSelected();
2711 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2712 for ( ; anIter.More(); anIter.Next())
2714 aList.Append(anIter.Key());
2716 TColStd_MapOfInteger aResMap;
2717 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2718 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2719 aResMap.Add(anIndMap(i));
2721 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2722 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2723 aViewWindow->highlight( anIter.Key(), true, true );
2725 mySelectionMgr->setSelectedObjects(aList, false);
2728 disconnect(mySMESHGUI, 0, this, 0);
2729 disconnect(mySelectionMgr, 0, this, 0);
2730 mySMESHGUI->ResetState();
2735 //=================================================================================
2736 // function : onHelp()
2738 //=================================================================================
2739 void SMESHGUI_FilterDlg::onHelp()
2741 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2743 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2747 platform = "winapplication";
2749 platform = "application";
2751 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2752 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2753 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2755 arg(myHelpFileName));
2759 //=======================================================================
2760 // name : SMESHGUI_FilterDlg::onDeactivate
2761 // Purpose : SLOT called when dialog must be deativated
2762 //=======================================================================
2763 void SMESHGUI_FilterDlg::onDeactivate()
2768 //=======================================================================
2769 // name : SMESHGUI_FilterDlg::enterEvent
2770 // Purpose : Event filter
2771 //=======================================================================
2772 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2774 // mySMESHGUI->EmitSignalDeactivateDialog();
2775 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2776 mySMESHGUI->ResetState();
2780 //=======================================================================
2781 // name : closeEvent()
2783 //=======================================================================
2784 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2789 //=======================================================================
2790 // name : SMESHGUI_FilterDlg::getIdsFromWg
2791 // Purpose : Retrieve list of ids from given widget
2792 //=======================================================================
2793 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2799 if (theWg->inherits("QListWidget"))
2801 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2803 for (int i = 0, n = aListBox->count(); i < n; i++)
2805 int anId = aListBox->item(i)->text().toInt(&b);
2807 theRes.append(anId);
2810 else if (theWg->inherits("QLineEdit"))
2812 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2813 QString aStr = aLineEdit->text();
2814 QRegExp aRegExp("(\\d+)");
2819 aPos = aRegExp.indexIn(aStr, aPos);
2822 int anId = aRegExp.cap(1).toInt(&b);
2824 theRes.append(anId);
2825 aPos += aRegExp.matchedLength();
2831 //=======================================================================
2832 // name : SMESHGUI_FilterDlg::getSelMode
2833 // Purpose : Get selection mode of specified type
2834 //=======================================================================
2835 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2839 case SMESH::NODE : return NodeSelection;
2840 case SMESH::EDGE : return EdgeSelection;
2841 case SMESH::FACE : return FaceSelection;
2842 case SMESH::VOLUME : return VolumeSelection;
2843 case SMESH::ALL : return CellSelection;
2844 default : return ActorSelection;
2849 //=======================================================================
2850 // name : SMESHGUI_FilterDlg::setIdsToWg
2851 // Purpose : Insert identifiers in specified widgets
2852 //=======================================================================
2853 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2858 QStringList aStrList;
2859 foreach(int id, theIds)
2860 aStrList << QString::number(id);
2862 if (theWg->inherits("QListWidget"))
2864 qobject_cast<QListWidget*>(theWg)->clear();
2865 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2867 else if (theWg->inherits("QLineEdit"))
2869 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2873 //=======================================================================
2874 // name : SMESHGUI_FilterDlg::isValid
2875 // Purpose : Verify validity of input data
2876 //=======================================================================
2877 bool SMESHGUI_FilterDlg::isValid() const
2879 if (!myTable->IsValid())
2882 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2884 int aType = myTable->GetCriterionType(i);
2885 if (aType == SMESH::FT_BelongToGeom ||
2886 aType == SMESH::FT_BelongToPlane ||
2887 aType == SMESH::FT_BelongToCylinder ||
2888 aType == SMESH::FT_BelongToGenSurface ||
2889 aType == SMESH::FT_LyingOnGeom)
2892 myTable->GetThreshold(i, aName);
2894 std::vector<_PTR(SObject)> aList =
2895 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2896 if (aList.size() == 0) {
2897 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2898 tr("BAD_SHAPE_NAME").arg(aName));
2902 if (aType == SMESH::FT_BelongToCylinder ||
2903 aType == SMESH::FT_BelongToPlane ||
2904 aType == SMESH::FT_BelongToGenSurface ) {
2905 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2906 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2907 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2908 if (!aGeomObj->_is_nil()) {
2910 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2912 aFace.ShapeType() != TopAbs_FACE) {
2913 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2914 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2918 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2919 if (aSurf.IsNull()) {
2920 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2921 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2925 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2926 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2927 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2931 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2932 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2933 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2939 else if (aType == SMESH::FT_CoplanarFaces)
2942 myTable->GetThreshold(i, faceID);
2943 if ( faceID.isEmpty() )
2945 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2946 tr("FACE_ID_NOT_SELECTED"));
2949 if ( myMesh->_is_nil() )
2951 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2952 tr("MESH_IS_NOT_SELECTED"));
2955 if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
2957 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2958 tr("NOT_FACE_ID").arg(faceID));
2967 //=======================================================================
2968 // name : SMESHGUI_FilterDlg::SetSourceWg
2969 // Purpose : Set widget of parent dialog containing idsto be filtered if
2970 // user select corresponding source radio button
2971 //=======================================================================
2972 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
2973 const bool initOnApply)
2976 myInitSourceWgOnApply = initOnApply;
2979 //=======================================================================
2980 // name : SMESHGUI_FilterDlg::SetMesh
2981 // Purpose : Set mesh
2982 //=======================================================================
2983 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2985 if ( !theMesh->_is_nil() ) {
2987 if ( !myFilter[ myTable->GetType() ]->_is_nil())
2988 myFilter[ myTable->GetType() ]->SetMesh( theMesh );
2990 const bool isEnable = !(myMesh->_is_nil());
2991 myButtons[BTN_OK]->setEnabled(isEnable);
2992 myButtons[BTN_Apply]->setEnabled(isEnable);
2995 //=======================================================================
2996 // name : SMESHGUI_FilterDlg::SetSelection
2997 // Purpose : Get filtered ids
2998 //=======================================================================
2999 void SMESHGUI_FilterDlg::SetSelection()
3002 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3004 if (mySelectionMgr) {
3006 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
3007 SALOME_ListIteratorOfListIO anIter (anObjs);
3008 for ( ; anIter.More(); anIter.Next()) {
3009 TColStd_IndexedMapOfInteger aMap;
3010 mySelector->GetIndex(anIter.Value(), aMap);
3011 myIObjects.Bind(anIter.Value(), aMap);
3014 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3022 //=======================================================================
3023 // name : SMESHGUI_FilterDlg::onApply
3024 // Purpose : SLOT called when "Apply" button pressed.
3025 // Assign filters to VTK viewer
3026 //=======================================================================
3027 bool SMESHGUI_FilterDlg::onApply()
3033 int aCurrType = myTable->GetType();
3035 if (!createFilter(aCurrType))
3038 insertFilterInViewer();
3040 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3041 QList<int> aResultIds;
3042 filterSource(aCurrType, aResultIds);
3044 selectInViewer(aCurrType, aResultIds);
3048 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3049 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3051 catch(const SALOME::SALOME_Exception& S_ex)
3053 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3062 //=======================================================================
3063 // name : SMESHGUI_FilterDlg::createFilter
3064 // Purpose : Create predicate for given type
3065 //=======================================================================
3066 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3068 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3069 if (aFilterMgr->_is_nil())
3072 int n = myTable->NumRows();
3074 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3075 aCriteria->length(n);
3077 long aPrecision = -1;
3078 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3080 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3081 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3083 for (CORBA::ULong i = 0; i < n; i++) {
3084 SMESH::Filter::Criterion aCriterion = createCriterion();
3085 myTable->GetCriterion(i, aCriterion);
3086 aCriterion.Precision = aPrecision;
3087 aCriteria[ i ] = aCriterion;
3090 myFilter[ theType ] = aFilterMgr->CreateFilter();
3091 myFilter[ theType ]->SetCriteria(aCriteria.inout());
3096 //================================================================================
3098 * \brief Return the current filter
3100 //================================================================================
3102 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3104 SMESH::Filter_var filter;
3106 int aCurrType = myTable->GetType();
3107 filter = myFilter[ aCurrType ];
3112 return filter._retn();
3115 //================================================================================
3117 * \brief Sets a filter to the table
3119 //================================================================================
3121 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3123 myFilter[ type ] = filter;
3126 //=======================================================================
3127 // name : SMESHGUI_FilterDlg::insertFilterInViewer
3128 // Purpose : Insert filter in viewer
3129 //=======================================================================
3130 void SMESHGUI_FilterDlg::insertFilterInViewer()
3132 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3133 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3135 if (myFilter[ myTable->GetType() ]->_is_nil() ||
3136 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3137 !mySetInViewer->isChecked()) {
3138 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3141 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3142 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3143 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3144 SMESH::SetFilter(aFilter, aSelector);
3149 //=======================================================================
3150 // name : SMESHGUI_FilterDlg::filterSource
3151 // Purpose : Filter source ids
3152 //=======================================================================
3153 void SMESHGUI_FilterDlg::filterSource (const int theType,
3154 QList<int>& theResIds)
3157 if (myFilter[ theType ]->_is_nil())
3160 int aSourceId = mySourceGrp->checkedId();
3162 if (aSourceId == Mesh)
3164 if (myMesh->_is_nil())
3166 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3167 for (int i = 0, n = anIds->length(); i < n; i++)
3168 theResIds.append(anIds[ i ]);
3170 else if (aSourceId == Selection)
3172 filterSelectionSource(theType, theResIds);
3174 else if (aSourceId == Dialog)
3176 // retrieve ids from dialog
3177 QList<int> aDialogIds;
3178 getIdsFromWg(mySourceWg, aDialogIds);
3180 if (myMesh->_is_nil())
3182 theResIds = aDialogIds;
3187 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3188 QList<int>::const_iterator anIter;
3189 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3190 if (aPred->IsSatisfy(*anIter))
3191 theResIds.append(*anIter);
3193 // set ids to the dialog
3194 if (myInitSourceWgOnApply || aSourceId == Dialog)
3195 setIdsToWg(mySourceWg, theResIds);
3198 //=======================================================================
3199 // name : SMESHGUI_FilterDlg::filterSelectionSource
3200 // Purpose : Filter source selection
3201 //=======================================================================
3202 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3203 QList<int>& theResIds)
3206 if (myMesh->_is_nil() || mySelectionMgr == 0)
3209 // Create map of entities to be filtered
3210 TColStd_MapOfInteger aToBeFiltered;
3211 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3213 for ( ; anIter.More(); anIter.Next())
3216 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3217 if (!aSubMesh->_is_nil())
3219 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3221 SMESH::long_array_var anIds =
3222 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3223 for (int i = 0, n = anIds->length(); i < n; i++)
3224 aToBeFiltered.Add(anIds[ i ]);
3229 SMESH::SMESH_GroupBase_var aGroup =
3230 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3231 if (!aGroup->_is_nil())
3233 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3235 SMESH::long_array_var anIds = aGroup->GetListOfID();
3236 for (int i = 0, n = anIds->length(); i < n; i++)
3237 aToBeFiltered.Add(anIds[ i ]);
3242 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3243 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3245 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3247 if (aSelMap.Extent() > 0)
3249 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3251 for (int i = 1; i <= aSelMap.Extent(); i++)
3252 aToBeFiltered.Add(aSelMap(i));
3259 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3260 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3261 for ( ; aResIter.More(); aResIter.Next())
3262 if (aPred->IsSatisfy(aResIter.Key()))
3263 theResIds.append(aResIter.Key());
3266 //=======================================================================
3267 // name : SMESHGUI_FilterDlg::selectInViewer
3268 // Purpose : Select given entities in viewer
3269 //=======================================================================
3270 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3272 if (mySelectionMgr == 0 || myMesh->_is_nil())
3275 mySelectionMgr->clearFilters();
3277 // Set new selection mode if necessary
3278 Selection_Mode aSelMode = getSelMode(theType);
3279 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3280 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3281 mySelectionMgr->clearSelected();
3282 mySelectionMgr->clearFilters();
3283 if (aSelMode == NodeSelection)
3284 SMESH::SetPointRepresentation(true);
3285 aViewWindow->SetSelectionMode(aSelMode);
3289 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3290 if (!anActor || !anActor->hasIO())
3293 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3294 //mySelectionMgr->clearSelected();
3295 //mySelectionMgr->AddIObject(anIO, false);
3296 SALOME_ListIO aList;
3298 mySelectionMgr->setSelectedObjects(aList, false);
3300 // Remove filter corresponding to the current type from viewer
3301 int aType = myTable->GetType();
3302 int aFilterId = SMESH::UnknownFilter;
3303 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3304 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3305 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3306 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3307 SMESH::RemoveFilter(aFilterId);
3310 TColStd_MapOfInteger aMap;
3311 QList<int>::const_iterator anIter;
3312 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3316 // Set new selection
3317 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3318 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3319 aViewWindow->highlight( anIO, true, true );
3321 // insert previously stored filter in viewer if necessary
3322 if (!aFilter.IsNull())
3323 SMESH::SetFilter(aFilter);
3326 //=======================================================================
3327 // name : SMESHGUI_FilterDlg::createCriterion
3328 // Purpose : Create criterion structure with default values
3329 //=======================================================================
3330 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3332 SMESH::Filter::Criterion aCriterion;
3334 aCriterion.Type = SMESH::FT_Undefined;
3335 aCriterion.Compare = SMESH::FT_Undefined;
3336 aCriterion.Threshold = 0;
3337 aCriterion.UnaryOp = SMESH::FT_Undefined;
3338 aCriterion.BinaryOp = SMESH::FT_Undefined;
3339 aCriterion.ThresholdStr = "";
3340 aCriterion.ThresholdID = "";
3341 aCriterion.TypeOfElement = SMESH::ALL;
3346 //=======================================================================
3347 // name : SMESHGUI_FilterDlg::onSelectionDone
3348 // Purpose : SLOT called when selection changed.
3349 // If current cell corresponds to the threshold value of
3350 // BelongToGeom criterion name of selected object is set in this cell
3351 //=======================================================================
3352 void SMESHGUI_FilterDlg::onSelectionDone()
3355 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3357 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3358 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3359 if ( !(myMesh->_is_nil()) ) {
3360 myButtons[BTN_OK]->setEnabled(true);
3361 myButtons[BTN_Apply]->setEnabled(true);
3366 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3367 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3368 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces;
3369 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
3370 !types.contains(myTable->GetCriterionType(aRow)))
3373 if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
3376 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
3377 aList.First(), aString);
3379 myTable->SetThreshold(aRow, aString);
3383 Handle(SALOME_InteractiveObject) anIO = aList.First();
3384 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3385 if (!anObj->_is_nil())
3387 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3388 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3389 myTable->SetID(aRow, anIO->getEntry());
3395 //=======================================================================
3396 // name : SMESHGUI_FilterDlg::onCriterionChanged
3397 // Purpose : SLOT called when cretarion of current row changed. Update selection
3398 //=======================================================================
3399 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3404 //=======================================================================
3405 // name : SMESHGUI_FilterDlg::onCurrentChanged
3406 // Purpose : SLOT called when current row changed. Update selection
3407 //=======================================================================
3408 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3413 //=======================================================================
3414 // name : SMESHGUI_FilterDlg::updateSelection
3415 // Purpose : UpdateSelection in accordance with current row
3416 //=======================================================================
3417 void SMESHGUI_FilterDlg::updateSelection()
3419 if (mySelectionMgr == 0)
3422 // TColStd_MapOfInteger allTypes;
3423 // for( int i=0; i<10; i++ )
3424 // allTypes.Add( i );
3425 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3430 mySelectionMgr->clearFilters();
3434 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3435 int aCriterionType = myTable->GetCriterionType(aRow);
3436 if ( isCurrentCell &&
3437 (aCriterionType == SMESH::FT_BelongToGeom ||
3438 aCriterionType == SMESH::FT_BelongToPlane ||
3439 aCriterionType == SMESH::FT_BelongToCylinder ||
3440 aCriterionType == SMESH::FT_BelongToGenSurface ||
3441 aCriterionType == SMESH::FT_LyingOnGeom))
3443 if (aCriterionType == SMESH::FT_BelongToGeom ||
3444 aCriterionType == SMESH::FT_BelongToGenSurface ||
3445 aCriterionType == SMESH::FT_LyingOnGeom) {
3447 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3449 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3450 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3452 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3453 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3455 myIsSelectionChanged = true;
3460 if (myIsSelectionChanged) {
3461 // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3462 // Impossible to select any object in the OB on the second opening of FilterDlg
3467 //=================================================================================
3468 // function : keyPressEvent()
3470 //=================================================================================
3471 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3473 QDialog::keyPressEvent( e );
3474 if ( e->isAccepted() )
3477 if ( e->key() == Qt::Key_F1 ) {