1 // Copyright (C) 2007-2013 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
29 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_Filter.h"
35 #include "SMESHGUI_FilterUtils.h"
36 #include "SMESHGUI_FilterLibraryDlg.h"
37 #include "SMESHGUI_SpinBox.h"
39 #include <SMESH_Actor.h>
40 #include <SMESH_NumberFilter.hxx>
41 #include <SMESH_TypeFilter.hxx>
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>
70 #include <Basics_Utils.hxx>
73 #include <StdSelect_TypeOfFace.hxx>
74 #include <BRep_Tool.hxx>
76 #include <TopoDS_Shape.hxx>
77 #include <Geom_Plane.hxx>
78 #include <Geom_CylindricalSurface.hxx>
79 #include <Precision.hxx>
80 #include <TColStd_MapOfInteger.hxx>
81 #include <TColStd_IndexedMapOfInteger.hxx>
82 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
87 #include <QPushButton>
89 #include <QTableWidget>
90 #include <QStringList>
91 #include <QHBoxLayout>
92 #include <QVBoxLayout>
93 #include <QGridLayout>
94 #include <QStackedWidget>
95 #include <QApplication>
97 #include <QFontMetrics>
99 #include <QButtonGroup>
100 #include <QRadioButton>
102 #include <QListWidget>
104 #include <QItemDelegate>
105 #include <QDoubleValidator>
107 #include <QHeaderView>
110 #include <SALOMEconfig.h>
111 #include CORBA_SERVER_HEADER(SMESH_Group)
116 //---------------------------------------
118 //---------------------------------------
119 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
122 QMap<int, QString>::const_iterator anIter;
123 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
124 aRes = qMax(aRes, theMetrics.width(anIter.value()));
128 //---------------------------------------
130 //---------------------------------------
131 static int getFilterId (SMESH::ElementType theType)
135 case SMESH::NODE : return SMESH::NodeFilter;
136 case SMESH::EDGE : return SMESH::EdgeFilter;
137 case SMESH::FACE : return SMESH::FaceFilter;
138 case SMESH::VOLUME : return SMESH::VolumeFilter;
139 case SMESH::ALL : return SMESH::AllElementsFilter;
140 default : return SMESH::UnknownFilter;
145 Class : SMESHGUI_FilterTable::AdditionalWidget
146 Description : Class for storing additional parameters of criterion
149 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
155 AdditionalWidget(QWidget* theParent);
156 virtual ~AdditionalWidget();
158 virtual QList<int> GetParameters() const;
159 virtual bool IsValid(const bool = true) const;
160 virtual double GetDouble(const int) const;
161 virtual int GetInteger(const int) const;
162 virtual QString GetString(const int) const;
163 virtual void SetDouble(const int, const double);
164 virtual void SetInteger(const int, const int);
165 virtual void SetString(const int, const QString&);
166 void SetEditable(const int, const bool);
167 void SetEditable(const bool);
168 void SetPrecision(const int, const char* = 0);
171 QMap< int, QWidget* > myWidgets;
174 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
177 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
179 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
180 sb->setAcceptNames( false ); // No Notebook variables allowed
181 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
182 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
183 myWidgets[ Tolerance ] = sb;
185 QHBoxLayout* aLay = new QHBoxLayout(this);
186 aLay->setSpacing(SPACING);
189 aLay->addWidget(aLabel);
190 aLay->addWidget(myWidgets[ Tolerance ]);
193 SetDouble( Tolerance, Precision::Confusion() );
196 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
200 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
203 theList.append(Tolerance);
207 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
212 QList<int> aParams = GetParameters();
213 QList<int>::const_iterator anIter;
214 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
215 if ( !myWidgets.contains( *anIter ) ) continue;
217 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
218 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
220 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
222 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
224 if (!valid && theMsg) {
225 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
226 tr("SMESHGUI_INVALID_PARAMETERS"));
234 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
237 if ( myWidgets.contains( theId ) ) {
238 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
239 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
240 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
241 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
246 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
249 if ( myWidgets.contains( theId ) ) {
250 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
251 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
252 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
253 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
258 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
261 if ( myWidgets.contains( theId ) ) {
262 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
263 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
264 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
265 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
270 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
272 if ( myWidgets.contains( theId ) ) {
273 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
274 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
275 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
276 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
280 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
282 if ( myWidgets.contains( theId ) ) {
283 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
284 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
285 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
286 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
290 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
292 if ( myWidgets.contains( theId ) ) {
293 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
294 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
295 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
296 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
300 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
302 if ( myWidgets.contains( theId ) ) {
303 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
304 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
305 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
306 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
310 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
312 QList<int> aParams = GetParameters();
313 QList<int>::const_iterator anIter;
314 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
315 SetEditable( *anIter, isEditable );
318 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
320 if ( myWidgets.contains( theId ) ) {
321 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
322 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
323 double val = sb->GetValue();
324 double min = pow(10.0, -(sb->decimals()));
325 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
326 sb->SetValue( qMax( val, min ) );
332 Class : SMESHGUI_FilterTable::ComboItem
333 Description : Combo table item. Identificator corresponding to string may be assigned
336 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
341 ComboItem( const QMap<int, QString>& );
343 void setItems( const QMap<int, QString>& );
348 void setValue( const int );
352 int index( int ) const;
355 QMap<int, int> myIdToIdx;
358 int SMESHGUI_FilterTable::ComboItem::Type()
360 return QTableWidgetItem::UserType + 1;
363 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
364 : QTableWidgetItem( Type() )
369 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
372 QMap<int, QString>::const_iterator it;
374 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
375 myIdToIdx[it.key()] = items.count();
376 items.append( it.value() );
378 setData( Qt::UserRole, items );
382 void SMESHGUI_FilterTable::ComboItem::clear()
384 QMap<int, QString> empty;
388 int SMESHGUI_FilterTable::ComboItem::count() const
390 return myIdToIdx.count();
393 int SMESHGUI_FilterTable::ComboItem::value() const
395 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
398 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
400 int idx = index( theId );
401 QStringList items = data( Qt::UserRole ).toStringList();
402 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
405 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
407 QMap<int,int>::const_iterator it;
408 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
409 if ( it.value() == idx ) return it.key();
413 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
415 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
418 Class : SMESHGUI_FilterTable::CheckItem
419 Description : Check table item.
422 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
427 CheckItem( bool = false );
428 CheckItem( const QString&, bool = false );
431 void setChecked( bool );
432 bool checked() const;
435 int SMESHGUI_FilterTable::CheckItem::Type()
437 return QTableWidgetItem::UserType + 2;
440 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
441 : QTableWidgetItem( Type() )
443 Qt::ItemFlags f = flags();
444 f = f | Qt::ItemIsUserCheckable;
445 f = f & ~Qt::ItemIsTristate;
446 f = f & ~Qt::ItemIsEditable;
451 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
452 : QTableWidgetItem( Type() )
454 Qt::ItemFlags f = flags();
455 f = f | Qt::ItemIsUserCheckable;
456 f = f & ~Qt::ItemIsTristate;
457 f = f & ~Qt::ItemIsEditable;
463 SMESHGUI_FilterTable::CheckItem::~CheckItem()
467 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
469 setCheckState( value ? Qt::Checked : Qt::Unchecked );
472 bool SMESHGUI_FilterTable::CheckItem::checked() const
474 return checkState() == Qt::Checked;
478 Class : SMESHGUI_FilterTable::IntSpinItem
479 Description : Integer spin table item.
482 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
487 IntSpinItem( const int theValue );
490 void setValue( const int theValue );
495 int SMESHGUI_FilterTable::IntSpinItem::Type()
497 return QTableWidgetItem::UserType + 3;
500 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
501 : QTableWidgetItem( Type() )
503 setValue( theValue );
506 int SMESHGUI_FilterTable::IntSpinItem::value() const
509 int value = data( Qt::UserRole ).toInt( &ok );
510 return ok ? value : 0;
513 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
515 setData( Qt::UserRole, theValue );
516 setText( QString::number( theValue ) );
519 void SMESHGUI_FilterTable::IntSpinItem::clear()
525 Class : SMESHGUI_FilterTable::DoubleSpinItem
526 Description : Double spin table item.
529 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
534 DoubleSpinItem( const double theValue );
536 double value() const;
537 void setValue( const double theValue );
539 int precision() const;
540 void setPrecision( const int thePrecision );
545 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
547 return QTableWidgetItem::UserType + 4;
550 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
551 : QTableWidgetItem( Type() )
553 setValue( theValue );
556 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
559 double value = data( Qt::UserRole ).toDouble( &ok );
560 return ok ? value : 0;
563 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
565 setData( Qt::UserRole, theValue );
566 setText( QString::number( theValue ) );
569 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
572 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
573 return ok ? precision : 0;
576 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
578 setData( Qt::UserRole + 1, thePrecision );
581 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
587 Class : SMESHGUI_FilterTable::ComboDelegate
588 Description : Table used by this widget
591 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
594 ComboDelegate( QObject* = 0 );
597 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
598 const QModelIndex& ) const;
600 void setEditorData( QWidget*, const QModelIndex& ) const;
601 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
603 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
604 const QModelIndex& ) const;
606 QTableWidget* myTable;
609 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
610 : QItemDelegate( parent ),
611 myTable( qobject_cast<QTableWidget*>( parent ) )
615 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
619 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
620 const QStyleOptionViewItem& option,
621 const QModelIndex& index ) const
623 QVariant aData = index.data( Qt::UserRole );
624 QVariant::Type aDataType = aData.type();
625 if( aDataType == QVariant::StringList ) {
626 QStringList l = aData.toStringList();
627 if ( !l.isEmpty() ) {
628 QComboBox* cb = new QComboBox( parent );
629 cb->setFrame( false );
634 else if( aDataType == QVariant::Int ) {
636 int aValue = aData.toInt( &ok );
638 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
639 intSpin->setFrame( false );
640 intSpin->setValue( aValue );
644 else if( aDataType == QVariant::Double ) {
646 double aValue = aData.toDouble( &ok );
648 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
652 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
653 dblSpin->setFrame( false );
654 dblSpin->setValue( aValue );
658 return QItemDelegate::createEditor( parent, option, index );
661 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
662 const QModelIndex& index ) const
664 QVariant data = index.model()->data( index, Qt::DisplayRole );
665 QString value = data.toString();
667 if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
668 int i = cb->findText( value );
670 cb->setCurrentIndex( i );
674 else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
675 if( data.type() == QVariant::Double ) {
676 double valueDouble = data.toDouble( &bOk );
678 dblSpin->setValue( valueDouble );
681 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
684 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
685 QAbstractItemModel* model,
686 const QModelIndex& index) const
688 if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
689 model->setData( index, cb->currentText(), Qt::DisplayRole );
690 else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
691 model->setData( index, intSpin->value(), Qt::DisplayRole );
692 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
693 model->setData( index, dblSpin->value(), Qt::DisplayRole );
694 else QItemDelegate::setModelData( editor, model, index );
697 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
698 const QStyleOptionViewItem& option,
699 const QModelIndex& index ) const
701 editor->setGeometry( option.rect );
705 Class : SMESHGUI_FilterTable::Table
706 Description : Table used by this widget
709 class SMESHGUI_FilterTable::Table : public QTableWidget
712 Table( QWidget* = 0 );
713 Table( int, int, QWidget* = 0 );
716 QSize minimumSizeHint() const;
718 void setEditable( bool, int, int );
719 bool isEditable( int, int ) const;
721 void setReadOnly( bool );
722 bool isReadOnly() const;
724 void insertRows( int, int = 1 );
725 QString text( int, int );
727 QList<int> selectedRows();
730 //=======================================================================
731 // name : SMESHGUI_FilterTable::Table::Table
732 // Purpose : Constructor
733 //=======================================================================
734 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
735 : QTableWidget(parent)
737 // set custom item delegate
738 setItemDelegate( new ComboDelegate(this) );
739 // set edit triggers by default
740 setReadOnly( false );
743 //=======================================================================
744 // name : SMESHGUI_FilterTable::Table::Table
745 // Purpose : Constructor
746 //=======================================================================
747 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
748 : QTableWidget(numRows, numCols, parent)
750 // set custom item delegate
751 setItemDelegate( new ComboDelegate(this) );
752 // set edit triggers by default
753 setReadOnly( false );
756 //=======================================================================
757 // name : SMESHGUI_FilterTable::Table::~Table
758 // Purpose : Destructor
759 //=======================================================================
760 SMESHGUI_FilterTable::Table::~Table()
764 //=======================================================================
765 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
766 // Purpose : Get minimum size for the table
767 //=======================================================================
768 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
770 QSize s = QTableWidget::minimumSizeHint();
771 QHeaderView* hv = horizontalHeader();
773 s.setWidth( qMax( s.width(), hv->length() ) );
777 //=======================================================================
778 // name : SMESHGUI_FilterTable::Table::setEditable
779 // Purpose : Set editable of specified cell
780 //=======================================================================
781 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
784 QTableWidgetItem* anItem = item( row, col );
786 bool isSignalsBlocked = signalsBlocked();
787 blockSignals( true );
789 Qt::ItemFlags f = anItem->flags();
790 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
791 else f = f | Qt::ItemIsEditable;
792 anItem->setFlags( f );
794 blockSignals( isSignalsBlocked );
798 //=======================================================================
799 // name : SMESHGUI_FilterTable::Table::isEditable
800 // Purpose : Verify wheter cell is editable
801 //=======================================================================
802 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
804 QTableWidgetItem* anItem = item( row, col );
805 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
808 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
810 setEditTriggers( on ?
811 QAbstractItemView::NoEditTriggers :
812 QAbstractItemView::AllEditTriggers );
815 bool SMESHGUI_FilterTable::Table::isReadOnly() const
817 return editTriggers() == QAbstractItemView::NoEditTriggers;
820 //=======================================================================
821 // name : SMESHGUI_FilterTable::Table::insertRows
822 // Purpose : Insert rows (virtual redefined)
823 //=======================================================================
824 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
826 closePersistentEditor( currentItem() );
827 while ( count-- ) insertRow( row );
830 //=======================================================================
831 // name : SMESHGUI_FilterTable::Table::text
832 // Purpose : Get text from cell (virtual redefined)
833 //=======================================================================
834 QString SMESHGUI_FilterTable::Table::text (int row, int col)
836 closePersistentEditor( currentItem() );
837 QTableWidgetItem* anItem = item( row, col );
838 return anItem ? anItem->text() : QString();
841 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
843 QList<QTableWidgetItem*> selItems = selectedItems();
844 QTableWidgetItem* anItem;
847 foreach( anItem, selItems ) {
848 int r = row( anItem );
849 if ( !rows.contains( r ) ) rows.append( r );
857 Class : SMESHGUI_FilterTable
858 Description : Frame containig
859 - Button group for switching entity type
860 - Table for displaying filter criterions
861 - Buttons for editing table and filter libraries
864 //=======================================================================
865 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
866 // Purpose : Constructor
867 //=======================================================================
868 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
873 mySMESHGUI( theModule )
882 //=======================================================================
883 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
884 // Purpose : Constructor
885 //=======================================================================
886 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
888 const QList<int>& types )
891 mySMESHGUI( theModule )
897 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
901 //=======================================================================
902 // name : SMESHGUI_FilterTable::Init
903 // Purpose : Create table corresponding to the specified type
904 //=======================================================================
905 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
907 if (theTypes.isEmpty())
910 // Create buttons if necessary
912 if (myTables.isEmpty())
914 // create main layout
915 QVBoxLayout* aMainLay = new QVBoxLayout(this);
916 aMainLay->setMargin( 0 );
917 aMainLay->setSpacing( SPACING );
919 // create switch of entity types
920 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
921 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
922 myEntityTypeBoxLayout->setMargin( MARGIN );
923 myEntityTypeBoxLayout->setSpacing( SPACING );
924 myEntityTypeGrp = new QButtonGroup(this);
926 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
927 QMap<int, QString>::const_iterator anIter;
928 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
930 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
931 myEntityTypeGrp->addButton(aBtn, anIter.key());
932 myEntityTypeBoxLayout->addWidget(aBtn);
935 myTableGrp = new QGroupBox(tr("FILTER"), this );
938 mySwitchTableGrp = new QWidget(myTableGrp);
939 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
940 mySwitchTableGrpLayout->setMargin(0);
941 mySwitchTableGrpLayout->setSpacing(0);
943 QList<int>::const_iterator typeIt = theTypes.begin();
944 for ( ; typeIt != theTypes.end(); ++typeIt ) {
945 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
946 myTables[ *typeIt ] = aTable;
947 mySwitchTableGrpLayout->addWidget(aTable);
948 if ( typeIt != theTypes.begin() )
953 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
954 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
955 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
956 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
957 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
958 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
960 myAddBtn->setAutoDefault(false);
961 myRemoveBtn->setAutoDefault(false);
962 myClearBtn->setAutoDefault(false);
963 myInsertBtn->setAutoDefault(false);
964 myCopyFromBtn->setAutoDefault(false);
965 myAddToBtn->setAutoDefault(false);
967 myCopyFromBtn->hide();
971 QGridLayout* aLay = new QGridLayout(myTableGrp);
972 aLay->setMargin(MARGIN);
973 aLay->setSpacing(SPACING);
975 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
976 aLay->addWidget(myAddBtn, 0, 1);
977 aLay->addWidget(myInsertBtn, 1, 1);
978 aLay->addWidget(myRemoveBtn, 2, 1);
979 aLay->addWidget(myClearBtn, 3, 1);
980 aLay->addWidget(myCopyFromBtn, 5, 1);
981 aLay->addWidget(myAddToBtn, 6, 1);
982 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
984 aLay->setRowMinimumHeight(4, 10);
985 aLay->setRowStretch(4, 1);
986 aLay->setColumnStretch(0, 1);
987 aLay->setColumnStretch(1, 0);
990 aMainLay->addWidget(myEntityTypeBox);
991 aMainLay->addWidget(myTableGrp);
994 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
995 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
996 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
997 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
999 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
1000 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
1002 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1008 QList<int>::const_iterator typeIt = theTypes.begin();
1009 for ( ; typeIt != theTypes.end(); ++typeIt ) {
1010 if ( !myTables[ *typeIt ] ) {
1011 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
1012 myTables[ *typeIt ] = aTable;
1013 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ *typeIt ]);
1018 // Hide buttons of entity types if necessary
1019 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1020 QMap<int, QString>::const_iterator anIt;
1021 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1023 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1024 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1027 // select first button if there is no selected buttons or it is hidden
1028 int aBtnId = myEntityTypeGrp->checkedId();
1029 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1030 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1031 if ( aBtn ) aBtn->setChecked(true);
1034 myEntityTypeBox->setVisible(theTypes.count() > 1);
1036 myTableGrp->updateGeometry();
1037 int cType = myEntityTypeGrp->checkedId();
1038 onEntityType(cType);
1041 //=======================================================================
1042 // name : SMESHGUI_FilterTable::createAdditionalFrame
1043 // Purpose : Get group box containing table. May be used for adding new widgets in it
1044 //=======================================================================
1045 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1047 QWidget* aFrame = new QWidget(theParent);
1049 QFrame* aLine1 = new QFrame(aFrame);
1050 QFrame* aLine2 = new QFrame(aFrame);
1051 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1052 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1053 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1054 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1056 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1058 myWgStack = new QStackedWidget(aFrame);
1060 QGridLayout* aLay = new QGridLayout(aFrame);
1062 aLay->setSpacing(SPACING);
1063 aLay->addWidget(aLine1, 0, 0);
1064 aLay->addWidget(aLabel, 0, 1);
1065 aLay->addWidget(aLine2, 0, 2);
1066 aLay->addWidget(myWgStack, 1, 0, 1, 3);
1071 //=======================================================================
1072 // name : SMESHGUI_FilterTable::GetTableGrp
1073 // Purpose : Get group box containing table. May be used for adding new widgets in it
1074 //=======================================================================
1075 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1080 //=======================================================================
1081 // name : SMESHGUI_FilterTable::onEntityType
1082 // Purpose : SLOT. Called when entity type changed.
1083 // Display corresponding table
1084 //=======================================================================
1085 void SMESHGUI_FilterTable::onEntityType (int theType)
1087 if (myEntityType == theType)
1091 emit NeedValidation();
1094 myEntityTypeGrp->button(myEntityType)->setChecked(true);
1098 myEntityType = theType;
1100 if (!myTables.contains(theType)) {
1101 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1102 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1105 TableMap::iterator anIter;
1106 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1107 anIter.value()->setVisible( myEntityType == anIter.key() );
1110 qApp->processEvents();
1111 myTables[ myEntityType ]->updateGeometry();
1114 emit EntityTypeChanged(theType);
1117 //=======================================================================
1118 // name : SMESHGUI_FilterTable::IsValid
1119 // Purpose : Verify validity of entered data
1120 //=======================================================================
1121 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1123 int aType = theEntityType == -1 ? GetType() : theEntityType;
1125 Table* aTable = myTables[ aType ];
1126 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1128 int aCriterion = GetCriterionType(i, aType);
1130 if (aCriterion == SMESH::FT_GroupColor ) {
1131 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1132 if (clrBtn && !clrBtn->color().isValid())
1133 errMsg = tr( "GROUPCOLOR_ERROR" );
1135 else if (aCriterion == SMESH::FT_RangeOfIds ||
1136 aCriterion == SMESH::FT_BelongToGeom ||
1137 aCriterion == SMESH::FT_BelongToPlane ||
1138 aCriterion == SMESH::FT_BelongToCylinder ||
1139 aCriterion == SMESH::FT_BelongToGenSurface ||
1140 aCriterion == SMESH::FT_ElemGeomType ||
1141 aCriterion == SMESH::FT_EntityType ||
1142 aCriterion == SMESH::FT_CoplanarFaces ||
1143 aCriterion == SMESH::FT_LyingOnGeom)
1145 if (aTable->text(i, 2).isEmpty())
1146 errMsg = tr( "ERROR" );
1150 bool isSignalsBlocked = aTable->signalsBlocked();
1151 aTable->blockSignals(true);
1152 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1153 aTable->blockSignals(isSignalsBlocked);
1155 if (!aRes && aTable->isEditable(i, 2))
1156 errMsg = tr( "ERROR" );
1157 else if (aType == SMESH::EDGE &&
1158 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1160 errMsg = tr( "MULTIEDGES_ERROR" );
1163 if (!errMsg.isEmpty()) {
1165 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1169 QTableWidgetItem* anItem = aTable->item(i, 0);
1170 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1177 //=======================================================================
1178 // name : SMESHGUI_FilterTable::SetValidity
1179 // Purpose : Set validity of the table
1180 //=======================================================================
1181 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1183 myIsValid = isValid;
1186 //=======================================================================
1187 // name : SMESHGUI_FilterTable::GetType
1188 // Purpose : Get current entity type
1189 //=======================================================================
1190 int SMESHGUI_FilterTable::GetType() const
1192 return myEntityType;
1195 //=======================================================================
1196 // name : SMESHGUI_FilterTable::SetType
1197 // Purpose : Set current entity type
1198 //=======================================================================
1199 void SMESHGUI_FilterTable::SetType (const int type)
1201 myEntityTypeGrp->button(type)->setChecked(true);
1205 //=======================================================================
1206 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1207 // Purpose : Restore previous entity type
1208 //=======================================================================
1209 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1211 SetType(myEntityType);
1214 //=======================================================================
1215 // name : SMESHGUI_FilterTable::GetCriterionType
1216 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1217 //=======================================================================
1218 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1220 int aType = theType == -1 ? GetType() : theType;
1221 Table* aTable = myTables[ aType ];
1222 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1223 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1226 //=======================================================================
1227 // name : SMESHGUI_FilterTable::GetCriterion
1228 // Purpose : Get parameters of criterion from specified row
1229 //=======================================================================
1230 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1231 SMESH::Filter::Criterion& theCriterion,
1232 const int theEntityType) const
1234 int aType = theEntityType == -1 ? GetType() : theEntityType;
1235 Table* aTable = myTables[ aType ];
1237 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1238 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1239 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1240 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1241 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1243 int aCriterionType = GetCriterionType(theRow, aType);
1245 if ( aCriterionType == SMESH::FT_GroupColor )
1247 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1250 Kernel_Utils::Localizer loc;
1251 const QColor qClr = clrBtn->color();
1252 QString clrStr = QString( "%1;%2;%3" ).
1253 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1254 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1257 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1258 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1259 else if ( aCriterionType == SMESH::FT_EntityType )
1260 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1261 else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1262 theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1263 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1264 aCriterionType != SMESH::FT_BelongToGeom &&
1265 aCriterionType != SMESH::FT_BelongToPlane &&
1266 aCriterionType != SMESH::FT_BelongToCylinder &&
1267 aCriterionType != SMESH::FT_BelongToGenSurface &&
1268 aCriterionType != SMESH::FT_LyingOnGeom )
1270 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1271 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1275 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1276 if ( aCriterionType != SMESH::FT_RangeOfIds )
1277 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1280 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1281 if (myAddWidgets.contains(anItem))
1282 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1285 //=======================================================================
1286 // name : SMESHGUI_FilterTable::SetCriterion
1287 // Purpose : Set parameters of criterion of specified row
1288 //=======================================================================
1289 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1290 const SMESH::Filter::Criterion& theCriterion,
1291 const int theEntityType)
1293 int aType = theEntityType == -1 ? GetType() : theEntityType;
1295 Table* aTable = myTables[ aType ];
1297 if (theRow > aTable->rowCount() - 1)
1300 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1301 onCriterionChanged(theRow, 0, aType);
1302 if ( theCriterion.Compare == SMESH::FT_Undefined )
1303 ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
1305 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1306 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1308 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1310 if (!aTable->isEditable(theRow, 4))
1311 aTable->setItem(theRow, 4, getBinaryItem());
1312 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1315 aTable->setEditable(false, theRow, 4);
1317 if (theCriterion.Type == SMESH::FT_GroupColor )
1319 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1323 QString clrStr( theCriterion.ThresholdStr );
1324 QStringList clrVals = clrStr.split( ";" );
1325 if ( clrVals.count() > 2 )
1326 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1327 (int)256*clrVals[1].toDouble(),
1328 (int)256*clrVals[2].toDouble() );
1329 clrBtn->setColor( qClr );
1332 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1334 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1335 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1337 else if (theCriterion.Type == SMESH::FT_EntityType )
1339 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1340 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1342 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1344 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1346 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1347 theCriterion.Type != SMESH::FT_BelongToGeom &&
1348 theCriterion.Type != SMESH::FT_BelongToPlane &&
1349 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1350 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1351 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1352 theCriterion.Type != SMESH::FT_CoplanarFaces &&
1353 theCriterion.Type != SMESH::FT_FreeBorders &&
1354 theCriterion.Type != SMESH::FT_FreeEdges &&
1355 theCriterion.Type != SMESH::FT_FreeNodes &&
1356 theCriterion.Type != SMESH::FT_FreeFaces &&
1357 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1358 theCriterion.Type != SMESH::FT_BareBorderFace &&
1359 theCriterion.Type != SMESH::FT_BareBorderVolume &&
1360 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1361 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1362 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1364 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1368 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1369 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1370 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1373 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1374 theCriterion.Type == SMESH::FT_BelongToPlane ||
1375 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1376 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1377 theCriterion.Type == SMESH::FT_BelongToGeom ||
1378 theCriterion.Type == SMESH::FT_LyingOnGeom ||
1379 theCriterion.Type == SMESH::FT_CoplanarFaces ||
1380 theCriterion.Type == SMESH::FT_EqualNodes)
1382 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1383 if (!myAddWidgets.contains(anItem))
1385 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1386 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1387 myWgStack->addWidget(myAddWidgets[ anItem ]);
1389 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1392 emit CriterionChanged(theRow, aType);
1395 //=======================================================================
1396 // name : SMESHGUI_FilterTable::Update
1397 // Purpose : Update table
1398 //=======================================================================
1399 void SMESHGUI_FilterTable::Update()
1401 Table* aTable = myTables[ GetType() ];
1402 int aCurrRow = aTable->currentRow();
1403 int numRows = aTable->rowCount();
1404 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1405 aTable->setCurrentCell(0, 0);
1406 updateAdditionalWidget();
1409 //=======================================================================
1410 // name : SMESHGUI_FilterTable::AddCriterion
1411 // Purpose : Add criterion with parameters
1412 //=======================================================================
1413 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1414 const int theEntityType)
1416 int aType = theEntityType == -1 ? GetType() : theEntityType;
1417 Table* aTable = myTables[ aType ];
1418 addRow(aTable, aType);
1419 SetCriterion(aTable->rowCount() - 1, theCriterion);
1422 //=======================================================================
1423 // name : SMESHGUI_FilterTable::NumRows
1424 // Purpose : Get number of criterions of current type
1425 //=======================================================================
1426 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1428 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1431 //=======================================================================
1432 // name : SMESHGUI_FilterTable::Clear
1433 // Purpose : Clear current table
1434 //=======================================================================
1435 void SMESHGUI_FilterTable::Clear (const int theType)
1437 int aType = theType == -1 ? GetType() : theType;
1438 Table* aTable = myTables[ aType ];
1440 if (aTable->rowCount() == 0)
1443 while (aTable->rowCount() > 0)
1445 removeAdditionalWidget(aTable, 0);
1446 aTable->removeRow(0);
1452 //=======================================================================
1453 // name : SMESHGUI_FilterTable::onAddBtn
1454 // Purpose : SLOT. Called then "Add" button pressed.
1455 // Adds new string to table
1456 //=======================================================================
1457 void SMESHGUI_FilterTable::onAddBtn()
1459 int aType = GetType();
1460 addRow(myTables[ aType ], aType);
1465 //=======================================================================
1466 // name : SMESHGUI_FilterTable::onInsertBtn
1467 // Purpose : SLOT. Called then "Insert" button pressed.
1468 // Inserts new string before current one
1469 //=======================================================================
1470 void SMESHGUI_FilterTable::onInsertBtn()
1472 addRow(myTables[ GetType() ], GetType(), false);
1475 //=======================================================================
1476 // name : SMESHGUI_FilterTable::onRemoveBtn
1477 // Purpose : SLOT. Called then "Remove" button pressed.
1478 // Removes current string from table
1479 //=======================================================================
1480 void SMESHGUI_FilterTable::onRemoveBtn()
1482 Table* aTable = myTables[ GetType() ];
1484 if (aTable->rowCount() == 0)
1487 QList<QTableWidgetItem*> items = aTable->selectedItems();
1489 QList<int> aRows = aTable->selectedRows(); // already sorted
1493 removeAdditionalWidget(aTable, i);
1494 aTable->removeRow(i);
1497 // remove control of binary logical operation from last row
1498 if (aTable->rowCount() > 0)
1499 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1504 //=======================================================================
1505 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1506 // Purpose : Enable/Disable widget with additonal parameters
1507 //=======================================================================
1508 void SMESHGUI_FilterTable::updateAdditionalWidget()
1510 Table* aTable = myTables[ GetType() ];
1511 int aRow = aTable->currentRow();
1512 if (aRow < 0 || aRow >= aTable->rowCount())
1514 myWgStack->setEnabled(false);
1518 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1519 int aCriterion = GetCriterionType(aRow);
1520 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1521 aCriterion != SMESH::FT_RangeOfIds &&
1522 aCriterion != SMESH::FT_FreeEdges &&
1523 aCriterion != SMESH::FT_FreeFaces &&
1524 aCriterion != SMESH::FT_BadOrientedVolume &&
1525 aCriterion != SMESH::FT_BareBorderFace &&
1526 aCriterion != SMESH::FT_BareBorderVolume &&
1527 aCriterion != SMESH::FT_OverConstrainedFace &&
1528 aCriterion != SMESH::FT_OverConstrainedVolume)
1530 aCriterion == SMESH::FT_CoplanarFaces);
1532 if (!myAddWidgets.contains(anItem))
1534 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1535 myWgStack->addWidget(myAddWidgets[ anItem ]);
1538 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1539 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1540 myWgStack->setEnabled(toEnable);
1543 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1545 const char* retval = 0;
1547 case SMESH::FT_AspectRatio:
1548 case SMESH::FT_AspectRatio3D:
1549 case SMESH::FT_Taper:
1550 retval = "parametric_precision"; break;
1551 case SMESH::FT_Warping:
1552 case SMESH::FT_MinimumAngle:
1553 case SMESH::FT_Skew:
1554 case SMESH::FT_CoplanarFaces:
1555 retval = "angle_precision"; break;
1556 case SMESH::FT_Area:
1557 retval = "area_precision"; break;
1558 case SMESH::FT_BelongToGeom:
1559 case SMESH::FT_BelongToPlane:
1560 case SMESH::FT_BelongToCylinder:
1561 case SMESH::FT_BelongToGenSurface:
1562 case SMESH::FT_LyingOnGeom:
1563 case SMESH::FT_EqualNodes:
1564 retval = "len_tol_precision"; break;
1565 case SMESH::FT_Length:
1566 case SMESH::FT_Length2D:
1567 case SMESH::FT_MaxElementLength2D:
1568 case SMESH::FT_MaxElementLength3D:
1569 retval = "length_precision"; break;
1570 case SMESH::FT_Volume3D:
1571 retval = "vol_precision"; break;
1578 //=======================================================================
1579 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1580 // Purpose : Remove widgets containing additional parameters from widget
1581 // stack and internal map
1582 //=======================================================================
1583 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1585 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1586 if (myAddWidgets.contains(anItem))
1588 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1589 myAddWidgets[ anItem ]->setParent(0);
1590 delete myAddWidgets[ anItem ];
1591 myAddWidgets.remove(anItem);
1595 //=======================================================================
1596 // name : SMESHGUI_FilterTable::onClearBtn
1597 // Purpose : SLOT. Called then "Clear" button pressed.
1598 // Removes all strings from table
1599 //=======================================================================
1600 void SMESHGUI_FilterTable::onClearBtn()
1602 Table* aTable = myTables[ GetType() ];
1604 if (aTable->rowCount() == 0)
1607 while (aTable->rowCount() > 0)
1609 removeAdditionalWidget(aTable, 0);
1610 aTable->removeRow(0);
1616 //=======================================================================
1617 // name : SMESHGUI_FilterTable::onCurrentChanged()
1618 // Purpose : SLOT. Called when current cell changed
1619 //=======================================================================
1620 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1623 updateAdditionalWidget();
1624 emit CurrentChanged(theRow, theCol);
1627 //=======================================================================
1629 // Purpose : returns available geometry types of elements
1630 //=======================================================================
1631 static QList<int> geomTypes( const int theType )
1634 if ( theType == SMESH::NODE )
1635 typeIds.append( SMESH::Geom_POINT );
1636 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1637 typeIds.append( SMESH::Geom_EDGE );
1638 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1640 typeIds.append( SMESH::Geom_TRIANGLE );
1641 typeIds.append( SMESH::Geom_QUADRANGLE );
1642 typeIds.append( SMESH::Geom_POLYGON );
1644 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1646 typeIds.append( SMESH::Geom_TETRA );
1647 typeIds.append( SMESH::Geom_PYRAMID );
1648 typeIds.append( SMESH::Geom_HEXA );
1649 typeIds.append( SMESH::Geom_PENTA );
1650 typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1651 typeIds.append( SMESH::Geom_POLYHEDRA );
1653 if ( theType == SMESH::ALL || theType == SMESH::ELEM0D )
1655 typeIds.append( SMESH::Geom_POINT );
1657 if ( theType == SMESH::ALL || theType == SMESH::BALL )
1659 typeIds.append( SMESH::Geom_BALL );
1664 //=======================================================================
1665 // name : entityTypes
1666 // Purpose : returns available entity types of elements
1667 //=======================================================================
1669 static QList<int> entityTypes( const int theType )
1673 if ( theType == SMESH::EDGE )
1675 typeIds.append( SMDSEntity_Edge );
1676 typeIds.append( SMDSEntity_Quad_Edge );
1678 if ( theType == SMESH::FACE )
1680 typeIds.append( SMDSEntity_Quadrangle );
1681 typeIds.append( SMDSEntity_Quad_Quadrangle );
1682 typeIds.append( SMDSEntity_BiQuad_Quadrangle );
1684 if ( theType == SMESH::VOLUME )
1686 typeIds.append( SMDSEntity_Hexa );
1687 typeIds.append( SMDSEntity_Quad_Hexa );
1688 typeIds.append( SMDSEntity_TriQuad_Hexa );
1693 //=======================================================================
1694 // name : SMESHGUI_FilterTable::onCriterionChanged()
1695 // Purpose : Provides reaction on change of criterion
1696 //=======================================================================
1698 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1700 int aType = entityType == -1 ? GetType() : entityType;
1701 Table* aTable = myTables[ aType ];
1702 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1704 int aCriterionType = GetCriterionType(row);
1705 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1706 int aComboType = ComboItem::Type();
1707 int aIntSpinType = IntSpinItem::Type();
1708 int aDoubleSpinType = DoubleSpinItem::Type();
1709 QTableWidgetItem* aTableItem = aTable->item(row, 2);
1710 bool isComboItem = false;
1711 bool isIntSpinItem = false;
1712 bool isDoubleSpinItem = false;
1714 int aTableType = aTable->item(row, 2)->type();
1715 isComboItem = ( aTableType == aComboType );
1716 isIntSpinItem = ( aTableType == aIntSpinType );
1717 isDoubleSpinItem = ( aTableType == aDoubleSpinType );
1720 bool anIsDoubleCriterion =
1721 aCriterionType == SMESH::FT_AspectRatio ||
1722 aCriterionType == SMESH::FT_AspectRatio3D ||
1723 aCriterionType == SMESH::FT_Taper ||
1724 aCriterionType == SMESH::FT_Warping ||
1725 aCriterionType == SMESH::FT_MinimumAngle ||
1726 aCriterionType == SMESH::FT_Skew ||
1727 aCriterionType == SMESH::FT_Area ||
1728 aCriterionType == SMESH::FT_Length ||
1729 aCriterionType == SMESH::FT_Length2D ||
1730 aCriterionType == SMESH::FT_MaxElementLength2D ||
1731 aCriterionType == SMESH::FT_MaxElementLength3D ||
1732 aCriterionType == SMESH::FT_Volume3D ||
1733 aCriterionType == SMESH::FT_EntityType;
1735 if ( anIsDoubleCriterion ) {
1736 const char* aPrecisionType = getPrecision( aCriterionType );
1737 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1738 if( aPrecisionType && aResourceMgr )
1739 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1742 // if the precision is to be changed we should remove the existing
1743 // spin item and create another one with new precision
1744 bool anIsPrecisionChanged = false;
1745 if ( anIsDoubleCriterion && isDoubleSpinItem ) {
1746 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
1747 anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
1751 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1752 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
1753 (aCriterionType != SMESH::FT_EntityType && isComboItem) ||
1754 (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
1755 (!anIsDoubleCriterion && isDoubleSpinItem) ||
1756 anIsPrecisionChanged )
1758 bool isSignalsBlocked = aTable->signalsBlocked();
1759 aTable->blockSignals( true );
1760 aTable->removeCellWidget( row, 2 );
1761 aTable->setItem( row, 2, new QTableWidgetItem() );
1762 aTable->blockSignals( isSignalsBlocked );
1764 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1765 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
1766 (aCriterionType == SMESH::FT_EntityType && !isComboItem) ||
1767 (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
1768 (anIsDoubleCriterion && !isDoubleSpinItem) ||
1769 anIsPrecisionChanged )
1771 bool isSignalsBlocked = aTable->signalsBlocked();
1772 aTable->blockSignals( true );
1773 if ( aCriterionType == SMESH::FT_GroupColor )
1774 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1775 else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
1776 QList<int> typeIds = geomTypes( aType );
1777 QMap<int, QString> typeNames;
1778 QList<int>::const_iterator anIter = typeIds.begin();
1779 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1781 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1782 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1784 ComboItem* typeBox = new ComboItem( typeNames );
1785 aTable->setItem( row, 2, typeBox );
1787 else if ( aCriterionType == SMESH::FT_EntityType ) {
1788 QList<int> typeIds = entityTypes( aType );
1789 QMap<int, QString> typeNames;
1790 QList<int>::const_iterator anIter = typeIds.begin();
1791 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1793 QString typeKey = QString( "ENTITY_TYPE_%1" ).arg( *anIter );
1794 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1796 ComboItem* typeBox = new ComboItem( typeNames );
1797 aTable->setItem( row, 2, typeBox );
1799 else if ( aCriterionType == SMESH::FT_MultiConnection ) {
1800 IntSpinItem* intSpin = new IntSpinItem( 0 );
1801 aTable->setItem( row, 2, intSpin );
1803 else if ( anIsDoubleCriterion ) {
1804 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1805 dblSpin->setPrecision( aPrecision );
1806 aTable->setItem( row, 2, dblSpin );
1808 aTable->blockSignals( isSignalsBlocked );
1811 // set Compare and enable/desable Threshold
1812 if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes ||
1813 aCriterionType == SMESH::FT_EqualNodes )) ||
1814 (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders ||
1815 aCriterionType == SMESH::FT_EqualEdges )) ||
1816 (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace ||
1817 aCriterionType == SMESH::FT_OverConstrainedFace ||
1818 aCriterionType == SMESH::FT_FreeEdges ||
1819 aCriterionType == SMESH::FT_FreeFaces ||
1820 aCriterionType == SMESH::FT_EqualFaces)) ||
1821 (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume ||
1822 aCriterionType == SMESH::FT_OverConstrainedVolume ||
1823 aCriterionType == SMESH::FT_BareBorderVolume ||
1824 aCriterionType == SMESH::FT_EqualVolumes )) ||
1825 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1826 aCriterionType == SMESH::FT_GroupColor ||
1827 aCriterionType == SMESH::FT_ElemGeomType ||
1828 aCriterionType == SMESH::FT_CoplanarFaces ||
1829 aCriterionType == SMESH::FT_EntityType
1832 bool isSignalsBlocked = aTable->signalsBlocked();
1833 aTable->blockSignals( true );
1835 if (aCompareItem->count() > 0)
1836 aCompareItem->clear();
1837 aTable->setEditable(false, row, 1);
1838 aTable->item(row, 2)->setText( QString("") );
1839 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1840 aCriterionType == SMESH::FT_ElemGeomType ||
1841 aCriterionType == SMESH::FT_EntityType ||
1842 aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
1843 aTable->blockSignals( isSignalsBlocked );
1845 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1846 aCriterionType == SMESH::FT_BelongToGeom ||
1847 aCriterionType == SMESH::FT_BelongToPlane ||
1848 aCriterionType == SMESH::FT_BelongToCylinder ||
1849 aCriterionType == SMESH::FT_BelongToGenSurface ||
1850 aCriterionType == SMESH::FT_LyingOnGeom)
1852 QMap<int, QString> aMap;
1853 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1854 aCompareItem->setItems(aMap);
1855 if (!aTable->isEditable(row, 2))
1856 aTable->setEditable(true, row, 1);
1857 if (!aTable->isEditable(row, 2))
1858 aTable->setEditable(true, row, 2);
1860 else if (aCriterionType == SMESH::FT_GroupColor ||
1861 aCriterionType == SMESH::FT_ElemGeomType ||
1862 aCriterionType == SMESH::FT_EntityType)
1864 if (!aTable->isEditable(row, 2))
1865 aTable->setEditable(true, row, 2);
1869 if (aCompareItem && aCompareItem->count() != 3)
1871 aCompareItem->setItems(getCompare());
1874 if (aTable->item( row, 2 )) {
1875 QString aText = aTable->text(row, 2);
1877 aText.toDouble(&isOk);
1878 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1879 if (!aTable->isEditable(row, 1))
1880 aTable->setEditable(true, row, 1);
1881 if (!aTable->isEditable(row, 2))
1882 aTable->setEditable(true, row, 2);
1886 updateAdditionalWidget();
1888 emit CriterionChanged(row, entityType);
1891 //=======================================================================
1892 // name : SMESHGUI_FilterTable::onCriterionChanged()
1893 // Purpose : SLOT. Called then contents of table changed
1894 // Provides reaction on change of criterion
1895 //=======================================================================
1896 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1899 onCriterionChanged(row, col, -1);
1902 //=======================================================================
1903 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1904 // Purpose : Get first selected row
1905 //=======================================================================
1906 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1908 Table* aTable = myTables[ GetType() ];
1910 QList<int> selRows = aTable->selectedRows(); // already sorted
1911 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1913 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1916 //=======================================================================
1917 // name : SMESHGUI_FilterTable::addRow
1918 // Purpose : Add row at the end of table
1919 //=======================================================================
1920 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1923 int aSelectedRow = getFirstSelectedRow();
1924 int aCurrCol = theTable->currentColumn();
1927 if (toTheEnd || aSelectedRow == -1)
1929 theTable->insertRows(theTable->rowCount());
1930 aCurrRow = theTable->rowCount() - 1;
1934 theTable->insertRows(aSelectedRow);
1935 aCurrRow = aSelectedRow;
1939 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1940 bool isSignalsBlocked = theTable->signalsBlocked();
1941 theTable->blockSignals( true );
1944 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1947 theTable->setItem(aCurrRow, 1, getCompareItem());
1950 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1952 // Logical operation NOT
1953 theTable->setItem(aCurrRow, 3, getUnaryItem());
1955 // Logical operation AND / OR
1956 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1958 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1960 theTable->blockSignals( isSignalsBlocked );
1962 // Logical binary operation for previous value
1963 int anAddBinOpStr = -1;
1964 if (aCurrRow == theTable->rowCount() - 1)
1965 anAddBinOpStr = aCurrRow - 1;
1966 else if (aCurrRow >= 0 )
1967 anAddBinOpStr = aCurrRow;
1969 if (theTable->item(aCurrRow, 4) == 0 ||
1970 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1972 if (anAddBinOpStr >= 0 &&
1973 (theTable->item(anAddBinOpStr, 4) == 0 ||
1974 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1975 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1978 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1980 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1981 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1982 theTable->setCurrentCell(aCurrRow, aCurrCol);
1984 onCriterionChanged(aCurrRow, 0);
1989 //=======================================================================
1990 // name : SMESHGUI_FilterTable::getCriterionItem
1991 // Purpose : Get combo table item for criteria of specified type
1992 //=======================================================================
1993 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1995 return new ComboItem(getCriteria(theType));
1998 //=======================================================================
1999 // name : SMESHGUI_FilterTable::getCompareItem
2000 // Purpose : Get combo table item for operation of comparision
2001 //=======================================================================
2002 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
2004 return new ComboItem(getCompare());
2007 //=======================================================================
2008 // name : SMESHGUI_FilterTable::getBinaryItem
2010 //=======================================================================
2011 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
2013 static QMap<int, QString> aMap;
2016 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
2017 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
2020 return new ComboItem(aMap);
2023 //=======================================================================
2024 // name : SMESHGUI_FilterTable::getUnaryItem
2025 // Purpose : Get check table item
2026 //=======================================================================
2027 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
2029 return new CheckItem(tr("NOT"));
2032 //=======================================================================
2033 // name : SMESHGUI_FilterTable::getSupportedTypes
2034 // Purpose : Get all supported type
2035 //=======================================================================
2036 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
2038 static QMap<int, QString> aTypes;
2039 if (aTypes.isEmpty())
2041 aTypes[ SMESH::NODE ] = tr("NODES");
2042 aTypes[ SMESH::ELEM0D ] = tr("ELEM0D");
2043 aTypes[ SMESH::BALL ] = tr("BALLS");
2044 aTypes[ SMESH::EDGE ] = tr("EDGES");
2045 aTypes[ SMESH::FACE ] = tr("FACES");
2046 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
2047 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
2053 //=======================================================================
2054 // name : SMESHGUI_FilterTable::getCriteria
2055 // Purpose : Get criteria for specified type
2056 //=======================================================================
2057 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
2059 if (theType == SMESH::NODE)
2061 static QMap<int, QString> aCriteria;
2062 if (aCriteria.isEmpty())
2064 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2065 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2066 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2067 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2068 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2069 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2070 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
2071 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2072 aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
2076 else if (theType == SMESH::EDGE)
2078 static QMap<int, QString> aCriteria;
2079 if (aCriteria.isEmpty())
2081 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
2082 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
2083 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
2084 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2085 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2086 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2087 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2088 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2089 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2090 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2091 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2092 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2093 aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
2094 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2098 else if (theType == SMESH::FACE)
2100 static QMap<int, QString> aCriteria;
2101 if (aCriteria.isEmpty())
2103 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
2104 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
2105 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
2106 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
2107 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
2108 aCriteria[ SMESH::FT_Area ] = tr("AREA");
2109 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2110 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
2111 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2112 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2113 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2114 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2115 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2116 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2117 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
2118 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
2119 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
2120 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
2121 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2122 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2123 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2124 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2125 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
2126 aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
2127 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2131 else if (theType == SMESH::VOLUME)
2133 static QMap<int, QString> aCriteria;
2134 if (aCriteria.isEmpty())
2136 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
2137 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2138 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2139 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2140 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
2141 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
2142 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2143 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
2144 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
2145 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2146 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2147 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2148 aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
2149 aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
2153 else if (theType == SMESH::ELEM0D)
2155 static QMap<int, QString> aCriteria;
2156 if (aCriteria.isEmpty())
2158 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2159 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2160 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2161 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2162 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2163 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2167 else if (theType == SMESH::BALL)
2169 static QMap<int, QString> aCriteria;
2170 if (aCriteria.isEmpty())
2172 aCriteria[ SMESH::FT_BallDiameter ] = tr("BALL_DIAMETER");
2173 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2174 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2175 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2176 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2177 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2178 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2182 else if (theType == SMESH::ELEM0D)
2184 static QMap<int, QString> aCriteria;
2185 if (aCriteria.isEmpty())
2187 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2188 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2189 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2190 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2191 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2192 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2198 static QMap<int, QString> aCriteria;
2199 if (aCriteria.isEmpty())
2201 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2202 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2203 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2204 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2205 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2206 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2214 //=======================================================================
2215 // name : SMESHGUI_FilterTable::getCompare
2216 // Purpose : Get operation of comparison
2217 //=======================================================================
2218 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2220 static QMap<int, QString> aMap;
2224 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2225 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2226 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
2232 //=======================================================================
2233 // name : SMESHGUI_FilterTable::createTable
2234 // Purpose : Create table
2235 //=======================================================================
2236 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
2240 Table* aTable= new Table(0, 6, theParent);
2242 QHeaderView* aHeaders = aTable->horizontalHeader();
2244 QFontMetrics aMetrics(aHeaders->font());
2246 // append spaces to the header of criteria in order to
2247 // provide visibility of criterion inside comboboxes
2248 static int aMaxLenCr = 0;
2252 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2253 QMap<int, QString>::const_iterator anIter;
2254 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2255 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2258 static int aLenCr = qAbs( aMaxLenCr -
2259 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2262 aCrStr.fill(' ', aLenCr);
2264 aCoStr.fill(' ', 10);
2266 QStringList aHeaderLabels;
2267 aHeaderLabels.append( tr("CRITERION") + aCrStr );
2268 aHeaderLabels.append( tr("COMPARE") + aCoStr );
2269 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2270 aHeaderLabels.append( tr("UNARY") );
2271 aHeaderLabels.append( tr("BINARY") + " " );
2272 aHeaderLabels.append( tr("ID") );
2273 aTable->setHorizontalHeaderLabels( aHeaderLabels );
2275 // set geometry of the table
2276 for (int i = 0; i <= 4; i++)
2277 aTable->resizeColumnToContents(i);
2279 // set the ID column invisible
2280 aTable->hideColumn( 5 );
2282 aTable->updateGeometry();
2283 QSize aSize = aTable->sizeHint();
2284 int aWidth = aSize.width();
2285 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2286 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2288 connect(aTable, SIGNAL(cellChanged(int, int)),
2289 this, SLOT(onCriterionChanged(int, int)));
2291 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2292 this, SLOT(onCurrentChanged(int, int)));
2297 //=======================================================================
2298 // name : SMESHGUI_FilterTable::updateBtnState
2299 // Purpose : Update button state
2300 //=======================================================================
2301 void SMESHGUI_FilterTable::updateBtnState()
2303 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2304 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2307 //=======================================================================
2308 // name : SMESHGUI_FilterTable::SetEditable
2309 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2310 //=======================================================================
2311 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2313 TableMap::iterator anIter;
2314 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2316 anIter.value()->setReadOnly(!isEditable);
2318 // Set Flags for CheckItems directly IPAL 19974
2319 Table* aTable = anIter.value();
2320 for (int i = 0, n = aTable->rowCount(); i < n; i++)
2321 for (int j = 0, m = aTable->columnCount(); j < m; j++)
2323 QTableWidgetItem* anItem = aTable->item(i, j);
2324 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2325 Qt::ItemFlags f = anItem->flags();
2326 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2327 else f = f | Qt::ItemIsUserCheckable;
2328 anItem->setFlags( f );
2336 myInsertBtn->show();
2337 myRemoveBtn->show();
2343 myInsertBtn->hide();
2344 myRemoveBtn->hide();
2349 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2350 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2351 anIter2.value()->SetEditable(isEditable);
2354 //=======================================================================
2355 // name : SMESHGUI_FilterTable::SetEnabled
2356 // Purpose : Enable/Disable table. Switching type of elements already enabled
2357 //=======================================================================
2358 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2360 myAddBtn->setEnabled(isEnabled);
2361 myInsertBtn->setEnabled(isEnabled);
2362 myRemoveBtn->setEnabled(isEnabled);
2363 myClearBtn->setEnabled(isEnabled);
2368 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2369 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2370 anIter2.value()->setEnabled(isEnabled);
2373 //=======================================================================
2374 // name : SMESHGUI_FilterTable::IsEditable
2375 // Purpose : Verify whether table is editable
2376 //=======================================================================
2377 bool SMESHGUI_FilterTable::IsEditable() const
2379 return !myTables[ GetType() ]->isReadOnly();
2382 //=======================================================================
2383 // name : SMESHGUI_FilterTable::SetLibsEnabled
2384 // Purpose : Show/hide buttons for work with libraries
2385 //=======================================================================
2386 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2390 myCopyFromBtn->show();
2395 myCopyFromBtn->hide();
2400 //=======================================================================
2401 // name : SMESHGUI_FilterTable::onCopyFromBtn
2402 // Purpose : SLOT. Called the "Copy from ..." button clicked
2403 // Display filter library dialog
2404 //=======================================================================
2405 void SMESHGUI_FilterTable::onCopyFromBtn()
2408 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2409 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2411 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2413 if (myLibDlg->exec() == QDialog::Accepted)
2415 Copy(myLibDlg->GetTable());
2420 //=======================================================================
2421 // name : SMESHGUI_FilterTable::onAddToBtn
2422 // Purpose : SLOT. Called the "Add to ..." button clicked
2423 // Display filter library dialog
2424 //=======================================================================
2425 void SMESHGUI_FilterTable::onAddToBtn()
2430 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2431 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2433 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2435 myLibDlg->SetTable(this);
2440 //=======================================================================
2441 // name : SMESHGUI_FilterTable::Copy
2442 // Purpose : Initialise table with values of other table
2443 //=======================================================================
2444 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2448 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2450 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2451 theTable->GetCriterion(i, aCriterion);
2452 AddCriterion(aCriterion);
2456 //=======================================================================
2457 // name : SMESHGUI_FilterTable::CurrentCell
2458 // Purpose : Returns current cell
2459 //=======================================================================
2460 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2462 theRow = myTables[ GetType() ]->currentRow();
2463 theCol = myTables[ GetType() ]->currentColumn();
2464 return theRow >= 0 && theCol >= 0;
2467 //=======================================================================
2468 // name : SMESHGUI_FilterTable::SetText
2469 // Purpose : Set text and internal value in cell of threshold value
2470 //=======================================================================
2471 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2472 const QString& theText,
2473 const int theEntityType)
2475 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2476 aTable->item( theRow, 2 )->setText(theText);
2479 //=======================================================================
2480 // name : SMESHGUI_FilterTable::SetText
2481 // Purpose : Get text and internal value from cell of threshold value
2482 //=======================================================================
2483 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2485 const int theEntityType)
2487 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2488 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2491 theText = anItem->text();
2498 //=======================================================================
2499 // name : SMESHGUI_FilterTable::SetID
2500 // Purpose : Set text and internal value in cell of ID value
2501 //=======================================================================
2502 void SMESHGUI_FilterTable::SetID( const int theRow,
2503 const QString& theText,
2504 const int theEntityType )
2506 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2507 aTable->item( theRow, 5 )->setText( theText );
2510 //=======================================================================
2511 // name : SMESHGUI_FilterTable::GetID
2512 // Purpose : Get text and internal value from cell of ID value
2513 //=======================================================================
2514 bool SMESHGUI_FilterTable::GetID( const int theRow,
2516 const int theEntityType )
2518 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2519 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2522 theText = anItem->text();
2530 Class : SMESHGUI_FilterDlg
2531 Description : Dialog to specify filters for VTK viewer
2535 //=======================================================================
2536 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2537 // Purpose : Constructor
2538 //=======================================================================
2539 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2540 const QList<int>& theTypes )
2541 : QDialog( SMESH::GetDesktop( theModule ) ),
2542 mySMESHGUI( theModule ),
2543 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2544 myInitSourceWgOnApply( true )
2546 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2547 mySelector = aViewWindow->GetSelector();
2549 construct(theTypes);
2552 //=======================================================================
2553 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2554 // Purpose : Constructor
2555 //=======================================================================
2556 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2558 : QDialog( SMESH::GetDesktop( theModule ) ),
2559 mySMESHGUI( theModule ),
2560 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2561 myInitSourceWgOnApply( true )
2563 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2564 mySelector = aViewWindow->GetSelector();
2566 aTypes.append(theType);
2570 //=======================================================================
2571 // name : SMESHGUI_FilterDlg::construct
2572 // Purpose : Construct dialog (called by constructor)
2573 //=======================================================================
2574 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2579 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2580 setWindowTitle(tr("CAPTION"));
2582 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2583 aDlgLay->setMargin(MARGIN);
2584 aDlgLay->setSpacing(SPACING);
2586 myMainFrame = createMainFrame (this);
2587 QWidget* aBtnFrame = createButtonFrame(this);
2589 aDlgLay->addWidget(myMainFrame);
2590 aDlgLay->addWidget(aBtnFrame);
2592 aDlgLay->setStretchFactor(myMainFrame, 1);
2594 myHelpFileName = "selection_filter_library_page.html";
2599 //=======================================================================
2600 // name : SMESHGUI_FilterDlg::createMainFrame
2601 // Purpose : Create frame containing dialog's input fields
2602 //=======================================================================
2603 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2605 QWidget* aMainFrame = new QWidget(theParent);
2606 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2607 aMainLay->setMargin(0);
2608 aMainLay->setSpacing(SPACING);
2612 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2613 myTable->SetLibsEnabled(true);
2615 QGroupBox* aGrp = myTable->GetTableGrp();
2616 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2617 int rows = aLay->rowCount();
2618 int cols = aLay->columnCount();
2620 QFrame* aLine = new QFrame(aGrp);
2621 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2622 aLay->addWidget(aLine, rows++, 0, 1, cols);
2624 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2625 mySetInViewer->setChecked(true);
2626 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2629 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2631 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2632 SLOT(onCriterionChanged(const int, const int)));
2634 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2635 SLOT(onCurrentChanged(int, int)));
2637 aMainLay->addWidget(myTable);
2638 aMainLay->addWidget(aSourceGrp);
2643 //=======================================================================
2644 // name : SMESHGUI_FilterDlg::createSourceFrame
2645 // Purpose : Create frame containing source radio button
2646 //=======================================================================
2647 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2649 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2650 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2651 aLay->setMargin(MARGIN);
2652 aLay->setSpacing(SPACING);
2654 mySourceGrp = new QButtonGroup(theParent);
2656 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2657 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2658 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2660 aLay->addWidget(aMeshBtn);
2661 aLay->addWidget(aSelBtn);
2662 aLay->addWidget(aDlgBtn);
2664 mySourceGrp->addButton(aMeshBtn, Mesh);
2665 mySourceGrp->addButton(aSelBtn, Selection);
2666 mySourceGrp->addButton(aDlgBtn, Dialog);
2668 aMeshBtn->setChecked(true);
2673 //=======================================================================
2674 // name : SMESHGUI_FilterDlg::updateMainButtons
2675 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2676 //=======================================================================
2677 void SMESHGUI_FilterDlg::updateMainButtons()
2679 myButtons[ BTN_Close ]->show();
2680 if (myTypes.count() == 1)
2682 myButtons[ BTN_Apply ]->hide();
2686 myButtons[ BTN_Apply ]->show();
2688 // updateGeometry();
2691 //=======================================================================
2692 // name : SMESHGUI_FilterDlg::createButtonFrame
2693 // Purpose : Create frame containing buttons
2694 //=======================================================================
2695 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2697 QGroupBox* aGrp = new QGroupBox(theParent);
2698 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2699 aLay->setMargin(MARGIN);
2700 aLay->setSpacing(SPACING);
2702 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2703 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2704 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2705 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2707 aLay->addWidget(myButtons[ BTN_OK ]);
2708 aLay->addSpacing(10);
2709 aLay->addWidget(myButtons[ BTN_Apply ]);
2710 aLay->addSpacing(10);
2712 aLay->addWidget(myButtons[ BTN_Close ]);
2713 aLay->addWidget(myButtons[ BTN_Help ]);
2715 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2716 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(reject()));
2717 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2718 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2720 updateMainButtons();
2725 //=======================================================================
2726 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2727 // Purpose : Destructor
2728 //=======================================================================
2729 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2733 //=======================================================================
2734 // name : SMESHGUI_FilterDlg::Init
2735 // Purpose : Init dialog fields, connect signals and slots, show dialog
2736 //=======================================================================
2737 void SMESHGUI_FilterDlg::Init (const int type, const bool setInViewer)
2740 aTypes.append(type);
2741 Init(aTypes,setInViewer);
2744 //=======================================================================
2745 // name : SMESHGUI_FilterDlg::Init
2746 // Purpose : Init dialog fields, connect signals and slots, show dialog
2747 //=======================================================================
2748 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewer)
2752 myMesh = SMESH::SMESH_Mesh::_nil();
2754 myIsSelectionChanged = false;
2756 myTable->Init(theTypes);
2759 if (theTypes.count() == 1)
2761 int aType = theTypes.first();
2762 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2763 else if (aType == SMESH::ELEM0D) setWindowTitle(tr("ELEM0D_TLT"));
2764 else if (aType == SMESH::BALL ) setWindowTitle(tr("BALL_TLT"));
2765 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2766 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2767 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2768 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2771 setWindowTitle(tr("TLT"));
2773 qApp->processEvents();
2778 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2780 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2781 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
2783 updateMainButtons();
2786 // Initialise filter table with values of previous filter
2787 QList<int>::const_iterator anIter;
2788 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2790 myTable->Clear(*anIter);
2791 if (!myFilter[ *anIter ]->_is_nil())
2793 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2794 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2796 for (int i = 0, n = aCriteria->length(); i < n; i++)
2797 myTable->AddCriterion(aCriteria[ i ], *anIter);
2802 if (myInsertState.contains(theTypes.first()))
2803 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2805 mySetInViewer->setChecked(setInViewer);
2807 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2808 myApplyToState[ theTypes.first() ] :
2809 Mesh)->setChecked(true);
2812 //=======================================================================
2813 // name : SMESHGUI_FilterDlg::onOk
2814 // Purpose : SLOT called when "Ok" button pressed.
2815 // Assign filters VTK viewer and close dialog
2816 //=======================================================================
2817 void SMESHGUI_FilterDlg::onOk()
2821 mySelectionMgr->clearFilters();
2822 disconnect(mySMESHGUI, 0, this, 0);
2823 disconnect(mySelectionMgr, 0, this, 0);
2824 mySMESHGUI->ResetState();
2830 //=======================================================================
2831 // name : SMESHGUI_FilterDlg::reject
2832 // Purpose : SLOT called when "Close" button pressed. Close dialog
2833 //=======================================================================
2834 void SMESHGUI_FilterDlg::reject()
2836 // Restore previously selected object
2839 SALOME_ListIO aList;
2840 mySelectionMgr->clearFilters();
2841 mySelectionMgr->clearSelected();
2842 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2843 for ( ; anIter.More(); anIter.Next())
2845 aList.Append(anIter.Key());
2847 TColStd_MapOfInteger aResMap;
2848 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2849 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2850 aResMap.Add(anIndMap(i));
2852 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2853 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2854 aViewWindow->highlight( anIter.Key(), true, true );
2856 mySelectionMgr->setSelectedObjects(aList, false);
2859 disconnect(mySMESHGUI, 0, this, 0);
2860 disconnect(mySelectionMgr, 0, this, 0);
2861 mySMESHGUI->ResetState();
2865 //=================================================================================
2866 // function : onHelp()
2868 //=================================================================================
2869 void SMESHGUI_FilterDlg::onHelp()
2871 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2873 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2877 platform = "winapplication";
2879 platform = "application";
2881 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2882 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2883 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2885 arg(myHelpFileName));
2889 //=======================================================================
2890 // name : SMESHGUI_FilterDlg::onDeactivate
2891 // Purpose : SLOT called when dialog must be deativated
2892 //=======================================================================
2893 void SMESHGUI_FilterDlg::onDeactivate()
2898 //=======================================================================
2899 // name : SMESHGUI_FilterDlg::enterEvent
2900 // Purpose : Event filter
2901 //=======================================================================
2902 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2904 // mySMESHGUI->EmitSignalDeactivateDialog();
2905 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2906 mySMESHGUI->ResetState();
2910 //=======================================================================
2911 // name : SMESHGUI_FilterDlg::getIdsFromWg
2912 // Purpose : Retrieve list of ids from given widget
2913 //=======================================================================
2914 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2920 if (theWg->inherits("QListWidget"))
2922 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2924 for (int i = 0, n = aListBox->count(); i < n; i++)
2926 int anId = aListBox->item(i)->text().toInt(&b);
2928 theRes.append(anId);
2931 else if (theWg->inherits("QLineEdit"))
2933 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2934 QString aStr = aLineEdit->text();
2935 QRegExp aRegExp("(\\d+)");
2940 aPos = aRegExp.indexIn(aStr, aPos);
2943 int anId = aRegExp.cap(1).toInt(&b);
2945 theRes.append(anId);
2946 aPos += aRegExp.matchedLength();
2952 //=======================================================================
2953 // name : SMESHGUI_FilterDlg::getSelMode
2954 // Purpose : Get selection mode of specified type
2955 //=======================================================================
2956 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2960 case SMESH::NODE : return NodeSelection;
2961 case SMESH::ELEM0D : return Elem0DSelection;
2962 case SMESH::BALL : return BallSelection;
2963 case SMESH::EDGE : return EdgeSelection;
2964 case SMESH::FACE : return FaceSelection;
2965 case SMESH::VOLUME : return VolumeSelection;
2966 case SMESH::ALL : return CellSelection;
2967 default : return ActorSelection;
2972 //=======================================================================
2973 // name : SMESHGUI_FilterDlg::setIdsToWg
2974 // Purpose : Insert identifiers in specified widgets
2975 //=======================================================================
2976 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2981 QStringList aStrList;
2982 foreach(int id, theIds)
2983 aStrList << QString::number(id);
2985 if (theWg->inherits("QListWidget"))
2987 qobject_cast<QListWidget*>(theWg)->clear();
2988 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2990 else if (theWg->inherits("QLineEdit"))
2992 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2996 //=======================================================================
2997 // name : SMESHGUI_FilterDlg::isValid
2998 // Purpose : Verify validity of input data
2999 //=======================================================================
3000 bool SMESHGUI_FilterDlg::isValid() const
3002 if (!myTable->IsValid())
3005 for (int i = 0, n = myTable->NumRows(); i < n; i++)
3007 int aType = myTable->GetCriterionType(i);
3008 if (aType == SMESH::FT_BelongToGeom ||
3009 aType == SMESH::FT_BelongToPlane ||
3010 aType == SMESH::FT_BelongToCylinder ||
3011 aType == SMESH::FT_BelongToGenSurface ||
3012 aType == SMESH::FT_LyingOnGeom)
3015 myTable->GetThreshold(i, aName);
3017 std::vector<_PTR(SObject)> aList =
3018 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
3019 if (aList.size() == 0) {
3020 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3021 tr("BAD_SHAPE_NAME").arg(aName));
3025 if (aType == SMESH::FT_BelongToCylinder ||
3026 aType == SMESH::FT_BelongToPlane ||
3027 aType == SMESH::FT_BelongToGenSurface ) {
3028 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
3029 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
3030 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
3031 if (!aGeomObj->_is_nil()) {
3033 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
3035 aFace.ShapeType() != TopAbs_FACE) {
3036 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3037 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3041 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
3042 if (aSurf.IsNull()) {
3043 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3044 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
3048 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
3049 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3050 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
3054 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
3055 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3056 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
3062 else if (aType == SMESH::FT_CoplanarFaces)
3065 myTable->GetThreshold(i, faceID);
3066 if ( faceID.isEmpty() )
3068 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3069 tr("FACE_ID_NOT_SELECTED"));
3072 if ( myMesh->_is_nil() )
3074 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3075 tr("MESH_IS_NOT_SELECTED"));
3078 if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
3080 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3081 tr("NOT_FACE_ID").arg(faceID));
3090 //=======================================================================
3091 // name : SMESHGUI_FilterDlg::SetSourceWg
3092 // Purpose : Set widget of parent dialog containing ids to be filtered if
3093 // user select corresponding source radio button
3094 //=======================================================================
3095 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
3096 const bool initOnApply)
3099 myInitSourceWgOnApply = initOnApply;
3102 //=======================================================================
3103 // name : SMESHGUI_FilterDlg::SetMesh
3104 // Purpose : Set mesh
3105 //=======================================================================
3106 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
3108 if ( !theMesh->_is_nil() ) {
3110 if ( !myFilter[ myTable->GetType() ]->_is_nil())
3111 myFilter[ myTable->GetType() ]->SetMesh( theMesh );
3113 const bool isEnable = !(myMesh->_is_nil());
3114 myButtons[BTN_OK]->setEnabled(isEnable);
3115 myButtons[BTN_Apply]->setEnabled(isEnable);
3118 //=======================================================================
3119 // name : SMESHGUI_FilterDlg::SetSelection
3120 // Purpose : Get filtered ids
3121 //=======================================================================
3122 void SMESHGUI_FilterDlg::SetSelection()
3125 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3127 if (mySelectionMgr) {
3129 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
3130 SALOME_ListIteratorOfListIO anIter (anObjs);
3131 for ( ; anIter.More(); anIter.Next()) {
3132 TColStd_IndexedMapOfInteger aMap;
3133 mySelector->GetIndex(anIter.Value(), aMap);
3134 myIObjects.Bind(anIter.Value(), aMap);
3137 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3145 //=======================================================================
3146 // name : SMESHGUI_FilterDlg::onApply
3147 // Purpose : SLOT called when "Apply" button pressed.
3148 // Assign filters to VTK viewer
3149 //=======================================================================
3150 bool SMESHGUI_FilterDlg::onApply()
3156 int aCurrType = myTable->GetType();
3158 if (!createFilter(aCurrType))
3161 insertFilterInViewer();
3163 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3164 QList<int> aResultIds;
3165 filterSource(aCurrType, aResultIds);
3167 selectInViewer(aCurrType, aResultIds);
3171 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3172 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3174 catch(const SALOME::SALOME_Exception& S_ex)
3176 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3185 //=======================================================================
3186 // name : SMESHGUI_FilterDlg::createFilter
3187 // Purpose : Create predicate for given type
3188 //=======================================================================
3189 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3191 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3192 if (aFilterMgr->_is_nil())
3195 int n = myTable->NumRows();
3197 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3198 aCriteria->length(n);
3200 long aPrecision = -1;
3201 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3203 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3204 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3206 for (CORBA::ULong i = 0; i < n; i++) {
3207 SMESH::Filter::Criterion aCriterion = createCriterion();
3208 myTable->GetCriterion(i, aCriterion);
3209 aCriterion.Precision = aPrecision;
3210 aCriteria[ i ] = aCriterion;
3213 myFilter[ theType ] = aFilterMgr->CreateFilter();
3214 myFilter[ theType ]->SetCriteria(aCriteria.inout());
3219 //================================================================================
3221 * \brief Return the current filter
3223 //================================================================================
3225 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3227 SMESH::Filter_var filter;
3229 int aCurrType = myTable->GetType();
3230 filter = myFilter[ aCurrType ];
3235 return filter._retn();
3238 //================================================================================
3240 * \brief Sets a filter to the table
3242 //================================================================================
3244 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3246 myFilter[ type ] = filter;
3249 //=======================================================================
3250 // name : SMESHGUI_FilterDlg::insertFilterInViewer
3251 // Purpose : Insert filter in viewer
3252 //=======================================================================
3253 void SMESHGUI_FilterDlg::insertFilterInViewer()
3255 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3256 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3258 if (myFilter[ myTable->GetType() ]->_is_nil() ||
3259 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3260 !mySetInViewer->isChecked()) {
3261 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3264 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3265 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3266 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3267 SMESH::SetFilter(aFilter, aSelector);
3272 //=======================================================================
3273 // name : SMESHGUI_FilterDlg::filterSource
3274 // Purpose : Filter source ids
3275 //=======================================================================
3276 void SMESHGUI_FilterDlg::filterSource (const int theType,
3277 QList<int>& theResIds)
3280 if (myFilter[ theType ]->_is_nil())
3283 int aSourceId = mySourceGrp->checkedId();
3285 if (aSourceId == Mesh)
3287 if (myMesh->_is_nil())
3289 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3290 for (int i = 0, n = anIds->length(); i < n; i++)
3291 theResIds.append(anIds[ i ]);
3293 else if (aSourceId == Selection)
3295 filterSelectionSource(theType, theResIds);
3297 else if (aSourceId == Dialog)
3299 // retrieve ids from dialog
3300 QList<int> aDialogIds;
3301 getIdsFromWg(mySourceWg, aDialogIds);
3303 if (myMesh->_is_nil())
3305 theResIds = aDialogIds;
3310 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3311 myFilter[ theType ]->SetMesh(myMesh);
3312 QList<int>::const_iterator anIter;
3313 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3314 if (aPred->IsSatisfy(*anIter))
3315 theResIds.append(*anIter);
3317 // set ids to the dialog
3318 if (myInitSourceWgOnApply || aSourceId == Dialog)
3319 setIdsToWg(mySourceWg, theResIds);
3322 //=======================================================================
3323 // name : SMESHGUI_FilterDlg::filterSelectionSource
3324 // Purpose : Filter source selection
3325 //=======================================================================
3326 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3327 QList<int>& theResIds)
3330 if (myMesh->_is_nil() || mySelectionMgr == 0)
3333 // Create map of entities to be filtered
3334 TColStd_MapOfInteger aToBeFiltered;
3335 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3337 for ( ; anIter.More(); anIter.Next())
3340 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3341 if (!aSubMesh->_is_nil())
3343 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3345 SMESH::long_array_var anIds =
3346 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3347 for (int i = 0, n = anIds->length(); i < n; i++)
3348 aToBeFiltered.Add(anIds[ i ]);
3353 SMESH::SMESH_GroupBase_var aGroup =
3354 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3355 if (!aGroup->_is_nil())
3357 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3359 SMESH::long_array_var anIds = aGroup->GetListOfID();
3360 for (int i = 0, n = anIds->length(); i < n; i++)
3361 aToBeFiltered.Add(anIds[ i ]);
3366 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3367 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3369 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3371 if (aSelMap.Extent() > 0)
3373 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3375 for (int i = 1; i <= aSelMap.Extent(); i++)
3376 aToBeFiltered.Add(aSelMap(i));
3383 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3384 myFilter[ theType ]->SetMesh(myMesh);
3385 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3386 for ( ; aResIter.More(); aResIter.Next())
3387 if (aPred->IsSatisfy(aResIter.Key()))
3388 theResIds.append(aResIter.Key());
3391 //=======================================================================
3392 // name : SMESHGUI_FilterDlg::selectInViewer
3393 // Purpose : Select given entities in viewer
3394 //=======================================================================
3395 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3397 if (mySelectionMgr == 0 || myMesh->_is_nil())
3400 mySelectionMgr->clearFilters();
3402 // Set new selection mode if necessary
3403 Selection_Mode aSelMode = getSelMode(theType);
3404 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3405 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3406 mySelectionMgr->clearSelected();
3407 mySelectionMgr->clearFilters();
3408 if (aSelMode == NodeSelection)
3409 SMESH::SetPointRepresentation(true);
3410 aViewWindow->SetSelectionMode(aSelMode);
3414 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3415 if (!anActor || !anActor->hasIO())
3418 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3419 //mySelectionMgr->clearSelected();
3420 //mySelectionMgr->AddIObject(anIO, false);
3421 SALOME_ListIO aList;
3423 mySelectionMgr->setSelectedObjects(aList, false);
3425 // Remove filter corresponding to the current type from viewer
3426 int aType = myTable->GetType();
3427 int aFilterId = SMESH::UnknownFilter;
3428 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3429 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3430 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3431 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3432 SMESH::RemoveFilter(aFilterId);
3435 TColStd_MapOfInteger aMap;
3436 QList<int>::const_iterator anIter;
3437 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3441 // Set new selection
3442 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3443 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3444 aViewWindow->highlight( anIO, true, true );
3446 // insert previously stored filter in viewer if necessary
3447 if (!aFilter.IsNull())
3448 SMESH::SetFilter(aFilter);
3451 //=======================================================================
3452 // name : SMESHGUI_FilterDlg::createCriterion
3453 // Purpose : Create criterion structure with default values
3454 //=======================================================================
3455 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3457 SMESH::Filter::Criterion aCriterion;
3459 aCriterion.Type = SMESH::FT_Undefined;
3460 aCriterion.Compare = SMESH::FT_Undefined;
3461 aCriterion.Threshold = 0;
3462 aCriterion.UnaryOp = SMESH::FT_Undefined;
3463 aCriterion.BinaryOp = SMESH::FT_Undefined;
3464 aCriterion.ThresholdStr = "";
3465 aCriterion.ThresholdID = "";
3466 aCriterion.TypeOfElement = SMESH::ALL;
3471 //=======================================================================
3472 // name : SMESHGUI_FilterDlg::onSelectionDone
3473 // Purpose : SLOT called when selection changed.
3474 // If current cell corresponds to the threshold value of
3475 // BelongToGeom criterion name of selected object is set in this cell
3476 //=======================================================================
3477 void SMESHGUI_FilterDlg::onSelectionDone()
3480 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3482 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3483 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3484 if ( !(myMesh->_is_nil()) ) {
3485 myButtons[BTN_OK]->setEnabled(true);
3486 myButtons[BTN_Apply]->setEnabled(true);
3491 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3492 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3493 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces;
3494 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
3495 !types.contains(myTable->GetCriterionType(aRow)))
3498 if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
3501 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
3502 aList.First(), aString);
3504 myTable->SetThreshold(aRow, aString);
3508 Handle(SALOME_InteractiveObject) anIO = aList.First();
3509 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3510 if (!anObj->_is_nil())
3512 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3513 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3514 myTable->SetID(aRow, anIO->getEntry());
3520 //=======================================================================
3521 // name : SMESHGUI_FilterDlg::onCriterionChanged
3522 // Purpose : SLOT called when cretarion of current row changed. Update selection
3523 //=======================================================================
3524 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3529 //=======================================================================
3530 // name : SMESHGUI_FilterDlg::onCurrentChanged
3531 // Purpose : SLOT called when current row changed. Update selection
3532 //=======================================================================
3533 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3538 //=======================================================================
3539 // name : SMESHGUI_FilterDlg::updateSelection
3540 // Purpose : UpdateSelection in accordance with current row
3541 //=======================================================================
3542 void SMESHGUI_FilterDlg::updateSelection()
3544 if (mySelectionMgr == 0)
3547 // TColStd_MapOfInteger allTypes;
3548 // for( int i=0; i<10; i++ )
3549 // allTypes.Add( i );
3550 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3555 mySelectionMgr->clearFilters();
3559 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3560 int aCriterionType = myTable->GetCriterionType(aRow);
3561 if ( isCurrentCell &&
3562 (aCriterionType == SMESH::FT_BelongToGeom ||
3563 aCriterionType == SMESH::FT_BelongToPlane ||
3564 aCriterionType == SMESH::FT_BelongToCylinder ||
3565 aCriterionType == SMESH::FT_BelongToGenSurface ||
3566 aCriterionType == SMESH::FT_LyingOnGeom))
3568 if (aCriterionType == SMESH::FT_BelongToGeom ||
3569 aCriterionType == SMESH::FT_BelongToGenSurface ||
3570 aCriterionType == SMESH::FT_LyingOnGeom) {
3572 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3574 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3575 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3577 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3578 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3580 myIsSelectionChanged = true;
3585 mySelector->SetSelectionMode( getSelMode( myTable->GetType() ));
3587 if (myIsSelectionChanged) {
3588 // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3589 // Impossible to select any object in the OB on the second opening of FilterDlg
3594 //=================================================================================
3595 // function : keyPressEvent()
3597 //=================================================================================
3598 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3600 QDialog::keyPressEvent( e );
3601 if ( e->isAccepted() )
3604 if ( e->key() == Qt::Key_F1 ) {