1 // Copyright (C) 2007-2008 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
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_FilterDlg.cxx
24 // Author : Sergey LITONIN, Open CASCADE S.A.S.
27 #include "SMESHGUI_FilterDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Filter.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_FilterLibraryDlg.h"
36 #include <SMESH_Actor.h>
37 #include <SMESH_NumberFilter.hxx>
38 #include <SMESH_TypeFilter.hxx>
40 // SALOME GEOM includes
42 #include <GEOM_FaceFilter.h>
43 #include <GEOM_TypeFilter.h>
45 // SALOME GUI includes
46 #include <SUIT_Desktop.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_Session.h>
49 #include <SUIT_MessageBox.h>
50 #include <QtxColorButton.h>
52 #include <LightApp_Application.h>
53 #include <LightApp_SelectionMgr.h>
54 #include <SalomeApp_Tools.h>
55 #include <SalomeApp_Study.h>
57 #include <SALOME_ListIO.hxx>
58 #include <SALOME_ListIteratorOfListIO.hxx>
59 #include <SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx>
61 #include <SVTK_ViewWindow.h>
63 // SALOME KERNEL includes
64 #include <SALOMEDSClient_Study.hxx>
67 #include <StdSelect_TypeOfFace.hxx>
68 #include <BRep_Tool.hxx>
70 #include <TopoDS_Shape.hxx>
71 #include <Geom_Plane.hxx>
72 #include <Geom_CylindricalSurface.hxx>
73 #include <Precision.hxx>
74 #include <TColStd_MapOfInteger.hxx>
75 #include <TColStd_IndexedMapOfInteger.hxx>
76 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
81 #include <QPushButton>
83 #include <QTableWidget>
84 #include <QStringList>
85 #include <QHBoxLayout>
86 #include <QVBoxLayout>
87 #include <QGridLayout>
88 #include <QStackedWidget>
89 #include <QApplication>
91 #include <QFontMetrics>
93 #include <QButtonGroup>
94 #include <QRadioButton>
96 #include <QListWidget>
98 #include <QItemDelegate>
99 #include <QDoubleValidator>
101 #include <QHeaderView>
104 #include <SALOMEconfig.h>
105 #include CORBA_SERVER_HEADER(SMESH_Group)
110 //---------------------------------------
112 //---------------------------------------
113 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
116 QMap<int, QString>::const_iterator anIter;
117 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
118 aRes = qMax(aRes, theMetrics.width(anIter.value()));
122 //---------------------------------------
124 //---------------------------------------
125 static int getFilterId (SMESH::ElementType theType)
129 case SMESH::NODE : return SMESH::NodeFilter;
130 case SMESH::EDGE : return SMESH::EdgeFilter;
131 case SMESH::FACE : return SMESH::FaceFilter;
132 case SMESH::VOLUME : return SMESH::VolumeFilter;
133 case SMESH::ALL : return SMESH::AllElementsFilter;
134 default : return SMESH::UnknownFilter;
139 Class : SMESHGUI_FilterTable::AdditionalWidget
140 Description : Class for storing additional parameters of criterion
143 class SMESHGUI_FilterTable::AdditionalWidget : public QWidget
149 AdditionalWidget(QWidget* theParent);
150 virtual ~AdditionalWidget();
152 virtual QList<int> GetParameters() const;
153 virtual bool IsValid(const bool = true) const;
154 virtual double GetDouble(const int) const;
155 virtual int GetInteger(const int) const;
156 virtual QString GetString(const int) const;
157 virtual void SetDouble(const int, const double);
158 virtual void SetInteger(const int, const int);
159 virtual void SetString(const int, const QString&);
160 void SetEditable(const int, const bool);
161 void SetEditable(const bool);
164 QMap< int, QLineEdit* > myLineEdits;
167 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
170 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
171 myLineEdits[ Tolerance ] = new QLineEdit(this);
172 QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]);
173 aValidator->setBottom(0);
174 myLineEdits[ Tolerance ]->setValidator(aValidator);
176 QHBoxLayout* aLay = new QHBoxLayout(this);
177 aLay->setSpacing(SPACING);
180 aLay->addWidget(aLabel);
181 aLay->addWidget(myLineEdits[ Tolerance ]);
184 QString aText = QString("%1").arg(Precision::Confusion());
185 myLineEdits[ Tolerance ]->setText(aText);
188 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
192 QList<int> SMESHGUI_FilterTable::AdditionalWidget::GetParameters() const
195 theList.append(Tolerance);
199 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
204 QList<int> aParams = GetParameters();
205 QList<int>::const_iterator anIter;
206 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
207 const QLineEdit* aWg = myLineEdits[ *anIter ];
209 QString aText = aWg->text();
210 if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) {
212 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
213 tr("SMESHGUI_INVALID_PARAMETERS"));
221 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
223 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toDouble() : 0;
226 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
228 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toInt() : 0;
231 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
233 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text() : QString("");
236 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
238 if (myLineEdits.contains(theId))
239 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
242 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
244 if (myLineEdits.contains(theId))
245 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
248 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
250 if (myLineEdits.contains(theId))
251 myLineEdits[ theId ]->setText(theVal);
254 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
256 if (myLineEdits.contains(theId))
257 myLineEdits[ theId ]->setReadOnly(!isEditable);
260 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
262 QList<int> aParams = GetParameters();
263 QList<int>::const_iterator anIter;
264 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
265 SetEditable( *anIter, isEditable );
269 Class : SMESHGUI_FilterTable::ComboItem
270 Description : Combo table item. Identificator corresponding to string may be assigned
273 class SMESHGUI_FilterTable::ComboItem : public QTableWidgetItem
278 ComboItem( const QMap<int, QString>& );
280 void setItems( const QMap<int, QString>& );
285 void setValue( const int );
289 int index( int ) const;
292 QMap<int, int> myIdToIdx;
295 int SMESHGUI_FilterTable::ComboItem::Type()
297 return QTableWidgetItem::UserType + 1;
300 SMESHGUI_FilterTable::ComboItem::ComboItem( const QMap<int, QString>& theIds )
301 : QTableWidgetItem( Type() )
306 void SMESHGUI_FilterTable::ComboItem::setItems( const QMap<int, QString>& theIds )
309 QMap<int, QString>::const_iterator it;
311 for ( it = theIds.begin(); it != theIds.end(); ++it ) {
312 myIdToIdx[it.key()] = items.count();
313 items.append( it.value() );
315 setData( Qt::UserRole, items );
319 void SMESHGUI_FilterTable::ComboItem::clear()
321 QMap<int, QString> empty;
325 int SMESHGUI_FilterTable::ComboItem::count() const
327 return myIdToIdx.count();
330 int SMESHGUI_FilterTable::ComboItem::value() const
332 return( id( data( Qt::UserRole ).toStringList().indexOf( text() ) ) );
335 void SMESHGUI_FilterTable::ComboItem::setValue( const int theId )
337 int idx = index( theId );
338 QStringList items = data( Qt::UserRole ).toStringList();
339 setText( idx >= 0 && idx < items.count() ? items[idx] : "" );
342 int SMESHGUI_FilterTable::ComboItem::id( int idx ) const
344 QMap<int,int>::const_iterator it;
345 for ( it = myIdToIdx.begin(); it != myIdToIdx.end(); ++it )
346 if ( it.value() == idx ) return it.key();
350 int SMESHGUI_FilterTable::ComboItem::index( int i ) const
352 return myIdToIdx.contains( i ) ? myIdToIdx[i] : -1;
355 Class : SMESHGUI_FilterTable::CheckItem
356 Description : Check table item.
359 class SMESHGUI_FilterTable::CheckItem : public QTableWidgetItem
364 CheckItem( bool = false );
365 CheckItem( const QString&, bool = false );
368 void setChecked( bool );
369 bool checked() const;
372 int SMESHGUI_FilterTable::CheckItem::Type()
374 return QTableWidgetItem::UserType + 2;
377 SMESHGUI_FilterTable::CheckItem::CheckItem( bool value )
378 : QTableWidgetItem( Type() )
380 Qt::ItemFlags f = flags();
381 f = f | Qt::ItemIsUserCheckable;
382 f = f & ~Qt::ItemIsTristate;
383 f = f & ~Qt::ItemIsEditable;
388 SMESHGUI_FilterTable::CheckItem::CheckItem( const QString& text, bool value )
389 : QTableWidgetItem( Type() )
391 Qt::ItemFlags f = flags();
392 f = f | Qt::ItemIsUserCheckable;
393 f = f & ~Qt::ItemIsTristate;
394 f = f & ~Qt::ItemIsEditable;
400 SMESHGUI_FilterTable::CheckItem::~CheckItem()
404 void SMESHGUI_FilterTable::CheckItem::setChecked( bool value )
406 setCheckState( value ? Qt::Checked : Qt::Unchecked );
409 bool SMESHGUI_FilterTable::CheckItem::checked() const
411 return checkState() == Qt::Checked;
415 Class : SMESHGUI_FilterTable::ComboDelegate
416 Description : Table used by this widget
419 class SMESHGUI_FilterTable::ComboDelegate : public QItemDelegate
422 ComboDelegate( QObject* = 0 );
425 QWidget* createEditor( QWidget*, const QStyleOptionViewItem&,
426 const QModelIndex& ) const;
428 void setEditorData( QWidget*, const QModelIndex& ) const;
429 void setModelData( QWidget*, QAbstractItemModel*, const QModelIndex& ) const;
431 void updateEditorGeometry( QWidget*, const QStyleOptionViewItem&,
432 const QModelIndex& ) const;
434 QTableWidget* myTable;
437 SMESHGUI_FilterTable::ComboDelegate::ComboDelegate( QObject* parent )
438 : QItemDelegate( parent ),
439 myTable( qobject_cast<QTableWidget*>( parent ) )
443 SMESHGUI_FilterTable::ComboDelegate::~ComboDelegate()
447 QWidget* SMESHGUI_FilterTable::ComboDelegate::createEditor( QWidget* parent,
448 const QStyleOptionViewItem& option,
449 const QModelIndex& index ) const
451 QStringList l = index.data( Qt::UserRole ).toStringList();
452 if ( !l.isEmpty() ) {
453 QComboBox* cb = new QComboBox( parent );
454 cb->setFrame( false );
458 return QItemDelegate::createEditor( parent, option, index );
461 void SMESHGUI_FilterTable::ComboDelegate::setEditorData( QWidget* editor,
462 const QModelIndex& index ) const
464 QString value = index.model()->data( index, Qt::DisplayRole ).toString();
465 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
468 int i = cb->findText( value );
470 cb->setCurrentIndex( i );
474 if ( !bOk ) QItemDelegate::setEditorData( editor, index );
477 void SMESHGUI_FilterTable::ComboDelegate::setModelData( QWidget* editor,
478 QAbstractItemModel* model,
479 const QModelIndex& index) const
481 QComboBox* cb = dynamic_cast<QComboBox*>( editor );
482 if ( cb ) model->setData( index, cb->currentText(), Qt::DisplayRole );
483 else QItemDelegate::setModelData( editor, model, index );
486 void SMESHGUI_FilterTable::ComboDelegate::updateEditorGeometry( QWidget* editor,
487 const QStyleOptionViewItem& option,
488 const QModelIndex& index ) const
490 editor->setGeometry( option.rect );
494 Class : SMESHGUI_FilterTable::Table
495 Description : Table used by this widget
498 class SMESHGUI_FilterTable::Table : public QTableWidget
501 Table( QWidget* = 0 );
502 Table( int, int, QWidget* = 0 );
505 QSize minimumSizeHint() const;
507 void setEditable( bool, int, int );
508 bool isEditable( int, int ) const;
510 void setReadOnly( bool );
511 bool isReadOnly() const;
513 void insertRows( int, int = 1 );
514 QString text( int, int );
516 QList<int> selectedRows();
519 //=======================================================================
520 // name : SMESHGUI_FilterTable::Table::Table
521 // Purpose : Constructor
522 //=======================================================================
523 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
524 : QTableWidget(parent)
526 // set custom item delegate
527 setItemDelegate( new ComboDelegate(this) );
528 // set edit triggers by default
529 setReadOnly( false );
532 //=======================================================================
533 // name : SMESHGUI_FilterTable::Table::Table
534 // Purpose : Constructor
535 //=======================================================================
536 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
537 : QTableWidget(numRows, numCols, parent)
539 // set custom item delegate
540 setItemDelegate( new ComboDelegate(this) );
541 // set edit triggers by default
542 setReadOnly( false );
545 //=======================================================================
546 // name : SMESHGUI_FilterTable::Table::~Table
547 // Purpose : Destructor
548 //=======================================================================
549 SMESHGUI_FilterTable::Table::~Table()
553 //=======================================================================
554 // name : SMESHGUI_FilterTable::Table::minimumSizeHint
555 // Purpose : Get minimum size for the table
556 //=======================================================================
557 QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
559 QSize s = QTableWidget::minimumSizeHint();
560 QHeaderView* hv = horizontalHeader();
562 s.setWidth( qMax( s.width(), hv->length() ) );
566 //=======================================================================
567 // name : SMESHGUI_FilterTable::Table::setEditable
568 // Purpose : Set editable of specified cell
569 //=======================================================================
570 void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
573 QTableWidgetItem* anItem = item( row, col );
575 bool isSignalsBlocked = signalsBlocked();
576 blockSignals( true );
578 Qt::ItemFlags f = anItem->flags();
579 if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
580 else f = f | Qt::ItemIsEditable;
581 anItem->setFlags( f );
583 blockSignals( isSignalsBlocked );
587 //=======================================================================
588 // name : SMESHGUI_FilterTable::Table::isEditable
589 // Purpose : Verify wheter cell is editable
590 //=======================================================================
591 bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
593 QTableWidgetItem* anItem = item( row, col );
594 return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
597 void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
599 setEditTriggers( on ?
600 QAbstractItemView::NoEditTriggers :
601 QAbstractItemView::AllEditTriggers );
604 bool SMESHGUI_FilterTable::Table::isReadOnly() const
606 return editTriggers() == QAbstractItemView::NoEditTriggers;
609 //=======================================================================
610 // name : SMESHGUI_FilterTable::Table::insertRows
611 // Purpose : Insert rows (virtual redefined)
612 //=======================================================================
613 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
615 closePersistentEditor( currentItem() );
616 while ( count-- ) insertRow( row );
619 //=======================================================================
620 // name : SMESHGUI_FilterTable::Table::text
621 // Purpose : Get text from cell (virtual redefined)
622 //=======================================================================
623 QString SMESHGUI_FilterTable::Table::text (int row, int col)
625 closePersistentEditor( currentItem() );
626 QTableWidgetItem* anItem = item( row, col );
627 return anItem ? anItem->text() : QString();
630 QList<int> SMESHGUI_FilterTable::Table::selectedRows()
632 QList<QTableWidgetItem*> selItems = selectedItems();
633 QTableWidgetItem* anItem;
636 foreach( anItem, selItems ) {
637 int r = row( anItem );
638 if ( !rows.contains( r ) ) rows.append( r );
646 Class : SMESHGUI_FilterTable
647 Description : Frame containig
648 - Button group for switching entity type
649 - Table for displaying filter criterions
650 - Buttons for editing table and filter libraries
653 //=======================================================================
654 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
655 // Purpose : Constructor
656 //=======================================================================
657 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
662 mySMESHGUI( theModule )
671 //=======================================================================
672 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
673 // Purpose : Constructor
674 //=======================================================================
675 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
677 const QList<int>& types )
680 mySMESHGUI( theModule )
686 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
690 //=======================================================================
691 // name : SMESHGUI_FilterTable::Init
692 // Purpose : Create table corresponding to the specified type
693 //=======================================================================
694 void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
696 if (theTypes.isEmpty())
699 // Create buttons if necessary
701 if (myTables.isEmpty())
703 // create main layout
704 QVBoxLayout* aMainLay = new QVBoxLayout(this);
705 aMainLay->setMargin( 0 );
706 aMainLay->setSpacing( SPACING );
708 // create switch of entity types
709 myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
710 QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
711 myEntityTypeBoxLayout->setMargin( MARGIN );
712 myEntityTypeBoxLayout->setSpacing( SPACING );
713 myEntityTypeGrp = new QButtonGroup(this);
715 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
716 QMap<int, QString>::const_iterator anIter;
717 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
719 QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
720 myEntityTypeGrp->addButton(aBtn, anIter.key());
721 myEntityTypeBoxLayout->addWidget(aBtn);
724 myTableGrp = new QGroupBox(tr("FILTER"), this );
727 mySwitchTableGrp = new QWidget(myTableGrp);
728 QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
729 mySwitchTableGrpLayout->setMargin(0);
730 mySwitchTableGrpLayout->setSpacing(0);
732 QList<int>::const_iterator typeIt = theTypes.begin();
733 for ( ; typeIt != theTypes.end(); ++typeIt ) {
734 Table* aTable = createTable(mySwitchTableGrp, *typeIt);
735 myTables[ *typeIt ] = aTable;
736 mySwitchTableGrpLayout->addWidget(aTable);
737 if ( typeIt != theTypes.begin() )
742 myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
743 myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
744 myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
745 myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
746 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
747 myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
749 myAddBtn->setAutoDefault(false);
750 myRemoveBtn->setAutoDefault(false);
751 myClearBtn->setAutoDefault(false);
752 myInsertBtn->setAutoDefault(false);
753 myCopyFromBtn->setAutoDefault(false);
754 myAddToBtn->setAutoDefault(false);
756 myCopyFromBtn->hide();
760 QGridLayout* aLay = new QGridLayout(myTableGrp);
761 aLay->setMargin(MARGIN);
762 aLay->setSpacing(SPACING);
764 aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
765 aLay->addWidget(myAddBtn, 0, 1);
766 aLay->addWidget(myInsertBtn, 1, 1);
767 aLay->addWidget(myRemoveBtn, 2, 1);
768 aLay->addWidget(myClearBtn, 3, 1);
769 aLay->addWidget(myCopyFromBtn, 5, 1);
770 aLay->addWidget(myAddToBtn, 6, 1);
771 aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
773 aLay->setRowMinimumHeight(4, 10);
774 aLay->setRowStretch(4, 1);
775 aLay->setColumnStretch(0, 1);
776 aLay->setColumnStretch(1, 0);
779 aMainLay->addWidget(myEntityTypeBox);
780 aMainLay->addWidget(myTableGrp);
783 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
784 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
785 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
786 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
788 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
789 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
791 connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
796 // Hide buttons of entity types if necessary
797 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
798 QMap<int, QString>::const_iterator anIt;
799 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
801 QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
802 if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
805 // select first button if there is no selected buttons or it is hidden
806 int aBtnId = myEntityTypeGrp->checkedId();
807 if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
808 QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
809 if ( aBtn ) aBtn->setChecked(true);
812 myEntityTypeBox->setVisible(theTypes.count() > 1);
814 myTableGrp->updateGeometry();
815 int cType = myEntityTypeGrp->checkedId();
819 //=======================================================================
820 // name : SMESHGUI_FilterTable::createAdditionalFrame
821 // Purpose : Get group box containing table. May be used for adding new widgets in it
822 //=======================================================================
823 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
825 QWidget* aFrame = new QWidget(theParent);
827 QFrame* aLine1 = new QFrame(aFrame);
828 QFrame* aLine2 = new QFrame(aFrame);
829 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
830 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
831 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
832 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
834 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
836 myWgStack = new QStackedWidget(aFrame);
838 QGridLayout* aLay = new QGridLayout(aFrame);
840 aLay->setSpacing(SPACING);
841 aLay->addWidget(aLine1, 0, 0);
842 aLay->addWidget(aLabel, 0, 1);
843 aLay->addWidget(aLine2, 0, 2);
844 aLay->addWidget(myWgStack, 1, 0, 1, 3);
849 //=======================================================================
850 // name : SMESHGUI_FilterTable::GetTableGrp
851 // Purpose : Get group box containing table. May be used for adding new widgets in it
852 //=======================================================================
853 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
858 //=======================================================================
859 // name : SMESHGUI_FilterTable::onEntityType
860 // Purpose : SLOT. Called when entity type changed.
861 // Display corresponding table
862 //=======================================================================
863 void SMESHGUI_FilterTable::onEntityType (int theType)
865 if (myEntityType == theType)
869 emit NeedValidation();
872 myEntityTypeGrp->button(myEntityType)->setChecked(true);
876 myEntityType = theType;
878 if (!myTables.contains(theType)) {
879 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
880 ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
883 TableMap::iterator anIter;
884 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
885 anIter.value()->setVisible( myEntityType == anIter.key() );
888 qApp->processEvents();
889 myTables[ myEntityType ]->updateGeometry();
892 emit EntityTypeChanged(theType);
895 //=======================================================================
896 // name : SMESHGUI_FilterTable::IsValid
897 // Purpose : Verify validity of entered data
898 //=======================================================================
899 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
901 int aType = theEntityType == -1 ? GetType() : theEntityType;
903 Table* aTable = myTables[ aType ];
904 for (int i = 0, n = aTable->rowCount(); i < n; i++)
906 int aCriterion = GetCriterionType(i, aType);
908 if (aCriterion == SMESH::FT_GroupColor ) {
909 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
910 if (clrBtn && !clrBtn->color().isValid())
911 errMsg = tr( "GROUPCOLOR_ERROR" );
912 } else if (aCriterion == SMESH::FT_RangeOfIds ||
913 aCriterion == SMESH::FT_BelongToGeom ||
914 aCriterion == SMESH::FT_BelongToPlane ||
915 aCriterion == SMESH::FT_BelongToCylinder ||
916 aCriterion == SMESH::FT_BelongToGenSurface ||
917 aCriterion == SMESH::FT_ElemGeomType ||
918 aCriterion == SMESH::FT_LyingOnGeom) {
919 if (aTable->text(i, 2).isEmpty())
920 errMsg = tr( "ERROR" );
924 bool isSignalsBlocked = aTable->signalsBlocked();
925 aTable->blockSignals(true);
926 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
927 aTable->blockSignals(isSignalsBlocked);
929 if (!aRes && aTable->isEditable(i, 2))
930 errMsg = tr( "ERROR" );
931 else if (aType == SMESH::EDGE &&
932 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
934 errMsg = tr( "MULTIEDGES_ERROR" );
937 if (!errMsg.isEmpty()) {
939 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
943 QTableWidgetItem* anItem = aTable->item(i, 0);
944 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
951 //=======================================================================
952 // name : SMESHGUI_FilterTable::SetValidity
953 // Purpose : Set validity of the table
954 //=======================================================================
955 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
960 //=======================================================================
961 // name : SMESHGUI_FilterTable::GetType
962 // Purpose : Get current entity type
963 //=======================================================================
964 int SMESHGUI_FilterTable::GetType() const
969 //=======================================================================
970 // name : SMESHGUI_FilterTable::SetType
971 // Purpose : Set current entity type
972 //=======================================================================
973 void SMESHGUI_FilterTable::SetType (const int type)
975 myEntityTypeGrp->button(type)->setChecked(true);
979 //=======================================================================
980 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
981 // Purpose : Restore previous entity type
982 //=======================================================================
983 void SMESHGUI_FilterTable::RestorePreviousEntityType()
985 SetType(myEntityType);
988 //=======================================================================
989 // name : SMESHGUI_FilterTable::GetCriterionType
990 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
991 //=======================================================================
992 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
994 int aType = theType == -1 ? GetType() : theType;
995 Table* aTable = myTables[ aType ];
996 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
997 return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
1000 //=======================================================================
1001 // name : SMESHGUI_FilterTable::GetCriterion
1002 // Purpose : Get parameters of criterion from specified row
1003 //=======================================================================
1004 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
1005 SMESH::Filter::Criterion& theCriterion,
1006 const int theEntityType) const
1008 int aType = theEntityType == -1 ? GetType() : theEntityType;
1009 Table* aTable = myTables[ aType ];
1011 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
1012 theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
1013 theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
1014 ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
1015 theCriterion.TypeOfElement = (SMESH::ElementType)aType;
1017 int aCriterionType = GetCriterionType(theRow, aType);
1019 if ( aCriterionType == SMESH::FT_GroupColor )
1021 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1024 const QColor qClr = clrBtn->color();
1025 QString clrStr = QString( "%1;%2;%3" ).
1026 arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
1027 theCriterion.ThresholdStr = clrStr.toLatin1().constData();
1030 else if ( aCriterionType == SMESH::FT_ElemGeomType )
1031 theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
1032 else if ( aCriterionType != SMESH::FT_RangeOfIds &&
1033 aCriterionType != SMESH::FT_BelongToGeom &&
1034 aCriterionType != SMESH::FT_BelongToPlane &&
1035 aCriterionType != SMESH::FT_BelongToCylinder &&
1036 aCriterionType != SMESH::FT_BelongToGenSurface &&
1037 aCriterionType != SMESH::FT_LyingOnGeom)
1039 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
1040 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
1044 theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
1045 if ( aCriterionType != SMESH::FT_RangeOfIds )
1046 theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
1049 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1050 if (myAddWidgets.contains(anItem))
1051 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
1054 //=======================================================================
1055 // name : SMESHGUI_FilterTable::SetCriterion
1056 // Purpose : Set parameters of criterion of specified row
1057 //=======================================================================
1058 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
1059 const SMESH::Filter::Criterion& theCriterion,
1060 const int theEntityType)
1062 int aType = theEntityType == -1 ? GetType() : theEntityType;
1064 Table* aTable = myTables[ aType ];
1066 if (theRow > aTable->rowCount() - 1)
1069 ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
1070 onCriterionChanged(theRow, 0, aType);
1071 ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
1072 ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
1074 if (theCriterion.BinaryOp != SMESH::FT_Undefined)
1076 if (!aTable->isEditable(theRow, 4))
1077 aTable->setItem(theRow, 4, getBinaryItem());
1078 ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
1081 aTable->setEditable(false, theRow, 4);
1083 if (theCriterion.Type == SMESH::FT_GroupColor )
1085 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
1089 QString clrStr( theCriterion.ThresholdStr );
1090 QStringList clrVals = clrStr.split( ";" );
1091 if ( clrVals.count() > 2 )
1092 qClr.setRgb( (int)256*clrVals[0].toDouble(),
1093 (int)256*clrVals[1].toDouble(),
1094 (int)256*clrVals[2].toDouble() );
1095 clrBtn->setColor( qClr );
1098 else if (theCriterion.Type == SMESH::FT_ElemGeomType )
1100 ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
1101 typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
1103 else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
1104 theCriterion.Type != SMESH::FT_BelongToGeom &&
1105 theCriterion.Type != SMESH::FT_BelongToPlane &&
1106 theCriterion.Type != SMESH::FT_BelongToCylinder &&
1107 theCriterion.Type != SMESH::FT_BelongToGenSurface &&
1108 theCriterion.Type != SMESH::FT_LyingOnGeom &&
1109 theCriterion.Type != SMESH::FT_FreeBorders &&
1110 theCriterion.Type != SMESH::FT_FreeEdges &&
1111 theCriterion.Type != SMESH::FT_FreeNodes &&
1112 theCriterion.Type != SMESH::FT_FreeFaces &&
1113 theCriterion.Type != SMESH::FT_BadOrientedVolume &&
1114 theCriterion.Type != SMESH::FT_LinearOrQuadratic)
1115 aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
1118 aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
1119 if ( theCriterion.Type != SMESH::FT_RangeOfIds )
1120 aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
1123 if (theCriterion.Compare == SMESH::FT_EqualTo ||
1124 theCriterion.Type == SMESH::FT_BelongToPlane ||
1125 theCriterion.Type == SMESH::FT_BelongToCylinder ||
1126 theCriterion.Type == SMESH::FT_BelongToGenSurface ||
1127 theCriterion.Type == SMESH::FT_BelongToGeom ||
1128 theCriterion.Type == SMESH::FT_LyingOnGeom)
1130 QTableWidgetItem* anItem = aTable->item(theRow, 0);
1131 if (!myAddWidgets.contains(anItem))
1133 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1134 myWgStack->addWidget(myAddWidgets[ anItem ]);
1136 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
1139 emit CriterionChanged(theRow, aType);
1143 //=======================================================================
1144 // name : SMESHGUI_FilterTable::Update
1145 // Purpose : Update table
1146 //=======================================================================
1147 void SMESHGUI_FilterTable::Update()
1149 Table* aTable = myTables[ GetType() ];
1150 int aCurrRow = aTable->currentRow();
1151 int numRows = aTable->rowCount();
1152 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
1153 aTable->setCurrentCell(0, 0);
1154 updateAdditionalWidget();
1157 //=======================================================================
1158 // name : SMESHGUI_FilterTable::AddCriterion
1159 // Purpose : Add criterion with parameters
1160 //=======================================================================
1161 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
1162 const int theEntityType)
1164 int aType = theEntityType == -1 ? GetType() : theEntityType;
1165 Table* aTable = myTables[ aType ];
1166 addRow(aTable, aType);
1167 SetCriterion(aTable->rowCount() - 1, theCriterion);
1170 //=======================================================================
1171 // name : SMESHGUI_FilterTable::NumRows
1172 // Purpose : Get number of criterions of current type
1173 //=======================================================================
1174 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
1176 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
1179 //=======================================================================
1180 // name : SMESHGUI_FilterTable::Clear
1181 // Purpose : Clear current table
1182 //=======================================================================
1183 void SMESHGUI_FilterTable::Clear (const int theType)
1185 int aType = theType == -1 ? GetType() : theType;
1186 Table* aTable = myTables[ aType ];
1188 if (aTable->rowCount() == 0)
1191 while (aTable->rowCount() > 0)
1193 removeAdditionalWidget(aTable, 0);
1194 aTable->removeRow(0);
1200 //=======================================================================
1201 // name : SMESHGUI_FilterTable::onAddBtn
1202 // Purpose : SLOT. Called then "Add" button pressed.
1203 // Adds new string to table
1204 //=======================================================================
1205 void SMESHGUI_FilterTable::onAddBtn()
1207 int aType = GetType();
1208 addRow(myTables[ aType ], aType);
1213 //=======================================================================
1214 // name : SMESHGUI_FilterTable::onInsertBtn
1215 // Purpose : SLOT. Called then "Insert" button pressed.
1216 // Inserts new string before current one
1217 //=======================================================================
1218 void SMESHGUI_FilterTable::onInsertBtn()
1220 addRow(myTables[ GetType() ], GetType(), false);
1223 //=======================================================================
1224 // name : SMESHGUI_FilterTable::onRemoveBtn
1225 // Purpose : SLOT. Called then "Remove" button pressed.
1226 // Removes current string from table
1227 //=======================================================================
1228 void SMESHGUI_FilterTable::onRemoveBtn()
1230 Table* aTable = myTables[ GetType() ];
1232 if (aTable->rowCount() == 0)
1235 QList<QTableWidgetItem*> items = aTable->selectedItems();
1237 QList<int> aRows = aTable->selectedRows(); // already sorted
1241 removeAdditionalWidget(aTable, i);
1242 aTable->removeRow(i);
1245 // remove control of binary logical operation from last row
1246 if (aTable->rowCount() > 0)
1247 aTable->setEditable(false, aTable->rowCount() - 1, 4);
1252 //=======================================================================
1253 // name : SMESHGUI_FilterTable::updateAdditionalWidget
1254 // Purpose : Enable/Disable widget with additonal parameters
1255 //=======================================================================
1256 void SMESHGUI_FilterTable::updateAdditionalWidget()
1258 Table* aTable = myTables[ GetType() ];
1259 int aRow = aTable->currentRow();
1260 if (aRow < 0 || aRow >= aTable->rowCount())
1262 myWgStack->setEnabled(false);
1266 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1267 int aCriterion = GetCriterionType(aRow);
1268 bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
1269 aCriterion != SMESH::FT_RangeOfIds &&
1270 aCriterion != SMESH::FT_FreeEdges &&
1271 aCriterion != SMESH::FT_FreeFaces &&
1272 aCriterion != SMESH::FT_BadOrientedVolume;
1274 if (!myAddWidgets.contains(anItem))
1276 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1277 myWgStack->addWidget(myAddWidgets[ anItem ]);
1280 myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
1281 myWgStack->setEnabled(toEnable);
1284 //=======================================================================
1285 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1286 // Purpose : Remove widgets containing additional parameters from widget
1287 // stack and internal map
1288 //=======================================================================
1289 void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
1291 QTableWidgetItem* anItem = theTable->item(theRow, 0);
1292 if (myAddWidgets.contains(anItem))
1294 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1295 myAddWidgets[ anItem ]->setParent(0);
1296 delete myAddWidgets[ anItem ];
1297 myAddWidgets.remove(anItem);
1301 //=======================================================================
1302 // name : SMESHGUI_FilterTable::onClearBtn
1303 // Purpose : SLOT. Called then "Clear" button pressed.
1304 // Removes all strings from table
1305 //=======================================================================
1306 void SMESHGUI_FilterTable::onClearBtn()
1308 Table* aTable = myTables[ GetType() ];
1310 if (aTable->rowCount() == 0)
1313 while (aTable->rowCount() > 0)
1315 removeAdditionalWidget(aTable, 0);
1316 aTable->removeRow(0);
1322 //=======================================================================
1323 // name : SMESHGUI_FilterTable::onCurrentChanged()
1324 // Purpose : SLOT. Called when current cell changed
1325 //=======================================================================
1326 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1329 updateAdditionalWidget();
1330 emit CurrentChanged(theRow, theCol);
1333 //=======================================================================
1335 // Purpose : returns available geometry types of elements
1336 //=======================================================================
1337 static QList<int> geomTypes( const int theType )
1340 if ( theType == SMESH::NODE )
1341 typeIds.append( SMESH::Geom_POINT );
1342 if ( theType == SMESH::ALL || theType == SMESH::EDGE )
1343 typeIds.append( SMESH::Geom_EDGE );
1344 if ( theType == SMESH::ALL || theType == SMESH::FACE )
1346 typeIds.append( SMESH::Geom_TRIANGLE );
1347 typeIds.append( SMESH::Geom_QUADRANGLE );
1348 typeIds.append( SMESH::Geom_POLYGON );
1350 if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
1352 typeIds.append( SMESH::Geom_TETRA );
1353 typeIds.append( SMESH::Geom_PYRAMID );
1354 typeIds.append( SMESH::Geom_HEXA );
1355 typeIds.append( SMESH::Geom_PENTA );
1356 typeIds.append( SMESH::Geom_POLYHEDRA );
1361 //=======================================================================
1362 // name : SMESHGUI_FilterTable::onCriterionChanged()
1363 // Purpose : Provides reaction on change of criterion
1364 //=======================================================================
1365 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1367 int aType = entityType == -1 ? GetType() : entityType;
1368 Table* aTable = myTables[ aType ];
1369 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1371 int aCriterionType = GetCriterionType(row);
1372 QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
1373 bool isComboItem = aTable->item(row, 2)->type() == ComboItem::Type();
1375 if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
1376 (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) )
1378 bool isSignalsBlocked = aTable->signalsBlocked();
1379 aTable->blockSignals( true );
1380 aTable->removeCellWidget( row, 2 );
1381 aTable->setItem( row, 2, new QTableWidgetItem() );
1382 aTable->blockSignals( isSignalsBlocked );
1384 if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
1385 (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) )
1387 bool isSignalsBlocked = aTable->signalsBlocked();
1388 aTable->blockSignals( true );
1389 if ( aCriterionType == SMESH::FT_GroupColor )
1390 aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
1392 QList<int> typeIds = geomTypes( aType );
1393 QMap<int, QString> typeNames;
1394 QList<int>::const_iterator anIter = typeIds.begin();
1395 for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
1397 QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
1398 typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
1400 ComboItem* typeBox = new ComboItem( typeNames );
1401 aTable->setItem( row, 2, typeBox );
1403 aTable->blockSignals( isSignalsBlocked );
1406 if (aType == SMESH::NODE && aCriterionType == SMESH::FT_FreeNodes ||
1407 aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1408 aType == SMESH::FACE && (aCriterionType == SMESH::FT_FreeEdges ||
1409 aCriterionType == SMESH::FT_FreeFaces) ||
1410 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume ||
1411 aCriterionType == SMESH::FT_LinearOrQuadratic ||
1412 aCriterionType == SMESH::FT_GroupColor ||
1413 aCriterionType == SMESH::FT_ElemGeomType)
1415 bool isSignalsBlocked = aTable->signalsBlocked();
1416 aTable->blockSignals( true );
1418 if (aCompareItem->count() > 0)
1419 aCompareItem->clear();
1420 aTable->setEditable(false, row, 1);
1421 aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
1422 aCriterionType == SMESH::FT_ElemGeomType, row, 2);
1423 aTable->blockSignals( isSignalsBlocked );
1425 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1426 aCriterionType == SMESH::FT_BelongToGeom ||
1427 aCriterionType == SMESH::FT_BelongToPlane ||
1428 aCriterionType == SMESH::FT_BelongToCylinder ||
1429 aCriterionType == SMESH::FT_BelongToGenSurface ||
1430 aCriterionType == SMESH::FT_LyingOnGeom)
1432 QMap<int, QString> aMap;
1433 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
1434 aCompareItem->setItems(aMap);
1435 if (!aTable->isEditable(row, 2))
1436 aTable->setEditable(true, row, 1);
1437 if (!aTable->isEditable(row, 2))
1438 aTable->setEditable(true, row, 2);
1440 else if (aCriterionType == SMESH::FT_GroupColor ||
1441 aCriterionType == SMESH::FT_ElemGeomType)
1443 if (!aTable->isEditable(row, 2))
1444 aTable->setEditable(true, row, 2);
1448 if (aCompareItem->count() != 3)
1450 aCompareItem->setItems(getCompare());
1453 QString aText = aTable->text(row, 2);
1455 aText.toDouble(&isOk);
1456 aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
1457 if (!aTable->isEditable(row, 1))
1458 aTable->setEditable(true, row, 1);
1459 if (!aTable->isEditable(row, 2))
1460 aTable->setEditable(true, row, 2);
1463 updateAdditionalWidget();
1465 emit CriterionChanged(row, entityType);
1468 //=======================================================================
1469 // name : SMESHGUI_FilterTable::onCriterionChanged()
1470 // Purpose : SLOT. Called then contents of table changed
1471 // Provides reaction on change of criterion
1472 //=======================================================================
1473 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1475 onCriterionChanged(row, col, -1);
1478 //=======================================================================
1479 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1480 // Purpose : Get first selected row
1481 //=======================================================================
1482 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1484 Table* aTable = myTables[ GetType() ];
1486 QList<int> selRows = aTable->selectedRows(); // already sorted
1487 int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
1489 return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
1492 //=======================================================================
1493 // name : SMESHGUI_FilterTable::addRow
1494 // Purpose : Add row at the end of table
1495 //=======================================================================
1496 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1499 int aSelectedRow = getFirstSelectedRow();
1500 int aCurrCol = theTable->currentColumn();
1503 if (toTheEnd || aSelectedRow == -1)
1505 theTable->insertRows(theTable->rowCount());
1506 aCurrRow = theTable->rowCount() - 1;
1510 theTable->insertRows(aSelectedRow);
1511 aCurrRow = aSelectedRow;
1515 // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
1516 bool isSignalsBlocked = theTable->signalsBlocked();
1517 theTable->blockSignals( true );
1520 theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
1523 theTable->setItem(aCurrRow, 1, getCompareItem());
1526 theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
1528 // Logical operation NOT
1529 theTable->setItem(aCurrRow, 3, getUnaryItem());
1531 // Logical operation AND / OR
1532 theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
1534 theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
1536 theTable->blockSignals( isSignalsBlocked );
1538 // Logical binary operation for previous value
1539 int anAddBinOpStr = -1;
1540 if (aCurrRow == theTable->rowCount() - 1)
1541 anAddBinOpStr = aCurrRow - 1;
1542 else if (aCurrRow >= 0 )
1543 anAddBinOpStr = aCurrRow;
1545 if (theTable->item(aCurrRow, 4) == 0 ||
1546 theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
1548 if (anAddBinOpStr >= 0 &&
1549 (theTable->item(anAddBinOpStr, 4) == 0 ||
1550 theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
1551 theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
1554 theTable->setEditable(false, theTable->rowCount() - 1, 4);
1556 if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
1557 aCurrCol >=0 && aCurrCol < theTable->rowCount())
1558 theTable->setCurrentCell(aCurrRow, aCurrCol);
1560 onCriterionChanged(aCurrRow, 0);
1565 //=======================================================================
1566 // name : SMESHGUI_FilterTable::getCriterionItem
1567 // Purpose : Get combo table item for criteria of specified type
1568 //=======================================================================
1569 QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
1571 return new ComboItem(getCriteria(theType));
1574 //=======================================================================
1575 // name : SMESHGUI_FilterTable::getCompareItem
1576 // Purpose : Get combo table item for operation of comparision
1577 //=======================================================================
1578 QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
1580 return new ComboItem(getCompare());
1583 //=======================================================================
1584 // name : SMESHGUI_FilterTable::getBinaryItem
1586 //=======================================================================
1587 QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
1589 static QMap<int, QString> aMap;
1592 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1593 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1596 return new ComboItem(aMap);
1599 //=======================================================================
1600 // name : SMESHGUI_FilterTable::getUnaryItem
1601 // Purpose : Get check table item
1602 //=======================================================================
1603 QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
1605 return new CheckItem(tr("NOT"));
1608 //=======================================================================
1609 // name : SMESHGUI_FilterTable::getSupportedTypes
1610 // Purpose : Get all supported type
1611 //=======================================================================
1612 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1614 static QMap<int, QString> aTypes;
1615 if (aTypes.isEmpty())
1617 aTypes[ SMESH::NODE ] = tr("NODES");
1618 aTypes[ SMESH::EDGE ] = tr("EDGES");
1619 aTypes[ SMESH::FACE ] = tr("FACES");
1620 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1621 aTypes[ SMESH::ALL ] = tr("ELEMENTS");
1627 //=======================================================================
1628 // name : SMESHGUI_FilterTable::getCriteria
1629 // Purpose : Get criteria for specified type
1630 //=======================================================================
1631 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1633 if (theType == SMESH::NODE)
1635 static QMap<int, QString> aCriteria;
1636 if (aCriteria.isEmpty())
1638 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1639 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1640 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1641 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1642 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1643 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1644 aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
1645 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1649 else if (theType == SMESH::EDGE)
1651 static QMap<int, QString> aCriteria;
1652 if (aCriteria.isEmpty())
1654 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1655 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
1656 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
1657 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1658 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1659 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1660 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1661 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1662 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1663 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1664 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1665 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1669 else if (theType == SMESH::FACE)
1671 static QMap<int, QString> aCriteria;
1672 if (aCriteria.isEmpty())
1674 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
1675 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
1676 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
1677 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
1678 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
1679 aCriteria[ SMESH::FT_Area ] = tr("AREA");
1680 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
1681 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1682 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1683 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1684 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1685 aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
1686 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1687 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
1688 aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
1689 aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
1690 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1691 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1692 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1696 else if (theType == SMESH::VOLUME)
1698 static QMap<int, QString> aCriteria;
1699 if (aCriteria.isEmpty())
1701 aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
1702 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1703 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1704 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1705 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
1706 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
1707 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1708 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1709 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1715 static QMap<int, QString> aCriteria;
1716 if (aCriteria.isEmpty())
1718 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1719 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1720 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1721 aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
1722 aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
1723 aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
1731 //=======================================================================
1732 // name : SMESHGUI_FilterTable::getCompare
1733 // Purpose : Get operation of comparison
1734 //=======================================================================
1735 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1737 static QMap<int, QString> aMap;
1741 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
1742 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
1743 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
1749 //=======================================================================
1750 // name : SMESHGUI_FilterTable::createTable
1751 // Purpose : Create table
1752 //=======================================================================
1753 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
1757 Table* aTable= new Table(0, 6, theParent);
1759 QHeaderView* aHeaders = aTable->horizontalHeader();
1761 QFontMetrics aMetrics(aHeaders->font());
1763 // append spaces to the header of criteria in order to
1764 // provide visibility of criterion inside comboboxes
1765 static int aMaxLenCr = 0;
1769 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1770 QMap<int, QString>::const_iterator anIter;
1771 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
1772 aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
1775 static int aLenCr = qAbs( aMaxLenCr -
1776 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
1779 aCrStr.fill(' ', aLenCr);
1781 aCoStr.fill(' ', 10);
1783 QStringList aHeaderLabels;
1784 aHeaderLabels.append( tr("CRITERION") + aCrStr );
1785 aHeaderLabels.append( tr("COMPARE") + aCoStr );
1786 aHeaderLabels.append( tr("THRESHOLD_VALUE") );
1787 aHeaderLabels.append( tr("UNARY") );
1788 aHeaderLabels.append( tr("BINARY") + " " );
1789 aHeaderLabels.append( tr("ID") );
1790 aTable->setHorizontalHeaderLabels( aHeaderLabels );
1792 // set geometry of the table
1793 for (int i = 0; i <= 4; i++)
1794 aTable->resizeColumnToContents(i);
1796 // set the ID column invisible
1797 aTable->hideColumn( 5 );
1799 aTable->updateGeometry();
1800 QSize aSize = aTable->sizeHint();
1801 int aWidth = aSize.width();
1802 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
1803 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
1805 connect(aTable, SIGNAL(cellChanged(int, int)),
1806 this, SLOT(onCriterionChanged(int, int)));
1808 connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
1809 this, SLOT(onCurrentChanged(int, int)));
1814 //=======================================================================
1815 // name : SMESHGUI_FilterTable::updateBtnState
1816 // Purpose : Update button state
1817 //=======================================================================
1818 void SMESHGUI_FilterTable::updateBtnState()
1820 myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1821 myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
1824 //=======================================================================
1825 // name : SMESHGUI_FilterTable::SetEditable
1826 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1827 //=======================================================================
1828 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
1830 TableMap::iterator anIter;
1831 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1833 anIter.value()->setReadOnly(!isEditable);
1835 // Set Flags for CheckItems directly IPAL 19974
1836 Table* aTable = anIter.value();
1837 for (int i = 0, n = aTable->rowCount(); i < n; i++)
1838 for (int j = 0, m = aTable->columnCount(); j < m; j++)
1840 QTableWidgetItem* anItem = aTable->item(i, j);
1841 if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
1842 Qt::ItemFlags f = anItem->flags();
1843 if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
1844 else f = f | Qt::ItemIsUserCheckable;
1845 anItem->setFlags( f );
1853 myInsertBtn->show();
1854 myRemoveBtn->show();
1860 myInsertBtn->hide();
1861 myRemoveBtn->hide();
1866 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1867 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1868 anIter2.value()->SetEditable(isEditable);
1871 //=======================================================================
1872 // name : SMESHGUI_FilterTable::SetEnabled
1873 // Purpose : Enable/Disable table. Switching type of elements already enabled
1874 //=======================================================================
1875 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
1877 myAddBtn->setEnabled(isEnabled);
1878 myInsertBtn->setEnabled(isEnabled);
1879 myRemoveBtn->setEnabled(isEnabled);
1880 myClearBtn->setEnabled(isEnabled);
1885 QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
1886 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1887 anIter2.value()->setEnabled(isEnabled);
1890 //=======================================================================
1891 // name : SMESHGUI_FilterTable::IsEditable
1892 // Purpose : Verify whether table is editable
1893 //=======================================================================
1894 bool SMESHGUI_FilterTable::IsEditable() const
1896 return !myTables[ GetType() ]->isReadOnly();
1899 //=======================================================================
1900 // name : SMESHGUI_FilterTable::SetLibsEnabled
1901 // Purpose : Show/hide buttons for work with libraries
1902 //=======================================================================
1903 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
1907 myCopyFromBtn->show();
1912 myCopyFromBtn->hide();
1917 //=======================================================================
1918 // name : SMESHGUI_FilterTable::onCopyFromBtn
1919 // Purpose : SLOT. Called the "Copy from ..." button clicked
1920 // Display filter library dialog
1921 //=======================================================================
1922 void SMESHGUI_FilterTable::onCopyFromBtn()
1925 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1926 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1928 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1930 if (myLibDlg->exec() == QDialog::Accepted)
1932 Copy(myLibDlg->GetTable());
1937 //=======================================================================
1938 // name : SMESHGUI_FilterTable::onAddToBtn
1939 // Purpose : SLOT. Called the "Add to ..." button clicked
1940 // Display filter library dialog
1941 //=======================================================================
1942 void SMESHGUI_FilterTable::onAddToBtn()
1947 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1948 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1950 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1952 myLibDlg->SetTable(this);
1957 //=======================================================================
1958 // name : SMESHGUI_FilterTable::Copy
1959 // Purpose : Initialise table with values of other table
1960 //=======================================================================
1961 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
1965 for (int i = 0, n = theTable->NumRows(); i < n; i++)
1967 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1968 theTable->GetCriterion(i, aCriterion);
1969 AddCriterion(aCriterion);
1973 //=======================================================================
1974 // name : SMESHGUI_FilterTable::CurrentCell
1975 // Purpose : Returns current cell
1976 //=======================================================================
1977 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
1979 theRow = myTables[ GetType() ]->currentRow();
1980 theCol = myTables[ GetType() ]->currentColumn();
1981 return theRow >= 0 && theCol >= 0;
1984 //=======================================================================
1985 // name : SMESHGUI_FilterTable::SetText
1986 // Purpose : Set text and internal value in cell of threshold value
1987 //=======================================================================
1988 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
1989 const QString& theText,
1990 const int theEntityType)
1992 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1993 aTable->item( theRow, 2 )->setText(theText);
1996 //=======================================================================
1997 // name : SMESHGUI_FilterTable::SetText
1998 // Purpose : Get text and internal value from cell of threshold value
1999 //=======================================================================
2000 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
2002 const int theEntityType)
2004 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2005 QTableWidgetItem* anItem = aTable->item(theRow, 2);
2008 theText = anItem->text();
2015 //=======================================================================
2016 // name : SMESHGUI_FilterTable::SetID
2017 // Purpose : Set text and internal value in cell of ID value
2018 //=======================================================================
2019 void SMESHGUI_FilterTable::SetID( const int theRow,
2020 const QString& theText,
2021 const int theEntityType )
2023 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2024 aTable->item( theRow, 5 )->setText( theText );
2027 //=======================================================================
2028 // name : SMESHGUI_FilterTable::GetID
2029 // Purpose : Get text and internal value from cell of ID value
2030 //=======================================================================
2031 bool SMESHGUI_FilterTable::GetID( const int theRow,
2033 const int theEntityType )
2035 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
2036 QTableWidgetItem* anItem = aTable->item( theRow, 5 );
2039 theText = anItem->text();
2047 Class : SMESHGUI_FilterDlg
2048 Description : Dialog to specify filters for VTK viewer
2052 //=======================================================================
2053 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2054 // Purpose : Constructor
2055 //=======================================================================
2056 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2057 const QList<int>& theTypes )
2058 : QDialog( SMESH::GetDesktop( theModule ) ),
2059 mySMESHGUI( theModule ),
2060 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2061 myInitSourceWgOnApply( true )
2063 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2064 mySelector = aViewWindow->GetSelector();
2066 construct(theTypes);
2069 //=======================================================================
2070 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
2071 // Purpose : Constructor
2072 //=======================================================================
2073 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
2075 : QDialog( SMESH::GetDesktop( theModule ) ),
2076 mySMESHGUI( theModule ),
2077 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
2078 myInitSourceWgOnApply( true )
2080 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2081 mySelector = aViewWindow->GetSelector();
2083 aTypes.append(theType);
2087 //=======================================================================
2088 // name : SMESHGUI_FilterDlg::construct
2089 // Purpose : Construct dialog (called by constructor)
2090 //=======================================================================
2091 void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
2096 //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
2097 setWindowTitle(tr("CAPTION"));
2099 QVBoxLayout* aDlgLay = new QVBoxLayout (this);
2100 aDlgLay->setMargin(MARGIN);
2101 aDlgLay->setSpacing(SPACING);
2103 myMainFrame = createMainFrame (this);
2104 QWidget* aBtnFrame = createButtonFrame(this);
2106 aDlgLay->addWidget(myMainFrame);
2107 aDlgLay->addWidget(aBtnFrame);
2109 aDlgLay->setStretchFactor(myMainFrame, 1);
2111 myHelpFileName = "selection_filter_library_page.html";
2116 //=======================================================================
2117 // name : SMESHGUI_FilterDlg::createMainFrame
2118 // Purpose : Create frame containing dialog's input fields
2119 //=======================================================================
2120 QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
2122 QWidget* aMainFrame = new QWidget(theParent);
2123 QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
2124 aMainLay->setMargin(0);
2125 aMainLay->setSpacing(SPACING);
2129 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
2130 myTable->SetLibsEnabled(true);
2132 QGroupBox* aGrp = myTable->GetTableGrp();
2133 QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
2134 int rows = aLay->rowCount();
2135 int cols = aLay->columnCount();
2137 QFrame* aLine = new QFrame(aGrp);
2138 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
2139 aLay->addWidget(aLine, rows++, 0, 1, cols);
2141 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
2142 mySetInViewer->setChecked(true);
2143 aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
2146 QWidget* aSourceGrp = createSourceGroup(aMainFrame);
2148 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
2149 SLOT(onCriterionChanged(const int, const int)));
2151 connect(myTable, SIGNAL(CurrentChanged(int, int)),
2152 SLOT(onCurrentChanged(int, int)));
2154 aMainLay->addWidget(myTable);
2155 aMainLay->addWidget(aSourceGrp);
2160 //=======================================================================
2161 // name : SMESHGUI_FilterDlg::createSourceFrame
2162 // Purpose : Create frame containing source radio button
2163 //=======================================================================
2164 QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
2166 QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
2167 QHBoxLayout* aLay = new QHBoxLayout(aBox);
2168 aLay->setMargin(MARGIN);
2169 aLay->setSpacing(SPACING);
2171 mySourceGrp = new QButtonGroup(theParent);
2173 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
2174 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
2175 QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
2177 aLay->addWidget(aMeshBtn);
2178 aLay->addWidget(aSelBtn);
2179 aLay->addWidget(aDlgBtn);
2181 mySourceGrp->addButton(aMeshBtn, Mesh);
2182 mySourceGrp->addButton(aSelBtn, Selection);
2183 mySourceGrp->addButton(aDlgBtn, Dialog);
2185 aSelBtn->setChecked(true);
2190 //=======================================================================
2191 // name : SMESHGUI_FilterDlg::updateMainButtons
2192 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
2193 //=======================================================================
2194 void SMESHGUI_FilterDlg::updateMainButtons()
2196 if (myTypes.count() == 1)
2198 myButtons[ BTN_Cancel ]->show();
2199 myButtons[ BTN_Apply ]->hide();
2200 myButtons[ BTN_Close ]->hide();
2204 myButtons[ BTN_Cancel ]->hide();
2205 myButtons[ BTN_Apply ]->show();
2206 myButtons[ BTN_Close ]->show();
2209 // updateGeometry();
2212 //=======================================================================
2213 // name : SMESHGUI_FilterDlg::createButtonFrame
2214 // Purpose : Create frame containing buttons
2215 //=======================================================================
2216 QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
2218 QGroupBox* aGrp = new QGroupBox(theParent);
2219 QHBoxLayout* aLay = new QHBoxLayout(aGrp);
2220 aLay->setMargin(MARGIN);
2221 aLay->setSpacing(SPACING);
2223 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
2224 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
2225 myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
2226 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
2227 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
2229 aLay->addWidget(myButtons[ BTN_OK ]);
2230 aLay->addSpacing(10);
2231 aLay->addWidget(myButtons[ BTN_Apply ]);
2232 aLay->addSpacing(10);
2234 aLay->addWidget(myButtons[ BTN_Cancel ]);
2235 aLay->addWidget(myButtons[ BTN_Close ]);
2236 aLay->addWidget(myButtons[ BTN_Help ]);
2238 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
2239 connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
2240 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
2241 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
2242 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
2244 updateMainButtons();
2249 //=======================================================================
2250 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
2251 // Purpose : Destructor
2252 //=======================================================================
2253 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
2257 //=======================================================================
2258 // name : SMESHGUI_FilterDlg::Init
2259 // Purpose : Init dialog fields, connect signals and slots, show dialog
2260 //=======================================================================
2261 void SMESHGUI_FilterDlg::Init (const int type)
2264 aTypes.append(type);
2268 //=======================================================================
2269 // name : SMESHGUI_FilterDlg::Init
2270 // Purpose : Init dialog fields, connect signals and slots, show dialog
2271 //=======================================================================
2272 void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
2276 myMesh = SMESH::SMESH_Mesh::_nil();
2278 myIsSelectionChanged = false;
2280 myTable->Init(theTypes);
2283 if (theTypes.count() == 1)
2285 int aType = theTypes.first();
2286 if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
2287 else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
2288 else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
2289 else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
2290 else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
2293 setWindowTitle(tr("TLT"));
2295 qApp->processEvents();
2300 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2302 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
2303 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
2305 updateMainButtons();
2308 // Initialise filter table with values of previous filter
2309 QList<int>::const_iterator anIter;
2310 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
2312 myTable->Clear(*anIter);
2313 if (!myFilter[ *anIter ]->_is_nil())
2315 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2316 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
2318 for (int i = 0, n = aCriteria->length(); i < n; i++)
2319 myTable->AddCriterion(aCriteria[ i ], *anIter);
2324 if (myInsertState.contains(theTypes.first()))
2325 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
2327 mySetInViewer->setChecked(true);
2329 mySourceGrp->button(myApplyToState.contains(theTypes.first()) ?
2330 myApplyToState[ theTypes.first() ] :
2331 Selection)->setChecked(true);
2334 //=======================================================================
2335 // name : SMESHGUI_FilterDlg::onOk
2336 // Purpose : SLOT called when "Ok" button pressed.
2337 // Assign filters VTK viewer and close dialog
2338 //=======================================================================
2339 void SMESHGUI_FilterDlg::onOk()
2343 mySelectionMgr->clearFilters();
2344 disconnect(mySMESHGUI, 0, this, 0);
2345 disconnect(mySelectionMgr, 0, this, 0);
2346 mySMESHGUI->ResetState();
2352 //=======================================================================
2353 // name : SMESHGUI_FilterDlg::onClose
2354 // Purpose : SLOT called when "Close" button pressed. Close dialog
2355 //=======================================================================
2356 void SMESHGUI_FilterDlg::onClose()
2358 // Restore previously selected object
2361 SALOME_ListIO aList;
2362 mySelectionMgr->clearFilters();
2363 mySelectionMgr->clearSelected();
2364 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
2365 for ( ; anIter.More(); anIter.Next())
2367 aList.Append(anIter.Key());
2369 TColStd_MapOfInteger aResMap;
2370 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
2371 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
2372 aResMap.Add(anIndMap(i));
2374 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
2375 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2376 aViewWindow->highlight( anIter.Key(), true, true );
2378 mySelectionMgr->setSelectedObjects(aList, false);
2381 disconnect(mySMESHGUI, 0, this, 0);
2382 disconnect(mySelectionMgr, 0, this, 0);
2383 mySMESHGUI->ResetState();
2388 //=================================================================================
2389 // function : onHelp()
2391 //=================================================================================
2392 void SMESHGUI_FilterDlg::onHelp()
2394 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
2396 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
2400 platform = "winapplication";
2402 platform = "application";
2404 SUIT_MessageBox::warning(this, tr("WRN_WARNING"),
2405 tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
2406 arg(app->resourceMgr()->stringValue("ExternalBrowser",
2408 arg(myHelpFileName));
2412 //=======================================================================
2413 // name : SMESHGUI_FilterDlg::onDeactivate
2414 // Purpose : SLOT called when dialog must be deativated
2415 //=======================================================================
2416 void SMESHGUI_FilterDlg::onDeactivate()
2421 //=======================================================================
2422 // name : SMESHGUI_FilterDlg::enterEvent
2423 // Purpose : Event filter
2424 //=======================================================================
2425 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
2427 // mySMESHGUI->EmitSignalDeactivateDialog();
2428 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
2429 mySMESHGUI->ResetState();
2433 //=======================================================================
2434 // name : closeEvent()
2436 //=======================================================================
2437 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2442 //=======================================================================
2443 // name : SMESHGUI_FilterDlg::getIdsFromWg
2444 // Purpose : Retrieve list of ids from given widget
2445 //=======================================================================
2446 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QList<int>& theRes) const
2452 if (theWg->inherits("QListWidget"))
2454 const QListWidget* aListBox = qobject_cast<const QListWidget*>( theWg );
2456 for (int i = 0, n = aListBox->count(); i < n; i++)
2458 int anId = aListBox->item(i)->text().toInt(&b);
2460 theRes.append(anId);
2463 else if (theWg->inherits("QLineEdit"))
2465 const QLineEdit* aLineEdit = qobject_cast<const QLineEdit*>( theWg );
2466 QString aStr = aLineEdit->text();
2467 QRegExp aRegExp("(\\d+)");
2472 aPos = aRegExp.indexIn(aStr, aPos);
2475 int anId = aRegExp.cap(1).toInt(&b);
2477 theRes.append(anId);
2478 aPos += aRegExp.matchedLength();
2484 //=======================================================================
2485 // name : SMESHGUI_FilterDlg::getSelMode
2486 // Purpose : Get selection mode of specified type
2487 //=======================================================================
2488 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2492 case SMESH::NODE : return NodeSelection;
2493 case SMESH::EDGE : return EdgeSelection;
2494 case SMESH::FACE : return FaceSelection;
2495 case SMESH::VOLUME : return VolumeSelection;
2496 case SMESH::ALL : return CellSelection;
2497 default : return ActorSelection;
2502 //=======================================================================
2503 // name : SMESHGUI_FilterDlg::setIdsToWg
2504 // Purpose : Insert identifiers in specified widgets
2505 //=======================================================================
2506 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QList<int>& theIds)
2511 if (theWg->inherits("QListWidget"))
2513 QListWidget* aListBox = qobject_cast<QListWidget*>( theWg );
2516 QStringList aStrList;
2517 QList<int>::const_iterator anIter;
2518 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter)
2519 aStrList.append(QString("%1").arg(*anIter));
2521 aListBox->addItems(aStrList);
2523 else if (theWg->inherits("QLineEdit"))
2525 QLineEdit* aLineEdit = qobject_cast<QLineEdit*>( theWg );
2527 QList<int>::const_iterator anIter;
2529 for (anIter = theIds.begin(); anIter != theIds.end(); ++ anIter)
2530 aStr += QString("%1 ").arg(*anIter);
2532 if (!aStr.isEmpty())
2533 aStr.remove(aStr.length() - 1, 1);
2535 aLineEdit->setText(aStr);
2539 //=======================================================================
2540 // name : SMESHGUI_FilterDlg::isValid
2541 // Purpose : Verify validity of input data
2542 //=======================================================================
2543 bool SMESHGUI_FilterDlg::isValid() const
2545 if (!myTable->IsValid())
2548 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2550 int aType = myTable->GetCriterionType(i);
2551 if (aType == SMESH::FT_BelongToGeom ||
2552 aType == SMESH::FT_BelongToPlane ||
2553 aType == SMESH::FT_BelongToCylinder ||
2554 aType == SMESH::FT_BelongToGenSurface ||
2555 aType == SMESH::FT_LyingOnGeom) {
2557 myTable->GetThreshold(i, aName);
2559 std::vector<_PTR(SObject)> aList =
2560 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.toLatin1().constData(), "GEOM");
2561 if (aList.size() == 0) {
2562 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2563 tr("BAD_SHAPE_NAME").arg(aName));
2567 if (aType == SMESH::FT_BelongToCylinder ||
2568 aType == SMESH::FT_BelongToPlane ||
2569 aType == SMESH::FT_BelongToGenSurface ) {
2570 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2571 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2572 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2573 if (!aGeomObj->_is_nil()) {
2575 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2577 aFace.ShapeType() != TopAbs_FACE) {
2578 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2579 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2583 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2584 if (aSurf.IsNull()) {
2585 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2586 tr("SHAPE_IS_NOT_A_FACE").arg(aName));
2590 if (aType == SMESH::FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2591 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2592 tr("SHAPE_IS_NOT_A_PLANE").arg(aName));
2596 if (aType == SMESH::FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2597 SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2598 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName));
2609 //=======================================================================
2610 // name : SMESHGUI_FilterDlg::SetSourceWg
2611 // Purpose : Set widget of parent dialog containing idsto be filtered if
2612 // user select corresponding source radio button
2613 //=======================================================================
2614 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg,
2615 const bool initOnApply)
2618 myInitSourceWgOnApply = initOnApply;
2621 //=======================================================================
2622 // name : SMESHGUI_FilterDlg::SetGroupIds
2623 // Purpose : Set mesh
2624 //=======================================================================
2625 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2628 const bool isEnable = !(myMesh->_is_nil());
2629 myButtons[BTN_OK]->setEnabled(isEnable);
2630 myButtons[BTN_Apply]->setEnabled(isEnable);
2633 //=======================================================================
2634 // name : SMESHGUI_FilterDlg::SetSelection
2635 // Purpose : Get filtered ids
2636 //=======================================================================
2637 void SMESHGUI_FilterDlg::SetSelection()
2640 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
2642 if (mySelectionMgr) {
2644 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
2645 SALOME_ListIteratorOfListIO anIter (anObjs);
2646 for ( ; anIter.More(); anIter.Next()) {
2647 TColStd_IndexedMapOfInteger aMap;
2648 mySelector->GetIndex(anIter.Value(), aMap);
2649 myIObjects.Bind(anIter.Value(), aMap);
2652 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2660 //=======================================================================
2661 // name : SMESHGUI_FilterDlg::onApply
2662 // Purpose : SLOT called when "Apply" button pressed.
2663 // Assign filters to VTK viewer
2664 //=======================================================================
2665 bool SMESHGUI_FilterDlg::onApply()
2671 int aCurrType = myTable->GetType();
2673 if (!createFilter(aCurrType))
2676 insertFilterInViewer();
2678 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
2679 QList<int> aResultIds;
2680 filterSource(aCurrType, aResultIds);
2682 selectInViewer(aCurrType, aResultIds);
2686 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2687 myApplyToState[ aCurrType ] = mySourceGrp->checkedId();
2689 catch(const SALOME::SALOME_Exception& S_ex)
2691 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2700 //=======================================================================
2701 // name : SMESHGUI_FilterDlg::createFilter
2702 // Purpose : Create predicate for given type
2703 //=======================================================================
2704 bool SMESHGUI_FilterDlg::createFilter (const int theType)
2706 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2707 if (aFilterMgr->_is_nil())
2710 int n = myTable->NumRows();
2712 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2713 aCriteria->length(n);
2715 long aPrecision = -1;
2716 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2718 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
2719 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
2721 for (CORBA::ULong i = 0; i < n; i++) {
2722 SMESH::Filter::Criterion aCriterion = createCriterion();
2723 myTable->GetCriterion(i, aCriterion);
2724 aCriterion.Precision = aPrecision;
2725 aCriteria[ i ] = aCriterion;
2728 myFilter[ theType ] = aFilterMgr->CreateFilter();
2729 myFilter[ theType ]->SetCriteria(aCriteria.inout());
2734 //=======================================================================
2735 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2736 // Purpose : Insert filter in viewer
2737 //=======================================================================
2738 void SMESHGUI_FilterDlg::insertFilterInViewer()
2740 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
2741 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2743 if (myFilter[ myTable->GetType() ]->_is_nil() ||
2744 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2745 !mySetInViewer->isChecked()) {
2746 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
2749 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2750 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
2751 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
2752 SMESH::SetFilter(aFilter, aSelector);
2757 //=======================================================================
2758 // name : SMESHGUI_FilterDlg::filterSource
2759 // Purpose : Filter source ids
2760 //=======================================================================
2761 void SMESHGUI_FilterDlg::filterSource (const int theType,
2762 QList<int>& theResIds)
2765 if (myFilter[ theType ]->_is_nil())
2768 int aSourceId = mySourceGrp->checkedId();
2770 if (aSourceId == Mesh)
2772 if (myMesh->_is_nil())
2774 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
2775 for (int i = 0, n = anIds->length(); i < n; i++)
2776 theResIds.append(anIds[ i ]);
2778 else if (aSourceId == Selection)
2780 filterSelectionSource(theType, theResIds);
2782 else if (aSourceId == Dialog)
2784 // retrieve ids from dialog
2785 QList<int> aDialogIds;
2786 getIdsFromWg(mySourceWg, aDialogIds);
2788 if (myMesh->_is_nil())
2790 theResIds = aDialogIds;
2795 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2796 aPred->SetMesh(myMesh);
2797 QList<int>::const_iterator anIter;
2798 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
2799 if (aPred->IsSatisfy(*anIter))
2800 theResIds.append(*anIter);
2802 // set ids to the dialog
2803 if (myInitSourceWgOnApply || aSourceId == Dialog)
2804 setIdsToWg(mySourceWg, theResIds);
2807 //=======================================================================
2808 // name : SMESHGUI_FilterDlg::filterSelectionSource
2809 // Purpose : Filter source selection
2810 //=======================================================================
2811 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
2812 QList<int>& theResIds)
2815 if (myMesh->_is_nil() || mySelectionMgr == 0)
2818 // Create map of entities to be filtered
2819 TColStd_MapOfInteger aToBeFiltered;
2820 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
2822 for ( ; anIter.More(); anIter.Next())
2825 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
2826 if (!aSubMesh->_is_nil())
2828 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
2830 SMESH::long_array_var anIds =
2831 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2832 for (int i = 0, n = anIds->length(); i < n; i++)
2833 aToBeFiltered.Add(anIds[ i ]);
2838 SMESH::SMESH_GroupBase_var aGroup =
2839 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
2840 if (!aGroup->_is_nil())
2842 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
2844 SMESH::long_array_var anIds = aGroup->GetListOfID();
2845 for (int i = 0, n = anIds->length(); i < n; i++)
2846 aToBeFiltered.Add(anIds[ i ]);
2851 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
2852 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
2854 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2856 if (aSelMap.Extent() > 0)
2858 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
2860 for (int i = 1; i <= aSelMap.Extent(); i++)
2861 aToBeFiltered.Add(aSelMap(i));
2868 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2869 aPred->SetMesh(myMesh);
2870 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
2871 for ( ; aResIter.More(); aResIter.Next())
2872 if (aPred->IsSatisfy(aResIter.Key()))
2873 theResIds.append(aResIter.Key());
2876 //=======================================================================
2877 // name : SMESHGUI_FilterDlg::selectInViewer
2878 // Purpose : Select given entities in viewer
2879 //=======================================================================
2880 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& theIds)
2882 if (mySelectionMgr == 0 || myMesh->_is_nil())
2885 mySelectionMgr->clearFilters();
2887 // Set new selection mode if necessary
2888 Selection_Mode aSelMode = getSelMode(theType);
2889 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2890 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
2891 mySelectionMgr->clearSelected();
2892 mySelectionMgr->clearFilters();
2893 if (aSelMode == NodeSelection)
2894 SMESH::SetPointRepresentation(true);
2895 aViewWindow->SetSelectionMode(aSelMode);
2899 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2900 if (!anActor || !anActor->hasIO())
2903 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2904 //mySelectionMgr->clearSelected();
2905 //mySelectionMgr->AddIObject(anIO, false);
2906 SALOME_ListIO aList;
2908 mySelectionMgr->setSelectedObjects(aList, false);
2910 // Remove filter corresponding to the current type from viewer
2911 int aType = myTable->GetType();
2912 int aFilterId = SMESH::UnknownFilter;
2913 if (aType == SMESH::EDGE ) aFilterId = SMESH::EdgeFilter;
2914 else if (aType == SMESH::FACE ) aFilterId = SMESH::FaceFilter;
2915 else if (aType == SMESH::VOLUME) aFilterId = SMESH::VolumeFilter;
2916 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
2917 SMESH::RemoveFilter(aFilterId);
2920 TColStd_MapOfInteger aMap;
2921 QList<int>::const_iterator anIter;
2922 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
2926 // Set new selection
2927 mySelector->AddOrRemoveIndex(anIO, aMap, false);
2928 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2929 aViewWindow->highlight( anIO, true, true );
2931 // insert previously stored filter in viewer if necessary
2932 if (!aFilter.IsNull())
2933 SMESH::SetFilter(aFilter);
2936 //=======================================================================
2937 // name : SMESHGUI_FilterDlg::createCriterion
2938 // Purpose : Create criterion structure with default values
2939 //=======================================================================
2940 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2942 SMESH::Filter::Criterion aCriterion;
2944 aCriterion.Type = SMESH::FT_Undefined;
2945 aCriterion.Compare = SMESH::FT_Undefined;
2946 aCriterion.Threshold = 0;
2947 aCriterion.UnaryOp = SMESH::FT_Undefined;
2948 aCriterion.BinaryOp = SMESH::FT_Undefined;
2949 aCriterion.ThresholdStr = "";
2950 aCriterion.ThresholdID = "";
2951 aCriterion.TypeOfElement = SMESH::ALL;
2956 //=======================================================================
2957 // name : SMESHGUI_FilterDlg::onSelectionDone
2958 // Purpose : SLOT called when selection changed.
2959 // If current cell corresponds to the threshold value of
2960 // BelongToGeom criterion name of selected object is set in this cell
2961 //=======================================================================
2962 void SMESHGUI_FilterDlg::onSelectionDone()
2965 const SALOME_ListIO& aList = mySelector->StoredIObjects();
2967 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
2968 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
2969 if ( !(myMesh->_is_nil()) ) {
2970 myButtons[BTN_OK]->setEnabled(true);
2971 myButtons[BTN_Apply]->setEnabled(true);
2975 int aCriterionType = myTable->GetCriterionType(aRow);
2976 if (aList.Extent() != 1 ||
2977 !myTable->CurrentCell(aRow, aCol) ||
2978 aCriterionType != SMESH::FT_BelongToGeom &&
2979 aCriterionType != SMESH::FT_BelongToPlane &&
2980 aCriterionType != SMESH::FT_BelongToCylinder &&
2981 aCriterionType != SMESH::FT_BelongToGenSurface &&
2982 aCriterionType != SMESH::FT_LyingOnGeom)
2985 Handle(SALOME_InteractiveObject) anIO = aList.First();
2986 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
2987 if (!anObj->_is_nil())
2989 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
2990 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
2991 myTable->SetID(aRow, anIO->getEntry());
2996 //=======================================================================
2997 // name : SMESHGUI_FilterDlg::onCriterionChanged
2998 // Purpose : SLOT called when cretarion of current row changed. Update selection
2999 //=======================================================================
3000 void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
3005 //=======================================================================
3006 // name : SMESHGUI_FilterDlg::onCurrentChanged
3007 // Purpose : SLOT called when current row changed. Update selection
3008 //=======================================================================
3009 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
3014 //=======================================================================
3015 // name : SMESHGUI_FilterDlg::updateSelection
3016 // Purpose : UpdateSelection in accordance with current row
3017 //=======================================================================
3018 void SMESHGUI_FilterDlg::updateSelection()
3020 if (mySelectionMgr == 0)
3023 TColStd_MapOfInteger allTypes;
3024 for( int i=0; i<10; i++ )
3026 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
3031 mySelectionMgr->clearFilters();
3035 int aCriterionType = myTable->GetCriterionType(aRow);
3036 if (myTable->CurrentCell(aRow, aCol) &&
3037 (aCriterionType == SMESH::FT_BelongToGeom ||
3038 aCriterionType == SMESH::FT_BelongToPlane ||
3039 aCriterionType == SMESH::FT_BelongToCylinder ||
3040 aCriterionType == SMESH::FT_BelongToGenSurface ||
3041 aCriterionType == SMESH::FT_LyingOnGeom)) {
3043 if (aCriterionType == SMESH::FT_BelongToGeom ||
3044 aCriterionType == SMESH::FT_BelongToGenSurface ||
3045 aCriterionType == SMESH::FT_LyingOnGeom) {
3047 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
3049 } else if (aCriterionType == SMESH::FT_BelongToPlane) {
3050 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
3052 } else if (aCriterionType == SMESH::FT_BelongToCylinder) {
3053 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
3055 myIsSelectionChanged = true;
3058 if (myIsSelectionChanged) {
3059 mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
3064 //=================================================================================
3065 // function : keyPressEvent()
3067 //=================================================================================
3068 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
3070 QDialog::keyPressEvent( e );
3071 if ( e->isAccepted() )
3074 if ( e->key() == Qt::Key_F1 ) {