1 // Copyright (C) 2007-2010 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.
28 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Filter.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_FilterLibraryDlg.h"
37 #include <SMESH_Actor.h>
38 #include <SMESH_NumberFilter.hxx>
39 #include <SMESH_TypeFilter.hxx>
40 #include <SMESHGUI_SpinBox.h>
42 // SALOME GEOM includes
44 #include <GEOM_FaceFilter.h>
45 #include <GEOM_TypeFilter.h>
47 // SALOME GUI includes
48 #include <SUIT_Desktop.h>
49 #include <SUIT_ResourceMgr.h>
50 #include <SUIT_Session.h>
51 #include <SUIT_MessageBox.h>
52 #include <QtxColorButton.h>
54 #include <LightApp_Application.h>
55 #include <LightApp_SelectionMgr.h>
56 #include <SalomeApp_Tools.h>
57 #include <SalomeApp_Study.h>
59 #include <SALOME_ListIO.hxx>
60 #include <SALOME_ListIteratorOfListIO.hxx>
61 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
63 #include <SVTK_ViewWindow.h>
65 // SALOME KERNEL includes
66 #include <SALOMEDSClient_Study.hxx>
69 #include <StdSelect_TypeOfFace.hxx>
70 #include <BRep_Tool.hxx>
72 #include <TopoDS_Shape.hxx>
73 #include <Geom_Plane.hxx>
74 #include <Geom_CylindricalSurface.hxx>
75 #include <Precision.hxx>
76 #include <TColStd_MapOfInteger.hxx>
77 #include <TColStd_IndexedMapOfInteger.hxx>
78 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
83 #include <QPushButton>
85 #include <QTableWidget>
86 #include <QStringList>
87 #include <QHBoxLayout>
88 #include <QVBoxLayout>
89 #include <QGridLayout>
90 #include <QStackedWidget>
91 #include <QApplication>
93 #include <QFontMetrics>
95 #include <QButtonGroup>
96 #include <QRadioButton>
98 #include <QListWidget>
100 #include <QItemDelegate>
101 #include <QDoubleValidator>
103 #include <QHeaderView>
106 #include <SALOMEconfig.h>
107 #include CORBA_SERVER_HEADER(SMESH_Group)
112 //---------------------------------------
114 //---------------------------------------
115 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
118 QMap<int, QString>::const_iterator anIter;
119 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
120 aRes = qMax(aRes, theMetrics.width(anIter.value()));
124 //---------------------------------------
126 //---------------------------------------
127 static int getFilterId (SMESH::ElementType theType)
131 case SMESH::NODE : return SMESH::NodeFilter;
132 case SMESH::EDGE : return SMESH::EdgeFilter;
133 case SMESH::FACE : return SMESH::FaceFilter;
134 case SMESH::VOLUME : return SMESH::VolumeFilter;
135 case SMESH::ALL : return SMESH::AllElementsFilter;
136 default : return SMESH::UnknownFilter;
141 Class : SMESHGUI_FilterTable::AdditionalWidget
142 Description : Class for storing additional parameters of criterion
145 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
151 AdditionalWidget(QWidget* theParent);
152 virtual ~AdditionalWidget();
154 virtual QList<int> GetParameters() const;
155 virtual bool IsValid(const bool = true) const;
156 virtual double GetDouble(const int) const;
157 virtual int GetInteger(const int) const;
158 virtual QString GetString(const int) const;
159 virtual void SetDouble(const int, const double);
160 virtual void SetInteger(const int, const int);
161 virtual void SetString(const int, const QString&);
162 void SetEditable(const int, const bool);
163 void SetEditable(const bool);
164 void SetPrecision(const int, const char* = 0);
167 QMap< int, QWidget* > myWidgets;
170 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
173 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
175 SMESHGUI_SpinBox* sb = new SMESHGUI_SpinBox(this);
176 sb->setAcceptNames( false ); // No Notebook variables allowed
177 sb->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
178 sb->RangeStepAndValidator( 0., 1.e20, 0.1, "len_tol_precision" );
179 myWidgets[ Tolerance ] = sb;
181 QHBoxLayout* aLay = new QHBoxLayout(this);
182 aLay->setSpacing(SPACING);
185 aLay->addWidget(aLabel);
186 aLay->addWidget(myWidgets[ Tolerance ]);
189 SetDouble( Tolerance, Precision::Confusion() );
192 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
196 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
199 theList.append(Tolerance);
203 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
208 QList<int> aParams = GetParameters();
209 QList<int>::const_iterator anIter;
210 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
211 if ( !myWidgets.contains( *anIter ) ) continue;
213 if ( qobject_cast<QLineEdit*>( myWidgets[ *anIter ] ) ) {
214 valid = qobject_cast<QLineEdit*>( myWidgets[ *anIter ] )->hasAcceptableInput();
216 else if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] ) ) {
218 valid = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ *anIter ] )->isValid( foo, false );
220 if (!valid && theMsg) {
221 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
222 tr("SMESHGUI_INVALID_PARAMETERS"));
230 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
233 if ( myWidgets.contains( theId ) ) {
234 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
235 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toDouble();
236 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
237 retval = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue();
242 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
245 if ( myWidgets.contains( theId ) ) {
246 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
247 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text().toInt();
248 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
249 retval = (int)( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
254 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
257 if ( myWidgets.contains( theId ) ) {
258 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
259 retval = qobject_cast<QLineEdit*>( myWidgets[ theId ] )->text();
260 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
261 retval = QString::number( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->GetValue() );
266 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
268 if ( myWidgets.contains( theId ) ) {
269 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
270 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
271 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
272 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal );
276 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
278 if ( myWidgets.contains( theId ) ) {
279 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
280 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( QString::number( theVal ) );
281 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
282 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( (double)theVal );
286 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
288 if ( myWidgets.contains( theId ) ) {
289 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
290 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setText( theVal );
291 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
292 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->SetValue( theVal.toDouble() );
296 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
298 if ( myWidgets.contains( theId ) ) {
299 if ( qobject_cast<QLineEdit*>( myWidgets[ theId ] ) )
300 qobject_cast<QLineEdit*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
301 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) )
302 qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] )->setReadOnly( !isEditable );
306 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
308 QList<int> aParams = GetParameters();
309 QList<int>::const_iterator anIter;
310 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
311 SetEditable( *anIter, isEditable );
314 void SMESHGUI_FilterTable::AdditionalWidget::SetPrecision(const int theId, const char* precision)
316 if ( myWidgets.contains( theId ) ) {
317 if ( qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] ) ) {
318 SMESHGUI_SpinBox* sb = qobject_cast<SMESHGUI_SpinBox*>( myWidgets[ theId ] );
319 double val = sb->GetValue();
320 double min = pow(10, -(sb->decimals()));
321 sb->RangeStepAndValidator( 0., 1.e20, 0.1, precision ? precision : "len_tol_precision" );
322 sb->SetValue( qMax( val, min ) );
328 Class : SMESHGUI_FilterTable::ComboItem
329 Description : Combo table item. Identificator corresponding to string may be assigned
332 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
337 ComboItem( const QMap<int, QString>& );
339 void setItems( const QMap<int, QString>& );
344 void setValue( const int );
348 int index( int ) const;
351 QMap<int, int> myIdToIdx;
354 int SMESHGUI_FilterTable::ComboItem::Type()
356 return QTableWidgetItem::UserType + 1;
359 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
360 : QTableWidgetItem( Type() )
365 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
368 QMap<int, QString>::const_iterator it;
370 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
371 myIdToIdx[it.key()] = items.count();
372 items.append( it.value() );
374 setData( Qt::UserRole, items );
378 void SMESHGUI_FilterTable::ComboItem::clear()
380 QMap<int, QString> empty;
384 int SMESHGUI_FilterTable::ComboItem::count() const
386 return myIdToIdx.count();
389 int SMESHGUI_FilterTable::ComboItem::value() const
391 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
394 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
396 int idx = index( theId );
397 QStringList items = data( Qt::UserRole ).toStringList();
398 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
401 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
403 QMap<int,int>::const_iterator it;
404 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
405 if ( it.value() == idx ) return it.key();
409 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
411 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
414 Class : SMESHGUI_FilterTable::CheckItem
415 Description : Check table item.
418 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
423 CheckItem( bool = false );
424 CheckItem( const QString&, bool = false );
427 void setChecked( bool );
428 bool checked() const;
431 int SMESHGUI_FilterTable::CheckItem::Type()
433 return QTableWidgetItem::UserType + 2;
436 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
437 : QTableWidgetItem( Type() )
439 Qt::ItemFlags f = flags();
440 f = f | Qt::ItemIsUserCheckable;
441 f = f & ~Qt::ItemIsTristate;
442 f = f & ~Qt::ItemIsEditable;
447 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
448 : QTableWidgetItem( Type() )
450 Qt::ItemFlags f = flags();
451 f = f | Qt::ItemIsUserCheckable;
452 f = f & ~Qt::ItemIsTristate;
453 f = f & ~Qt::ItemIsEditable;
459 SMESHGUI_FilterTable::CheckItem::~CheckItem()
463 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
465 setCheckState( value ? Qt::Checked : Qt::Unchecked );
468 bool SMESHGUI_FilterTable::CheckItem::checked() const
470 return checkState() == Qt::Checked;
474 Class : SMESHGUI_FilterTable::ComboDelegate
475 Description : Table used by this widget
478 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
481 ComboDelegate( QObject* = 0 );
484 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
485 const QModelIndex& ) const;
487 void setEditorData( QWidget*, const QModelIndex& ) const;
488 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
490 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
491 const QModelIndex& ) const;
493 QTableWidget* myTable;
496 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
497 : QItemDelegate( parent ),
498 myTable( qobject_cast<QTableWidget*>( parent ) )
502 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
506 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
507 const QStyleOptionViewItem& option,
508 const QModelIndex& index ) const
510 QStringList l = index.data( Qt::UserRole ).toStringList();
511 if ( !l.isEmpty() ) {
512 QComboBox* cb = new QComboBox( parent );
513 cb->setFrame( false );
517 return QItemDelegate::createEditor( parent, option, index );
520 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
521 const QModelIndex& index ) const
523 QString value = index.model()->data( index, Qt::DisplayRole ).toString();
524 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
527 int i = cb->findText( value );
529 cb->setCurrentIndex( i );
533 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
536 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
537 QAbstractItemModel* model,
538 const QModelIndex& index) const
540 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
541 if ( cb ) model->setData( index, cb->currentText(), Qt::DisplayRole );
542 else QItemDelegate::setModelData( editor, model, index );
545 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
546 const QStyleOptionViewItem& option,
547 const QModelIndex& index ) const
549 editor->setGeometry( option.rect );
553 Class : SMESHGUI_FilterTable::Table
554 Description : Table used by this widget
557 class SMESHGUI_FilterTable::Table : public QTableWidget
560 Table( QWidget* = 0 );
561 Table( int, int, QWidget* = 0 );
564 QSize minimumSizeHint() const;
566 void setEditable( bool, int, int );
567 bool isEditable( int, int ) const;
569 void setReadOnly( bool );
570 bool isReadOnly() const;
572 void insertRows( int, int = 1 );
573 QString text( int, int );
575 QList<int> selectedRows();
578 //=======================================================================
579 // name : SMESHGUI_FilterTable::Table::Table
580 // Purpose : Constructor
581 //=======================================================================
582 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
583 : QTableWidget(parent)
585 // set custom item delegate
586 setItemDelegate( new ComboDelegate(this) );
587 // set edit triggers by default
588 setReadOnly( false );
591 //=======================================================================
592 // name : SMESHGUI_FilterTable::Table::Table
593 // Purpose : Constructor
594 //=======================================================================
595 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
596 : QTableWidget(numRows, numCols, parent)
598 // set custom item delegate
599 setItemDelegate( new ComboDelegate(this) );
600 // set edit triggers by default
601 setReadOnly( false );
604 //=======================================================================
605 // name : SMESHGUI_FilterTable::Table::~Table
606 // Purpose : Destructor
607 //=======================================================================
608 SMESHGUI_FilterTable::Table::~Table()
612 //=======================================================================
613 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
614 // Purpose : Get minimum size for the table
615 //=======================================================================
616 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
618 QSize s = QTableWidget::minimumSizeHint();
619 QHeaderView* hv = horizontalHeader();
621 s.setWidth( qMax( s.width(), hv->length() ) );
625 //=======================================================================
626 // name : SMESHGUI_FilterTable::Table::setEditable
627 // Purpose : Set editable of specified cell
628 //=======================================================================
629 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
632 QTableWidgetItem* anItem = item( row, col );
634 bool isSignalsBlocked = signalsBlocked();
635 blockSignals( true );
637 Qt::ItemFlags f = anItem->flags();
638 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
639 else f = f | Qt::ItemIsEditable;
640 anItem->setFlags( f );
642 blockSignals( isSignalsBlocked );
646 //=======================================================================
647 // name : SMESHGUI_FilterTable::Table::isEditable
648 // Purpose : Verify wheter cell is editable
649 //=======================================================================
650 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
652 QTableWidgetItem* anItem = item( row, col );
653 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
656 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
658 setEditTriggers( on ?
659 QAbstractItemView::NoEditTriggers :
660 QAbstractItemView::AllEditTriggers );
663 bool SMESHGUI_FilterTable::Table::isReadOnly() const
665 return editTriggers() == QAbstractItemView::NoEditTriggers;
668 //=======================================================================
669 // name : SMESHGUI_FilterTable::Table::insertRows
670 // Purpose : Insert rows (virtual redefined)
671 //=======================================================================
672 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
674 closePersistentEditor( currentItem() );
675 while ( count-- ) insertRow( row );
678 //=======================================================================
679 // name : SMESHGUI_FilterTable::Table::text
680 // Purpose : Get text from cell (virtual redefined)
681 //=======================================================================
682 QString SMESHGUI_FilterTable::Table::text (int row, int col)
684 closePersistentEditor( currentItem() );
685 QTableWidgetItem* anItem = item( row, col );
686 return anItem ? anItem->text() : QString();
689 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
691 QList<QTableWidgetItem*> selItems = selectedItems();
692 QTableWidgetItem* anItem;
695 foreach( anItem, selItems ) {
696 int r = row( anItem );
697 if ( !rows.contains( r ) ) rows.append( r );
705 Class : SMESHGUI_FilterTable
706 Description : Frame containig
707 - Button group for switching entity type
708 - Table for displaying filter criterions
709 - Buttons for editing table and filter libraries
712 //=======================================================================
713 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
714 // Purpose : Constructor
715 //=======================================================================
716 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
721 mySMESHGUI( theModule )
730 //=======================================================================
731 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
732 // Purpose : Constructor
733 //=======================================================================
734 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
736 const QList<int>& types )
739 mySMESHGUI( theModule )
745 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
749 //=======================================================================
750 // name : SMESHGUI_FilterTable::Init
751 // Purpose : Create table corresponding to the specified type
752 //=======================================================================
753 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
755 if (theTypes.isEmpty())
758 // Create buttons if necessary
760 if (myTables.isEmpty())
762 // create main layout
763 QVBoxLayout* aMainLay = new QVBoxLayout(this);
764 aMainLay->setMargin( 0 );
765 aMainLay->setSpacing( SPACING );
767 // create switch of entity types
768 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
769 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
770 myEntityTypeBoxLayout->setMargin( MARGIN );
771 myEntityTypeBoxLayout->setSpacing( SPACING );
772 myEntityTypeGrp = new QButtonGroup(this);
774 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
775 QMap<int, QString>::const_iterator anIter;
776 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
778 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
779 myEntityTypeGrp->addButton(aBtn, anIter.key());
780 myEntityTypeBoxLayout->addWidget(aBtn);
783 myTableGrp = new QGroupBox(tr("FILTER"), this );
786 mySwitchTableGrp = new QWidget(myTableGrp);
787 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
788 mySwitchTableGrpLayout->setMargin(0);
789 mySwitchTableGrpLayout->setSpacing(0);
791 QList<int>::const_iterator typeIt = theTypes.begin();
792 for ( ; typeIt != theTypes.end(); ++typeIt ) {
793 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
794 myTables[ *typeIt ] = aTable;
795 mySwitchTableGrpLayout->addWidget(aTable);
796 if ( typeIt != theTypes.begin() )
801 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
802 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
803 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
804 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
805 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
806 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
808 myAddBtn->setAutoDefault(false);
809 myRemoveBtn->setAutoDefault(false);
810 myClearBtn->setAutoDefault(false);
811 myInsertBtn->setAutoDefault(false);
812 myCopyFromBtn->setAutoDefault(false);
813 myAddToBtn->setAutoDefault(false);
815 myCopyFromBtn->hide();
819 QGridLayout* aLay = new QGridLayout(myTableGrp);
820 aLay->setMargin(MARGIN);
821 aLay->setSpacing(SPACING);
823 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
824 aLay->addWidget(myAddBtn, 0, 1);
825 aLay->addWidget(myInsertBtn, 1, 1);
826 aLay->addWidget(myRemoveBtn, 2, 1);
827 aLay->addWidget(myClearBtn, 3, 1);
828 aLay->addWidget(myCopyFromBtn, 5, 1);
829 aLay->addWidget(myAddToBtn, 6, 1);
830 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
832 aLay->setRowMinimumHeight(4, 10);
833 aLay->setRowStretch(4, 1);
834 aLay->setColumnStretch(0, 1);
835 aLay->setColumnStretch(1, 0);
838 aMainLay->addWidget(myEntityTypeBox);
839 aMainLay->addWidget(myTableGrp);
842 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
843 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
844 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
845 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
847 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
848 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
850 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
855 // Hide buttons of entity types if necessary
856 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
857 QMap<int, QString>::const_iterator anIt;
858 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
860 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
861 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
864 // select first button if there is no selected buttons or it is hidden
865 int aBtnId = myEntityTypeGrp->checkedId();
866 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
867 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
868 if ( aBtn ) aBtn->setChecked(true);
871 myEntityTypeBox->setVisible(theTypes.count() > 1);
873 myTableGrp->updateGeometry();
874 int cType = myEntityTypeGrp->checkedId();
878 //=======================================================================
879 // name : SMESHGUI_FilterTable::createAdditionalFrame
880 // Purpose : Get group box containing table. May be used for adding new widgets in it
881 //=======================================================================
882 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
884 QWidget* aFrame = new QWidget(theParent);
886 QFrame* aLine1 = new QFrame(aFrame);
887 QFrame* aLine2 = new QFrame(aFrame);
888 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
889 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
890 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
891 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
893 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
895 myWgStack = new QStackedWidget(aFrame);
897 QGridLayout* aLay = new QGridLayout(aFrame);
899 aLay->setSpacing(SPACING);
900 aLay->addWidget(aLine1, 0, 0);
901 aLay->addWidget(aLabel, 0, 1);
902 aLay->addWidget(aLine2, 0, 2);
903 aLay->addWidget(myWgStack, 1, 0, 1, 3);
908 //=======================================================================
909 // name : SMESHGUI_FilterTable::GetTableGrp
910 // Purpose : Get group box containing table. May be used for adding new widgets in it
911 //=======================================================================
912 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
917 //=======================================================================
918 // name : SMESHGUI_FilterTable::onEntityType
919 // Purpose : SLOT. Called when entity type changed.
920 // Display corresponding table
921 //=======================================================================
922 void SMESHGUI_FilterTable::onEntityType (int theType)
924 if (myEntityType == theType)
928 emit NeedValidation();
931 myEntityTypeGrp->button(myEntityType)->setChecked(true);
935 myEntityType = theType;
937 if (!myTables.contains(theType)) {
938 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
939 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
942 TableMap::iterator anIter;
943 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
944 anIter.value()->setVisible( myEntityType == anIter.key() );
947 qApp->processEvents();
948 myTables[ myEntityType ]->updateGeometry();
951 emit EntityTypeChanged(theType);
954 //=======================================================================
955 // name : SMESHGUI_FilterTable::IsValid
956 // Purpose : Verify validity of entered data
957 //=======================================================================
958 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
960 int aType = theEntityType == -1 ? GetType() : theEntityType;
962 Table* aTable = myTables[ aType ];
963 for (int i = 0, n = aTable->rowCount(); i < n; i++)
965 int aCriterion = GetCriterionType(i, aType);
967 if (aCriterion == SMESH::FT_GroupColor ) {
968 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
969 if (clrBtn && !clrBtn->color().isValid())
970 errMsg = tr( "GROUPCOLOR_ERROR" );
971 } else if (aCriterion == SMESH::FT_RangeOfIds ||
972 aCriterion == SMESH::FT_BelongToGeom ||
973 aCriterion == SMESH::FT_BelongToPlane ||
974 aCriterion == SMESH::FT_BelongToCylinder ||
975 aCriterion == SMESH::FT_BelongToGenSurface ||
976 aCriterion == SMESH::FT_ElemGeomType ||
977 aCriterion == SMESH::FT_LyingOnGeom) {
978 if (aTable->text(i, 2).isEmpty())
979 errMsg = tr( "ERROR" );
983 bool isSignalsBlocked = aTable->signalsBlocked();
984 aTable->blockSignals(true);
985 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
986 aTable->blockSignals(isSignalsBlocked);
988 if (!aRes && aTable->isEditable(i, 2))
989 errMsg = tr( "ERROR" );
990 else if (aType == SMESH::EDGE &&
991 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
993 errMsg = tr( "MULTIEDGES_ERROR" );
996 if (!errMsg.isEmpty()) {
998 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
1002 QTableWidgetItem* anItem = aTable->item(i, 0);
1003 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
1010 //=======================================================================
1011 // name : SMESHGUI_FilterTable::SetValidity
1012 // Purpose : Set validity of the table
1013 //=======================================================================
1014 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
1016 myIsValid = isValid;
1019 //=======================================================================
1020 // name : SMESHGUI_FilterTable::GetType
1021 // Purpose : Get current entity type
1022 //=======================================================================
1023 int SMESHGUI_FilterTable::GetType() const
1025 return myEntityType;
1028 //=======================================================================
1029 // name : SMESHGUI_FilterTable::SetType
1030 // Purpose : Set current entity type
1031 //=======================================================================
1032 void SMESHGUI_FilterTable::SetType (const int type)
1034 myEntityTypeGrp->button(type)->setChecked(true);
1038 //=======================================================================
1039 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
1040 // Purpose : Restore previous entity type
1041 //=======================================================================
1042 void SMESHGUI_FilterTable::RestorePreviousEntityType()
1044 SetType(myEntityType);
1047 //=======================================================================
1048 // name : SMESHGUI_FilterTable::GetCriterionType
1049 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
1050 //=======================================================================
1051 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
1053 int aType = theType == -1 ? GetType() : theType;
1054 Table* aTable = myTables[ aType ];
1055 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
1056 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1059 //=======================================================================
1060 // name : SMESHGUI_FilterTable::GetCriterion
1061 // Purpose : Get parameters of criterion from specified row
1062 //=======================================================================
1063 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1064 SMESH::Filter::Criterion& theCriterion,
1065 const int theEntityType) const
1067 int aType = theEntityType == -1 ? GetType() : theEntityType;
1068 Table* aTable = myTables[ aType ];
1070 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1071 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1072 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1073 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1074 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1076 int aCriterionType = GetCriterionType(theRow, aType);
1078 if ( aCriterionType == SMESH::FT_GroupColor )
1080 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1083 const QColor qClr = clrBtn->color();
1084 QString clrStr = QString( "%1;%2;%3" ).
1085 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1086 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1089 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1090 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1091 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1092 aCriterionType != SMESH::FT_BelongToGeom &&
1093 aCriterionType != SMESH::FT_BelongToPlane &&
1094 aCriterionType != SMESH::FT_BelongToCylinder &&
1095 aCriterionType != SMESH::FT_BelongToGenSurface &&
1096 aCriterionType != SMESH::FT_LyingOnGeom)
1098 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1099 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1103 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1104 if ( aCriterionType != SMESH::FT_RangeOfIds )
1105 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1108 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1109 if (myAddWidgets.contains(anItem))
1110 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1113 //=======================================================================
1114 // name : SMESHGUI_FilterTable::SetCriterion
1115 // Purpose : Set parameters of criterion of specified row
1116 //=======================================================================
1117 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1118 const SMESH::Filter::Criterion& theCriterion,
1119 const int theEntityType)
1121 int aType = theEntityType == -1 ? GetType() : theEntityType;
1123 Table* aTable = myTables[ aType ];
1125 if (theRow > aTable->rowCount() - 1)
1128 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1129 onCriterionChanged(theRow, 0, aType);
1130 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1131 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1133 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1135 if (!aTable->isEditable(theRow, 4))
1136 aTable->setItem(theRow, 4, getBinaryItem());
1137 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1140 aTable->setEditable(false, theRow, 4);
1142 if (theCriterion.Type == SMESH::FT_GroupColor )
1144 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1148 QString clrStr( theCriterion.ThresholdStr );
1149 QStringList clrVals = clrStr.split( ";" );
1150 if ( clrVals.count() > 2 )
1151 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1152 (int)256*clrVals[1].toDouble(),
1153 (int)256*clrVals[2].toDouble() );
1154 clrBtn->setColor( qClr );
1157 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1159 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1160 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1162 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1163 theCriterion.Type != SMESH::FT_BelongToGeom &&
1164 theCriterion.Type != SMESH::FT_BelongToPlane &&
1165 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1166 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1167 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1168 theCriterion.Type != SMESH::FT_FreeBorders &&
1169 theCriterion.Type != SMESH::FT_FreeEdges &&
1170 theCriterion.Type != SMESH::FT_FreeNodes &&
1171 theCriterion.Type != SMESH::FT_FreeFaces &&
1172 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1173 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1174 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1177 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1178 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1179 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1182 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1183 theCriterion.Type == SMESH::FT_BelongToPlane ||
1184 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1185 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1186 theCriterion.Type == SMESH::FT_BelongToGeom ||
1187 theCriterion.Type == SMESH::FT_LyingOnGeom)
1189 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1190 if (!myAddWidgets.contains(anItem))
1192 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1193 myWgStack->addWidget(myAddWidgets[ anItem ]);
1195 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1198 emit CriterionChanged(theRow, aType);
1202 //=======================================================================
1203 // name : SMESHGUI_FilterTable::Update
1204 // Purpose : Update table
1205 //=======================================================================
1206 void SMESHGUI_FilterTable::Update()
1208 Table* aTable = myTables[ GetType() ];
1209 int aCurrRow = aTable->currentRow();
1210 int numRows = aTable->rowCount();
1211 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1212 aTable->setCurrentCell(0, 0);
1213 updateAdditionalWidget();
1216 //=======================================================================
1217 // name : SMESHGUI_FilterTable::AddCriterion
1218 // Purpose : Add criterion with parameters
1219 //=======================================================================
1220 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1221 const int theEntityType)
1223 int aType = theEntityType == -1 ? GetType() : theEntityType;
1224 Table* aTable = myTables[ aType ];
1225 addRow(aTable, aType);
1226 SetCriterion(aTable->rowCount() - 1, theCriterion);
1229 //=======================================================================
1230 // name : SMESHGUI_FilterTable::NumRows
1231 // Purpose : Get number of criterions of current type
1232 //=======================================================================
1233 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1235 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1238 //=======================================================================
1239 // name : SMESHGUI_FilterTable::Clear
1240 // Purpose : Clear current table
1241 //=======================================================================
1242 void SMESHGUI_FilterTable::Clear (const int theType)
1244 int aType = theType == -1 ? GetType() : theType;
1245 Table* aTable = myTables[ aType ];
1247 if (aTable->rowCount() == 0)
1250 while (aTable->rowCount() > 0)
1252 removeAdditionalWidget(aTable, 0);
1253 aTable->removeRow(0);
1259 //=======================================================================
1260 // name : SMESHGUI_FilterTable::onAddBtn
1261 // Purpose : SLOT. Called then "Add" button pressed.
1262 // Adds new string to table
1263 //=======================================================================
1264 void SMESHGUI_FilterTable::onAddBtn()
1266 int aType = GetType();
1267 addRow(myTables[ aType ], aType);
1272 //=======================================================================
1273 // name : SMESHGUI_FilterTable::onInsertBtn
1274 // Purpose : SLOT. Called then "Insert" button pressed.
1275 // Inserts new string before current one
1276 //=======================================================================
1277 void SMESHGUI_FilterTable::onInsertBtn()
1279 addRow(myTables[ GetType() ], GetType(), false);
1282 //=======================================================================
1283 // name : SMESHGUI_FilterTable::onRemoveBtn
1284 // Purpose : SLOT. Called then "Remove" button pressed.
1285 // Removes current string from table
1286 //=======================================================================
1287 void SMESHGUI_FilterTable::onRemoveBtn()
1289 Table* aTable = myTables[ GetType() ];
1291 if (aTable->rowCount() == 0)
1294 QList<QTableWidgetItem*> items = aTable->selectedItems();
1296 QList<int> aRows = aTable->selectedRows(); // already sorted
1300 removeAdditionalWidget(aTable, i);
1301 aTable->removeRow(i);
1304 // remove control of binary logical operation from last row
1305 if (aTable->rowCount() > 0)
1306 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1311 //=======================================================================
1312 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1313 // Purpose : Enable/Disable widget with additonal parameters
1314 //=======================================================================
1315 void SMESHGUI_FilterTable::updateAdditionalWidget()
1317 Table* aTable = myTables[ GetType() ];
1318 int aRow = aTable->currentRow();
1319 if (aRow < 0 || aRow >= aTable->rowCount())
1321 myWgStack->setEnabled(false);
1325 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1326 int aCriterion = GetCriterionType(aRow);
1327 bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1328 aCriterion != SMESH::FT_RangeOfIds &&
1329 aCriterion != SMESH::FT_FreeEdges &&
1330 aCriterion != SMESH::FT_FreeFaces &&
1331 aCriterion != SMESH::FT_BadOrientedVolume;
1333 if (!myAddWidgets.contains(anItem))
1335 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1336 myWgStack->addWidget(myAddWidgets[ anItem ]);
1339 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1340 myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
1341 myWgStack->setEnabled(toEnable);
1344 const char* SMESHGUI_FilterTable::getPrecision( const int aType )
1346 const char* retval = 0;
1348 case SMESH::FT_AspectRatio:
1349 case SMESH::FT_AspectRatio3D:
1350 case SMESH::FT_Taper:
1351 retval = "parametric_precision"; break;
1352 case SMESH::FT_Warping:
1353 case SMESH::FT_MinimumAngle:
1354 case SMESH::FT_Skew:
1355 retval = "angle_precision"; break;
1356 case SMESH::FT_Area:
1357 retval = "area_precision"; break;
1358 case SMESH::FT_BelongToGeom:
1359 case SMESH::FT_BelongToPlane:
1360 case SMESH::FT_BelongToCylinder:
1361 case SMESH::FT_BelongToGenSurface:
1362 case SMESH::FT_LyingOnGeom:
1363 retval = "len_tol_precision"; break;
1364 case SMESH::FT_Length:
1365 case SMESH::FT_Length2D:
1366 case SMESH::FT_MaxElementLength2D:
1367 case SMESH::FT_MaxElementLength3D:
1368 retval = "length_precision"; break;
1369 case SMESH::FT_Volume3D:
1370 retval = "vol_precision"; break;
1377 //=======================================================================
1378 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1379 // Purpose : Remove widgets containing additional parameters from widget
1380 // stack and internal map
1381 //=======================================================================
1382 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1384 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1385 if (myAddWidgets.contains(anItem))
1387 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1388 myAddWidgets[ anItem ]->setParent(0);
1389 delete myAddWidgets[ anItem ];
1390 myAddWidgets.remove(anItem);
1394 //=======================================================================
1395 // name : SMESHGUI_FilterTable::onClearBtn
1396 // Purpose : SLOT. Called then "Clear" button pressed.
1397 // Removes all strings from table
1398 //=======================================================================
1399 void SMESHGUI_FilterTable::onClearBtn()
1401 Table* aTable = myTables[ GetType() ];
1403 if (aTable->rowCount() == 0)
1406 while (aTable->rowCount() > 0)
1408 removeAdditionalWidget(aTable, 0);
1409 aTable->removeRow(0);
1415 //=======================================================================
1416 // name : SMESHGUI_FilterTable::onCurrentChanged()
1417 // Purpose : SLOT. Called when current cell changed
1418 //=======================================================================
1419 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1422 updateAdditionalWidget();
1423 emit CurrentChanged(theRow, theCol);
1426 //=======================================================================
1428 // Purpose : returns available geometry types of elements
1429 //=======================================================================
1430 static QList<int> geomTypes( const int theType )
1433 if ( theType == SMESH::NODE )
1434 typeIds.append( SMESH::Geom_POINT );
1435 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1436 typeIds.append( SMESH::Geom_EDGE );
1437 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1439 typeIds.append( SMESH::Geom_TRIANGLE );
1440 typeIds.append( SMESH::Geom_QUADRANGLE );
1441 typeIds.append( SMESH::Geom_POLYGON );
1443 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1445 typeIds.append( SMESH::Geom_TETRA );
1446 typeIds.append( SMESH::Geom_PYRAMID );
1447 typeIds.append( SMESH::Geom_HEXA );
1448 typeIds.append( SMESH::Geom_PENTA );
1449 typeIds.append( SMESH::Geom_POLYHEDRA );
1454 //=======================================================================
1455 // name : SMESHGUI_FilterTable::onCriterionChanged()
1456 // Purpose : Provides reaction on change of criterion
1457 //=======================================================================
1458 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1460 int aType = entityType == -1 ? GetType() : entityType;
1461 Table* aTable = myTables[ aType ];
1462 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1464 int aCriterionType = GetCriterionType(row);
1465 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1466 int aComboType = ComboItem::Type();
1467 QTableWidgetItem* aTableItem = aTable->item(row, 2);
1468 bool isComboItem = false;
1470 int aTableType = aTable->item(row, 2)->type();
1471 isComboItem = aTableType == aComboType ? true : false;
1474 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1475 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) )
1477 bool isSignalsBlocked = aTable->signalsBlocked();
1478 aTable->blockSignals( true );
1479 aTable->removeCellWidget( row, 2 );
1480 aTable->setItem( row, 2, new QTableWidgetItem() );
1481 aTable->blockSignals( isSignalsBlocked );
1483 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1484 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) )
1486 bool isSignalsBlocked = aTable->signalsBlocked();
1487 aTable->blockSignals( true );
1488 if ( aCriterionType == SMESH::FT_GroupColor )
1489 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1491 QList<int> typeIds = geomTypes( aType );
1492 QMap<int, QString> typeNames;
1493 QList<int>::const_iterator anIter = typeIds.begin();
1494 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1496 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1497 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1499 ComboItem* typeBox = new ComboItem( typeNames );
1500 aTable->setItem( row, 2, typeBox );
1502 aTable->blockSignals( isSignalsBlocked );
1505 if (aType == SMESH::NODE && aCriterionType == SMESH::FT_FreeNodes ||
1506 aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1507 aType == SMESH::FACE && (aCriterionType == SMESH::FT_FreeEdges ||
1508 aCriterionType == SMESH::FT_FreeFaces) ||
1509 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume ||
1510 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1511 aCriterionType == SMESH::FT_GroupColor ||
1512 aCriterionType == SMESH::FT_ElemGeomType)
1514 bool isSignalsBlocked = aTable->signalsBlocked();
1515 aTable->blockSignals( true );
1517 if (aCompareItem->count() > 0)
1518 aCompareItem->clear();
1519 aTable->setEditable(false, row, 1);
1520 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1521 aCriterionType == SMESH::FT_ElemGeomType, row, 2);
1522 aTable->blockSignals( isSignalsBlocked );
1524 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1525 aCriterionType == SMESH::FT_BelongToGeom ||
1526 aCriterionType == SMESH::FT_BelongToPlane ||
1527 aCriterionType == SMESH::FT_BelongToCylinder ||
1528 aCriterionType == SMESH::FT_BelongToGenSurface ||
1529 aCriterionType == SMESH::FT_LyingOnGeom)
1531 QMap<int, QString> aMap;
1532 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1533 aCompareItem->setItems(aMap);
1534 if (!aTable->isEditable(row, 2))
1535 aTable->setEditable(true, row, 1);
1536 if (!aTable->isEditable(row, 2))
1537 aTable->setEditable(true, row, 2);
1539 else if (aCriterionType == SMESH::FT_GroupColor ||
1540 aCriterionType == SMESH::FT_ElemGeomType)
1542 if (!aTable->isEditable(row, 2))
1543 aTable->setEditable(true, row, 2);
1547 if (aCompareItem && aCompareItem->count() != 3)
1549 aCompareItem->setItems(getCompare());
1552 if (aTable->item( row, 2 )) {
1553 QString aText = aTable->text(row, 2);
1555 aText.toDouble(&isOk);
1556 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1557 if (!aTable->isEditable(row, 1))
1558 aTable->setEditable(true, row, 1);
1559 if (!aTable->isEditable(row, 2))
1560 aTable->setEditable(true, row, 2);
1564 updateAdditionalWidget();
1566 emit CriterionChanged(row, entityType);
1569 //=======================================================================
1570 // name : SMESHGUI_FilterTable::onCriterionChanged()
1571 // Purpose : SLOT. Called then contents of table changed
1572 // Provides reaction on change of criterion
1573 //=======================================================================
1574 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1576 onCriterionChanged(row, col, -1);
1579 //=======================================================================
1580 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1581 // Purpose : Get first selected row
1582 //=======================================================================
1583 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1585 Table* aTable = myTables[ GetType() ];
1587 QList<int> selRows = aTable->selectedRows(); // already sorted
1588 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1590 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1593 //=======================================================================
1594 // name : SMESHGUI_FilterTable::addRow
1595 // Purpose : Add row at the end of table
1596 //=======================================================================
1597 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1600 int aSelectedRow = getFirstSelectedRow();
1601 int aCurrCol = theTable->currentColumn();
1604 if (toTheEnd || aSelectedRow == -1)
1606 theTable->insertRows(theTable->rowCount());
1607 aCurrRow = theTable->rowCount() - 1;
1611 theTable->insertRows(aSelectedRow);
1612 aCurrRow = aSelectedRow;
1616 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1617 bool isSignalsBlocked = theTable->signalsBlocked();
1618 theTable->blockSignals( true );
1621 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1624 theTable->setItem(aCurrRow, 1, getCompareItem());
1627 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1629 // Logical operation NOT
1630 theTable->setItem(aCurrRow, 3, getUnaryItem());
1632 // Logical operation AND / OR
1633 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1635 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1637 theTable->blockSignals( isSignalsBlocked );
1639 // Logical binary operation for previous value
1640 int anAddBinOpStr = -1;
1641 if (aCurrRow == theTable->rowCount() - 1)
1642 anAddBinOpStr = aCurrRow - 1;
1643 else if (aCurrRow >= 0 )
1644 anAddBinOpStr = aCurrRow;
1646 if (theTable->item(aCurrRow, 4) == 0 ||
1647 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1649 if (anAddBinOpStr >= 0 &&
1650 (theTable->item(anAddBinOpStr, 4) == 0 ||
1651 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1652 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1655 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1657 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1658 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1659 theTable->setCurrentCell(aCurrRow, aCurrCol);
1661 onCriterionChanged(aCurrRow, 0);
1666 //=======================================================================
1667 // name : SMESHGUI_FilterTable::getCriterionItem
1668 // Purpose : Get combo table item for criteria of specified type
1669 //=======================================================================
1670 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1672 return new ComboItem(getCriteria(theType));
1675 //=======================================================================
1676 // name : SMESHGUI_FilterTable::getCompareItem
1677 // Purpose : Get combo table item for operation of comparision
1678 //=======================================================================
1679 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1681 return new ComboItem(getCompare());
1684 //=======================================================================
1685 // name : SMESHGUI_FilterTable::getBinaryItem
1687 //=======================================================================
1688 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1690 static QMap<int, QString> aMap;
1693 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1694 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1697 return new ComboItem(aMap);
1700 //=======================================================================
1701 // name : SMESHGUI_FilterTable::getUnaryItem
1702 // Purpose : Get check table item
1703 //=======================================================================
1704 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1706 return new CheckItem(tr("NOT"));
1709 //=======================================================================
1710 // name : SMESHGUI_FilterTable::getSupportedTypes
1711 // Purpose : Get all supported type
1712 //=======================================================================
1713 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1715 static QMap<int, QString> aTypes;
1716 if (aTypes.isEmpty())
1718 aTypes[ SMESH::NODE ] = tr("NODES");
1719 aTypes[ SMESH::EDGE ] = tr("EDGES");
1720 aTypes[ SMESH::FACE ] = tr("FACES");
1721 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1722 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
1728 //=======================================================================
1729 // name : SMESHGUI_FilterTable::getCriteria
1730 // Purpose : Get criteria for specified type
1731 //=======================================================================
1732 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1734 if (theType == SMESH::NODE)
1736 static QMap<int, QString> aCriteria;
1737 if (aCriteria.isEmpty())
1739 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1740 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1741 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1742 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1743 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1744 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1745 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
1746 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1750 else if (theType == SMESH::EDGE)
1752 static QMap<int, QString> aCriteria;
1753 if (aCriteria.isEmpty())
1755 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1756 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
1757 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
1758 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1759 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1760 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1761 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1762 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1763 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1764 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1765 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1766 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1770 else if (theType == SMESH::FACE)
1772 static QMap<int, QString> aCriteria;
1773 if (aCriteria.isEmpty())
1775 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
1776 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
1777 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
1778 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
1779 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
1780 aCriteria[ SMESH::FT_Area ] = tr("AREA");
1781 aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
1782 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
1783 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1784 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1785 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1786 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1787 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1788 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1789 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
1790 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
1791 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
1792 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1793 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1794 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1798 else if (theType == SMESH::VOLUME)
1800 static QMap<int, QString> aCriteria;
1801 if (aCriteria.isEmpty())
1803 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
1804 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1805 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1806 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1807 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
1808 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
1809 aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
1810 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1811 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1812 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1818 static QMap<int, QString> aCriteria;
1819 if (aCriteria.isEmpty())
1821 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1822 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1823 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1824 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1825 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1826 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1834 //=======================================================================
1835 // name : SMESHGUI_FilterTable::getCompare
1836 // Purpose : Get operation of comparison
1837 //=======================================================================
1838 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1840 static QMap<int, QString> aMap;
1844 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
1845 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
1846 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
1852 //=======================================================================
1853 // name : SMESHGUI_FilterTable::createTable
1854 // Purpose : Create table
1855 //=======================================================================
1856 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
1860 Table* aTable= new Table(0, 6, theParent);
1862 QHeaderView* aHeaders = aTable->horizontalHeader();
1864 QFontMetrics aMetrics(aHeaders->font());
1866 // append spaces to the header of criteria in order to
1867 // provide visibility of criterion inside comboboxes
1868 static int aMaxLenCr = 0;
1872 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1873 QMap<int, QString>::const_iterator anIter;
1874 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
1875 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
1878 static int aLenCr = qAbs( aMaxLenCr -
1879 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
1882 aCrStr.fill(' ', aLenCr);
1884 aCoStr.fill(' ', 10);
1886 QStringList aHeaderLabels;
1887 aHeaderLabels.append( tr("CRITERION") + aCrStr );
1888 aHeaderLabels.append( tr("COMPARE") + aCoStr );
1889 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
1890 aHeaderLabels.append( tr("UNARY") );
1891 aHeaderLabels.append( tr("BINARY") + " " );
1892 aHeaderLabels.append( tr("ID") );
1893 aTable->setHorizontalHeaderLabels( aHeaderLabels );
1895 // set geometry of the table
1896 for (int i = 0; i <= 4; i++)
1897 aTable->resizeColumnToContents(i);
1899 // set the ID column invisible
1900 aTable->hideColumn( 5 );
1902 aTable->updateGeometry();
1903 QSize aSize = aTable->sizeHint();
1904 int aWidth = aSize.width();
1905 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
1906 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
1908 connect(aTable, SIGNAL(cellChanged(int, int)),
1909 this, SLOT(onCriterionChanged(int, int)));
1911 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
1912 this, SLOT(onCurrentChanged(int, int)));
1917 //=======================================================================
1918 // name : SMESHGUI_FilterTable::updateBtnState
1919 // Purpose : Update button state
1920 //=======================================================================
1921 void SMESHGUI_FilterTable::updateBtnState()
1923 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1924 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1927 //=======================================================================
1928 // name : SMESHGUI_FilterTable::SetEditable
1929 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1930 //=======================================================================
1931 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
1933 TableMap::iterator anIter;
1934 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1936 anIter.value()->setReadOnly(!isEditable);
1938 // Set Flags for CheckItems directly IPAL 19974
1939 Table* aTable = anIter.value();
1940 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1941 for (int j = 0, m = aTable->columnCount(); j < m; j++)
1943 QTableWidgetItem* anItem = aTable->item(i, j);
1944 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
1945 Qt::ItemFlags f = anItem->flags();
1946 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
1947 else f = f | Qt::ItemIsUserCheckable;
1948 anItem->setFlags( f );
1956 myInsertBtn->show();
1957 myRemoveBtn->show();
1963 myInsertBtn->hide();
1964 myRemoveBtn->hide();
1969 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1970 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1971 anIter2.value()->SetEditable(isEditable);
1974 //=======================================================================
1975 // name : SMESHGUI_FilterTable::SetEnabled
1976 // Purpose : Enable/Disable table. Switching type of elements already enabled
1977 //=======================================================================
1978 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
1980 myAddBtn->setEnabled(isEnabled);
1981 myInsertBtn->setEnabled(isEnabled);
1982 myRemoveBtn->setEnabled(isEnabled);
1983 myClearBtn->setEnabled(isEnabled);
1988 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1989 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1990 anIter2.value()->setEnabled(isEnabled);
1993 //=======================================================================
1994 // name : SMESHGUI_FilterTable::IsEditable
1995 // Purpose : Verify whether table is editable
1996 //=======================================================================
1997 bool SMESHGUI_FilterTable::IsEditable() const
1999 return !myTables[ GetType() ]->isReadOnly();
2002 //=======================================================================
2003 // name : SMESHGUI_FilterTable::SetLibsEnabled
2004 // Purpose : Show/hide buttons for work with libraries
2005 //=======================================================================
2006 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
2010 myCopyFromBtn->show();
2015 myCopyFromBtn->hide();
2020 //=======================================================================
2021 // name : SMESHGUI_FilterTable::onCopyFromBtn
2022 // Purpose : SLOT. Called the "Copy from ..." button clicked
2023 // Display filter library dialog
2024 //=======================================================================
2025 void SMESHGUI_FilterTable::onCopyFromBtn()
2028 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2029 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2031 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
2033 if (myLibDlg->exec() == QDialog::Accepted)
2035 Copy(myLibDlg->GetTable());
2040 //=======================================================================
2041 // name : SMESHGUI_FilterTable::onAddToBtn
2042 // Purpose : SLOT. Called the "Add to ..." button clicked
2043 // Display filter library dialog
2044 //=======================================================================
2045 void SMESHGUI_FilterTable::onAddToBtn()
2050 myLibDlg = new SMESHGUI_FilterLibraryDlg(
2051 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2053 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
2055 myLibDlg->SetTable(this);
2060 //=======================================================================
2061 // name : SMESHGUI_FilterTable::Copy
2062 // Purpose : Initialise table with values of other table
2063 //=======================================================================
2064 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
2068 for (int i = 0, n = theTable->NumRows(); i < n; i++)
2070 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
2071 theTable->GetCriterion(i, aCriterion);
2072 AddCriterion(aCriterion);
2076 //=======================================================================
2077 // name : SMESHGUI_FilterTable::CurrentCell
2078 // Purpose : Returns current cell
2079 //=======================================================================
2080 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
2082 theRow = myTables[ GetType() ]->currentRow();
2083 theCol = myTables[ GetType() ]->currentColumn();
2084 return theRow >= 0 && theCol >= 0;
2087 //=======================================================================
2088 // name : SMESHGUI_FilterTable::SetText
2089 // Purpose : Set text and internal value in cell of threshold value
2090 //=======================================================================
2091 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
2092 const QString& theText,
2093 const int theEntityType)
2095 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2096 aTable->item( theRow, 2 )->setText(theText);
2099 //=======================================================================
2100 // name : SMESHGUI_FilterTable::SetText
2101 // Purpose : Get text and internal value from cell of threshold value
2102 //=======================================================================
2103 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2105 const int theEntityType)
2107 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2108 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2111 theText = anItem->text();
2118 //=======================================================================
2119 // name : SMESHGUI_FilterTable::SetID
2120 // Purpose : Set text and internal value in cell of ID value
2121 //=======================================================================
2122 void SMESHGUI_FilterTable::SetID( const int theRow,
2123 const QString& theText,
2124 const int theEntityType )
2126 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2127 aTable->item( theRow, 5 )->setText( theText );
2130 //=======================================================================
2131 // name : SMESHGUI_FilterTable::GetID
2132 // Purpose : Get text and internal value from cell of ID value
2133 //=======================================================================
2134 bool SMESHGUI_FilterTable::GetID( const int theRow,
2136 const int theEntityType )
2138 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2139 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2142 theText = anItem->text();
2150 Class : SMESHGUI_FilterDlg
2151 Description : Dialog to specify filters for VTK viewer
2155 //=======================================================================
2156 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2157 // Purpose : Constructor
2158 //=======================================================================
2159 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2160 const QList<int>& theTypes )
2161 : QDialog( SMESH::GetDesktop( theModule ) ),
2162 mySMESHGUI( theModule ),
2163 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2164 myInitSourceWgOnApply( true )
2166 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2167 mySelector = aViewWindow->GetSelector();
2169 construct(theTypes);
2172 //=======================================================================
2173 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2174 // Purpose : Constructor
2175 //=======================================================================
2176 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2178 : QDialog( SMESH::GetDesktop( theModule ) ),
2179 mySMESHGUI( theModule ),
2180 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2181 myInitSourceWgOnApply( true )
2183 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2184 mySelector = aViewWindow->GetSelector();
2186 aTypes.append(theType);
2190 //=======================================================================
2191 // name : SMESHGUI_FilterDlg::construct
2192 // Purpose : Construct dialog (called by constructor)
2193 //=======================================================================
2194 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2199 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2200 setWindowTitle(tr("CAPTION"));
2202 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2203 aDlgLay->setMargin(MARGIN);
2204 aDlgLay->setSpacing(SPACING);
2206 myMainFrame = createMainFrame (this);
2207 QWidget* aBtnFrame = createButtonFrame(this);
2209 aDlgLay->addWidget(myMainFrame);
2210 aDlgLay->addWidget(aBtnFrame);
2212 aDlgLay->setStretchFactor(myMainFrame, 1);
2214 myHelpFileName = "selection_filter_library_page.html";
2219 //=======================================================================
2220 // name : SMESHGUI_FilterDlg::createMainFrame
2221 // Purpose : Create frame containing dialog's input fields
2222 //=======================================================================
2223 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2225 QWidget* aMainFrame = new QWidget(theParent);
2226 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2227 aMainLay->setMargin(0);
2228 aMainLay->setSpacing(SPACING);
2232 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2233 myTable->SetLibsEnabled(true);
2235 QGroupBox* aGrp = myTable->GetTableGrp();
2236 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2237 int rows = aLay->rowCount();
2238 int cols = aLay->columnCount();
2240 QFrame* aLine = new QFrame(aGrp);
2241 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2242 aLay->addWidget(aLine, rows++, 0, 1, cols);
2244 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2245 mySetInViewer->setChecked(true);
2246 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2249 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2251 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2252 SLOT(onCriterionChanged(const int, const int)));
2254 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2255 SLOT(onCurrentChanged(int, int)));
2257 aMainLay->addWidget(myTable);
2258 aMainLay->addWidget(aSourceGrp);
2263 //=======================================================================
2264 // name : SMESHGUI_FilterDlg::createSourceFrame
2265 // Purpose : Create frame containing source radio button
2266 //=======================================================================
2267 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2269 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2270 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2271 aLay->setMargin(MARGIN);
2272 aLay->setSpacing(SPACING);
2274 mySourceGrp = new QButtonGroup(theParent);
2276 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2277 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2278 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2280 aLay->addWidget(aMeshBtn);
2281 aLay->addWidget(aSelBtn);
2282 aLay->addWidget(aDlgBtn);
2284 mySourceGrp->addButton(aMeshBtn, Mesh);
2285 mySourceGrp->addButton(aSelBtn, Selection);
2286 mySourceGrp->addButton(aDlgBtn, Dialog);
2288 aSelBtn->setChecked(true);
2293 //=======================================================================
2294 // name : SMESHGUI_FilterDlg::updateMainButtons
2295 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2296 //=======================================================================
2297 void SMESHGUI_FilterDlg::updateMainButtons()
2299 if (myTypes.count() == 1)
2301 myButtons[ BTN_Cancel ]->show();
2302 myButtons[ BTN_Apply ]->hide();
2303 myButtons[ BTN_Close ]->hide();
2307 myButtons[ BTN_Cancel ]->hide();
2308 myButtons[ BTN_Apply ]->show();
2309 myButtons[ BTN_Close ]->show();
2312 // updateGeometry();
2315 //=======================================================================
2316 // name : SMESHGUI_FilterDlg::createButtonFrame
2317 // Purpose : Create frame containing buttons
2318 //=======================================================================
2319 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2321 QGroupBox* aGrp = new QGroupBox(theParent);
2322 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2323 aLay->setMargin(MARGIN);
2324 aLay->setSpacing(SPACING);
2326 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2327 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2328 myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
2329 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2330 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2332 aLay->addWidget(myButtons[ BTN_OK ]);
2333 aLay->addSpacing(10);
2334 aLay->addWidget(myButtons[ BTN_Apply ]);
2335 aLay->addSpacing(10);
2337 aLay->addWidget(myButtons[ BTN_Cancel ]);
2338 aLay->addWidget(myButtons[ BTN_Close ]);
2339 aLay->addWidget(myButtons[ BTN_Help ]);
2341 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2342 connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
2343 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
2344 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2345 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2347 updateMainButtons();
2352 //=======================================================================
2353 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2354 // Purpose : Destructor
2355 //=======================================================================
2356 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2360 //=======================================================================
2361 // name : SMESHGUI_FilterDlg::Init
2362 // Purpose : Init dialog fields, connect signals and slots, show dialog
2363 //=======================================================================
2364 void SMESHGUI_FilterDlg::Init (const int type)
2367 aTypes.append(type);
2371 //=======================================================================
2372 // name : SMESHGUI_FilterDlg::Init
2373 // Purpose : Init dialog fields, connect signals and slots, show dialog
2374 //=======================================================================
2375 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2379 myMesh = SMESH::SMESH_Mesh::_nil();
2381 myIsSelectionChanged = false;
2383 myTable->Init(theTypes);
2386 if (theTypes.count() == 1)
2388 int aType = theTypes.first();
2389 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2390 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2391 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2392 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2393 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2396 setWindowTitle(tr("TLT"));
2398 qApp->processEvents();
2403 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2405 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2406 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2408 updateMainButtons();
2411 // Initialise filter table with values of previous filter
2412 QList<int>::const_iterator anIter;
2413 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2415 myTable->Clear(*anIter);
2416 if (!myFilter[ *anIter ]->_is_nil())
2418 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2419 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2421 for (int i = 0, n = aCriteria->length(); i < n; i++)
2422 myTable->AddCriterion(aCriteria[ i ], *anIter);
2427 if (myInsertState.contains(theTypes.first()))
2428 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2430 mySetInViewer->setChecked(true);
2432 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2433 myApplyToState[ theTypes.first() ] :
2434 Selection)->setChecked(true);
2437 //=======================================================================
2438 // name : SMESHGUI_FilterDlg::onOk
2439 // Purpose : SLOT called when "Ok" button pressed.
2440 // Assign filters VTK viewer and close dialog
2441 //=======================================================================
2442 void SMESHGUI_FilterDlg::onOk()
2446 mySelectionMgr->clearFilters();
2447 disconnect(mySMESHGUI, 0, this, 0);
2448 disconnect(mySelectionMgr, 0, this, 0);
2449 mySMESHGUI->ResetState();
2455 //=======================================================================
2456 // name : SMESHGUI_FilterDlg::onClose
2457 // Purpose : SLOT called when "Close" button pressed. Close dialog
2458 //=======================================================================
2459 void SMESHGUI_FilterDlg::onClose()
2461 // Restore previously selected object
2464 SALOME_ListIO aList;
2465 mySelectionMgr->clearFilters();
2466 mySelectionMgr->clearSelected();
2467 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2468 for ( ; anIter.More(); anIter.Next())
2470 aList.Append(anIter.Key());
2472 TColStd_MapOfInteger aResMap;
2473 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2474 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2475 aResMap.Add(anIndMap(i));
2477 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2478 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2479 aViewWindow->highlight( anIter.Key(), true, true );
2481 mySelectionMgr->setSelectedObjects(aList, false);
2484 disconnect(mySMESHGUI, 0, this, 0);
2485 disconnect(mySelectionMgr, 0, this, 0);
2486 mySMESHGUI->ResetState();
2491 //=================================================================================
2492 // function : onHelp()
2494 //=================================================================================
2495 void SMESHGUI_FilterDlg::onHelp()
2497 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2499 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2503 platform = "winapplication";
2505 platform = "application";
2507 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2508 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2509 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2511 arg(myHelpFileName));
2515 //=======================================================================
2516 // name : SMESHGUI_FilterDlg::onDeactivate
2517 // Purpose : SLOT called when dialog must be deativated
2518 //=======================================================================
2519 void SMESHGUI_FilterDlg::onDeactivate()
2524 //=======================================================================
2525 // name : SMESHGUI_FilterDlg::enterEvent
2526 // Purpose : Event filter
2527 //=======================================================================
2528 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2530 // mySMESHGUI->EmitSignalDeactivateDialog();
2531 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2532 mySMESHGUI->ResetState();
2536 //=======================================================================
2537 // name : closeEvent()
2539 //=======================================================================
2540 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2545 //=======================================================================
2546 // name : SMESHGUI_FilterDlg::getIdsFromWg
2547 // Purpose : Retrieve list of ids from given widget
2548 //=======================================================================
2549 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2555 if (theWg->inherits("QListWidget"))
2557 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2559 for (int i = 0, n = aListBox->count(); i < n; i++)
2561 int anId = aListBox->item(i)->text().toInt(&b);
2563 theRes.append(anId);
2566 else if (theWg->inherits("QLineEdit"))
2568 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2569 QString aStr = aLineEdit->text();
2570 QRegExp aRegExp("(\\d+)");
2575 aPos = aRegExp.indexIn(aStr, aPos);
2578 int anId = aRegExp.cap(1).toInt(&b);
2580 theRes.append(anId);
2581 aPos += aRegExp.matchedLength();
2587 //=======================================================================
2588 // name : SMESHGUI_FilterDlg::getSelMode
2589 // Purpose : Get selection mode of specified type
2590 //=======================================================================
2591 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2595 case SMESH::NODE : return NodeSelection;
2596 case SMESH::EDGE : return EdgeSelection;
2597 case SMESH::FACE : return FaceSelection;
2598 case SMESH::VOLUME : return VolumeSelection;
2599 case SMESH::ALL : return CellSelection;
2600 default : return ActorSelection;
2605 //=======================================================================
2606 // name : SMESHGUI_FilterDlg::setIdsToWg
2607 // Purpose : Insert identifiers in specified widgets
2608 //=======================================================================
2609 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2614 QStringList aStrList;
2615 foreach(int id, theIds)
2616 aStrList << QString::number(id);
2618 if (theWg->inherits("QListWidget"))
2620 qobject_cast<QListWidget*>(theWg)->clear();
2621 qobject_cast<QListWidget*>(theWg)->addItems(aStrList);
2623 else if (theWg->inherits("QLineEdit"))
2625 qobject_cast<QLineEdit*>( theWg )->setText(aStrList.join(" "));
2629 //=======================================================================
2630 // name : SMESHGUI_FilterDlg::isValid
2631 // Purpose : Verify validity of input data
2632 //=======================================================================
2633 bool SMESHGUI_FilterDlg::isValid() const
2635 if (!myTable->IsValid())
2638 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2640 int aType = myTable->GetCriterionType(i);
2641 if (aType == SMESH::FT_BelongToGeom ||
2642 aType == SMESH::FT_BelongToPlane ||
2643 aType == SMESH::FT_BelongToCylinder ||
2644 aType == SMESH::FT_BelongToGenSurface ||
2645 aType == SMESH::FT_LyingOnGeom) {
2647 myTable->GetThreshold(i, aName);
2649 std::vector<_PTR(SObject)> aList =
2650 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2651 if (aList.size() == 0) {
2652 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2653 tr("BAD_SHAPE_NAME").arg(aName));
2657 if (aType == SMESH::FT_BelongToCylinder ||
2658 aType == SMESH::FT_BelongToPlane ||
2659 aType == SMESH::FT_BelongToGenSurface ) {
2660 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2661 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2662 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2663 if (!aGeomObj->_is_nil()) {
2665 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2667 aFace.ShapeType() != TopAbs_FACE) {
2668 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2669 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2673 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2674 if (aSurf.IsNull()) {
2675 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2676 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2680 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2681 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2682 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2686 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2687 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2688 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2699 //=======================================================================
2700 // name : SMESHGUI_FilterDlg::SetSourceWg
2701 // Purpose : Set widget of parent dialog containing idsto be filtered if
2702 // user select corresponding source radio button
2703 //=======================================================================
2704 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
2705 const bool initOnApply)
2708 myInitSourceWgOnApply = initOnApply;
2711 //=======================================================================
2712 // name : SMESHGUI_FilterDlg::SetGroupIds
2713 // Purpose : Set mesh
2714 //=======================================================================
2715 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2717 if ( !theMesh->_is_nil() ) {
2719 if ( !myFilter[ myTable->GetType() ]->_is_nil() && !myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ) {
2720 SMESH::Predicate_ptr aPred = myFilter[ myTable->GetType() ]->GetPredicate();
2721 aPred->SetMesh(myMesh);
2724 const bool isEnable = !(myMesh->_is_nil());
2725 myButtons[BTN_OK]->setEnabled(isEnable);
2726 myButtons[BTN_Apply]->setEnabled(isEnable);
2729 //=======================================================================
2730 // name : SMESHGUI_FilterDlg::SetSelection
2731 // Purpose : Get filtered ids
2732 //=======================================================================
2733 void SMESHGUI_FilterDlg::SetSelection()
2736 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
2738 if (mySelectionMgr) {
2740 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
2741 SALOME_ListIteratorOfListIO anIter (anObjs);
2742 for ( ; anIter.More(); anIter.Next()) {
2743 TColStd_IndexedMapOfInteger aMap;
2744 mySelector->GetIndex(anIter.Value(), aMap);
2745 myIObjects.Bind(anIter.Value(), aMap);
2748 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2756 //=======================================================================
2757 // name : SMESHGUI_FilterDlg::onApply
2758 // Purpose : SLOT called when "Apply" button pressed.
2759 // Assign filters to VTK viewer
2760 //=======================================================================
2761 bool SMESHGUI_FilterDlg::onApply()
2767 int aCurrType = myTable->GetType();
2769 if (!createFilter(aCurrType))
2772 insertFilterInViewer();
2774 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
2775 QList<int> aResultIds;
2776 filterSource(aCurrType, aResultIds);
2778 selectInViewer(aCurrType, aResultIds);
2782 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2783 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
2785 catch(const SALOME::SALOME_Exception& S_ex)
2787 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2796 //=======================================================================
2797 // name : SMESHGUI_FilterDlg::createFilter
2798 // Purpose : Create predicate for given type
2799 //=======================================================================
2800 bool SMESHGUI_FilterDlg::createFilter (const int theType)
2802 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2803 if (aFilterMgr->_is_nil())
2806 int n = myTable->NumRows();
2808 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2809 aCriteria->length(n);
2811 long aPrecision = -1;
2812 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2814 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
2815 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
2817 for (CORBA::ULong i = 0; i < n; i++) {
2818 SMESH::Filter::Criterion aCriterion = createCriterion();
2819 myTable->GetCriterion(i, aCriterion);
2820 aCriterion.Precision = aPrecision;
2821 aCriteria[ i ] = aCriterion;
2824 myFilter[ theType ] = aFilterMgr->CreateFilter();
2825 myFilter[ theType ]->SetCriteria(aCriteria.inout());
2830 //=======================================================================
2831 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2832 // Purpose : Insert filter in viewer
2833 //=======================================================================
2834 void SMESHGUI_FilterDlg::insertFilterInViewer()
2836 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
2837 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2839 if (myFilter[ myTable->GetType() ]->_is_nil() ||
2840 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2841 !mySetInViewer->isChecked()) {
2842 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
2845 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2846 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
2847 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
2848 SMESH::SetFilter(aFilter, aSelector);
2853 //=======================================================================
2854 // name : SMESHGUI_FilterDlg::filterSource
2855 // Purpose : Filter source ids
2856 //=======================================================================
2857 void SMESHGUI_FilterDlg::filterSource (const int theType,
2858 QList<int>& theResIds)
2861 if (myFilter[ theType ]->_is_nil())
2864 int aSourceId = mySourceGrp->checkedId();
2866 if (aSourceId == Mesh)
2868 if (myMesh->_is_nil())
2870 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
2871 for (int i = 0, n = anIds->length(); i < n; i++)
2872 theResIds.append(anIds[ i ]);
2874 else if (aSourceId == Selection)
2876 filterSelectionSource(theType, theResIds);
2878 else if (aSourceId == Dialog)
2880 // retrieve ids from dialog
2881 QList<int> aDialogIds;
2882 getIdsFromWg(mySourceWg, aDialogIds);
2884 if (myMesh->_is_nil())
2886 theResIds = aDialogIds;
2891 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2892 aPred->SetMesh(myMesh);
2893 QList<int>::const_iterator anIter;
2894 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
2895 if (aPred->IsSatisfy(*anIter))
2896 theResIds.append(*anIter);
2898 // set ids to the dialog
2899 if (myInitSourceWgOnApply || aSourceId == Dialog)
2900 setIdsToWg(mySourceWg, theResIds);
2903 //=======================================================================
2904 // name : SMESHGUI_FilterDlg::filterSelectionSource
2905 // Purpose : Filter source selection
2906 //=======================================================================
2907 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
2908 QList<int>& theResIds)
2911 if (myMesh->_is_nil() || mySelectionMgr == 0)
2914 // Create map of entities to be filtered
2915 TColStd_MapOfInteger aToBeFiltered;
2916 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
2918 for ( ; anIter.More(); anIter.Next())
2921 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
2922 if (!aSubMesh->_is_nil())
2924 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
2926 SMESH::long_array_var anIds =
2927 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2928 for (int i = 0, n = anIds->length(); i < n; i++)
2929 aToBeFiltered.Add(anIds[ i ]);
2934 SMESH::SMESH_GroupBase_var aGroup =
2935 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
2936 if (!aGroup->_is_nil())
2938 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
2940 SMESH::long_array_var anIds = aGroup->GetListOfID();
2941 for (int i = 0, n = anIds->length(); i < n; i++)
2942 aToBeFiltered.Add(anIds[ i ]);
2947 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
2948 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
2950 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2952 if (aSelMap.Extent() > 0)
2954 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
2956 for (int i = 1; i <= aSelMap.Extent(); i++)
2957 aToBeFiltered.Add(aSelMap(i));
2964 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2965 aPred->SetMesh(myMesh);
2966 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
2967 for ( ; aResIter.More(); aResIter.Next())
2968 if (aPred->IsSatisfy(aResIter.Key()))
2969 theResIds.append(aResIter.Key());
2972 //=======================================================================
2973 // name : SMESHGUI_FilterDlg::selectInViewer
2974 // Purpose : Select given entities in viewer
2975 //=======================================================================
2976 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
2978 if (mySelectionMgr == 0 || myMesh->_is_nil())
2981 mySelectionMgr->clearFilters();
2983 // Set new selection mode if necessary
2984 Selection_Mode aSelMode = getSelMode(theType);
2985 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2986 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
2987 mySelectionMgr->clearSelected();
2988 mySelectionMgr->clearFilters();
2989 if (aSelMode == NodeSelection)
2990 SMESH::SetPointRepresentation(true);
2991 aViewWindow->SetSelectionMode(aSelMode);
2995 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2996 if (!anActor || !anActor->hasIO())
2999 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
3000 //mySelectionMgr->clearSelected();
3001 //mySelectionMgr->AddIObject(anIO, false);
3002 SALOME_ListIO aList;
3004 mySelectionMgr->setSelectedObjects(aList, false);
3006 // Remove filter corresponding to the current type from viewer
3007 int aType = myTable->GetType();
3008 int aFilterId = SMESH::UnknownFilter;
3009 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
3010 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
3011 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
3012 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
3013 SMESH::RemoveFilter(aFilterId);
3016 TColStd_MapOfInteger aMap;
3017 QList<int>::const_iterator anIter;
3018 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
3022 // Set new selection
3023 mySelector->AddOrRemoveIndex(anIO, aMap, false);
3024 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
3025 aViewWindow->highlight( anIO, true, true );
3027 // insert previously stored filter in viewer if necessary
3028 if (!aFilter.IsNull())
3029 SMESH::SetFilter(aFilter);
3032 //=======================================================================
3033 // name : SMESHGUI_FilterDlg::createCriterion
3034 // Purpose : Create criterion structure with default values
3035 //=======================================================================
3036 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
3038 SMESH::Filter::Criterion aCriterion;
3040 aCriterion.Type = SMESH::FT_Undefined;
3041 aCriterion.Compare = SMESH::FT_Undefined;
3042 aCriterion.Threshold = 0;
3043 aCriterion.UnaryOp = SMESH::FT_Undefined;
3044 aCriterion.BinaryOp = SMESH::FT_Undefined;
3045 aCriterion.ThresholdStr = "";
3046 aCriterion.ThresholdID = "";
3047 aCriterion.TypeOfElement = SMESH::ALL;
3052 //=======================================================================
3053 // name : SMESHGUI_FilterDlg::onSelectionDone
3054 // Purpose : SLOT called when selection changed.
3055 // If current cell corresponds to the threshold value of
3056 // BelongToGeom criterion name of selected object is set in this cell
3057 //=======================================================================
3058 void SMESHGUI_FilterDlg::onSelectionDone()
3061 const SALOME_ListIO& aList = mySelector->StoredIObjects();
3063 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
3064 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
3065 if ( !(myMesh->_is_nil()) ) {
3066 myButtons[BTN_OK]->setEnabled(true);
3067 myButtons[BTN_Apply]->setEnabled(true);
3072 types << SMESH::FT_BelongToGeom << SMESH::FT_BelongToPlane
3073 << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
3074 << SMESH::FT_LyingOnGeom;
3075 if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) ||
3076 !types.contains(myTable->GetCriterionType(aRow)))
3079 Handle(SALOME_InteractiveObject) anIO = aList.First();
3080 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
3081 if (!anObj->_is_nil())
3083 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
3084 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
3085 myTable->SetID(aRow, anIO->getEntry());
3090 //=======================================================================
3091 // name : SMESHGUI_FilterDlg::onCriterionChanged
3092 // Purpose : SLOT called when cretarion of current row changed. Update selection
3093 //=======================================================================
3094 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3099 //=======================================================================
3100 // name : SMESHGUI_FilterDlg::onCurrentChanged
3101 // Purpose : SLOT called when current row changed. Update selection
3102 //=======================================================================
3103 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3108 //=======================================================================
3109 // name : SMESHGUI_FilterDlg::updateSelection
3110 // Purpose : UpdateSelection in accordance with current row
3111 //=======================================================================
3112 void SMESHGUI_FilterDlg::updateSelection()
3114 if (mySelectionMgr == 0)
3117 TColStd_MapOfInteger allTypes;
3118 for( int i=0; i<10; i++ )
3120 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3125 mySelectionMgr->clearFilters();
3129 int aCriterionType = myTable->GetCriterionType(aRow);
3130 if (myTable->CurrentCell(aRow, aCol) &&
3131 (aCriterionType == SMESH::FT_BelongToGeom ||
3132 aCriterionType == SMESH::FT_BelongToPlane ||
3133 aCriterionType == SMESH::FT_BelongToCylinder ||
3134 aCriterionType == SMESH::FT_BelongToGenSurface ||
3135 aCriterionType == SMESH::FT_LyingOnGeom)) {
3137 if (aCriterionType == SMESH::FT_BelongToGeom ||
3138 aCriterionType == SMESH::FT_BelongToGenSurface ||
3139 aCriterionType == SMESH::FT_LyingOnGeom) {
3141 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3143 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3144 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3146 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3147 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3149 myIsSelectionChanged = true;
3152 if (myIsSelectionChanged) {
3153 mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3158 //=================================================================================
3159 // function : keyPressEvent()
3161 //=================================================================================
3162 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3164 QDialog::keyPressEvent( e );
3165 if ( e->isAccepted() )
3168 if ( e->key() == Qt::Key_F1 ) {