1 // Copyright (C) 2007-2012 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>
43 // SALOME GEOM includes
45 #include <GEOM_FaceFilter.h>
46 #include <GEOM_TypeFilter.h>
48 // SALOME GUI includes
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
53 #include <QtxColorButton.h>
55 #include <LightApp_Application.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <SalomeApp_Tools.h>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_IntSpinBox.h>
60 #include <SalomeApp_DoubleSpinBox.h>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
66 #include <SVTK_ViewWindow.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <StdSelect_TypeOfFace.hxx>
73 #include <BRep_Tool.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_CylindricalSurface.hxx>
78 #include <Precision.hxx>
79 #include <TColStd_MapOfInteger.hxx>
80 #include <TColStd_IndexedMapOfInteger.hxx>
81 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
86 #include <QPushButton>
88 #include <QTableWidget>
89 #include <QStringList>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QGridLayout>
93 #include <QStackedWidget>
94 #include <QApplication>
96 #include <QFontMetrics>
98 #include <QButtonGroup>
99 #include <QRadioButton>
101 #include <QListWidget>
103 #include <QItemDelegate>
104 #include <QDoubleValidator>
106 #include <QHeaderView>
109 #include <SALOMEconfig.h>
110 #include CORBA_SERVER_HEADER(SMESH_Group)
115 //---------------------------------------
117 //---------------------------------------
118 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
121 QMap<int, QString>::const_iterator anIter;
122 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
123 aRes = qMax(aRes, theMetrics.width(anIter.value()));
127 //---------------------------------------
129 //---------------------------------------
130 static int getFilterId (SMESH::ElementType theType)
134 case SMESH::NODE : return SMESH::NodeFilter;
135 case SMESH::EDGE : return SMESH::EdgeFilter;
136 case SMESH::FACE : return SMESH::FaceFilter;
137 case SMESH::VOLUME : return SMESH::VolumeFilter;
138 case SMESH::ALL : return SMESH::AllElementsFilter;
139 default : return SMESH::UnknownFilter;
144 Class : SMESHGUI_FilterTable::AdditionalWidget
145 Description : Class for storing additional parameters of criterion
148 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
154 AdditionalWidget(QWidget* theParent);
155 virtual ~AdditionalWidget();
157 virtual QList<int> GetParameters() const;
158 virtual bool IsValid(const bool = true) const;
159 virtual double GetDouble(const int) const;
160 virtual int GetInteger(const int) const;
161 virtual QString GetString(const int) const;
162 virtual void SetDouble(const int, const double);
163 virtual void SetInteger(const int, const int);
164 virtual void SetString(const int, const QString&);
165 void SetEditable(const int, const bool);
166 void SetEditable(const bool);
167 void SetPrecision(const int, const char* = 0);
170 QMap< int, QWidget* > myWidgets;
173 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
176 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
178 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
179 sb->setAcceptNames( false ); // No Notebook variables allowed
180 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
182 myWidgets[ Tolerance ] = sb;
184 QHBoxLayout* aLay = new QHBoxLayout(this);
185 aLay->setSpacing(SPACING);
188 aLay->addWidget(aLabel);
189 aLay->addWidget(myWidgets[ Tolerance ]);
192 SetDouble( Tolerance, Precision::Confusion() );
195 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
199 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
202 theList.append(Tolerance);
206 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
211 QList<int> aParams = GetParameters();
212 QList<int>::const_iterator anIter;
213 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
214 if ( !myWidgets.contains( *anIter ) ) continue;
216 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
217 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
219 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
221 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
223 if (!valid && theMsg) {
224 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
225 tr("SMESHGUI_INVALID_PARAMETERS"));
233 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
236 if ( myWidgets.contains( theId ) ) {
237 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
238 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
239 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
240 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
245 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
248 if ( myWidgets.contains( theId ) ) {
249 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
250 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
251 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
252 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
257 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
260 if ( myWidgets.contains( theId ) ) {
261 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
262 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
263 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
264 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
269 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
271 if ( myWidgets.contains( theId ) ) {
272 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
273 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
274 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
275 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
279 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
281 if ( myWidgets.contains( theId ) ) {
282 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
283 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
284 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
285 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
289 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
291 if ( myWidgets.contains( theId ) ) {
292 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
293 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
294 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
295 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
299 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
301 if ( myWidgets.contains( theId ) ) {
302 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
303 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
304 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
305 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
309 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
311 QList<int> aParams = GetParameters();
312 QList<int>::const_iterator anIter;
313 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
314 SetEditable( *anIter, isEditable );
317 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
319 if ( myWidgets.contains( theId ) ) {
320 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
321 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
322 double val = sb->GetValue();
323 double min = pow(10.0, -(sb->decimals()));
324 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
325 sb->SetValue( qMax( val, min ) );
331 Class : SMESHGUI_FilterTable::ComboItem
332 Description : Combo table item. Identificator corresponding to string may be assigned
335 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
340 ComboItem( const QMap<int, QString>& );
342 void setItems( const QMap<int, QString>& );
347 void setValue( const int );
351 int index( int ) const;
354 QMap<int, int> myIdToIdx;
357 int SMESHGUI_FilterTable::ComboItem::Type()
359 return QTableWidgetItem::UserType + 1;
362 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
363 : QTableWidgetItem( Type() )
368 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
371 QMap<int, QString>::const_iterator it;
373 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
374 myIdToIdx[it.key()] = items.count();
375 items.append( it.value() );
377 setData( Qt::UserRole, items );
381 void SMESHGUI_FilterTable::ComboItem::clear()
383 QMap<int, QString> empty;
387 int SMESHGUI_FilterTable::ComboItem::count() const
389 return myIdToIdx.count();
392 int SMESHGUI_FilterTable::ComboItem::value() const
394 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
397 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
399 int idx = index( theId );
400 QStringList items = data( Qt::UserRole ).toStringList();
401 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
404 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
406 QMap<int,int>::const_iterator it;
407 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
408 if ( it.value() == idx ) return it.key();
412 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
414 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
417 Class : SMESHGUI_FilterTable::CheckItem
418 Description : Check table item.
421 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
426 CheckItem( bool = false );
427 CheckItem( const QString&, bool = false );
430 void setChecked( bool );
431 bool checked() const;
434 int SMESHGUI_FilterTable::CheckItem::Type()
436 return QTableWidgetItem::UserType + 2;
439 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
440 : QTableWidgetItem( Type() )
442 Qt::ItemFlags f = flags();
443 f = f | Qt::ItemIsUserCheckable;
444 f = f & ~Qt::ItemIsTristate;
445 f = f & ~Qt::ItemIsEditable;
450 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
451 : QTableWidgetItem( Type() )
453 Qt::ItemFlags f = flags();
454 f = f | Qt::ItemIsUserCheckable;
455 f = f & ~Qt::ItemIsTristate;
456 f = f & ~Qt::ItemIsEditable;
462 SMESHGUI_FilterTable::CheckItem::~CheckItem()
466 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
468 setCheckState( value ? Qt::Checked : Qt::Unchecked );
471 bool SMESHGUI_FilterTable::CheckItem::checked() const
473 return checkState() == Qt::Checked;
477 Class : SMESHGUI_FilterTable::IntSpinItem
478 Description : Integer spin table item.
481 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
486 IntSpinItem( const int theValue );
489 void setValue( const int theValue );
494 int SMESHGUI_FilterTable::IntSpinItem::Type()
496 return QTableWidgetItem::UserType + 3;
499 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
500 : QTableWidgetItem( Type() )
502 setValue( theValue );
505 int SMESHGUI_FilterTable::IntSpinItem::value() const
508 int value = data( Qt::UserRole ).toInt( &ok );
509 return ok ? value : 0;
512 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
514 setData( Qt::UserRole, theValue );
515 setText( QString::number( theValue ) );
518 void SMESHGUI_FilterTable::IntSpinItem::clear()
524 Class : SMESHGUI_FilterTable::DoubleSpinItem
525 Description : Double spin table item.
528 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
533 DoubleSpinItem( const double theValue );
535 double value() const;
536 void setValue( const double theValue );
538 int precision() const;
539 void setPrecision( const int thePrecision );
544 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
546 return QTableWidgetItem::UserType + 4;
549 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
550 : QTableWidgetItem( Type() )
552 setValue( theValue );
555 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
558 double value = data( Qt::UserRole ).toDouble( &ok );
559 return ok ? value : 0;
562 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
564 setData( Qt::UserRole, theValue );
565 setText( QString::number( theValue ) );
568 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
571 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
572 return ok ? precision : 0;
575 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
577 setData( Qt::UserRole + 1, thePrecision );
580 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
586 Class : SMESHGUI_FilterTable::ComboDelegate
587 Description : Table used by this widget
590 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
593 ComboDelegate( QObject* = 0 );
596 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
597 const QModelIndex& ) const;
599 void setEditorData( QWidget*, const QModelIndex& ) const;
600 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
602 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
603 const QModelIndex& ) const;
605 QTableWidget* myTable;
608 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
609 : QItemDelegate( parent ),
610 myTable( qobject_cast<QTableWidget*>( parent ) )
614 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
618 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
619 const QStyleOptionViewItem& option,
620 const QModelIndex& index ) const
622 QVariant aData = index.data( Qt::UserRole );
623 QVariant::Type aDataType = aData.type();
624 if( aDataType == QVariant::StringList ) {
625 QStringList l = aData.toStringList();
626 if ( !l.isEmpty() ) {
627 QComboBox* cb = new QComboBox( parent );
628 cb->setFrame( false );
633 else if( aDataType == QVariant::Int ) {
635 int aValue = aData.toInt( &ok );
637 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
638 intSpin->setFrame( false );
639 intSpin->setValue( aValue );
643 else if( aDataType == QVariant::Double ) {
645 double aValue = aData.toDouble( &ok );
647 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
651 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
652 dblSpin->setFrame( false );
653 dblSpin->setValue( aValue );
657 return QItemDelegate::createEditor( parent, option, index );
660 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
661 const QModelIndex& index ) const
663 QVariant data = index.model()->data( index, Qt::DisplayRole );
664 QString value = data.toString();
666 if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
667 int i = cb->findText( value );
669 cb->setCurrentIndex( i );
673 else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
674 if( data.type() == QVariant::Double ) {
675 double valueDouble = data.toDouble( &bOk );
677 dblSpin->setValue( valueDouble );
680 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
683 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
684 QAbstractItemModel* model,
685 const QModelIndex& index) const
687 if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
688 model->setData( index, cb->currentText(), Qt::DisplayRole );
689 else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
690 model->setData( index, intSpin->value(), Qt::DisplayRole );
691 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
692 model->setData( index, dblSpin->value(), Qt::DisplayRole );
693 else QItemDelegate::setModelData( editor, model, index );
696 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
697 const QStyleOptionViewItem& option,
698 const QModelIndex& index ) const
700 editor->setGeometry( option.rect );
704 Class : SMESHGUI_FilterTable::Table
705 Description : Table used by this widget
708 class SMESHGUI_FilterTable::Table : public QTableWidget
711 Table( QWidget* = 0 );
712 Table( int, int, QWidget* = 0 );
715 QSize minimumSizeHint() const;
717 void setEditable( bool, int, int );
718 bool isEditable( int, int ) const;
720 void setReadOnly( bool );
721 bool isReadOnly() const;
723 void insertRows( int, int = 1 );
724 QString text( int, int );
726 QList<int> selectedRows();
729 //=======================================================================
730 // name : SMESHGUI_FilterTable::Table::Table
731 // Purpose : Constructor
732 //=======================================================================
733 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
734 : QTableWidget(parent)
736 // set custom item delegate
737 setItemDelegate( new ComboDelegate(this) );
738 // set edit triggers by default
739 setReadOnly( false );
742 //=======================================================================
743 // name : SMESHGUI_FilterTable::Table::Table
744 // Purpose : Constructor
745 //=======================================================================
746 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
747 : QTableWidget(numRows, numCols, parent)
749 // set custom item delegate
750 setItemDelegate( new ComboDelegate(this) );
751 // set edit triggers by default
752 setReadOnly( false );
755 //=======================================================================
756 // name : SMESHGUI_FilterTable::Table::~Table
757 // Purpose : Destructor
758 //=======================================================================
759 SMESHGUI_FilterTable::Table::~Table()
763 //=======================================================================
764 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
765 // Purpose : Get minimum size for the table
766 //=======================================================================
767 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
769 QSize s = QTableWidget::minimumSizeHint();
770 QHeaderView* hv = horizontalHeader();
772 s.setWidth( qMax( s.width(), hv->length() ) );
776 //=======================================================================
777 // name : SMESHGUI_FilterTable::Table::setEditable
778 // Purpose : Set editable of specified cell
779 //=======================================================================
780 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
783 QTableWidgetItem* anItem = item( row, col );
785 bool isSignalsBlocked = signalsBlocked();
786 blockSignals( true );
788 Qt::ItemFlags f = anItem->flags();
789 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
790 else f = f | Qt::ItemIsEditable;
791 anItem->setFlags( f );
793 blockSignals( isSignalsBlocked );
797 //=======================================================================
798 // name : SMESHGUI_FilterTable::Table::isEditable
799 // Purpose : Verify wheter cell is editable
800 //=======================================================================
801 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
803 QTableWidgetItem* anItem = item( row, col );
804 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
807 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
809 setEditTriggers( on ?
810 QAbstractItemView::NoEditTriggers :
811 QAbstractItemView::AllEditTriggers );
814 bool SMESHGUI_FilterTable::Table::isReadOnly() const
816 return editTriggers() == QAbstractItemView::NoEditTriggers;
819 //=======================================================================
820 // name : SMESHGUI_FilterTable::Table::insertRows
821 // Purpose : Insert rows (virtual redefined)
822 //=======================================================================
823 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
825 closePersistentEditor( currentItem() );
826 while ( count-- ) insertRow( row );
829 //=======================================================================
830 // name : SMESHGUI_FilterTable::Table::text
831 // Purpose : Get text from cell (virtual redefined)
832 //=======================================================================
833 QString SMESHGUI_FilterTable::Table::text (int row, int col)
835 closePersistentEditor( currentItem() );
836 QTableWidgetItem* anItem = item( row, col );
837 return anItem ? anItem->text() : QString();
840 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
842 QList<QTableWidgetItem*> selItems = selectedItems();
843 QTableWidgetItem* anItem;
846 foreach( anItem, selItems ) {
847 int r = row( anItem );
848 if ( !rows.contains( r ) ) rows.append( r );
856 Class : SMESHGUI_FilterTable
857 Description : Frame containig
858 - Button group for switching entity type
859 - Table for displaying filter criterions
860 - Buttons for editing table and filter libraries
863 //=======================================================================
864 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
865 // Purpose : Constructor
866 //=======================================================================
867 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
872 mySMESHGUI( theModule )
881 //=======================================================================
882 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
883 // Purpose : Constructor
884 //=======================================================================
885 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
887 const QList<int>& types )
890 mySMESHGUI( theModule )
896 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
900 //=======================================================================
901 // name : SMESHGUI_FilterTable::Init
902 // Purpose : Create table corresponding to the specified type
903 //=======================================================================
904 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
906 if (theTypes.isEmpty())
909 // Create buttons if necessary
911 if (myTables.isEmpty())
913 // create main layout
914 QVBoxLayout* aMainLay = new QVBoxLayout(this);
915 aMainLay->setMargin( 0 );
916 aMainLay->setSpacing( SPACING );
918 // create switch of entity types
919 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
920 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
921 myEntityTypeBoxLayout->setMargin( MARGIN );
922 myEntityTypeBoxLayout->setSpacing( SPACING );
923 myEntityTypeGrp = new QButtonGroup(this);
925 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
926 QMap<int, QString>::const_iterator anIter;
927 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
929 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
930 myEntityTypeGrp->addButton(aBtn, anIter.key());
931 myEntityTypeBoxLayout->addWidget(aBtn);
934 myTableGrp = new QGroupBox(tr("FILTER"), this );
937 mySwitchTableGrp = new QWidget(myTableGrp);
938 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
939 mySwitchTableGrpLayout->setMargin(0);
940 mySwitchTableGrpLayout->setSpacing(0);
942 QList<int>::const_iterator typeIt = theTypes.begin();
943 for ( ; typeIt != theTypes.end(); ++typeIt ) {
944 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
945 myTables[ *typeIt ] = aTable;
946 mySwitchTableGrpLayout->addWidget(aTable);
947 if ( typeIt != theTypes.begin() )
952 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
953 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
954 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
955 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
956 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
957 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
959 myAddBtn->setAutoDefault(false);
960 myRemoveBtn->setAutoDefault(false);
961 myClearBtn->setAutoDefault(false);
962 myInsertBtn->setAutoDefault(false);
963 myCopyFromBtn->setAutoDefault(false);
964 myAddToBtn->setAutoDefault(false);
966 myCopyFromBtn->hide();
970 QGridLayout* aLay = new QGridLayout(myTableGrp);
971 aLay->setMargin(MARGIN);
972 aLay->setSpacing(SPACING);
974 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
975 aLay->addWidget(myAddBtn, 0, 1);
976 aLay->addWidget(myInsertBtn, 1, 1);
977 aLay->addWidget(myRemoveBtn, 2, 1);
978 aLay->addWidget(myClearBtn, 3, 1);
979 aLay->addWidget(myCopyFromBtn, 5, 1);
980 aLay->addWidget(myAddToBtn, 6, 1);
981 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
983 aLay->setRowMinimumHeight(4, 10);
984 aLay->setRowStretch(4, 1);
985 aLay->setColumnStretch(0, 1);
986 aLay->setColumnStretch(1, 0);
989 aMainLay->addWidget(myEntityTypeBox);
990 aMainLay->addWidget(myTableGrp);
993 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
994 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
995 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
996 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
998 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
999 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
1001 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1007 QList<int>::const_iterator typeIt = theTypes.begin();
1008 for ( ; typeIt != theTypes.end(); ++typeIt ) {
1009 if ( !myTables[ *typeIt ] ) {
1010 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
1011 myTables[ *typeIt ] = aTable;
1012 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ *typeIt ]);
1017 // Hide buttons of entity types if necessary
1018 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1019 QMap<int, QString>::const_iterator anIt;
1020 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1022 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1023 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1026 // select first button if there is no selected buttons or it is hidden
1027 int aBtnId = myEntityTypeGrp->checkedId();
1028 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1029 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1030 if ( aBtn ) aBtn->setChecked(true);
1033 myEntityTypeBox->setVisible(theTypes.count() > 1);
1035 myTableGrp->updateGeometry();
1036 int cType = myEntityTypeGrp->checkedId();
1037 onEntityType(cType);
1040 //=======================================================================
1041 // name : SMESHGUI_FilterTable::createAdditionalFrame
1042 // Purpose : Get group box containing table. May be used for adding new widgets in it
1043 //=======================================================================
1044 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1046 QWidget* aFrame = new QWidget(theParent);
1048 QFrame* aLine1 = new QFrame(aFrame);
1049 QFrame* aLine2 = new QFrame(aFrame);
1050 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1051 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1052 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1053 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1055 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1057 myWgStack = new QStackedWidget(aFrame);
1059 QGridLayout* aLay = new QGridLayout(aFrame);
1061 aLay->setSpacing(SPACING);
1062 aLay->addWidget(aLine1, 0, 0);
1063 aLay->addWidget(aLabel, 0, 1);
1064 aLay->addWidget(aLine2, 0, 2);
1065 aLay->addWidget(myWgStack, 1, 0, 1, 3);
1070 //=======================================================================
1071 // name : SMESHGUI_FilterTable::GetTableGrp
1072 // Purpose : Get group box containing table. May be used for adding new widgets in it
1073 //=======================================================================
1074 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1079 //=======================================================================
1080 // name : SMESHGUI_FilterTable::onEntityType
1081 // Purpose : SLOT. Called when entity type changed.
1082 // Display corresponding table
1083 //=======================================================================
1084 void SMESHGUI_FilterTable::onEntityType (int theType)
1086 if (myEntityType == theType)
1090 emit NeedValidation();
1093 myEntityTypeGrp->button(myEntityType)->setChecked(true);
1097 myEntityType = theType;
1099 if (!myTables.contains(theType)) {
1100 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1101 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1104 TableMap::iterator anIter;
1105 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1106 anIter.value()->setVisible( myEntityType == anIter.key() );
1109 qApp->processEvents();
1110 myTables[ myEntityType ]->updateGeometry();
1113 emit EntityTypeChanged(theType);
1116 //=======================================================================
1117 // name : SMESHGUI_FilterTable::IsValid
1118 // Purpose : Verify validity of entered data
1119 //=======================================================================
1120 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1122 int aType = theEntityType == -1 ? GetType() : theEntityType;
1124 Table* aTable = myTables[ aType ];
1125 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1127 int aCriterion = GetCriterionType(i, aType);
1129 if (aCriterion == SMESH::FT_GroupColor ) {
1130 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1131 if (clrBtn && !clrBtn->color().isValid())
1132 errMsg = tr( "GROUPCOLOR_ERROR" );
1134 else if (aCriterion == SMESH::FT_RangeOfIds ||
1135 aCriterion == SMESH::FT_BelongToGeom ||
1136 aCriterion == SMESH::FT_BelongToPlane ||
1137 aCriterion == SMESH::FT_BelongToCylinder ||
1138 aCriterion == SMESH::FT_BelongToGenSurface ||
1139 aCriterion == SMESH::FT_ElemGeomType ||
1140 aCriterion == SMESH::FT_EntityType ||
1141 aCriterion == SMESH::FT_CoplanarFaces ||
1142 aCriterion == SMESH::FT_LyingOnGeom)
1144 if (aTable->text(i, 2).isEmpty())
1145 errMsg = tr( "ERROR" );
1149 bool isSignalsBlocked = aTable->signalsBlocked();
1150 aTable->blockSignals(true);
1151 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1152 aTable->blockSignals(isSignalsBlocked);
1154 if (!aRes && aTable->isEditable(i, 2))
1155 errMsg = tr( "ERROR" );
1156 else if (aType == SMESH::EDGE &&
1157 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1159 errMsg = tr( "MULTIEDGES_ERROR" );
1162 if (!errMsg.isEmpty()) {
1164 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1168 QTableWidgetItem* anItem = aTable->item(i, 0);
1169 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1176 //=======================================================================
1177 // name : SMESHGUI_FilterTable::SetValidity
1178 // Purpose : Set validity of the table
1179 //=======================================================================
1180 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1182 myIsValid = isValid;
1185 //=======================================================================
1186 // name : SMESHGUI_FilterTable::GetType
1187 // Purpose : Get current entity type
1188 //=======================================================================
1189 int SMESHGUI_FilterTable::GetType() const
1191 return myEntityType;
1194 //=======================================================================
1195 // name : SMESHGUI_FilterTable::SetType
1196 // Purpose : Set current entity type
1197 //=======================================================================
1198 void SMESHGUI_FilterTable::SetType (const int type)
1200 myEntityTypeGrp->button(type)->setChecked(true);
1204 //=======================================================================
1205 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1206 // Purpose : Restore previous entity type
1207 //=======================================================================
1208 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1210 SetType(myEntityType);
1213 //=======================================================================
1214 // name : SMESHGUI_FilterTable::GetCriterionType
1215 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1216 //=======================================================================
1217 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1219 int aType = theType == -1 ? GetType() : theType;
1220 Table* aTable = myTables[ aType ];
1221 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1222 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1225 //=======================================================================
1226 // name : SMESHGUI_FilterTable::GetCriterion
1227 // Purpose : Get parameters of criterion from specified row
1228 //=======================================================================
1229 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1230 SMESH::Filter::Criterion& theCriterion,
1231 const int theEntityType) const
1233 int aType = theEntityType == -1 ? GetType() : theEntityType;
1234 Table* aTable = myTables[ aType ];
1236 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1237 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1238 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1239 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1240 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1242 int aCriterionType = GetCriterionType(theRow, aType);
1244 if ( aCriterionType == SMESH::FT_GroupColor )
1246 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1249 const QColor qClr = clrBtn->color();
1250 QString clrStr = QString( "%1;%2;%3" ).
1251 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1252 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1255 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1256 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1257 else if ( aCriterionType == SMESH::FT_EntityType )
1258 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1259 else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1260 theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1261 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1262 aCriterionType != SMESH::FT_BelongToGeom &&
1263 aCriterionType != SMESH::FT_BelongToPlane &&
1264 aCriterionType != SMESH::FT_BelongToCylinder &&
1265 aCriterionType != SMESH::FT_BelongToGenSurface &&
1266 aCriterionType != SMESH::FT_LyingOnGeom )
1268 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1269 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1273 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1274 if ( aCriterionType != SMESH::FT_RangeOfIds )
1275 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1278 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1279 if (myAddWidgets.contains(anItem))
1280 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1283 //=======================================================================
1284 // name : SMESHGUI_FilterTable::SetCriterion
1285 // Purpose : Set parameters of criterion of specified row
1286 //=======================================================================
1287 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1288 const SMESH::Filter::Criterion& theCriterion,
1289 const int theEntityType)
1291 int aType = theEntityType == -1 ? GetType() : theEntityType;
1293 Table* aTable = myTables[ aType ];
1295 if (theRow > aTable->rowCount() - 1)
1298 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1299 onCriterionChanged(theRow, 0, aType);
1300 if ( theCriterion.Compare == SMESH::FT_Undefined )
1301 ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
1303 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1304 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1306 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1308 if (!aTable->isEditable(theRow, 4))
1309 aTable->setItem(theRow, 4, getBinaryItem());
1310 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1313 aTable->setEditable(false, theRow, 4);
1315 if (theCriterion.Type == SMESH::FT_GroupColor )
1317 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1321 QString clrStr( theCriterion.ThresholdStr );
1322 QStringList clrVals = clrStr.split( ";" );
1323 if ( clrVals.count() > 2 )
1324 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1325 (int)256*clrVals[1].toDouble(),
1326 (int)256*clrVals[2].toDouble() );
1327 clrBtn->setColor( qClr );
1330 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1332 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1333 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1335 else if (theCriterion.Type == SMESH::FT_EntityType )
1337 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1338 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1340 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1342 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1344 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1345 theCriterion.Type != SMESH::FT_BelongToGeom &&
1346 theCriterion.Type != SMESH::FT_BelongToPlane &&
1347 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1348 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1349 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1350 theCriterion.Type != SMESH::FT_CoplanarFaces &&
1351 theCriterion.Type != SMESH::FT_FreeBorders &&
1352 theCriterion.Type != SMESH::FT_FreeEdges &&
1353 theCriterion.Type != SMESH::FT_FreeNodes &&
1354 theCriterion.Type != SMESH::FT_FreeFaces &&
1355 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1356 theCriterion.Type != SMESH::FT_BareBorderFace &&
1357 theCriterion.Type != SMESH::FT_BareBorderVolume &&
1358 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1359 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1360 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1362 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1366 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1367 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1368 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1371 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1372 theCriterion.Type == SMESH::FT_BelongToPlane ||
1373 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1374 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1375 theCriterion.Type == SMESH::FT_BelongToGeom ||
1376 theCriterion.Type == SMESH::FT_LyingOnGeom ||
1377 theCriterion.Type == SMESH::FT_CoplanarFaces ||
1378 theCriterion.Type == SMESH::FT_EqualNodes)
1380 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1381 if (!myAddWidgets.contains(anItem))
1383 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1384 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1385 myWgStack->addWidget(myAddWidgets[ anItem ]);
1387 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1390 emit CriterionChanged(theRow, aType);
1393 //=======================================================================
1394 // name : SMESHGUI_FilterTable::Update
1395 // Purpose : Update table
1396 //=======================================================================
1397 void SMESHGUI_FilterTable::Update()
1399 Table* aTable = myTables[ GetType() ];
1400 int aCurrRow = aTable->currentRow();
1401 int numRows = aTable->rowCount();
1402 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1403 aTable->setCurrentCell(0, 0);
1404 updateAdditionalWidget();
1407 //=======================================================================
1408 // name : SMESHGUI_FilterTable::AddCriterion
1409 // Purpose : Add criterion with parameters
1410 //=======================================================================
1411 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1412 const int theEntityType)
1414 int aType = theEntityType == -1 ? GetType() : theEntityType;
1415 Table* aTable = myTables[ aType ];
1416 addRow(aTable, aType);
1417 SetCriterion(aTable->rowCount() - 1, theCriterion);
1420 //=======================================================================
1421 // name : SMESHGUI_FilterTable::NumRows
1422 // Purpose : Get number of criterions of current type
1423 //=======================================================================
1424 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1426 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1429 //=======================================================================
1430 // name : SMESHGUI_FilterTable::Clear
1431 // Purpose : Clear current table
1432 //=======================================================================
1433 void SMESHGUI_FilterTable::Clear (const int theType)
1435 int aType = theType == -1 ? GetType() : theType;
1436 Table* aTable = myTables[ aType ];
1438 if (aTable->rowCount() == 0)
1441 while (aTable->rowCount() > 0)
1443 removeAdditionalWidget(aTable, 0);
1444 aTable->removeRow(0);
1450 //=======================================================================
1451 // name : SMESHGUI_FilterTable::onAddBtn
1452 // Purpose : SLOT. Called then "Add" button pressed.
1453 // Adds new string to table
1454 //=======================================================================
1455 void SMESHGUI_FilterTable::onAddBtn()
1457 int aType = GetType();
1458 addRow(myTables[ aType ], aType);
1463 //=======================================================================
1464 // name : SMESHGUI_FilterTable::onInsertBtn
1465 // Purpose : SLOT. Called then "Insert" button pressed.
1466 // Inserts new string before current one
1467 //=======================================================================
1468 void SMESHGUI_FilterTable::onInsertBtn()
1470 addRow(myTables[ GetType() ], GetType(), false);
1473 //=======================================================================
1474 // name : SMESHGUI_FilterTable::onRemoveBtn
1475 // Purpose : SLOT. Called then "Remove" button pressed.
1476 // Removes current string from table
1477 //=======================================================================
1478 void SMESHGUI_FilterTable::onRemoveBtn()
1480 Table* aTable = myTables[ GetType() ];
1482 if (aTable->rowCount() == 0)
1485 QList<QTableWidgetItem*> items = aTable->selectedItems();
1487 QList<int> aRows = aTable->selectedRows(); // already sorted
1491 removeAdditionalWidget(aTable, i);
1492 aTable->removeRow(i);
1495 // remove control of binary logical operation from last row
1496 if (aTable->rowCount() > 0)
1497 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1502 //=======================================================================
1503 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1504 // Purpose : Enable/Disable widget with additonal parameters
1505 //=======================================================================
1506 void SMESHGUI_FilterTable::updateAdditionalWidget()
1508 Table* aTable = myTables[ GetType() ];
1509 int aRow = aTable->currentRow();
1510 if (aRow < 0 || aRow >= aTable->rowCount())
1512 myWgStack->setEnabled(false);
1516 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1517 int aCriterion = GetCriterionType(aRow);
1518 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1519 aCriterion != SMESH::FT_RangeOfIds &&
1520 aCriterion != SMESH::FT_FreeEdges &&
1521 aCriterion != SMESH::FT_FreeFaces &&
1522 aCriterion != SMESH::FT_BadOrientedVolume &&
1523 aCriterion != SMESH::FT_BareBorderFace &&
1524 aCriterion != SMESH::FT_BareBorderVolume &&
1525 aCriterion != SMESH::FT_OverConstrainedFace &&
1526 aCriterion != SMESH::FT_OverConstrainedVolume)
1528 aCriterion == SMESH::FT_CoplanarFaces);
1530 if (!myAddWidgets.contains(anItem))
1532 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1533 myWgStack->addWidget(myAddWidgets[ anItem ]);
1536 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1537 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1538 myWgStack->setEnabled(toEnable);
1541 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1543 const char* retval = 0;
1545 case SMESH::FT_AspectRatio:
1546 case SMESH::FT_AspectRatio3D:
1547 case SMESH::FT_Taper:
1548 retval = "parametric_precision"; break;
1549 case SMESH::FT_Warping:
1550 case SMESH::FT_MinimumAngle:
1551 case SMESH::FT_Skew:
1552 case SMESH::FT_CoplanarFaces:
1553 retval = "angle_precision"; break;
1554 case SMESH::FT_Area:
1555 retval = "area_precision"; break;
1556 case SMESH::FT_BelongToGeom:
1557 case SMESH::FT_BelongToPlane:
1558 case SMESH::FT_BelongToCylinder:
1559 case SMESH::FT_BelongToGenSurface:
1560 case SMESH::FT_LyingOnGeom:
1561 case SMESH::FT_EqualNodes:
1562 retval = "len_tol_precision"; break;
1563 case SMESH::FT_Length:
1564 case SMESH::FT_Length2D:
1565 case SMESH::FT_MaxElementLength2D:
1566 case SMESH::FT_MaxElementLength3D:
1567 retval = "length_precision"; break;
1568 case SMESH::FT_Volume3D:
1569 retval = "vol_precision"; break;
1576 //=======================================================================
1577 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1578 // Purpose : Remove widgets containing additional parameters from widget
1579 // stack and internal map
1580 //=======================================================================
1581 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1583 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1584 if (myAddWidgets.contains(anItem))
1586 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1587 myAddWidgets[ anItem ]->setParent(0);
1588 delete myAddWidgets[ anItem ];
1589 myAddWidgets.remove(anItem);
1593 //=======================================================================
1594 // name : SMESHGUI_FilterTable::onClearBtn
1595 // Purpose : SLOT. Called then "Clear" button pressed.
1596 // Removes all strings from table
1597 //=======================================================================
1598 void SMESHGUI_FilterTable::onClearBtn()
1600 Table* aTable = myTables[ GetType() ];
1602 if (aTable->rowCount() == 0)
1605 while (aTable->rowCount() > 0)
1607 removeAdditionalWidget(aTable, 0);
1608 aTable->removeRow(0);
1614 //=======================================================================
1615 // name : SMESHGUI_FilterTable::onCurrentChanged()
1616 // Purpose : SLOT. Called when current cell changed
1617 //=======================================================================
1618 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1621 updateAdditionalWidget();
1622 emit CurrentChanged(theRow, theCol);
1625 //=======================================================================
1627 // Purpose : returns available geometry types of elements
1628 //=======================================================================
1629 static QList<int> geomTypes( const int theType )
1632 if ( theType == SMESH::NODE )
1633 typeIds.append( SMESH::Geom_POINT );
1634 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1635 typeIds.append( SMESH::Geom_EDGE );
1636 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1638 typeIds.append( SMESH::Geom_TRIANGLE );
1639 typeIds.append( SMESH::Geom_QUADRANGLE );
1640 typeIds.append( SMESH::Geom_POLYGON );
1642 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1644 typeIds.append( SMESH::Geom_TETRA );
1645 typeIds.append( SMESH::Geom_PYRAMID );
1646 typeIds.append( SMESH::Geom_HEXA );
1647 typeIds.append( SMESH::Geom_PENTA );
1648 typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1649 typeIds.append( SMESH::Geom_POLYHEDRA );
1651 if ( theType == SMESH::ALL || theType == SMESH::ELEM0D )
1653 typeIds.append( SMESH::Geom_POINT );
1655 if ( theType == SMESH::ALL || theType == SMESH::BALL )
1657 typeIds.append( SMESH::Geom_BALL );
1662 //=======================================================================
1663 // name : entityTypes
1664 // Purpose : returns available entity types of elements
1665 //=======================================================================
1667 static QList<int> entityTypes( const int theType )
1671 if ( theType == SMESH::EDGE )
1673 typeIds.append( SMDSEntity_Edge );
1674 typeIds.append( SMDSEntity_Quad_Edge );
1676 if ( theType == SMESH::FACE )
1678 typeIds.append( SMDSEntity_Quadrangle );
1679 typeIds.append( SMDSEntity_Quad_Quadrangle );
1680 typeIds.append( SMDSEntity_BiQuad_Quadrangle );
1682 if ( theType == SMESH::VOLUME )
1684 typeIds.append( SMDSEntity_Hexa );
1685 typeIds.append( SMDSEntity_Quad_Hexa );
1686 typeIds.append( SMDSEntity_TriQuad_Hexa );
1691 //=======================================================================
1692 // name : SMESHGUI_FilterTable::onCriterionChanged()
1693 // Purpose : Provides reaction on change of criterion
1694 //=======================================================================
1696 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1698 int aType = entityType == -1 ? GetType() : entityType;
1699 Table* aTable = myTables[ aType ];
1700 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1702 int aCriterionType = GetCriterionType(row);
1703 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1704 int aComboType = ComboItem::Type();
1705 int aIntSpinType = IntSpinItem::Type();
1706 int aDoubleSpinType = DoubleSpinItem::Type();
1707 QTableWidgetItem* aTableItem = aTable->item(row, 2);
1708 bool isComboItem = false;
1709 bool isIntSpinItem = false;
1710 bool isDoubleSpinItem = false;
1712 int aTableType = aTable->item(row, 2)->type();
1713 isComboItem = ( aTableType == aComboType );
1714 isIntSpinItem = ( aTableType == aIntSpinType );
1715 isDoubleSpinItem = ( aTableType == aDoubleSpinType );
1718 bool anIsDoubleCriterion =
1719 aCriterionType == SMESH::FT_AspectRatio ||
1720 aCriterionType == SMESH::FT_AspectRatio3D ||
1721 aCriterionType == SMESH::FT_Taper ||
1722 aCriterionType == SMESH::FT_Warping ||
1723 aCriterionType == SMESH::FT_MinimumAngle ||
1724 aCriterionType == SMESH::FT_Skew ||
1725 aCriterionType == SMESH::FT_Area ||
1726 aCriterionType == SMESH::FT_Length ||
1727 aCriterionType == SMESH::FT_Length2D ||
1728 aCriterionType == SMESH::FT_MaxElementLength2D ||
1729 aCriterionType == SMESH::FT_MaxElementLength3D ||
1730 aCriterionType == SMESH::FT_Volume3D ||
1731 aCriterionType == SMESH::FT_EntityType;
1733 if ( anIsDoubleCriterion ) {
1734 const char* aPrecisionType = getPrecision( aCriterionType );
1735 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1736 if( aPrecisionType && aResourceMgr )
1737 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1740 // if the precision is to be changed we should remove the existing
1741 // spin item and create another one with new precision
1742 bool anIsPrecisionChanged = false;
1743 if ( anIsDoubleCriterion && isDoubleSpinItem ) {
1744 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
1745 anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
1749 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1750 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
1751 (aCriterionType != SMESH::FT_EntityType && isComboItem) ||
1752 (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
1753 (!anIsDoubleCriterion && isDoubleSpinItem) ||
1754 anIsPrecisionChanged )
1756 bool isSignalsBlocked = aTable->signalsBlocked();
1757 aTable->blockSignals( true );
1758 aTable->removeCellWidget( row, 2 );
1759 aTable->setItem( row, 2, new QTableWidgetItem() );
1760 aTable->blockSignals( isSignalsBlocked );
1762 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1763 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
1764 (aCriterionType == SMESH::FT_EntityType && !isComboItem) ||
1765 (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
1766 (anIsDoubleCriterion && !isDoubleSpinItem) ||
1767 anIsPrecisionChanged )
1769 bool isSignalsBlocked = aTable->signalsBlocked();
1770 aTable->blockSignals( true );
1771 if ( aCriterionType == SMESH::FT_GroupColor )
1772 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1773 else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
1774 QList<int> typeIds = geomTypes( aType );
1775 QMap<int, QString> typeNames;
1776 QList<int>::const_iterator anIter = typeIds.begin();
1777 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1779 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1780 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1782 ComboItem* typeBox = new ComboItem( typeNames );
1783 aTable->setItem( row, 2, typeBox );
1785 else if ( aCriterionType == SMESH::FT_EntityType ) {
1786 QList<int> typeIds = entityTypes( aType );
1787 QMap<int, QString> typeNames;
1788 QList<int>::const_iterator anIter = typeIds.begin();
1789 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1791 QString typeKey = QString( "ENTITY_TYPE_%1" ).arg( *anIter );
1792 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1794 ComboItem* typeBox = new ComboItem( typeNames );
1795 aTable->setItem( row, 2, typeBox );
1797 else if ( aCriterionType == SMESH::FT_MultiConnection ) {
1798 IntSpinItem* intSpin = new IntSpinItem( 0 );
1799 aTable->setItem( row, 2, intSpin );
1801 else if ( anIsDoubleCriterion ) {
1802 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1803 dblSpin->setPrecision( aPrecision );
1804 aTable->setItem( row, 2, dblSpin );
1806 aTable->blockSignals( isSignalsBlocked );
1809 // set Compare and enable/desable Threshold
1810 if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes ||
1811 aCriterionType == SMESH::FT_EqualNodes )) ||
1812 (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders ||
1813 aCriterionType == SMESH::FT_EqualEdges )) ||
1814 (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace ||
1815 aCriterionType == SMESH::FT_OverConstrainedFace ||
1816 aCriterionType == SMESH::FT_FreeEdges ||
1817 aCriterionType == SMESH::FT_FreeFaces ||
1818 aCriterionType == SMESH::FT_EqualFaces)) ||
1819 (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume ||
1820 aCriterionType == SMESH::FT_OverConstrainedVolume ||
1821 aCriterionType == SMESH::FT_BareBorderVolume ||
1822 aCriterionType == SMESH::FT_EqualVolumes )) ||
1823 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1824 aCriterionType == SMESH::FT_GroupColor ||
1825 aCriterionType == SMESH::FT_ElemGeomType ||
1826 aCriterionType == SMESH::FT_CoplanarFaces ||
1827 aCriterionType == SMESH::FT_EntityType
1830 bool isSignalsBlocked = aTable->signalsBlocked();
1831 aTable->blockSignals( true );
1833 if (aCompareItem->count() > 0)
1834 aCompareItem->clear();
1835 aTable->setEditable(false, row, 1);
1836 aTable->item(row, 2)->setText( QString("") );
1837 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1838 aCriterionType == SMESH::FT_ElemGeomType ||
1839 aCriterionType == SMESH::FT_EntityType ||
1840 aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
1841 aTable->blockSignals( isSignalsBlocked );
1843 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1844 aCriterionType == SMESH::FT_BelongToGeom ||
1845 aCriterionType == SMESH::FT_BelongToPlane ||
1846 aCriterionType == SMESH::FT_BelongToCylinder ||
1847 aCriterionType == SMESH::FT_BelongToGenSurface ||
1848 aCriterionType == SMESH::FT_LyingOnGeom)
1850 QMap<int, QString> aMap;
1851 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1852 aCompareItem->setItems(aMap);
1853 if (!aTable->isEditable(row, 2))
1854 aTable->setEditable(true, row, 1);
1855 if (!aTable->isEditable(row, 2))
1856 aTable->setEditable(true, row, 2);
1858 else if (aCriterionType == SMESH::FT_GroupColor ||
1859 aCriterionType == SMESH::FT_ElemGeomType ||
1860 aCriterionType == SMESH::FT_EntityType)
1862 if (!aTable->isEditable(row, 2))
1863 aTable->setEditable(true, row, 2);
1867 if (aCompareItem && aCompareItem->count() != 3)
1869 aCompareItem->setItems(getCompare());
1872 if (aTable->item( row, 2 )) {
1873 QString aText = aTable->text(row, 2);
1875 aText.toDouble(&isOk);
1876 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1877 if (!aTable->isEditable(row, 1))
1878 aTable->setEditable(true, row, 1);
1879 if (!aTable->isEditable(row, 2))
1880 aTable->setEditable(true, row, 2);
1884 updateAdditionalWidget();
1886 emit CriterionChanged(row, entityType);
1889 //=======================================================================
1890 // name : SMESHGUI_FilterTable::onCriterionChanged()
1891 // Purpose : SLOT. Called then contents of table changed
1892 // Provides reaction on change of criterion
1893 //=======================================================================
1894 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1897 onCriterionChanged(row, col, -1);
1900 //=======================================================================
1901 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1902 // Purpose : Get first selected row
1903 //=======================================================================
1904 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1906 Table* aTable = myTables[ GetType() ];
1908 QList<int> selRows = aTable->selectedRows(); // already sorted
1909 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1911 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1914 //=======================================================================
1915 // name : SMESHGUI_FilterTable::addRow
1916 // Purpose : Add row at the end of table
1917 //=======================================================================
1918 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1921 int aSelectedRow = getFirstSelectedRow();
1922 int aCurrCol = theTable->currentColumn();
1925 if (toTheEnd || aSelectedRow == -1)
1927 theTable->insertRows(theTable->rowCount());
1928 aCurrRow = theTable->rowCount() - 1;
1932 theTable->insertRows(aSelectedRow);
1933 aCurrRow = aSelectedRow;
1937 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1938 bool isSignalsBlocked = theTable->signalsBlocked();
1939 theTable->blockSignals( true );
1942 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1945 theTable->setItem(aCurrRow, 1, getCompareItem());
1948 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1950 // Logical operation NOT
1951 theTable->setItem(aCurrRow, 3, getUnaryItem());
1953 // Logical operation AND / OR
1954 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1956 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1958 theTable->blockSignals( isSignalsBlocked );
1960 // Logical binary operation for previous value
1961 int anAddBinOpStr = -1;
1962 if (aCurrRow == theTable->rowCount() - 1)
1963 anAddBinOpStr = aCurrRow - 1;
1964 else if (aCurrRow >= 0 )
1965 anAddBinOpStr = aCurrRow;
1967 if (theTable->item(aCurrRow, 4) == 0 ||
1968 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1970 if (anAddBinOpStr >= 0 &&
1971 (theTable->item(anAddBinOpStr, 4) == 0 ||
1972 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1973 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1976 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1978 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1979 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1980 theTable->setCurrentCell(aCurrRow, aCurrCol);
1982 onCriterionChanged(aCurrRow, 0);
1987 //=======================================================================
1988 // name : SMESHGUI_FilterTable::getCriterionItem
1989 // Purpose : Get combo table item for criteria of specified type
1990 //=======================================================================
1991 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1993 return new ComboItem(getCriteria(theType));
1996 //=======================================================================
1997 // name : SMESHGUI_FilterTable::getCompareItem
1998 // Purpose : Get combo table item for operation of comparision
1999 //=======================================================================
2000 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
2002 return new ComboItem(getCompare());
2005 //=======================================================================
2006 // name : SMESHGUI_FilterTable::getBinaryItem
2008 //=======================================================================
2009 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
2011 static QMap<int, QString> aMap;
2014 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
2015 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
2018 return new ComboItem(aMap);
2021 //=======================================================================
2022 // name : SMESHGUI_FilterTable::getUnaryItem
2023 // Purpose : Get check table item
2024 //=======================================================================
2025 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
2027 return new CheckItem(tr("NOT"));
2030 //=======================================================================
2031 // name : SMESHGUI_FilterTable::getSupportedTypes
2032 // Purpose : Get all supported type
2033 //=======================================================================
2034 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
2036 static QMap<int, QString> aTypes;
2037 if (aTypes.isEmpty())
2039 aTypes[ SMESH::NODE ] = tr("NODES");
2040 aTypes[ SMESH::ELEM0D ] = tr("ELEM0D");
2041 aTypes[ SMESH::BALL ] = tr("BALLS");
2042 aTypes[ SMESH::EDGE ] = tr("EDGES");
2043 aTypes[ SMESH::FACE ] = tr("FACES");
2044 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
2045 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
2051 //=======================================================================
2052 // name : SMESHGUI_FilterTable::getCriteria
2053 // Purpose : Get criteria for specified type
2054 //=======================================================================
2055 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
2057 if (theType == SMESH::NODE)
2059 static QMap<int, QString> aCriteria;
2060 if (aCriteria.isEmpty())
2062 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2063 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2064 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2065 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2066 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2067 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2068 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
2069 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2070 aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
2074 else if (theType == SMESH::EDGE)
2076 static QMap<int, QString> aCriteria;
2077 if (aCriteria.isEmpty())
2079 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
2080 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
2081 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
2082 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2083 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2084 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2085 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2086 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2087 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2088 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2089 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2090 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2091 aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
2092 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2096 else if (theType == SMESH::FACE)
2098 static QMap<int, QString> aCriteria;
2099 if (aCriteria.isEmpty())
2101 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
2102 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
2103 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
2104 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
2105 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
2106 aCriteria[ SMESH::FT_Area ] = tr("AREA");
2107 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2108 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
2109 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2110 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2111 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2112 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2113 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2114 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2115 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
2116 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
2117 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
2118 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
2119 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2120 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2121 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2122 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2123 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
2124 aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
2125 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2129 else if (theType == SMESH::VOLUME)
2131 static QMap<int, QString> aCriteria;
2132 if (aCriteria.isEmpty())
2134 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
2135 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2136 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2137 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2138 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
2139 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
2140 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2141 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
2142 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
2143 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2144 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2145 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2146 aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
2147 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2151 else if (theType == SMESH::ELEM0D)
2153 static QMap<int, QString> aCriteria;
2154 if (aCriteria.isEmpty())
2156 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2157 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2158 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2159 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2160 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2161 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2165 else if (theType == SMESH::BALL)
2167 static QMap<int, QString> aCriteria;
2168 if (aCriteria.isEmpty())
2170 aCriteria[ SMESH::FT_BallDiameter ] = tr("BALL_DIAMETER");
2171 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2172 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2173 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2174 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2175 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2176 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2180 else if (theType == SMESH::ELEM0D)
2182 static QMap<int, QString> aCriteria;
2183 if (aCriteria.isEmpty())
2185 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2186 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2187 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2188 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2189 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2190 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2196 static QMap<int, QString> aCriteria;
2197 if (aCriteria.isEmpty())
2199 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2200 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2201 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2202 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2203 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2204 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2212 //=======================================================================
2213 // name : SMESHGUI_FilterTable::getCompare
2214 // Purpose : Get operation of comparison
2215 //=======================================================================
2216 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2218 static QMap<int, QString> aMap;
2222 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2223 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2224 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
2230 //=======================================================================
2231 // name : SMESHGUI_FilterTable::createTable
2232 // Purpose : Create table
2233 //=======================================================================
2234 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
2238 Table* aTable= new Table(0, 6, theParent);
2240 QHeaderView* aHeaders = aTable->horizontalHeader();
2242 QFontMetrics aMetrics(aHeaders->font());
2244 // append spaces to the header of criteria in order to
2245 // provide visibility of criterion inside comboboxes
2246 static int aMaxLenCr = 0;
2250 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2251 QMap<int, QString>::const_iterator anIter;
2252 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2253 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2256 static int aLenCr = qAbs( aMaxLenCr -
2257 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2260 aCrStr.fill(' ', aLenCr);
2262 aCoStr.fill(' ', 10);
2264 QStringList aHeaderLabels;
2265 aHeaderLabels.append( tr("CRITERION") + aCrStr );
2266 aHeaderLabels.append( tr("COMPARE") + aCoStr );
2267 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2268 aHeaderLabels.append( tr("UNARY") );
2269 aHeaderLabels.append( tr("BINARY") + " " );
2270 aHeaderLabels.append( tr("ID") );
2271 aTable->setHorizontalHeaderLabels( aHeaderLabels );
2273 // set geometry of the table
2274 for (int i = 0; i <= 4; i++)
2275 aTable->resizeColumnToContents(i);
2277 // set the ID column invisible
2278 aTable->hideColumn( 5 );
2280 aTable->updateGeometry();
2281 QSize aSize = aTable->sizeHint();
2282 int aWidth = aSize.width();
2283 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2284 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2286 connect(aTable, SIGNAL(cellChanged(int, int)),
2287 this, SLOT(onCriterionChanged(int, int)));
2289 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2290 this, SLOT(onCurrentChanged(int, int)));
2295 //=======================================================================
2296 // name : SMESHGUI_FilterTable::updateBtnState
2297 // Purpose : Update button state
2298 //=======================================================================
2299 void SMESHGUI_FilterTable::updateBtnState()
2301 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2302 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2305 //=======================================================================
2306 // name : SMESHGUI_FilterTable::SetEditable
2307 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2308 //=======================================================================
2309 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2311 TableMap::iterator anIter;
2312 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2314 anIter.value()->setReadOnly(!isEditable);
2316 // Set Flags for CheckItems directly IPAL 19974
2317 Table* aTable = anIter.value();
2318 for (int i = 0, n = aTable->rowCount(); i < n; i++)
2319 for (int j = 0, m = aTable->columnCount(); j < m; j++)
2321 QTableWidgetItem* anItem = aTable->item(i, j);
2322 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2323 Qt::ItemFlags f = anItem->flags();
2324 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2325 else f = f | Qt::ItemIsUserCheckable;
2326 anItem->setFlags( f );
2334 myInsertBtn->show();
2335 myRemoveBtn->show();
2341 myInsertBtn->hide();
2342 myRemoveBtn->hide();
2347 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2348 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2349 anIter2.value()->SetEditable(isEditable);
2352 //=======================================================================
2353 // name : SMESHGUI_FilterTable::SetEnabled
2354 // Purpose : Enable/Disable table. Switching type of elements already enabled
2355 //=======================================================================
2356 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2358 myAddBtn->setEnabled(isEnabled);
2359 myInsertBtn->setEnabled(isEnabled);
2360 myRemoveBtn->setEnabled(isEnabled);
2361 myClearBtn->setEnabled(isEnabled);
2366 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2367 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2368 anIter2.value()->setEnabled(isEnabled);
2371 //=======================================================================
2372 // name : SMESHGUI_FilterTable::IsEditable
2373 // Purpose : Verify whether table is editable
2374 //=======================================================================
2375 bool SMESHGUI_FilterTable::IsEditable() const
2377 return !myTables[ GetType() ]->isReadOnly();
2380 //=======================================================================
2381 // name : SMESHGUI_FilterTable::SetLibsEnabled
2382 // Purpose : Show/hide buttons for work with libraries
2383 //=======================================================================
2384 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2388 myCopyFromBtn->show();
2393 myCopyFromBtn->hide();
2398 //=======================================================================
2399 // name : SMESHGUI_FilterTable::onCopyFromBtn
2400 // Purpose : SLOT. Called the "Copy from ..." button clicked
2401 // Display filter library dialog
2402 //=======================================================================
2403 void SMESHGUI_FilterTable::onCopyFromBtn()
2406 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2407 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2409 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2411 if (myLibDlg->exec() == QDialog::Accepted)
2413 Copy(myLibDlg->GetTable());
2418 //=======================================================================
2419 // name : SMESHGUI_FilterTable::onAddToBtn
2420 // Purpose : SLOT. Called the "Add to ..." button clicked
2421 // Display filter library dialog
2422 //=======================================================================
2423 void SMESHGUI_FilterTable::onAddToBtn()
2428 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2429 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2431 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2433 myLibDlg->SetTable(this);
2438 //=======================================================================
2439 // name : SMESHGUI_FilterTable::Copy
2440 // Purpose : Initialise table with values of other table
2441 //=======================================================================
2442 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2446 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2448 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2449 theTable->GetCriterion(i, aCriterion);
2450 AddCriterion(aCriterion);
2454 //=======================================================================
2455 // name : SMESHGUI_FilterTable::CurrentCell
2456 // Purpose : Returns current cell
2457 //=======================================================================
2458 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2460 theRow = myTables[ GetType() ]->currentRow();
2461 theCol = myTables[ GetType() ]->currentColumn();
2462 return theRow >= 0 && theCol >= 0;
2465 //=======================================================================
2466 // name : SMESHGUI_FilterTable::SetText
2467 // Purpose : Set text and internal value in cell of threshold value
2468 //=======================================================================
2469 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2470 const QString& theText,
2471 const int theEntityType)
2473 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2474 aTable->item( theRow, 2 )->setText(theText);
2477 //=======================================================================
2478 // name : SMESHGUI_FilterTable::SetText
2479 // Purpose : Get text and internal value from cell of threshold value
2480 //=======================================================================
2481 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2483 const int theEntityType)
2485 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2486 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2489 theText = anItem->text();
2496 //=======================================================================
2497 // name : SMESHGUI_FilterTable::SetID
2498 // Purpose : Set text and internal value in cell of ID value
2499 //=======================================================================
2500 void SMESHGUI_FilterTable::SetID( const int theRow,
2501 const QString& theText,
2502 const int theEntityType )
2504 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2505 aTable->item( theRow, 5 )->setText( theText );
2508 //=======================================================================
2509 // name : SMESHGUI_FilterTable::GetID
2510 // Purpose : Get text and internal value from cell of ID value
2511 //=======================================================================
2512 bool SMESHGUI_FilterTable::GetID( const int theRow,
2514 const int theEntityType )
2516 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2517 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2520 theText = anItem->text();
2528 Class : SMESHGUI_FilterDlg
2529 Description : Dialog to specify filters for VTK viewer
2533 //=======================================================================
2534 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2535 // Purpose : Constructor
2536 //=======================================================================
2537 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2538 const QList<int>& theTypes )
2539 : QDialog( SMESH::GetDesktop( theModule ) ),
2540 mySMESHGUI( theModule ),
2541 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2542 myInitSourceWgOnApply( true )
2544 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2545 mySelector = aViewWindow->GetSelector();
2547 construct(theTypes);
2550 //=======================================================================
2551 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2552 // Purpose : Constructor
2553 //=======================================================================
2554 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2556 : QDialog( SMESH::GetDesktop( theModule ) ),
2557 mySMESHGUI( theModule ),
2558 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2559 myInitSourceWgOnApply( true )
2561 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2562 mySelector = aViewWindow->GetSelector();
2564 aTypes.append(theType);
2568 //=======================================================================
2569 // name : SMESHGUI_FilterDlg::construct
2570 // Purpose : Construct dialog (called by constructor)
2571 //=======================================================================
2572 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2577 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2578 setWindowTitle(tr("CAPTION"));
2580 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2581 aDlgLay->setMargin(MARGIN);
2582 aDlgLay->setSpacing(SPACING);
2584 myMainFrame = createMainFrame (this);
2585 QWidget* aBtnFrame = createButtonFrame(this);
2587 aDlgLay->addWidget(myMainFrame);
2588 aDlgLay->addWidget(aBtnFrame);
2590 aDlgLay->setStretchFactor(myMainFrame, 1);
2592 myHelpFileName = "selection_filter_library_page.html";
2597 //=======================================================================
2598 // name : SMESHGUI_FilterDlg::createMainFrame
2599 // Purpose : Create frame containing dialog's input fields
2600 //=======================================================================
2601 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2603 QWidget* aMainFrame = new QWidget(theParent);
2604 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2605 aMainLay->setMargin(0);
2606 aMainLay->setSpacing(SPACING);
2610 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2611 myTable->SetLibsEnabled(true);
2613 QGroupBox* aGrp = myTable->GetTableGrp();
2614 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2615 int rows = aLay->rowCount();
2616 int cols = aLay->columnCount();
2618 QFrame* aLine = new QFrame(aGrp);
2619 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2620 aLay->addWidget(aLine, rows++, 0, 1, cols);
2622 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2623 mySetInViewer->setChecked(true);
2624 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2627 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2629 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2630 SLOT(onCriterionChanged(const int, const int)));
2632 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2633 SLOT(onCurrentChanged(int, int)));
2635 aMainLay->addWidget(myTable);
2636 aMainLay->addWidget(aSourceGrp);
2641 //=======================================================================
2642 // name : SMESHGUI_FilterDlg::createSourceFrame
2643 // Purpose : Create frame containing source radio button
2644 //=======================================================================
2645 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2647 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2648 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2649 aLay->setMargin(MARGIN);
2650 aLay->setSpacing(SPACING);
2652 mySourceGrp = new QButtonGroup(theParent);
2654 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2655 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2656 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2658 aLay->addWidget(aMeshBtn);
2659 aLay->addWidget(aSelBtn);
2660 aLay->addWidget(aDlgBtn);
2662 mySourceGrp->addButton(aMeshBtn, Mesh);
2663 mySourceGrp->addButton(aSelBtn, Selection);
2664 mySourceGrp->addButton(aDlgBtn, Dialog);
2666 aMeshBtn->setChecked(true);
2671 //=======================================================================
2672 // name : SMESHGUI_FilterDlg::updateMainButtons
2673 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2674 //=======================================================================
2675 void SMESHGUI_FilterDlg::updateMainButtons()
2677 myButtons[ BTN_Close ]->show();
2678 if (myTypes.count() == 1)
2680 myButtons[ BTN_Apply ]->hide();
2684 myButtons[ BTN_Apply ]->show();
2686 // updateGeometry();
2689 //=======================================================================
2690 // name : SMESHGUI_FilterDlg::createButtonFrame
2691 // Purpose : Create frame containing buttons
2692 //=======================================================================
2693 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2695 QGroupBox* aGrp = new QGroupBox(theParent);
2696 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2697 aLay->setMargin(MARGIN);
2698 aLay->setSpacing(SPACING);
2700 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2701 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2702 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2703 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2705 aLay->addWidget(myButtons[ BTN_OK ]);
2706 aLay->addSpacing(10);
2707 aLay->addWidget(myButtons[ BTN_Apply ]);
2708 aLay->addSpacing(10);
2710 aLay->addWidget(myButtons[ BTN_Close ]);
2711 aLay->addWidget(myButtons[ BTN_Help ]);
2713 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2714 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(reject()));
2715 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2716 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2718 updateMainButtons();
2723 //=======================================================================
2724 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2725 // Purpose : Destructor
2726 //=======================================================================
2727 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2731 //=======================================================================
2732 // name : SMESHGUI_FilterDlg::Init
2733 // Purpose : Init dialog fields, connect signals and slots, show dialog
2734 //=======================================================================
2735 void SMESHGUI_FilterDlg::Init (const int type, const bool setInViewer)
2738 aTypes.append(type);
2739 Init(aTypes,setInViewer);
2742 //=======================================================================
2743 // name : SMESHGUI_FilterDlg::Init
2744 // Purpose : Init dialog fields, connect signals and slots, show dialog
2745 //=======================================================================
2746 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewer)
2750 myMesh = SMESH::SMESH_Mesh::_nil();
2752 myIsSelectionChanged = false;
2754 myTable->Init(theTypes);
2757 if (theTypes.count() == 1)
2759 int aType = theTypes.first();
2760 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2761 else if (aType == SMESH::ELEM0D) setWindowTitle(tr("ELEM0D_TLT"));
2762 else if (aType == SMESH::BALL ) setWindowTitle(tr("BALL_TLT"));
2763 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2764 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2765 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2766 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2769 setWindowTitle(tr("TLT"));
2771 qApp->processEvents();
2776 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2778 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2779 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
2781 updateMainButtons();
2784 // Initialise filter table with values of previous filter
2785 QList<int>::const_iterator anIter;
2786 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2788 myTable->Clear(*anIter);
2789 if (!myFilter[ *anIter ]->_is_nil())
2791 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2792 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2794 for (int i = 0, n = aCriteria->length(); i < n; i++)
2795 myTable->AddCriterion(aCriteria[ i ], *anIter);
2800 if (myInsertState.contains(theTypes.first()))
2801 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2803 mySetInViewer->setChecked(setInViewer);
2805 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2806 myApplyToState[ theTypes.first() ] :
2807 Mesh)->setChecked(true);
2810 //=======================================================================
2811 // name : SMESHGUI_FilterDlg::onOk
2812 // Purpose : SLOT called when "Ok" button pressed.
2813 // Assign filters VTK viewer and close dialog
2814 //=======================================================================
2815 void SMESHGUI_FilterDlg::onOk()
2819 mySelectionMgr->clearFilters();
2820 disconnect(mySMESHGUI, 0, this, 0);
2821 disconnect(mySelectionMgr, 0, this, 0);
2822 mySMESHGUI->ResetState();
2828 //=======================================================================
2829 // name : SMESHGUI_FilterDlg::reject
2830 // Purpose : SLOT called when "Close" button pressed. Close dialog
2831 //=======================================================================
2832 void SMESHGUI_FilterDlg::reject()
2834 // Restore previously selected object
2837 SALOME_ListIO aList;
2838 mySelectionMgr->clearFilters();
2839 mySelectionMgr->clearSelected();
2840 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2841 for ( ; anIter.More(); anIter.Next())
2843 aList.Append(anIter.Key());
2845 TColStd_MapOfInteger aResMap;
2846 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2847 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2848 aResMap.Add(anIndMap(i));
2850 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2851 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2852 aViewWindow->highlight( anIter.Key(), true, true );
2854 mySelectionMgr->setSelectedObjects(aList, false);
2857 disconnect(mySMESHGUI, 0, this, 0);
2858 disconnect(mySelectionMgr, 0, this, 0);
2859 mySMESHGUI->ResetState();
2863 //=================================================================================
2864 // function : onHelp()
2866 //=================================================================================
2867 void SMESHGUI_FilterDlg::onHelp()
2869 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2871 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2875 platform = "winapplication";
2877 platform = "application";
2879 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2880 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2881 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2883 arg(myHelpFileName));
2887 //=======================================================================
2888 // name : SMESHGUI_FilterDlg::onDeactivate
2889 // Purpose : SLOT called when dialog must be deativated
2890 //=======================================================================
2891 void SMESHGUI_FilterDlg::onDeactivate()
2896 //=======================================================================
2897 // name : SMESHGUI_FilterDlg::enterEvent
2898 // Purpose : Event filter
2899 //=======================================================================
2900 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2902 // mySMESHGUI->EmitSignalDeactivateDialog();
2903 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2904 mySMESHGUI->ResetState();
2908 //=======================================================================
2909 // name : SMESHGUI_FilterDlg::getIdsFromWg
2910 // Purpose : Retrieve list of ids from given widget
2911 //=======================================================================
2912 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2918 if (theWg->inherits("QListWidget"))
2920 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2922 for (int i = 0, n = aListBox->count(); i < n; i++)
2924 int anId = aListBox->item(i)->text().toInt(&b);
2926 theRes.append(anId);
2929 else if (theWg->inherits("QLineEdit"))
2931 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2932 QString aStr = aLineEdit->text();
2933 QRegExp aRegExp("(\\d+)");
2938 aPos = aRegExp.indexIn(aStr, aPos);
2941 int anId = aRegExp.cap(1).toInt(&b);
2943 theRes.append(anId);
2944 aPos += aRegExp.matchedLength();
2950 //=======================================================================
2951 // name : SMESHGUI_FilterDlg::getSelMode
2952 // Purpose : Get selection mode of specified type
2953 //=======================================================================
2954 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2958 case SMESH::NODE : return NodeSelection;
2959 case SMESH::ELEM0D : return Elem0DSelection;
2960 case SMESH::BALL : return BallSelection;
2961 case SMESH::EDGE : return EdgeSelection;
2962 case SMESH::FACE : return FaceSelection;
2963 case SMESH::VOLUME : return VolumeSelection;
2964 case SMESH::ALL : return CellSelection;
2965 default : return ActorSelection;
2970 //=======================================================================
2971 // name : SMESHGUI_FilterDlg::setIdsToWg
2972 // Purpose : Insert identifiers in specified widgets
2973 //=======================================================================
2974 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2979 QStringList aStrList;
2980 foreach(int id, theIds)
2981 aStrList << QString::number(id);
2983 if (theWg->inherits("QListWidget"))
2985 qobject_cast<QListWidget*>(theWg)->clear();
2986 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2988 else if (theWg->inherits("QLineEdit"))
2990 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2994 //=======================================================================
2995 // name : SMESHGUI_FilterDlg::isValid
2996 // Purpose : Verify validity of input data
2997 //=======================================================================
2998 bool SMESHGUI_FilterDlg::isValid() const
3000 if (!myTable->IsValid())
3003 for (int i = 0, n = myTable->NumRows(); i < n; i++)
3005 int aType = myTable->GetCriterionType(i);
3006 if (aType == SMESH::FT_BelongToGeom ||
3007 aType == SMESH::FT_BelongToPlane ||
3008 aType == SMESH::FT_BelongToCylinder ||
3009 aType == SMESH::FT_BelongToGenSurface ||
3010 aType == SMESH::FT_LyingOnGeom)
3013 myTable->GetThreshold(i, aName);
3015 std::vector<_PTR(SObject)> aList =
3016 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
3017 if (aList.size() == 0) {
3018 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3019 tr("BAD_SHAPE_NAME").arg(aName));
3023 if (aType == SMESH::FT_BelongToCylinder ||
3024 aType == SMESH::FT_BelongToPlane ||
3025 aType == SMESH::FT_BelongToGenSurface ) {
3026 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
3027 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
3028 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
3029 if (!aGeomObj->_is_nil()) {
3031 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
3033 aFace.ShapeType() != TopAbs_FACE) {
3034 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3035 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3039 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
3040 if (aSurf.IsNull()) {
3041 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3042 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3046 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
3047 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3048 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
3052 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
3053 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3054 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
3060 else if (aType == SMESH::FT_CoplanarFaces)
3063 myTable->GetThreshold(i, faceID);
3064 if ( faceID.isEmpty() )
3066 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3067 tr("FACE_ID_NOT_SELECTED"));
3070 if ( myMesh->_is_nil() )
3072 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3073 tr("MESH_IS_NOT_SELECTED"));
3076 if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
3078 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3079 tr("NOT_FACE_ID").arg(faceID));
3088 //=======================================================================
3089 // name : SMESHGUI_FilterDlg::SetSourceWg
3090 // Purpose : Set widget of parent dialog containing ids to be filtered if
3091 // user select corresponding source radio button
3092 //=======================================================================
3093 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
3094 const bool initOnApply)
3097 myInitSourceWgOnApply = initOnApply;
3100 //=======================================================================
3101 // name : SMESHGUI_FilterDlg::SetMesh
3102 // Purpose : Set mesh
3103 //=======================================================================
3104 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
3106 if ( !theMesh->_is_nil() ) {
3108 if ( !myFilter[ myTable->GetType() ]->_is_nil())
3109 myFilter[ myTable->GetType() ]->SetMesh( theMesh );
3111 const bool isEnable = !(myMesh->_is_nil());
3112 myButtons[BTN_OK]->setEnabled(isEnable);
3113 myButtons[BTN_Apply]->setEnabled(isEnable);
3116 //=======================================================================
3117 // name : SMESHGUI_FilterDlg::SetSelection
3118 // Purpose : Get filtered ids
3119 //=======================================================================
3120 void SMESHGUI_FilterDlg::SetSelection()
3123 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3125 if (mySelectionMgr) {
3127 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
3128 SALOME_ListIteratorOfListIO anIter (anObjs);
3129 for ( ; anIter.More(); anIter.Next()) {
3130 TColStd_IndexedMapOfInteger aMap;
3131 mySelector->GetIndex(anIter.Value(), aMap);
3132 myIObjects.Bind(anIter.Value(), aMap);
3135 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3143 //=======================================================================
3144 // name : SMESHGUI_FilterDlg::onApply
3145 // Purpose : SLOT called when "Apply" button pressed.
3146 // Assign filters to VTK viewer
3147 //=======================================================================
3148 bool SMESHGUI_FilterDlg::onApply()
3154 int aCurrType = myTable->GetType();
3156 if (!createFilter(aCurrType))
3159 insertFilterInViewer();
3161 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3162 QList<int> aResultIds;
3163 filterSource(aCurrType, aResultIds);
3165 selectInViewer(aCurrType, aResultIds);
3169 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3170 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3172 catch(const SALOME::SALOME_Exception& S_ex)
3174 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3183 //=======================================================================
3184 // name : SMESHGUI_FilterDlg::createFilter
3185 // Purpose : Create predicate for given type
3186 //=======================================================================
3187 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3189 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3190 if (aFilterMgr->_is_nil())
3193 int n = myTable->NumRows();
3195 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3196 aCriteria->length(n);
3198 long aPrecision = -1;
3199 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3201 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3202 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3204 for (CORBA::ULong i = 0; i < n; i++) {
3205 SMESH::Filter::Criterion aCriterion = createCriterion();
3206 myTable->GetCriterion(i, aCriterion);
3207 aCriterion.Precision = aPrecision;
3208 aCriteria[ i ] = aCriterion;
3211 myFilter[ theType ] = aFilterMgr->CreateFilter();
3212 myFilter[ theType ]->SetCriteria(aCriteria.inout());
3217 //================================================================================
3219 * \brief Return the current filter
3221 //================================================================================
3223 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3225 SMESH::Filter_var filter;
3227 int aCurrType = myTable->GetType();
3228 filter = myFilter[ aCurrType ];
3233 return filter._retn();
3236 //================================================================================
3238 * \brief Sets a filter to the table
3240 //================================================================================
3242 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3244 myFilter[ type ] = filter;
3247 //=======================================================================
3248 // name : SMESHGUI_FilterDlg::insertFilterInViewer
3249 // Purpose : Insert filter in viewer
3250 //=======================================================================
3251 void SMESHGUI_FilterDlg::insertFilterInViewer()
3253 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3254 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3256 if (myFilter[ myTable->GetType() ]->_is_nil() ||
3257 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3258 !mySetInViewer->isChecked()) {
3259 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3262 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3263 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3264 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3265 SMESH::SetFilter(aFilter, aSelector);
3270 //=======================================================================
3271 // name : SMESHGUI_FilterDlg::filterSource
3272 // Purpose : Filter source ids
3273 //=======================================================================
3274 void SMESHGUI_FilterDlg::filterSource (const int theType,
3275 QList<int>& theResIds)
3278 if (myFilter[ theType ]->_is_nil())
3281 int aSourceId = mySourceGrp->checkedId();
3283 if (aSourceId == Mesh)
3285 if (myMesh->_is_nil())
3287 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3288 for (int i = 0, n = anIds->length(); i < n; i++)
3289 theResIds.append(anIds[ i ]);
3291 else if (aSourceId == Selection)
3293 filterSelectionSource(theType, theResIds);
3295 else if (aSourceId == Dialog)
3297 // retrieve ids from dialog
3298 QList<int> aDialogIds;
3299 getIdsFromWg(mySourceWg, aDialogIds);
3301 if (myMesh->_is_nil())
3303 theResIds = aDialogIds;
3308 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3309 myFilter[ theType ]->SetMesh(myMesh);
3310 QList<int>::const_iterator anIter;
3311 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3312 if (aPred->IsSatisfy(*anIter))
3313 theResIds.append(*anIter);
3315 // set ids to the dialog
3316 if (myInitSourceWgOnApply || aSourceId == Dialog)
3317 setIdsToWg(mySourceWg, theResIds);
3320 //=======================================================================
3321 // name : SMESHGUI_FilterDlg::filterSelectionSource
3322 // Purpose : Filter source selection
3323 //=======================================================================
3324 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3325 QList<int>& theResIds)
3328 if (myMesh->_is_nil() || mySelectionMgr == 0)
3331 // Create map of entities to be filtered
3332 TColStd_MapOfInteger aToBeFiltered;
3333 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3335 for ( ; anIter.More(); anIter.Next())
3338 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3339 if (!aSubMesh->_is_nil())
3341 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3343 SMESH::long_array_var anIds =
3344 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3345 for (int i = 0, n = anIds->length(); i < n; i++)
3346 aToBeFiltered.Add(anIds[ i ]);
3351 SMESH::SMESH_GroupBase_var aGroup =
3352 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3353 if (!aGroup->_is_nil())
3355 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3357 SMESH::long_array_var anIds = aGroup->GetListOfID();
3358 for (int i = 0, n = anIds->length(); i < n; i++)
3359 aToBeFiltered.Add(anIds[ i ]);
3364 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3365 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3367 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3369 if (aSelMap.Extent() > 0)
3371 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3373 for (int i = 1; i <= aSelMap.Extent(); i++)
3374 aToBeFiltered.Add(aSelMap(i));
3381 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3382 myFilter[ theType ]->SetMesh(myMesh);
3383 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3384 for ( ; aResIter.More(); aResIter.Next())
3385 if (aPred->IsSatisfy(aResIter.Key()))
3386 theResIds.append(aResIter.Key());
3389 //=======================================================================
3390 // name : SMESHGUI_FilterDlg::selectInViewer
3391 // Purpose : Select given entities in viewer
3392 //=======================================================================
3393 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3395 if (mySelectionMgr == 0 || myMesh->_is_nil())
3398 mySelectionMgr->clearFilters();
3400 // Set new selection mode if necessary
3401 Selection_Mode aSelMode = getSelMode(theType);
3402 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3403 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3404 mySelectionMgr->clearSelected();
3405 mySelectionMgr->clearFilters();
3406 if (aSelMode == NodeSelection)
3407 SMESH::SetPointRepresentation(true);
3408 aViewWindow->SetSelectionMode(aSelMode);
3412 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3413 if (!anActor || !anActor->hasIO())
3416 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3417 //mySelectionMgr->clearSelected();
3418 //mySelectionMgr->AddIObject(anIO, false);
3419 SALOME_ListIO aList;
3421 mySelectionMgr->setSelectedObjects(aList, false);
3423 // Remove filter corresponding to the current type from viewer
3424 int aType = myTable->GetType();
3425 int aFilterId = SMESH::UnknownFilter;
3426 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3427 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3428 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3429 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3430 SMESH::RemoveFilter(aFilterId);
3433 TColStd_MapOfInteger aMap;
3434 QList<int>::const_iterator anIter;
3435 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3439 // Set new selection
3440 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3441 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3442 aViewWindow->highlight( anIO, true, true );
3444 // insert previously stored filter in viewer if necessary
3445 if (!aFilter.IsNull())
3446 SMESH::SetFilter(aFilter);
3449 //=======================================================================
3450 // name : SMESHGUI_FilterDlg::createCriterion
3451 // Purpose : Create criterion structure with default values
3452 //=======================================================================
3453 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3455 SMESH::Filter::Criterion aCriterion;
3457 aCriterion.Type = SMESH::FT_Undefined;
3458 aCriterion.Compare = SMESH::FT_Undefined;
3459 aCriterion.Threshold = 0;
3460 aCriterion.UnaryOp = SMESH::FT_Undefined;
3461 aCriterion.BinaryOp = SMESH::FT_Undefined;
3462 aCriterion.ThresholdStr = "";
3463 aCriterion.ThresholdID = "";
3464 aCriterion.TypeOfElement = SMESH::ALL;
3469 //=======================================================================
3470 // name : SMESHGUI_FilterDlg::onSelectionDone
3471 // Purpose : SLOT called when selection changed.
3472 // If current cell corresponds to the threshold value of
3473 // BelongToGeom criterion name of selected object is set in this cell
3474 //=======================================================================
3475 void SMESHGUI_FilterDlg::onSelectionDone()
3478 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3480 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3481 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3482 if ( !(myMesh->_is_nil()) ) {
3483 myButtons[BTN_OK]->setEnabled(true);
3484 myButtons[BTN_Apply]->setEnabled(true);
3489 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3490 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3491 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces;
3492 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
3493 !types.contains(myTable->GetCriterionType(aRow)))
3496 if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
3499 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
3500 aList.First(), aString);
3502 myTable->SetThreshold(aRow, aString);
3506 Handle(SALOME_InteractiveObject) anIO = aList.First();
3507 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3508 if (!anObj->_is_nil())
3510 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3511 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3512 myTable->SetID(aRow, anIO->getEntry());
3518 //=======================================================================
3519 // name : SMESHGUI_FilterDlg::onCriterionChanged
3520 // Purpose : SLOT called when cretarion of current row changed. Update selection
3521 //=======================================================================
3522 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3527 //=======================================================================
3528 // name : SMESHGUI_FilterDlg::onCurrentChanged
3529 // Purpose : SLOT called when current row changed. Update selection
3530 //=======================================================================
3531 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3536 //=======================================================================
3537 // name : SMESHGUI_FilterDlg::updateSelection
3538 // Purpose : UpdateSelection in accordance with current row
3539 //=======================================================================
3540 void SMESHGUI_FilterDlg::updateSelection()
3542 if (mySelectionMgr == 0)
3545 // TColStd_MapOfInteger allTypes;
3546 // for( int i=0; i<10; i++ )
3547 // allTypes.Add( i );
3548 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3553 mySelectionMgr->clearFilters();
3557 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3558 int aCriterionType = myTable->GetCriterionType(aRow);
3559 if ( isCurrentCell &&
3560 (aCriterionType == SMESH::FT_BelongToGeom ||
3561 aCriterionType == SMESH::FT_BelongToPlane ||
3562 aCriterionType == SMESH::FT_BelongToCylinder ||
3563 aCriterionType == SMESH::FT_BelongToGenSurface ||
3564 aCriterionType == SMESH::FT_LyingOnGeom))
3566 if (aCriterionType == SMESH::FT_BelongToGeom ||
3567 aCriterionType == SMESH::FT_BelongToGenSurface ||
3568 aCriterionType == SMESH::FT_LyingOnGeom) {
3570 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3572 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3573 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3575 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3576 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3578 myIsSelectionChanged = true;
3583 mySelector->SetSelectionMode( getSelMode( myTable->GetType() ));
3585 if (myIsSelectionChanged) {
3586 // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3587 // Impossible to select any object in the OB on the second opening of FilterDlg
3592 //=================================================================================
3593 // function : keyPressEvent()
3595 //=================================================================================
3596 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3598 QDialog::keyPressEvent( e );
3599 if ( e->isAccepted() )
3602 if ( e->key() == Qt::Key_F1 ) {