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>
85 #include "SALOMEconfig.h"
86 #include CORBA_SERVER_HEADER(SMESH_Group)
91 using namespace SMESH;
93 static int maxLength( const QMap<int, QString> theMap, const QFontMetrics& theMetrics )
96 QMap<int, QString>::const_iterator anIter;
97 for ( anIter = theMap.begin(); anIter != theMap.end(); ++anIter )
98 aRes = Max( aRes, theMetrics.width( anIter.data() ) );
102 static int getFilterId( SMESH::ElementType theType )
106 case SMESH::NODE : return SMESHGUI_NodeFilter;
107 case SMESH::EDGE : return SMESHGUI_EdgeFilter;
108 case SMESH::FACE : return SMESHGUI_FaceFilter;
109 case SMESH::VOLUME : return SMESHGUI_VolumeFilter;
110 case SMESH::ALL : return SMESHGUI_AllElementsFilter;
111 default : return SMESHGUI_UnknownFilter;
116 Class : SMESHGUI_FilterTable::AdditionalWidget
117 Description : Class for storing additional parameters of criterion
120 class SMESHGUI_FilterTable::AdditionalWidget : public QFrame
127 AdditionalWidget( QWidget* theParent );
128 virtual ~AdditionalWidget();
130 virtual void GetParameters( QValueList<int>& ) const;
131 virtual bool IsValid( const bool theMsg = true ) const;
132 virtual double GetDouble( const int theId ) const;
133 virtual int GetInteger( const int theId ) const;
134 virtual QString GetString( const int theId ) const;
135 virtual void SetDouble( const int theId, const double theVal );
136 virtual void SetInteger( const int theId, const int theVal );
137 virtual void SetString( const int theId, const QString& theVal );
138 void SetEditable( const int theId, const bool isEditable );
139 void SetEditable( const bool isEditable );
142 QMap< int, QLineEdit* > myLineEdits;
145 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget( QWidget* theParent )
146 : QFrame( theParent )
148 QLabel* aLabel = new QLabel( tr( "SMESH_TOLERANCE" ), this );
149 myLineEdits[ Tolerance ] = new QLineEdit( this );
150 QDoubleValidator* aValidator = new QDoubleValidator( myLineEdits[ Tolerance ] );
151 aValidator->setBottom( 0 );
152 myLineEdits[ Tolerance ]->setValidator( aValidator );
154 QHBoxLayout* aLay = new QHBoxLayout( this, 0, SPACING );
155 aLay->addWidget( aLabel );
156 aLay->addWidget( myLineEdits[ Tolerance ] );
158 QSpacerItem* aSpacer = new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum );
159 aLay->addItem( aSpacer );
161 QString aText = QString( "%1" ).arg( Precision::Confusion() );
162 myLineEdits[ Tolerance ]->setText( aText );
164 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
168 void SMESHGUI_FilterTable::AdditionalWidget::GetParameters( QValueList<int>& theList ) const
171 theList.append( Tolerance );
174 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid( const bool theMsg ) const
179 QValueList<int> aParams;
180 GetParameters( aParams );
181 QValueList<int>::const_iterator anIter;
182 for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
184 const QLineEdit* aWg = myLineEdits[ *anIter ];
186 QString aText = aWg->text();
187 if ( aWg->isEnabled() && aWg->validator()->validate( aText, p ) != QValidator::Acceptable )
190 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
191 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SMESHGUI_INVALID_PARAMETERS" ), QMessageBox::Ok );
199 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble( const int theId ) const
201 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toDouble() : 0;
204 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger( const int theId ) const
206 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text().toInt() : 0;
209 QString SMESHGUI_FilterTable::AdditionalWidget::GetString( const int theId ) const
211 return myLineEdits.contains( theId ) ? myLineEdits[ theId ]->text() : QString("");
214 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble( const int theId, const double theVal )
216 if ( myLineEdits.contains( theId ) )
217 myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
220 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger( const int theId, const int theVal )
222 if ( myLineEdits.contains( theId ) )
223 myLineEdits[ theId ]->setText( QString( "%1" ).arg( theVal ) );
226 void SMESHGUI_FilterTable::AdditionalWidget::SetString( const int theId, const QString& theVal )
228 if ( myLineEdits.contains( theId ) )
229 myLineEdits[ theId ]->setText( theVal );
232 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const int theId, const bool isEditable )
234 if ( myLineEdits.contains( theId ) )
235 myLineEdits[ theId ]->setEdited( isEditable );
238 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable( const bool isEditable )
240 QValueList<int> aParams;
241 GetParameters( aParams );
242 QValueList<int>::const_iterator anIter;
243 for ( anIter = aParams.begin(); anIter != aParams.end(); ++anIter )
244 myLineEdits[ *anIter ]->setEdited( isEditable );
248 Class : SMESHGUI_FilterTable::ComboItem
249 Description : Combo table item. Identificator corresponding to string may be assigned
252 class SMESHGUI_FilterTable::ComboItem : public QComboTableItem
256 ComboItem( QTable*, const QMap<int, QString>& );
257 virtual ~ComboItem();
259 virtual void setStringList ( const QStringList & l );
260 void setStringList( const QMap<int, QString>& theIds );
262 int GetValue() const;
263 void SetValue( const int );
267 QMap<int, int> myNumToId;
268 QMap<int, int> myIdToNum;
271 SMESHGUI_FilterTable::ComboItem::ComboItem( QTable* theParent,
272 const QMap<int, QString>& theIds )
273 : QComboTableItem( theParent, QStringList() )
275 setStringList( theIds );
278 void SMESHGUI_FilterTable::ComboItem::setStringList( const QStringList & l )
280 QComboTableItem::setStringList( l );
283 void SMESHGUI_FilterTable::ComboItem::setStringList( const QMap<int, QString>& theIds )
287 QMap<int, QString>::const_iterator anIter;
288 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
290 myNumToId[ i ] = anIter.key();
291 myIdToNum[ anIter.key() ] = i;
292 aList.append( anIter.data() );
296 setStringList( aList );
299 SMESHGUI_FilterTable::ComboItem::~ComboItem()
303 int SMESHGUI_FilterTable::ComboItem::GetValue() const
305 return myNumToId[ currentItem() ];
308 void SMESHGUI_FilterTable::ComboItem::SetValue( const int theVal )
310 setCurrentItem( myIdToNum[ theVal ] );
315 Class : SMESHGUI_FilterTable::Table
316 Description : Table used by this widget
319 class SMESHGUI_FilterTable::Table : public QTable
322 Table( QWidget* parent );
323 Table( int numRows, int numCols, QWidget* parent = 0 );
326 void SetEditable( const bool state, const int row, const int col );
327 bool IsEditable( const int row, const int col ) const;
329 virtual void insertRows( int row, int count = 1 );
330 virtual QString text( int row, int col ) const;
333 //=======================================================================
334 // name : SMESHGUI_FilterTable::Table::Table
335 // Purpose : Constructor
336 //=======================================================================
337 SMESHGUI_FilterTable::Table::Table( QWidget* parent )
338 : QTable( parent, "SMESHGUI_FilterTable::Table" )
342 SMESHGUI_FilterTable::Table::Table( int numRows, int numCols, QWidget* parent )
343 : QTable( numRows, numCols, parent, "SMESHGUI_FilterTable::Table" )
347 SMESHGUI_FilterTable::Table::~Table()
351 //=======================================================================
352 // name : SMESHGUI_FilterTable::Table::SetEditable
353 // Purpose : Set editable of specified cell
354 //=======================================================================
355 void SMESHGUI_FilterTable::Table::SetEditable( const bool isEditable, const int row, const int col )
357 QTableItem* anItem = item( row, col );
362 setItem( row, col, new QTableItem( this, QTableItem::Never, "" ) );
364 setItem( row, col, new QTableItem( this, QTableItem::OnTyping, "" ) );
367 //=======================================================================
368 // name : SMESHGUI_FilterTable::Table::IsEditable
369 // Purpose : Verify wheter cell is editable
370 //=======================================================================
371 bool SMESHGUI_FilterTable::Table::IsEditable( const int row, const int col ) const
373 QTableItem* anItem = item( row, col );
374 return anItem == 0 || anItem->editType() != QTableItem::Never;
377 //=======================================================================
378 // name : SMESHGUI_FilterTable::Table::insertRows
379 // Purpose : Insert rows ( virtual redefined )
380 //=======================================================================
381 void SMESHGUI_FilterTable::Table::insertRows( int row, int count )
383 int anEditRow = currEditRow();
384 int anEditCol = currEditCol();
386 if ( anEditRow >= 0 && anEditCol >= 0 )
387 endEdit( anEditRow, anEditCol, true, false );
389 QTable::insertRows( row, count );
392 //=======================================================================
393 // name : SMESHGUI_FilterTable::Table::text
394 // Purpose : Get text from cell ( virtual redefined )
395 //=======================================================================
396 QString SMESHGUI_FilterTable::Table::text( int row, int col ) const
398 int anEditRow = currEditRow();
399 int anEditCol = currEditCol();
401 if ( anEditRow >= 0 && anEditCol >= 0 && anEditRow == row && anEditCol == col )
402 ((Table*)this)->endEdit( row, col, true, false );
404 return QTable::text( row, col );
410 Class : SMESHGUI_FilterTable
411 Description : Frame containig
412 - Button group for switching entity type
413 - Table for displaying filter criterions
414 - Buttons for editing table and filter libraries
417 //=======================================================================
418 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
419 // Purpose : Constructor
420 //=======================================================================
421 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent,
429 //=======================================================================
430 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
431 // Purpose : Constructor
432 //=======================================================================
433 SMESHGUI_FilterTable::SMESHGUI_FilterTable( QWidget* parent,
434 const QValueList<int>& types )
441 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
445 //=======================================================================
446 // name : SMESHGUI_FilterTable::Init
447 // Purpose : Create table corresponding to the specified type
448 //=======================================================================
449 void SMESHGUI_FilterTable::Init( const int type )
451 QValueList<int> aTypes;
452 aTypes.append( type );
456 //=======================================================================
457 // name : SMESHGUI_FilterTable::Init
458 // Purpose : Create table corresponding to the specified type
459 //=======================================================================
460 void SMESHGUI_FilterTable::Init( const QValueList<int>& theTypes )
462 if ( theTypes.isEmpty() )
465 // Create buttons if necessary
467 if ( myTables.isEmpty() )
469 int aType = theTypes.first();
471 // create main layout
472 QVBoxLayout* aMainLay = new QVBoxLayout( this );
473 QGroupBox* aMainGrp = new QGroupBox( 1, Qt::Horizontal, this );
474 aMainGrp->setFrameStyle( QFrame::NoFrame );
475 aMainGrp->setInsideMargin( 0 );
476 aMainLay->addWidget( aMainGrp );
478 // create switch of entity types
479 myEntityTypeGrp = new QButtonGroup( 1, Qt::Vertical, tr( "ENTITY_TYPE" ), aMainGrp );
480 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
481 QMap<int, QString>::const_iterator anIter;
482 for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
484 QRadioButton* aBtn = new QRadioButton( anIter.data(), myEntityTypeGrp );
485 myEntityTypeGrp->insert( aBtn, anIter.key() );
488 myTableGrp = new QGroupBox( 1, Qt::Horizontal, tr( "FILTER" ), aMainGrp );
489 QFrame* aTableFrame = new QFrame( myTableGrp );
492 mySwitchTableGrp = new QGroupBox( 1, Qt::Horizontal, aTableFrame );
493 mySwitchTableGrp->setFrameStyle( QFrame::NoFrame );
494 mySwitchTableGrp->setInsideMargin( 0 );
496 myTables[ aType ] = createTable( mySwitchTableGrp, aType );
499 myAddBtn = new QPushButton( tr( "ADD" ), aTableFrame );
500 myRemoveBtn = new QPushButton( tr( "REMOVE" ), aTableFrame );
501 myClearBtn = new QPushButton( tr( "CLEAR" ), aTableFrame );
502 myInsertBtn = new QPushButton( tr( "INSERT" ), aTableFrame );
503 myCopyFromBtn = new QPushButton( tr( "COPY_FROM" ), aTableFrame );
504 myAddToBtn = new QPushButton( tr( "ADD_TO" ), aTableFrame );
506 myAddBtn->setAutoDefault( false );
507 myRemoveBtn->setAutoDefault( false );
508 myClearBtn->setAutoDefault( false );
509 myInsertBtn->setAutoDefault( false );
510 myCopyFromBtn->setAutoDefault( false );
511 myAddToBtn->setAutoDefault( false );
513 myCopyFromBtn->hide();
517 QGridLayout* aLay = new QGridLayout( aTableFrame, 8, 2, 0, SPACING );
519 aLay->addMultiCellWidget( mySwitchTableGrp, 0, 6, 0, 0 );
520 aLay->addWidget( myAddBtn, 0, 1 );
521 aLay->addWidget( myInsertBtn, 1, 1 );
522 aLay->addWidget( myRemoveBtn, 2, 1 );
523 aLay->addWidget( myClearBtn, 3, 1 );
524 aLay->addWidget( myCopyFromBtn, 5, 1 );
525 aLay->addWidget( myAddToBtn, 6, 1 );
526 aLay->addMultiCellWidget( createAdditionalFrame( aTableFrame ), 7, 7, 0, 1 );
528 aLay->setColStretch( 0, 1 );
529 aLay->setColStretch( 1, 0 );
531 QSpacerItem* aVSpacer = new QSpacerItem( 0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding );
532 aLay->addItem( aVSpacer, 4, 1 );
535 connect( myAddBtn, SIGNAL( clicked() ), this, SLOT( onAddBtn() ) );
536 connect( myInsertBtn, SIGNAL( clicked() ), this, SLOT( onInsertBtn() ) );
537 connect( myRemoveBtn, SIGNAL( clicked() ), this, SLOT( onRemoveBtn() ) );
538 connect( myClearBtn, SIGNAL( clicked() ), this, SLOT( onClearBtn() ) );
540 connect( myCopyFromBtn, SIGNAL( clicked() ), this, SLOT( onCopyFromBtn() ) );
541 connect( myAddToBtn, SIGNAL( clicked() ), this, SLOT( onAddToBtn() ) );
543 connect( myEntityTypeGrp, SIGNAL( clicked( int ) ), this, SLOT( onEntityType( int ) ) );
548 // Hide buttons of entity types if necessary
549 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
550 QMap<int, QString>::const_iterator anIt;
551 for ( anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt )
553 QButton* aBtn = myEntityTypeGrp->find( anIt.key() );
554 theTypes.contains( anIt.key() ) ? aBtn->show() : aBtn->hide();
557 // select first button if there is no selected buttons or it is hidden
558 QButton* aBtn = myEntityTypeGrp->selected();
559 if ( aBtn == 0 || theTypes.find( myEntityTypeGrp->id( aBtn ) ) == theTypes.end() )
560 myEntityTypeGrp->setButton( theTypes.first() );
562 if ( theTypes.count() == 1 )
563 myEntityTypeGrp->hide();
565 myEntityTypeGrp->show();
567 myTableGrp->updateGeometry();
568 int aType = myEntityTypeGrp->id( myEntityTypeGrp->selected() );
569 onEntityType( aType );
572 //=======================================================================
573 // name : SMESHGUI_FilterTable::GetTableGrp
574 // Purpose : Get group box containing table. May be used for adding new widgets in it
575 ////=======================================================================
576 QWidget* SMESHGUI_FilterTable::createAdditionalFrame( QWidget* theParent )
578 QFrame* aFrame = new QFrame( theParent );
580 QFrame* aLine1 = new QFrame( aFrame );
581 QFrame* aLine2 = new QFrame( aFrame );
582 aLine1->setFrameStyle( QFrame::HLine | QFrame::Sunken );
583 aLine2->setFrameStyle( QFrame::HLine | QFrame::Sunken );
584 aLine1->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
585 aLine2->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed) );
587 QLabel* aLabel = new QLabel( tr( "ADDITIONAL_PARAMETERS" ), aFrame );
589 myWgStack = new QWidgetStack( aFrame );
591 QGridLayout* aLay = new QGridLayout( aFrame, 2, 3, 0, SPACING );
592 aLay->addWidget( aLine1, 0, 0 );
593 aLay->addWidget( aLabel, 0, 1 );
594 aLay->addWidget( aLine2, 0, 2 );
595 aLay->addMultiCellWidget( myWgStack, 1, 1, 0, 2 );
600 //=======================================================================
601 // name : SMESHGUI_FilterTable::GetTableGrp
602 // Purpose : Get group box containing table. May be used for adding new widgets in it
603 ////=======================================================================
604 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
609 //=======================================================================
610 // name : SMESHGUI_FilterTable::onEntityType
611 // Purpose : SLOT. Called when entity type changed.
612 // Display corresponding table
613 //=======================================================================
614 void SMESHGUI_FilterTable::onEntityType( int theType )
616 if ( myEntityType == theType )
620 emit NeedValidation();
623 myEntityTypeGrp->setButton( myEntityType );
627 myEntityType = theType;
629 if ( !myTables.contains( theType ) )
630 myTables[ theType ] = createTable( mySwitchTableGrp, theType );
632 TableMap::iterator anIter;
633 for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
634 myEntityType == anIter.key() ? anIter.data()->show() : anIter.data()->hide();
637 qApp->processEvents();
638 myTables[ myEntityType ]->updateGeometry();
641 emit EntityTypeChanged( theType );
645 //=======================================================================
646 // name : SMESHGUI_FilterTable::IsValid
647 // Purpose : Verify validity of entered data
648 //=======================================================================
649 bool SMESHGUI_FilterTable::IsValid( const bool theMess, const int theEntityType ) const
651 int aType = theEntityType == -1 ? GetType() : theEntityType;
653 Table* aTable = myTables[ aType ];
654 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
656 int aCriterion = GetCriterionType( i, aType );
658 if ( aCriterion == FT_RangeOfIds ||
659 aCriterion == FT_BelongToGeom ||
660 aCriterion == FT_BelongToPlane ||
661 aCriterion == FT_BelongToCylinder ||
662 aCriterion == FT_LyingOnGeom)
664 if ( aTable->text( i, 2 ).isEmpty() )
667 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
668 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
675 aTable->blockSignals( true );
676 double aThreshold = ( int )aTable->text( i, 2 ).toDouble( &aRes );
677 aTable->blockSignals( false );
679 if ( !aRes && aTable->IsEditable( i, 2 ) )
682 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
683 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "ERROR" ), QMessageBox::Ok );
686 else if ( aType == SMESH::EDGE &&
687 GetCriterionType( i, aType ) == SMESH::FT_MultiConnection &&
691 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
692 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "MULTIEDGES_ERROR" ), QMessageBox::Ok );
697 QTableItem* anItem = aTable->item( i, 0 );
698 if ( myAddWidgets.contains( anItem ) && !myAddWidgets[ anItem ]->IsValid() )
705 //=======================================================================
706 // name : SMESHGUI_FilterTable::SetValidity
707 // Purpose : Set validity of the table
708 //=======================================================================
709 void SMESHGUI_FilterTable::SetValidity( const bool isValid )
714 //=======================================================================
715 // name : SMESHGUI_FilterTable::GetType
716 // Purpose : Get current entity type
717 //=======================================================================
718 int SMESHGUI_FilterTable::GetType() const
723 //=======================================================================
724 // name : SMESHGUI_FilterTable::SetType
725 // Purpose : Set current entity type
726 //=======================================================================
727 void SMESHGUI_FilterTable::SetType( const int type )
729 myEntityTypeGrp->setButton( type );
730 onEntityType( type );
733 //=======================================================================
734 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
735 // Purpose : Restore previous entity type
736 //=======================================================================
737 void SMESHGUI_FilterTable::RestorePreviousEntityType()
739 SetType( myEntityType );
742 //=======================================================================
743 // name : SMESHGUI_FilterTable::GetCriterionType
744 // Purpose : Get type of criterion from specified row ( corresponding enums in h-file )
745 //=======================================================================
746 int SMESHGUI_FilterTable::GetCriterionType( const int theRow, const int theType ) const
748 int aType = theType == -1 ? GetType() : theType;
749 Table* aTable = myTables[ aType ];
750 ComboItem* anItem = (ComboItem*)aTable->item( theRow, 0 );
751 return anItem != 0 ? anItem->GetValue() : FT_Undefined;
754 //=======================================================================
755 // name : SMESHGUI_FilterTable::GetCriterion
756 // Purpose : Get parameters of criterion from specified row
757 //=======================================================================
758 void SMESHGUI_FilterTable::GetCriterion( const int theRow,
759 SMESH::Filter::Criterion& theCriterion,
760 const int theEntityType ) const
762 int aType = theEntityType == -1 ? GetType() : theEntityType;
763 Table* aTable = myTables[ aType ];
765 theCriterion.Type = ( (ComboItem*)aTable->item( theRow, 0 ) )->GetValue();
766 theCriterion.UnaryOp = ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->isChecked() ? FT_LogicalNOT : FT_Undefined;
767 theCriterion.BinaryOp = theRow != aTable->numRows() - 1 ?
768 ( (ComboItem*)aTable->item( theRow, 4 ) )->GetValue() : FT_Undefined;
769 theCriterion.TypeOfElement = (ElementType)aType;
771 int aCriterionType = GetCriterionType( theRow, aType );
773 if ( aCriterionType != FT_RangeOfIds &&
774 aCriterionType != FT_BelongToGeom &&
775 aCriterionType != FT_BelongToPlane &&
776 aCriterionType != FT_BelongToCylinder &&
777 aCriterionType != FT_LyingOnGeom)
779 theCriterion.Compare = ( (ComboItem*)aTable->item( theRow, 1 ) )->GetValue();
780 theCriterion.Threshold = aTable->item( theRow, 2 )->text().toDouble();
783 theCriterion.ThresholdStr = aTable->text( theRow, 2 ).latin1();
785 QTableItem* anItem = aTable->item( theRow, 0 );
786 if ( myAddWidgets.contains( anItem ) )
787 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble( AdditionalWidget::Tolerance );
790 //=======================================================================
791 // name : SMESHGUI_FilterTable::SetCriterion
792 // Purpose : Set parameters of criterion of specified row
793 //=======================================================================
794 void SMESHGUI_FilterTable::SetCriterion( const int theRow,
795 const SMESH::Filter::Criterion& theCriterion,
796 const int theEntityType )
798 int aType = theEntityType == -1 ? GetType() : theEntityType;
800 Table* aTable = myTables[ aType ];
802 if ( theRow > aTable->numRows() - 1 )
805 ( (ComboItem*)aTable->item( theRow, 0 ) )->SetValue( theCriterion.Type );
806 onCriterionChanged( theRow, 0, aType );
807 ( (ComboItem*)aTable->item( theRow, 1 ) )->SetValue( theCriterion.Compare );
808 ( (QCheckTableItem*)aTable->item( theRow, 3 ) )->setChecked( theCriterion.UnaryOp == FT_LogicalNOT );
810 if ( theCriterion.BinaryOp != FT_Undefined )
812 if ( !aTable->IsEditable( theRow, 4 ) )
813 aTable->setItem( theRow, 4, getBinaryItem( aTable ) );
814 ( (ComboItem*)aTable->item( theRow, 4 ) )->SetValue( theCriterion.BinaryOp );
817 aTable->SetEditable( false, theRow, 4 );
819 if ( theCriterion.Type != FT_RangeOfIds &&
820 theCriterion.Type != FT_BelongToGeom &&
821 theCriterion.Type != FT_BelongToPlane &&
822 theCriterion.Type != FT_BelongToCylinder &&
823 theCriterion.Type != FT_LyingOnGeom)
824 aTable->setText( theRow, 2, QString( "%1" ).arg( theCriterion.Threshold, 0, 'g', 15 ) );
826 aTable->setText( theRow, 2, QString( theCriterion.ThresholdStr ) );
828 if ( theCriterion.Compare == FT_EqualTo ||
829 theCriterion.Type == FT_BelongToPlane ||
830 theCriterion.Type == FT_BelongToCylinder )
832 QTableItem* anItem = aTable->item( theRow, 0 );
833 if ( !myAddWidgets.contains( anItem ) )
835 myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
836 myWgStack->addWidget( myAddWidgets[ anItem ] );
838 myAddWidgets[ anItem ]->SetDouble( AdditionalWidget::Tolerance, theCriterion.Tolerance );
841 emit CretarionChanged( theRow, aType );
845 //=======================================================================
846 // name : SMESHGUI_FilterTable::Update
847 // Purpose : Update table
848 //=======================================================================
849 void SMESHGUI_FilterTable::Update()
851 Table* aTable = myTables[ GetType() ];
852 int aCurrRow = aTable->currentRow();
853 int numRows = aTable->numRows();
854 if ( ( aCurrRow < 0 || aCurrRow >= numRows ) && numRows > 0 )
855 aTable->setCurrentCell( 0, 0 );
856 updateAdditionalWidget();
859 //=======================================================================
860 // name : SMESHGUI_FilterTable::AddCriterion
861 // Purpose : Add criterion with parameters
862 //=======================================================================
863 void SMESHGUI_FilterTable::AddCriterion( const SMESH::Filter::Criterion& theCriterion,
864 const int theEntityType )
866 int aType = theEntityType == -1 ? GetType() : theEntityType;
867 Table* aTable = myTables[ aType ];
868 addRow( aTable, aType );
869 SetCriterion( aTable->numRows() - 1, theCriterion );
872 //=======================================================================
873 // name : SMESHGUI_FilterTable::NumRows
874 // Purpose : Get number of criterions of current type
875 //=======================================================================
876 int SMESHGUI_FilterTable::NumRows( const int theEntityType ) const
878 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->numRows();
881 //=======================================================================
882 // name : SMESHGUI_FilterTable::Clear
883 // Purpose : Clear current table
884 //=======================================================================
885 void SMESHGUI_FilterTable::Clear( const int theType )
887 int aType = theType == -1 ? GetType() : theType;
888 QTable* aTable = myTables[ aType ];
890 if ( aTable->numRows() == 0 )
893 while ( aTable->numRows() > 0 )
895 removeAdditionalWidget( aTable, 0 );
896 aTable->removeRow( 0 );
902 //=======================================================================
903 // name : SMESHGUI_FilterTable::onAddBtn
904 // Purpose : SLOT. Called then "Add" button pressed.
905 // Adds new string to table
906 //=======================================================================
907 void SMESHGUI_FilterTable::onAddBtn()
909 int aType = GetType();
910 addRow( myTables[ aType ], aType );
915 //=======================================================================
916 // name : SMESHGUI_FilterTable::onInsertBtn
917 // Purpose : SLOT. Called then "Insert" button pressed.
918 // Inserts new string before current one
919 //=======================================================================
920 void SMESHGUI_FilterTable::onInsertBtn()
922 addRow( myTables[ GetType() ], GetType(), false );
925 //=======================================================================
926 // name : SMESHGUI_FilterTable::onRemoveBtn
927 // Purpose : SLOT. Called then "Remove" button pressed.
928 // Removes current string from table
929 //=======================================================================
930 void SMESHGUI_FilterTable::onRemoveBtn()
932 Table* aTable = myTables[ GetType() ];
934 if ( aTable->numRows() == 0 )
937 QMemArray<int> aRows;
938 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
940 if ( aTable->isRowSelected( i ) )
942 aRows.resize( aRows.size() + 1 );
943 aRows[ aRows.size() - 1 ] = i;
944 removeAdditionalWidget( aTable, i );
948 aTable->removeRows( aRows );
950 // remove control of binary logical operation from last row
951 if ( aTable->numRows() > 0 )
952 aTable->SetEditable( false, aTable->numRows() - 1, 4 );
957 //=======================================================================
958 // name : SMESHGUI_FilterTable::updateAdditionalWidget
959 // Purpose : Enable/Disable widget with additonal parameters
960 //=======================================================================
961 void SMESHGUI_FilterTable::updateAdditionalWidget()
963 Table* aTable = myTables[ GetType() ];
964 int aRow = aTable->currentRow();
965 if ( aRow < 0 || aRow >= aTable->numRows() )
967 myWgStack->setEnabled( false );
971 ComboItem* anItem = ( (ComboItem*)aTable->item( aRow, 0 ) );
972 bool toEnable = ( (ComboItem*)aTable->item( aRow, 1 ) )->GetValue() == FT_EqualTo &&
973 GetCriterionType( aRow ) != FT_BelongToGeom &&
974 GetCriterionType( aRow ) != FT_LyingOnGeom &&
975 GetCriterionType( aRow ) != FT_RangeOfIds &&
976 GetCriterionType( aRow ) != FT_FreeEdges &&
977 GetCriterionType( aRow ) != FT_BadOrientedVolume;
978 if ( !myAddWidgets.contains( anItem ) )
980 myAddWidgets[ anItem ] = new AdditionalWidget( myWgStack );
981 myWgStack->addWidget( myAddWidgets[ anItem ] );
984 myWgStack->raiseWidget( myWgStack->id( myAddWidgets[ anItem ] ) );
985 myWgStack->setEnabled( toEnable );
988 //=======================================================================
989 // name : SMESHGUI_FilterTable::removeAdditionalWidget
990 // Purpose : Remove widgets containing additional parameters from widget
991 // stack and internal map
992 //=======================================================================
993 void SMESHGUI_FilterTable::removeAdditionalWidget( QTable* theTable, const int theRow )
995 QTableItem* anItem = theTable->item( theRow, 0 );
996 if ( myAddWidgets.contains( anItem ) )
998 myWgStack->removeWidget( myAddWidgets[ anItem ] );
999 myAddWidgets[ anItem ]->reparent( 0, QPoint() );
1000 delete myAddWidgets[ anItem ];
1001 myAddWidgets.remove( anItem );
1005 //=======================================================================
1006 // name : SMESHGUI_FilterTable::onClearBtn
1007 // Purpose : SLOT. Called then "Clear" button pressed.
1008 // Removes all strings from table
1009 //=======================================================================
1010 void SMESHGUI_FilterTable::onClearBtn()
1012 QTable* aTable = myTables[ GetType() ];
1014 if ( aTable->numRows() == 0 )
1017 while ( aTable->numRows() > 0 )
1019 removeAdditionalWidget( aTable, 0 );
1020 aTable->removeRow( 0 );
1026 //=======================================================================
1027 // name : SMESHGUI_FilterTable::onCurrentChanged()
1028 // Purpose : SLOT. Called when current cell changed
1029 //=======================================================================
1030 void SMESHGUI_FilterTable::onCurrentChanged( int theRow, int theCol )
1032 updateAdditionalWidget();
1033 emit CurrentChanged( theRow, theCol );
1036 //=======================================================================
1037 // name : SMESHGUI_FilterTable::onCriterionChanged()
1038 // Purpose : Provides reaction on change of criterion
1039 //=======================================================================
1040 void SMESHGUI_FilterTable::onCriterionChanged( const int row, const int col, const int entityType )
1042 int aType = entityType == -1 ? GetType() : entityType;
1043 Table* aTable = myTables[ aType ];
1044 ComboItem* aCompareItem = (ComboItem*)aTable->item( row, 1 );
1046 int aCriterionType = GetCriterionType( row );
1048 if ( aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1049 aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
1050 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume )
1052 if ( aCompareItem->count() > 0 )
1053 aCompareItem->setStringList( QStringList() );
1054 aTable->SetEditable( false, row, 2 );
1056 else if ( aCriterionType == SMESH::FT_RangeOfIds ||
1057 aCriterionType == SMESH::FT_BelongToGeom ||
1058 aCriterionType == SMESH::FT_BelongToPlane ||
1059 aCriterionType == SMESH::FT_BelongToCylinder ||
1060 aCriterionType == SMESH::FT_LyingOnGeom)
1062 QMap<int, QString> aMap;
1063 aMap[ FT_EqualTo ] = tr( "EQUAL_TO" );
1064 aCompareItem->setStringList( aMap );
1065 if ( !aTable->IsEditable( row, 2 ) )
1066 aTable->SetEditable( true, row, 2 );
1070 if ( aCompareItem->count() != 3 )
1072 aCompareItem->setStringList( QStringList() );
1073 aCompareItem->setStringList( getCompare() );
1076 QString aText = aTable->text( row, 2 );
1078 aText.toDouble( &isOk );
1079 aTable->setText( row, 2, isOk ? aText : QString("") );
1080 if ( !aTable->IsEditable( row, 2 ) )
1081 aTable->SetEditable( true, row, 2 );
1084 updateAdditionalWidget();
1086 emit CretarionChanged( row, entityType );
1089 //=======================================================================
1090 // name : SMESHGUI_FilterTable::onCriterionChanged()
1091 // Purpose : SLOT. Called then contents of table changed
1092 // Provides reaction on change of criterion
1093 //=======================================================================
1094 void SMESHGUI_FilterTable::onCriterionChanged( int row, int col )
1096 onCriterionChanged( row, col, -1 );
1099 //=======================================================================
1100 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1101 // Purpose : Get first selected row
1102 //=======================================================================
1103 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1105 QTable* aTable = myTables[ GetType() ];
1106 for ( int i = 0, n = aTable->numRows(); i < n; i++ )
1107 if ( aTable->isRowSelected( i ) )
1110 int aRow = aTable->currentRow();
1111 return aRow >= 0 && aRow < aTable->numRows() ? aRow : -1;
1114 //=======================================================================
1115 // name : SMESHGUI_FilterTable::addRow
1116 // Purpose : Add row at the end of table
1117 //=======================================================================
1118 void SMESHGUI_FilterTable::addRow( Table* theTable, const int theType, const bool toTheEnd )
1121 int aSelectedRow = getFirstSelectedRow();
1122 int aCurrCol = theTable->currentColumn();
1124 if ( toTheEnd || aSelectedRow == -1 )
1126 theTable->insertRows( theTable->numRows() );
1127 aCurrRow = theTable->numRows() - 1;
1131 theTable->insertRows( aSelectedRow );
1132 aCurrRow = aSelectedRow;
1136 theTable->setItem( aCurrRow, 0, getCriterionItem( theTable, theType ) );
1139 theTable->setItem( aCurrRow, 1, getCompareItem( theTable ) );
1142 //theTable->setItem( aCurrRow, 2, new QTableItem( theTable ) );
1144 //Logical operation NOT
1145 theTable->setItem( aCurrRow, 3, getUnaryItem( theTable ) );
1147 // Logical binary operation for previous value
1148 int anAddBinOpStr = -1;
1149 if ( aCurrRow == theTable->numRows() - 1 )
1150 anAddBinOpStr = aCurrRow - 1;
1151 else if ( aCurrRow >= 0 )
1152 anAddBinOpStr = aCurrRow;
1154 if ( theTable->item( aCurrRow, 4 ) == 0 ||
1155 theTable->item( aCurrRow, 4 )->rtti() != 1 )
1159 if ( anAddBinOpStr >= 0 &&
1160 ( theTable->item( anAddBinOpStr, 4 ) == 0 ||
1161 theTable->item( anAddBinOpStr, 4 )->rtti() != 1 ) )
1162 theTable->setItem( anAddBinOpStr, 4, getBinaryItem( theTable ) );
1165 theTable->SetEditable( false, theTable->numRows() - 1, 4 );
1167 if ( aCurrRow >=0 && aCurrRow < theTable->numRows() &&
1168 aCurrCol >=0 && aCurrCol < theTable->numRows() )
1169 theTable->setCurrentCell( aCurrRow, aCurrCol );
1171 onCriterionChanged( aCurrRow, 0 );
1176 //=======================================================================
1177 // name : SMESHGUI_FilterTable::getCriterionItem
1178 // Purpose : Get combo table item for criteria of specified type
1179 //=======================================================================
1180 QTableItem* SMESHGUI_FilterTable::getCriterionItem( QTable* theParent , const int theType )
1182 return new ComboItem( theParent, getCriteria( theType ) );
1185 //=======================================================================
1186 // name : SMESHGUI_FilterTable::getCompareItem
1187 // Purpose : Get combo table item for operation of comparision
1188 //=======================================================================
1189 QTableItem* SMESHGUI_FilterTable::getCompareItem( QTable* theParent )
1191 return new ComboItem( theParent, getCompare() );
1194 //=======================================================================
1195 // name : SMESHGUI_FilterTable::getBinaryItem
1197 //=======================================================================
1198 QTableItem* SMESHGUI_FilterTable::getBinaryItem( QTable* theParent )
1200 static QMap<int, QString> aMap;
1201 if ( aMap.isEmpty() )
1203 aMap[ SMESH::FT_LogicalAND ] = tr( "AND" );
1204 aMap[ SMESH::FT_LogicalOR ] = tr( "OR" );
1207 return new ComboItem( theParent, aMap );
1210 //=======================================================================
1211 // name : SMESHGUI_FilterTable::getUnaryItem
1212 // Purpose : Get check table item
1213 //=======================================================================
1214 QTableItem* SMESHGUI_FilterTable::getUnaryItem( QTable* theParent )
1216 return new QCheckTableItem( theParent, tr( "NOT" ) );
1219 //=======================================================================
1220 // name : SMESHGUI_FilterTable::getSupportedTypes
1221 // Purpose : Get all supported type
1222 //=======================================================================
1223 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1225 static QMap<int, QString> aTypes;
1226 if ( aTypes.isEmpty() )
1228 aTypes[ SMESH::NODE ] = tr( "NODES" );
1229 aTypes[ SMESH::EDGE ] = tr( "EDGES" );
1230 aTypes[ SMESH::FACE ] = tr( "FACES" );
1231 aTypes[ SMESH::VOLUME ] = tr( "VOLUMES" );
1237 //=======================================================================
1238 // name : SMESHGUI_FilterTable::getCriteria
1239 // Purpose : Get criteria for specified type
1240 //=======================================================================
1241 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria( const int theType ) const
1243 if ( theType == SMESH::NODE )
1245 static QMap<int, QString> aCriteria;
1246 if ( aCriteria.isEmpty() )
1248 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1249 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1250 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1251 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1252 aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" );
1256 else if ( theType == SMESH::EDGE )
1258 static QMap<int, QString> aCriteria;
1259 if ( aCriteria.isEmpty() )
1261 aCriteria[ SMESH::FT_FreeBorders ] = tr( "FREE_BORDERS" );
1262 aCriteria[ SMESH::FT_MultiConnection ] = tr( "MULTI_BORDERS" );
1263 aCriteria[ SMESH::FT_Length ] = tr( "LENGTH" );
1264 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1265 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1266 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1267 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1268 aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" );
1272 else if ( theType == SMESH::FACE )
1274 static QMap<int, QString> aCriteria;
1275 if ( aCriteria.isEmpty() )
1277 aCriteria[ SMESH::FT_AspectRatio ] = tr( "ASPECT_RATIO" );
1278 aCriteria[ SMESH::FT_Warping ] = tr( "WARPING" );
1279 aCriteria[ SMESH::FT_MinimumAngle ] = tr( "MINIMUM_ANGLE" );
1280 aCriteria[ SMESH::FT_Taper ] = tr( "TAPER" );
1281 aCriteria[ SMESH::FT_Skew ] = tr( "SKEW" );
1282 aCriteria[ SMESH::FT_Area ] = tr( "AREA" );
1283 aCriteria[ SMESH::FT_FreeEdges ] = tr( "FREE_EDGES" );
1284 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1285 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1286 aCriteria[ SMESH::FT_BelongToPlane ] = tr( "BELONG_TO_PLANE" );
1287 aCriteria[ SMESH::FT_BelongToCylinder ] = tr( "BELONG_TO_CYLINDER" );
1288 aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" );
1289 aCriteria[ SMESH::FT_Length2D ] = tr( "LENGTH2D" );
1290 aCriteria[ SMESH::FT_MultiConnection2D] = tr( "MULTI2D_BORDERS" );
1294 else if ( theType == SMESH::VOLUME )
1296 static QMap<int, QString> aCriteria;
1297 if ( aCriteria.isEmpty() )
1299 aCriteria[ SMESH::FT_AspectRatio3D] = tr( "ASPECT_RATIO_3D" );
1300 aCriteria[ SMESH::FT_RangeOfIds ] = tr( "RANGE_OF_IDS" );
1301 aCriteria[ SMESH::FT_BelongToGeom ] = tr( "BELONG_TO_GEOM" );
1302 aCriteria[ SMESH::FT_LyingOnGeom ] = tr( "LYING_ON_GEOM" );
1303 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr( "BAD_ORIENTED_VOLUME" );
1309 static QMap<int, QString> aCriteria;
1315 //=======================================================================
1316 // name : SMESHGUI_FilterTable::getCompare
1317 // Purpose : Get operation of comparison
1318 //=======================================================================
1319 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1321 static QMap<int, QString> aMap;
1323 if ( aMap.isEmpty() )
1325 aMap[ SMESH::FT_LessThan ] = tr( "LESS_THAN" );
1326 aMap[ SMESH::FT_MoreThan ] = tr( "MORE_THAN" );
1327 aMap[ SMESH::FT_EqualTo ] = tr( "EQUAL_TO" );
1333 //=======================================================================
1334 // name : SMESHGUI_FilterTable::createTable
1335 // Purpose : Create table
1336 //=======================================================================
1337 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable( QWidget* theParent,
1341 Table* aTable= new Table( 0, 5, theParent );
1343 QHeader* aHeaders = aTable->horizontalHeader();
1345 QFontMetrics aMetrics( aHeaders->font() );
1347 // append spaces to the header of criteria in order to
1348 // provide visibility of criterion inside comboboxes
1349 static int aMaxLenCr = 0;
1351 if ( aMaxLenCr == 0 )
1353 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1354 QMap<int, QString>::const_iterator anIter;
1355 for ( anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter )
1356 aMaxLenCr = Max( maxLength( getCriteria( anIter.key() ), aMetrics ), aMaxLenCr );
1359 static int aLenCr = abs( aMaxLenCr -
1360 aMetrics.width( tr( "CRITERION" ) ) ) / aMetrics.width( ' ' ) + 5;
1363 aCrStr.fill( ' ', aLenCr );
1365 aCoStr.fill( ' ', 10 );
1367 aHeaders->setLabel( 0, tr( "CRITERION" ) + aCrStr );
1368 aHeaders->setLabel( 1, tr( "COMPARE" ) + aCoStr );
1369 aHeaders->setLabel( 2, tr( "THRESHOLD_VALUE" ) );
1370 aHeaders->setLabel( 3, tr( "UNARY" ) );
1371 aHeaders->setLabel( 4, tr( "BINARY" ) + " " );
1373 // set geometry of the table
1374 for ( int i = 0; i <= 4; i++ )
1375 aTable->adjustColumn( i );
1377 aTable->updateGeometry();
1378 QSize aSize = aTable->sizeHint();
1379 int aWidth = aSize.width();
1380 aTable->setMinimumSize( QSize( aWidth, aWidth / 2 ) );
1381 aTable->setSizePolicy( QSizePolicy( QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding) );
1383 connect( aTable, SIGNAL( valueChanged( int, int ) ),
1384 this, SLOT( onCriterionChanged( int, int ) ) );
1386 connect( aTable, SIGNAL( currentChanged( int, int ) ),
1387 this, SLOT( onCurrentChanged( int, int ) ) );
1392 //=======================================================================
1393 // name : SMESHGUI_FilterTable::updateBtnState
1394 // Purpose : Update button state
1395 //=======================================================================
1396 void SMESHGUI_FilterTable::updateBtnState()
1398 myRemoveBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1399 myClearBtn->setEnabled( myTables[ GetType() ]->numRows() > 0 );
1402 //=======================================================================
1403 // name : SMESHGUI_FilterTable::SetEditable
1404 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1405 //=======================================================================
1406 void SMESHGUI_FilterTable::SetEditable( const bool isEditable )
1408 TableMap::iterator anIter;
1409 for ( anIter = myTables.begin(); anIter != myTables.end(); ++anIter )
1411 anIter.data()->setReadOnly( !isEditable );
1416 myInsertBtn->show();
1417 myRemoveBtn->show();
1423 myInsertBtn->hide();
1424 myRemoveBtn->hide();
1429 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1430 for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1431 anIter2.data()->SetEditable( isEditable );
1434 //=======================================================================
1435 // name : SMESHGUI_FilterTable::SetEnabled
1436 // Purpose : Enable/Disable table. Switching type of elements already enabled
1437 //=======================================================================
1438 void SMESHGUI_FilterTable::SetEnabled( const bool isEnabled )
1440 myAddBtn->setEnabled( isEnabled );
1441 myInsertBtn->setEnabled( isEnabled );
1442 myRemoveBtn->setEnabled( isEnabled );
1443 myClearBtn->setEnabled( isEnabled );
1448 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1449 for ( anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2 )
1450 anIter2.data()->setEnabled( isEnabled );
1453 //=======================================================================
1454 // name : SMESHGUI_FilterTable::IsEditable
1455 // Purpose : Verify whether table is editable
1456 //=======================================================================
1457 bool SMESHGUI_FilterTable::IsEditable() const
1459 return !myTables[ GetType() ]->isReadOnly();
1462 //=======================================================================
1463 // name : SMESHGUI_FilterTable::SetLibsEnabled
1464 // Purpose : Show/hide buttons for work with libraries
1465 //=======================================================================
1466 void SMESHGUI_FilterTable::SetLibsEnabled( const bool isEnabled )
1470 myCopyFromBtn->show();
1475 myCopyFromBtn->hide();
1480 //=======================================================================
1481 // name : SMESHGUI_FilterTable::onCopyFromBtn
1482 // Purpose : SLOT. Called the "Copy from ..." button clicked
1483 // Display filter library dialog
1484 //=======================================================================
1485 void SMESHGUI_FilterTable::onCopyFromBtn()
1487 if ( myLibDlg == 0 )
1488 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1489 this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1491 myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM );
1493 if ( myLibDlg->exec() == QDialog::Accepted )
1495 Copy( myLibDlg->GetTable() );
1500 //=======================================================================
1501 // name : SMESHGUI_FilterTable::onAddToBtn
1502 // Purpose : SLOT. Called the "Add to ..." button clicked
1503 // Display filter library dialog
1504 //=======================================================================
1505 void SMESHGUI_FilterTable::onAddToBtn()
1507 if ( !IsValid( true ) )
1509 if ( myLibDlg == 0 )
1510 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1511 this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1513 myLibDlg->Init( GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO );
1515 myLibDlg->SetTable( this );
1520 //=======================================================================
1521 // name : SMESHGUI_FilterTable::Copy
1522 // Purpose : Initialise table with values of other table
1523 //=======================================================================
1524 void SMESHGUI_FilterTable::Copy( const SMESHGUI_FilterTable* theTable )
1528 for ( int i = 0, n = theTable->NumRows(); i < n; i++ )
1530 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1531 theTable->GetCriterion( i, aCriterion );
1532 AddCriterion( aCriterion );
1536 //=======================================================================
1537 // name : SMESHGUI_FilterTable::CurrentCell
1538 // Purpose : Returns current cell
1539 //=======================================================================
1540 bool SMESHGUI_FilterTable::CurrentCell( int& theRow, int& theCol ) const
1542 theRow = myTables[ GetType() ]->currentRow();
1543 theCol = myTables[ GetType() ]->currentColumn();
1544 return theRow >= 0 && theCol >= 0;
1547 //=======================================================================
1548 // name : SMESHGUI_FilterTable::SetText
1549 // Purpose : Set text and internal value in cell of threshold value
1550 //=======================================================================
1551 void SMESHGUI_FilterTable::SetThreshold( const int theRow,
1552 const QString& theText,
1553 const int theEntityType )
1555 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1556 aTable->setText( theRow, 2, theText );
1559 //=======================================================================
1560 // name : SMESHGUI_FilterTable::SetText
1561 // Purpose : Get text and internal value from cell of threshold value
1562 //=======================================================================
1563 bool SMESHGUI_FilterTable::GetThreshold( const int theRow,
1565 const int theEntityType )
1567 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1568 QTableItem* anItem = aTable->item( theRow, 2 );
1571 theText = anItem->text();
1579 Class : SMESHGUI_FilterDlg
1580 Description : Dialog to specify filters for VTK viewer
1584 //=======================================================================
1585 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1586 // Purpose : Constructor
1587 //=======================================================================
1588 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget* theParent,
1589 const QValueList<int>& theTypes,
1590 const char* theName )
1591 : QDialog( theParent, theName, false,
1592 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1594 construct( theTypes );
1597 //=======================================================================
1598 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1599 // Purpose : Constructor
1600 //=======================================================================
1601 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( QWidget* theParent,
1603 const char* theName )
1604 : QDialog( theParent, theName, false,
1605 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu )
1607 QValueList<int> aTypes;
1608 aTypes.append( theType );
1609 construct( aTypes );
1612 //=======================================================================
1613 // name : SMESHGUI_FilterDlg::construct
1614 // Purpose : Construct dialog ( called by constructor )
1615 //=======================================================================
1616 void SMESHGUI_FilterDlg::construct( const QValueList<int>& theTypes )
1620 setCaption( tr( "CAPTION" ) );
1622 QVBoxLayout* aDlgLay = new QVBoxLayout( this, MARGIN, SPACING );
1624 myMainFrame = createMainFrame ( this );
1625 QFrame* aBtnFrame = createButtonFrame( this );
1627 aDlgLay->addWidget( myMainFrame );
1628 aDlgLay->addWidget( aBtnFrame );
1630 aDlgLay->setStretchFactor( myMainFrame, 1 );
1635 //=======================================================================
1636 // name : SMESHGUI_FilterDlg::createMainFrame
1637 // Purpose : Create frame containing dialog's input fields
1638 //=======================================================================
1639 QFrame* SMESHGUI_FilterDlg::createMainFrame( QWidget* theParent )
1641 QGroupBox* aMainFrame = new QGroupBox( 1, Qt::Horizontal, theParent );
1642 aMainFrame->setFrameStyle( QFrame::NoFrame );
1643 aMainFrame->setInsideMargin( 0 );
1647 myTable = new SMESHGUI_FilterTable( aMainFrame, myTypes );
1648 myTable->SetLibsEnabled( true );
1650 QFrame* aLine = new QFrame( myTable->GetTableGrp() );
1651 aLine->setFrameStyle( QFrame::HLine | QFrame::Sunken );
1653 mySetInViewer = new QCheckBox( tr( "SET_IN_VIEWER" ), myTable->GetTableGrp() );
1654 mySetInViewer->setChecked( true );
1657 mySourceGrp = createSourceGroup( aMainFrame );
1659 connect( myTable, SIGNAL( CretarionChanged( const int, const int ) ),
1660 SLOT( onCriterionChanged( const int, const int ) ) );
1662 connect( myTable, SIGNAL( CurrentChanged( int, int ) ),
1663 SLOT( onCurrentChanged( int, int ) ) );
1668 //=======================================================================
1669 // name : SMESHGUI_FilterDlg::createSourceFrame
1670 // Purpose : Create frame containing source radio button
1671 //=======================================================================
1672 QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup( QWidget* theParent )
1674 QButtonGroup* aGrp = new QButtonGroup( 1, Qt::Vertical, tr( "SOURCE" ), theParent );
1676 QRadioButton* aMeshBtn = new QRadioButton( tr( "MESH" ), aGrp );
1677 QRadioButton* aSelBtn = new QRadioButton( tr( "SELECTION" ), aGrp );
1678 QRadioButton* aGrpBtn = new QRadioButton( tr( "CURRENT_GROUP" ), aGrp );
1680 aGrp->insert( aMeshBtn, Mesh );
1681 aGrp->insert( aSelBtn, Selection );
1682 aGrp->insert( aGrpBtn, Dialog );
1684 aGrp->setButton( Selection );
1689 //=======================================================================
1690 // name : SMESHGUI_FilterDlg::updateMainButtons
1691 // Purpose : Update visibility of main buttons ( OK, Cancel, Close ... )
1692 //=======================================================================
1693 void SMESHGUI_FilterDlg::updateMainButtons()
1695 if ( myTypes.count() == 1 )
1697 myButtons[ BTN_Cancel ]->show();
1698 myButtons[ BTN_Apply ]->hide();
1699 myButtons[ BTN_Close ]->hide();
1703 myButtons[ BTN_Cancel ]->hide();
1704 myButtons[ BTN_Apply ]->show();
1705 myButtons[ BTN_Close ]->show();
1708 // updateGeometry();
1711 //=======================================================================
1712 // name : SMESHGUI_FilterDlg::createButtonFrame
1713 // Purpose : Create frame containing buttons
1714 //=======================================================================
1715 QFrame* SMESHGUI_FilterDlg::createButtonFrame( QWidget* theParent )
1717 QGroupBox* aGrp = new QGroupBox( 1, Qt::Vertical, theParent );
1719 myButtons[ BTN_OK ] = new QPushButton( tr( "SMESH_BUT_OK" ), aGrp );
1720 myButtons[ BTN_Apply ] = new QPushButton( tr( "SMESH_BUT_APPLY" ), aGrp );
1722 QLabel* aLbl = new QLabel( aGrp );
1723 aLbl->setSizePolicy( QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Fixed ) );
1725 myButtons[ BTN_Cancel ] = new QPushButton( tr( "SMESH_BUT_CANCEL" ), aGrp );
1726 myButtons[ BTN_Close ] = new QPushButton( tr( "SMESH_BUT_CLOSE" ), aGrp );
1728 connect( myButtons[ BTN_OK ], SIGNAL( clicked() ), SLOT( onOk() ) );
1729 connect( myButtons[ BTN_Cancel ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1730 connect( myButtons[ BTN_Close ], SIGNAL( clicked() ), SLOT( onClose() ) ) ;
1731 connect( myButtons[ BTN_Apply ], SIGNAL( clicked() ), SLOT( onApply() ) );
1733 updateMainButtons();
1738 //=======================================================================
1739 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
1740 // Purpose : Destructor
1741 //=======================================================================
1742 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
1746 //=======================================================================
1747 // name : SMESHGUI_FilterDlg::Init
1748 // Purpose : Init dialog fields, connect signals and slots, show dialog
1749 //=======================================================================
1750 void SMESHGUI_FilterDlg::Init( const int type )
1752 QValueList<int> aTypes;
1753 aTypes.append( type );
1757 //=======================================================================
1758 // name : SMESHGUI_FilterDlg::Init
1759 // Purpose : Init dialog fields, connect signals and slots, show dialog
1760 //=======================================================================
1761 void SMESHGUI_FilterDlg::Init( const QValueList<int>& theTypes )
1766 myMesh = SMESH::SMESH_Mesh::_nil();
1768 myIsSelectionChanged = false;
1770 myTable->Init( theTypes );
1773 if ( theTypes.count() == 1 )
1775 int aType = theTypes.first();
1776 if ( aType == SMESH::NODE ) setCaption( tr( "NODES_TLT" ) );
1777 else if ( aType == SMESH::EDGE ) setCaption( tr( "EDGES_TLT" ) );
1778 else if ( aType == SMESH::FACE ) setCaption( tr( "FACES_TLT" ) );
1779 else if ( aType == SMESH::VOLUME ) setCaption( tr( "VOLUMES_TLT" ) );
1782 setCaption( tr( "TLT" ) );
1784 qApp->processEvents();
1789 mySMESHGUI = SMESHGUI::GetSMESHGUI() ;
1790 mySMESHGUI->SetActiveDialogBox( ( QDialog* )this ) ;
1792 connect( mySMESHGUI, SIGNAL( SignalDeactivateActiveDialog() ), SLOT( onDeactivate() ) );
1793 connect( mySMESHGUI, SIGNAL( SignalCloseAllDialogs() ), SLOT( onClose() ) );
1796 mySMESHGUI->DefineDlgPosition( this, x, y );
1799 updateMainButtons();
1802 // Initialise filter table with values of previous filter
1803 QValueList<int>::const_iterator anIter;
1804 for ( anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter )
1806 myTable->Clear( *anIter );
1807 if ( !myFilter[ *anIter ]->_is_nil() )
1809 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1810 if ( myFilter[ *anIter ]->GetCriteria( aCriteria ) )
1812 for ( int i = 0, n = aCriteria->length(); i < n; i++ )
1813 myTable->AddCriterion( aCriteria[ i ], *anIter );
1818 if ( myInsertState.contains( theTypes.first() ) )
1819 mySetInViewer->setChecked( myInsertState[ theTypes.first() ] );
1821 mySetInViewer->setChecked( true );
1822 if ( myApplyToState.contains( theTypes.first() ) )
1823 mySourceGrp->setButton( myApplyToState[ theTypes.first() ] );
1825 mySourceGrp->setButton( Selection );
1828 //=======================================================================
1829 // name : SMESHGUI_FilterDlg::onOk
1830 // Purpose : SLOT called when "Ok" button pressed.
1831 // Assign filters VTK viewer and close dialog
1832 //=======================================================================
1833 void SMESHGUI_FilterDlg::onOk()
1837 mySelection->ClearFilters();
1838 disconnect( mySMESHGUI, 0, this, 0 );
1839 disconnect( mySelection, 0, this, 0 );
1840 mySMESHGUI->ResetState() ;
1846 //=======================================================================
1847 // name : SMESHGUI_FilterDlg::onClose
1848 // Purpose : SLOT called when "Close" button pressed. Close dialog
1849 //=======================================================================
1850 void SMESHGUI_FilterDlg::onClose()
1852 // Restore previously selected object
1855 mySelection->ClearFilters();
1856 mySelection->Clear();
1857 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
1858 for ( ; anIter.More(); anIter.Next() )
1860 mySelection->AddIObject( anIter.Key() );
1862 TColStd_MapOfInteger aResMap;
1863 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
1864 for ( int i = 1, n = anIndMap.Extent(); i <= n; i++ )
1865 aResMap.Add( anIndMap( i ) );
1867 mySelection->AddOrRemoveIndex( anIter.Key(), aResMap, false );
1871 disconnect( mySMESHGUI, 0, this, 0 );
1872 disconnect( mySelection, 0, this, 0 );
1873 mySMESHGUI->ResetState() ;
1878 //=======================================================================
1879 // name : SMESHGUI_FilterDlg::onDeactivate
1880 // Purpose : SLOT called when dialog must be deativated
1881 //=======================================================================
1882 void SMESHGUI_FilterDlg::onDeactivate()
1884 setEnabled( false );
1887 //=======================================================================
1888 // name : SMESHGUI_FilterDlg::enterEvent
1889 // Purpose : Event filter
1890 //=======================================================================
1891 void SMESHGUI_FilterDlg::enterEvent( QEvent* )
1893 // mySMESHGUI->EmitSignalDeactivateDialog();
1894 mySMESHGUI->SetActiveDialogBox( (QDialog*)this );
1895 mySMESHGUI->ResetState();
1900 //=================================================================================
1901 // function : closeEvent()
1903 //=================================================================================
1904 void SMESHGUI_FilterDlg::closeEvent( QCloseEvent* e )
1909 //=======================================================================
1910 // name : SMESHGUI_FilterDlg::getIdsFromWg
1911 // Purpose : Retrieve list of ids from given widget
1912 //=======================================================================
1913 void SMESHGUI_FilterDlg::getIdsFromWg( const QWidget* theWg, QValueList<int>& theRes ) const
1919 if ( theWg->inherits( "QListBox" ) )
1921 QListBox* aListBox = ( QListBox* )theWg;
1923 for ( int i = 0, n = aListBox->count(); i < n; i++ )
1925 int anId = aListBox->text( i ).toInt( &b );
1927 theRes.append( anId );
1930 else if ( theWg->inherits( "QLineEdit" ) )
1932 QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1933 QString aStr = aLineEdit->text();
1934 QRegExp aRegExp( "(\\d+)" );
1939 aPos = aRegExp.search( aStr, aPos );
1942 int anId = aRegExp.cap( 1 ).toInt( &b );
1944 theRes.append( anId );
1945 aPos += aRegExp.matchedLength();
1951 //=======================================================================
1952 // name : SMESHGUI_FilterDlg::getSelMode
1953 // Purpose : Get selection mode of specified type
1954 //=======================================================================
1955 Selection_Mode SMESHGUI_FilterDlg::getSelMode( const int theType ) const
1959 case SMESH::NODE : return NodeSelection;
1960 case SMESH::EDGE : return EdgeSelection;
1961 case SMESH::FACE : return FaceSelection;
1962 case SMESH::VOLUME : return VolumeSelection;
1963 default : return ActorSelection;
1968 //=======================================================================
1969 // name : SMESHGUI_FilterDlg::setIdsToWg
1970 // Purpose : Insert identifiers in specified widgets
1971 //=======================================================================
1972 void SMESHGUI_FilterDlg::setIdsToWg( QWidget* theWg, const QValueList<int>& theIds )
1977 if ( theWg->inherits( "QListBox" ) )
1979 QListBox* aListBox = ( QListBox* )theWg;
1982 QStringList aStrList;
1983 QValueList<int>::const_iterator anIter;
1984 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
1985 aStrList.append( QString( "%1" ).arg( *anIter ) );
1987 aListBox->insertStringList( aStrList );
1989 else if ( theWg->inherits( "QLineEdit" ) )
1991 QLineEdit* aLineEdit = ( QLineEdit* )theWg;
1993 QValueList<int>::const_iterator anIter;
1995 for ( anIter = theIds.begin(); anIter != theIds.end(); ++ anIter )
1996 aStr += QString( "%1 " ).arg( *anIter );
1998 if ( !aStr.isEmpty() )
1999 aStr.remove( aStr.length() - 1, 1 );
2001 aLineEdit->setText( aStr );
2005 //=======================================================================
2006 // name : SMESHGUI_FilterDlg::isValid
2007 // Purpose : Verify validity of input data
2008 //=======================================================================
2009 bool SMESHGUI_FilterDlg::isValid() const
2011 if ( !myTable->IsValid() )
2014 for ( int i = 0, n = myTable->NumRows(); i < n; i++ )
2016 int aType = myTable->GetCriterionType( i );
2017 if ( aType == FT_BelongToGeom ||
2018 aType == FT_BelongToPlane ||
2019 aType == FT_BelongToCylinder ||
2020 aType == FT_LyingOnGeom)
2023 myTable->GetThreshold( i, aName );
2025 SALOMEDS::Study::ListOfSObject_var aList = SMESHGUI::GetSMESHGUI()->GetActiveStudy()->
2026 getStudyDocument()->FindObjectByName( aName.latin1(), "GEOM" );
2027 if ( aList->length() == 0 )
2029 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2030 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "BAD_SHAPE_NAME" ).arg( aName ), QMessageBox::Ok );
2034 if ( aType == FT_BelongToCylinder || aType == FT_BelongToPlane )
2036 GEOM::GEOM_Object_var aGeomObj =
2037 GEOM::GEOM_Object::_narrow( aList[ 0 ]->GetObject() );
2038 if ( !aGeomObj->_is_nil() )
2041 if ( !GEOMBase::GetShape( aGeomObj, aFace ) ||
2043 aFace.ShapeType() != TopAbs_FACE )
2045 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2046 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2050 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( TopoDS::Face( aFace ) );
2051 if ( aSurf.IsNull() )
2053 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2054 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_FACE" ).arg( aName ), QMessageBox::Ok );
2058 if ( aType == FT_BelongToPlane && !aSurf->IsKind( STANDARD_TYPE( Geom_Plane ) ) )
2060 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2061 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_PLANE" ).arg( aName ), QMessageBox::Ok );
2065 if ( aType == FT_BelongToCylinder && !aSurf->IsKind( STANDARD_TYPE( Geom_CylindricalSurface ) ) )
2067 QMessageBox::information( SMESHGUI::GetSMESHGUI()->GetDesktop(),
2068 tr( "SMESH_INSUFFICIENT_DATA" ), tr( "SHAPE_IS_NOT_A_CYLINDER" ).arg( aName ), QMessageBox::Ok );
2079 //=======================================================================
2080 // name : SMESHGUI_FilterDlg::SetSourceWg
2081 // Purpose : Set widget of parent dialog containing idsto be filtered if
2082 // user select corresponding source radio button
2083 //=======================================================================
2084 void SMESHGUI_FilterDlg::SetSourceWg( QWidget* theWg )
2089 //=======================================================================
2090 // name : SMESHGUI_FilterDlg::SetGroupIds
2091 // Purpose : Set mesh
2092 //=======================================================================
2093 void SMESHGUI_FilterDlg::SetMesh( SMESH::SMESH_Mesh_ptr theMesh )
2098 //=======================================================================
2099 // name : SMESHGUI_FilterDlg::SetSelection
2100 // Purpose : Get filtered ids
2101 //=======================================================================
2102 void SMESHGUI_FilterDlg::SetSelection( SALOME_Selection* theSel )
2105 disconnect( mySelection, SIGNAL( currentSelectionChanged() ), this, SLOT( onSelectionDone() ) );
2107 mySelection = theSel;
2112 const SALOME_ListIO& anObjs = mySelection->StoredIObjects();
2113 SALOME_ListIteratorOfListIO anIter( anObjs );
2114 for ( ;anIter.More(); anIter.Next() )
2116 TColStd_IndexedMapOfInteger aMap;
2117 mySelection->GetIndex( anIter.Value(), aMap );
2118 myIObjects.Bind( anIter.Value(), aMap );
2121 connect( mySelection, SIGNAL( currentSelectionChanged() ), SLOT( onSelectionDone() ) );
2129 //=======================================================================
2130 // name : SMESHGUI_FilterDlg::onApply
2131 // Purpose : SLOT called when "Apply" button pressed.
2132 // Assign filters to VTK viewer
2133 //=======================================================================
2134 bool SMESHGUI_FilterDlg::onApply()
2141 int aCurrType = myTable->GetType();
2143 if ( !createFilter( aCurrType ) )
2146 insertFilterInViewer();
2148 if ( !myFilter[ aCurrType ]->GetPredicate()->_is_nil() )
2150 QValueList<int> aResultIds;
2151 filterSource( aCurrType, aResultIds );
2152 selectInViewer( aCurrType, aResultIds );
2155 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2156 myApplyToState[ aCurrType ] = mySourceGrp->id( mySourceGrp->selected() );
2159 catch( const SALOME::SALOME_Exception& S_ex )
2161 QtCatchCorbaException( S_ex );
2170 //=======================================================================
2171 // name : SMESHGUI_FilterDlg::createFilter
2172 // Purpose : Create predicate for given type
2173 //=======================================================================
2174 bool SMESHGUI_FilterDlg::createFilter( const int theType )
2176 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2177 if ( aFilterMgr->_is_nil() )
2180 int n = myTable->NumRows();
2182 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2183 aCriteria->length( n );
2185 long aPrecision = -1;
2186 if ( QAD_CONFIG->hasSetting( "SMESH:ControlsPrecision" ) )
2188 QString aStr = QAD_CONFIG->getSetting( "SMESH:ControlsPrecision" );
2190 int aVal = aStr.toInt( &isOk );
2195 for ( CORBA::ULong i = 0; i < n; i++ )
2197 SMESH::Filter::Criterion aCriterion = createCriterion();
2198 myTable->GetCriterion( i, aCriterion );
2199 aCriterion.Precision = aPrecision;
2200 aCriteria[ i ] = aCriterion;
2203 myFilter[ theType ] = aFilterMgr->CreateFilter();
2204 myFilter[ theType ]->SetCriteria( aCriteria.inout() );
2209 //=======================================================================
2210 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2211 // Purpose : Insert filter in viewer
2212 //=======================================================================
2213 void SMESHGUI_FilterDlg::insertFilterInViewer()
2215 if ( VTKViewer_InteractorStyleSALOME* aStyle = SMESH::GetInteractorStyle() )
2217 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2219 if ( myFilter[ myTable->GetType() ]->_is_nil() ||
2220 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2221 !mySetInViewer->isChecked() )
2222 SMESH::RemoveFilter( getFilterId( anEntType ), aStyle );
2225 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2226 aFilter->SetPredicate( myFilter[ myTable->GetType() ]->GetPredicate() );
2227 SMESH::SetFilter( aFilter, aStyle );
2232 //=======================================================================
2233 // name : SMESHGUI_FilterDlg::filterSource
2234 // Purpose : Filter source ids
2235 //=======================================================================
2236 void SMESHGUI_FilterDlg::filterSource( const int theType,
2237 QValueList<int>& theResIds )
2240 if ( myFilter[ theType ]->_is_nil() )
2243 int aSourceId = mySourceGrp->id( mySourceGrp->selected() );
2245 if ( aSourceId == Mesh )
2247 if ( myMesh->_is_nil() )
2249 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId( myMesh );
2250 for ( int i = 0, n = anIds->length(); i < n; i++ )
2251 theResIds.append( anIds[ i ] );
2253 else if ( aSourceId == Selection )
2255 filterSelectionSource( theType, theResIds );
2257 else if ( aSourceId == Dialog )
2259 // retrieve ids from dialog
2260 QValueList<int> aDialogIds;
2261 getIdsFromWg( mySourceWg, aDialogIds );
2263 if ( myMesh->_is_nil() )
2265 theResIds = aDialogIds;
2270 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2271 aPred->SetMesh( myMesh );
2272 QValueList<int>::const_iterator anIter;
2273 for ( anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter )
2274 if ( aPred->IsSatisfy( *anIter ) )
2275 theResIds.append( *anIter );
2277 // set ids to the dialog
2278 setIdsToWg( mySourceWg, theResIds );
2282 //=======================================================================
2283 // name : SMESHGUI_FilterDlg::filterSelectionSource
2284 // Purpose : Filter source selection
2285 //=======================================================================
2286 void SMESHGUI_FilterDlg::filterSelectionSource( const int theType,
2287 QValueList<int>& theResIds )
2290 if ( myMesh->_is_nil() || mySelection == 0 )
2293 // Create map of entities to be filtered
2294 TColStd_MapOfInteger aToBeFiltered;
2295 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter( myIObjects );
2297 for ( ; anIter.More(); anIter.Next() )
2300 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>( anIter.Key() );
2301 if ( !aSubMesh->_is_nil() )
2303 if ( aSubMesh->GetFather()->GetId() == myMesh->GetId() )
2305 SMESH::long_array_var anIds =
2306 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2307 for ( int i = 0, n = anIds->length(); i < n; i++ )
2308 aToBeFiltered.Add( anIds[ i ] );
2313 SMESH::SMESH_GroupBase_var aGroup =
2314 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>( anIter.Key() );
2315 if ( !aGroup->_is_nil() )
2317 if ( aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId() )
2319 SMESH::long_array_var anIds = aGroup->GetListOfID();
2320 for ( int i = 0, n = anIds->length(); i < n; i++ )
2321 aToBeFiltered.Add( anIds[ i ] );
2326 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>( anIter.Key() );
2327 if ( !aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId() )
2329 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2331 if ( aSelMap.Extent() > 0 )
2333 if( SMESH::FindActorByEntry( anIter.Key()->getEntry() ) )
2335 for ( int i = 1; i <= aSelMap.Extent(); i++ )
2336 aToBeFiltered.Add( aSelMap(i) );
2343 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2344 aPred->SetMesh( myMesh );
2345 TColStd_MapIteratorOfMapOfInteger aResIter( aToBeFiltered );
2346 for ( ; aResIter.More(); aResIter.Next() )
2347 if ( aPred->IsSatisfy( aResIter.Key() ) )
2348 theResIds.append( aResIter.Key() );
2351 //=======================================================================
2352 // name : SMESHGUI_FilterDlg::selectInViewer
2353 // Purpose : Select given entities in viewer
2354 //=======================================================================
2355 void SMESHGUI_FilterDlg::selectInViewer( const int theType, const QValueList<int>& theIds )
2357 if ( mySelection == 0 || myMesh->_is_nil() )
2360 mySelection->ClearFilters();
2362 // Set new selection mode if necessary
2363 Selection_Mode aSelMode = getSelMode( theType );
2364 if ( aSelMode != mySelection->SelectionMode() )
2366 mySelection->ClearIObjects();
2367 mySelection->ClearFilters();
2368 if ( aSelMode == NodeSelection )
2369 SMESH::SetPointRepresentation(true);
2370 QAD_Application::getDesktop()->SetSelectionMode( aSelMode );
2374 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2375 if ( !anActor || !anActor->hasIO() )
2378 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2379 mySelection->ClearIObjects();
2380 mySelection->AddIObject( anIO, false );
2382 // Remove filter corresponding to the current type from viewer
2383 int aType = myTable->GetType();
2384 int aFilterId = SMESHGUI_UnknownFilter;
2385 if ( aType == SMESH::EDGE ) aFilterId = SMESHGUI_EdgeFilter;
2386 else if ( aType == SMESH::FACE ) aFilterId = SMESHGUI_FaceFilter;
2387 else if ( aType == SMESH::VOLUME ) aFilterId = SMESHGUI_VolumeFilter;
2388 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter( aFilterId );
2389 SMESH::RemoveFilter( aFilterId );
2392 TColStd_MapOfInteger aMap;
2393 QValueList<int>::const_iterator anIter;
2394 for ( anIter = theIds.begin(); anIter != theIds.end(); ++anIter )
2396 aMap.Add( *anIter );
2399 // Set new selection
2400 mySelection->AddOrRemoveIndex( anIO, aMap, false, true );
2402 // insert previously stored filter in viewer if necessary
2403 if ( !aFilter.IsNull() )
2404 SMESH::SetFilter( aFilter );
2407 //=======================================================================
2408 // name : SMESHGUI_FilterDlg::createCriterion
2409 // Purpose : Create criterion structure with default values
2410 //=======================================================================
2411 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2413 SMESH::Filter::Criterion aCriterion;
2415 aCriterion.Type = FT_Undefined;
2416 aCriterion.Compare = FT_Undefined;
2417 aCriterion.Threshold = 0;
2418 aCriterion.UnaryOp = FT_Undefined;
2419 aCriterion.BinaryOp = FT_Undefined;
2420 aCriterion.ThresholdStr = "";
2421 aCriterion.TypeOfElement = SMESH::ALL;
2426 //=======================================================================
2427 // name : SMESHGUI_FilterDlg::onSelectionDone
2428 // Purpose : SLOT called when selection changed.
2429 // If current cell corresponds to the threshold value of
2430 // BelongToGeom criterion name of selected object is set in this cell
2431 //=======================================================================
2432 void SMESHGUI_FilterDlg::onSelectionDone()
2435 if ( mySelection->IObjectCount() != 1 ||
2436 !myTable->CurrentCell( aRow, aCol ) ||
2437 myTable->GetCriterionType( aRow ) != FT_BelongToGeom &&
2438 myTable->GetCriterionType( aRow ) != FT_BelongToPlane &&
2439 myTable->GetCriterionType( aRow ) != FT_BelongToCylinder &&
2440 myTable->GetCriterionType( aRow ) != FT_LyingOnGeom )
2443 Handle(SALOME_InteractiveObject) anIO = mySelection->firstIObject() ;
2444 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>( anIO ) ;
2445 if ( !anObj->_is_nil() )
2446 myTable->SetThreshold( aRow, GEOMBase::GetName(anObj) );
2449 //=======================================================================
2450 // name : SMESHGUI_FilterDlg::onCriterionChanged
2451 // Purpose : SLOT called when cretarion of current row changed. Update selection
2452 //=======================================================================
2453 void SMESHGUI_FilterDlg::onCriterionChanged( const int , const int )
2458 //=======================================================================
2459 // name : SMESHGUI_FilterDlg::onCurrentChanged
2460 // Purpose : SLOT called when current row changed. Update selection
2461 //=======================================================================
2462 void SMESHGUI_FilterDlg::onCurrentChanged( int, int )
2467 //=======================================================================
2468 // name : SMESHGUI_FilterDlg::updateSelection
2469 // Purpose : UpdateSelection in accordance with current row
2470 //=======================================================================
2471 void SMESHGUI_FilterDlg::updateSelection()
2473 if ( mySelection == 0 )
2476 mySelection->ClearFilters();
2480 if ( myTable->CurrentCell( aRow, aCol ) &&
2481 ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom ||
2482 myTable->GetCriterionType( aRow ) == FT_BelongToPlane ||
2483 myTable->GetCriterionType( aRow ) == FT_BelongToCylinder ||
2484 myTable->GetCriterionType( aRow ) == FT_LyingOnGeom) )
2486 if ( myTable->GetCriterionType( aRow ) == FT_BelongToGeom || myTable->GetCriterionType( aRow ) == FT_LyingOnGeom )
2487 mySelection->AddFilter( new SALOME_TypeFilter( "GEOM" ) );
2488 else if ( myTable->GetCriterionType( aRow ) == FT_BelongToPlane )
2489 mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Plane ) );
2490 else if ( myTable->GetCriterionType( aRow ) == FT_BelongToCylinder )
2491 mySelection->AddFilter( new GEOM_FaceFilter( StdSelect_Cylinder ) );
2493 myIsSelectionChanged = true;
2497 if ( myIsSelectionChanged )
2498 mySelection->AddFilter( new SALOME_TypeFilter( "This filter deactivate selection" ) );