1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_Filter.h"
36 #include "SMESH_Actor.h"
37 #include "VTKViewer_ViewFrame.h"
38 #include "QAD_Desktop.h"
39 #include "QAD_MessageBox.h"
40 #include "QAD_RightFrame.h"
41 #include "QAD_Config.h"
42 #include "SALOME_ListIteratorOfListIO.hxx"
43 #include "SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx"
44 #include "SALOMEGUI_QtCatchCorbaException.hxx"
45 #include "SMESHGUI_FilterLibraryDlg.h"
46 #include "SALOME_TypeFilter.hxx"
49 #include "GEOM_FaceFilter.hxx"
51 #include <TColStd_MapOfInteger.hxx>
52 #include <TColStd_IndexedMapOfInteger.hxx>
53 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
54 #include <Precision.hxx>
55 #include <BRep_Tool.hxx>
56 #include <TopoDS_Shape.hxx>
58 #include <TopoDS_Face.hxx>
59 #include <Geom_Plane.hxx>
60 #include <Geom_CylindricalSurface.hxx>
64 #include <qlineedit.h>
65 #include <qpushbutton.h>
66 #include <qgroupbox.h>
68 #include <qstringlist.h>
70 #include <qwidgetstack.h>
71 #include <qapplication.h>
72 #include <qcombobox.h>
73 #include <qfontmetrics.h>
74 #include <qmessagebox.h>
76 #include <qbuttongroup.h>
77 #include <qradiobutton.h>
80 #include <qcheckbox.h>
81 #include <qobjectlist.h>
82 #include <qvalidator.h>
87 using namespace SMESH;
89 static int maxLength( const QMap<int, QString> theMap, const QFontMetrics& theMetrics )
92 QMap<int, QString>::const_iterator anIter;
93 for ( anIter = theMap.begin(); anIter != theMap.end(); ++anIter )
94 aRes = Max( aRes, theMetrics.width( anIter.data() ) );
98 static int getFilterId( SMESH::ElementType theType )
102 case SMESH::NODE : return SMESHGUI_NodeFilter;
103 case SMESH::EDGE : return SMESHGUI_EdgeFilter;
104 case SMESH::FACE : return SMESHGUI_FaceFilter;
105 case SMESH::VOLUME : return SMESHGUI_VolumeFilter;
106 case SMESH::ALL : return SMESHGUI_AllElementsFilter;
107 default : return SMESHGUI_UnknownFilter;
112 Class : SMESHGUI_FilterTable::AdditionalWidget
113 Description : Class for storing additional parameters of criterion
116 class SMESHGUI_FilterTable::AdditionalWidget : public QFrame
123 AdditionalWidget( QWidget* theParent );
124 virtual ~AdditionalWidget();
126 virtual void GetParameters( QValueList<int>& ) const;
127 virtual bool IsValid( const bool theMsg = true ) const;
128 virtual double GetDouble( const int theId ) const;
129 virtual int GetInteger( const int theId ) const;
130 virtual QString GetString( const int theId ) const;
131 virtual void SetDouble( const int theId, const double theVal );
132 virtual void SetInteger( const int theId, const int theVal );
133 virtual void SetString( const int theId, const QString& theVal );
134 void SetEditable( const int theId, const bool isEditable );
135 void SetEditable( const bool isEditable );
138 QMap< int, QLineEdit* > myLineEdits;
141 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget( QWidget* theParent )
142 : QFrame( theParent )
144 QLabel* aLabel = new QLabel( tr( "SMESH_TOLERANCE" ), this );
145 myLineEdits[ Tolerance ] = new QLineEdit( this );
146 QDoubleValidator* aValidator = new QDoubleValidator( myLineEdits[ Tolerance ] );
147 aValidator->setBottom( 0 );
148 myLineEdits[ Tolerance ]->setValidator( aValidator );
150 QHBoxLayout* aLay = new QHBoxLayout( this, 0, SPACING );
151 aLay->addWidget( aLabel );
152 aLay->addWidget( myLineEdits[ Tolerance ] );
154 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
155 aLay->addItem( aSpacer );
157 QString aText = QString( "%1" ).arg( Precision::Confusion() );
158 myLineEdits[ Tolerance ]->setText( aText );
160 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
164 void SMESHGUI_FilterTable::AdditionalWidget::GetParameters( QValueList<int>& theList ) const
167 theList.append( Tolerance );
170 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid( const bool theMsg ) const
175 QValueList<int> aParams;
176 GetParameters( aParams );
177 QValueList<int>::const_iterator anIter;
178 for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
180 const QLineEdit* aWg = myLineEdits[ *anIter ];
182 QString aText = aWg->text();
183 if ( aWg->isEnabled() && aWg->validator()->validate( aText, p ) != QValidator::Acceptable )
186 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
187 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
195 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble( const int theId ) const
197 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toDouble() : 0;
200 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger( const int theId ) const
202 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toInt() : 0;
205 QString SMESHGUI_FilterTable::AdditionalWidget::GetString( const int theId ) const
207 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text() : QString("");
210 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble( const int theId, const double theVal )
212 if ( myLineEdits.contains( theId ) )
213 myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
216 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger( const int theId, const int theVal )
218 if ( myLineEdits.contains( theId ) )
219 myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
222 void SMESHGUI_FilterTable::AdditionalWidget::SetString( const int theId, const QString& theVal )
224 if ( myLineEdits.contains( theId ) )
225 myLineEdits[ theId ]->setText( theVal );
228 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const int theId, const bool isEditable )
230 if ( myLineEdits.contains( theId ) )
231 myLineEdits[ theId ]->setEdited( isEditable );
234 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const bool isEditable )
236 QValueList<int> aParams;
237 GetParameters( aParams );
238 QValueList<int>::const_iterator anIter;
239 for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
240 myLineEdits[ *anIter ]->setEdited( isEditable );
244 Class : SMESHGUI_FilterTable::ComboItem
245 Description : Combo table item. Identificator corresponding to string may be assigned
248 class SMESHGUI_FilterTable::ComboItem : public QComboTableItem
252 ComboItem( QTable*, const QMap<int, QString>& );
253 virtual ~ComboItem();
255 virtual void setStringList ( const QStringList & l );
256 void setStringList( const QMap<int, QString>& theIds );
258 int GetValue() const;
259 void SetValue( const int );
263 QMap<int, int> myNumToId;
264 QMap<int, int> myIdToNum;
267 SMESHGUI_FilterTable::ComboItem::ComboItem( QTable* theParent,
268 const QMap<int, QString>& theIds )
269 : QComboTableItem( theParent, QStringList() )
271 setStringList( theIds );
274 void SMESHGUI_FilterTable::ComboItem::setStringList( const QStringList & l )
276 QComboTableItem::setStringList( l );
279 void SMESHGUI_FilterTable::ComboItem::setStringList( const QMap<int, QString>& theIds )
283 QMap<int, QString>::const_iterator anIter;
284 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
286 myNumToId[ i ] = anIter.key();
287 myIdToNum[ anIter.key() ] = i;
288 aList.append( anIter.data() );
292 setStringList( aList );
295 SMESHGUI_FilterTable::ComboItem::~ComboItem()
299 int SMESHGUI_FilterTable::ComboItem::GetValue() const
301 return myNumToId[ currentItem() ];
304 void SMESHGUI_FilterTable::ComboItem::SetValue( const int theVal )
306 setCurrentItem( myIdToNum[ theVal ] );
311 Class : SMESHGUI_FilterTable::Table
312 Description : Table used by this widget
315 class SMESHGUI_FilterTable::Table : public QTable
318 Table( QWidget* parent );
319 Table( int numRows, int numCols, QWidget* parent = 0 );
322 void SetEditable( const bool state, const int row, const int col );
323 bool IsEditable( const int row, const int col ) const;
325 virtual void insertRows( int row, int count = 1 );
326 virtual QString text( int row, int col ) const;
329 //=======================================================================
330 // name : SMESHGUI_FilterTable::Table::Table
331 // Purpose : Constructor
332 //=======================================================================
333 SMESHGUI_FilterTable::Table::Table( QWidget* parent )
334 : QTable( parent, "SMESHGUI_FilterTable::Table" )
338 SMESHGUI_FilterTable::Table::Table( int numRows, int numCols, QWidget* parent )
339 : QTable( numRows, numCols, parent, "SMESHGUI_FilterTable::Table" )
343 SMESHGUI_FilterTable::Table::~Table()
347 //=======================================================================
348 // name : SMESHGUI_FilterTable::Table::SetEditable
349 // Purpose : Set editable of specified cell
350 //=======================================================================
351 void SMESHGUI_FilterTable::Table::SetEditable( const bool isEditable, const int row, const int col )
353 QTableItem* anItem = item( row, col );
358 setItem( row, col, new QTableItem( this, QTableItem::Never, "" ) );
360 setItem( row, col, new QTableItem( this, QTableItem::OnTyping, "" ) );
363 //=======================================================================
364 // name : SMESHGUI_FilterTable::Table::IsEditable
365 // Purpose : Verify wheter cell is editable
366 //=======================================================================
367 bool SMESHGUI_FilterTable::Table::IsEditable( const int row, const int col ) const
369 QTableItem* anItem = item( row, col );
370 return anItem == 0 || anItem->editType() != QTableItem::Never;
373 //=======================================================================
374 // name : SMESHGUI_FilterTable::Table::insertRows
375 // Purpose : Insert rows ( virtual redefined )
376 //=======================================================================
377 void SMESHGUI_FilterTable::Table::insertRows( int row, int count )
379 int anEditRow = currEditRow();
380 int anEditCol = currEditCol();
382 if ( anEditRow >= 0 && anEditCol >= 0 )
383 endEdit( anEditRow, anEditCol, true, false );
385 QTable::insertRows( row, count );
388 //=======================================================================
389 // name : SMESHGUI_FilterTable::Table::text
390 // Purpose : Get text from cell ( virtual redefined )
391 //=======================================================================
392 QString SMESHGUI_FilterTable::Table::text( int row, int col ) const
394 int anEditRow = currEditRow();
395 int anEditCol = currEditCol();
397 if ( anEditRow >= 0 && anEditCol >= 0 && anEditRow == row && anEditCol == col )
398 ((Table*)this)->endEdit( row, col, true, false );
400 return QTable::text( row, col );
406 Class : SMESHGUI_FilterTable
407 Description : Frame containig
408 - Button group for switching entity type
409 - Table for displaying filter criterions
410 - Buttons for editing table and filter libraries
413 //=======================================================================
414 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
415 // Purpose : Constructor
416 //=======================================================================
417 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent,
425 //=======================================================================
426 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
427 // Purpose : Constructor
428 //=======================================================================
429 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent,
430 const QValueList<int>& types )
437 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
441 //=======================================================================
442 // name : SMESHGUI_FilterTable::Init
443 // Purpose : Create table corresponding to the specified type
444 //=======================================================================
445 void SMESHGUI_FilterTable::Init( const int type )
447 QValueList<int> aTypes;
448 aTypes.append( type );
452 //=======================================================================
453 // name : SMESHGUI_FilterTable::Init
454 // Purpose : Create table corresponding to the specified type
455 //=======================================================================
456 void SMESHGUI_FilterTable::Init( const QValueList<int>& theTypes )
458 if ( theTypes.isEmpty() )
461 // Create buttons if necessary
463 if ( myTables.isEmpty() )
465 int aType = theTypes.first();
467 // create main layout
468 QVBoxLayout* aMainLay = new QVBoxLayout( this );
469 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, this );
470 aMainGrp->setFrameStyle( QFrame::NoFrame );
471 aMainGrp->setInsideMargin( 0 );
472 aMainLay->addWidget( aMainGrp );
474 // create switch of entity types
475 myEntityTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "ENTITY_TYPE" ), aMainGrp );
476 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
477 QMap<int, QString>::const_iterator anIter;
478 for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
480 QRadioButton* aBtn = new QRadioButton( anIter.data(), myEntityTypeGrp );
481 myEntityTypeGrp->insert( aBtn, anIter.key() );
484 myTableGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FILTER" ), aMainGrp );
485 QFrame* aTableFrame = new QFrame( myTableGrp );
488 mySwitchTableGrp = new QGroupBox( 1, Qt::Horizontal, aTableFrame );
489 mySwitchTableGrp->setFrameStyle( QFrame::NoFrame );
490 mySwitchTableGrp->setInsideMargin( 0 );
492 myTables[ aType ] = createTable( mySwitchTableGrp, aType );
495 myAddBtn = new QPushButton( tr( "ADD" ), aTableFrame );
496 myRemoveBtn = new QPushButton( tr( "REMOVE" ), aTableFrame );
497 myClearBtn = new QPushButton( tr( "CLEAR" ), aTableFrame );
498 myInsertBtn = new QPushButton( tr( "INSERT" ), aTableFrame );
499 myCopyFromBtn = new QPushButton( tr( "COPY_FROM" ), aTableFrame );
500 myAddToBtn = new QPushButton( tr( "ADD_TO" ), aTableFrame );
502 myAddBtn->setAutoDefault( false );
503 myRemoveBtn->setAutoDefault( false );
504 myClearBtn->setAutoDefault( false );
505 myInsertBtn->setAutoDefault( false );
506 myCopyFromBtn->setAutoDefault( false );
507 myAddToBtn->setAutoDefault( false );
509 myCopyFromBtn->hide();
513 QGridLayout* aLay = new QGridLayout( aTableFrame, 8, 2, 0, SPACING );
515 aLay->addMultiCellWidget( mySwitchTableGrp, 0, 6, 0, 0 );
516 aLay->addWidget( myAddBtn, 0, 1 );
517 aLay->addWidget( myInsertBtn, 1, 1 );
518 aLay->addWidget( myRemoveBtn, 2, 1 );
519 aLay->addWidget( myClearBtn, 3, 1 );
520 aLay->addWidget( myCopyFromBtn, 5, 1 );
521 aLay->addWidget( myAddToBtn, 6, 1 );
522 aLay->addMultiCellWidget( createAdditionalFrame( aTableFrame ), 7, 7, 0, 1 );
524 aLay->setColStretch( 0, 1 );
525 aLay->setColStretch( 1, 0 );
527 QSpacerItem* aVSpacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
528 aLay->addItem( aVSpacer, 4, 1 );
531 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( onAddBtn() ) );
532 connect( myInsertBtn, SIGNAL( clicked() ), this, SLOT( onInsertBtn() ) );
533 connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveBtn() ) );
534 connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( onClearBtn() ) );
536 connect( myCopyFromBtn, SIGNAL( clicked() ), this, SLOT( onCopyFromBtn() ) );
537 connect( myAddToBtn, SIGNAL( clicked() ), this, SLOT( onAddToBtn() ) );
539 connect( myEntityTypeGrp, SIGNAL( clicked( int ) ), this, SLOT( onEntityType( int ) ) );
544 // Hide buttons of entity types if necessary
545 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
546 QMap<int, QString>::const_iterator anIt;
547 for ( anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt )
549 QButton* aBtn = myEntityTypeGrp->find( anIt.key() );
550 theTypes.contains( anIt.key() ) ? aBtn->show() : aBtn->hide();
553 // select first button if there is no selected buttons or it is hidden
554 QButton* aBtn = myEntityTypeGrp->selected();
555 if ( aBtn == 0 || theTypes.find( myEntityTypeGrp->id( aBtn ) ) == theTypes.end() )
556 myEntityTypeGrp->setButton( theTypes.first() );
558 if ( theTypes.count() == 1 )
559 myEntityTypeGrp->hide();
561 myEntityTypeGrp->show();
563 myTableGrp->updateGeometry();
564 int aType = myEntityTypeGrp->id( myEntityTypeGrp->selected() );
565 onEntityType( aType );
568 //=======================================================================
569 // name : SMESHGUI_FilterTable::GetTableGrp
570 // Purpose : Get group box containing table. May be used for adding new widgets in it
571 ////=======================================================================
572 QWidget* SMESHGUI_FilterTable::createAdditionalFrame( QWidget* theParent )
574 QFrame* aFrame = new QFrame( theParent );
576 QFrame* aLine1 = new QFrame( aFrame );
577 QFrame* aLine2 = new QFrame( aFrame );
578 aLine1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
579 aLine2->setFrameStyle( QFrame::HLine | QFrame::Sunken );
580 aLine1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
581 aLine2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
583 QLabel* aLabel = new QLabel( tr( "ADDITIONAL_PARAMETERS" ), aFrame );
585 myWgStack = new QWidgetStack( aFrame );
587 QGridLayout* aLay = new QGridLayout( aFrame, 2, 3, 0, SPACING );
588 aLay->addWidget( aLine1, 0, 0 );
589 aLay->addWidget( aLabel, 0, 1 );
590 aLay->addWidget( aLine2, 0, 2 );
591 aLay->addMultiCellWidget( myWgStack, 1, 1, 0, 2 );
596 //=======================================================================
597 // name : SMESHGUI_FilterTable::GetTableGrp
598 // Purpose : Get group box containing table. May be used for adding new widgets in it
599 ////=======================================================================
600 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
605 //=======================================================================
606 // name : SMESHGUI_FilterTable::onEntityType
607 // Purpose : SLOT. Called when entity type changed.
608 // Display corresponding table
609 //=======================================================================
610 void SMESHGUI_FilterTable::onEntityType( int theType )
612 if ( myEntityType == theType )
616 emit NeedValidation();
619 myEntityTypeGrp->setButton( myEntityType );
623 myEntityType = theType;
625 if ( !myTables.contains( theType ) )
626 myTables[ theType ] = createTable( mySwitchTableGrp, theType );
628 TableMap::iterator anIter;
629 for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
630 myEntityType == anIter.key() ? anIter.data()->show() : anIter.data()->hide();
633 qApp->processEvents();
634 myTables[ myEntityType ]->updateGeometry();
637 emit EntityTypeChanged( theType );
641 //=======================================================================
642 // name : SMESHGUI_FilterTable::IsValid
643 // Purpose : Verify validity of entered data
644 //=======================================================================
645 bool SMESHGUI_FilterTable::IsValid( const bool theMess, const int theEntityType ) const
647 int aType = theEntityType == -1 ? GetType() : theEntityType;
649 Table* aTable = myTables[ aType ];
650 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
652 int aCriterion = GetCriterionType( i, aType );
654 if ( aCriterion == FT_RangeOfIds ||
655 aCriterion == FT_BelongToGeom ||
656 aCriterion == FT_BelongToPlane ||
657 aCriterion == FT_BelongToCylinder )
659 if ( aTable->text( i, 2 ).isEmpty() )
662 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
663 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
670 aTable->blockSignals( true );
671 double aThreshold = ( int )aTable->text( i, 2 ).toDouble( &aRes );
672 aTable->blockSignals( false );
674 if ( !aRes && aTable->IsEditable( i, 2 ) )
677 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
678 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
681 else if ( aType == SMESH::EDGE &&
682 GetCriterionType( i, aType ) == SMESH::FT_MultiConnection &&
686 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
687 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "MULTIEDGES_ERROR" ), QMessageBox::Ok );
692 QTableItem* anItem = aTable->item( i, 0 );
693 if ( myAddWidgets.contains( anItem ) && !myAddWidgets[ anItem ]->IsValid() )
700 //=======================================================================
701 // name : SMESHGUI_FilterTable::SetValidity
702 // Purpose : Set validity of the table
703 //=======================================================================
704 void SMESHGUI_FilterTable::SetValidity( const bool isValid )
709 //=======================================================================
710 // name : SMESHGUI_FilterTable::GetType
711 // Purpose : Get current entity type
712 //=======================================================================
713 int SMESHGUI_FilterTable::GetType() const
718 //=======================================================================
719 // name : SMESHGUI_FilterTable::SetType
720 // Purpose : Set current entity type
721 //=======================================================================
722 void SMESHGUI_FilterTable::SetType( const int type )
724 myEntityTypeGrp->setButton( type );
725 onEntityType( type );
728 //=======================================================================
729 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
730 // Purpose : Restore previous entity type
731 //=======================================================================
732 void SMESHGUI_FilterTable::RestorePreviousEntityType()
734 SetType( myEntityType );
737 //=======================================================================
738 // name : SMESHGUI_FilterTable::GetCriterionType
739 // Purpose : Get type of criterion from specified row ( corresponding enums in h-file )
740 //=======================================================================
741 int SMESHGUI_FilterTable::GetCriterionType( const int theRow, const int theType ) const
743 int aType = theType == -1 ? GetType() : theType;
744 Table* aTable = myTables[ aType ];
745 ComboItem* anItem = (ComboItem*)aTable->item( theRow, 0 );
746 return anItem != 0 ? anItem->GetValue() : FT_Undefined;
749 //=======================================================================
750 // name : SMESHGUI_FilterTable::GetCriterion
751 // Purpose : Get parameters of criterion from specified row
752 //=======================================================================
753 void SMESHGUI_FilterTable::GetCriterion( const int theRow,
754 SMESH::Filter::Criterion& theCriterion,
755 const int theEntityType ) const
757 int aType = theEntityType == -1 ? GetType() : theEntityType;
758 Table* aTable = myTables[ aType ];
760 theCriterion.Type = ( (ComboItem*)aTable->item( theRow, 0 ) )->GetValue();
761 theCriterion.UnaryOp = ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->isChecked() ? FT_LogicalNOT : FT_Undefined;
762 theCriterion.BinaryOp = theRow != aTable->numRows() - 1 ?
763 ( (ComboItem*)aTable->item( theRow, 4 ) )->GetValue() : FT_Undefined;
764 theCriterion.TypeOfElement = (ElementType)aType;
766 int aCriterionType = GetCriterionType( theRow, aType );
768 if ( aCriterionType != FT_RangeOfIds &&
769 aCriterionType != FT_BelongToGeom &&
770 aCriterionType != FT_BelongToPlane &&
771 aCriterionType != FT_BelongToCylinder )
773 theCriterion.Compare = ( (ComboItem*)aTable->item( theRow, 1 ) )->GetValue();
774 theCriterion.Threshold = aTable->item( theRow, 2 )->text().toDouble();
777 theCriterion.ThresholdStr = aTable->text( theRow, 2 ).latin1();
779 QTableItem* anItem = aTable->item( theRow, 0 );
780 if ( myAddWidgets.contains( anItem ) )
781 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble( AdditionalWidget::Tolerance );
784 //=======================================================================
785 // name : SMESHGUI_FilterTable::SetCriterion
786 // Purpose : Set parameters of criterion of specified row
787 //=======================================================================
788 void SMESHGUI_FilterTable::SetCriterion( const int theRow,
789 const SMESH::Filter::Criterion& theCriterion,
790 const int theEntityType )
792 int aType = theEntityType == -1 ? GetType() : theEntityType;
794 Table* aTable = myTables[ aType ];
796 if ( theRow > aTable->numRows() - 1 )
799 ( (ComboItem*)aTable->item( theRow, 0 ) )->SetValue( theCriterion.Type );
800 onCriterionChanged( theRow, 0, aType );
801 ( (ComboItem*)aTable->item( theRow, 1 ) )->SetValue( theCriterion.Compare );
802 ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->setChecked( theCriterion.UnaryOp == FT_LogicalNOT );
804 if ( theCriterion.BinaryOp != FT_Undefined )
806 if ( !aTable->IsEditable( theRow, 4 ) )
807 aTable->setItem( theRow, 4, getBinaryItem( aTable ) );
808 ( (ComboItem*)aTable->item( theRow, 4 ) )->SetValue( theCriterion.BinaryOp );
811 aTable->SetEditable( false, theRow, 4 );
813 if ( theCriterion.Type != FT_RangeOfIds &&
814 theCriterion.Type != FT_BelongToGeom &&
815 theCriterion.Type != FT_BelongToPlane &&
816 theCriterion.Type != FT_BelongToCylinder )
817 aTable->setText( theRow, 2, QString( "%1" ).arg( theCriterion.Threshold, 0, 'g', 15 ) );
819 aTable->setText( theRow, 2, QString( theCriterion.ThresholdStr ) );
821 if ( theCriterion.Compare == FT_EqualTo ||
822 theCriterion.Type == FT_BelongToPlane ||
823 theCriterion.Type == FT_BelongToCylinder )
825 QTableItem* anItem = aTable->item( theRow, 0 );
826 if ( !myAddWidgets.contains( anItem ) )
828 myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
829 myWgStack->addWidget( myAddWidgets[ anItem ] );
831 myAddWidgets[ anItem ]->SetDouble( AdditionalWidget::Tolerance, theCriterion.Tolerance );
834 emit CretarionChanged( theRow, aType );
838 //=======================================================================
839 // name : SMESHGUI_FilterTable::Update
840 // Purpose : Update table
841 //=======================================================================
842 void SMESHGUI_FilterTable::Update()
844 Table* aTable = myTables[ GetType() ];
845 int aCurrRow = aTable->currentRow();
846 int numRows = aTable->numRows();
847 if ( ( aCurrRow < 0 || aCurrRow >= numRows ) && numRows > 0 )
848 aTable->setCurrentCell( 0, 0 );
849 updateAdditionalWidget();
852 //=======================================================================
853 // name : SMESHGUI_FilterTable::AddCriterion
854 // Purpose : Add criterion with parameters
855 //=======================================================================
856 void SMESHGUI_FilterTable::AddCriterion( const SMESH::Filter::Criterion& theCriterion,
857 const int theEntityType )
859 int aType = theEntityType == -1 ? GetType() : theEntityType;
860 Table* aTable = myTables[ aType ];
861 addRow( aTable, aType );
862 SetCriterion( aTable->numRows() - 1, theCriterion );
865 //=======================================================================
866 // name : SMESHGUI_FilterTable::NumRows
867 // Purpose : Get number of criterions of current type
868 //=======================================================================
869 int SMESHGUI_FilterTable::NumRows( const int theEntityType ) const
871 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->numRows();
874 //=======================================================================
875 // name : SMESHGUI_FilterTable::Clear
876 // Purpose : Clear current table
877 //=======================================================================
878 void SMESHGUI_FilterTable::Clear( const int theType )
880 int aType = theType == -1 ? GetType() : theType;
881 QTable* aTable = myTables[ aType ];
883 if ( aTable->numRows() == 0 )
886 while ( aTable->numRows() > 0 )
888 removeAdditionalWidget( aTable, 0 );
889 aTable->removeRow( 0 );
895 //=======================================================================
896 // name : SMESHGUI_FilterTable::onAddBtn
897 // Purpose : SLOT. Called then "Add" button pressed.
898 // Adds new string to table
899 //=======================================================================
900 void SMESHGUI_FilterTable::onAddBtn()
902 int aType = GetType();
903 addRow( myTables[ aType ], aType );
905 Table* aTable = myTables[ aType ];
909 //=======================================================================
910 // name : SMESHGUI_FilterTable::onInsertBtn
911 // Purpose : SLOT. Called then "Insert" button pressed.
912 // Inserts new string before current one
913 //=======================================================================
914 void SMESHGUI_FilterTable::onInsertBtn()
916 addRow( myTables[ GetType() ], GetType(), false );
919 //=======================================================================
920 // name : SMESHGUI_FilterTable::onRemoveBtn
921 // Purpose : SLOT. Called then "Remove" button pressed.
922 // Removes current string from table
923 //=======================================================================
924 void SMESHGUI_FilterTable::onRemoveBtn()
926 Table* aTable = myTables[ GetType() ];
928 if ( aTable->numRows() == 0 )
931 QMemArray<int> aRows;
932 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
934 if ( aTable->isRowSelected( i ) )
936 aRows.resize( aRows.size() + 1 );
937 aRows[ aRows.size() - 1 ] = i;
938 removeAdditionalWidget( aTable, i );
942 aTable->removeRows( aRows );
944 // remove control of binary logical operation from last row
945 if ( aTable->numRows() > 0 )
946 aTable->SetEditable( false, aTable->numRows() - 1, 4 );
951 //=======================================================================
952 // name : SMESHGUI_FilterTable::updateAdditionalWidget
953 // Purpose : Enable/Disable widget with additonal parameters
954 //=======================================================================
955 void SMESHGUI_FilterTable::updateAdditionalWidget()
957 Table* aTable = myTables[ GetType() ];
958 int aRow = aTable->currentRow();
959 if ( aRow < 0 || aRow >= aTable->numRows() )
961 myWgStack->setEnabled( false );
965 ComboItem* anItem = ( (ComboItem*)aTable->item( aRow, 0 ) );
966 bool toEnable = ( (ComboItem*)aTable->item( aRow, 1 ) )->GetValue() == FT_EqualTo &&
967 GetCriterionType( aRow ) != FT_BelongToGeom &&
968 GetCriterionType( aRow ) != FT_RangeOfIds &&
969 GetCriterionType( aRow ) != FT_FreeEdges;
970 if ( !myAddWidgets.contains( anItem ) )
972 myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
973 myWgStack->addWidget( myAddWidgets[ anItem ] );
976 myWgStack->raiseWidget( myWgStack->id( myAddWidgets[ anItem ] ) );
977 myWgStack->setEnabled( toEnable );
980 //=======================================================================
981 // name : SMESHGUI_FilterTable::removeAdditionalWidget
982 // Purpose : Remove widgets containing additional parameters from widget
983 // stack and internal map
984 //=======================================================================
985 void SMESHGUI_FilterTable::removeAdditionalWidget( QTable* theTable, const int theRow )
987 QTableItem* anItem = theTable->item( theRow, 0 );
988 if ( myAddWidgets.contains( anItem ) )
990 myWgStack->removeWidget( myAddWidgets[ anItem ] );
991 myAddWidgets[ anItem ]->reparent( 0, QPoint() );
992 delete myAddWidgets[ anItem ];
993 myAddWidgets.remove( anItem );
997 //=======================================================================
998 // name : SMESHGUI_FilterTable::onClearBtn
999 // Purpose : SLOT. Called then "Clear" button pressed.
1000 // Removes all strings from table
1001 //=======================================================================
1002 void SMESHGUI_FilterTable::onClearBtn()
1004 QTable* aTable = myTables[ GetType() ];
1006 if ( aTable->numRows() == 0 )
1009 while ( aTable->numRows() > 0 )
1011 removeAdditionalWidget( aTable, 0 );
1012 aTable->removeRow( 0 );
1018 //=======================================================================
1019 // name : SMESHGUI_FilterTable::onCurrentChanged()
1020 // Purpose : SLOT. Called when current cell changed
1021 //=======================================================================
1022 void SMESHGUI_FilterTable::onCurrentChanged( int theRow, int theCol )
1024 updateAdditionalWidget();
1025 emit CurrentChanged( theRow, theCol );
1028 //=======================================================================
1029 // name : SMESHGUI_FilterTable::onCriterionChanged()
1030 // Purpose : Provides reaction on change of criterion
1031 //=======================================================================
1032 void SMESHGUI_FilterTable::onCriterionChanged( const int row, const int col, const int entityType )
1034 int aType = entityType == -1 ? GetType() : entityType;
1035 Table* aTable = myTables[ aType ];
1036 ComboItem* aCompareItem = (ComboItem*)aTable->item( row, 1 );
1038 int aCriterionType = GetCriterionType( row );
1040 if ( aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1041 aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges )
1043 if ( aCompareItem->count() > 0 )
1044 aCompareItem->setStringList( QStringList() );
1045 aTable->SetEditable( false, row, 2 );
1047 else if ( aCriterionType == SMESH::FT_RangeOfIds ||
1048 aCriterionType == SMESH::FT_BelongToGeom ||
1049 aCriterionType == SMESH::FT_BelongToPlane ||
1050 aCriterionType == SMESH::FT_BelongToCylinder )
1052 QMap<int, QString> aMap;
1053 aMap[ FT_EqualTo ] = tr( "EQUAL_TO" );
1054 aCompareItem->setStringList( aMap );
1055 if ( !aTable->IsEditable( row, 2 ) )
1056 aTable->SetEditable( true, row, 2 );
1060 if ( aCompareItem->count() != 3 )
1062 aCompareItem->setStringList( QStringList() );
1063 aCompareItem->setStringList( getCompare() );
1066 QString aText = aTable->text( row, 2 );
1068 aText.toDouble( &isOk );
1069 aTable->setText( row, 2, isOk ? aText : QString("") );
1070 if ( !aTable->IsEditable( row, 2 ) )
1071 aTable->SetEditable( true, row, 2 );
1074 updateAdditionalWidget();
1076 emit CretarionChanged( row, entityType );
1079 //=======================================================================
1080 // name : SMESHGUI_FilterTable::onCriterionChanged()
1081 // Purpose : SLOT. Called then contents of table changed
1082 // Provides reaction on change of criterion
1083 //=======================================================================
1084 void SMESHGUI_FilterTable::onCriterionChanged( int row, int col )
1086 onCriterionChanged( row, col, -1 );
1089 //=======================================================================
1090 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1091 // Purpose : Get first selected row
1092 //=======================================================================
1093 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1095 QTable* aTable = myTables[ GetType() ];
1096 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
1097 if ( aTable->isRowSelected( i ) )
1100 int aRow = aTable->currentRow();
1101 return aRow >= 0 && aRow < aTable->numRows() ? aRow : -1;
1104 //=======================================================================
1105 // name : SMESHGUI_FilterTable::addRow
1106 // Purpose : Add row at the end of table
1107 //=======================================================================
1108 void SMESHGUI_FilterTable::addRow( Table* theTable, const int theType, const bool toTheEnd )
1111 int aSelectedRow = getFirstSelectedRow();
1112 int aCurrCol = theTable->currentColumn();
1114 if ( toTheEnd || aSelectedRow == -1 )
1116 theTable->insertRows( theTable->numRows() );
1117 aCurrRow = theTable->numRows() - 1;
1121 theTable->insertRows( aSelectedRow );
1122 aCurrRow = aSelectedRow;
1126 theTable->setItem( aCurrRow, 0, getCriterionItem( theTable, theType ) );
1129 theTable->setItem( aCurrRow, 1, getCompareItem( theTable ) );
1132 //theTable->setItem( aCurrRow, 2, new QTableItem( theTable ) );
1134 //Logical operation NOT
1135 theTable->setItem( aCurrRow, 3, getUnaryItem( theTable ) );
1137 // Logical binary operation for previous value
1138 int anAddBinOpStr = -1;
1139 if ( aCurrRow == theTable->numRows() - 1 )
1140 anAddBinOpStr = aCurrRow - 1;
1141 else if ( aCurrRow >= 0 )
1142 anAddBinOpStr = aCurrRow;
1144 if ( theTable->item( aCurrRow, 4 ) == 0 ||
1145 theTable->item( aCurrRow, 4 )->rtti() != 1 )
1149 if ( anAddBinOpStr >= 0 &&
1150 ( theTable->item( anAddBinOpStr, 4 ) == 0 ||
1151 theTable->item( anAddBinOpStr, 4 )->rtti() != 1 ) )
1152 theTable->setItem( anAddBinOpStr, 4, getBinaryItem( theTable ) );
1155 theTable->SetEditable( false, theTable->numRows() - 1, 4 );
1157 if ( aCurrRow >=0 && aCurrRow < theTable->numRows() &&
1158 aCurrCol >=0 && aCurrCol < theTable->numRows() )
1159 theTable->setCurrentCell( aCurrRow, aCurrCol );
1161 onCriterionChanged( aCurrRow, 0 );
1166 //=======================================================================
1167 // name : SMESHGUI_FilterTable::getCriterionItem
1168 // Purpose : Get combo table item for criteria of specified type
1169 //=======================================================================
1170 QTableItem* SMESHGUI_FilterTable::getCriterionItem( QTable* theParent , const int theType )
1172 return new ComboItem( theParent, getCriteria( theType ) );
1175 //=======================================================================
1176 // name : SMESHGUI_FilterTable::getCompareItem
1177 // Purpose : Get combo table item for operation of comparision
1178 //=======================================================================
1179 QTableItem* SMESHGUI_FilterTable::getCompareItem( QTable* theParent )
1181 return new ComboItem( theParent, getCompare() );
1184 //=======================================================================
1185 // name : SMESHGUI_FilterTable::getBinaryItem
1187 //=======================================================================
1188 QTableItem* SMESHGUI_FilterTable::getBinaryItem( QTable* theParent )
1190 static QMap<int, QString> aMap;
1191 if ( aMap.isEmpty() )
1193 aMap[ SMESH::FT_LogicalAND ] = tr( "AND" );
1194 aMap[ SMESH::FT_LogicalOR ] = tr( "OR" );
1197 return new ComboItem( theParent, aMap );
1200 //=======================================================================
1201 // name : SMESHGUI_FilterTable::getUnaryItem
1202 // Purpose : Get check table item
1203 //=======================================================================
1204 QTableItem* SMESHGUI_FilterTable::getUnaryItem( QTable* theParent )
1206 return new QCheckTableItem( theParent, tr( "NOT" ) );
1209 //=======================================================================
1210 // name : SMESHGUI_FilterTable::getSupportedTypes
1211 // Purpose : Get all supported type
1212 //=======================================================================
1213 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1215 static QMap<int, QString> aTypes;
1216 if ( aTypes.isEmpty() )
1218 aTypes[ SMESH::NODE ] = tr( "NODES" );
1219 aTypes[ SMESH::EDGE ] = tr( "EDGES" );
1220 aTypes[ SMESH::FACE ] = tr( "FACES" );
1221 aTypes[ SMESH::VOLUME ] = tr( "VOLUMES" );
1227 //=======================================================================
1228 // name : SMESHGUI_FilterTable::getCriteria
1229 // Purpose : Get criteria for specified type
1230 //=======================================================================
1231 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria( const int theType ) const
1233 if ( theType == SMESH::NODE )
1235 static QMap<int, QString> aCriteria;
1236 if ( aCriteria.isEmpty() )
1238 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1239 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1240 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1241 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1245 else if ( theType == SMESH::EDGE )
1247 static QMap<int, QString> aCriteria;
1248 if ( aCriteria.isEmpty() )
1250 aCriteria[ SMESH::FT_FreeBorders ] = tr( "FREE_BORDERS" );
1251 aCriteria[ SMESH::FT_MultiConnection ] = tr( "MULTI_BORDERS" );
1252 aCriteria[ SMESH::FT_Length ] = tr( "LENGTH" );
1253 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1254 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1255 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1256 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1260 else if ( theType == SMESH::FACE )
1262 static QMap<int, QString> aCriteria;
1263 if ( aCriteria.isEmpty() )
1265 aCriteria[ SMESH::FT_AspectRatio ] = tr( "ASPECT_RATIO" );
1266 aCriteria[ SMESH::FT_Warping ] = tr( "WARPING" );
1267 aCriteria[ SMESH::FT_MinimumAngle ] = tr( "MINIMUM_ANGLE" );
1268 aCriteria[ SMESH::FT_Taper ] = tr( "TAPER" );
1269 aCriteria[ SMESH::FT_Skew ] = tr( "SKEW" );
1270 aCriteria[ SMESH::FT_Area ] = tr( "AREA" );
1271 aCriteria[ SMESH::FT_FreeEdges ] = tr( "FREE_EDGES" );
1272 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1273 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1274 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1275 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1279 else if ( theType == SMESH::VOLUME )
1281 static QMap<int, QString> aCriteria;
1282 if ( aCriteria.isEmpty() )
1284 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1285 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1291 static QMap<int, QString> aCriteria;
1297 //=======================================================================
1298 // name : SMESHGUI_FilterTable::getCompare
1299 // Purpose : Get operation of comparison
1300 //=======================================================================
1301 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1303 static QMap<int, QString> aMap;
1305 if ( aMap.isEmpty() )
1307 aMap[ SMESH::FT_LessThan ] = tr( "LESS_THAN" );
1308 aMap[ SMESH::FT_MoreThan ] = tr( "MORE_THAN" );
1309 aMap[ SMESH::FT_EqualTo ] = tr( "EQUAL_TO" );
1315 //=======================================================================
1316 // name : SMESHGUI_FilterTable::createTable
1317 // Purpose : Create table
1318 //=======================================================================
1319 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable( QWidget* theParent,
1323 Table* aTable= new Table( 0, 5, theParent );
1325 QHeader* aHeaders = aTable->horizontalHeader();
1327 QFontMetrics aMetrics( aHeaders->font() );
1329 // append spaces to the header of criteria in order to
1330 // provide visibility of criterion inside comboboxes
1331 static int aMaxLenCr = 0;
1333 if ( aMaxLenCr == 0 )
1335 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1336 QMap<int, QString>::const_iterator anIter;
1337 for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
1338 aMaxLenCr = Max( maxLength( getCriteria( anIter.key() ), aMetrics ), aMaxLenCr );
1341 static int aLenCr = abs( aMaxLenCr -
1342 aMetrics.width( tr( "CRITERION" ) ) ) / aMetrics.width( ' ' ) + 5;
1344 static int aLenCo = abs( maxLength( getCompare(), aMetrics ) -
1345 aMetrics.width( tr( "COMPARE" ) ) ) / aMetrics.width( ' ' ) + 5;
1348 aCrStr.fill( ' ', aLenCr );
1350 aCoStr.fill( ' ', 10 );
1352 aHeaders->setLabel( 0, tr( "CRITERION" ) + aCrStr );
1353 aHeaders->setLabel( 1, tr( "COMPARE" ) + aCoStr );
1354 aHeaders->setLabel( 2, tr( "THRESHOLD_VALUE" ) );
1355 aHeaders->setLabel( 3, tr( "UNARY" ) );
1356 aHeaders->setLabel( 4, tr( "BINARY" ) + " " );
1358 // set geometry of the table
1359 for ( int i = 0; i <= 4; i++ )
1360 aTable->adjustColumn( i );
1362 aTable->updateGeometry();
1363 QSize aSize = aTable->sizeHint();
1364 int aWidth = aSize.width();
1365 aTable->setMinimumSize( QSize( aWidth, aWidth / 2 ) );
1366 aTable->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) );
1368 connect( aTable, SIGNAL( valueChanged( int, int ) ),
1369 this, SLOT( onCriterionChanged( int, int ) ) );
1371 connect( aTable, SIGNAL( currentChanged( int, int ) ),
1372 this, SLOT( onCurrentChanged( int, int ) ) );
1377 //=======================================================================
1378 // name : SMESHGUI_FilterTable::updateBtnState
1379 // Purpose : Update button state
1380 //=======================================================================
1381 void SMESHGUI_FilterTable::updateBtnState()
1383 myRemoveBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1384 myClearBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1387 //=======================================================================
1388 // name : SMESHGUI_FilterTable::SetEditable
1389 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1390 //=======================================================================
1391 void SMESHGUI_FilterTable::SetEditable( const bool isEditable )
1393 TableMap::iterator anIter;
1394 for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
1396 anIter.data()->setReadOnly( !isEditable );
1401 myInsertBtn->show();
1402 myRemoveBtn->show();
1408 myInsertBtn->hide();
1409 myRemoveBtn->hide();
1414 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1415 for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1416 anIter2.data()->SetEditable( isEditable );
1419 //=======================================================================
1420 // name : SMESHGUI_FilterTable::SetEnabled
1421 // Purpose : Enable/Disable table. Switching type of elements already enabled
1422 //=======================================================================
1423 void SMESHGUI_FilterTable::SetEnabled( const bool isEnabled )
1425 myAddBtn->setEnabled( isEnabled );
1426 myInsertBtn->setEnabled( isEnabled );
1427 myRemoveBtn->setEnabled( isEnabled );
1428 myClearBtn->setEnabled( isEnabled );
1433 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1434 for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1435 anIter2.data()->setEnabled( isEnabled );
1438 //=======================================================================
1439 // name : SMESHGUI_FilterTable::IsEditable
1440 // Purpose : Verify whether table is editable
1441 //=======================================================================
1442 bool SMESHGUI_FilterTable::IsEditable() const
1444 return !myTables[ GetType() ]->isReadOnly();
1447 //=======================================================================
1448 // name : SMESHGUI_FilterTable::SetLibsEnabled
1449 // Purpose : Show/hide buttons for work with libraries
1450 //=======================================================================
1451 void SMESHGUI_FilterTable::SetLibsEnabled( const bool isEnabled )
1455 myCopyFromBtn->show();
1460 myCopyFromBtn->hide();
1465 //=======================================================================
1466 // name : SMESHGUI_FilterTable::onCopyFromBtn
1467 // Purpose : SLOT. Called the "Copy from ..." button clicked
1468 // Display filter library dialog
1469 //=======================================================================
1470 void SMESHGUI_FilterTable::onCopyFromBtn()
1472 if ( myLibDlg == 0 )
1473 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1474 this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1476 myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1478 if ( myLibDlg->exec() == QDialog::Accepted )
1480 Copy( myLibDlg->GetTable() );
1485 //=======================================================================
1486 // name : SMESHGUI_FilterTable::onAddToBtn
1487 // Purpose : SLOT. Called the "Add to ..." button clicked
1488 // Display filter library dialog
1489 //=======================================================================
1490 void SMESHGUI_FilterTable::onAddToBtn()
1492 if ( !IsValid( true ) )
1494 if ( myLibDlg == 0 )
1495 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1496 this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1498 myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1500 myLibDlg->SetTable( this );
1505 //=======================================================================
1506 // name : SMESHGUI_FilterTable::Copy
1507 // Purpose : Initialise table with values of other table
1508 //=======================================================================
1509 void SMESHGUI_FilterTable::Copy( const SMESHGUI_FilterTable* theTable )
1513 for ( int i = 0, n = theTable->NumRows(); i < n; i++ )
1515 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1516 theTable->GetCriterion( i, aCriterion );
1517 AddCriterion( aCriterion );
1521 //=======================================================================
1522 // name : SMESHGUI_FilterTable::CurrentCell
1523 // Purpose : Returns current cell
1524 //=======================================================================
1525 bool SMESHGUI_FilterTable::CurrentCell( int& theRow, int& theCol ) const
1527 theRow = myTables[ GetType() ]->currentRow();
1528 theCol = myTables[ GetType() ]->currentColumn();
1529 return theRow >= 0 && theCol >= 0;
1532 //=======================================================================
1533 // name : SMESHGUI_FilterTable::SetText
1534 // Purpose : Set text and internal value in cell of threshold value
1535 //=======================================================================
1536 void SMESHGUI_FilterTable::SetThreshold( const int theRow,
1537 const QString& theText,
1538 const int theEntityType )
1540 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1541 aTable->setText( theRow, 2, theText );
1544 //=======================================================================
1545 // name : SMESHGUI_FilterTable::SetText
1546 // Purpose : Get text and internal value from cell of threshold value
1547 //=======================================================================
1548 bool SMESHGUI_FilterTable::GetThreshold( const int theRow,
1550 const int theEntityType )
1552 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1553 QTableItem* anItem = aTable->item( theRow, 2 );
1556 theText = anItem->text();
1564 Class : SMESHGUI_FilterDlg
1565 Description : Dialog to specify filters for VTK viewer
1569 //=======================================================================
1570 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1571 // Purpose : Constructor
1572 //=======================================================================
1573 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget* theParent,
1574 const QValueList<int>& theTypes,
1575 const char* theName )
1576 : QDialog( theParent, theName, false,
1577 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1579 construct( theTypes );
1582 //=======================================================================
1583 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1584 // Purpose : Constructor
1585 //=======================================================================
1586 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget* theParent,
1588 const char* theName )
1589 : QDialog( theParent, theName, false,
1590 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1592 QValueList<int> aTypes;
1593 aTypes.append( theType );
1594 construct( aTypes );
1597 //=======================================================================
1598 // name : SMESHGUI_FilterDlg::construct
1599 // Purpose : Construct dialog ( called by constructor )
1600 //=======================================================================
1601 void SMESHGUI_FilterDlg::construct( const QValueList<int>& theTypes )
1605 setCaption( tr( "CAPTION" ) );
1607 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
1609 myMainFrame = createMainFrame ( this );
1610 QFrame* aBtnFrame = createButtonFrame( this );
1612 aDlgLay->addWidget( myMainFrame );
1613 aDlgLay->addWidget( aBtnFrame );
1615 aDlgLay->setStretchFactor( myMainFrame, 1 );
1620 //=======================================================================
1621 // name : SMESHGUI_FilterDlg::createMainFrame
1622 // Purpose : Create frame containing dialog's input fields
1623 //=======================================================================
1624 QFrame* SMESHGUI_FilterDlg::createMainFrame( QWidget* theParent )
1626 QGroupBox* aMainFrame = new QGroupBox( 1, Qt::Horizontal, theParent );
1627 aMainFrame->setFrameStyle( QFrame::NoFrame );
1628 aMainFrame->setInsideMargin( 0 );
1632 myTable = new SMESHGUI_FilterTable( aMainFrame, myTypes );
1633 myTable->SetLibsEnabled( true );
1635 QFrame* aLine = new QFrame( myTable->GetTableGrp() );
1636 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
1638 mySetInViewer = new QCheckBox( tr( "SET_IN_VIEWER" ), myTable->GetTableGrp() );
1639 mySetInViewer->setChecked( true );
1642 mySourceGrp = createSourceGroup( aMainFrame );
1644 connect( myTable, SIGNAL( CretarionChanged( const int, const int ) ),
1645 SLOT( onCriterionChanged( const int, const int ) ) );
1647 connect( myTable, SIGNAL( CurrentChanged( int, int ) ),
1648 SLOT( onCurrentChanged( int, int ) ) );
1653 //=======================================================================
1654 // name : SMESHGUI_FilterDlg::createSourceFrame
1655 // Purpose : Create frame containing source radio button
1656 //=======================================================================
1657 QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup( QWidget* theParent )
1659 QButtonGroup* aGrp = new QButtonGroup( 1, Qt::Vertical, tr( "SOURCE" ), theParent );
1661 QRadioButton* aMeshBtn = new QRadioButton( tr( "MESH" ), aGrp );
1662 QRadioButton* aSelBtn = new QRadioButton( tr( "SELECTION" ), aGrp );
1663 QRadioButton* aGrpBtn = new QRadioButton( tr( "CURRENT_GROUP" ), aGrp );
1665 aGrp->insert( aMeshBtn, Mesh );
1666 aGrp->insert( aSelBtn, Selection );
1667 aGrp->insert( aGrpBtn, Dialog );
1669 aGrp->setButton( Selection );
1674 //=======================================================================
1675 // name : SMESHGUI_FilterDlg::updateMainButtons
1676 // Purpose : Update visibility of main buttons ( OK, Cancel, Close ... )
1677 //=======================================================================
1678 void SMESHGUI_FilterDlg::updateMainButtons()
1680 if ( myTypes.count() == 1 )
1682 myButtons[ BTN_Cancel ]->show();
1683 myButtons[ BTN_Apply ]->hide();
1684 myButtons[ BTN_Close ]->hide();
1688 myButtons[ BTN_Cancel ]->hide();
1689 myButtons[ BTN_Apply ]->show();
1690 myButtons[ BTN_Close ]->show();
1693 // updateGeometry();
1696 //=======================================================================
1697 // name : SMESHGUI_FilterDlg::createButtonFrame
1698 // Purpose : Create frame containing buttons
1699 //=======================================================================
1700 QFrame* SMESHGUI_FilterDlg::createButtonFrame( QWidget* theParent )
1702 QGroupBox* aGrp = new QGroupBox( 1, Qt::Vertical, theParent );
1704 myButtons[ BTN_OK ] = new QPushButton( tr( "SMESH_BUT_OK" ), aGrp );
1705 myButtons[ BTN_Apply ] = new QPushButton( tr( "SMESH_BUT_APPLY" ), aGrp );
1707 QLabel* aLbl = new QLabel( aGrp );
1708 aLbl->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1710 myButtons[ BTN_Cancel ] = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aGrp );
1711 myButtons[ BTN_Close ] = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aGrp );
1713 connect( myButtons[ BTN_OK ], SIGNAL( clicked() ), SLOT( onOk() ) );
1714 connect( myButtons[ BTN_Cancel ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1715 connect( myButtons[ BTN_Close ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1716 connect( myButtons[ BTN_Apply ], SIGNAL( clicked() ), SLOT( onApply() ) );
1718 updateMainButtons();
1723 //=======================================================================
1724 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
1725 // Purpose : Destructor
1726 //=======================================================================
1727 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
1731 //=======================================================================
1732 // name : SMESHGUI_FilterDlg::Init
1733 // Purpose : Init dialog fields, connect signals and slots, show dialog
1734 //=======================================================================
1735 void SMESHGUI_FilterDlg::Init( const int type )
1737 QValueList<int> aTypes;
1738 aTypes.append( type );
1742 //=======================================================================
1743 // name : SMESHGUI_FilterDlg::Init
1744 // Purpose : Init dialog fields, connect signals and slots, show dialog
1745 //=======================================================================
1746 void SMESHGUI_FilterDlg::Init( const QValueList<int>& theTypes )
1751 myMesh = SMESH::SMESH_Mesh::_nil();
1753 myIsSelectionChanged = false;
1755 myTable->Init( theTypes );
1758 if ( theTypes.count() == 1 )
1760 int aType = theTypes.first();
1761 if ( aType == SMESH::NODE ) setCaption( tr( "NODES_TLT" ) );
1762 else if ( aType == SMESH::EDGE ) setCaption( tr( "EDGES_TLT" ) );
1763 else if ( aType == SMESH::FACE ) setCaption( tr( "FACES_TLT" ) );
1764 else if ( aType == SMESH::VOLUME ) setCaption( tr( "VOLUMES_TLT" ) );
1767 setCaption( tr( "TLT" ) );
1769 qApp->processEvents();
1774 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
1775 mySMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
1777 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
1778 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
1781 mySMESHGUI->DefineDlgPosition( this, x, y );
1784 updateMainButtons();
1787 // Initialise filter table with values of previous filter
1788 QValueList<int>::const_iterator anIter;
1789 for ( anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter )
1791 myTable->Clear( *anIter );
1792 if ( !myFilter[ *anIter ]->_is_nil() )
1794 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1795 if ( myFilter[ *anIter ]->GetCriteria( aCriteria ) )
1797 for ( int i = 0, n = aCriteria->length(); i < n; i++ )
1798 myTable->AddCriterion( aCriteria[ i ], *anIter );
1803 if ( myInsertState.contains( theTypes.first() ) )
1804 mySetInViewer->setChecked( myInsertState[ theTypes.first() ] );
1806 mySetInViewer->setChecked( true );
1807 if ( myApplyToState.contains( theTypes.first() ) )
1808 mySourceGrp->setButton( myApplyToState[ theTypes.first() ] );
1810 mySourceGrp->setButton( Selection );
1813 //=======================================================================
1814 // name : SMESHGUI_FilterDlg::onOk
1815 // Purpose : SLOT called when "Ok" button pressed.
1816 // Assign filters VTK viewer and close dialog
1817 //=======================================================================
1818 void SMESHGUI_FilterDlg::onOk()
1822 mySelection->ClearFilters();
1823 disconnect( mySMESHGUI, 0, this, 0 );
1824 disconnect( mySelection, 0, this, 0 );
1825 mySMESHGUI->ResetState() ;
1831 //=======================================================================
1832 // name : SMESHGUI_FilterDlg::onClose
1833 // Purpose : SLOT called when "Close" button pressed. Close dialog
1834 //=======================================================================
1835 void SMESHGUI_FilterDlg::onClose()
1837 // Restore previously selected object
1840 mySelection->ClearFilters();
1841 mySelection->Clear();
1842 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
1843 for ( ; anIter.More(); anIter.Next() )
1845 mySelection->AddIObject( anIter.Key() );
1847 TColStd_MapOfInteger aResMap;
1848 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
1849 for ( int i = 1, n = anIndMap.Extent(); i <= n; i++ )
1850 aResMap.Add( anIndMap( i ) );
1852 mySelection->AddOrRemoveIndex( anIter.Key(), aResMap, false );
1856 disconnect( mySMESHGUI, 0, this, 0 );
1857 disconnect( mySelection, 0, this, 0 );
1858 mySMESHGUI->ResetState() ;
1863 //=======================================================================
1864 // name : SMESHGUI_FilterDlg::onDeactivate
1865 // Purpose : SLOT called when dialog must be deativated
1866 //=======================================================================
1867 void SMESHGUI_FilterDlg::onDeactivate()
1869 setEnabled( false );
1872 //=======================================================================
1873 // name : SMESHGUI_FilterDlg::enterEvent
1874 // Purpose : Event filter
1875 //=======================================================================
1876 void SMESHGUI_FilterDlg::enterEvent( QEvent* )
1878 // mySMESHGUI->EmitSignalDeactivateDialog();
1883 //=================================================================================
1884 // function : closeEvent()
1886 //=================================================================================
1887 void SMESHGUI_FilterDlg::closeEvent( QCloseEvent* e )
1892 //=======================================================================
1893 // name : SMESHGUI_FilterDlg::getIdsFromWg
1894 // Purpose : Retrieve list of ids from given widget
1895 //=======================================================================
1896 void SMESHGUI_FilterDlg::getIdsFromWg( const QWidget* theWg, QValueList<int>& theRes ) const
1902 if ( theWg->inherits( "QListBox" ) )
1904 QListBox* aListBox = ( QListBox* )theWg;
1906 for ( int i = 0, n = aListBox->count(); i < n; i++ )
1908 int anId = aListBox->text( i ).toInt( &b );
1910 theRes.append( anId );
1913 else if ( theWg->inherits( "QLineEdit" ) )
1915 QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1916 QString aStr = aLineEdit->text();
1917 QRegExp aRegExp( "(\\d+)" );
1922 aPos = aRegExp.search( aStr, aPos );
1925 int anId = aRegExp.cap( 1 ).toInt( &b );
1927 theRes.append( anId );
1928 aPos += aRegExp.matchedLength();
1934 //=======================================================================
1935 // name : SMESHGUI_FilterDlg::getSelMode
1936 // Purpose : Get selection mode of specified type
1937 //=======================================================================
1938 Selection_Mode SMESHGUI_FilterDlg::getSelMode( const int theType ) const
1942 case SMESH::NODE : return NodeSelection;
1943 case SMESH::EDGE : return EdgeSelection;
1944 case SMESH::FACE : return FaceSelection;
1945 case SMESH::VOLUME : return VolumeSelection;
1946 default : return ActorSelection;
1951 //=======================================================================
1952 // name : SMESHGUI_FilterDlg::setIdsToWg
1953 // Purpose : Insert identifiers in specified widgets
1954 //=======================================================================
1955 void SMESHGUI_FilterDlg::setIdsToWg( QWidget* theWg, const QValueList<int>& theIds )
1960 if ( theWg->inherits( "QListBox" ) )
1962 QListBox* aListBox = ( QListBox* )theWg;
1965 QStringList aStrList;
1966 QValueList<int>::const_iterator anIter;
1967 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
1968 aStrList.append( QString( "%1" ).arg( *anIter ) );
1970 aListBox->insertStringList( aStrList );
1972 else if ( theWg->inherits( "QLineEdit" ) )
1974 QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1976 QValueList<int>::const_iterator anIter;
1978 for ( anIter = theIds.begin(); anIter != theIds.end(); ++ anIter )
1979 aStr += QString( "%1 " ).arg( *anIter );
1981 if ( !aStr.isEmpty() )
1982 aStr.remove( aStr.length() - 1, 1 );
1984 aLineEdit->setText( aStr );
1988 //=======================================================================
1989 // name : SMESHGUI_FilterDlg::isValid
1990 // Purpose : Verify validity of input data
1991 //=======================================================================
1992 bool SMESHGUI_FilterDlg::isValid() const
1994 if ( !myTable->IsValid() )
1997 for ( int i = 0, n = myTable->NumRows(); i < n; i++ )
1999 int aType = myTable->GetCriterionType( i );
2000 if ( aType == FT_BelongToGeom ||
2001 aType == FT_BelongToPlane ||
2002 aType == FT_BelongToCylinder )
2005 myTable->GetThreshold( i, aName );
2007 SALOMEDS::Study::ListOfSObject_var aList = SMESHGUI::GetSMESHGUI()->GetActiveStudy()->
2008 getStudyDocument()->FindObjectByName( aName.latin1(), "GEOM" );
2009 if ( aList->length() == 0 )
2011 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2012 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "BAD_SHAPE_NAME" ).arg( aName ), QMessageBox::Ok );
2016 if ( aType == FT_BelongToCylinder || aType == FT_BelongToPlane )
2018 GEOM::GEOM_Object_var aGeomObj =
2019 GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
2020 if ( !aGeomObj->_is_nil() )
2023 if ( !GEOMBase::GetShape( aGeomObj, aFace ) ||
2025 aFace.ShapeType() != TopAbs_FACE )
2027 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2028 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2032 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aFace ) );
2033 if ( aSurf.IsNull() )
2035 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2036 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2040 if ( aType == FT_BelongToPlane && !aSurf->IsKind( STANDARD_TYPE( Geom_Plane ) ) )
2042 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2043 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_PLANE" ).arg( aName ), QMessageBox::Ok );
2047 if ( aType == FT_BelongToCylinder && !aSurf->IsKind( STANDARD_TYPE( Geom_CylindricalSurface ) ) )
2049 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2050 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_CYLINDER" ).arg( aName ), QMessageBox::Ok );
2061 //=======================================================================
2062 // name : SMESHGUI_FilterDlg::SetSourceWg
2063 // Purpose : Set widget of parent dialog containing idsto be filtered if
2064 // user select corresponding source radio button
2065 //=======================================================================
2066 void SMESHGUI_FilterDlg::SetSourceWg( QWidget* theWg )
2071 //=======================================================================
2072 // name : SMESHGUI_FilterDlg::SetGroupIds
2073 // Purpose : Set mesh
2074 //=======================================================================
2075 void SMESHGUI_FilterDlg::SetMesh( SMESH::SMESH_Mesh_ptr theMesh )
2080 //=======================================================================
2081 // name : SMESHGUI_FilterDlg::SetSelection
2082 // Purpose : Get filtered ids
2083 //=======================================================================
2084 void SMESHGUI_FilterDlg::SetSelection( SALOME_Selection* theSel )
2087 disconnect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
2089 mySelection = theSel;
2094 const SALOME_ListIO& anObjs = mySelection->StoredIObjects();
2095 SALOME_ListIteratorOfListIO anIter( anObjs );
2096 for ( ;anIter.More(); anIter.Next() )
2098 TColStd_IndexedMapOfInteger aMap;
2099 mySelection->GetIndex( anIter.Value(), aMap );
2100 myIObjects.Bind( anIter.Value(), aMap );
2103 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
2111 //=======================================================================
2112 // name : SMESHGUI_FilterDlg::onApply
2113 // Purpose : SLOT called when "Apply" button pressed.
2114 // Assign filters to VTK viewer
2115 //=======================================================================
2116 bool SMESHGUI_FilterDlg::onApply()
2123 int aCurrType = myTable->GetType();
2125 if ( !createFilter( aCurrType ) )
2128 insertFilterInViewer();
2130 if ( !myFilter[ aCurrType ]->GetPredicate()->_is_nil() )
2132 QValueList<int> aResultIds;
2133 filterSource( aCurrType, aResultIds );
2134 selectInViewer( aCurrType, aResultIds );
2137 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2138 myApplyToState[ aCurrType ] = mySourceGrp->id( mySourceGrp->selected() );
2141 catch( const SALOME::SALOME_Exception& S_ex )
2143 QtCatchCorbaException( S_ex );
2152 //=======================================================================
2153 // name : SMESHGUI_FilterDlg::createFilter
2154 // Purpose : Create predicate for given type
2155 //=======================================================================
2156 bool SMESHGUI_FilterDlg::createFilter( const int theType )
2158 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2159 if ( aFilterMgr->_is_nil() )
2162 int n = myTable->NumRows();
2164 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2165 aCriteria->length( n );
2167 long aPrecision = -1;
2168 if ( QAD_CONFIG->hasSetting( "SMESH:ControlsPrecision" ) )
2170 QString aStr = QAD_CONFIG->getSetting( "SMESH:ControlsPrecision" );
2172 int aVal = aStr.toInt( &isOk );
2177 for ( CORBA::ULong i = 0; i < n; i++ )
2179 SMESH::Filter::Criterion aCriterion = createCriterion();
2180 myTable->GetCriterion( i, aCriterion );
2181 aCriterion.Precision = aPrecision;
2182 aCriteria[ i ] = aCriterion;
2185 myFilter[ theType ] = aFilterMgr->CreateFilter();
2186 myFilter[ theType ]->SetCriteria( aCriteria.inout() );
2191 //=======================================================================
2192 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2193 // Purpose : Insert filter in viewer
2194 //=======================================================================
2195 void SMESHGUI_FilterDlg::insertFilterInViewer()
2197 if ( VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle() )
2199 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2201 if ( myFilter[ myTable->GetType() ]->_is_nil() ||
2202 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2203 !mySetInViewer->isChecked() )
2204 SMESH::RemoveFilter( getFilterId( anEntType ), aStyle );
2207 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2208 aFilter->SetPredicate( myFilter[ myTable->GetType() ]->GetPredicate() );
2209 SMESH::SetFilter( aFilter, aStyle );
2214 //=======================================================================
2215 // name : SMESHGUI_FilterDlg::filterSource
2216 // Purpose : Filter source ids
2217 //=======================================================================
2218 void SMESHGUI_FilterDlg::filterSource( const int theType,
2219 QValueList<int>& theResIds )
2222 if ( myFilter[ theType ]->_is_nil() )
2225 int aSourceId = mySourceGrp->id( mySourceGrp->selected() );
2227 if ( aSourceId == Mesh )
2229 if ( myMesh->_is_nil() )
2231 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId( myMesh );
2232 for ( int i = 0, n = anIds->length(); i < n; i++ )
2233 theResIds.append( anIds[ i ] );
2235 else if ( aSourceId == Selection )
2237 filterSelectionSource( theType, theResIds );
2239 else if ( aSourceId == Dialog )
2241 // retrieve ids from dialog
2242 QValueList<int> aDialogIds;
2243 getIdsFromWg( mySourceWg, aDialogIds );
2245 if ( myMesh->_is_nil() )
2247 theResIds = aDialogIds;
2252 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2253 aPred->SetMesh( myMesh );
2254 QValueList<int>::const_iterator anIter;
2255 for ( anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter )
2256 if ( aPred->IsSatisfy( *anIter ) )
2257 theResIds.append( *anIter );
2259 // set ids to the dialog
2260 setIdsToWg( mySourceWg, theResIds );
2264 //=======================================================================
2265 // name : SMESHGUI_FilterDlg::filterSelectionSource
2266 // Purpose : Filter source selection
2267 //=======================================================================
2268 void SMESHGUI_FilterDlg::filterSelectionSource( const int theType,
2269 QValueList<int>& theResIds )
2272 if ( myMesh->_is_nil() || mySelection == 0 )
2275 // Create map of entities to be filtered
2276 TColStd_MapOfInteger aToBeFiltered;
2277 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
2279 for ( ; anIter.More(); anIter.Next() )
2282 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIter.Key() );
2283 if ( !aSubMesh->_is_nil() )
2285 if ( aSubMesh->GetFather()->GetId() == myMesh->GetId() )
2287 SMESH::long_array_var anIds =
2288 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2289 for ( int i = 0, n = anIds->length(); i < n; i++ )
2290 aToBeFiltered.Add( anIds[ i ] );
2295 SMESH::SMESH_GroupBase_var aGroup =
2296 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( anIter.Key() );
2297 if ( !aGroup->_is_nil() )
2299 if ( aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId() )
2301 SMESH::long_array_var anIds = aGroup->GetListOfID();
2302 for ( int i = 0, n = anIds->length(); i < n; i++ )
2303 aToBeFiltered.Add( anIds[ i ] );
2308 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIter.Key() );
2309 if ( !aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId() )
2311 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2313 if ( aSelMap.Extent() > 0 )
2315 if(SMESH_Actor *anActor = SMESH::FindActorByEntry( anIter.Key()->getEntry() ) )
2317 for ( int i = 1; i <= aSelMap.Extent(); i++ )
2318 aToBeFiltered.Add( aSelMap(i) );
2325 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2326 aPred->SetMesh( myMesh );
2327 TColStd_MapIteratorOfMapOfInteger aResIter( aToBeFiltered );
2328 for ( ; aResIter.More(); aResIter.Next() )
2329 if ( aPred->IsSatisfy( aResIter.Key() ) )
2330 theResIds.append( aResIter.Key() );
2333 //=======================================================================
2334 // name : SMESHGUI_FilterDlg::selectInViewer
2335 // Purpose : Select given entities in viewer
2336 //=======================================================================
2337 void SMESHGUI_FilterDlg::selectInViewer( const int theType, const QValueList<int>& theIds )
2339 if ( mySelection == 0 || myMesh->_is_nil() )
2342 mySelection->ClearFilters();
2344 // Set new selection mode if necessary
2345 Selection_Mode aSelMode = getSelMode( theType );
2346 if ( aSelMode != mySelection->SelectionMode() )
2348 mySelection->ClearIObjects();
2349 mySelection->ClearFilters();
2350 if ( aSelMode == NodeSelection )
2351 SMESH::SetPointRepresentation(true);
2352 QAD_Application::getDesktop()->SetSelectionMode( aSelMode );
2356 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2357 if ( !anActor || !anActor->hasIO() )
2360 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2361 mySelection->ClearIObjects();
2362 mySelection->AddIObject( anIO, false );
2364 // Remove filter corresponding to the current type from viewer
2365 int aType = myTable->GetType();
2366 int aFilterId = SMESHGUI_UnknownFilter;
2367 if ( aType == SMESH::EDGE ) aFilterId = SMESHGUI_EdgeFilter;
2368 else if ( aType == SMESH::FACE ) aFilterId = SMESHGUI_FaceFilter;
2369 else if ( aType == SMESH::VOLUME ) aFilterId = SMESHGUI_VolumeFilter;
2370 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter( aFilterId );
2371 SMESH::RemoveFilter( aFilterId );
2374 TColStd_MapOfInteger aMap;
2375 QValueList<int>::const_iterator anIter;
2376 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
2378 aMap.Add( *anIter );
2381 // Set new selection
2382 mySelection->AddOrRemoveIndex( anIO, aMap, false, true );
2384 // insert previously stored filter in viewer if necessary
2385 if ( !aFilter.IsNull() )
2386 SMESH::SetFilter( aFilter );
2389 //=======================================================================
2390 // name : SMESHGUI_FilterDlg::createCriterion
2391 // Purpose : Create criterion structure with default values
2392 //=======================================================================
2393 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2395 SMESH::Filter::Criterion aCriterion;
2397 aCriterion.Type = FT_Undefined;
2398 aCriterion.Compare = FT_Undefined;
2399 aCriterion.Threshold = 0;
2400 aCriterion.UnaryOp = FT_Undefined;
2401 aCriterion.BinaryOp = FT_Undefined;
2402 aCriterion.ThresholdStr = "";
2403 aCriterion.TypeOfElement = SMESH::ALL;
2408 //=======================================================================
2409 // name : SMESHGUI_FilterDlg::onSelectionDone
2410 // Purpose : SLOT called when selection changed.
2411 // If current cell corresponds to the threshold value of
2412 // BelongToGeom criterion name of selected object is set in this cell
2413 //=======================================================================
2414 void SMESHGUI_FilterDlg::onSelectionDone()
2417 if ( mySelection->IObjectCount() != 1 ||
2418 !myTable->CurrentCell( aRow, aCol ) ||
2419 myTable->GetCriterionType( aRow ) != FT_BelongToGeom &&
2420 myTable->GetCriterionType( aRow ) != FT_BelongToPlane &&
2421 myTable->GetCriterionType( aRow ) != FT_BelongToCylinder)
2424 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject() ;
2425 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO ) ;
2426 if ( !anObj->_is_nil() )
2427 myTable->SetThreshold( aRow, anIO->getName() );
2430 //=======================================================================
2431 // name : SMESHGUI_FilterDlg::onCriterionChanged
2432 // Purpose : SLOT called when cretarion of current row changed. Update selection
2433 //=======================================================================
2434 void SMESHGUI_FilterDlg::onCriterionChanged( const int , const int )
2439 //=======================================================================
2440 // name : SMESHGUI_FilterDlg::onCurrentChanged
2441 // Purpose : SLOT called when current row changed. Update selection
2442 //=======================================================================
2443 void SMESHGUI_FilterDlg::onCurrentChanged( int, int )
2448 //=======================================================================
2449 // name : SMESHGUI_FilterDlg::updateSelection
2450 // Purpose : UpdateSelection in accordance with current row
2451 //=======================================================================
2452 void SMESHGUI_FilterDlg::updateSelection()
2454 if ( mySelection == 0 )
2457 mySelection->ClearFilters();
2461 if ( myTable->CurrentCell( aRow, aCol ) &&
2462 ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom ||
2463 myTable->GetCriterionType( aRow ) == FT_BelongToPlane ||
2464 myTable->GetCriterionType( aRow ) == FT_BelongToCylinder ) )
2466 if ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom )
2467 mySelection->AddFilter( new SALOME_TypeFilter( "GEOM" ) );
2468 else if ( myTable->GetCriterionType( aRow ) == FT_BelongToPlane )
2469 mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Plane ) );
2470 else if ( myTable->GetCriterionType( aRow ) == FT_BelongToCylinder )
2471 mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Cylinder ) );
2473 myIsSelectionChanged = true;
2477 if ( myIsSelectionChanged )
2478 mySelection->AddFilter( new SALOME_TypeFilter( "This filter deactivate selection" ) );