1 // Copyright (C) 2007-2012 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // SMESH SMESHGUI : GUI for SMESH component
24 // File : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN, Open CASCADE S.A.S.
29 #include "SMESHGUI_FilterDlg.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_Filter.h"
35 #include "SMESHGUI_FilterUtils.h"
36 #include "SMESHGUI_FilterLibraryDlg.h"
37 #include "SMESHGUI_SpinBox.h"
39 #include <SMESH_Actor.h>
40 #include <SMESH_NumberFilter.hxx>
41 #include <SMESH_TypeFilter.hxx>
43 // SALOME GEOM includes
45 #include <GEOM_FaceFilter.h>
46 #include <GEOM_TypeFilter.h>
48 // SALOME GUI includes
49 #include <SUIT_Desktop.h>
50 #include <SUIT_ResourceMgr.h>
51 #include <SUIT_Session.h>
52 #include <SUIT_MessageBox.h>
53 #include <QtxColorButton.h>
55 #include <LightApp_Application.h>
56 #include <LightApp_SelectionMgr.h>
57 #include <SalomeApp_Tools.h>
58 #include <SalomeApp_Study.h>
59 #include <SalomeApp_IntSpinBox.h>
60 #include <SalomeApp_DoubleSpinBox.h>
62 #include <SALOME_ListIO.hxx>
63 #include <SALOME_ListIteratorOfListIO.hxx>
64 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
66 #include <SVTK_ViewWindow.h>
68 // SALOME KERNEL includes
69 #include <SALOMEDSClient_Study.hxx>
72 #include <StdSelect_TypeOfFace.hxx>
73 #include <BRep_Tool.hxx>
75 #include <TopoDS_Shape.hxx>
76 #include <Geom_Plane.hxx>
77 #include <Geom_CylindricalSurface.hxx>
78 #include <Precision.hxx>
79 #include <TColStd_MapOfInteger.hxx>
80 #include <TColStd_IndexedMapOfInteger.hxx>
81 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
86 #include <QPushButton>
88 #include <QTableWidget>
89 #include <QStringList>
90 #include <QHBoxLayout>
91 #include <QVBoxLayout>
92 #include <QGridLayout>
93 #include <QStackedWidget>
94 #include <QApplication>
96 #include <QFontMetrics>
98 #include <QButtonGroup>
99 #include <QRadioButton>
101 #include <QListWidget>
103 #include <QItemDelegate>
104 #include <QDoubleValidator>
106 #include <QHeaderView>
109 #include <SALOMEconfig.h>
110 #include CORBA_SERVER_HEADER(SMESH_Group)
115 //---------------------------------------
117 //---------------------------------------
118 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
121 QMap<int, QString>::const_iterator anIter;
122 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
123 aRes = qMax(aRes, theMetrics.width(anIter.value()));
127 //---------------------------------------
129 //---------------------------------------
130 static int getFilterId (SMESH::ElementType theType)
134 case SMESH::NODE : return SMESH::NodeFilter;
135 case SMESH::EDGE : return SMESH::EdgeFilter;
136 case SMESH::FACE : return SMESH::FaceFilter;
137 case SMESH::VOLUME : return SMESH::VolumeFilter;
138 case SMESH::ALL : return SMESH::AllElementsFilter;
139 default : return SMESH::UnknownFilter;
144 Class : SMESHGUI_FilterTable::AdditionalWidget
145 Description : Class for storing additional parameters of criterion
148 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
154 AdditionalWidget(QWidget* theParent);
155 virtual ~AdditionalWidget();
157 virtual QList<int> GetParameters() const;
158 virtual bool IsValid(const bool = true) const;
159 virtual double GetDouble(const int) const;
160 virtual int GetInteger(const int) const;
161 virtual QString GetString(const int) const;
162 virtual void SetDouble(const int, const double);
163 virtual void SetInteger(const int, const int);
164 virtual void SetString(const int, const QString&);
165 void SetEditable(const int, const bool);
166 void SetEditable(const bool);
167 void SetPrecision(const int, const char* = 0);
170 QMap< int, QWidget* > myWidgets;
173 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
176 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
178 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
179 sb->setAcceptNames( false ); // No Notebook variables allowed
180 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
181 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
182 myWidgets[ Tolerance ] = sb;
184 QHBoxLayout* aLay = new QHBoxLayout(this);
185 aLay->setSpacing(SPACING);
188 aLay->addWidget(aLabel);
189 aLay->addWidget(myWidgets[ Tolerance ]);
192 SetDouble( Tolerance, Precision::Confusion() );
195 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
199 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
202 theList.append(Tolerance);
206 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
211 QList<int> aParams = GetParameters();
212 QList<int>::const_iterator anIter;
213 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
214 if ( !myWidgets.contains( *anIter ) ) continue;
216 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
217 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
219 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
221 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
223 if (!valid && theMsg) {
224 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
225 tr("SMESHGUI_INVALID_PARAMETERS"));
233 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
236 if ( myWidgets.contains( theId ) ) {
237 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
238 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
239 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
240 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
245 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
248 if ( myWidgets.contains( theId ) ) {
249 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
250 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
251 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
252 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
257 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
260 if ( myWidgets.contains( theId ) ) {
261 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
262 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
263 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
264 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
269 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
271 if ( myWidgets.contains( theId ) ) {
272 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
273 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
274 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
275 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
279 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
281 if ( myWidgets.contains( theId ) ) {
282 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
283 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
284 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
285 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
289 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
291 if ( myWidgets.contains( theId ) ) {
292 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
293 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
294 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
295 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
299 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
301 if ( myWidgets.contains( theId ) ) {
302 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
303 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
304 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
305 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
309 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
311 QList<int> aParams = GetParameters();
312 QList<int>::const_iterator anIter;
313 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
314 SetEditable( *anIter, isEditable );
317 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
319 if ( myWidgets.contains( theId ) ) {
320 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
321 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
322 double val = sb->GetValue();
323 double min = pow(10.0, -(sb->decimals()));
324 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
325 sb->SetValue( qMax( val, min ) );
331 Class : SMESHGUI_FilterTable::ComboItem
332 Description : Combo table item. Identificator corresponding to string may be assigned
335 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
340 ComboItem( const QMap<int, QString>& );
342 void setItems( const QMap<int, QString>& );
347 void setValue( const int );
351 int index( int ) const;
354 QMap<int, int> myIdToIdx;
357 int SMESHGUI_FilterTable::ComboItem::Type()
359 return QTableWidgetItem::UserType + 1;
362 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
363 : QTableWidgetItem( Type() )
368 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
371 QMap<int, QString>::const_iterator it;
373 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
374 myIdToIdx[it.key()] = items.count();
375 items.append( it.value() );
377 setData( Qt::UserRole, items );
381 void SMESHGUI_FilterTable::ComboItem::clear()
383 QMap<int, QString> empty;
387 int SMESHGUI_FilterTable::ComboItem::count() const
389 return myIdToIdx.count();
392 int SMESHGUI_FilterTable::ComboItem::value() const
394 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
397 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
399 int idx = index( theId );
400 QStringList items = data( Qt::UserRole ).toStringList();
401 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
404 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
406 QMap<int,int>::const_iterator it;
407 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
408 if ( it.value() == idx ) return it.key();
412 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
414 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
417 Class : SMESHGUI_FilterTable::CheckItem
418 Description : Check table item.
421 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
426 CheckItem( bool = false );
427 CheckItem( const QString&, bool = false );
430 void setChecked( bool );
431 bool checked() const;
434 int SMESHGUI_FilterTable::CheckItem::Type()
436 return QTableWidgetItem::UserType + 2;
439 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
440 : QTableWidgetItem( Type() )
442 Qt::ItemFlags f = flags();
443 f = f | Qt::ItemIsUserCheckable;
444 f = f & ~Qt::ItemIsTristate;
445 f = f & ~Qt::ItemIsEditable;
450 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
451 : QTableWidgetItem( Type() )
453 Qt::ItemFlags f = flags();
454 f = f | Qt::ItemIsUserCheckable;
455 f = f & ~Qt::ItemIsTristate;
456 f = f & ~Qt::ItemIsEditable;
462 SMESHGUI_FilterTable::CheckItem::~CheckItem()
466 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
468 setCheckState( value ? Qt::Checked : Qt::Unchecked );
471 bool SMESHGUI_FilterTable::CheckItem::checked() const
473 return checkState() == Qt::Checked;
477 Class : SMESHGUI_FilterTable::IntSpinItem
478 Description : Integer spin table item.
481 class SMESHGUI_FilterTable::IntSpinItem : public QTableWidgetItem
486 IntSpinItem( const int theValue );
489 void setValue( const int theValue );
494 int SMESHGUI_FilterTable::IntSpinItem::Type()
496 return QTableWidgetItem::UserType + 3;
499 SMESHGUI_FilterTable::IntSpinItem::IntSpinItem( const int theValue )
500 : QTableWidgetItem( Type() )
502 setValue( theValue );
505 int SMESHGUI_FilterTable::IntSpinItem::value() const
508 int value = data( Qt::UserRole ).toInt( &ok );
509 return ok ? value : 0;
512 void SMESHGUI_FilterTable::IntSpinItem::setValue( const int theValue )
514 setData( Qt::UserRole, theValue );
515 setText( QString::number( theValue ) );
518 void SMESHGUI_FilterTable::IntSpinItem::clear()
524 Class : SMESHGUI_FilterTable::DoubleSpinItem
525 Description : Double spin table item.
528 class SMESHGUI_FilterTable::DoubleSpinItem : public QTableWidgetItem
533 DoubleSpinItem( const double theValue );
535 double value() const;
536 void setValue( const double theValue );
538 int precision() const;
539 void setPrecision( const int thePrecision );
544 int SMESHGUI_FilterTable::DoubleSpinItem::Type()
546 return QTableWidgetItem::UserType + 4;
549 SMESHGUI_FilterTable::DoubleSpinItem::DoubleSpinItem( const double theValue )
550 : QTableWidgetItem( Type() )
552 setValue( theValue );
555 double SMESHGUI_FilterTable::DoubleSpinItem::value() const
558 double value = data( Qt::UserRole ).toDouble( &ok );
559 return ok ? value : 0;
562 void SMESHGUI_FilterTable::DoubleSpinItem::setValue( const double theValue )
564 setData( Qt::UserRole, theValue );
565 setText( QString::number( theValue ) );
568 int SMESHGUI_FilterTable::DoubleSpinItem::precision() const
571 int precision = data( Qt::UserRole + 1 ).toInt( &ok );
572 return ok ? precision : 0;
575 void SMESHGUI_FilterTable::DoubleSpinItem::setPrecision( const int thePrecision )
577 setData( Qt::UserRole + 1, thePrecision );
580 void SMESHGUI_FilterTable::DoubleSpinItem::clear()
586 Class : SMESHGUI_FilterTable::ComboDelegate
587 Description : Table used by this widget
590 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
593 ComboDelegate( QObject* = 0 );
596 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
597 const QModelIndex& ) const;
599 void setEditorData( QWidget*, const QModelIndex& ) const;
600 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
602 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
603 const QModelIndex& ) const;
605 QTableWidget* myTable;
608 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
609 : QItemDelegate( parent ),
610 myTable( qobject_cast<QTableWidget*>( parent ) )
614 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
618 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
619 const QStyleOptionViewItem& option,
620 const QModelIndex& index ) const
622 QVariant aData = index.data( Qt::UserRole );
623 QVariant::Type aDataType = aData.type();
624 if( aDataType == QVariant::StringList ) {
625 QStringList l = aData.toStringList();
626 if ( !l.isEmpty() ) {
627 QComboBox* cb = new QComboBox( parent );
628 cb->setFrame( false );
633 else if( aDataType == QVariant::Int ) {
635 int aValue = aData.toInt( &ok );
637 SalomeApp_IntSpinBox* intSpin = new SalomeApp_IntSpinBox( 0, 1000, 1, parent, false, true );
638 intSpin->setFrame( false );
639 intSpin->setValue( aValue );
643 else if( aDataType == QVariant::Double ) {
645 double aValue = aData.toDouble( &ok );
647 int aPrecision = index.data( Qt::UserRole + 1 ).toInt( &ok );
651 SalomeApp_DoubleSpinBox* dblSpin = new SalomeApp_DoubleSpinBox( -1.e20, 1.e20, 1, aPrecision, 20, parent, false, true );
652 dblSpin->setFrame( false );
653 dblSpin->setValue( aValue );
657 return QItemDelegate::createEditor( parent, option, index );
660 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
661 const QModelIndex& index ) const
663 QVariant data = index.model()->data( index, Qt::DisplayRole );
664 QString value = data.toString();
666 if ( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) ) {
667 int i = cb->findText( value );
669 cb->setCurrentIndex( i );
673 else if ( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) ) {
674 if( data.type() == QVariant::Double ) {
675 double valueDouble = data.toDouble( &bOk );
677 dblSpin->setValue( valueDouble );
680 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
683 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
684 QAbstractItemModel* model,
685 const QModelIndex& index) const
687 if( QComboBox* cb = dynamic_cast<QComboBox*>( editor ) )
688 model->setData( index, cb->currentText(), Qt::DisplayRole );
689 else if( SalomeApp_IntSpinBox* intSpin = dynamic_cast<SalomeApp_IntSpinBox*>( editor ) )
690 model->setData( index, intSpin->value(), Qt::DisplayRole );
691 else if( SalomeApp_DoubleSpinBox* dblSpin = dynamic_cast<SalomeApp_DoubleSpinBox*>( editor ) )
692 model->setData( index, dblSpin->value(), Qt::DisplayRole );
693 else QItemDelegate::setModelData( editor, model, index );
696 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
697 const QStyleOptionViewItem& option,
698 const QModelIndex& index ) const
700 editor->setGeometry( option.rect );
704 Class : SMESHGUI_FilterTable::Table
705 Description : Table used by this widget
708 class SMESHGUI_FilterTable::Table : public QTableWidget
711 Table( QWidget* = 0 );
712 Table( int, int, QWidget* = 0 );
715 QSize minimumSizeHint() const;
717 void setEditable( bool, int, int );
718 bool isEditable( int, int ) const;
720 void setReadOnly( bool );
721 bool isReadOnly() const;
723 void insertRows( int, int = 1 );
724 QString text( int, int );
726 QList<int> selectedRows();
729 //=======================================================================
730 // name : SMESHGUI_FilterTable::Table::Table
731 // Purpose : Constructor
732 //=======================================================================
733 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
734 : QTableWidget(parent)
736 // set custom item delegate
737 setItemDelegate( new ComboDelegate(this) );
738 // set edit triggers by default
739 setReadOnly( false );
742 //=======================================================================
743 // name : SMESHGUI_FilterTable::Table::Table
744 // Purpose : Constructor
745 //=======================================================================
746 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
747 : QTableWidget(numRows, numCols, parent)
749 // set custom item delegate
750 setItemDelegate( new ComboDelegate(this) );
751 // set edit triggers by default
752 setReadOnly( false );
755 //=======================================================================
756 // name : SMESHGUI_FilterTable::Table::~Table
757 // Purpose : Destructor
758 //=======================================================================
759 SMESHGUI_FilterTable::Table::~Table()
763 //=======================================================================
764 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
765 // Purpose : Get minimum size for the table
766 //=======================================================================
767 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
769 QSize s = QTableWidget::minimumSizeHint();
770 QHeaderView* hv = horizontalHeader();
772 s.setWidth( qMax( s.width(), hv->length() ) );
776 //=======================================================================
777 // name : SMESHGUI_FilterTable::Table::setEditable
778 // Purpose : Set editable of specified cell
779 //=======================================================================
780 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
783 QTableWidgetItem* anItem = item( row, col );
785 bool isSignalsBlocked = signalsBlocked();
786 blockSignals( true );
788 Qt::ItemFlags f = anItem->flags();
789 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
790 else f = f | Qt::ItemIsEditable;
791 anItem->setFlags( f );
793 blockSignals( isSignalsBlocked );
797 //=======================================================================
798 // name : SMESHGUI_FilterTable::Table::isEditable
799 // Purpose : Verify wheter cell is editable
800 //=======================================================================
801 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
803 QTableWidgetItem* anItem = item( row, col );
804 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
807 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
809 setEditTriggers( on ?
810 QAbstractItemView::NoEditTriggers :
811 QAbstractItemView::AllEditTriggers );
814 bool SMESHGUI_FilterTable::Table::isReadOnly() const
816 return editTriggers() == QAbstractItemView::NoEditTriggers;
819 //=======================================================================
820 // name : SMESHGUI_FilterTable::Table::insertRows
821 // Purpose : Insert rows (virtual redefined)
822 //=======================================================================
823 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
825 closePersistentEditor( currentItem() );
826 while ( count-- ) insertRow( row );
829 //=======================================================================
830 // name : SMESHGUI_FilterTable::Table::text
831 // Purpose : Get text from cell (virtual redefined)
832 //=======================================================================
833 QString SMESHGUI_FilterTable::Table::text (int row, int col)
835 closePersistentEditor( currentItem() );
836 QTableWidgetItem* anItem = item( row, col );
837 return anItem ? anItem->text() : QString();
840 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
842 QList<QTableWidgetItem*> selItems = selectedItems();
843 QTableWidgetItem* anItem;
846 foreach( anItem, selItems ) {
847 int r = row( anItem );
848 if ( !rows.contains( r ) ) rows.append( r );
856 Class : SMESHGUI_FilterTable
857 Description : Frame containig
858 - Button group for switching entity type
859 - Table for displaying filter criterions
860 - Buttons for editing table and filter libraries
863 //=======================================================================
864 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
865 // Purpose : Constructor
866 //=======================================================================
867 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
872 mySMESHGUI( theModule )
881 //=======================================================================
882 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
883 // Purpose : Constructor
884 //=======================================================================
885 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
887 const QList<int>& types )
890 mySMESHGUI( theModule )
896 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
900 //=======================================================================
901 // name : SMESHGUI_FilterTable::Init
902 // Purpose : Create table corresponding to the specified type
903 //=======================================================================
904 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
906 if (theTypes.isEmpty())
909 // Create buttons if necessary
911 if (myTables.isEmpty())
913 // create main layout
914 QVBoxLayout* aMainLay = new QVBoxLayout(this);
915 aMainLay->setMargin( 0 );
916 aMainLay->setSpacing( SPACING );
918 // create switch of entity types
919 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
920 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
921 myEntityTypeBoxLayout->setMargin( MARGIN );
922 myEntityTypeBoxLayout->setSpacing( SPACING );
923 myEntityTypeGrp = new QButtonGroup(this);
925 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
926 QMap<int, QString>::const_iterator anIter;
927 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
929 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
930 myEntityTypeGrp->addButton(aBtn, anIter.key());
931 myEntityTypeBoxLayout->addWidget(aBtn);
934 myTableGrp = new QGroupBox(tr("FILTER"), this );
937 mySwitchTableGrp = new QWidget(myTableGrp);
938 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
939 mySwitchTableGrpLayout->setMargin(0);
940 mySwitchTableGrpLayout->setSpacing(0);
942 QList<int>::const_iterator typeIt = theTypes.begin();
943 for ( ; typeIt != theTypes.end(); ++typeIt ) {
944 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
945 myTables[ *typeIt ] = aTable;
946 mySwitchTableGrpLayout->addWidget(aTable);
947 if ( typeIt != theTypes.begin() )
952 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
953 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
954 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
955 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
956 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
957 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
959 myAddBtn->setAutoDefault(false);
960 myRemoveBtn->setAutoDefault(false);
961 myClearBtn->setAutoDefault(false);
962 myInsertBtn->setAutoDefault(false);
963 myCopyFromBtn->setAutoDefault(false);
964 myAddToBtn->setAutoDefault(false);
966 myCopyFromBtn->hide();
970 QGridLayout* aLay = new QGridLayout(myTableGrp);
971 aLay->setMargin(MARGIN);
972 aLay->setSpacing(SPACING);
974 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
975 aLay->addWidget(myAddBtn, 0, 1);
976 aLay->addWidget(myInsertBtn, 1, 1);
977 aLay->addWidget(myRemoveBtn, 2, 1);
978 aLay->addWidget(myClearBtn, 3, 1);
979 aLay->addWidget(myCopyFromBtn, 5, 1);
980 aLay->addWidget(myAddToBtn, 6, 1);
981 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
983 aLay->setRowMinimumHeight(4, 10);
984 aLay->setRowStretch(4, 1);
985 aLay->setColumnStretch(0, 1);
986 aLay->setColumnStretch(1, 0);
989 aMainLay->addWidget(myEntityTypeBox);
990 aMainLay->addWidget(myTableGrp);
993 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
994 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
995 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
996 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
998 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
999 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
1001 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
1006 // Hide buttons of entity types if necessary
1007 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1008 QMap<int, QString>::const_iterator anIt;
1009 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
1011 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
1012 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
1015 // select first button if there is no selected buttons or it is hidden
1016 int aBtnId = myEntityTypeGrp->checkedId();
1017 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
1018 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
1019 if ( aBtn ) aBtn->setChecked(true);
1022 myEntityTypeBox->setVisible(theTypes.count() > 1);
1024 myTableGrp->updateGeometry();
1025 int cType = myEntityTypeGrp->checkedId();
1026 onEntityType(cType);
1029 //=======================================================================
1030 // name : SMESHGUI_FilterTable::createAdditionalFrame
1031 // Purpose : Get group box containing table. May be used for adding new widgets in it
1032 //=======================================================================
1033 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
1035 QWidget* aFrame = new QWidget(theParent);
1037 QFrame* aLine1 = new QFrame(aFrame);
1038 QFrame* aLine2 = new QFrame(aFrame);
1039 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1040 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1041 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1042 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1044 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
1046 myWgStack = new QStackedWidget(aFrame);
1048 QGridLayout* aLay = new QGridLayout(aFrame);
1050 aLay->setSpacing(SPACING);
1051 aLay->addWidget(aLine1, 0, 0);
1052 aLay->addWidget(aLabel, 0, 1);
1053 aLay->addWidget(aLine2, 0, 2);
1054 aLay->addWidget(myWgStack, 1, 0, 1, 3);
1059 //=======================================================================
1060 // name : SMESHGUI_FilterTable::GetTableGrp
1061 // Purpose : Get group box containing table. May be used for adding new widgets in it
1062 //=======================================================================
1063 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
1068 //=======================================================================
1069 // name : SMESHGUI_FilterTable::onEntityType
1070 // Purpose : SLOT. Called when entity type changed.
1071 // Display corresponding table
1072 //=======================================================================
1073 void SMESHGUI_FilterTable::onEntityType (int theType)
1075 if (myEntityType == theType)
1079 emit NeedValidation();
1082 myEntityTypeGrp->button(myEntityType)->setChecked(true);
1086 myEntityType = theType;
1088 if (!myTables.contains(theType)) {
1089 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
1090 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
1093 TableMap::iterator anIter;
1094 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1095 anIter.value()->setVisible( myEntityType == anIter.key() );
1098 qApp->processEvents();
1099 myTables[ myEntityType ]->updateGeometry();
1102 emit EntityTypeChanged(theType);
1105 //=======================================================================
1106 // name : SMESHGUI_FilterTable::IsValid
1107 // Purpose : Verify validity of entered data
1108 //=======================================================================
1109 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
1111 int aType = theEntityType == -1 ? GetType() : theEntityType;
1113 Table* aTable = myTables[ aType ];
1114 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1116 int aCriterion = GetCriterionType(i, aType);
1118 if (aCriterion == SMESH::FT_GroupColor ) {
1119 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
1120 if (clrBtn && !clrBtn->color().isValid())
1121 errMsg = tr( "GROUPCOLOR_ERROR" );
1123 else if (aCriterion == SMESH::FT_RangeOfIds ||
1124 aCriterion == SMESH::FT_BelongToGeom ||
1125 aCriterion == SMESH::FT_BelongToPlane ||
1126 aCriterion == SMESH::FT_BelongToCylinder ||
1127 aCriterion == SMESH::FT_BelongToGenSurface ||
1128 aCriterion == SMESH::FT_ElemGeomType ||
1129 aCriterion == SMESH::FT_CoplanarFaces ||
1130 aCriterion == SMESH::FT_LyingOnGeom)
1132 if (aTable->text(i, 2).isEmpty())
1133 errMsg = tr( "ERROR" );
1137 bool isSignalsBlocked = aTable->signalsBlocked();
1138 aTable->blockSignals(true);
1139 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
1140 aTable->blockSignals(isSignalsBlocked);
1142 if (!aRes && aTable->isEditable(i, 2))
1143 errMsg = tr( "ERROR" );
1144 else if (aType == SMESH::EDGE &&
1145 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
1147 errMsg = tr( "MULTIEDGES_ERROR" );
1150 if (!errMsg.isEmpty()) {
1152 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1156 QTableWidgetItem* anItem = aTable->item(i, 0);
1157 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1164 //=======================================================================
1165 // name : SMESHGUI_FilterTable::SetValidity
1166 // Purpose : Set validity of the table
1167 //=======================================================================
1168 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1170 myIsValid = isValid;
1173 //=======================================================================
1174 // name : SMESHGUI_FilterTable::GetType
1175 // Purpose : Get current entity type
1176 //=======================================================================
1177 int SMESHGUI_FilterTable::GetType() const
1179 return myEntityType;
1182 //=======================================================================
1183 // name : SMESHGUI_FilterTable::SetType
1184 // Purpose : Set current entity type
1185 //=======================================================================
1186 void SMESHGUI_FilterTable::SetType (const int type)
1188 myEntityTypeGrp->button(type)->setChecked(true);
1192 //=======================================================================
1193 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1194 // Purpose : Restore previous entity type
1195 //=======================================================================
1196 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1198 SetType(myEntityType);
1201 //=======================================================================
1202 // name : SMESHGUI_FilterTable::GetCriterionType
1203 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1204 //=======================================================================
1205 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1207 int aType = theType == -1 ? GetType() : theType;
1208 Table* aTable = myTables[ aType ];
1209 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1210 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1213 //=======================================================================
1214 // name : SMESHGUI_FilterTable::GetCriterion
1215 // Purpose : Get parameters of criterion from specified row
1216 //=======================================================================
1217 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1218 SMESH::Filter::Criterion& theCriterion,
1219 const int theEntityType) const
1221 int aType = theEntityType == -1 ? GetType() : theEntityType;
1222 Table* aTable = myTables[ aType ];
1224 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1225 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1226 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1227 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1228 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1230 int aCriterionType = GetCriterionType(theRow, aType);
1232 if ( aCriterionType == SMESH::FT_GroupColor )
1234 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1237 const QColor qClr = clrBtn->color();
1238 QString clrStr = QString( "%1;%2;%3" ).
1239 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1240 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1243 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1244 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1245 else if ( aCriterionType == SMESH::FT_CoplanarFaces )
1246 theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
1247 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1248 aCriterionType != SMESH::FT_BelongToGeom &&
1249 aCriterionType != SMESH::FT_BelongToPlane &&
1250 aCriterionType != SMESH::FT_BelongToCylinder &&
1251 aCriterionType != SMESH::FT_BelongToGenSurface &&
1252 aCriterionType != SMESH::FT_LyingOnGeom )
1254 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1255 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1259 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1260 if ( aCriterionType != SMESH::FT_RangeOfIds )
1261 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1264 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1265 if (myAddWidgets.contains(anItem))
1266 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1269 //=======================================================================
1270 // name : SMESHGUI_FilterTable::SetCriterion
1271 // Purpose : Set parameters of criterion of specified row
1272 //=======================================================================
1273 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1274 const SMESH::Filter::Criterion& theCriterion,
1275 const int theEntityType)
1277 int aType = theEntityType == -1 ? GetType() : theEntityType;
1279 Table* aTable = myTables[ aType ];
1281 if (theRow > aTable->rowCount() - 1)
1284 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1285 onCriterionChanged(theRow, 0, aType);
1286 if ( theCriterion.Compare == SMESH::FT_Undefined )
1287 ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
1289 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1290 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1292 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1294 if (!aTable->isEditable(theRow, 4))
1295 aTable->setItem(theRow, 4, getBinaryItem());
1296 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1299 aTable->setEditable(false, theRow, 4);
1301 if (theCriterion.Type == SMESH::FT_GroupColor )
1303 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1307 QString clrStr( theCriterion.ThresholdStr );
1308 QStringList clrVals = clrStr.split( ";" );
1309 if ( clrVals.count() > 2 )
1310 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1311 (int)256*clrVals[1].toDouble(),
1312 (int)256*clrVals[2].toDouble() );
1313 clrBtn->setColor( qClr );
1316 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1318 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1319 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1321 else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
1323 aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
1325 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1326 theCriterion.Type != SMESH::FT_BelongToGeom &&
1327 theCriterion.Type != SMESH::FT_BelongToPlane &&
1328 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1329 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1330 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1331 theCriterion.Type != SMESH::FT_CoplanarFaces &&
1332 theCriterion.Type != SMESH::FT_FreeBorders &&
1333 theCriterion.Type != SMESH::FT_FreeEdges &&
1334 theCriterion.Type != SMESH::FT_FreeNodes &&
1335 theCriterion.Type != SMESH::FT_FreeFaces &&
1336 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1337 theCriterion.Type != SMESH::FT_BareBorderFace &&
1338 theCriterion.Type != SMESH::FT_BareBorderVolume &&
1339 theCriterion.Type != SMESH::FT_OverConstrainedFace &&
1340 theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
1341 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1343 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1347 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1348 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1349 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1352 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1353 theCriterion.Type == SMESH::FT_BelongToPlane ||
1354 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1355 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1356 theCriterion.Type == SMESH::FT_BelongToGeom ||
1357 theCriterion.Type == SMESH::FT_LyingOnGeom ||
1358 theCriterion.Type == SMESH::FT_CoplanarFaces ||
1359 theCriterion.Type == SMESH::FT_EqualNodes)
1361 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1362 if (!myAddWidgets.contains(anItem))
1364 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1365 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
1366 myWgStack->addWidget(myAddWidgets[ anItem ]);
1368 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1371 emit CriterionChanged(theRow, aType);
1374 //=======================================================================
1375 // name : SMESHGUI_FilterTable::Update
1376 // Purpose : Update table
1377 //=======================================================================
1378 void SMESHGUI_FilterTable::Update()
1380 Table* aTable = myTables[ GetType() ];
1381 int aCurrRow = aTable->currentRow();
1382 int numRows = aTable->rowCount();
1383 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1384 aTable->setCurrentCell(0, 0);
1385 updateAdditionalWidget();
1388 //=======================================================================
1389 // name : SMESHGUI_FilterTable::AddCriterion
1390 // Purpose : Add criterion with parameters
1391 //=======================================================================
1392 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1393 const int theEntityType)
1395 int aType = theEntityType == -1 ? GetType() : theEntityType;
1396 Table* aTable = myTables[ aType ];
1397 addRow(aTable, aType);
1398 SetCriterion(aTable->rowCount() - 1, theCriterion);
1401 //=======================================================================
1402 // name : SMESHGUI_FilterTable::NumRows
1403 // Purpose : Get number of criterions of current type
1404 //=======================================================================
1405 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1407 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1410 //=======================================================================
1411 // name : SMESHGUI_FilterTable::Clear
1412 // Purpose : Clear current table
1413 //=======================================================================
1414 void SMESHGUI_FilterTable::Clear (const int theType)
1416 int aType = theType == -1 ? GetType() : theType;
1417 Table* aTable = myTables[ aType ];
1419 if (aTable->rowCount() == 0)
1422 while (aTable->rowCount() > 0)
1424 removeAdditionalWidget(aTable, 0);
1425 aTable->removeRow(0);
1431 //=======================================================================
1432 // name : SMESHGUI_FilterTable::onAddBtn
1433 // Purpose : SLOT. Called then "Add" button pressed.
1434 // Adds new string to table
1435 //=======================================================================
1436 void SMESHGUI_FilterTable::onAddBtn()
1438 int aType = GetType();
1439 addRow(myTables[ aType ], aType);
1444 //=======================================================================
1445 // name : SMESHGUI_FilterTable::onInsertBtn
1446 // Purpose : SLOT. Called then "Insert" button pressed.
1447 // Inserts new string before current one
1448 //=======================================================================
1449 void SMESHGUI_FilterTable::onInsertBtn()
1451 addRow(myTables[ GetType() ], GetType(), false);
1454 //=======================================================================
1455 // name : SMESHGUI_FilterTable::onRemoveBtn
1456 // Purpose : SLOT. Called then "Remove" button pressed.
1457 // Removes current string from table
1458 //=======================================================================
1459 void SMESHGUI_FilterTable::onRemoveBtn()
1461 Table* aTable = myTables[ GetType() ];
1463 if (aTable->rowCount() == 0)
1466 QList<QTableWidgetItem*> items = aTable->selectedItems();
1468 QList<int> aRows = aTable->selectedRows(); // already sorted
1472 removeAdditionalWidget(aTable, i);
1473 aTable->removeRow(i);
1476 // remove control of binary logical operation from last row
1477 if (aTable->rowCount() > 0)
1478 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1483 //=======================================================================
1484 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1485 // Purpose : Enable/Disable widget with additonal parameters
1486 //=======================================================================
1487 void SMESHGUI_FilterTable::updateAdditionalWidget()
1489 Table* aTable = myTables[ GetType() ];
1490 int aRow = aTable->currentRow();
1491 if (aRow < 0 || aRow >= aTable->rowCount())
1493 myWgStack->setEnabled(false);
1497 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1498 int aCriterion = GetCriterionType(aRow);
1499 bool toEnable = ((((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1500 aCriterion != SMESH::FT_RangeOfIds &&
1501 aCriterion != SMESH::FT_FreeEdges &&
1502 aCriterion != SMESH::FT_FreeFaces &&
1503 aCriterion != SMESH::FT_BadOrientedVolume &&
1504 aCriterion != SMESH::FT_BareBorderFace &&
1505 aCriterion != SMESH::FT_BareBorderVolume &&
1506 aCriterion != SMESH::FT_OverConstrainedFace &&
1507 aCriterion != SMESH::FT_OverConstrainedVolume)
1509 aCriterion == SMESH::FT_CoplanarFaces);
1511 if (!myAddWidgets.contains(anItem))
1513 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1514 myWgStack->addWidget(myAddWidgets[ anItem ]);
1517 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1518 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1519 myWgStack->setEnabled(toEnable);
1522 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1524 const char* retval = 0;
1526 case SMESH::FT_AspectRatio:
1527 case SMESH::FT_AspectRatio3D:
1528 case SMESH::FT_Taper:
1529 retval = "parametric_precision"; break;
1530 case SMESH::FT_Warping:
1531 case SMESH::FT_MinimumAngle:
1532 case SMESH::FT_Skew:
1533 case SMESH::FT_CoplanarFaces:
1534 retval = "angle_precision"; break;
1535 case SMESH::FT_Area:
1536 retval = "area_precision"; break;
1537 case SMESH::FT_BelongToGeom:
1538 case SMESH::FT_BelongToPlane:
1539 case SMESH::FT_BelongToCylinder:
1540 case SMESH::FT_BelongToGenSurface:
1541 case SMESH::FT_LyingOnGeom:
1542 case SMESH::FT_EqualNodes:
1543 retval = "len_tol_precision"; break;
1544 case SMESH::FT_Length:
1545 case SMESH::FT_Length2D:
1546 case SMESH::FT_MaxElementLength2D:
1547 case SMESH::FT_MaxElementLength3D:
1548 retval = "length_precision"; break;
1549 case SMESH::FT_Volume3D:
1550 retval = "vol_precision"; break;
1557 //=======================================================================
1558 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1559 // Purpose : Remove widgets containing additional parameters from widget
1560 // stack and internal map
1561 //=======================================================================
1562 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1564 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1565 if (myAddWidgets.contains(anItem))
1567 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1568 myAddWidgets[ anItem ]->setParent(0);
1569 delete myAddWidgets[ anItem ];
1570 myAddWidgets.remove(anItem);
1574 //=======================================================================
1575 // name : SMESHGUI_FilterTable::onClearBtn
1576 // Purpose : SLOT. Called then "Clear" button pressed.
1577 // Removes all strings from table
1578 //=======================================================================
1579 void SMESHGUI_FilterTable::onClearBtn()
1581 Table* aTable = myTables[ GetType() ];
1583 if (aTable->rowCount() == 0)
1586 while (aTable->rowCount() > 0)
1588 removeAdditionalWidget(aTable, 0);
1589 aTable->removeRow(0);
1595 //=======================================================================
1596 // name : SMESHGUI_FilterTable::onCurrentChanged()
1597 // Purpose : SLOT. Called when current cell changed
1598 //=======================================================================
1599 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1602 updateAdditionalWidget();
1603 emit CurrentChanged(theRow, theCol);
1606 //=======================================================================
1608 // Purpose : returns available geometry types of elements
1609 //=======================================================================
1610 static QList<int> geomTypes( const int theType )
1613 if ( theType == SMESH::NODE )
1614 typeIds.append( SMESH::Geom_POINT );
1615 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1616 typeIds.append( SMESH::Geom_EDGE );
1617 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1619 typeIds.append( SMESH::Geom_TRIANGLE );
1620 typeIds.append( SMESH::Geom_QUADRANGLE );
1621 typeIds.append( SMESH::Geom_POLYGON );
1623 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1625 typeIds.append( SMESH::Geom_TETRA );
1626 typeIds.append( SMESH::Geom_PYRAMID );
1627 typeIds.append( SMESH::Geom_HEXA );
1628 typeIds.append( SMESH::Geom_PENTA );
1629 typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
1630 typeIds.append( SMESH::Geom_POLYHEDRA );
1632 if ( theType == SMESH::ALL || theType == SMESH::ELEM0D )
1634 typeIds.append( SMESH::Geom_POINT );
1636 if ( theType == SMESH::ALL || theType == SMESH::BALL )
1638 typeIds.append( SMESH::Geom_BALL );
1643 //=======================================================================
1644 // name : SMESHGUI_FilterTable::onCriterionChanged()
1645 // Purpose : Provides reaction on change of criterion
1646 //=======================================================================
1647 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1649 int aType = entityType == -1 ? GetType() : entityType;
1650 Table* aTable = myTables[ aType ];
1651 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1653 int aCriterionType = GetCriterionType(row);
1654 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1655 int aComboType = ComboItem::Type();
1656 int aIntSpinType = IntSpinItem::Type();
1657 int aDoubleSpinType = DoubleSpinItem::Type();
1658 QTableWidgetItem* aTableItem = aTable->item(row, 2);
1659 bool isComboItem = false;
1660 bool isIntSpinItem = false;
1661 bool isDoubleSpinItem = false;
1663 int aTableType = aTable->item(row, 2)->type();
1664 isComboItem = ( aTableType == aComboType );
1665 isIntSpinItem = ( aTableType == aIntSpinType );
1666 isDoubleSpinItem = ( aTableType == aDoubleSpinType );
1669 bool anIsDoubleCriterion =
1670 aCriterionType == SMESH::FT_AspectRatio ||
1671 aCriterionType == SMESH::FT_AspectRatio3D ||
1672 aCriterionType == SMESH::FT_Taper ||
1673 aCriterionType == SMESH::FT_Warping ||
1674 aCriterionType == SMESH::FT_MinimumAngle ||
1675 aCriterionType == SMESH::FT_Skew ||
1676 aCriterionType == SMESH::FT_Area ||
1677 aCriterionType == SMESH::FT_Length ||
1678 aCriterionType == SMESH::FT_Length2D ||
1679 aCriterionType == SMESH::FT_MaxElementLength2D ||
1680 aCriterionType == SMESH::FT_MaxElementLength3D ||
1681 aCriterionType == SMESH::FT_Volume3D;
1684 if ( anIsDoubleCriterion ) {
1685 const char* aPrecisionType = getPrecision( aCriterionType );
1686 SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
1687 if( aPrecisionType && aResourceMgr )
1688 aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
1691 // if the precision is to be changed we should remove the existing
1692 // spin item and create another one with new precision
1693 bool anIsPrecisionChanged = false;
1694 if ( anIsDoubleCriterion && isDoubleSpinItem ) {
1695 if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 ) ) ) {
1696 anIsPrecisionChanged = aDoubleSpinItem->precision() != aPrecision;
1700 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1701 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
1702 (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
1703 (!anIsDoubleCriterion && isDoubleSpinItem) ||
1704 anIsPrecisionChanged )
1706 bool isSignalsBlocked = aTable->signalsBlocked();
1707 aTable->blockSignals( true );
1708 aTable->removeCellWidget( row, 2 );
1709 aTable->setItem( row, 2, new QTableWidgetItem() );
1710 aTable->blockSignals( isSignalsBlocked );
1712 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1713 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
1714 (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
1715 (anIsDoubleCriterion && !isDoubleSpinItem) ||
1716 anIsPrecisionChanged )
1718 bool isSignalsBlocked = aTable->signalsBlocked();
1719 aTable->blockSignals( true );
1720 if ( aCriterionType == SMESH::FT_GroupColor )
1721 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1722 else if ( aCriterionType == SMESH::FT_ElemGeomType ) {
1723 QList<int> typeIds = geomTypes( aType );
1724 QMap<int, QString> typeNames;
1725 QList<int>::const_iterator anIter = typeIds.begin();
1726 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1728 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1729 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1731 ComboItem* typeBox = new ComboItem( typeNames );
1732 aTable->setItem( row, 2, typeBox );
1734 else if ( aCriterionType == SMESH::FT_MultiConnection ) {
1735 IntSpinItem* intSpin = new IntSpinItem( 0 );
1736 aTable->setItem( row, 2, intSpin );
1738 else if ( anIsDoubleCriterion ) {
1739 DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
1740 dblSpin->setPrecision( aPrecision );
1741 aTable->setItem( row, 2, dblSpin );
1743 aTable->blockSignals( isSignalsBlocked );
1746 if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes ||
1747 aCriterionType == SMESH::FT_EqualNodes )) ||
1748 (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders ||
1749 aCriterionType == SMESH::FT_EqualEdges )) ||
1750 (aType == SMESH::FACE && (aCriterionType == SMESH::FT_BareBorderFace ||
1751 aCriterionType == SMESH::FT_OverConstrainedFace ||
1752 aCriterionType == SMESH::FT_FreeEdges ||
1753 aCriterionType == SMESH::FT_FreeFaces ||
1754 aCriterionType == SMESH::FT_EqualFaces)) ||
1755 (aType == SMESH::VOLUME && (aCriterionType == SMESH::FT_BadOrientedVolume ||
1756 aCriterionType == SMESH::FT_OverConstrainedVolume ||
1757 aCriterionType == SMESH::FT_BareBorderVolume ||
1758 aCriterionType == SMESH::FT_EqualVolumes )) ||
1759 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1760 aCriterionType == SMESH::FT_GroupColor ||
1761 aCriterionType == SMESH::FT_ElemGeomType ||
1762 aCriterionType == SMESH::FT_CoplanarFaces
1765 bool isSignalsBlocked = aTable->signalsBlocked();
1766 aTable->blockSignals( true );
1768 if (aCompareItem->count() > 0)
1769 aCompareItem->clear();
1770 aTable->setEditable(false, row, 1);
1771 aTable->item(row, 2)->setText( QString("") );
1772 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1773 aCriterionType == SMESH::FT_ElemGeomType ||
1774 aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
1775 aTable->blockSignals( isSignalsBlocked );
1777 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1778 aCriterionType == SMESH::FT_BelongToGeom ||
1779 aCriterionType == SMESH::FT_BelongToPlane ||
1780 aCriterionType == SMESH::FT_BelongToCylinder ||
1781 aCriterionType == SMESH::FT_BelongToGenSurface ||
1782 aCriterionType == SMESH::FT_LyingOnGeom)
1784 QMap<int, QString> aMap;
1785 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1786 aCompareItem->setItems(aMap);
1787 if (!aTable->isEditable(row, 2))
1788 aTable->setEditable(true, row, 1);
1789 if (!aTable->isEditable(row, 2))
1790 aTable->setEditable(true, row, 2);
1792 else if (aCriterionType == SMESH::FT_GroupColor ||
1793 aCriterionType == SMESH::FT_ElemGeomType)
1795 if (!aTable->isEditable(row, 2))
1796 aTable->setEditable(true, row, 2);
1800 if (aCompareItem && aCompareItem->count() != 3)
1802 aCompareItem->setItems(getCompare());
1805 if (aTable->item( row, 2 )) {
1806 QString aText = aTable->text(row, 2);
1808 aText.toDouble(&isOk);
1809 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1810 if (!aTable->isEditable(row, 1))
1811 aTable->setEditable(true, row, 1);
1812 if (!aTable->isEditable(row, 2))
1813 aTable->setEditable(true, row, 2);
1817 updateAdditionalWidget();
1819 emit CriterionChanged(row, entityType);
1822 //=======================================================================
1823 // name : SMESHGUI_FilterTable::onCriterionChanged()
1824 // Purpose : SLOT. Called then contents of table changed
1825 // Provides reaction on change of criterion
1826 //=======================================================================
1827 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1830 onCriterionChanged(row, col, -1);
1833 //=======================================================================
1834 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1835 // Purpose : Get first selected row
1836 //=======================================================================
1837 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1839 Table* aTable = myTables[ GetType() ];
1841 QList<int> selRows = aTable->selectedRows(); // already sorted
1842 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1844 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1847 //=======================================================================
1848 // name : SMESHGUI_FilterTable::addRow
1849 // Purpose : Add row at the end of table
1850 //=======================================================================
1851 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1854 int aSelectedRow = getFirstSelectedRow();
1855 int aCurrCol = theTable->currentColumn();
1858 if (toTheEnd || aSelectedRow == -1)
1860 theTable->insertRows(theTable->rowCount());
1861 aCurrRow = theTable->rowCount() - 1;
1865 theTable->insertRows(aSelectedRow);
1866 aCurrRow = aSelectedRow;
1870 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1871 bool isSignalsBlocked = theTable->signalsBlocked();
1872 theTable->blockSignals( true );
1875 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1878 theTable->setItem(aCurrRow, 1, getCompareItem());
1881 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1883 // Logical operation NOT
1884 theTable->setItem(aCurrRow, 3, getUnaryItem());
1886 // Logical operation AND / OR
1887 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1889 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1891 theTable->blockSignals( isSignalsBlocked );
1893 // Logical binary operation for previous value
1894 int anAddBinOpStr = -1;
1895 if (aCurrRow == theTable->rowCount() - 1)
1896 anAddBinOpStr = aCurrRow - 1;
1897 else if (aCurrRow >= 0 )
1898 anAddBinOpStr = aCurrRow;
1900 if (theTable->item(aCurrRow, 4) == 0 ||
1901 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1903 if (anAddBinOpStr >= 0 &&
1904 (theTable->item(anAddBinOpStr, 4) == 0 ||
1905 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1906 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1909 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1911 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1912 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1913 theTable->setCurrentCell(aCurrRow, aCurrCol);
1915 onCriterionChanged(aCurrRow, 0);
1920 //=======================================================================
1921 // name : SMESHGUI_FilterTable::getCriterionItem
1922 // Purpose : Get combo table item for criteria of specified type
1923 //=======================================================================
1924 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1926 return new ComboItem(getCriteria(theType));
1929 //=======================================================================
1930 // name : SMESHGUI_FilterTable::getCompareItem
1931 // Purpose : Get combo table item for operation of comparision
1932 //=======================================================================
1933 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1935 return new ComboItem(getCompare());
1938 //=======================================================================
1939 // name : SMESHGUI_FilterTable::getBinaryItem
1941 //=======================================================================
1942 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1944 static QMap<int, QString> aMap;
1947 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1948 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1951 return new ComboItem(aMap);
1954 //=======================================================================
1955 // name : SMESHGUI_FilterTable::getUnaryItem
1956 // Purpose : Get check table item
1957 //=======================================================================
1958 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1960 return new CheckItem(tr("NOT"));
1963 //=======================================================================
1964 // name : SMESHGUI_FilterTable::getSupportedTypes
1965 // Purpose : Get all supported type
1966 //=======================================================================
1967 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1969 static QMap<int, QString> aTypes;
1970 if (aTypes.isEmpty())
1972 aTypes[ SMESH::NODE ] = tr("NODES");
1973 aTypes[ SMESH::BALL ] = tr("BALLS");
1974 aTypes[ SMESH::EDGE ] = tr("EDGES");
1975 aTypes[ SMESH::FACE ] = tr("FACES");
1976 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1977 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
1983 //=======================================================================
1984 // name : SMESHGUI_FilterTable::getCriteria
1985 // Purpose : Get criteria for specified type
1986 //=======================================================================
1987 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1989 if (theType == SMESH::NODE)
1991 static QMap<int, QString> aCriteria;
1992 if (aCriteria.isEmpty())
1994 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1995 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1996 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1997 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1998 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1999 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2000 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
2001 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2002 aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
2006 else if (theType == SMESH::EDGE)
2008 static QMap<int, QString> aCriteria;
2009 if (aCriteria.isEmpty())
2011 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
2012 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
2013 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
2014 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2015 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2016 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2017 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2018 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2019 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2020 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2021 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2022 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2023 aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
2027 else if (theType == SMESH::FACE)
2029 static QMap<int, QString> aCriteria;
2030 if (aCriteria.isEmpty())
2032 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
2033 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
2034 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
2035 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
2036 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
2037 aCriteria[ SMESH::FT_Area ] = tr("AREA");
2038 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
2039 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
2040 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2041 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2042 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2043 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2044 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2045 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2046 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
2047 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
2048 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
2049 aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
2050 aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
2051 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2052 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2053 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2054 aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
2055 aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
2059 else if (theType == SMESH::VOLUME)
2061 static QMap<int, QString> aCriteria;
2062 if (aCriteria.isEmpty())
2064 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
2065 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2066 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2067 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2068 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
2069 aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
2070 aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
2071 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
2072 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
2073 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2074 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2075 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2076 aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
2080 else if (theType == SMESH::ELEM0D)
2082 static QMap<int, QString> aCriteria;
2083 if (aCriteria.isEmpty())
2085 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2086 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2087 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2088 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2089 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2090 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2094 else if (theType == SMESH::BALL)
2096 static QMap<int, QString> aCriteria;
2097 if (aCriteria.isEmpty())
2099 aCriteria[ SMESH::FT_BallDiameter ] = tr("BALL_DIAMETER");
2100 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2101 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2102 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
2103 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
2104 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
2105 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2111 static QMap<int, QString> aCriteria;
2112 if (aCriteria.isEmpty())
2114 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
2115 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
2116 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
2117 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
2118 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
2119 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
2127 //=======================================================================
2128 // name : SMESHGUI_FilterTable::getCompare
2129 // Purpose : Get operation of comparison
2130 //=======================================================================
2131 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
2133 static QMap<int, QString> aMap;
2137 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
2138 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
2139 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
2145 //=======================================================================
2146 // name : SMESHGUI_FilterTable::createTable
2147 // Purpose : Create table
2148 //=======================================================================
2149 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
2153 Table* aTable= new Table(0, 6, theParent);
2155 QHeaderView* aHeaders = aTable->horizontalHeader();
2157 QFontMetrics aMetrics(aHeaders->font());
2159 // append spaces to the header of criteria in order to
2160 // provide visibility of criterion inside comboboxes
2161 static int aMaxLenCr = 0;
2165 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
2166 QMap<int, QString>::const_iterator anIter;
2167 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
2168 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
2171 static int aLenCr = qAbs( aMaxLenCr -
2172 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
2175 aCrStr.fill(' ', aLenCr);
2177 aCoStr.fill(' ', 10);
2179 QStringList aHeaderLabels;
2180 aHeaderLabels.append( tr("CRITERION") + aCrStr );
2181 aHeaderLabels.append( tr("COMPARE") + aCoStr );
2182 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
2183 aHeaderLabels.append( tr("UNARY") );
2184 aHeaderLabels.append( tr("BINARY") + " " );
2185 aHeaderLabels.append( tr("ID") );
2186 aTable->setHorizontalHeaderLabels( aHeaderLabels );
2188 // set geometry of the table
2189 for (int i = 0; i <= 4; i++)
2190 aTable->resizeColumnToContents(i);
2192 // set the ID column invisible
2193 aTable->hideColumn( 5 );
2195 aTable->updateGeometry();
2196 QSize aSize = aTable->sizeHint();
2197 int aWidth = aSize.width();
2198 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
2199 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
2201 connect(aTable, SIGNAL(cellChanged(int, int)),
2202 this, SLOT(onCriterionChanged(int, int)));
2204 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
2205 this, SLOT(onCurrentChanged(int, int)));
2210 //=======================================================================
2211 // name : SMESHGUI_FilterTable::updateBtnState
2212 // Purpose : Update button state
2213 //=======================================================================
2214 void SMESHGUI_FilterTable::updateBtnState()
2216 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2217 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
2220 //=======================================================================
2221 // name : SMESHGUI_FilterTable::SetEditable
2222 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
2223 //=======================================================================
2224 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
2226 TableMap::iterator anIter;
2227 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
2229 anIter.value()->setReadOnly(!isEditable);
2231 // Set Flags for CheckItems directly IPAL 19974
2232 Table* aTable = anIter.value();
2233 for (int i = 0, n = aTable->rowCount(); i < n; i++)
2234 for (int j = 0, m = aTable->columnCount(); j < m; j++)
2236 QTableWidgetItem* anItem = aTable->item(i, j);
2237 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
2238 Qt::ItemFlags f = anItem->flags();
2239 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
2240 else f = f | Qt::ItemIsUserCheckable;
2241 anItem->setFlags( f );
2249 myInsertBtn->show();
2250 myRemoveBtn->show();
2256 myInsertBtn->hide();
2257 myRemoveBtn->hide();
2262 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2263 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2264 anIter2.value()->SetEditable(isEditable);
2267 //=======================================================================
2268 // name : SMESHGUI_FilterTable::SetEnabled
2269 // Purpose : Enable/Disable table. Switching type of elements already enabled
2270 //=======================================================================
2271 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
2273 myAddBtn->setEnabled(isEnabled);
2274 myInsertBtn->setEnabled(isEnabled);
2275 myRemoveBtn->setEnabled(isEnabled);
2276 myClearBtn->setEnabled(isEnabled);
2281 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
2282 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
2283 anIter2.value()->setEnabled(isEnabled);
2286 //=======================================================================
2287 // name : SMESHGUI_FilterTable::IsEditable
2288 // Purpose : Verify whether table is editable
2289 //=======================================================================
2290 bool SMESHGUI_FilterTable::IsEditable() const
2292 return !myTables[ GetType() ]->isReadOnly();
2295 //=======================================================================
2296 // name : SMESHGUI_FilterTable::SetLibsEnabled
2297 // Purpose : Show/hide buttons for work with libraries
2298 //=======================================================================
2299 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2303 myCopyFromBtn->show();
2308 myCopyFromBtn->hide();
2313 //=======================================================================
2314 // name : SMESHGUI_FilterTable::onCopyFromBtn
2315 // Purpose : SLOT. Called the "Copy from ..." button clicked
2316 // Display filter library dialog
2317 //=======================================================================
2318 void SMESHGUI_FilterTable::onCopyFromBtn()
2321 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2322 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2324 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2326 if (myLibDlg->exec() == QDialog::Accepted)
2328 Copy(myLibDlg->GetTable());
2333 //=======================================================================
2334 // name : SMESHGUI_FilterTable::onAddToBtn
2335 // Purpose : SLOT. Called the "Add to ..." button clicked
2336 // Display filter library dialog
2337 //=======================================================================
2338 void SMESHGUI_FilterTable::onAddToBtn()
2343 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2344 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2346 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2348 myLibDlg->SetTable(this);
2353 //=======================================================================
2354 // name : SMESHGUI_FilterTable::Copy
2355 // Purpose : Initialise table with values of other table
2356 //=======================================================================
2357 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2361 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2363 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2364 theTable->GetCriterion(i, aCriterion);
2365 AddCriterion(aCriterion);
2369 //=======================================================================
2370 // name : SMESHGUI_FilterTable::CurrentCell
2371 // Purpose : Returns current cell
2372 //=======================================================================
2373 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2375 theRow = myTables[ GetType() ]->currentRow();
2376 theCol = myTables[ GetType() ]->currentColumn();
2377 return theRow >= 0 && theCol >= 0;
2380 //=======================================================================
2381 // name : SMESHGUI_FilterTable::SetText
2382 // Purpose : Set text and internal value in cell of threshold value
2383 //=======================================================================
2384 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2385 const QString& theText,
2386 const int theEntityType)
2388 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2389 aTable->item( theRow, 2 )->setText(theText);
2392 //=======================================================================
2393 // name : SMESHGUI_FilterTable::SetText
2394 // Purpose : Get text and internal value from cell of threshold value
2395 //=======================================================================
2396 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2398 const int theEntityType)
2400 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2401 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2404 theText = anItem->text();
2411 //=======================================================================
2412 // name : SMESHGUI_FilterTable::SetID
2413 // Purpose : Set text and internal value in cell of ID value
2414 //=======================================================================
2415 void SMESHGUI_FilterTable::SetID( const int theRow,
2416 const QString& theText,
2417 const int theEntityType )
2419 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2420 aTable->item( theRow, 5 )->setText( theText );
2423 //=======================================================================
2424 // name : SMESHGUI_FilterTable::GetID
2425 // Purpose : Get text and internal value from cell of ID value
2426 //=======================================================================
2427 bool SMESHGUI_FilterTable::GetID( const int theRow,
2429 const int theEntityType )
2431 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2432 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2435 theText = anItem->text();
2443 Class : SMESHGUI_FilterDlg
2444 Description : Dialog to specify filters for VTK viewer
2448 //=======================================================================
2449 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2450 // Purpose : Constructor
2451 //=======================================================================
2452 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2453 const QList<int>& theTypes )
2454 : QDialog( SMESH::GetDesktop( theModule ) ),
2455 mySMESHGUI( theModule ),
2456 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2457 myInitSourceWgOnApply( true )
2459 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2460 mySelector = aViewWindow->GetSelector();
2462 construct(theTypes);
2465 //=======================================================================
2466 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2467 // Purpose : Constructor
2468 //=======================================================================
2469 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2471 : QDialog( SMESH::GetDesktop( theModule ) ),
2472 mySMESHGUI( theModule ),
2473 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2474 myInitSourceWgOnApply( true )
2476 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2477 mySelector = aViewWindow->GetSelector();
2479 aTypes.append(theType);
2483 //=======================================================================
2484 // name : SMESHGUI_FilterDlg::construct
2485 // Purpose : Construct dialog (called by constructor)
2486 //=======================================================================
2487 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2492 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2493 setWindowTitle(tr("CAPTION"));
2495 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2496 aDlgLay->setMargin(MARGIN);
2497 aDlgLay->setSpacing(SPACING);
2499 myMainFrame = createMainFrame (this);
2500 QWidget* aBtnFrame = createButtonFrame(this);
2502 aDlgLay->addWidget(myMainFrame);
2503 aDlgLay->addWidget(aBtnFrame);
2505 aDlgLay->setStretchFactor(myMainFrame, 1);
2507 myHelpFileName = "selection_filter_library_page.html";
2512 //=======================================================================
2513 // name : SMESHGUI_FilterDlg::createMainFrame
2514 // Purpose : Create frame containing dialog's input fields
2515 //=======================================================================
2516 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2518 QWidget* aMainFrame = new QWidget(theParent);
2519 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2520 aMainLay->setMargin(0);
2521 aMainLay->setSpacing(SPACING);
2525 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2526 myTable->SetLibsEnabled(true);
2528 QGroupBox* aGrp = myTable->GetTableGrp();
2529 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2530 int rows = aLay->rowCount();
2531 int cols = aLay->columnCount();
2533 QFrame* aLine = new QFrame(aGrp);
2534 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2535 aLay->addWidget(aLine, rows++, 0, 1, cols);
2537 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2538 mySetInViewer->setChecked(true);
2539 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2542 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2544 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2545 SLOT(onCriterionChanged(const int, const int)));
2547 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2548 SLOT(onCurrentChanged(int, int)));
2550 aMainLay->addWidget(myTable);
2551 aMainLay->addWidget(aSourceGrp);
2556 //=======================================================================
2557 // name : SMESHGUI_FilterDlg::createSourceFrame
2558 // Purpose : Create frame containing source radio button
2559 //=======================================================================
2560 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2562 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2563 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2564 aLay->setMargin(MARGIN);
2565 aLay->setSpacing(SPACING);
2567 mySourceGrp = new QButtonGroup(theParent);
2569 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2570 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2571 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2573 aLay->addWidget(aMeshBtn);
2574 aLay->addWidget(aSelBtn);
2575 aLay->addWidget(aDlgBtn);
2577 mySourceGrp->addButton(aMeshBtn, Mesh);
2578 mySourceGrp->addButton(aSelBtn, Selection);
2579 mySourceGrp->addButton(aDlgBtn, Dialog);
2581 aMeshBtn->setChecked(true);
2586 //=======================================================================
2587 // name : SMESHGUI_FilterDlg::updateMainButtons
2588 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2589 //=======================================================================
2590 void SMESHGUI_FilterDlg::updateMainButtons()
2592 myButtons[ BTN_Close ]->show();
2593 if (myTypes.count() == 1)
2595 myButtons[ BTN_Apply ]->hide();
2599 myButtons[ BTN_Apply ]->show();
2601 // updateGeometry();
2604 //=======================================================================
2605 // name : SMESHGUI_FilterDlg::createButtonFrame
2606 // Purpose : Create frame containing buttons
2607 //=======================================================================
2608 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2610 QGroupBox* aGrp = new QGroupBox(theParent);
2611 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2612 aLay->setMargin(MARGIN);
2613 aLay->setSpacing(SPACING);
2615 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2616 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2617 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2618 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2620 aLay->addWidget(myButtons[ BTN_OK ]);
2621 aLay->addSpacing(10);
2622 aLay->addWidget(myButtons[ BTN_Apply ]);
2623 aLay->addSpacing(10);
2625 aLay->addWidget(myButtons[ BTN_Close ]);
2626 aLay->addWidget(myButtons[ BTN_Help ]);
2628 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2629 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
2630 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2631 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2633 updateMainButtons();
2638 //=======================================================================
2639 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2640 // Purpose : Destructor
2641 //=======================================================================
2642 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2646 //=======================================================================
2647 // name : SMESHGUI_FilterDlg::Init
2648 // Purpose : Init dialog fields, connect signals and slots, show dialog
2649 //=======================================================================
2650 void SMESHGUI_FilterDlg::Init (const int type)
2653 aTypes.append(type);
2657 //=======================================================================
2658 // name : SMESHGUI_FilterDlg::Init
2659 // Purpose : Init dialog fields, connect signals and slots, show dialog
2660 //=======================================================================
2661 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2665 myMesh = SMESH::SMESH_Mesh::_nil();
2667 myIsSelectionChanged = false;
2669 myTable->Init(theTypes);
2672 if (theTypes.count() == 1)
2674 int aType = theTypes.first();
2675 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2676 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2677 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2678 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2679 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2682 setWindowTitle(tr("TLT"));
2684 qApp->processEvents();
2689 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2691 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2692 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2694 updateMainButtons();
2697 // Initialise filter table with values of previous filter
2698 QList<int>::const_iterator anIter;
2699 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2701 myTable->Clear(*anIter);
2702 if (!myFilter[ *anIter ]->_is_nil())
2704 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2705 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2707 for (int i = 0, n = aCriteria->length(); i < n; i++)
2708 myTable->AddCriterion(aCriteria[ i ], *anIter);
2713 if (myInsertState.contains(theTypes.first()))
2714 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2716 mySetInViewer->setChecked(true);
2718 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2719 myApplyToState[ theTypes.first() ] :
2720 Mesh)->setChecked(true);
2723 //=======================================================================
2724 // name : SMESHGUI_FilterDlg::onOk
2725 // Purpose : SLOT called when "Ok" button pressed.
2726 // Assign filters VTK viewer and close dialog
2727 //=======================================================================
2728 void SMESHGUI_FilterDlg::onOk()
2732 mySelectionMgr->clearFilters();
2733 disconnect(mySMESHGUI, 0, this, 0);
2734 disconnect(mySelectionMgr, 0, this, 0);
2735 mySMESHGUI->ResetState();
2741 //=======================================================================
2742 // name : SMESHGUI_FilterDlg::onClose
2743 // Purpose : SLOT called when "Close" button pressed. Close dialog
2744 //=======================================================================
2745 void SMESHGUI_FilterDlg::onClose()
2747 // Restore previously selected object
2750 SALOME_ListIO aList;
2751 mySelectionMgr->clearFilters();
2752 mySelectionMgr->clearSelected();
2753 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2754 for ( ; anIter.More(); anIter.Next())
2756 aList.Append(anIter.Key());
2758 TColStd_MapOfInteger aResMap;
2759 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2760 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2761 aResMap.Add(anIndMap(i));
2763 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2764 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2765 aViewWindow->highlight( anIter.Key(), true, true );
2767 mySelectionMgr->setSelectedObjects(aList, false);
2770 disconnect(mySMESHGUI, 0, this, 0);
2771 disconnect(mySelectionMgr, 0, this, 0);
2772 mySMESHGUI->ResetState();
2777 //=================================================================================
2778 // function : onHelp()
2780 //=================================================================================
2781 void SMESHGUI_FilterDlg::onHelp()
2783 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2785 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2789 platform = "winapplication";
2791 platform = "application";
2793 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2794 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2795 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2797 arg(myHelpFileName));
2801 //=======================================================================
2802 // name : SMESHGUI_FilterDlg::onDeactivate
2803 // Purpose : SLOT called when dialog must be deativated
2804 //=======================================================================
2805 void SMESHGUI_FilterDlg::onDeactivate()
2810 //=======================================================================
2811 // name : SMESHGUI_FilterDlg::enterEvent
2812 // Purpose : Event filter
2813 //=======================================================================
2814 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2816 // mySMESHGUI->EmitSignalDeactivateDialog();
2817 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2818 mySMESHGUI->ResetState();
2822 //=======================================================================
2823 // name : closeEvent()
2825 //=======================================================================
2826 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2831 //=======================================================================
2832 // name : SMESHGUI_FilterDlg::getIdsFromWg
2833 // Purpose : Retrieve list of ids from given widget
2834 //=======================================================================
2835 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2841 if (theWg->inherits("QListWidget"))
2843 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2845 for (int i = 0, n = aListBox->count(); i < n; i++)
2847 int anId = aListBox->item(i)->text().toInt(&b);
2849 theRes.append(anId);
2852 else if (theWg->inherits("QLineEdit"))
2854 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2855 QString aStr = aLineEdit->text();
2856 QRegExp aRegExp("(\\d+)");
2861 aPos = aRegExp.indexIn(aStr, aPos);
2864 int anId = aRegExp.cap(1).toInt(&b);
2866 theRes.append(anId);
2867 aPos += aRegExp.matchedLength();
2873 //=======================================================================
2874 // name : SMESHGUI_FilterDlg::getSelMode
2875 // Purpose : Get selection mode of specified type
2876 //=======================================================================
2877 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2881 case SMESH::NODE : return NodeSelection;
2882 case SMESH::EDGE : return EdgeSelection;
2883 case SMESH::FACE : return FaceSelection;
2884 case SMESH::VOLUME : return VolumeSelection;
2885 case SMESH::ALL : return CellSelection;
2886 default : return ActorSelection;
2891 //=======================================================================
2892 // name : SMESHGUI_FilterDlg::setIdsToWg
2893 // Purpose : Insert identifiers in specified widgets
2894 //=======================================================================
2895 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2900 QStringList aStrList;
2901 foreach(int id, theIds)
2902 aStrList << QString::number(id);
2904 if (theWg->inherits("QListWidget"))
2906 qobject_cast<QListWidget*>(theWg)->clear();
2907 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2909 else if (theWg->inherits("QLineEdit"))
2911 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2915 //=======================================================================
2916 // name : SMESHGUI_FilterDlg::isValid
2917 // Purpose : Verify validity of input data
2918 //=======================================================================
2919 bool SMESHGUI_FilterDlg::isValid() const
2921 if (!myTable->IsValid())
2924 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2926 int aType = myTable->GetCriterionType(i);
2927 if (aType == SMESH::FT_BelongToGeom ||
2928 aType == SMESH::FT_BelongToPlane ||
2929 aType == SMESH::FT_BelongToCylinder ||
2930 aType == SMESH::FT_BelongToGenSurface ||
2931 aType == SMESH::FT_LyingOnGeom)
2934 myTable->GetThreshold(i, aName);
2936 std::vector<_PTR(SObject)> aList =
2937 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2938 if (aList.size() == 0) {
2939 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2940 tr("BAD_SHAPE_NAME").arg(aName));
2944 if (aType == SMESH::FT_BelongToCylinder ||
2945 aType == SMESH::FT_BelongToPlane ||
2946 aType == SMESH::FT_BelongToGenSurface ) {
2947 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2948 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2949 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2950 if (!aGeomObj->_is_nil()) {
2952 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2954 aFace.ShapeType() != TopAbs_FACE) {
2955 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2956 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2960 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2961 if (aSurf.IsNull()) {
2962 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2963 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2967 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2968 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2969 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2973 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2974 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2975 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2981 else if (aType == SMESH::FT_CoplanarFaces)
2984 myTable->GetThreshold(i, faceID);
2985 if ( faceID.isEmpty() )
2987 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2988 tr("FACE_ID_NOT_SELECTED"));
2991 if ( myMesh->_is_nil() )
2993 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2994 tr("MESH_IS_NOT_SELECTED"));
2997 if ( myMesh->GetElementType( faceID.toLong(), /*iselem=*/true) != SMESH::FACE )
2999 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
3000 tr("NOT_FACE_ID").arg(faceID));
3009 //=======================================================================
3010 // name : SMESHGUI_FilterDlg::SetSourceWg
3011 // Purpose : Set widget of parent dialog containing idsto be filtered if
3012 // user select corresponding source radio button
3013 //=======================================================================
3014 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
3015 const bool initOnApply)
3018 myInitSourceWgOnApply = initOnApply;
3021 //=======================================================================
3022 // name : SMESHGUI_FilterDlg::SetMesh
3023 // Purpose : Set mesh
3024 //=======================================================================
3025 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
3027 if ( !theMesh->_is_nil() ) {
3029 if ( !myFilter[ myTable->GetType() ]->_is_nil())
3030 myFilter[ myTable->GetType() ]->SetMesh( theMesh );
3032 const bool isEnable = !(myMesh->_is_nil());
3033 myButtons[BTN_OK]->setEnabled(isEnable);
3034 myButtons[BTN_Apply]->setEnabled(isEnable);
3037 //=======================================================================
3038 // name : SMESHGUI_FilterDlg::SetSelection
3039 // Purpose : Get filtered ids
3040 //=======================================================================
3041 void SMESHGUI_FilterDlg::SetSelection()
3044 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
3046 if (mySelectionMgr) {
3048 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
3049 SALOME_ListIteratorOfListIO anIter (anObjs);
3050 for ( ; anIter.More(); anIter.Next()) {
3051 TColStd_IndexedMapOfInteger aMap;
3052 mySelector->GetIndex(anIter.Value(), aMap);
3053 myIObjects.Bind(anIter.Value(), aMap);
3056 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
3064 //=======================================================================
3065 // name : SMESHGUI_FilterDlg::onApply
3066 // Purpose : SLOT called when "Apply" button pressed.
3067 // Assign filters to VTK viewer
3068 //=======================================================================
3069 bool SMESHGUI_FilterDlg::onApply()
3075 int aCurrType = myTable->GetType();
3077 if (!createFilter(aCurrType))
3080 insertFilterInViewer();
3082 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
3083 QList<int> aResultIds;
3084 filterSource(aCurrType, aResultIds);
3086 selectInViewer(aCurrType, aResultIds);
3090 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
3091 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
3093 catch(const SALOME::SALOME_Exception& S_ex)
3095 SalomeApp_Tools::QtCatchCorbaException(S_ex);
3104 //=======================================================================
3105 // name : SMESHGUI_FilterDlg::createFilter
3106 // Purpose : Create predicate for given type
3107 //=======================================================================
3108 bool SMESHGUI_FilterDlg::createFilter (const int theType)
3110 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
3111 if (aFilterMgr->_is_nil())
3114 int n = myTable->NumRows();
3116 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
3117 aCriteria->length(n);
3119 long aPrecision = -1;
3120 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
3122 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
3123 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
3125 for (CORBA::ULong i = 0; i < n; i++) {
3126 SMESH::Filter::Criterion aCriterion = createCriterion();
3127 myTable->GetCriterion(i, aCriterion);
3128 aCriterion.Precision = aPrecision;
3129 aCriteria[ i ] = aCriterion;
3132 myFilter[ theType ] = aFilterMgr->CreateFilter();
3133 myFilter[ theType ]->SetCriteria(aCriteria.inout());
3138 //================================================================================
3140 * \brief Return the current filter
3142 //================================================================================
3144 SMESH::Filter_var SMESHGUI_FilterDlg::GetFilter() const
3146 SMESH::Filter_var filter;
3148 int aCurrType = myTable->GetType();
3149 filter = myFilter[ aCurrType ];
3154 return filter._retn();
3157 //================================================================================
3159 * \brief Sets a filter to the table
3161 //================================================================================
3163 void SMESHGUI_FilterDlg::SetFilter(SMESH::Filter_var filter, int type)
3165 myFilter[ type ] = filter;
3168 //=======================================================================
3169 // name : SMESHGUI_FilterDlg::insertFilterInViewer
3170 // Purpose : Insert filter in viewer
3171 //=======================================================================
3172 void SMESHGUI_FilterDlg::insertFilterInViewer()
3174 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
3175 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
3177 if (myFilter[ myTable->GetType() ]->_is_nil() ||
3178 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
3179 !mySetInViewer->isChecked()) {
3180 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
3183 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
3184 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
3185 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
3186 SMESH::SetFilter(aFilter, aSelector);
3191 //=======================================================================
3192 // name : SMESHGUI_FilterDlg::filterSource
3193 // Purpose : Filter source ids
3194 //=======================================================================
3195 void SMESHGUI_FilterDlg::filterSource (const int theType,
3196 QList<int>& theResIds)
3199 if (myFilter[ theType ]->_is_nil())
3202 int aSourceId = mySourceGrp->checkedId();
3204 if (aSourceId == Mesh)
3206 if (myMesh->_is_nil())
3208 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
3209 for (int i = 0, n = anIds->length(); i < n; i++)
3210 theResIds.append(anIds[ i ]);
3212 else if (aSourceId == Selection)
3214 filterSelectionSource(theType, theResIds);
3216 else if (aSourceId == Dialog)
3218 // retrieve ids from dialog
3219 QList<int> aDialogIds;
3220 getIdsFromWg(mySourceWg, aDialogIds);
3222 if (myMesh->_is_nil())
3224 theResIds = aDialogIds;
3229 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3230 myFilter[ theType ]->SetMesh(myMesh);
3231 QList<int>::const_iterator anIter;
3232 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
3233 if (aPred->IsSatisfy(*anIter))
3234 theResIds.append(*anIter);
3236 // set ids to the dialog
3237 if (myInitSourceWgOnApply || aSourceId == Dialog)
3238 setIdsToWg(mySourceWg, theResIds);
3241 //=======================================================================
3242 // name : SMESHGUI_FilterDlg::filterSelectionSource
3243 // Purpose : Filter source selection
3244 //=======================================================================
3245 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
3246 QList<int>& theResIds)
3249 if (myMesh->_is_nil() || mySelectionMgr == 0)
3252 // Create map of entities to be filtered
3253 TColStd_MapOfInteger aToBeFiltered;
3254 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
3256 for ( ; anIter.More(); anIter.Next())
3259 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
3260 if (!aSubMesh->_is_nil())
3262 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
3264 SMESH::long_array_var anIds =
3265 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
3266 for (int i = 0, n = anIds->length(); i < n; i++)
3267 aToBeFiltered.Add(anIds[ i ]);
3272 SMESH::SMESH_GroupBase_var aGroup =
3273 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
3274 if (!aGroup->_is_nil())
3276 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
3278 SMESH::long_array_var anIds = aGroup->GetListOfID();
3279 for (int i = 0, n = anIds->length(); i < n; i++)
3280 aToBeFiltered.Add(anIds[ i ]);
3285 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
3286 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
3288 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
3290 if (aSelMap.Extent() > 0)
3292 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
3294 for (int i = 1; i <= aSelMap.Extent(); i++)
3295 aToBeFiltered.Add(aSelMap(i));
3302 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
3303 myFilter[ theType ]->SetMesh(myMesh);
3304 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
3305 for ( ; aResIter.More(); aResIter.Next())
3306 if (aPred->IsSatisfy(aResIter.Key()))
3307 theResIds.append(aResIter.Key());
3310 //=======================================================================
3311 // name : SMESHGUI_FilterDlg::selectInViewer
3312 // Purpose : Select given entities in viewer
3313 //=======================================================================
3314 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
3316 if (mySelectionMgr == 0 || myMesh->_is_nil())
3319 mySelectionMgr->clearFilters();
3321 // Set new selection mode if necessary
3322 Selection_Mode aSelMode = getSelMode(theType);
3323 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
3324 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
3325 mySelectionMgr->clearSelected();
3326 mySelectionMgr->clearFilters();
3327 if (aSelMode == NodeSelection)
3328 SMESH::SetPointRepresentation(true);
3329 aViewWindow->SetSelectionMode(aSelMode);
3333 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
3334 if (!anActor || !anActor->hasIO())
3337 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3338 //mySelectionMgr->clearSelected();
3339 //mySelectionMgr->AddIObject(anIO, false);
3340 SALOME_ListIO aList;
3342 mySelectionMgr->setSelectedObjects(aList, false);
3344 // Remove filter corresponding to the current type from viewer
3345 int aType = myTable->GetType();
3346 int aFilterId = SMESH::UnknownFilter;
3347 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3348 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3349 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3350 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3351 SMESH::RemoveFilter(aFilterId);
3354 TColStd_MapOfInteger aMap;
3355 QList<int>::const_iterator anIter;
3356 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3360 // Set new selection
3361 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3362 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3363 aViewWindow->highlight( anIO, true, true );
3365 // insert previously stored filter in viewer if necessary
3366 if (!aFilter.IsNull())
3367 SMESH::SetFilter(aFilter);
3370 //=======================================================================
3371 // name : SMESHGUI_FilterDlg::createCriterion
3372 // Purpose : Create criterion structure with default values
3373 //=======================================================================
3374 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3376 SMESH::Filter::Criterion aCriterion;
3378 aCriterion.Type = SMESH::FT_Undefined;
3379 aCriterion.Compare = SMESH::FT_Undefined;
3380 aCriterion.Threshold = 0;
3381 aCriterion.UnaryOp = SMESH::FT_Undefined;
3382 aCriterion.BinaryOp = SMESH::FT_Undefined;
3383 aCriterion.ThresholdStr = "";
3384 aCriterion.ThresholdID = "";
3385 aCriterion.TypeOfElement = SMESH::ALL;
3390 //=======================================================================
3391 // name : SMESHGUI_FilterDlg::onSelectionDone
3392 // Purpose : SLOT called when selection changed.
3393 // If current cell corresponds to the threshold value of
3394 // BelongToGeom criterion name of selected object is set in this cell
3395 //=======================================================================
3396 void SMESHGUI_FilterDlg::onSelectionDone()
3399 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3401 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3402 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3403 if ( !(myMesh->_is_nil()) ) {
3404 myButtons[BTN_OK]->setEnabled(true);
3405 myButtons[BTN_Apply]->setEnabled(true);
3410 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3411 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3412 << SMESH::FT_LyingOnGeom << SMESH::FT_CoplanarFaces;
3413 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
3414 !types.contains(myTable->GetCriterionType(aRow)))
3417 if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
3420 int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
3421 aList.First(), aString);
3423 myTable->SetThreshold(aRow, aString);
3427 Handle(SALOME_InteractiveObject) anIO = aList.First();
3428 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3429 if (!anObj->_is_nil())
3431 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3432 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3433 myTable->SetID(aRow, anIO->getEntry());
3439 //=======================================================================
3440 // name : SMESHGUI_FilterDlg::onCriterionChanged
3441 // Purpose : SLOT called when cretarion of current row changed. Update selection
3442 //=======================================================================
3443 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3448 //=======================================================================
3449 // name : SMESHGUI_FilterDlg::onCurrentChanged
3450 // Purpose : SLOT called when current row changed. Update selection
3451 //=======================================================================
3452 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3457 //=======================================================================
3458 // name : SMESHGUI_FilterDlg::updateSelection
3459 // Purpose : UpdateSelection in accordance with current row
3460 //=======================================================================
3461 void SMESHGUI_FilterDlg::updateSelection()
3463 if (mySelectionMgr == 0)
3466 // TColStd_MapOfInteger allTypes;
3467 // for( int i=0; i<10; i++ )
3468 // allTypes.Add( i );
3469 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3474 mySelectionMgr->clearFilters();
3478 bool isCurrentCell = myTable->CurrentCell(aRow, aCol);
3479 int aCriterionType = myTable->GetCriterionType(aRow);
3480 if ( isCurrentCell &&
3481 (aCriterionType == SMESH::FT_BelongToGeom ||
3482 aCriterionType == SMESH::FT_BelongToPlane ||
3483 aCriterionType == SMESH::FT_BelongToCylinder ||
3484 aCriterionType == SMESH::FT_BelongToGenSurface ||
3485 aCriterionType == SMESH::FT_LyingOnGeom))
3487 if (aCriterionType == SMESH::FT_BelongToGeom ||
3488 aCriterionType == SMESH::FT_BelongToGenSurface ||
3489 aCriterionType == SMESH::FT_LyingOnGeom) {
3491 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3493 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3494 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3496 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3497 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3499 myIsSelectionChanged = true;
3504 if (myIsSelectionChanged) {
3505 // mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3506 // Impossible to select any object in the OB on the second opening of FilterDlg
3511 //=================================================================================
3512 // function : keyPressEvent()
3514 //=================================================================================
3515 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3517 QDialog::keyPressEvent( e );
3518 if ( e->isAccepted() )
3521 if ( e->key() == Qt::Key_F1 ) {