1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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
22 // File : SMESHGUI_FilterDlg.cxx
23 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_FilterDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Filter.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_FilterLibraryDlg.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_NumberFilter.hxx>
38 #include <SMESH_TypeFilter.hxx>
40 // SALOME GEOM includes
42 #include <GEOM_FaceFilter.h>
43 #include <GEOM_TypeFilter.h>
45 // SALOME GUI includes
46 #include <SUIT_Desktop.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_MessageBox.h>
51 #include <LightApp_Application.h>
52 #include <LightApp_SelectionMgr.h>
53 #include <SalomeApp_Tools.h>
54 #include <SalomeApp_Study.h>
56 #include <SALOME_ListIO.hxx>
57 #include <SALOME_ListIteratorOfListIO.hxx>
58 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
60 #include <SVTK_ViewWindow.h>
62 // SALOME KERNEL includes
63 #include <SALOMEDSClient_Study.hxx>
66 #include <StdSelect_TypeOfFace.hxx>
67 #include <BRep_Tool.hxx>
69 #include <TopoDS_Shape.hxx>
70 #include <Geom_Plane.hxx>
71 #include <Geom_CylindricalSurface.hxx>
72 #include <Precision.hxx>
73 #include <TColStd_MapOfInteger.hxx>
74 #include <TColStd_IndexedMapOfInteger.hxx>
75 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
80 #include <QPushButton>
82 #include <QTableWidget>
83 #include <QStringList>
84 #include <QHBoxLayout>
85 #include <QVBoxLayout>
86 #include <QGridLayout>
87 #include <QStackedWidget>
88 #include <QApplication>
90 #include <QFontMetrics>
92 #include <QButtonGroup>
93 #include <QRadioButton>
95 #include <QListWidget>
97 #include <QItemDelegate>
98 #include <QDoubleValidator>
100 #include <QHeaderView>
103 #include <SALOMEconfig.h>
104 #include CORBA_SERVER_HEADER(SMESH_Group)
109 //---------------------------------------
111 //---------------------------------------
112 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
115 QMap<int, QString>::const_iterator anIter;
116 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
117 aRes = qMax(aRes, theMetrics.width(anIter.value()));
121 //---------------------------------------
123 //---------------------------------------
124 static int getFilterId (SMESH::ElementType theType)
128 case SMESH::NODE : return SMESH::NodeFilter;
129 case SMESH::EDGE : return SMESH::EdgeFilter;
130 case SMESH::FACE : return SMESH::FaceFilter;
131 case SMESH::VOLUME : return SMESH::VolumeFilter;
132 case SMESH::ALL : return SMESH::AllElementsFilter;
133 default : return SMESH::UnknownFilter;
138 Class : SMESHGUI_FilterTable::AdditionalWidget
139 Description : Class for storing additional parameters of criterion
142 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
148 AdditionalWidget(QWidget* theParent);
149 virtual ~AdditionalWidget();
151 virtual QList<int> GetParameters() const;
152 virtual bool IsValid(const bool = true) const;
153 virtual double GetDouble(const int) const;
154 virtual int GetInteger(const int) const;
155 virtual QString GetString(const int) const;
156 virtual void SetDouble(const int, const double);
157 virtual void SetInteger(const int, const int);
158 virtual void SetString(const int, const QString&);
159 void SetEditable(const int, const bool);
160 void SetEditable(const bool);
163 QMap< int, QLineEdit* > myLineEdits;
166 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
169 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
170 myLineEdits[ Tolerance ] = new QLineEdit(this);
171 QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]);
172 aValidator->setBottom(0);
173 myLineEdits[ Tolerance ]->setValidator(aValidator);
175 QHBoxLayout* aLay = new QHBoxLayout(this);
176 aLay->setSpacing(SPACING);
179 aLay->addWidget(aLabel);
180 aLay->addWidget(myLineEdits[ Tolerance ]);
183 QString aText = QString("%1").arg(Precision::Confusion());
184 myLineEdits[ Tolerance ]->setText(aText);
187 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
191 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
194 theList.append(Tolerance);
198 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
203 QList<int> aParams = GetParameters();
204 QList<int>::const_iterator anIter;
205 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
206 const QLineEdit* aWg = myLineEdits[ *anIter ];
208 QString aText = aWg->text();
209 if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) {
211 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
212 tr("SMESHGUI_INVALID_PARAMETERS"));
220 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
222 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toDouble() : 0;
225 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
227 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toInt() : 0;
230 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
232 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text() : QString("");
235 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
237 if (myLineEdits.contains(theId))
238 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
241 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
243 if (myLineEdits.contains(theId))
244 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
247 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
249 if (myLineEdits.contains(theId))
250 myLineEdits[ theId ]->setText(theVal);
253 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
255 if (myLineEdits.contains(theId))
256 myLineEdits[ theId ]->setReadOnly(!isEditable);
259 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
261 QList<int> aParams = GetParameters();
262 QList<int>::const_iterator anIter;
263 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
264 SetEditable( *anIter, isEditable );
268 Class : SMESHGUI_FilterTable::ComboItem
269 Description : Combo table item. Identificator corresponding to string may be assigned
272 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
277 ComboItem( const QMap<int, QString>& );
279 void setItems( const QMap<int, QString>& );
284 void setValue( const int );
288 int index( int ) const;
291 QMap<int, int> myIdToIdx;
294 int SMESHGUI_FilterTable::ComboItem::Type()
296 return QTableWidgetItem::UserType + 1;
299 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
300 : QTableWidgetItem( Type() )
305 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
308 QMap<int, QString>::const_iterator it;
310 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
311 myIdToIdx[it.key()] = items.count();
312 items.append( it.value() );
314 setData( Qt::UserRole, items );
318 void SMESHGUI_FilterTable::ComboItem::clear()
320 QMap<int, QString> empty;
324 int SMESHGUI_FilterTable::ComboItem::count() const
326 return myIdToIdx.count();
329 int SMESHGUI_FilterTable::ComboItem::value() const
331 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
334 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
336 int idx = index( theId );
337 QStringList items = data( Qt::UserRole ).toStringList();
338 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
341 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
343 QMap<int,int>::const_iterator it;
344 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
345 if ( it.value() == idx ) return it.key();
349 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
351 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
354 Class : SMESHGUI_FilterTable::CheckItem
355 Description : Check table item.
358 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
363 CheckItem( bool = false );
364 CheckItem( const QString&, bool = false );
367 void setChecked( bool );
368 bool checked() const;
371 int SMESHGUI_FilterTable::CheckItem::Type()
373 return QTableWidgetItem::UserType + 2;
376 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
377 : QTableWidgetItem( Type() )
379 Qt::ItemFlags f = flags();
380 f = f | Qt::ItemIsUserCheckable;
381 f = f & ~Qt::ItemIsTristate;
382 f = f & ~Qt::ItemIsEditable;
387 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
388 : QTableWidgetItem( Type() )
390 Qt::ItemFlags f = flags();
391 f = f | Qt::ItemIsUserCheckable;
392 f = f & ~Qt::ItemIsTristate;
393 f = f & ~Qt::ItemIsEditable;
399 SMESHGUI_FilterTable::CheckItem::~CheckItem()
403 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
405 setCheckState( value ? Qt::Checked : Qt::Unchecked );
408 bool SMESHGUI_FilterTable::CheckItem::checked() const
410 return checkState() == Qt::Checked;
414 Class : SMESHGUI_FilterTable::ComboDelegate
415 Description : Table used by this widget
418 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
421 ComboDelegate( QObject* = 0 );
424 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
425 const QModelIndex& ) const;
427 void setEditorData( QWidget*, const QModelIndex& ) const;
428 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
430 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
431 const QModelIndex& ) const;
433 QTableWidget* myTable;
436 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
437 : QItemDelegate( parent ),
438 myTable( qobject_cast<QTableWidget*>( parent ) )
442 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
446 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
447 const QStyleOptionViewItem& option,
448 const QModelIndex& index ) const
450 QStringList l = index.data( Qt::UserRole ).toStringList();
451 if ( !l.isEmpty() ) {
452 QComboBox* cb = new QComboBox( parent );
453 cb->setFrame( false );
457 return QItemDelegate::createEditor( parent, option, index );
460 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
461 const QModelIndex& index ) const
463 QString value = index.model()->data( index, Qt::DisplayRole ).toString();
464 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
467 int i = cb->findText( value );
469 cb->setCurrentIndex( i );
473 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
476 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
477 QAbstractItemModel* model,
478 const QModelIndex& index) const
480 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
481 if ( cb ) model->setData( index, cb->currentText(), Qt::DisplayRole );
482 else QItemDelegate::setModelData( editor, model, index );
485 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
486 const QStyleOptionViewItem& option,
487 const QModelIndex& index ) const
489 editor->setGeometry( option.rect );
493 Class : SMESHGUI_FilterTable::Table
494 Description : Table used by this widget
497 class SMESHGUI_FilterTable::Table : public QTableWidget
500 Table( QWidget* = 0 );
501 Table( int, int, QWidget* = 0 );
504 QSize minimumSizeHint() const;
506 void setEditable( bool, int, int );
507 bool isEditable( int, int ) const;
509 void setReadOnly( bool );
510 bool isReadOnly() const;
512 void insertRows( int, int = 1 );
513 QString text( int, int );
515 QList<int> selectedRows();
518 //=======================================================================
519 // name : SMESHGUI_FilterTable::Table::Table
520 // Purpose : Constructor
521 //=======================================================================
522 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
523 : QTableWidget(parent)
525 // set custom item delegate
526 setItemDelegate( new ComboDelegate(this) );
527 // set edit triggers by default
528 setReadOnly( false );
531 //=======================================================================
532 // name : SMESHGUI_FilterTable::Table::Table
533 // Purpose : Constructor
534 //=======================================================================
535 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
536 : QTableWidget(numRows, numCols, parent)
538 // set custom item delegate
539 setItemDelegate( new ComboDelegate(this) );
540 // set edit triggers by default
541 setReadOnly( false );
544 //=======================================================================
545 // name : SMESHGUI_FilterTable::Table::~Table
546 // Purpose : Destructor
547 //=======================================================================
548 SMESHGUI_FilterTable::Table::~Table()
552 //=======================================================================
553 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
554 // Purpose : Get minimum size for the table
555 //=======================================================================
556 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
558 QSize s = QTableWidget::minimumSizeHint();
559 QHeaderView* hv = horizontalHeader();
561 s.setWidth( qMax( s.width(), hv->length() ) );
565 //=======================================================================
566 // name : SMESHGUI_FilterTable::Table::setEditable
567 // Purpose : Set editable of specified cell
568 //=======================================================================
569 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
572 QTableWidgetItem* anItem = item( row, col );
574 bool isSignalsBlocked = signalsBlocked();
575 blockSignals( true );
577 Qt::ItemFlags f = anItem->flags();
578 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
579 else f = f | Qt::ItemIsEditable;
580 anItem->setFlags( f );
582 blockSignals( isSignalsBlocked );
586 //=======================================================================
587 // name : SMESHGUI_FilterTable::Table::isEditable
588 // Purpose : Verify wheter cell is editable
589 //=======================================================================
590 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
592 QTableWidgetItem* anItem = item( row, col );
593 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
596 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
598 setEditTriggers( on ?
599 QAbstractItemView::NoEditTriggers :
600 QAbstractItemView::AllEditTriggers );
603 bool SMESHGUI_FilterTable::Table::isReadOnly() const
605 return editTriggers() == QAbstractItemView::NoEditTriggers;
608 //=======================================================================
609 // name : SMESHGUI_FilterTable::Table::insertRows
610 // Purpose : Insert rows (virtual redefined)
611 //=======================================================================
612 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
614 closePersistentEditor( currentItem() );
615 while ( count-- ) insertRow( row );
618 //=======================================================================
619 // name : SMESHGUI_FilterTable::Table::text
620 // Purpose : Get text from cell (virtual redefined)
621 //=======================================================================
622 QString SMESHGUI_FilterTable::Table::text (int row, int col)
624 closePersistentEditor( currentItem() );
625 QTableWidgetItem* anItem = item( row, col );
626 return anItem ? anItem->text() : QString();
629 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
631 QList<QTableWidgetItem*> selItems = selectedItems();
632 QTableWidgetItem* anItem;
635 foreach( anItem, selItems ) {
636 int r = row( anItem );
637 if ( !rows.contains( r ) ) rows.append( r );
645 Class : SMESHGUI_FilterTable
646 Description : Frame containig
647 - Button group for switching entity type
648 - Table for displaying filter criterions
649 - Buttons for editing table and filter libraries
652 //=======================================================================
653 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
654 // Purpose : Constructor
655 //=======================================================================
656 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
661 mySMESHGUI( theModule )
670 //=======================================================================
671 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
672 // Purpose : Constructor
673 //=======================================================================
674 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
676 const QList<int>& types )
679 mySMESHGUI( theModule )
685 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
689 //=======================================================================
690 // name : SMESHGUI_FilterTable::Init
691 // Purpose : Create table corresponding to the specified type
692 //=======================================================================
693 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
695 if (theTypes.isEmpty())
698 // Create buttons if necessary
700 if (myTables.isEmpty())
702 int aType = theTypes.first();
704 // create main layout
705 QVBoxLayout* aMainLay = new QVBoxLayout(this);
706 aMainLay->setMargin( 0 );
707 aMainLay->setSpacing( SPACING );
709 // create switch of entity types
710 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
711 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
712 myEntityTypeBoxLayout->setMargin( MARGIN );
713 myEntityTypeBoxLayout->setSpacing( SPACING );
714 myEntityTypeGrp = new QButtonGroup(this);
716 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
717 QMap<int, QString>::const_iterator anIter;
718 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
720 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
721 myEntityTypeGrp->addButton(aBtn, anIter.key());
722 myEntityTypeBoxLayout->addWidget(aBtn);
725 myTableGrp = new QGroupBox(tr("FILTER"), this );
728 mySwitchTableGrp = new QWidget(myTableGrp);
729 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
730 mySwitchTableGrpLayout->setMargin(0);
731 mySwitchTableGrpLayout->setSpacing(0);
733 myTables[ aType ] = createTable(mySwitchTableGrp, aType);
734 mySwitchTableGrpLayout->addWidget(myTables[ aType ]);
737 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
738 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
739 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
740 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
741 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
742 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
744 myAddBtn->setAutoDefault(false);
745 myRemoveBtn->setAutoDefault(false);
746 myClearBtn->setAutoDefault(false);
747 myInsertBtn->setAutoDefault(false);
748 myCopyFromBtn->setAutoDefault(false);
749 myAddToBtn->setAutoDefault(false);
751 myCopyFromBtn->hide();
755 QGridLayout* aLay = new QGridLayout(myTableGrp);
756 aLay->setMargin(MARGIN);
757 aLay->setSpacing(SPACING);
759 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
760 aLay->addWidget(myAddBtn, 0, 1);
761 aLay->addWidget(myInsertBtn, 1, 1);
762 aLay->addWidget(myRemoveBtn, 2, 1);
763 aLay->addWidget(myClearBtn, 3, 1);
764 aLay->addWidget(myCopyFromBtn, 5, 1);
765 aLay->addWidget(myAddToBtn, 6, 1);
766 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
768 aLay->setRowMinimumHeight(4, 10);
769 aLay->setRowStretch(4, 1);
770 aLay->setColumnStretch(0, 1);
771 aLay->setColumnStretch(1, 0);
774 aMainLay->addWidget(myEntityTypeBox);
775 aMainLay->addWidget(myTableGrp);
778 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
779 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
780 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
781 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
783 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
784 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
786 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
791 // Hide buttons of entity types if necessary
792 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
793 QMap<int, QString>::const_iterator anIt;
794 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
796 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
797 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
800 // select first button if there is no selected buttons or it is hidden
801 int aBtnId = myEntityTypeGrp->checkedId();
802 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
803 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
804 if ( aBtn ) aBtn->setChecked(true);
807 myEntityTypeBox->setVisible(theTypes.count() > 1);
809 myTableGrp->updateGeometry();
810 int cType = myEntityTypeGrp->checkedId();
814 //=======================================================================
815 // name : SMESHGUI_FilterTable::createAdditionalFrame
816 // Purpose : Get group box containing table. May be used for adding new widgets in it
817 //=======================================================================
818 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
820 QWidget* aFrame = new QWidget(theParent);
822 QFrame* aLine1 = new QFrame(aFrame);
823 QFrame* aLine2 = new QFrame(aFrame);
824 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
825 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
826 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
827 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
829 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
831 myWgStack = new QStackedWidget(aFrame);
833 QGridLayout* aLay = new QGridLayout(aFrame);
835 aLay->setSpacing(SPACING);
836 aLay->addWidget(aLine1, 0, 0);
837 aLay->addWidget(aLabel, 0, 1);
838 aLay->addWidget(aLine2, 0, 2);
839 aLay->addWidget(myWgStack, 1, 0, 1, 3);
844 //=======================================================================
845 // name : SMESHGUI_FilterTable::GetTableGrp
846 // Purpose : Get group box containing table. May be used for adding new widgets in it
847 //=======================================================================
848 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
853 //=======================================================================
854 // name : SMESHGUI_FilterTable::onEntityType
855 // Purpose : SLOT. Called when entity type changed.
856 // Display corresponding table
857 //=======================================================================
858 void SMESHGUI_FilterTable::onEntityType (int theType)
860 if (myEntityType == theType)
864 emit NeedValidation();
867 myEntityTypeGrp->button(myEntityType)->setChecked(true);
871 myEntityType = theType;
873 if (!myTables.contains(theType)) {
874 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
875 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
878 TableMap::iterator anIter;
879 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
880 anIter.value()->setVisible( myEntityType == anIter.key() );
883 qApp->processEvents();
884 myTables[ myEntityType ]->updateGeometry();
887 emit EntityTypeChanged(theType);
890 //=======================================================================
891 // name : SMESHGUI_FilterTable::IsValid
892 // Purpose : Verify validity of entered data
893 //=======================================================================
894 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
896 int aType = theEntityType == -1 ? GetType() : theEntityType;
898 Table* aTable = myTables[ aType ];
899 for (int i = 0, n = aTable->rowCount(); i < n; i++)
901 int aCriterion = GetCriterionType(i, aType);
903 if (aCriterion == SMESH::FT_RangeOfIds ||
904 aCriterion == SMESH::FT_BelongToGeom ||
905 aCriterion == SMESH::FT_BelongToPlane ||
906 aCriterion == SMESH::FT_BelongToCylinder ||
907 aCriterion == SMESH::FT_BelongToGenSurface ||
908 aCriterion == SMESH::FT_LyingOnGeom) {
909 if (aTable->text(i, 2).isEmpty()) {
911 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
917 bool isSignalsBlocked = aTable->signalsBlocked();
918 aTable->blockSignals(true);
919 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
920 aTable->blockSignals(isSignalsBlocked);
922 if (!aRes && aTable->isEditable(i, 2)) {
924 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
928 else if (aType == SMESH::EDGE &&
929 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
933 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
934 tr("MULTIEDGES_ERROR"));
939 QTableWidgetItem* anItem = aTable->item(i, 0);
940 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
947 //=======================================================================
948 // name : SMESHGUI_FilterTable::SetValidity
949 // Purpose : Set validity of the table
950 //=======================================================================
951 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
956 //=======================================================================
957 // name : SMESHGUI_FilterTable::GetType
958 // Purpose : Get current entity type
959 //=======================================================================
960 int SMESHGUI_FilterTable::GetType() const
965 //=======================================================================
966 // name : SMESHGUI_FilterTable::SetType
967 // Purpose : Set current entity type
968 //=======================================================================
969 void SMESHGUI_FilterTable::SetType (const int type)
971 myEntityTypeGrp->button(type)->setChecked(true);
975 //=======================================================================
976 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
977 // Purpose : Restore previous entity type
978 //=======================================================================
979 void SMESHGUI_FilterTable::RestorePreviousEntityType()
981 SetType(myEntityType);
984 //=======================================================================
985 // name : SMESHGUI_FilterTable::GetCriterionType
986 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
987 //=======================================================================
988 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
990 int aType = theType == -1 ? GetType() : theType;
991 Table* aTable = myTables[ aType ];
992 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
993 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
996 //=======================================================================
997 // name : SMESHGUI_FilterTable::GetCriterion
998 // Purpose : Get parameters of criterion from specified row
999 //=======================================================================
1000 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1001 SMESH::Filter::Criterion& theCriterion,
1002 const int theEntityType) const
1004 int aType = theEntityType == -1 ? GetType() : theEntityType;
1005 Table* aTable = myTables[ aType ];
1007 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1008 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1009 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1010 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1011 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1013 int aCriterionType = GetCriterionType(theRow, aType);
1015 if ( aCriterionType != SMESH::FT_RangeOfIds &&
1016 aCriterionType != SMESH::FT_BelongToGeom &&
1017 aCriterionType != SMESH::FT_BelongToPlane &&
1018 aCriterionType != SMESH::FT_BelongToCylinder &&
1019 aCriterionType != SMESH::FT_BelongToGenSurface &&
1020 aCriterionType != SMESH::FT_LyingOnGeom)
1022 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1023 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1027 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1028 if ( aCriterionType != SMESH::FT_RangeOfIds )
1029 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1032 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1033 if (myAddWidgets.contains(anItem))
1034 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1037 //=======================================================================
1038 // name : SMESHGUI_FilterTable::SetCriterion
1039 // Purpose : Set parameters of criterion of specified row
1040 //=======================================================================
1041 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1042 const SMESH::Filter::Criterion& theCriterion,
1043 const int theEntityType)
1045 int aType = theEntityType == -1 ? GetType() : theEntityType;
1047 Table* aTable = myTables[ aType ];
1049 if (theRow > aTable->rowCount() - 1)
1052 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1053 onCriterionChanged(theRow, 0, aType);
1054 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1055 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1057 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1059 if (!aTable->isEditable(theRow, 4))
1060 aTable->setItem(theRow, 4, getBinaryItem());
1061 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1064 aTable->setEditable(false, theRow, 4);
1066 if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1067 theCriterion.Type != SMESH::FT_BelongToGeom &&
1068 theCriterion.Type != SMESH::FT_BelongToPlane &&
1069 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1070 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1071 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1072 theCriterion.Type != SMESH::FT_FreeBorders &&
1073 theCriterion.Type != SMESH::FT_FreeEdges &&
1074 theCriterion.Type != SMESH::FT_BadOrientedVolume)
1075 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1078 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1079 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1080 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1083 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1084 theCriterion.Type == SMESH::FT_BelongToPlane ||
1085 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1086 theCriterion.Type == SMESH::FT_BelongToGenSurface)
1088 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1089 if (!myAddWidgets.contains(anItem))
1091 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1092 myWgStack->addWidget(myAddWidgets[ anItem ]);
1094 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1097 emit CriterionChanged(theRow, aType);
1101 //=======================================================================
1102 // name : SMESHGUI_FilterTable::Update
1103 // Purpose : Update table
1104 //=======================================================================
1105 void SMESHGUI_FilterTable::Update()
1107 Table* aTable = myTables[ GetType() ];
1108 int aCurrRow = aTable->currentRow();
1109 int numRows = aTable->rowCount();
1110 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1111 aTable->setCurrentCell(0, 0);
1112 updateAdditionalWidget();
1115 //=======================================================================
1116 // name : SMESHGUI_FilterTable::AddCriterion
1117 // Purpose : Add criterion with parameters
1118 //=======================================================================
1119 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1120 const int theEntityType)
1122 int aType = theEntityType == -1 ? GetType() : theEntityType;
1123 Table* aTable = myTables[ aType ];
1124 addRow(aTable, aType);
1125 SetCriterion(aTable->rowCount() - 1, theCriterion);
1128 //=======================================================================
1129 // name : SMESHGUI_FilterTable::NumRows
1130 // Purpose : Get number of criterions of current type
1131 //=======================================================================
1132 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1134 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1137 //=======================================================================
1138 // name : SMESHGUI_FilterTable::Clear
1139 // Purpose : Clear current table
1140 //=======================================================================
1141 void SMESHGUI_FilterTable::Clear (const int theType)
1143 int aType = theType == -1 ? GetType() : theType;
1144 Table* aTable = myTables[ aType ];
1146 if (aTable->rowCount() == 0)
1149 while (aTable->rowCount() > 0)
1151 removeAdditionalWidget(aTable, 0);
1152 aTable->removeRow(0);
1158 //=======================================================================
1159 // name : SMESHGUI_FilterTable::onAddBtn
1160 // Purpose : SLOT. Called then "Add" button pressed.
1161 // Adds new string to table
1162 //=======================================================================
1163 void SMESHGUI_FilterTable::onAddBtn()
1165 int aType = GetType();
1166 addRow(myTables[ aType ], aType);
1171 //=======================================================================
1172 // name : SMESHGUI_FilterTable::onInsertBtn
1173 // Purpose : SLOT. Called then "Insert" button pressed.
1174 // Inserts new string before current one
1175 //=======================================================================
1176 void SMESHGUI_FilterTable::onInsertBtn()
1178 addRow(myTables[ GetType() ], GetType(), false);
1181 //=======================================================================
1182 // name : SMESHGUI_FilterTable::onRemoveBtn
1183 // Purpose : SLOT. Called then "Remove" button pressed.
1184 // Removes current string from table
1185 //=======================================================================
1186 void SMESHGUI_FilterTable::onRemoveBtn()
1188 Table* aTable = myTables[ GetType() ];
1190 if (aTable->rowCount() == 0)
1193 QList<QTableWidgetItem*> items = aTable->selectedItems();
1195 QList<int> aRows = aTable->selectedRows(); // already sorted
1199 removeAdditionalWidget(aTable, i);
1200 aTable->removeRow(i);
1203 // remove control of binary logical operation from last row
1204 if (aTable->rowCount() > 0)
1205 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1210 //=======================================================================
1211 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1212 // Purpose : Enable/Disable widget with additonal parameters
1213 //=======================================================================
1214 void SMESHGUI_FilterTable::updateAdditionalWidget()
1216 Table* aTable = myTables[ GetType() ];
1217 int aRow = aTable->currentRow();
1218 if (aRow < 0 || aRow >= aTable->rowCount())
1220 myWgStack->setEnabled(false);
1224 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1225 bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1226 GetCriterionType(aRow) != SMESH::FT_BelongToGeom &&
1227 GetCriterionType(aRow) != SMESH::FT_LyingOnGeom &&
1228 GetCriterionType(aRow) != SMESH::FT_RangeOfIds &&
1229 GetCriterionType(aRow) != SMESH::FT_FreeEdges &&
1230 GetCriterionType(aRow) != SMESH::FT_BadOrientedVolume;
1231 if (!myAddWidgets.contains(anItem))
1233 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1234 myWgStack->addWidget(myAddWidgets[ anItem ]);
1237 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1238 myWgStack->setEnabled(toEnable);
1241 //=======================================================================
1242 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1243 // Purpose : Remove widgets containing additional parameters from widget
1244 // stack and internal map
1245 //=======================================================================
1246 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1248 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1249 if (myAddWidgets.contains(anItem))
1251 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1252 myAddWidgets[ anItem ]->setParent(0);
1253 delete myAddWidgets[ anItem ];
1254 myAddWidgets.remove(anItem);
1258 //=======================================================================
1259 // name : SMESHGUI_FilterTable::onClearBtn
1260 // Purpose : SLOT. Called then "Clear" button pressed.
1261 // Removes all strings from table
1262 //=======================================================================
1263 void SMESHGUI_FilterTable::onClearBtn()
1265 Table* aTable = myTables[ GetType() ];
1267 if (aTable->rowCount() == 0)
1270 while (aTable->rowCount() > 0)
1272 removeAdditionalWidget(aTable, 0);
1273 aTable->removeRow(0);
1279 //=======================================================================
1280 // name : SMESHGUI_FilterTable::onCurrentChanged()
1281 // Purpose : SLOT. Called when current cell changed
1282 //=======================================================================
1283 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1286 updateAdditionalWidget();
1287 emit CurrentChanged(theRow, theCol);
1290 //=======================================================================
1291 // name : SMESHGUI_FilterTable::onCriterionChanged()
1292 // Purpose : Provides reaction on change of criterion
1293 //=======================================================================
1294 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1296 int aType = entityType == -1 ? GetType() : entityType;
1297 Table* aTable = myTables[ aType ];
1298 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1300 int aCriterionType = GetCriterionType(row);
1302 if (aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1303 aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
1304 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume)
1306 bool isSignalsBlocked = aTable->signalsBlocked();
1307 aTable->blockSignals( true );
1309 if (aCompareItem->count() > 0)
1310 aCompareItem->clear();
1311 aTable->setEditable(false, row, 2);
1313 aTable->blockSignals( isSignalsBlocked );
1315 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1316 aCriterionType == SMESH::FT_BelongToGeom ||
1317 aCriterionType == SMESH::FT_BelongToPlane ||
1318 aCriterionType == SMESH::FT_BelongToCylinder ||
1319 aCriterionType == SMESH::FT_BelongToGenSurface ||
1320 aCriterionType == SMESH::FT_LyingOnGeom)
1322 QMap<int, QString> aMap;
1323 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1324 aCompareItem->setItems(aMap);
1325 if (!aTable->isEditable(row, 2))
1326 aTable->setEditable(true, row, 2);
1330 if (aCompareItem->count() != 3)
1332 aCompareItem->setItems(getCompare());
1335 QString aText = aTable->text(row, 2);
1337 aText.toDouble(&isOk);
1338 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1339 if (!aTable->isEditable(row, 2))
1340 aTable->setEditable(true, row, 2);
1343 updateAdditionalWidget();
1345 emit CriterionChanged(row, entityType);
1348 //=======================================================================
1349 // name : SMESHGUI_FilterTable::onCriterionChanged()
1350 // Purpose : SLOT. Called then contents of table changed
1351 // Provides reaction on change of criterion
1352 //=======================================================================
1353 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1355 onCriterionChanged(row, col, -1);
1358 //=======================================================================
1359 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1360 // Purpose : Get first selected row
1361 //=======================================================================
1362 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1364 Table* aTable = myTables[ GetType() ];
1366 QList<int> selRows = aTable->selectedRows(); // already sorted
1367 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1369 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1372 //=======================================================================
1373 // name : SMESHGUI_FilterTable::addRow
1374 // Purpose : Add row at the end of table
1375 //=======================================================================
1376 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1379 int aSelectedRow = getFirstSelectedRow();
1380 int aCurrCol = theTable->currentColumn();
1383 if (toTheEnd || aSelectedRow == -1)
1385 theTable->insertRows(theTable->rowCount());
1386 aCurrRow = theTable->rowCount() - 1;
1390 theTable->insertRows(aSelectedRow);
1391 aCurrRow = aSelectedRow;
1395 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1396 bool isSignalsBlocked = theTable->signalsBlocked();
1397 theTable->blockSignals( true );
1400 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1403 theTable->setItem(aCurrRow, 1, getCompareItem());
1406 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1408 // Logical operation NOT
1409 theTable->setItem(aCurrRow, 3, getUnaryItem());
1411 // Logical operation AND / OR
1412 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1414 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1416 theTable->blockSignals( isSignalsBlocked );
1418 // Logical binary operation for previous value
1419 int anAddBinOpStr = -1;
1420 if (aCurrRow == theTable->rowCount() - 1)
1421 anAddBinOpStr = aCurrRow - 1;
1422 else if (aCurrRow >= 0 )
1423 anAddBinOpStr = aCurrRow;
1425 if (theTable->item(aCurrRow, 4) == 0 ||
1426 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1430 if (anAddBinOpStr >= 0 &&
1431 (theTable->item(anAddBinOpStr, 4) == 0 ||
1432 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1433 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1436 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1438 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1439 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1440 theTable->setCurrentCell(aCurrRow, aCurrCol);
1442 onCriterionChanged(aCurrRow, 0);
1447 //=======================================================================
1448 // name : SMESHGUI_FilterTable::getCriterionItem
1449 // Purpose : Get combo table item for criteria of specified type
1450 //=======================================================================
1451 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1453 return new ComboItem(getCriteria(theType));
1456 //=======================================================================
1457 // name : SMESHGUI_FilterTable::getCompareItem
1458 // Purpose : Get combo table item for operation of comparision
1459 //=======================================================================
1460 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1462 return new ComboItem(getCompare());
1465 //=======================================================================
1466 // name : SMESHGUI_FilterTable::getBinaryItem
1468 //=======================================================================
1469 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1471 static QMap<int, QString> aMap;
1474 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1475 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1478 return new ComboItem(aMap);
1481 //=======================================================================
1482 // name : SMESHGUI_FilterTable::getUnaryItem
1483 // Purpose : Get check table item
1484 //=======================================================================
1485 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1487 return new CheckItem(tr("NOT"));
1490 //=======================================================================
1491 // name : SMESHGUI_FilterTable::getSupportedTypes
1492 // Purpose : Get all supported type
1493 //=======================================================================
1494 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1496 static QMap<int, QString> aTypes;
1497 if (aTypes.isEmpty())
1499 aTypes[ SMESH::NODE ] = tr("NODES");
1500 aTypes[ SMESH::EDGE ] = tr("EDGES");
1501 aTypes[ SMESH::FACE ] = tr("FACES");
1502 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1508 //=======================================================================
1509 // name : SMESHGUI_FilterTable::getCriteria
1510 // Purpose : Get criteria for specified type
1511 //=======================================================================
1512 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1514 if (theType == SMESH::NODE)
1516 static QMap<int, QString> aCriteria;
1517 if (aCriteria.isEmpty())
1519 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1520 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1521 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1522 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1523 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1524 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1528 else if (theType == SMESH::EDGE)
1530 static QMap<int, QString> aCriteria;
1531 if (aCriteria.isEmpty())
1533 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1534 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
1535 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
1536 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1537 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1538 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1539 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1540 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1541 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1545 else if (theType == SMESH::FACE)
1547 static QMap<int, QString> aCriteria;
1548 if (aCriteria.isEmpty())
1550 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
1551 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
1552 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
1553 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
1554 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
1555 aCriteria[ SMESH::FT_Area ] = tr("AREA");
1556 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
1557 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1558 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1559 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1560 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1561 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1562 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1563 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
1564 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
1568 else if (theType == SMESH::VOLUME)
1570 static QMap<int, QString> aCriteria;
1571 if (aCriteria.isEmpty())
1573 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
1574 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1575 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1576 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1577 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
1578 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
1584 static QMap<int, QString> aCriteria;
1590 //=======================================================================
1591 // name : SMESHGUI_FilterTable::getCompare
1592 // Purpose : Get operation of comparison
1593 //=======================================================================
1594 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1596 static QMap<int, QString> aMap;
1600 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
1601 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
1602 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
1608 //=======================================================================
1609 // name : SMESHGUI_FilterTable::createTable
1610 // Purpose : Create table
1611 //=======================================================================
1612 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
1616 Table* aTable= new Table(0, 6, theParent);
1618 QHeaderView* aHeaders = aTable->horizontalHeader();
1620 QFontMetrics aMetrics(aHeaders->font());
1622 // append spaces to the header of criteria in order to
1623 // provide visibility of criterion inside comboboxes
1624 static int aMaxLenCr = 0;
1628 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1629 QMap<int, QString>::const_iterator anIter;
1630 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
1631 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
1634 static int aLenCr = qAbs( aMaxLenCr -
1635 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
1638 aCrStr.fill(' ', aLenCr);
1640 aCoStr.fill(' ', 10);
1642 QStringList aHeaderLabels;
1643 aHeaderLabels.append( tr("CRITERION") + aCrStr );
1644 aHeaderLabels.append( tr("COMPARE") + aCoStr );
1645 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
1646 aHeaderLabels.append( tr("UNARY") );
1647 aHeaderLabels.append( tr("BINARY") + " " );
1648 aHeaderLabels.append( tr("ID") );
1649 aTable->setHorizontalHeaderLabels( aHeaderLabels );
1651 // set geometry of the table
1652 for (int i = 0; i <= 4; i++)
1653 aTable->resizeColumnToContents(i);
1655 // set the ID column invisible
1656 aTable->hideColumn( 5 );
1658 aTable->updateGeometry();
1659 QSize aSize = aTable->sizeHint();
1660 int aWidth = aSize.width();
1661 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
1662 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
1664 connect(aTable, SIGNAL(cellChanged(int, int)),
1665 this, SLOT(onCriterionChanged(int, int)));
1667 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
1668 this, SLOT(onCurrentChanged(int, int)));
1673 //=======================================================================
1674 // name : SMESHGUI_FilterTable::updateBtnState
1675 // Purpose : Update button state
1676 //=======================================================================
1677 void SMESHGUI_FilterTable::updateBtnState()
1679 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1680 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1683 //=======================================================================
1684 // name : SMESHGUI_FilterTable::SetEditable
1685 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1686 //=======================================================================
1687 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
1689 TableMap::iterator anIter;
1690 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1692 anIter.value()->setReadOnly(!isEditable);
1697 myInsertBtn->show();
1698 myRemoveBtn->show();
1704 myInsertBtn->hide();
1705 myRemoveBtn->hide();
1710 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1711 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1712 anIter2.value()->SetEditable(isEditable);
1715 //=======================================================================
1716 // name : SMESHGUI_FilterTable::SetEnabled
1717 // Purpose : Enable/Disable table. Switching type of elements already enabled
1718 //=======================================================================
1719 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
1721 myAddBtn->setEnabled(isEnabled);
1722 myInsertBtn->setEnabled(isEnabled);
1723 myRemoveBtn->setEnabled(isEnabled);
1724 myClearBtn->setEnabled(isEnabled);
1729 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1730 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1731 anIter2.value()->setEnabled(isEnabled);
1734 //=======================================================================
1735 // name : SMESHGUI_FilterTable::IsEditable
1736 // Purpose : Verify whether table is editable
1737 //=======================================================================
1738 bool SMESHGUI_FilterTable::IsEditable() const
1740 return !myTables[ GetType() ]->isReadOnly();
1743 //=======================================================================
1744 // name : SMESHGUI_FilterTable::SetLibsEnabled
1745 // Purpose : Show/hide buttons for work with libraries
1746 //=======================================================================
1747 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
1751 myCopyFromBtn->show();
1756 myCopyFromBtn->hide();
1761 //=======================================================================
1762 // name : SMESHGUI_FilterTable::onCopyFromBtn
1763 // Purpose : SLOT. Called the "Copy from ..." button clicked
1764 // Display filter library dialog
1765 //=======================================================================
1766 void SMESHGUI_FilterTable::onCopyFromBtn()
1769 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1770 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1772 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1774 if (myLibDlg->exec() == QDialog::Accepted)
1776 Copy(myLibDlg->GetTable());
1781 //=======================================================================
1782 // name : SMESHGUI_FilterTable::onAddToBtn
1783 // Purpose : SLOT. Called the "Add to ..." button clicked
1784 // Display filter library dialog
1785 //=======================================================================
1786 void SMESHGUI_FilterTable::onAddToBtn()
1791 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1792 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1794 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1796 myLibDlg->SetTable(this);
1801 //=======================================================================
1802 // name : SMESHGUI_FilterTable::Copy
1803 // Purpose : Initialise table with values of other table
1804 //=======================================================================
1805 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
1809 for (int i = 0, n = theTable->NumRows(); i < n; i++)
1811 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1812 theTable->GetCriterion(i, aCriterion);
1813 AddCriterion(aCriterion);
1817 //=======================================================================
1818 // name : SMESHGUI_FilterTable::CurrentCell
1819 // Purpose : Returns current cell
1820 //=======================================================================
1821 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
1823 theRow = myTables[ GetType() ]->currentRow();
1824 theCol = myTables[ GetType() ]->currentColumn();
1825 return theRow >= 0 && theCol >= 0;
1828 //=======================================================================
1829 // name : SMESHGUI_FilterTable::SetText
1830 // Purpose : Set text and internal value in cell of threshold value
1831 //=======================================================================
1832 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
1833 const QString& theText,
1834 const int theEntityType)
1836 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1837 aTable->item( theRow, 2 )->setText(theText);
1840 //=======================================================================
1841 // name : SMESHGUI_FilterTable::SetText
1842 // Purpose : Get text and internal value from cell of threshold value
1843 //=======================================================================
1844 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
1846 const int theEntityType)
1848 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1849 QTableWidgetItem* anItem = aTable->item(theRow, 2);
1852 theText = anItem->text();
1859 //=======================================================================
1860 // name : SMESHGUI_FilterTable::SetID
1861 // Purpose : Set text and internal value in cell of ID value
1862 //=======================================================================
1863 void SMESHGUI_FilterTable::SetID( const int theRow,
1864 const QString& theText,
1865 const int theEntityType )
1867 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1868 aTable->item( theRow, 5 )->setText( theText );
1871 //=======================================================================
1872 // name : SMESHGUI_FilterTable::GetID
1873 // Purpose : Get text and internal value from cell of ID value
1874 //=======================================================================
1875 bool SMESHGUI_FilterTable::GetID( const int theRow,
1877 const int theEntityType )
1879 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1880 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
1883 theText = anItem->text();
1891 Class : SMESHGUI_FilterDlg
1892 Description : Dialog to specify filters for VTK viewer
1896 //=======================================================================
1897 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1898 // Purpose : Constructor
1899 //=======================================================================
1900 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1901 const QList<int>& theTypes )
1902 : QDialog( SMESH::GetDesktop( theModule ) ),
1903 mySMESHGUI( theModule ),
1904 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
1906 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1907 mySelector = aViewWindow->GetSelector();
1909 construct(theTypes);
1912 //=======================================================================
1913 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1914 // Purpose : Constructor
1915 //=======================================================================
1916 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1918 : QDialog( SMESH::GetDesktop( theModule ) ),
1919 mySMESHGUI( theModule ),
1920 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
1922 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1923 mySelector = aViewWindow->GetSelector();
1925 aTypes.append(theType);
1929 //=======================================================================
1930 // name : SMESHGUI_FilterDlg::construct
1931 // Purpose : Construct dialog (called by constructor)
1932 //=======================================================================
1933 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
1938 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
1939 setWindowTitle(tr("CAPTION"));
1941 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
1942 aDlgLay->setMargin(MARGIN);
1943 aDlgLay->setSpacing(SPACING);
1945 myMainFrame = createMainFrame (this);
1946 QWidget* aBtnFrame = createButtonFrame(this);
1948 aDlgLay->addWidget(myMainFrame);
1949 aDlgLay->addWidget(aBtnFrame);
1951 aDlgLay->setStretchFactor(myMainFrame, 1);
1953 myHelpFileName = "selection_filter_library_page.html";
1958 //=======================================================================
1959 // name : SMESHGUI_FilterDlg::createMainFrame
1960 // Purpose : Create frame containing dialog's input fields
1961 //=======================================================================
1962 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
1964 QWidget* aMainFrame = new QWidget(theParent);
1965 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
1966 aMainLay->setMargin(0);
1967 aMainLay->setSpacing(SPACING);
1971 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
1972 myTable->SetLibsEnabled(true);
1974 QGroupBox* aGrp = myTable->GetTableGrp();
1975 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
1976 int rows = aLay->rowCount();
1977 int cols = aLay->columnCount();
1979 QFrame* aLine = new QFrame(aGrp);
1980 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1981 aLay->addWidget(aLine, rows++, 0, 1, cols);
1983 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
1984 mySetInViewer->setChecked(true);
1985 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
1988 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
1990 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
1991 SLOT(onCriterionChanged(const int, const int)));
1993 connect(myTable, SIGNAL(CurrentChanged(int, int)),
1994 SLOT(onCurrentChanged(int, int)));
1996 aMainLay->addWidget(myTable);
1997 aMainLay->addWidget(aSourceGrp);
2002 //=======================================================================
2003 // name : SMESHGUI_FilterDlg::createSourceFrame
2004 // Purpose : Create frame containing source radio button
2005 //=======================================================================
2006 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2008 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2009 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2010 aLay->setMargin(MARGIN);
2011 aLay->setSpacing(SPACING);
2013 mySourceGrp = new QButtonGroup(theParent);
2015 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2016 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2017 QRadioButton* aGrpBtn = new QRadioButton(tr("CURRENT_GROUP"), aBox);
2019 aLay->addWidget(aMeshBtn);
2020 aLay->addWidget(aSelBtn);
2021 aLay->addWidget(aGrpBtn);
2023 mySourceGrp->addButton(aMeshBtn, Mesh);
2024 mySourceGrp->addButton(aSelBtn, Selection);
2025 mySourceGrp->addButton(aGrpBtn, Dialog);
2027 aSelBtn->setChecked(true);
2032 //=======================================================================
2033 // name : SMESHGUI_FilterDlg::updateMainButtons
2034 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2035 //=======================================================================
2036 void SMESHGUI_FilterDlg::updateMainButtons()
2038 if (myTypes.count() == 1)
2040 myButtons[ BTN_Cancel ]->show();
2041 myButtons[ BTN_Apply ]->hide();
2042 myButtons[ BTN_Close ]->hide();
2046 myButtons[ BTN_Cancel ]->hide();
2047 myButtons[ BTN_Apply ]->show();
2048 myButtons[ BTN_Close ]->show();
2051 // updateGeometry();
2054 //=======================================================================
2055 // name : SMESHGUI_FilterDlg::createButtonFrame
2056 // Purpose : Create frame containing buttons
2057 //=======================================================================
2058 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2060 QGroupBox* aGrp = new QGroupBox(theParent);
2061 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2062 aLay->setMargin(MARGIN);
2063 aLay->setSpacing(SPACING);
2065 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2066 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2067 myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
2068 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2069 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2071 aLay->addWidget(myButtons[ BTN_OK ]);
2072 aLay->addSpacing(10);
2073 aLay->addWidget(myButtons[ BTN_Apply ]);
2074 aLay->addSpacing(10);
2076 aLay->addWidget(myButtons[ BTN_Cancel ]);
2077 aLay->addWidget(myButtons[ BTN_Close ]);
2078 aLay->addWidget(myButtons[ BTN_Help ]);
2080 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2081 connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
2082 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
2083 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2084 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2086 updateMainButtons();
2091 //=======================================================================
2092 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2093 // Purpose : Destructor
2094 //=======================================================================
2095 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2099 //=======================================================================
2100 // name : SMESHGUI_FilterDlg::Init
2101 // Purpose : Init dialog fields, connect signals and slots, show dialog
2102 //=======================================================================
2103 void SMESHGUI_FilterDlg::Init (const int type)
2106 aTypes.append(type);
2110 //=======================================================================
2111 // name : SMESHGUI_FilterDlg::Init
2112 // Purpose : Init dialog fields, connect signals and slots, show dialog
2113 //=======================================================================
2114 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2118 myMesh = SMESH::SMESH_Mesh::_nil();
2120 myIsSelectionChanged = false;
2122 myTable->Init(theTypes);
2125 if (theTypes.count() == 1)
2127 int aType = theTypes.first();
2128 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2129 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2130 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2131 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2134 setWindowTitle(tr("TLT"));
2136 qApp->processEvents();
2141 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2143 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2144 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2146 updateMainButtons();
2149 // Initialise filter table with values of previous filter
2150 QList<int>::const_iterator anIter;
2151 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2153 myTable->Clear(*anIter);
2154 if (!myFilter[ *anIter ]->_is_nil())
2156 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2157 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2159 for (int i = 0, n = aCriteria->length(); i < n; i++)
2160 myTable->AddCriterion(aCriteria[ i ], *anIter);
2165 if (myInsertState.contains(theTypes.first()))
2166 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2168 mySetInViewer->setChecked(true);
2170 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2171 myApplyToState[ theTypes.first() ] :
2172 Selection)->setChecked(true);
2175 //=======================================================================
2176 // name : SMESHGUI_FilterDlg::onOk
2177 // Purpose : SLOT called when "Ok" button pressed.
2178 // Assign filters VTK viewer and close dialog
2179 //=======================================================================
2180 void SMESHGUI_FilterDlg::onOk()
2184 mySelectionMgr->clearFilters();
2185 disconnect(mySMESHGUI, 0, this, 0);
2186 disconnect(mySelectionMgr, 0, this, 0);
2187 mySMESHGUI->ResetState();
2193 //=======================================================================
2194 // name : SMESHGUI_FilterDlg::onClose
2195 // Purpose : SLOT called when "Close" button pressed. Close dialog
2196 //=======================================================================
2197 void SMESHGUI_FilterDlg::onClose()
2199 // Restore previously selected object
2202 SALOME_ListIO aList;
2203 mySelectionMgr->clearFilters();
2204 mySelectionMgr->clearSelected();
2205 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2206 for ( ; anIter.More(); anIter.Next())
2208 aList.Append(anIter.Key());
2210 TColStd_MapOfInteger aResMap;
2211 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2212 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2213 aResMap.Add(anIndMap(i));
2215 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2216 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2217 aViewWindow->highlight( anIter.Key(), true, true );
2219 mySelectionMgr->setSelectedObjects(aList, false);
2222 disconnect(mySMESHGUI, 0, this, 0);
2223 disconnect(mySelectionMgr, 0, this, 0);
2224 mySMESHGUI->ResetState();
2229 //=================================================================================
2230 // function : onHelp()
2232 //=================================================================================
2233 void SMESHGUI_FilterDlg::onHelp()
2235 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2237 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2241 platform = "winapplication";
2243 platform = "application";
2245 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2246 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2247 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2249 arg(myHelpFileName));
2253 //=======================================================================
2254 // name : SMESHGUI_FilterDlg::onDeactivate
2255 // Purpose : SLOT called when dialog must be deativated
2256 //=======================================================================
2257 void SMESHGUI_FilterDlg::onDeactivate()
2262 //=======================================================================
2263 // name : SMESHGUI_FilterDlg::enterEvent
2264 // Purpose : Event filter
2265 //=======================================================================
2266 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2268 // mySMESHGUI->EmitSignalDeactivateDialog();
2269 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2270 mySMESHGUI->ResetState();
2274 //=======================================================================
2275 // name : closeEvent()
2277 //=======================================================================
2278 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2283 //=======================================================================
2284 // name : SMESHGUI_FilterDlg::getIdsFromWg
2285 // Purpose : Retrieve list of ids from given widget
2286 //=======================================================================
2287 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2293 if (theWg->inherits("QListWidget"))
2295 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2297 for (int i = 0, n = aListBox->count(); i < n; i++)
2299 int anId = aListBox->item(i)->text().toInt(&b);
2301 theRes.append(anId);
2304 else if (theWg->inherits("QLineEdit"))
2306 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2307 QString aStr = aLineEdit->text();
2308 QRegExp aRegExp("(\\d+)");
2313 aPos = aRegExp.indexIn(aStr, aPos);
2316 int anId = aRegExp.cap(1).toInt(&b);
2318 theRes.append(anId);
2319 aPos += aRegExp.matchedLength();
2325 //=======================================================================
2326 // name : SMESHGUI_FilterDlg::getSelMode
2327 // Purpose : Get selection mode of specified type
2328 //=======================================================================
2329 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2333 case SMESH::NODE : return NodeSelection;
2334 case SMESH::EDGE : return EdgeSelection;
2335 case SMESH::FACE : return FaceSelection;
2336 case SMESH::VOLUME : return VolumeSelection;
2337 default : return ActorSelection;
2342 //=======================================================================
2343 // name : SMESHGUI_FilterDlg::setIdsToWg
2344 // Purpose : Insert identifiers in specified widgets
2345 //=======================================================================
2346 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2351 if (theWg->inherits("QListWidget"))
2353 QListWidget* aListBox = qobject_cast<QListWidget*>( theWg );
2356 QStringList aStrList;
2357 QList<int>::const_iterator anIter;
2358 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter)
2359 aStrList.append(QString("%1").arg(*anIter));
2361 aListBox->addItems(aStrList);
2363 else if (theWg->inherits("QLineEdit"))
2365 QLineEdit* aLineEdit = qobject_cast<QLineEdit*>( theWg );
2367 QList<int>::const_iterator anIter;
2369 for (anIter = theIds.begin(); anIter != theIds.end(); ++ anIter)
2370 aStr += QString("%1 ").arg(*anIter);
2372 if (!aStr.isEmpty())
2373 aStr.remove(aStr.length() - 1, 1);
2375 aLineEdit->setText(aStr);
2379 //=======================================================================
2380 // name : SMESHGUI_FilterDlg::isValid
2381 // Purpose : Verify validity of input data
2382 //=======================================================================
2383 bool SMESHGUI_FilterDlg::isValid() const
2385 if (!myTable->IsValid())
2388 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2390 int aType = myTable->GetCriterionType(i);
2391 if (aType == SMESH::FT_BelongToGeom ||
2392 aType == SMESH::FT_BelongToPlane ||
2393 aType == SMESH::FT_BelongToCylinder ||
2394 aType == SMESH::FT_BelongToGenSurface ||
2395 aType == SMESH::FT_LyingOnGeom) {
2397 myTable->GetThreshold(i, aName);
2399 std::vector<_PTR(SObject)> aList =
2400 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2401 if (aList.size() == 0) {
2402 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2403 tr("BAD_SHAPE_NAME").arg(aName));
2407 if (aType == SMESH::FT_BelongToCylinder ||
2408 aType == SMESH::FT_BelongToPlane ||
2409 aType == SMESH::FT_BelongToGenSurface ) {
2410 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2411 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2412 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2413 if (!aGeomObj->_is_nil()) {
2415 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2417 aFace.ShapeType() != TopAbs_FACE) {
2418 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2419 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2423 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2424 if (aSurf.IsNull()) {
2425 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2426 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2430 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2431 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2432 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2436 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2437 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2438 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2449 //=======================================================================
2450 // name : SMESHGUI_FilterDlg::SetSourceWg
2451 // Purpose : Set widget of parent dialog containing idsto be filtered if
2452 // user select corresponding source radio button
2453 //=======================================================================
2454 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg)
2459 //=======================================================================
2460 // name : SMESHGUI_FilterDlg::SetGroupIds
2461 // Purpose : Set mesh
2462 //=======================================================================
2463 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2466 if ( myMesh->_is_nil() ) {
2467 myButtons[BTN_OK]->setEnabled(false);
2468 myButtons[BTN_Apply]->setEnabled(false);
2472 //=======================================================================
2473 // name : SMESHGUI_FilterDlg::SetSelection
2474 // Purpose : Get filtered ids
2475 //=======================================================================
2476 void SMESHGUI_FilterDlg::SetSelection()
2479 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
2481 if (mySelectionMgr) {
2483 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
2484 SALOME_ListIteratorOfListIO anIter (anObjs);
2485 for ( ; anIter.More(); anIter.Next()) {
2486 TColStd_IndexedMapOfInteger aMap;
2487 mySelector->GetIndex(anIter.Value(), aMap);
2488 myIObjects.Bind(anIter.Value(), aMap);
2491 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2499 //=======================================================================
2500 // name : SMESHGUI_FilterDlg::onApply
2501 // Purpose : SLOT called when "Apply" button pressed.
2502 // Assign filters to VTK viewer
2503 //=======================================================================
2504 bool SMESHGUI_FilterDlg::onApply()
2510 int aCurrType = myTable->GetType();
2512 if (!createFilter(aCurrType))
2515 insertFilterInViewer();
2517 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
2518 QList<int> aResultIds;
2519 filterSource(aCurrType, aResultIds);
2520 selectInViewer(aCurrType, aResultIds);
2523 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2524 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
2526 catch(const SALOME::SALOME_Exception& S_ex)
2528 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2537 //=======================================================================
2538 // name : SMESHGUI_FilterDlg::createFilter
2539 // Purpose : Create predicate for given type
2540 //=======================================================================
2541 bool SMESHGUI_FilterDlg::createFilter (const int theType)
2543 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2544 if (aFilterMgr->_is_nil())
2547 int n = myTable->NumRows();
2549 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2550 aCriteria->length(n);
2552 long aPrecision = -1;
2553 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2555 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
2556 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
2558 for (CORBA::ULong i = 0; i < n; i++) {
2559 SMESH::Filter::Criterion aCriterion = createCriterion();
2560 myTable->GetCriterion(i, aCriterion);
2561 aCriterion.Precision = aPrecision;
2562 aCriteria[ i ] = aCriterion;
2565 myFilter[ theType ] = aFilterMgr->CreateFilter();
2566 myFilter[ theType ]->SetCriteria(aCriteria.inout());
2571 //=======================================================================
2572 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2573 // Purpose : Insert filter in viewer
2574 //=======================================================================
2575 void SMESHGUI_FilterDlg::insertFilterInViewer()
2577 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
2578 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2580 if (myFilter[ myTable->GetType() ]->_is_nil() ||
2581 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2582 !mySetInViewer->isChecked()) {
2583 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
2586 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2587 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
2588 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
2589 SMESH::SetFilter(aFilter, aSelector);
2594 //=======================================================================
2595 // name : SMESHGUI_FilterDlg::filterSource
2596 // Purpose : Filter source ids
2597 //=======================================================================
2598 void SMESHGUI_FilterDlg::filterSource (const int theType,
2599 QList<int>& theResIds)
2602 if (myFilter[ theType ]->_is_nil())
2605 int aSourceId = mySourceGrp->checkedId();
2607 if (aSourceId == Mesh)
2609 if (myMesh->_is_nil())
2611 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
2612 for (int i = 0, n = anIds->length(); i < n; i++)
2613 theResIds.append(anIds[ i ]);
2615 else if (aSourceId == Selection)
2617 filterSelectionSource(theType, theResIds);
2619 else if (aSourceId == Dialog)
2621 // retrieve ids from dialog
2622 QList<int> aDialogIds;
2623 getIdsFromWg(mySourceWg, aDialogIds);
2625 if (myMesh->_is_nil())
2627 theResIds = aDialogIds;
2632 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2633 aPred->SetMesh(myMesh);
2634 QList<int>::const_iterator anIter;
2635 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
2636 if (aPred->IsSatisfy(*anIter))
2637 theResIds.append(*anIter);
2639 // set ids to the dialog
2640 setIdsToWg(mySourceWg, theResIds);
2644 //=======================================================================
2645 // name : SMESHGUI_FilterDlg::filterSelectionSource
2646 // Purpose : Filter source selection
2647 //=======================================================================
2648 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
2649 QList<int>& theResIds)
2652 if (myMesh->_is_nil() || mySelectionMgr == 0)
2655 // Create map of entities to be filtered
2656 TColStd_MapOfInteger aToBeFiltered;
2657 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
2659 for ( ; anIter.More(); anIter.Next())
2662 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
2663 if (!aSubMesh->_is_nil())
2665 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
2667 SMESH::long_array_var anIds =
2668 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2669 for (int i = 0, n = anIds->length(); i < n; i++)
2670 aToBeFiltered.Add(anIds[ i ]);
2675 SMESH::SMESH_GroupBase_var aGroup =
2676 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
2677 if (!aGroup->_is_nil())
2679 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
2681 SMESH::long_array_var anIds = aGroup->GetListOfID();
2682 for (int i = 0, n = anIds->length(); i < n; i++)
2683 aToBeFiltered.Add(anIds[ i ]);
2688 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
2689 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
2691 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2693 if (aSelMap.Extent() > 0)
2695 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
2697 for (int i = 1; i <= aSelMap.Extent(); i++)
2698 aToBeFiltered.Add(aSelMap(i));
2705 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2706 aPred->SetMesh(myMesh);
2707 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
2708 for ( ; aResIter.More(); aResIter.Next())
2709 if (aPred->IsSatisfy(aResIter.Key()))
2710 theResIds.append(aResIter.Key());
2713 //=======================================================================
2714 // name : SMESHGUI_FilterDlg::selectInViewer
2715 // Purpose : Select given entities in viewer
2716 //=======================================================================
2717 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
2719 if (mySelectionMgr == 0 || myMesh->_is_nil())
2722 mySelectionMgr->clearFilters();
2724 // Set new selection mode if necessary
2725 Selection_Mode aSelMode = getSelMode(theType);
2726 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2727 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
2728 mySelectionMgr->clearSelected();
2729 mySelectionMgr->clearFilters();
2730 if (aSelMode == NodeSelection)
2731 SMESH::SetPointRepresentation(true);
2732 aViewWindow->SetSelectionMode(aSelMode);
2736 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2737 if (!anActor || !anActor->hasIO())
2740 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2741 //mySelectionMgr->clearSelected();
2742 //mySelectionMgr->AddIObject(anIO, false);
2743 SALOME_ListIO aList;
2745 mySelectionMgr->setSelectedObjects(aList, false);
2747 // Remove filter corresponding to the current type from viewer
2748 int aType = myTable->GetType();
2749 int aFilterId = SMESH::UnknownFilter;
2750 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
2751 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
2752 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
2753 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
2754 SMESH::RemoveFilter(aFilterId);
2757 TColStd_MapOfInteger aMap;
2758 QList<int>::const_iterator anIter;
2759 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
2763 // Set new selection
2764 mySelector->AddOrRemoveIndex(anIO, aMap, false);
2765 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2766 aViewWindow->highlight( anIO, true, true );
2768 // insert previously stored filter in viewer if necessary
2769 if (!aFilter.IsNull())
2770 SMESH::SetFilter(aFilter);
2773 //=======================================================================
2774 // name : SMESHGUI_FilterDlg::createCriterion
2775 // Purpose : Create criterion structure with default values
2776 //=======================================================================
2777 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2779 SMESH::Filter::Criterion aCriterion;
2781 aCriterion.Type = SMESH::FT_Undefined;
2782 aCriterion.Compare = SMESH::FT_Undefined;
2783 aCriterion.Threshold = 0;
2784 aCriterion.UnaryOp = SMESH::FT_Undefined;
2785 aCriterion.BinaryOp = SMESH::FT_Undefined;
2786 aCriterion.ThresholdStr = "";
2787 aCriterion.ThresholdID = "";
2788 aCriterion.TypeOfElement = SMESH::ALL;
2793 //=======================================================================
2794 // name : SMESHGUI_FilterDlg::onSelectionDone
2795 // Purpose : SLOT called when selection changed.
2796 // If current cell corresponds to the threshold value of
2797 // BelongToGeom criterion name of selected object is set in this cell
2798 //=======================================================================
2799 void SMESHGUI_FilterDlg::onSelectionDone()
2802 const SALOME_ListIO& aList = mySelector->StoredIObjects();
2804 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
2805 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
2806 if ( !(myMesh->_is_nil()) ) {
2807 myButtons[BTN_OK]->setEnabled(true);
2808 myButtons[BTN_Apply]->setEnabled(true);
2812 if (aList.Extent() != 1 ||
2813 !myTable->CurrentCell(aRow, aCol) ||
2814 myTable->GetCriterionType(aRow) != SMESH::FT_BelongToGeom &&
2815 myTable->GetCriterionType(aRow) != SMESH::FT_BelongToPlane &&
2816 myTable->GetCriterionType(aRow) != SMESH::FT_BelongToCylinder &&
2817 myTable->GetCriterionType(aRow) != SMESH::FT_BelongToGenSurface &&
2818 myTable->GetCriterionType(aRow) != SMESH::FT_LyingOnGeom)
2821 Handle(SALOME_InteractiveObject) anIO = aList.First();
2822 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
2823 if (!anObj->_is_nil())
2825 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
2826 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
2827 myTable->SetID(aRow, anIO->getEntry());
2832 //=======================================================================
2833 // name : SMESHGUI_FilterDlg::onCriterionChanged
2834 // Purpose : SLOT called when cretarion of current row changed. Update selection
2835 //=======================================================================
2836 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
2841 //=======================================================================
2842 // name : SMESHGUI_FilterDlg::onCurrentChanged
2843 // Purpose : SLOT called when current row changed. Update selection
2844 //=======================================================================
2845 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
2850 //=======================================================================
2851 // name : SMESHGUI_FilterDlg::updateSelection
2852 // Purpose : UpdateSelection in accordance with current row
2853 //=======================================================================
2854 void SMESHGUI_FilterDlg::updateSelection()
2856 if (mySelectionMgr == 0)
2859 TColStd_MapOfInteger allTypes;
2860 for( int i=0; i<10; i++ )
2862 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
2867 mySelectionMgr->clearFilters();
2871 if (myTable->CurrentCell(aRow, aCol) &&
2872 (myTable->GetCriterionType(aRow) == SMESH::FT_BelongToGeom ||
2873 myTable->GetCriterionType(aRow) == SMESH::FT_BelongToPlane ||
2874 myTable->GetCriterionType(aRow) == SMESH::FT_BelongToCylinder ||
2875 myTable->GetCriterionType(aRow) == SMESH::FT_BelongToGenSurface ||
2876 myTable->GetCriterionType(aRow) == SMESH::FT_LyingOnGeom)) {
2878 if (myTable->GetCriterionType(aRow) == SMESH::FT_BelongToGeom ||
2879 myTable->GetCriterionType(aRow) == SMESH::FT_BelongToGenSurface ||
2880 myTable->GetCriterionType(aRow) == SMESH::FT_LyingOnGeom) {
2882 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
2884 } else if (myTable->GetCriterionType(aRow) == SMESH::FT_BelongToPlane) {
2885 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
2887 } else if (myTable->GetCriterionType(aRow) == SMESH::FT_BelongToCylinder) {
2888 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
2890 myIsSelectionChanged = true;
2893 if (myIsSelectionChanged) {
2894 mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
2899 //=================================================================================
2900 // function : keyPressEvent()
2902 //=================================================================================
2903 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
2905 QDialog::keyPressEvent( e );
2906 if ( e->isAccepted() )
2909 if ( e->key() == Qt::Key_F1 ) {