1 // Copyright (C) 2007-2013 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.
29 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_Filter.h"
35 #include "SMESHGUI_FilterUtils.h"
36 #include "SMESHGUI_FilterLibraryDlg.h"
37 #include "SMESHGUI_SpinBox.h"
39 #include "SMESH_Actor.h"
40 #include "SMESH_NumberFilter.hxx"
41 #include "SMESH_TypeFilter.hxx"
42 #include "SMESH_LogicalFilter.hxx"
44 // SALOME GEOM includes
46 #include <GEOM_FaceFilter.h>
47 #include <GEOM_TypeFilter.h>
49 // SALOME GUI includes
50 #include <SUIT_Desktop.h>
51 #include <SUIT_ResourceMgr.h>
52 #include <SUIT_Session.h>
53 #include <SUIT_MessageBox.h>
54 #include <SUIT_OverrideCursor.h>
55 #include <QtxColorButton.h>
57 #include <LightApp_Application.h>
58 #include <LightApp_SelectionMgr.h>
59 #include <SalomeApp_Tools.h>
60 #include <SalomeApp_Study.h>
61 #include <SalomeApp_IntSpinBox.h>
62 #include <SalomeApp_DoubleSpinBox.h>
64 #include <SALOME_ListIO.hxx>
65 #include <SALOME_ListIteratorOfListIO.hxx>
66 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
68 #include <SVTK_ViewWindow.h>
70 // SALOME KERNEL includes
71 #include <SALOMEDSClient_Study.hxx>
72 #include <Basics_Utils.hxx>
75 #include <StdSelect_TypeOfFace.hxx>
76 #include <BRep_Tool.hxx>
78 #include <TopoDS_Shape.hxx>
79 #include <Geom_Plane.hxx>
80 #include <Geom_CylindricalSurface.hxx>
81 #include <Precision.hxx>
82 #include <TColStd_MapOfInteger.hxx>
83 #include <TColStd_IndexedMapOfInteger.hxx>
84 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
89 #include <QPushButton>
91 #include <QTableWidget>
92 #include <QStringList>
93 #include <QHBoxLayout>
94 #include <QVBoxLayout>
95 #include <QGridLayout>
96 #include <QStackedWidget>
97 #include <QApplication>
99 #include <QFontMetrics>
101 #include <QButtonGroup>
102 #include <QRadioButton>
104 #include <QListWidget>
106 #include <QItemDelegate>
107 #include <QDoubleValidator>
109 #include <QHeaderView>
112 #include <SALOMEconfig.h>
113 #include CORBA_SERVER_HEADER(SMESH_Group)
118 //---------------------------------------
120 //---------------------------------------
121 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
124 QMap<int, QString>::const_iterator anIter;
125 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
126 aRes = qMax(aRes, theMetrics.width(anIter.value()));
130 //---------------------------------------
132 //---------------------------------------
133 static int getFilterId (SMESH::ElementType theType)
137 case SMESH::NODE : return SMESH::NodeFilter;
138 case SMESH::EDGE : return SMESH::EdgeFilter;
139 case SMESH::FACE : return SMESH::FaceFilter;
140 case SMESH::VOLUME : return SMESH::VolumeFilter;
141 case SMESH::ALL : return SMESH::AllElementsFilter;
142 default : return SMESH::UnknownFilter;
147 Class : SMESHGUI_FilterTable::AdditionalWidget
148 Description : Class for storing additional parameters of criterion
151 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
157 AdditionalWidget(QWidget* theParent);
158 virtual ~AdditionalWidget();
160 virtual QList<int> GetParameters() const;
161 virtual bool IsValid(const bool = true) const;
162 virtual double GetDouble(const int) const;
163 virtual int GetInteger(const int) const;
164 virtual QString GetString(const int) const;
165 virtual void SetDouble(const int, const double);
166 virtual void SetInteger(const int, const int);
167 virtual void SetString(const int, const QString&);
168 void SetEditable(const int, const bool);
169 void SetEditable(const bool);
170 void SetPrecision(const int, const char* = 0);
173 QMap< int, QWidget* > myWidgets;
176 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
179 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
181 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
182 sb->setAcceptNames( false ); // No Notebook variables allowed
183 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
184 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
185 myWidgets[ Tolerance ] = sb;
187 QHBoxLayout* aLay = new QHBoxLayout(this);
188 aLay->setSpacing(SPACING);
191 aLay->addWidget(aLabel);
192 aLay->addWidget(myWidgets[ Tolerance ]);
195 SetDouble( Tolerance, Precision::Confusion() );
198 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
202 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
205 theList.append(Tolerance);
209 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
214 QList<int> aParams = GetParameters();
215 QList<int>::const_iterator anIter;
216 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
217 if ( !myWidgets.contains( *anIter ) ) continue;
219 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
220 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
222 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
224 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
226 if (!valid && theMsg) {
227 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
228 tr("SMESHGUI_INVALID_PARAMETERS"));
236 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
239 if ( myWidgets.contains( theId ) ) {
240 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
241 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
242 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
243 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
248 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
251 if ( myWidgets.contains( theId ) ) {
252 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
253 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
254 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
255 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
260 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
263 if ( myWidgets.contains( theId ) ) {
264 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
265 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
266 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
267 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
272 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
274 if ( myWidgets.contains( theId ) ) {
275 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
276 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
277 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
278 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
282 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
284 if ( myWidgets.contains( theId ) ) {
285 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
286 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
287 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
288 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
292 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
294 if ( myWidgets.contains( theId ) ) {
295 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
296 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
297 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
298 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
302 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
304 if ( myWidgets.contains( theId ) ) {
305 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
306 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
307 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
308 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
312 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
314 QList<int> aParams = GetParameters();
315 QList<int>::const_iterator anIter;
316 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
317 SetEditable( *anIter, isEditable );
320 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
322 if ( myWidgets.contains( theId ) ) {
323 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
324 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
325 double val = sb->GetValue();
326 double min = pow(10.0, -(sb->decimals()));
327 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
328 sb->SetValue( qMax( val, min ) );
334 Class : SMESHGUI_FilterTable::ComboItem
335 Description : Combo table item. Identificator corresponding to string may be assigned
338 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
343 ComboItem( const QMap<int, QString>& );
345 void setItems( const QMap<int, QString>& );
350 void setValue( const int );
354 int index( int ) const;
357 QMap<int, int> myIdToIdx;
360 int SMESHGUI_FilterTable::ComboItem::Type()
362 return QTableWidgetItem::UserType + 1;
365 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
366 : QTableWidgetItem( Type() )
371 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
374 QMap<int, QString>::const_iterator it;
376 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
377 myIdToIdx[it.key()] = items.count();
378 items.append( it.value() );
380 setData( Qt::UserRole, items );
384 void SMESHGUI_FilterTable::ComboItem::clear()
386 QMap<int, QString> empty;
390 int SMESHGUI_FilterTable::ComboItem::count() const
392 return myIdToIdx.count();
395 int SMESHGUI_FilterTable::ComboItem::value() const
397 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
400 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
402 int idx = index( theId );
403 QStringList items = data( Qt::UserRole ).toStringList();
404 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
407 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
409 QMap<int,int>::const_iterator it;
410 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
411 if ( it.value() == idx ) return it.key();
415 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
417 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
420 Class : SMESHGUI_FilterTable::CheckItem
421 Description : Check table item.
424 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
429 CheckItem( bool = false );
430 CheckItem( const QString&, bool = false );
433 void setChecked( bool );
434 bool checked() const;
437 int SMESHGUI_FilterTable::CheckItem::Type()
439 return QTableWidgetItem::UserType + 2;
442 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
443 : QTableWidgetItem( Type() )
445 Qt::ItemFlags f = flags();
446 f = f | Qt::ItemIsUserCheckable;
447 f = f & ~Qt::ItemIsTristate;
448 f = f & ~Qt::ItemIsEditable;
453 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
454 : QTableWidgetItem( Type() )
456 Qt::ItemFlags f = flags();
457 f = f | Qt::ItemIsUserCheckable;
458 f = f & ~Qt::ItemIsTristate;
459 f = f & ~Qt::ItemIsEditable;
465 SMESHGUI_FilterTable::CheckItem::~CheckItem()
469 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
471 setCheckState( value ? Qt::Checked : Qt::Unchecked );
474 bool SMESHGUI_FilterTable::CheckItem::checked() const
476 return checkState() == Qt::Checked;
480 Class : SMESHGUI_FilterTable::IntSpinItem
481 Description : Integer spin table item.
484 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
489 IntSpinItem( const int theValue );
492 void setValue( const int theValue );
497 int SMESHGUI_FilterTable::IntSpinItem::Type()
499 return QTableWidgetItem::UserType + 3;
502 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
503 : QTableWidgetItem( Type() )
505 setValue( theValue );
508 int SMESHGUI_FilterTable::IntSpinItem::value() const
511 int value = data( Qt::UserRole ).toInt( &ok );
512 return ok ? value : 0;
515 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
517 setData( Qt::UserRole, theValue );
518 setText( QString::number( theValue ) );
521 void SMESHGUI_FilterTable::IntSpinItem::clear()
527 Class : SMESHGUI_FilterTable::DoubleSpinItem
528 Description : Double spin table item.
531 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
536 DoubleSpinItem( const double theValue );
538 double value() const;
539 void setValue( const double theValue );
541 int precision() const;
542 void setPrecision( const int thePrecision );
547 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
549 return QTableWidgetItem::UserType + 4;
552 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
553 : QTableWidgetItem( Type() )
555 setValue( theValue );
558 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
561 double value = data( Qt::UserRole ).toDouble( &ok );
562 return ok ? value : 0;
565 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
567 setData( Qt::UserRole, theValue );
568 setText( QString::number( theValue ) );
571 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
574 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
575 return ok ? precision : 0;
578 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
580 setData( Qt::UserRole + 1, thePrecision );
583 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
589 Class : SMESHGUI_FilterTable::ComboDelegate
590 Description : Table used by this widget
593 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
596 ComboDelegate( QObject* = 0 );
599 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
600 const QModelIndex& ) const;
602 void setEditorData( QWidget*, const QModelIndex& ) const;
603 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
605 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
606 const QModelIndex& ) const;
608 QTableWidget* myTable;
611 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
612 : QItemDelegate( parent ),
613 myTable( qobject_cast<QTableWidget*>( parent ) )
617 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
621 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
622 const QStyleOptionViewItem& option,
623 const QModelIndex& index ) const
625 QVariant aData = index.data( Qt::UserRole );
626 QVariant::Type aDataType = aData.type();
627 if( aDataType == QVariant::StringList ) {
628 QStringList l = aData.toStringList();
629 if ( !l.isEmpty() ) {
630 QComboBox* cb = new QComboBox( parent );
631 cb->setFrame( false );
636 else if( aDataType == QVariant::Int ) {
638 int aValue = aData.toInt( &ok );
640 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
641 intSpin->setFrame( false );
642 intSpin->setValue( aValue );
646 else if( aDataType == QVariant::Double ) {
648 double aValue = aData.toDouble( &ok );
650 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
654 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
655 dblSpin->setFrame( false );
656 dblSpin->setValue( aValue );
660 return QItemDelegate::createEditor( parent, option, index );
663 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
664 const QModelIndex& index ) const
666 QVariant data = index.model()->data( index, Qt::DisplayRole );
667 QString value = data.toString();
669 if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
670 int i = cb->findText( value );
672 cb->setCurrentIndex( i );
676 else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
677 if( data.type() == QVariant::Double ) {
678 double valueDouble = data.toDouble( &bOk );
680 dblSpin->setValue( valueDouble );
683 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
686 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
687 QAbstractItemModel* model,
688 const QModelIndex& index) const
690 if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
691 model->setData( index, cb->currentText(), Qt::DisplayRole );
692 else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
693 model->setData( index, intSpin->value(), Qt::DisplayRole );
694 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
695 model->setData( index, dblSpin->value(), Qt::DisplayRole );
696 else QItemDelegate::setModelData( editor, model, index );
699 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
700 const QStyleOptionViewItem& option,
701 const QModelIndex& index ) const
703 editor->setGeometry( option.rect );
707 Class : SMESHGUI_FilterTable::Table
708 Description : Table used by this widget
711 class SMESHGUI_FilterTable::Table : public QTableWidget
714 Table( QWidget* = 0 );
715 Table( int, int, QWidget* = 0 );
718 QSize minimumSizeHint() const;
720 void setEditable( bool, int, int );
721 bool isEditable( int, int ) const;
723 void setReadOnly( bool );
724 bool isReadOnly() const;
726 void insertRows( int, int = 1 );
727 QString text( int, int );
729 QList<int> selectedRows();
732 //=======================================================================
733 // name : SMESHGUI_FilterTable::Table::Table
734 // Purpose : Constructor
735 //=======================================================================
736 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
737 : QTableWidget(parent)
739 // set custom item delegate
740 setItemDelegate( new ComboDelegate(this) );
741 // set edit triggers by default
742 setReadOnly( false );
745 //=======================================================================
746 // name : SMESHGUI_FilterTable::Table::Table
747 // Purpose : Constructor
748 //=======================================================================
749 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
750 : QTableWidget(numRows, numCols, parent)
752 // set custom item delegate
753 setItemDelegate( new ComboDelegate(this) );
754 // set edit triggers by default
755 setReadOnly( false );
758 //=======================================================================
759 // name : SMESHGUI_FilterTable::Table::~Table
760 // Purpose : Destructor
761 //=======================================================================
762 SMESHGUI_FilterTable::Table::~Table()
766 //=======================================================================
767 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
768 // Purpose : Get minimum size for the table
769 //=======================================================================
770 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
772 QSize s = QTableWidget::minimumSizeHint();
773 QHeaderView* hv = horizontalHeader();
775 s.setWidth( qMax( s.width(), hv->length() ) );
779 //=======================================================================
780 // name : SMESHGUI_FilterTable::Table::setEditable
781 // Purpose : Set editable of specified cell
782 //=======================================================================
783 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
786 QTableWidgetItem* anItem = item( row, col );
788 bool isSignalsBlocked = signalsBlocked();
789 blockSignals( true );
791 Qt::ItemFlags f = anItem->flags();
792 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
793 else f = f | Qt::ItemIsEditable;
794 anItem->setFlags( f );
796 blockSignals( isSignalsBlocked );
800 //=======================================================================
801 // name : SMESHGUI_FilterTable::Table::isEditable
802 // Purpose : Verify wheter cell is editable
803 //=======================================================================
804 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
806 QTableWidgetItem* anItem = item( row, col );
807 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
810 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
812 setEditTriggers( on ?
813 QAbstractItemView::NoEditTriggers :
814 QAbstractItemView::AllEditTriggers );
817 bool SMESHGUI_FilterTable::Table::isReadOnly() const
819 return editTriggers() == QAbstractItemView::NoEditTriggers;
822 //=======================================================================
823 // name : SMESHGUI_FilterTable::Table::insertRows
824 // Purpose : Insert rows (virtual redefined)
825 //=======================================================================
826 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
828 closePersistentEditor( currentItem() );
829 while ( count-- ) insertRow( row );
832 //=======================================================================
833 // name : SMESHGUI_FilterTable::Table::text
834 // Purpose : Get text from cell (virtual redefined)
835 //=======================================================================
836 QString SMESHGUI_FilterTable::Table::text (int row, int col)
838 closePersistentEditor( currentItem() );
839 QTableWidgetItem* anItem = item( row, col );
840 return anItem ? anItem->text() : QString();
843 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
845 QList<QTableWidgetItem*> selItems = selectedItems();
846 QTableWidgetItem* anItem;
849 foreach( anItem, selItems ) {
850 int r = row( anItem );
851 if ( !rows.contains( r ) ) rows.append( r );
859 Class : SMESHGUI_FilterTable
860 Description : Frame containig
861 - Button group for switching entity type
862 - Table for displaying filter criterions
863 - Buttons for editing table and filter libraries
866 //=======================================================================
867 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
868 // Purpose : Constructor
869 //=======================================================================
870 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
875 mySMESHGUI( theModule )
884 //=======================================================================
885 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
886 // Purpose : Constructor
887 //=======================================================================
888 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
890 const QList<int>& types )
893 mySMESHGUI( theModule )
899 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
903 //=======================================================================
904 // name : SMESHGUI_FilterTable::Init
905 // Purpose : Create table corresponding to the specified type
906 //=======================================================================
907 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
909 if (theTypes.isEmpty())
912 // Create buttons if necessary
914 if (myTables.isEmpty())
916 // create main layout
917 QVBoxLayout* aMainLay = new QVBoxLayout(this);
918 aMainLay->setMargin( 0 );
919 aMainLay->setSpacing( SPACING );
921 // create switch of entity types
922 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
923 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
924 myEntityTypeBoxLayout->setMargin( MARGIN );
925 myEntityTypeBoxLayout->setSpacing( SPACING );
926 myEntityTypeGrp = new QButtonGroup(this);
928 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
929 QMap<int, QString>::const_iterator anIter;
930 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
932 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
933 myEntityTypeGrp->addButton(aBtn, anIter.key());
934 myEntityTypeBoxLayout->addWidget(aBtn);
937 myTableGrp = new QGroupBox(tr("FILTER"), this );
940 mySwitchTableGrp = new QWidget(myTableGrp);
941 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
942 mySwitchTableGrpLayout->setMargin(0);
943 mySwitchTableGrpLayout->setSpacing(0);
945 QList<int>::const_iterator typeIt = theTypes.begin();
946 for ( ; typeIt != theTypes.end(); ++typeIt ) {
947 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
948 myTables[ *typeIt ] = aTable;
949 mySwitchTableGrpLayout->addWidget(aTable);
950 if ( typeIt != theTypes.begin() )
955 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
956 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
957 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
958 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
959 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
960 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
962 myAddBtn->setAutoDefault(false);
963 myRemoveBtn->setAutoDefault(false);
964 myClearBtn->setAutoDefault(false);
965 myInsertBtn->setAutoDefault(false);
966 myCopyFromBtn->setAutoDefault(false);
967 myAddToBtn->setAutoDefault(false);
969 myCopyFromBtn->hide();
973 QGridLayout* aLay = new QGridLayout(myTableGrp);
974 aLay->setMargin(MARGIN);
975 aLay->setSpacing(SPACING);
977 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
978 aLay->addWidget(myAddBtn, 0, 1);
979 aLay->addWidget(myInsertBtn, 1, 1);
980 aLay->addWidget(myRemoveBtn, 2, 1);
981 aLay->addWidget(myClearBtn, 3, 1);
982 aLay->addWidget(myCopyFromBtn, 5, 1);
983 aLay->addWidget(myAddToBtn, 6, 1);
984 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
986 aLay->setRowMinimumHeight(4, 10);
987 aLay->setRowStretch(4, 1);
988 aLay->setColumnStretch(0, 1);
989 aLay->setColumnStretch(1, 0);
992 aMainLay->addWidget(myEntityTypeBox);
993 aMainLay->addWidget(myTableGrp);
996 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
997 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
998 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
999 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
1001 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
1002 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
1004 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1010 QList<int>::const_iterator typeIt = theTypes.begin();
1011 for ( ; typeIt != theTypes.end(); ++typeIt ) {
1012 if ( !myTables[ *typeIt ] ) {
1013 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
1014 myTables[ *typeIt ] = aTable;
1015 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ *typeIt ]);
1020 // Hide buttons of entity types if necessary
1021 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1022 QMap<int, QString>::const_iterator anIt;
1023 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1025 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1026 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1029 // select first button if there is no selected buttons or it is hidden
1030 int aBtnId = myEntityTypeGrp->checkedId();
1031 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1032 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1033 if ( aBtn ) aBtn->setChecked(true);
1036 myEntityTypeBox->setVisible(theTypes.count() > 1);
1038 myTableGrp->updateGeometry();
1039 int cType = myEntityTypeGrp->checkedId();
1040 onEntityType(cType);
1043 //=======================================================================
1044 // name : SMESHGUI_FilterTable::createAdditionalFrame
1045 // Purpose : Get group box containing table. May be used for adding new widgets in it
1046 //=======================================================================
1047 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1049 QWidget* aFrame = new QWidget(theParent);
1051 QFrame* aLine1 = new QFrame(aFrame);
1052 QFrame* aLine2 = new QFrame(aFrame);
1053 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1054 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1055 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1056 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1058 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1060 myWgStack = new QStackedWidget(aFrame);
1062 QGridLayout* aLay = new QGridLayout(aFrame);
1064 aLay->setSpacing(SPACING);
1065 aLay->addWidget(aLine1, 0, 0);
1066 aLay->addWidget(aLabel, 0, 1);
1067 aLay->addWidget(aLine2, 0, 2);
1068 aLay->addWidget(myWgStack, 1, 0, 1, 3);
1073 //=======================================================================
1074 // name : SMESHGUI_FilterTable::GetTableGrp
1075 // Purpose : Get group box containing table. May be used for adding new widgets in it
1076 //=======================================================================
1077 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1082 //=======================================================================
1083 // name : SMESHGUI_FilterTable::onEntityType
1084 // Purpose : SLOT. Called when entity type changed.
1085 // Display corresponding table
1086 //=======================================================================
1087 void SMESHGUI_FilterTable::onEntityType (int theType)
1089 if (myEntityType == theType)
1093 emit NeedValidation();
1096 myEntityTypeGrp->button(myEntityType)->setChecked(true);
1100 myEntityType = theType;
1102 if (!myTables.contains(theType)) {
1103 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1104 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1107 TableMap::iterator anIter;
1108 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1109 anIter.value()->setVisible( myEntityType == anIter.key() );
1112 qApp->processEvents();
1113 myTables[ myEntityType ]->updateGeometry();
1116 emit EntityTypeChanged(theType);
1119 //=======================================================================
1120 // name : SMESHGUI_FilterTable::IsValid
1121 // Purpose : Verify validity of entered data
1122 //=======================================================================
1123 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1125 int aType = theEntityType == -1 ? GetType() : theEntityType;
1127 Table* aTable = myTables[ aType ];
1128 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1130 int aCriterion = GetCriterionType(i, aType);
1132 if (aCriterion == SMESH::FT_GroupColor )
1134 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1135 if (clrBtn && !clrBtn->color().isValid())
1136 errMsg = tr( "GROUPCOLOR_ERROR" );
1138 else if (aCriterion == SMESH::FT_RangeOfIds ||
1139 aCriterion == SMESH::FT_BelongToGeom ||
1140 aCriterion == SMESH::FT_BelongToPlane ||
1141 aCriterion == SMESH::FT_BelongToCylinder ||
1142 aCriterion == SMESH::FT_BelongToGenSurface ||
1143 aCriterion == SMESH::FT_ElemGeomType ||
1144 aCriterion == SMESH::FT_EntityType ||
1145 aCriterion == SMESH::FT_CoplanarFaces ||
1146 aCriterion == SMESH::FT_LyingOnGeom ||
1147 aCriterion == SMESH::FT_ConnectedElements )
1149 if (aTable->text(i, 2).isEmpty())
1150 errMsg = tr( "ERROR" );
1155 bool isSignalsBlocked = aTable->signalsBlocked();
1156 aTable->blockSignals(true);
1157 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1158 aTable->blockSignals(isSignalsBlocked);
1160 if (!aRes && aTable->isEditable(i, 2))
1161 errMsg = tr( "ERROR" );
1162 else if (aType == SMESH::EDGE &&
1163 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1165 errMsg = tr( "MULTIEDGES_ERROR" );
1168 if (!errMsg.isEmpty()) {
1170 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1174 QTableWidgetItem* anItem = aTable->item(i, 0);
1175 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1182 //=======================================================================
1183 // name : SMESHGUI_FilterTable::SetValidity
1184 // Purpose : Set validity of the table
1185 //=======================================================================
1186 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1188 myIsValid = isValid;
1191 //=======================================================================
1192 // name : SMESHGUI_FilterTable::GetType
1193 // Purpose : Get current entity type
1194 //=======================================================================
1195 int SMESHGUI_FilterTable::GetType() const
1197 return myEntityType;
1200 //=======================================================================
1201 // name : SMESHGUI_FilterTable::SetType
1202 // Purpose : Set current entity type
1203 //=======================================================================
1204 void SMESHGUI_FilterTable::SetType (const int type)
1206 myEntityTypeGrp->button(type)->setChecked(true);
1210 //=======================================================================
1211 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1212 // Purpose : Restore previous entity type
1213 //=======================================================================
1214 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1216 SetType(myEntityType);
1219 //=======================================================================
1220 // name : SMESHGUI_FilterTable::GetCriterionType
1221 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1222 //=======================================================================
1223 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1225 int aType = theType == -1 ? GetType() : theType;
1226 Table* aTable = myTables[ aType ];
1227 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1228 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1231 //=======================================================================
1232 // name : SMESHGUI_FilterTable::GetCriterion
1233 // Purpose : Get parameters of criterion from specified row
1234 //=======================================================================
1235 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1236 SMESH::Filter::Criterion& theCriterion,
1237 const int theEntityType) const
1239 int aType = theEntityType == -1 ? GetType() : theEntityType;
1240 Table* aTable = myTables[ aType ];
1242 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1243 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1244 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1245 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1246 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1248 int aCriterionType = GetCriterionType(theRow, aType);
1250 if ( aCriterionType == SMESH::FT_GroupColor )
1252 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1255 Kernel_Utils::Localizer loc;
1256 const QColor qClr = clrBtn->color();
1257 QString clrStr = QString( "%1;%2;%3" ).
1258 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1259 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1262 else if ( aCriterionType == SMESH::FT_ElemGeomType ||
1263 aCriterionType == SMESH::FT_EntityType )
1265 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1267 else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1269 theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1271 else if ( aCriterionType == SMESH::FT_ConnectedElements )
1273 QString id = aTable->text(theRow, 5);
1274 if ( !id.isEmpty() ) // shape ID
1276 theCriterion.ThresholdID = id.toLatin1().constData();
1280 QString text = aTable->text(theRow, 2).trimmed();
1281 QString workText = text;
1282 for ( char c = '0'; c <= '9'; ++c )
1283 workText.remove( c );
1285 if ( workText.isEmpty() ) // node ID
1286 theCriterion.Threshold = text.toDouble();
1287 else // point coordinates
1288 theCriterion.ThresholdStr = text.toLatin1().constData();
1291 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1292 aCriterionType != SMESH::FT_BelongToGeom &&
1293 aCriterionType != SMESH::FT_BelongToPlane &&
1294 aCriterionType != SMESH::FT_BelongToCylinder &&
1295 aCriterionType != SMESH::FT_BelongToGenSurface &&
1296 aCriterionType != SMESH::FT_LyingOnGeom )
1298 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1299 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1303 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1304 if ( aCriterionType != SMESH::FT_RangeOfIds )
1305 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1308 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1309 if (myAddWidgets.contains(anItem))
1310 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1313 //=======================================================================
1314 // name : SMESHGUI_FilterTable::SetCriterion
1315 // Purpose : Set parameters of criterion of specified row
1316 //=======================================================================
1317 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1318 const SMESH::Filter::Criterion& theCriterion,
1319 const int theEntityType)
1321 int aType = theEntityType == -1 ? GetType() : theEntityType;
1323 Table* aTable = myTables[ aType ];
1325 if (theRow > aTable->rowCount() - 1)
1328 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1329 onCriterionChanged(theRow, 0, aType);
1330 if ( theCriterion.Compare == SMESH::FT_Undefined )
1331 ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
1333 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1334 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1336 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1338 if (!aTable->isEditable(theRow, 4))
1339 aTable->setItem(theRow, 4, getBinaryItem());
1340 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1343 aTable->setEditable(false, theRow, 4);
1345 if (theCriterion.Type == SMESH::FT_GroupColor )
1347 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1351 QString clrStr( theCriterion.ThresholdStr );
1352 QStringList clrVals = clrStr.split( ";" );
1353 if ( clrVals.count() > 2 )
1354 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1355 (int)256*clrVals[1].toDouble(),
1356 (int)256*clrVals[2].toDouble() );
1357 clrBtn->setColor( qClr );
1360 else if (theCriterion.Type == SMESH::FT_ElemGeomType ||
1361 theCriterion.Type == SMESH::FT_EntityType )
1363 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1364 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1366 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1368 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1370 else if (theCriterion.Type == SMESH::FT_ConnectedElements )
1372 if ( strlen( theCriterion.ThresholdID ) > 0 ) // shape ID -> name
1374 _PTR(SObject) sobj =
1375 SMESH::GetActiveStudyDocument()->FindObjectID( theCriterion.ThresholdID.in() );
1377 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1379 aTable->item( theRow, 2 )->setText( QString( sobj->GetName().c_str() ));
1381 else if ( strlen( theCriterion.ThresholdStr ) > 0 ) // point coords
1383 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdStr ));
1387 aTable->item( theRow, 2 )->setText( QString("%1").arg((int) theCriterion.Threshold ));
1390 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1391 theCriterion.Type != SMESH::FT_BelongToGeom &&
1392 theCriterion.Type != SMESH::FT_BelongToPlane &&
1393 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1394 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1395 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1396 theCriterion.Type != SMESH::FT_FreeBorders &&
1397 theCriterion.Type != SMESH::FT_FreeEdges &&
1398 theCriterion.Type != SMESH::FT_FreeNodes &&
1399 theCriterion.Type != SMESH::FT_FreeFaces &&
1400 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1401 theCriterion.Type != SMESH::FT_BareBorderFace &&
1402 theCriterion.Type != SMESH::FT_BareBorderVolume &&
1403 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1404 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1405 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1407 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1411 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1412 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1413 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1416 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1417 theCriterion.Type == SMESH::FT_BelongToPlane ||
1418 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1419 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1420 theCriterion.Type == SMESH::FT_BelongToGeom ||
1421 theCriterion.Type == SMESH::FT_LyingOnGeom ||
1422 theCriterion.Type == SMESH::FT_CoplanarFaces ||
1423 theCriterion.Type == SMESH::FT_EqualNodes)
1425 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1426 if (!myAddWidgets.contains(anItem))
1428 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1429 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1430 myWgStack->addWidget(myAddWidgets[ anItem ]);
1432 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1435 emit CriterionChanged(theRow, aType);
1438 //=======================================================================
1439 // name : SMESHGUI_FilterTable::Update
1440 // Purpose : Update table
1441 //=======================================================================
1442 void SMESHGUI_FilterTable::Update()
1444 Table* aTable = myTables[ GetType() ];
1445 int aCurrRow = aTable->currentRow();
1446 int numRows = aTable->rowCount();
1447 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1448 aTable->setCurrentCell(0, 0);
1449 updateAdditionalWidget();
1452 //=======================================================================
1453 // name : SMESHGUI_FilterTable::AddCriterion
1454 // Purpose : Add criterion with parameters
1455 //=======================================================================
1456 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1457 const int theEntityType)
1459 int aType = theEntityType == -1 ? GetType() : theEntityType;
1460 Table* aTable = myTables[ aType ];
1461 addRow(aTable, aType);
1462 SetCriterion(aTable->rowCount() - 1, theCriterion);
1465 //=======================================================================
1466 // name : SMESHGUI_FilterTable::NumRows
1467 // Purpose : Get number of criterions of current type
1468 //=======================================================================
1469 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1471 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1474 //=======================================================================
1475 // name : SMESHGUI_FilterTable::Clear
1476 // Purpose : Clear current table
1477 //=======================================================================
1478 void SMESHGUI_FilterTable::Clear (const int theType)
1480 int aType = theType == -1 ? GetType() : theType;
1481 Table* aTable = myTables[ aType ];
1483 if (aTable->rowCount() == 0)
1486 while (aTable->rowCount() > 0)
1488 removeAdditionalWidget(aTable, 0);
1489 aTable->removeRow(0);
1495 //=======================================================================
1496 // name : SMESHGUI_FilterTable::onAddBtn
1497 // Purpose : SLOT. Called then "Add" button pressed.
1498 // Adds new string to table
1499 //=======================================================================
1500 void SMESHGUI_FilterTable::onAddBtn()
1502 int aType = GetType();
1503 addRow(myTables[ aType ], aType);
1508 //=======================================================================
1509 // name : SMESHGUI_FilterTable::onInsertBtn
1510 // Purpose : SLOT. Called then "Insert" button pressed.
1511 // Inserts new string before current one
1512 //=======================================================================
1513 void SMESHGUI_FilterTable::onInsertBtn()
1515 addRow(myTables[ GetType() ], GetType(), false);
1518 //=======================================================================
1519 // name : SMESHGUI_FilterTable::onRemoveBtn
1520 // Purpose : SLOT. Called then "Remove" button pressed.
1521 // Removes current string from table
1522 //=======================================================================
1523 void SMESHGUI_FilterTable::onRemoveBtn()
1525 Table* aTable = myTables[ GetType() ];
1527 if (aTable->rowCount() == 0)
1530 QList<QTableWidgetItem*> items = aTable->selectedItems();
1532 QList<int> aRows = aTable->selectedRows(); // already sorted
1536 removeAdditionalWidget(aTable, i);
1537 aTable->removeRow(i);
1540 // remove control of binary logical operation from last row
1541 if (aTable->rowCount() > 0)
1542 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1547 //=======================================================================
1548 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1549 // Purpose : Enable/Disable widget with additonal parameters
1550 //=======================================================================
1551 void SMESHGUI_FilterTable::updateAdditionalWidget()
1553 Table* aTable = myTables[ GetType() ];
1554 int aRow = aTable->currentRow();
1555 if (aRow < 0 || aRow >= aTable->rowCount())
1557 myWgStack->setEnabled(false);
1561 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1562 int aCriterion = GetCriterionType(aRow);
1563 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1564 aCriterion != SMESH::FT_RangeOfIds &&
1565 aCriterion != SMESH::FT_FreeEdges &&
1566 aCriterion != SMESH::FT_FreeFaces &&
1567 aCriterion != SMESH::FT_BadOrientedVolume &&
1568 aCriterion != SMESH::FT_BareBorderFace &&
1569 aCriterion != SMESH::FT_BareBorderVolume &&
1570 aCriterion != SMESH::FT_OverConstrainedFace &&
1571 aCriterion != SMESH::FT_OverConstrainedVolume)
1573 aCriterion == SMESH::FT_CoplanarFaces ||
1574 aCriterion == SMESH::FT_EqualNodes);
1576 if (!myAddWidgets.contains(anItem))
1578 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1579 myWgStack->addWidget(myAddWidgets[ anItem ]);
1582 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1583 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1584 myWgStack->setEnabled(toEnable);
1587 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1589 const char* retval = 0;
1591 case SMESH::FT_AspectRatio:
1592 case SMESH::FT_AspectRatio3D:
1593 case SMESH::FT_Taper:
1594 retval = "parametric_precision"; break;
1595 case SMESH::FT_Warping:
1596 case SMESH::FT_MinimumAngle:
1597 case SMESH::FT_Skew:
1598 case SMESH::FT_CoplanarFaces:
1599 retval = "angle_precision"; break;
1600 case SMESH::FT_Area:
1601 retval = "area_precision"; break;
1602 case SMESH::FT_BelongToGeom:
1603 case SMESH::FT_BelongToPlane:
1604 case SMESH::FT_BelongToCylinder:
1605 case SMESH::FT_BelongToGenSurface:
1606 case SMESH::FT_LyingOnGeom:
1607 case SMESH::FT_EqualNodes:
1608 retval = "len_tol_precision"; break;
1609 case SMESH::FT_Length:
1610 case SMESH::FT_Length2D:
1611 case SMESH::FT_MaxElementLength2D:
1612 case SMESH::FT_MaxElementLength3D:
1613 case SMESH::FT_BallDiameter:
1614 retval = "length_precision"; break;
1615 case SMESH::FT_Volume3D:
1616 retval = "vol_precision"; break;
1623 //=======================================================================
1624 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1625 // Purpose : Remove widgets containing additional parameters from widget
1626 // stack and internal map
1627 //=======================================================================
1628 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1630 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1631 if (myAddWidgets.contains(anItem))
1633 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1634 myAddWidgets[ anItem ]->setParent(0);
1635 delete myAddWidgets[ anItem ];
1636 myAddWidgets.remove(anItem);
1640 //=======================================================================
1641 // name : SMESHGUI_FilterTable::onClearBtn
1642 // Purpose : SLOT. Called then "Clear" button pressed.
1643 // Removes all strings from table
1644 //=======================================================================
1645 void SMESHGUI_FilterTable::onClearBtn()
1647 Table* aTable = myTables[ GetType() ];
1649 if (aTable->rowCount() == 0)
1652 while (aTable->rowCount() > 0)
1654 removeAdditionalWidget(aTable, 0);
1655 aTable->removeRow(0);
1661 //=======================================================================
1662 // name : SMESHGUI_FilterTable::onCurrentChanged()
1663 // Purpose : SLOT. Called when current cell changed
1664 //=======================================================================
1665 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1668 updateAdditionalWidget();
1669 emit CurrentChanged(theRow, theCol);
1672 //=======================================================================
1674 // Purpose : returns available geometry types of elements
1675 //=======================================================================
1676 static QList<int> geomTypes( const int theType )
1679 if ( theType == SMESH::NODE )
1680 typeIds.append( SMESH::Geom_POINT );
1681 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1682 typeIds.append( SMESH::Geom_EDGE );
1683 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1685 typeIds.append( SMESH::Geom_TRIANGLE );
1686 typeIds.append( SMESH::Geom_QUADRANGLE );
1687 typeIds.append( SMESH::Geom_POLYGON );
1689 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1691 typeIds.append( SMESH::Geom_TETRA );
1692 typeIds.append( SMESH::Geom_PYRAMID );
1693 typeIds.append( SMESH::Geom_HEXA );
1694 typeIds.append( SMESH::Geom_PENTA );
1695 typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1696 typeIds.append( SMESH::Geom_POLYHEDRA );
1698 if ( theType == SMESH::ALL || theType == SMESH::ELEM0D )
1700 typeIds.append( SMESH::Geom_POINT );
1702 if ( theType == SMESH::ALL || theType == SMESH::BALL )
1704 typeIds.append( SMESH::Geom_BALL );
1709 //=======================================================================
1710 // name : entityTypes
1711 // Purpose : returns available entity types of elements
1712 //=======================================================================
1714 static QList<int> entityTypes( const int theType )
1721 typeIds.append( SMDSEntity_Node );
1723 typeIds.append( SMDSEntity_Edge );
1724 typeIds.append( SMDSEntity_Quad_Edge );
1727 typeIds.append( SMDSEntity_Triangle );
1728 typeIds.append( SMDSEntity_Quad_Triangle );
1729 typeIds.append( SMDSEntity_BiQuad_Triangle );
1730 typeIds.append( SMDSEntity_Quadrangle );
1731 typeIds.append( SMDSEntity_Quad_Quadrangle );
1732 typeIds.append( SMDSEntity_BiQuad_Quadrangle );
1733 typeIds.append( SMDSEntity_Polygon );
1734 //typeIds.append( SMDSEntity_Quad_Polygon );
1737 typeIds.append( SMDSEntity_Tetra );
1738 typeIds.append( SMDSEntity_Quad_Tetra );
1739 typeIds.append( SMDSEntity_Pyramid );
1740 typeIds.append( SMDSEntity_Quad_Pyramid );
1741 typeIds.append( SMDSEntity_Hexa );
1742 typeIds.append( SMDSEntity_Quad_Hexa );
1743 typeIds.append( SMDSEntity_TriQuad_Hexa );
1744 typeIds.append( SMDSEntity_Penta );
1745 typeIds.append( SMDSEntity_Quad_Penta );
1746 typeIds.append( SMDSEntity_Hexagonal_Prism );
1747 typeIds.append( SMDSEntity_Polyhedra );
1748 //typeIds.append( SMDSEntity_Quad_Polyhedra );
1751 typeIds.append( SMDSEntity_0D );
1754 typeIds.append( SMDSEntity_Ball );
1760 //=======================================================================
1761 // name : SMESHGUI_FilterTable::onCriterionChanged()
1762 // Purpose : Provides reaction on change of criterion
1763 //=======================================================================
1765 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1767 int aType = entityType == -1 ? GetType() : entityType;
1768 Table* aTable = myTables[ aType ];
1769 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1771 // find out type of a existing threshould table item
1772 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1773 bool isComboItem = false;
1774 bool isIntSpinItem = false;
1775 bool isDoubleSpinItem = false;
1776 if ( QTableWidgetItem* aTableItem = aTable->item(row, 2) )
1778 int aTableType = aTableItem->type();
1779 isComboItem = ( aTableType == ComboItem::Type() );
1780 isIntSpinItem = ( aTableType == IntSpinItem::Type() );
1781 isDoubleSpinItem = ( aTableType == DoubleSpinItem::Type() );
1784 // find out a type of item required by a new criterion and other table features
1785 int aCriterionType = GetCriterionType(row);
1786 bool anIsDoubleCriterion = false;
1787 bool anIsIntCriterion = false;
1788 bool anIsComboCriterion = false;
1790 QList<int> comboIDs; // values to show in a combo item
1791 int nbCompareSigns = 0; // possible values are 0,1,3
1792 bool isThresholdEditable = false; // actual for "simple" item types
1793 switch ( aCriterionType )
1795 case SMESH::FT_AspectRatio:
1796 case SMESH::FT_AspectRatio3D:
1797 case SMESH::FT_Warping:
1798 case SMESH::FT_MinimumAngle:
1799 case SMESH::FT_Taper:
1800 case SMESH::FT_Skew:
1801 case SMESH::FT_Area:
1802 case SMESH::FT_Volume3D:
1803 case SMESH::FT_MaxElementLength2D:
1804 case SMESH::FT_MaxElementLength3D:
1805 anIsDoubleCriterion = true; break;
1807 case SMESH::FT_FreeBorders:
1808 case SMESH::FT_FreeEdges:
1809 case SMESH::FT_FreeNodes:
1810 case SMESH::FT_FreeFaces:
1811 case SMESH::FT_EqualNodes:
1812 case SMESH::FT_EqualEdges:
1813 case SMESH::FT_EqualFaces:
1814 case SMESH::FT_EqualVolumes: break;
1816 case SMESH::FT_MultiConnection:
1817 case SMESH::FT_MultiConnection2D: anIsIntCriterion = true; break;
1819 case SMESH::FT_Length:
1820 case SMESH::FT_Length2D: anIsDoubleCriterion = true; break;
1822 case SMESH::FT_BelongToGeom:
1823 case SMESH::FT_BelongToPlane:
1824 case SMESH::FT_BelongToCylinder:
1825 case SMESH::FT_BelongToGenSurface:
1826 case SMESH::FT_LyingOnGeom: nbCompareSigns = 1; isThresholdEditable = true; break;
1828 case SMESH::FT_RangeOfIds: nbCompareSigns = 1; isThresholdEditable = true; break;
1830 case SMESH::FT_BadOrientedVolume:
1831 case SMESH::FT_BareBorderVolume:
1832 case SMESH::FT_BareBorderFace:
1833 case SMESH::FT_OverConstrainedVolume:
1834 case SMESH::FT_OverConstrainedFace:
1835 case SMESH::FT_LinearOrQuadratic: break;
1837 case SMESH::FT_GroupColor: nbCompareSigns = 1; isThresholdEditable = true; break;
1839 case SMESH::FT_ElemGeomType:
1840 comboIDs = geomTypes( aType ); anIsComboCriterion = true; nbCompareSigns = 1; break;
1842 case SMESH::FT_EntityType:
1843 comboIDs = entityTypes( aType ); anIsComboCriterion = true; nbCompareSigns = 1; break;
1845 case SMESH::FT_CoplanarFaces: isThresholdEditable = true; break;
1847 case SMESH::FT_BallDiameter: anIsDoubleCriterion = true; break;
1849 case SMESH::FT_ConnectedElements: isThresholdEditable = true; break;
1851 case SMESH::FT_LessThan:
1852 case SMESH::FT_MoreThan:
1853 case SMESH::FT_EqualTo:
1854 case SMESH::FT_LogicalNOT:
1855 case SMESH::FT_LogicalAND:
1856 case SMESH::FT_LogicalOR:
1857 case SMESH::FT_Undefined:
1861 // get a precision of a double criterion
1863 if ( anIsDoubleCriterion ) {
1864 const char* aPrecisionType = getPrecision( aCriterionType );
1865 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1866 if( aPrecisionType && aResourceMgr )
1867 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1870 // check if the current item type satisfies the criterion
1872 ( aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1873 ( anIsComboCriterion && !isComboItem ) ||
1874 ( anIsIntCriterion && !isIntSpinItem ) ||
1875 ( anIsDoubleCriterion && !isDoubleSpinItem );
1879 if ( anIsDoubleCriterion )
1881 // if the precision is to be changed we should remove the existing
1882 // spin item and create another one with new precision
1883 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 )))
1884 itemTypeKO = ( aDoubleSpinItem->precision() != aPrecision );
1888 else if ( anIsComboCriterion )
1890 if ( ComboItem* aComboItem = dynamic_cast<ComboItem*>( aTable->item( row, 2 )))
1891 itemTypeKO = ( aComboItem->count() != comboIDs.count() );
1895 else if ( !anIsIntCriterion && aCriterionType != SMESH::FT_GroupColor )
1897 itemTypeKO = ( clrBtn || isComboItem || isIntSpinItem || isDoubleSpinItem );
1901 // update the table row
1903 bool isSignalsBlocked = aTable->signalsBlocked();
1904 aTable->blockSignals( true );
1906 // update threshold table item
1909 aTable->removeCellWidget( row, 2 );
1911 if ( aCriterionType == SMESH::FT_GroupColor ) // ---------------------- QtxColorButton
1913 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1915 else if ( anIsComboCriterion ) // -------------------------------------------ComboItem
1918 ( aCriterionType == SMESH::FT_ElemGeomType ? "GEOM_TYPE_%1" : "ENTITY_TYPE_%1" );
1919 QMap<int, QString> names;
1920 QList<int>::const_iterator id = comboIDs.begin();
1921 for ( ; id != comboIDs.end(); ++id )
1923 QString name = msgPrefix.arg( *id );
1924 names[ *id ] = tr( name.toLatin1().data() );
1926 ComboItem* comboBox = new ComboItem( names );
1927 aTable->setItem( row, 2, comboBox );
1929 else if ( anIsIntCriterion ) // ------------------------------------------ IntSpinItem
1931 IntSpinItem* intSpin = new IntSpinItem( 0 );
1932 aTable->setItem( row, 2, intSpin );
1934 else if ( anIsDoubleCriterion ) // -------------------------------------DoubleSpinItem
1936 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1937 dblSpin->setPrecision( aPrecision );
1938 aTable->setItem( row, 2, dblSpin );
1941 else // --------------------------------------------------------------QTableWidgetItem
1943 aTable->setItem( row, 2, new QTableWidgetItem() );
1948 if ( aCompareItem->count() != nbCompareSigns )
1950 switch ( nbCompareSigns ) {
1952 aCompareItem->clear();
1956 QMap<int, QString> aMap;
1957 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1958 aCompareItem->setItems(aMap);
1962 aCompareItem->setItems(getCompare());
1967 aTable->setEditable( nbCompareSigns == 3, row, 1);
1969 // enable/desable Threshold
1970 if ( aCriterionType == SMESH::FT_GroupColor ||
1971 anIsComboCriterion ||
1973 anIsDoubleCriterion )
1975 isThresholdEditable = true;
1977 if ( !isThresholdEditable )
1979 aTable->setItem( row, 2, new QTableWidgetItem() );
1981 aTable->setEditable( isThresholdEditable, row, 2);
1984 aTable->blockSignals( isSignalsBlocked );
1986 updateAdditionalWidget();
1988 emit CriterionChanged(row, entityType);
1991 //=======================================================================
1992 // name : SMESHGUI_FilterTable::onCriterionChanged()
1993 // Purpose : SLOT. Called then contents of table changed
1994 // Provides reaction on change of criterion
1995 //=======================================================================
1996 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1999 onCriterionChanged(row, col, -1);
2000 else if ( col == 2 )
2001 emit ThresholdChanged(row, GetType());
2004 //=======================================================================
2005 // name : SMESHGUI_FilterTable::getFirstSelectedRow
2006 // Purpose : Get first selected row
2007 //=======================================================================
2008 int SMESHGUI_FilterTable::getFirstSelectedRow() const
2010 Table* aTable = myTables[ GetType() ];
2012 QList<int> selRows = aTable->selectedRows(); // already sorted
2013 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
2015 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
2018 //=======================================================================
2019 // name : SMESHGUI_FilterTable::addRow
2020 // Purpose : Add row at the end of table
2021 //=======================================================================
2022 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
2025 int aSelectedRow = getFirstSelectedRow();
2026 int aCurrCol = theTable->currentColumn();
2029 if (toTheEnd || aSelectedRow == -1)
2031 theTable->insertRows(theTable->rowCount());
2032 aCurrRow = theTable->rowCount() - 1;
2036 theTable->insertRows(aSelectedRow);
2037 aCurrRow = aSelectedRow;
2041 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
2042 bool isSignalsBlocked = theTable->signalsBlocked();
2043 theTable->blockSignals( true );
2046 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
2049 theTable->setItem(aCurrRow, 1, getCompareItem());
2052 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
2054 // Logical operation NOT
2055 theTable->setItem(aCurrRow, 3, getUnaryItem());
2057 // Logical operation AND / OR
2058 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
2060 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
2062 theTable->blockSignals( isSignalsBlocked );
2064 // Logical binary operation for previous value
2065 int anAddBinOpStr = -1;
2066 if (aCurrRow == theTable->rowCount() - 1)
2067 anAddBinOpStr = aCurrRow - 1;
2068 else if (aCurrRow >= 0 )
2069 anAddBinOpStr = aCurrRow;
2071 if (theTable->item(aCurrRow, 4) == 0 ||
2072 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
2074 if (anAddBinOpStr >= 0 &&
2075 (theTable->item(anAddBinOpStr, 4) == 0 ||
2076 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
2077 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
2080 theTable->setEditable(false, theTable->rowCount() - 1, 4);
2082 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
2083 aCurrCol >=0 && aCurrCol < theTable->rowCount())
2084 theTable->setCurrentCell(aCurrRow, aCurrCol);
2086 onCriterionChanged(aCurrRow, 0);
2091 //=======================================================================
2092 // name : SMESHGUI_FilterTable::getCriterionItem
2093 // Purpose : Get combo table item for criteria of specified type
2094 //=======================================================================
2095 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
2097 return new ComboItem(getCriteria(theType));
2100 //=======================================================================
2101 // name : SMESHGUI_FilterTable::getCompareItem
2102 // Purpose : Get combo table item for operation of comparision
2103 //=======================================================================
2104 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
2106 return new ComboItem(getCompare());
2109 //=======================================================================
2110 // name : SMESHGUI_FilterTable::getBinaryItem
2112 //=======================================================================
2113 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
2115 static QMap<int, QString> aMap;
2118 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
2119 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
2122 return new ComboItem(aMap);
2125 //=======================================================================
2126 // name : SMESHGUI_FilterTable::getUnaryItem
2127 // Purpose : Get check table item
2128 //=======================================================================
2129 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
2131 return new CheckItem(tr("NOT"));
2134 //=======================================================================
2135 // name : SMESHGUI_FilterTable::getSupportedTypes
2136 // Purpose : Get all supported type
2137 //=======================================================================
2138 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
2140 static QMap<int, QString> aTypes;
2141 if (aTypes.isEmpty())
2143 aTypes[ SMESH::NODE ] = tr("NODES");
2144 aTypes[ SMESH::ELEM0D ] = tr("ELEM0D");
2145 aTypes[ SMESH::BALL ] = tr("BALLS");
2146 aTypes[ SMESH::EDGE ] = tr("EDGES");
2147 aTypes[ SMESH::FACE ] = tr("FACES");
2148 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
2149 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
2155 //=======================================================================
2156 // name : SMESHGUI_FilterTable::getCriteria
2157 // Purpose : Get criteria for specified type
2158 //=======================================================================
2159 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
2161 if (theType == SMESH::NODE)
2163 static QMap<int, QString> aCriteria;
2164 if (aCriteria.isEmpty())
2166 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2167 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2168 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2169 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2170 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2171 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2172 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
2173 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2174 aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
2175 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2179 else if (theType == SMESH::EDGE)
2181 static QMap<int, QString> aCriteria;
2182 if (aCriteria.isEmpty())
2184 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
2185 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
2186 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
2187 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2188 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2189 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2190 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2191 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2192 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2193 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2194 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2195 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2196 aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
2197 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2198 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2202 else if (theType == SMESH::FACE)
2204 static QMap<int, QString> aCriteria;
2205 if (aCriteria.isEmpty())
2207 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
2208 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
2209 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
2210 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
2211 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
2212 aCriteria[ SMESH::FT_Area ] = tr("AREA");
2213 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2214 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
2215 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2216 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2217 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2218 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2219 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2220 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2221 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
2222 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
2223 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
2224 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
2225 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2226 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2227 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2228 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2229 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
2230 aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
2231 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2232 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2236 else if (theType == SMESH::VOLUME)
2238 static QMap<int, QString> aCriteria;
2239 if (aCriteria.isEmpty())
2241 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
2242 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2243 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2244 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2245 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
2246 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
2247 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2248 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
2249 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
2250 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2251 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2252 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2253 aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
2254 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2255 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2259 else if (theType == SMESH::ELEM0D)
2261 static QMap<int, QString> aCriteria;
2262 if (aCriteria.isEmpty())
2264 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2265 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2266 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2267 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2268 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2269 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2270 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2274 else if (theType == SMESH::BALL)
2276 static QMap<int, QString> aCriteria;
2277 if (aCriteria.isEmpty())
2279 aCriteria[ SMESH::FT_BallDiameter ] = tr("BALL_DIAMETER");
2280 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2281 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2282 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2283 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2284 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2285 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2286 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2290 else if (theType == SMESH::ELEM0D)
2292 static QMap<int, QString> aCriteria;
2293 if (aCriteria.isEmpty())
2295 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2296 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2297 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2298 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2299 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2300 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2301 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2307 static QMap<int, QString> aCriteria;
2308 if (aCriteria.isEmpty())
2310 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2311 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2312 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2313 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2314 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2315 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2316 aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
2324 //=======================================================================
2325 // name : SMESHGUI_FilterTable::getCompare
2326 // Purpose : Get operation of comparison
2327 //=======================================================================
2328 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2330 static QMap<int, QString> aMap;
2334 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2335 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2336 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
2342 //=======================================================================
2343 // name : SMESHGUI_FilterTable::createTable
2344 // Purpose : Create table
2345 //=======================================================================
2346 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
2350 Table* aTable= new Table(0, 6, theParent);
2352 QHeaderView* aHeaders = aTable->horizontalHeader();
2354 QFontMetrics aMetrics(aHeaders->font());
2356 // append spaces to the header of criteria in order to
2357 // provide visibility of criterion inside comboboxes
2358 static int aMaxLenCr = 0;
2362 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2363 QMap<int, QString>::const_iterator anIter;
2364 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2365 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2368 static int aLenCr = qAbs( aMaxLenCr -
2369 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2372 aCrStr.fill(' ', aLenCr);
2374 aCoStr.fill(' ', 10);
2376 QStringList aHeaderLabels;
2377 aHeaderLabels.append( tr("CRITERION") + aCrStr );
2378 aHeaderLabels.append( tr("COMPARE") + aCoStr );
2379 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2380 aHeaderLabels.append( tr("UNARY") );
2381 aHeaderLabels.append( tr("BINARY") + " " );
2382 aHeaderLabels.append( tr("ID") );
2383 aTable->setHorizontalHeaderLabels( aHeaderLabels );
2385 // set geometry of the table
2386 for (int i = 0; i <= 4; i++)
2387 aTable->resizeColumnToContents(i);
2389 // set the ID column invisible
2390 aTable->hideColumn( 5 );
2392 aTable->updateGeometry();
2393 QSize aSize = aTable->sizeHint();
2394 int aWidth = aSize.width();
2395 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2396 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2398 connect(aTable, SIGNAL(cellChanged(int, int)),
2399 this, SLOT(onCriterionChanged(int, int)));
2401 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2402 this, SLOT(onCurrentChanged(int, int)));
2407 //=======================================================================
2408 // name : SMESHGUI_FilterTable::updateBtnState
2409 // Purpose : Update button state
2410 //=======================================================================
2411 void SMESHGUI_FilterTable::updateBtnState()
2413 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2414 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2417 //=======================================================================
2418 // name : SMESHGUI_FilterTable::SetEditable
2419 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2420 //=======================================================================
2421 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2423 TableMap::iterator anIter;
2424 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2426 anIter.value()->setReadOnly(!isEditable);
2428 // Set Flags for CheckItems directly IPAL 19974
2429 Table* aTable = anIter.value();
2430 for (int i = 0, n = aTable->rowCount(); i < n; i++)
2431 for (int j = 0, m = aTable->columnCount(); j < m; j++)
2433 QTableWidgetItem* anItem = aTable->item(i, j);
2434 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2435 Qt::ItemFlags f = anItem->flags();
2436 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2437 else f = f | Qt::ItemIsUserCheckable;
2438 anItem->setFlags( f );
2446 myInsertBtn->show();
2447 myRemoveBtn->show();
2453 myInsertBtn->hide();
2454 myRemoveBtn->hide();
2459 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2460 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2461 anIter2.value()->SetEditable(isEditable);
2464 //=======================================================================
2465 // name : SMESHGUI_FilterTable::SetEnabled
2466 // Purpose : Enable/Disable table. Switching type of elements already enabled
2467 //=======================================================================
2468 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2470 myAddBtn->setEnabled(isEnabled);
2471 myInsertBtn->setEnabled(isEnabled);
2472 myRemoveBtn->setEnabled(isEnabled);
2473 myClearBtn->setEnabled(isEnabled);
2478 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2479 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2480 anIter2.value()->setEnabled(isEnabled);
2483 //=======================================================================
2484 // name : SMESHGUI_FilterTable::IsEditable
2485 // Purpose : Verify whether table is editable
2486 //=======================================================================
2487 bool SMESHGUI_FilterTable::IsEditable() const
2489 return !myTables[ GetType() ]->isReadOnly();
2492 //=======================================================================
2493 // name : SMESHGUI_FilterTable::SetLibsEnabled
2494 // Purpose : Show/hide buttons for work with libraries
2495 //=======================================================================
2496 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2500 myCopyFromBtn->show();
2505 myCopyFromBtn->hide();
2510 //=======================================================================
2511 // name : SMESHGUI_FilterTable::onCopyFromBtn
2512 // Purpose : SLOT. Called the "Copy from ..." button clicked
2513 // Display filter library dialog
2514 //=======================================================================
2515 void SMESHGUI_FilterTable::onCopyFromBtn()
2518 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2519 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2521 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2523 if (myLibDlg->exec() == QDialog::Accepted)
2525 Copy(myLibDlg->GetTable());
2530 //=======================================================================
2531 // name : SMESHGUI_FilterTable::onAddToBtn
2532 // Purpose : SLOT. Called the "Add to ..." button clicked
2533 // Display filter library dialog
2534 //=======================================================================
2535 void SMESHGUI_FilterTable::onAddToBtn()
2540 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2541 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2543 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2545 myLibDlg->SetTable(this);
2550 //=======================================================================
2551 // name : SMESHGUI_FilterTable::Copy
2552 // Purpose : Initialise table with values of other table
2553 //=======================================================================
2554 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2558 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2560 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2561 theTable->GetCriterion(i, aCriterion);
2562 AddCriterion(aCriterion);
2566 //=======================================================================
2567 // name : SMESHGUI_FilterTable::CurrentCell
2568 // Purpose : Returns current cell
2569 //=======================================================================
2570 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2572 theRow = myTables[ GetType() ]->currentRow();
2573 theCol = myTables[ GetType() ]->currentColumn();
2574 return theRow >= 0 && theCol >= 0;
2577 //=======================================================================
2578 // name : SMESHGUI_FilterTable::SetText
2579 // Purpose : Set text and internal value in cell of threshold value
2580 //=======================================================================
2581 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2582 const QString& theText,
2583 const int theEntityType)
2585 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2587 bool isSignalsBlocked = aTable->signalsBlocked();
2588 aTable->blockSignals(true);
2590 aTable->item( theRow, 2 )->setText(theText);
2592 aTable->blockSignals(isSignalsBlocked);
2595 //=======================================================================
2596 // name : SMESHGUI_FilterTable::SetText
2597 // Purpose : Get text and internal value from cell of threshold value
2598 //=======================================================================
2599 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2601 const int theEntityType)
2603 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2604 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2607 theText = anItem->text();
2614 //=======================================================================
2615 // name : SMESHGUI_FilterTable::SetID
2616 // Purpose : Set text and internal value in cell of ID value
2617 //=======================================================================
2618 void SMESHGUI_FilterTable::SetID( const int theRow,
2619 const QString& theText,
2620 const int theEntityType )
2622 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2623 aTable->item( theRow, 5 )->setText( theText );
2626 //=======================================================================
2627 // name : SMESHGUI_FilterTable::GetID
2628 // Purpose : Get text and internal value from cell of ID value
2629 //=======================================================================
2630 bool SMESHGUI_FilterTable::GetID( const int theRow,
2632 const int theEntityType )
2634 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2635 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2638 theText = anItem->text();
2646 Class : SMESHGUI_FilterDlg
2647 Description : Dialog to specify filters for VTK viewer
2651 //=======================================================================
2652 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2653 // Purpose : Constructor
2654 //=======================================================================
2655 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2656 const QList<int>& theTypes )
2657 : QDialog( SMESH::GetDesktop( theModule ) ),
2658 mySMESHGUI( theModule ),
2659 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2660 myInitSourceWgOnApply( true )
2662 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2663 mySelector = aViewWindow->GetSelector();
2665 construct(theTypes);
2668 //=======================================================================
2669 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2670 // Purpose : Constructor
2671 //=======================================================================
2672 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2674 : QDialog( SMESH::GetDesktop( theModule ) ),
2675 mySMESHGUI( theModule ),
2676 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2677 myInitSourceWgOnApply( true )
2679 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2680 mySelector = aViewWindow->GetSelector();
2682 aTypes.append(theType);
2686 //=======================================================================
2687 // name : SMESHGUI_FilterDlg::construct
2688 // Purpose : Construct dialog (called by constructor)
2689 //=======================================================================
2690 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2695 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2696 setWindowTitle(tr("CAPTION"));
2698 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2699 aDlgLay->setMargin(MARGIN);
2700 aDlgLay->setSpacing(SPACING);
2702 myMainFrame = createMainFrame (this);
2703 QWidget* aBtnFrame = createButtonFrame(this);
2705 aDlgLay->addWidget(myMainFrame);
2706 aDlgLay->addWidget(aBtnFrame);
2708 aDlgLay->setStretchFactor(myMainFrame, 1);
2710 myHelpFileName = "selection_filter_library_page.html";
2715 //=======================================================================
2716 // name : SMESHGUI_FilterDlg::createMainFrame
2717 // Purpose : Create frame containing dialog's input fields
2718 //=======================================================================
2719 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2721 QWidget* aMainFrame = new QWidget(theParent);
2722 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2723 aMainLay->setMargin(0);
2724 aMainLay->setSpacing(SPACING);
2728 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2729 myTable->SetLibsEnabled(true);
2731 QGroupBox* aGrp = myTable->GetTableGrp();
2732 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2733 int rows = aLay->rowCount();
2734 int cols = aLay->columnCount();
2736 QFrame* aLine = new QFrame(aGrp);
2737 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2738 aLay->addWidget(aLine, rows++, 0, 1, cols);
2740 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2741 mySetInViewer->setChecked(true);
2742 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2745 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2747 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2748 SLOT(onCriterionChanged(const int, const int)));
2750 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2751 SLOT(onCurrentChanged(int, int)));
2753 aMainLay->addWidget(myTable);
2754 aMainLay->addWidget(aSourceGrp);
2759 //=======================================================================
2760 // name : SMESHGUI_FilterDlg::createSourceFrame
2761 // Purpose : Create frame containing source radio button
2762 //=======================================================================
2763 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2765 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2766 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2767 aLay->setMargin(MARGIN);
2768 aLay->setSpacing(SPACING);
2770 mySourceGrp = new QButtonGroup(theParent);
2772 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2773 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2774 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2776 aLay->addWidget(aMeshBtn);
2777 aLay->addWidget(aSelBtn);
2778 aLay->addWidget(aDlgBtn);
2780 mySourceGrp->addButton(aMeshBtn, Mesh);
2781 mySourceGrp->addButton(aSelBtn, Selection);
2782 mySourceGrp->addButton(aDlgBtn, Dialog);
2784 aMeshBtn->setChecked(true);
2789 //=======================================================================
2790 // name : SMESHGUI_FilterDlg::updateMainButtons
2791 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2792 //=======================================================================
2793 void SMESHGUI_FilterDlg::updateMainButtons()
2795 myButtons[ BTN_Close ]->show();
2796 if (myTypes.count() == 1)
2798 myButtons[ BTN_Apply ]->hide();
2802 myButtons[ BTN_Apply ]->show();
2804 // updateGeometry();
2807 //=======================================================================
2808 // name : SMESHGUI_FilterDlg::createButtonFrame
2809 // Purpose : Create frame containing buttons
2810 //=======================================================================
2811 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2813 QGroupBox* aGrp = new QGroupBox(theParent);
2814 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2815 aLay->setMargin(MARGIN);
2816 aLay->setSpacing(SPACING);
2818 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2819 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2820 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2821 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2823 aLay->addWidget(myButtons[ BTN_OK ]);
2824 aLay->addSpacing(10);
2825 aLay->addWidget(myButtons[ BTN_Apply ]);
2826 aLay->addSpacing(10);
2828 aLay->addWidget(myButtons[ BTN_Close ]);
2829 aLay->addWidget(myButtons[ BTN_Help ]);
2831 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2832 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(reject()));
2833 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2834 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2836 updateMainButtons();
2841 //=======================================================================
2842 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2843 // Purpose : Destructor
2844 //=======================================================================
2845 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2849 //=======================================================================
2850 // name : SMESHGUI_FilterDlg::Init
2851 // Purpose : Init dialog fields, connect signals and slots, show dialog
2852 //=======================================================================
2853 void SMESHGUI_FilterDlg::Init (const int type, const bool setInViewer)
2856 aTypes.append(type);
2857 Init(aTypes,setInViewer);
2860 //=======================================================================
2861 // name : SMESHGUI_FilterDlg::Init
2862 // Purpose : Init dialog fields, connect signals and slots, show dialog
2863 //=======================================================================
2864 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewer)
2868 myMesh = SMESH::SMESH_Mesh::_nil();
2870 myIsSelectionChanged = false;
2871 myToRestoreSelMode = false;
2873 myTable->Init(theTypes);
2876 if (theTypes.count() == 1)
2878 int aType = theTypes.first();
2879 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2880 else if (aType == SMESH::ELEM0D) setWindowTitle(tr("ELEM0D_TLT"));
2881 else if (aType == SMESH::BALL ) setWindowTitle(tr("BALL_TLT"));
2882 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2883 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2884 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2885 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2888 setWindowTitle(tr("TLT"));
2890 qApp->processEvents();
2895 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2897 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2898 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
2900 updateMainButtons();
2903 // Initialise filter table with values of previous filter
2904 QList<int>::const_iterator anIter;
2905 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2907 myTable->Clear(*anIter);
2908 if (!myFilter[ *anIter ]->_is_nil())
2910 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2911 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2913 for (int i = 0, n = aCriteria->length(); i < n; i++)
2914 myTable->AddCriterion(aCriteria[ i ], *anIter);
2919 if (myInsertState.contains(theTypes.first()))
2920 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2922 mySetInViewer->setChecked(setInViewer);
2924 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2925 myApplyToState[ theTypes.first() ] :
2926 Mesh)->setChecked(true);
2929 //=======================================================================
2930 // name : SMESHGUI_FilterDlg::onOk
2931 // Purpose : SLOT called when "Ok" button pressed.
2932 // Assign filters VTK viewer and close dialog
2933 //=======================================================================
2934 void SMESHGUI_FilterDlg::onOk()
2939 mySelectionMgr->clearFilters();
2940 disconnect(mySMESHGUI, 0, this, 0);
2941 disconnect(mySelectionMgr, 0, this, 0);
2942 mySMESHGUI->ResetState();
2948 //=======================================================================
2949 // name : SMESHGUI_FilterDlg::reject
2950 // Purpose : SLOT called when "Close" button pressed. Close dialog
2951 //=======================================================================
2952 void SMESHGUI_FilterDlg::reject()
2955 // Restore previously selected object
2958 SALOME_ListIO aList;
2959 mySelectionMgr->clearFilters();
2960 mySelectionMgr->clearSelected();
2961 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2962 for ( ; anIter.More(); anIter.Next())
2964 aList.Append(anIter.Key());
2966 TColStd_MapOfInteger aResMap;
2967 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2968 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2969 aResMap.Add(anIndMap(i));
2971 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2972 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2973 aViewWindow->highlight( anIter.Key(), true, true );
2975 mySelectionMgr->setSelectedObjects(aList, false);
2978 disconnect(mySMESHGUI, 0, this, 0);
2979 disconnect(mySelectionMgr, 0, this, 0);
2980 mySMESHGUI->ResetState();
2984 //=================================================================================
2985 // function : onHelp()
2987 //=================================================================================
2988 void SMESHGUI_FilterDlg::onHelp()
2990 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2992 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2996 platform = "winapplication";
2998 platform = "application";
3000 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
3001 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
3002 arg(app->resourceMgr()->stringValue("ExternalBrowser",
3004 arg(myHelpFileName));
3008 //=======================================================================
3009 // name : SMESHGUI_FilterDlg::onDeactivate
3010 // Purpose : SLOT called when dialog must be deativated
3011 //=======================================================================
3012 void SMESHGUI_FilterDlg::onDeactivate()
3017 //=======================================================================
3018 // name : SMESHGUI_FilterDlg::enterEvent
3019 // Purpose : Event filter
3020 //=======================================================================
3021 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
3023 // mySMESHGUI->EmitSignalDeactivateDialog();
3024 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
3025 mySMESHGUI->ResetState();
3029 //=======================================================================
3030 // name : SMESHGUI_FilterDlg::getIdsFromWg
3031 // Purpose : Retrieve list of ids from given widget
3032 //=======================================================================
3033 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
3039 if (theWg->inherits("QListWidget"))
3041 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
3043 for (int i = 0, n = aListBox->count(); i < n; i++)
3045 int anId = aListBox->item(i)->text().toInt(&b);
3047 theRes.append(anId);
3050 else if (theWg->inherits("QLineEdit"))
3052 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
3053 QString aStr = aLineEdit->text();
3054 QRegExp aRegExp("(\\d+)");
3059 aPos = aRegExp.indexIn(aStr, aPos);
3062 int anId = aRegExp.cap(1).toInt(&b);
3064 theRes.append(anId);
3065 aPos += aRegExp.matchedLength();
3071 //=======================================================================
3072 // name : SMESHGUI_FilterDlg::getSelMode
3073 // Purpose : Get selection mode of specified type
3074 //=======================================================================
3075 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
3079 case SMESH::NODE : return NodeSelection;
3080 case SMESH::ELEM0D : return Elem0DSelection;
3081 case SMESH::BALL : return BallSelection;
3082 case SMESH::EDGE : return EdgeSelection;
3083 case SMESH::FACE : return FaceSelection;
3084 case SMESH::VOLUME : return VolumeSelection;
3085 case SMESH::ALL : return CellSelection;
3086 default : return ActorSelection;
3091 //=======================================================================
3092 // name : SMESHGUI_FilterDlg::setIdsToWg
3093 // Purpose : Insert identifiers in specified widgets
3094 //=======================================================================
3095 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
3100 QStringList aStrList;
3101 foreach(int id, theIds)
3102 aStrList << QString::number(id);
3104 if (theWg->inherits("QListWidget"))
3106 qobject_cast<QListWidget*>(theWg)->clear();
3107 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
3109 else if (theWg->inherits("QLineEdit"))
3111 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
3115 //=======================================================================
3116 // name : SMESHGUI_FilterDlg::isValid
3117 // Purpose : Verify validity of input data
3118 //=======================================================================
3119 bool SMESHGUI_FilterDlg::isValid() const
3121 if (!myTable->IsValid())
3124 for (int i = 0, n = myTable->NumRows(); i < n; i++)
3126 int aType = myTable->GetCriterionType(i);
3127 if (aType == SMESH::FT_BelongToGeom ||
3128 aType == SMESH::FT_BelongToPlane ||
3129 aType == SMESH::FT_BelongToCylinder ||
3130 aType == SMESH::FT_BelongToGenSurface ||
3131 aType == SMESH::FT_LyingOnGeom)
3134 myTable->GetThreshold(i, aName);
3136 std::vector<_PTR(SObject)> aList =
3137 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
3138 if (aList.size() == 0) {
3139 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3140 tr("BAD_SHAPE_NAME").arg(aName));
3144 if (aType == SMESH::FT_BelongToCylinder ||
3145 aType == SMESH::FT_BelongToPlane ||
3146 aType == SMESH::FT_BelongToGenSurface ) {
3147 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
3148 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
3149 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
3150 if (!aGeomObj->_is_nil()) {
3152 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
3154 aFace.ShapeType() != TopAbs_FACE) {
3155 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3156 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3160 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
3161 if (aSurf.IsNull()) {
3162 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3163 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3167 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
3168 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3169 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
3173 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
3174 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3175 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
3181 else if (aType == SMESH::FT_CoplanarFaces)
3184 myTable->GetThreshold(i, faceID);
3185 if ( faceID.isEmpty() )
3187 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3188 tr("FACE_ID_NOT_SELECTED"));
3191 if ( myMesh->_is_nil() )
3193 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3194 tr("MESH_IS_NOT_SELECTED"));
3197 if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
3199 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3200 tr("NOT_FACE_ID").arg(faceID));
3209 //=======================================================================
3210 // name : SMESHGUI_FilterDlg::SetSourceWg
3211 // Purpose : Set widget of parent dialog containing ids to be filtered if
3212 // user select corresponding source radio button
3213 //=======================================================================
3214 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
3215 const bool initOnApply)
3218 myInitSourceWgOnApply = initOnApply;
3221 //=======================================================================
3222 // name : SMESHGUI_FilterDlg::SetMesh
3223 // Purpose : Set mesh
3224 //=======================================================================
3225 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
3227 if ( !theMesh->_is_nil() ) {
3229 if ( !myFilter[ myTable->GetType() ]->_is_nil())
3230 myFilter[ myTable->GetType() ]->SetMesh( theMesh );
3232 const bool isEnable = !(myMesh->_is_nil());
3233 myButtons[BTN_OK]->setEnabled(isEnable);
3234 myButtons[BTN_Apply]->setEnabled(isEnable);
3237 //=======================================================================
3238 // name : SMESHGUI_FilterDlg::SetSelection
3239 // Purpose : Get filtered ids
3240 //=======================================================================
3241 void SMESHGUI_FilterDlg::SetSelection()
3244 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3246 if (mySelectionMgr) {
3248 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
3249 SALOME_ListIteratorOfListIO anIter (anObjs);
3250 for ( ; anIter.More(); anIter.Next()) {
3251 TColStd_IndexedMapOfInteger aMap;
3252 mySelector->GetIndex(anIter.Value(), aMap);
3253 myIObjects.Bind(anIter.Value(), aMap);
3256 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3264 //=======================================================================
3265 // name : SMESHGUI_FilterDlg::onApply
3266 // Purpose : SLOT called when "Apply" button pressed.
3267 // Assign filters to VTK viewer
3268 //=======================================================================
3269 bool SMESHGUI_FilterDlg::onApply()
3274 SUIT_OverrideCursor wc;
3276 int aCurrType = myTable->GetType();
3278 if (!createFilter(aCurrType))
3281 insertFilterInViewer();
3283 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3284 QList<int> aResultIds;
3285 filterSource(aCurrType, aResultIds);
3287 selectInViewer(aCurrType, aResultIds);
3291 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3292 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3294 catch(const SALOME::SALOME_Exception& S_ex)
3296 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3307 //=======================================================================
3308 // name : SMESHGUI_FilterDlg::createFilter
3309 // Purpose : Create predicate for given type
3310 //=======================================================================
3311 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3313 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3314 if (aFilterMgr->_is_nil())
3317 int n = myTable->NumRows();
3319 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3320 aCriteria->length(n);
3322 long aPrecision = -1;
3323 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3325 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3326 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3328 for (CORBA::ULong i = 0; i < n; i++) {
3329 SMESH::Filter::Criterion aCriterion = createCriterion();
3330 myTable->GetCriterion(i, aCriterion);
3331 aCriterion.Precision = aPrecision;
3332 aCriteria[ i ] = aCriterion;
3335 if ( !myFilter[ theType ]->_is_nil() )
3336 myFilter[ theType ]->UnRegister();
3337 myFilter[ theType ] = aFilterMgr->CreateFilter();
3338 myFilter[ theType ]->SetCriteria(aCriteria.inout());
3343 //================================================================================
3345 * \brief Return the current filter
3347 //================================================================================
3349 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3351 SMESH::Filter_var filter;
3353 int aCurrType = myTable->GetType();
3354 filter = myFilter[ aCurrType ];
3359 return filter._retn();
3362 //================================================================================
3364 * \brief Sets a filter to the table
3366 //================================================================================
3368 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3370 if ( !filter->_is_nil() )
3372 if ( !myFilter[ type ]->_is_nil() )
3373 myFilter[ type ]->UnRegister();
3375 myFilter[ type ] = filter;
3378 //================================================================================
3380 * \brief call UnRegister() for myFilter's
3382 //================================================================================
3384 void SMESHGUI_FilterDlg::UnRegisterFilters()
3386 QMap< int, SMESH::Filter_var >::iterator i_f = myFilter.begin();
3387 for ( ; i_f != myFilter.end(); ++i_f )
3388 if ( !i_f.value()->_is_nil() )
3389 i_f.value()->UnRegister();
3393 //=======================================================================
3394 // name : SMESHGUI_FilterDlg::insertFilterInViewer
3395 // Purpose : Insert filter in viewer
3396 //=======================================================================
3397 void SMESHGUI_FilterDlg::insertFilterInViewer()
3399 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3400 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3402 if (myFilter[ myTable->GetType() ]->_is_nil() ||
3403 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3404 !mySetInViewer->isChecked()) {
3405 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3408 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3409 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3410 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3411 SMESH::SetFilter(aFilter, aSelector);
3416 //=======================================================================
3417 // name : SMESHGUI_FilterDlg::filterSource
3418 // Purpose : Filter source ids
3419 //=======================================================================
3420 void SMESHGUI_FilterDlg::filterSource (const int theType,
3421 QList<int>& theResIds)
3424 if (myFilter[ theType ]->_is_nil())
3427 int aSourceId = mySourceGrp->checkedId();
3429 if (aSourceId == Mesh)
3431 if (myMesh->_is_nil())
3433 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3434 for (int i = 0, n = anIds->length(); i < n; i++)
3435 theResIds.append(anIds[ i ]);
3437 else if (aSourceId == Selection)
3439 filterSelectionSource(theType, theResIds);
3441 else if (aSourceId == Dialog)
3443 // retrieve ids from dialog
3444 QList<int> aDialogIds;
3445 getIdsFromWg(mySourceWg, aDialogIds);
3447 if (myMesh->_is_nil())
3449 theResIds = aDialogIds;
3454 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3455 myFilter[ theType ]->SetMesh(myMesh);
3456 QList<int>::const_iterator anIter;
3457 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3458 if (aPred->IsSatisfy(*anIter))
3459 theResIds.append(*anIter);
3461 // set ids to the dialog
3462 if (myInitSourceWgOnApply || aSourceId == Dialog)
3463 setIdsToWg(mySourceWg, theResIds);
3466 //=======================================================================
3467 // name : SMESHGUI_FilterDlg::filterSelectionSource
3468 // Purpose : Filter source selection
3469 //=======================================================================
3470 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3471 QList<int>& theResIds)
3474 if (myMesh->_is_nil() || mySelectionMgr == 0)
3477 // Create map of entities to be filtered
3478 TColStd_MapOfInteger aToBeFiltered;
3479 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3481 for ( ; anIter.More(); anIter.Next())
3484 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3485 if (!aSubMesh->_is_nil())
3487 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3489 SMESH::long_array_var anIds =
3490 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3491 for (int i = 0, n = anIds->length(); i < n; i++)
3492 aToBeFiltered.Add(anIds[ i ]);
3497 SMESH::SMESH_GroupBase_var aGroup =
3498 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3499 if (!aGroup->_is_nil())
3501 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3503 SMESH::long_array_var anIds = aGroup->GetListOfID();
3504 for (int i = 0, n = anIds->length(); i < n; i++)
3505 aToBeFiltered.Add(anIds[ i ]);
3510 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3511 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3513 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3515 if (aSelMap.Extent() > 0)
3517 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3519 for (int i = 1; i <= aSelMap.Extent(); i++)
3520 aToBeFiltered.Add(aSelMap(i));
3527 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3528 myFilter[ theType ]->SetMesh(myMesh);
3529 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3530 for ( ; aResIter.More(); aResIter.Next())
3531 if (aPred->IsSatisfy(aResIter.Key()))
3532 theResIds.append(aResIter.Key());
3535 //=======================================================================
3536 // name : SMESHGUI_FilterDlg::selectInViewer
3537 // Purpose : Select given entities in viewer
3538 //=======================================================================
3539 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3541 if (mySelectionMgr == 0 || myMesh->_is_nil())
3544 mySelectionMgr->clearFilters();
3546 // Set new selection mode if necessary
3547 Selection_Mode aSelMode = getSelMode(theType);
3548 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3549 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3550 mySelectionMgr->clearSelected();
3551 mySelectionMgr->clearFilters();
3552 SMESH::SetPointRepresentation( aSelMode == NodeSelection );
3553 aViewWindow->SetSelectionMode(aSelMode);
3557 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3558 if (!anActor || !anActor->hasIO())
3561 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3562 //mySelectionMgr->clearSelected();
3563 //mySelectionMgr->AddIObject(anIO, false);
3564 SALOME_ListIO aList;
3566 mySelectionMgr->setSelectedObjects(aList, false);
3568 // Remove filter corresponding to the current type from viewer
3569 int aType = myTable->GetType();
3570 int aFilterId = SMESH::UnknownFilter;
3571 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3572 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3573 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3574 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3575 SMESH::RemoveFilter(aFilterId);
3578 TColStd_MapOfInteger aMap;
3579 QList<int>::const_iterator anIter;
3580 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3584 // Set new selection
3585 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3586 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3587 aViewWindow->highlight( anIO, true, true );
3589 // insert previously stored filter in viewer if necessary
3590 if (!aFilter.IsNull())
3591 SMESH::SetFilter(aFilter);
3594 //=======================================================================
3595 // name : SMESHGUI_FilterDlg::createCriterion
3596 // Purpose : Create criterion structure with default values
3597 //=======================================================================
3598 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3600 SMESH::Filter::Criterion aCriterion;
3602 aCriterion.Type = SMESH::FT_Undefined;
3603 aCriterion.Compare = SMESH::FT_Undefined;
3604 aCriterion.Threshold = 0;
3605 aCriterion.UnaryOp = SMESH::FT_Undefined;
3606 aCriterion.BinaryOp = SMESH::FT_Undefined;
3607 aCriterion.ThresholdStr = "";
3608 aCriterion.ThresholdID = "";
3609 aCriterion.TypeOfElement = SMESH::ALL;
3614 //=======================================================================
3615 // name : SMESHGUI_FilterDlg::onSelectionDone
3616 // Purpose : SLOT called when selection changed.
3617 // If current cell corresponds to the threshold value of
3618 // BelongToGeom criterion name of selected object is set in this cell
3619 //=======================================================================
3620 void SMESHGUI_FilterDlg::onSelectionDone()
3622 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3623 if ( myMesh->_is_nil() && aList.Extent()>0 )
3625 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3626 if ( !(myMesh->_is_nil()) ) {
3627 myButtons[BTN_OK]->setEnabled(true);
3628 myButtons[BTN_Apply]->setEnabled(true);
3632 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol))
3635 const int type = myTable->GetCriterionType(aRow);
3637 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3638 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3639 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces
3640 << SMESH::FT_ConnectedElements;
3641 if ( !types.contains( type ))
3644 Handle(SALOME_InteractiveObject) anIO = aList.First();
3647 case SMESH::FT_CoplanarFaces: // get ID of a selected mesh face
3650 int nbElems = SMESH::GetNameOfSelectedElements(mySelector, anIO, aString);
3652 myTable->SetThreshold(aRow, aString);
3655 case SMESH::FT_ConnectedElements: // get either VERTEX or a node ID
3657 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3658 if (!anObj->_is_nil())
3660 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3661 myTable->SetID (aRow, anIO->getEntry());
3666 int nbElems = SMESH::GetNameOfSelectedElements(mySelector, anIO, aString);
3668 myTable->SetThreshold(aRow, aString);
3672 default: // get a GEOM object
3674 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3675 if (!anObj->_is_nil())
3677 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3678 myTable->SetID(aRow, anIO->getEntry());
3685 //=======================================================================
3686 // name : SMESHGUI_FilterDlg::onCriterionChanged
3687 // Purpose : SLOT called when cretarion of current row changed. Update selection
3688 //=======================================================================
3689 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3694 //=======================================================================
3695 // name : SMESHGUI_FilterDlg::onThresholdChanged
3696 // Purpose : SLOT called when a threshold value is changed by the user and
3697 // not by myTable->SetThreshold()
3698 //=======================================================================
3699 void SMESHGUI_FilterDlg::onThresholdChanged( const int row, const int type )
3701 if ( myTable->GetCriterionType( row, type ) == SMESH::FT_ConnectedElements )
3703 // to differ the text entered by the user from that got from selection
3704 myTable->SetID( row, "", type );
3708 //=======================================================================
3709 // name : SMESHGUI_FilterDlg::onCurrentChanged
3710 // Purpose : SLOT called when current row changed. Update selection
3711 //=======================================================================
3712 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3717 //=======================================================================
3718 // name : SMESHGUI_FilterDlg::updateSelection
3719 // Purpose : UpdateSelection in accordance with current row
3720 //=======================================================================
3721 void SMESHGUI_FilterDlg::updateSelection()
3723 if (mySelectionMgr == 0)
3726 // TColStd_MapOfInteger allTypes;
3727 // for( int i=0; i<10; i++ )
3728 // allTypes.Add( i );
3729 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3735 mySelectionMgr->clearFilters();
3739 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3740 int aCriterionType = myTable->GetCriterionType(aRow);
3741 if ( isCurrentCell &&
3742 (aCriterionType == SMESH::FT_BelongToGeom ||
3743 aCriterionType == SMESH::FT_BelongToPlane ||
3744 aCriterionType == SMESH::FT_BelongToCylinder ||
3745 aCriterionType == SMESH::FT_BelongToGenSurface ||
3746 aCriterionType == SMESH::FT_LyingOnGeom))
3748 if (aCriterionType == SMESH::FT_BelongToGeom ||
3749 aCriterionType == SMESH::FT_BelongToGenSurface ||
3750 aCriterionType == SMESH::FT_LyingOnGeom) {
3752 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3754 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3755 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3757 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3758 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3760 myIsSelectionChanged = true;
3763 else if ( aCriterionType == SMESH::FT_ConnectedElements )
3765 QList<SUIT_SelectionFilter*> fList;
3766 fList.push_back( new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX ));
3767 fList.push_back( new SMESH_TypeFilter( SMESH::IDSOURCE ));
3768 mySelectionMgr->installFilter
3769 ( new SMESH_LogicalFilter( fList, SMESH_LogicalFilter::LO_OR,
3770 !mySelectionMgr->autoDeleteFilter() ));
3772 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3774 mySelModeToRestore = aViewWindow->SelectionMode();
3775 aViewWindow->SetSelectionMode( NodeSelection );
3776 myToRestoreSelMode = ( mySelModeToRestore != NodeSelection );
3777 if ( myToRestoreSelMode )
3778 SMESH::SetPointRepresentation( true );
3783 mySelector->SetSelectionMode( getSelMode( myTable->GetType() ));
3785 if (myIsSelectionChanged) {
3786 // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3787 // Impossible to select any object in the OB on the second opening of FilterDlg
3792 //=================================================================================
3793 // function : keyPressEvent()
3795 //=================================================================================
3796 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3798 QDialog::keyPressEvent( e );
3799 if ( e->isAccepted() )
3802 if ( e->key() == Qt::Key_F1 ) {
3808 //================================================================================
3810 * \brief Restores a selection mode if it was changed to set up some criterion
3812 //================================================================================
3814 void SMESHGUI_FilterDlg::restoreSelMode()
3816 if ( myToRestoreSelMode )
3818 SMESH::SetPointRepresentation( mySelModeToRestore == NodeSelection );
3820 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3821 aViewWindow->SetSelectionMode( mySelModeToRestore );
3823 myToRestoreSelMode = false;