+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::~Table
+// Purpose : Destructor
+//=======================================================================
+SMESHGUI_FilterTable::Table::~Table()
+{
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::minimumSizeHint
+// Purpose : Get minimum size for the table
+//=======================================================================
+QSize SMESHGUI_FilterTable::Table::minimumSizeHint() const
+{
+ QSize s = QTableWidget::minimumSizeHint();
+ QHeaderView* hv = horizontalHeader();
+ if ( hv )
+ s.setWidth( qMax( s.width(), hv->length() ) );
+ return s;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::setEditable
+// Purpose : Set editable of specified cell
+//=======================================================================
+void SMESHGUI_FilterTable::Table::setEditable (bool isEditable,
+ int row, int col)
+{
+ QTableWidgetItem* anItem = item( row, col );
+ if ( anItem ) {
+ bool isSignalsBlocked = signalsBlocked();
+ blockSignals( true );
+
+ Qt::ItemFlags f = anItem->flags();
+ if ( !isEditable ) f = f & ~Qt::ItemIsEditable;
+ else f = f | Qt::ItemIsEditable;
+ anItem->setFlags( f );
+
+ blockSignals( isSignalsBlocked );
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::isEditable
+// Purpose : Verify wheter cell is editable
+//=======================================================================
+bool SMESHGUI_FilterTable::Table::isEditable (int row, int col) const
+{
+ QTableWidgetItem* anItem = item( row, col );
+ return anItem == 0 || anItem->flags() & Qt::ItemIsEditable;
+}
+
+void SMESHGUI_FilterTable::Table::setReadOnly( bool on )
+{
+ setEditTriggers( on ?
+ QAbstractItemView::NoEditTriggers :
+ QAbstractItemView::AllEditTriggers );
+}
+
+bool SMESHGUI_FilterTable::Table::isReadOnly() const
+{
+ return editTriggers() == QAbstractItemView::NoEditTriggers;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::insertRows
+// Purpose : Insert rows (virtual redefined)
+//=======================================================================
+void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
+{
+ closePersistentEditor( currentItem() );
+ while ( count-- ) insertRow( row );
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Table::text
+// Purpose : Get text from cell (virtual redefined)
+//=======================================================================
+QString SMESHGUI_FilterTable::Table::text (int row, int col)
+{
+ closePersistentEditor( currentItem() );
+ QTableWidgetItem* anItem = item( row, col );
+ return anItem ? anItem->text() : QString();
+}
+
+QList<int> SMESHGUI_FilterTable::Table::selectedRows()
+{
+ QList<QTableWidgetItem*> selItems = selectedItems();
+ QTableWidgetItem* anItem;
+ QList<int> rows;
+
+ foreach( anItem, selItems ) {
+ int r = row( anItem );
+ if ( !rows.contains( r ) ) rows.append( r );
+ }
+
+ qSort( rows );
+ return rows;
+}
+
+/*
+ Class : SMESHGUI_FilterTable
+ Description : Frame containig
+ - Button group for switching entity type
+ - Table for displaying filter criterions
+ - Buttons for editing table and filter libraries
+*/
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
+ QWidget* parent,
+ const int type )
+: QWidget( parent ),
+ myIsLocked( false ),
+ mySMESHGUI( theModule )
+{
+ myEntityType = -1;
+
+ QList<int> aTypes;
+ aTypes.append(type);
+ Init(aTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
+ QWidget* parent,
+ const QList<int>& types )
+: QWidget( parent ),
+ myIsLocked( false ),
+ mySMESHGUI( theModule )
+{
+ myEntityType = -1;
+ Init(types);
+}
+
+SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
+{
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Init
+// Purpose : Create table corresponding to the specified type
+//=======================================================================
+void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
+{
+ if (theTypes.isEmpty())
+ return;
+
+ // Create buttons if necessary
+
+ if (myTables.isEmpty())
+ {
+ // create main layout
+ QVBoxLayout* aMainLay = new QVBoxLayout(this);
+ aMainLay->setMargin( 0 );
+ aMainLay->setSpacing( SPACING );
+
+ // create switch of entity types
+ myEntityTypeBox = new QGroupBox(tr("ENTITY_TYPE"), this);
+ QHBoxLayout* myEntityTypeBoxLayout = new QHBoxLayout(myEntityTypeBox);
+ myEntityTypeBoxLayout->setMargin( MARGIN );
+ myEntityTypeBoxLayout->setSpacing( SPACING );
+ myEntityTypeGrp = new QButtonGroup(this);
+
+ const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
+ QMap<int, QString>::const_iterator anIter;
+ for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
+ {
+ QRadioButton* aBtn = new QRadioButton(anIter.value(), myEntityTypeBox);
+ myEntityTypeGrp->addButton(aBtn, anIter.key());
+ myEntityTypeBoxLayout->addWidget(aBtn);
+ }
+
+ myTableGrp = new QGroupBox(tr("FILTER"), this );
+
+ // create table
+ mySwitchTableGrp = new QWidget(myTableGrp);
+ QVBoxLayout* mySwitchTableGrpLayout = new QVBoxLayout(mySwitchTableGrp);
+ mySwitchTableGrpLayout->setMargin(0);
+ mySwitchTableGrpLayout->setSpacing(0);
+
+ QList<int>::const_iterator typeIt = theTypes.begin();
+ for ( ; typeIt != theTypes.end(); ++typeIt ) {
+ Table* aTable = createTable(mySwitchTableGrp, *typeIt);
+ myTables[ *typeIt ] = aTable;
+ mySwitchTableGrpLayout->addWidget(aTable);
+ if ( typeIt != theTypes.begin() )
+ aTable->hide();
+ }
+
+ // create buttons
+ myAddBtn = new QPushButton(tr("ADD"), myTableGrp);
+ myRemoveBtn = new QPushButton(tr("REMOVE"), myTableGrp);
+ myClearBtn = new QPushButton(tr("CLEAR"), myTableGrp);
+ myInsertBtn = new QPushButton(tr("INSERT"), myTableGrp);
+ myCopyFromBtn = new QPushButton(tr("COPY_FROM"), myTableGrp);
+ myAddToBtn = new QPushButton(tr("ADD_TO"), myTableGrp);
+
+ myAddBtn->setAutoDefault(false);
+ myRemoveBtn->setAutoDefault(false);
+ myClearBtn->setAutoDefault(false);
+ myInsertBtn->setAutoDefault(false);
+ myCopyFromBtn->setAutoDefault(false);
+ myAddToBtn->setAutoDefault(false);
+
+ myCopyFromBtn->hide();
+ myAddToBtn->hide();
+
+ // layout widgets
+ QGridLayout* aLay = new QGridLayout(myTableGrp);
+ aLay->setMargin(MARGIN);
+ aLay->setSpacing(SPACING);
+
+ aLay->addWidget(mySwitchTableGrp, 0, 0, 7, 1);
+ aLay->addWidget(myAddBtn, 0, 1);
+ aLay->addWidget(myInsertBtn, 1, 1);
+ aLay->addWidget(myRemoveBtn, 2, 1);
+ aLay->addWidget(myClearBtn, 3, 1);
+ aLay->addWidget(myCopyFromBtn, 5, 1);
+ aLay->addWidget(myAddToBtn, 6, 1);
+ aLay->addWidget(createAdditionalFrame(myTableGrp), 7, 0, 1, 2 );
+
+ aLay->setRowMinimumHeight(4, 10);
+ aLay->setRowStretch(4, 1);
+ aLay->setColumnStretch(0, 1);
+ aLay->setColumnStretch(1, 0);
+
+ // layout
+ aMainLay->addWidget(myEntityTypeBox);
+ aMainLay->addWidget(myTableGrp);
+
+ // signals and slots
+ connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
+ connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
+ connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
+ connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
+
+ connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
+ connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
+
+ connect(myEntityTypeGrp, SIGNAL(buttonClicked(int)), this, SLOT(onEntityType(int)));
+
+ myLibDlg = 0;
+ }
+ else
+ {
+ QList<int>::const_iterator typeIt = theTypes.begin();
+ for ( ; typeIt != theTypes.end(); ++typeIt ) {
+ if ( !myTables[ *typeIt ] ) {
+ Table* aTable = createTable(mySwitchTableGrp, *typeIt);
+ myTables[ *typeIt ] = aTable;
+ ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ *typeIt ]);
+ myEntityType = -1;
+ }
+ }
+ }
+
+ // Hide buttons of entity types if necessary
+ const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
+ QMap<int, QString>::const_iterator anIt;
+ for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
+ {
+ QAbstractButton* aBtn = myEntityTypeGrp->button(anIt.key());
+ if ( aBtn ) aBtn->setVisible( theTypes.contains(anIt.key()) );
+ }
+
+ // select first button if there is no selected buttons or it is hidden
+ int aBtnId = myEntityTypeGrp->checkedId();
+ if ( aBtnId == -1 || !theTypes.contains(aBtnId) ) {
+ QAbstractButton* aBtn = myEntityTypeGrp->button(theTypes.first());
+ if ( aBtn ) aBtn->setChecked(true);
+ }
+
+ myEntityTypeBox->setVisible(theTypes.count() > 1);
+
+ myTableGrp->updateGeometry();
+ int cType = myEntityTypeGrp->checkedId();
+ onEntityType(cType);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::createAdditionalFrame
+// Purpose : Get group box containing table. May be used for adding new widgets in it
+//=======================================================================
+QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
+{
+ QWidget* aFrame = new QWidget(theParent);
+
+ QFrame* aLine1 = new QFrame(aFrame);
+ QFrame* aLine2 = new QFrame(aFrame);
+ aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
+ aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
+ aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+ aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+
+ QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
+
+ myWgStack = new QStackedWidget(aFrame);
+
+ QGridLayout* aLay = new QGridLayout(aFrame);
+ aLay->setMargin(0);
+ aLay->setSpacing(SPACING);
+ aLay->addWidget(aLine1, 0, 0);
+ aLay->addWidget(aLabel, 0, 1);
+ aLay->addWidget(aLine2, 0, 2);
+ aLay->addWidget(myWgStack, 1, 0, 1, 3);
+
+ return aFrame;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::GetTableGrp
+// Purpose : Get group box containing table. May be used for adding new widgets in it
+//=======================================================================
+QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
+{
+ return myTableGrp;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onEntityType
+// Purpose : SLOT. Called when entity type changed.
+// Display corresponding table
+//=======================================================================
+void SMESHGUI_FilterTable::onEntityType (int theType)
+{
+ if (myEntityType == theType)
+ return;
+
+ myIsValid = true;
+ emit NeedValidation();
+ if (!myIsValid)
+ {
+ myEntityTypeGrp->button(myEntityType)->setChecked(true);
+ return;
+ }
+
+ myEntityType = theType;
+
+ if (!myTables.contains(theType)) {
+ myTables[ theType ] = createTable(mySwitchTableGrp, theType);
+ ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ theType ]);
+ }
+
+ TableMap::iterator anIter;
+ for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
+ anIter.value()->setVisible( myEntityType == anIter.key() );
+
+ updateBtnState();
+ qApp->processEvents();
+ myTables[ myEntityType ]->updateGeometry();
+ adjustSize();
+
+ emit EntityTypeChanged(theType);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::IsValid
+// Purpose : Verify validity of entered data
+//=======================================================================
+bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
+{
+ int aType = theEntityType == -1 ? GetType() : theEntityType;
+
+ Table* aTable = myTables[ aType ];
+ for (int i = 0, n = aTable->rowCount(); i < n; i++)
+ {
+ int aCriterion = GetCriterionType(i, aType);
+ QString errMsg;
+ if (aCriterion == SMESH::FT_GroupColor )
+ {
+ QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
+ if (clrBtn && !clrBtn->color().isValid())
+ errMsg = tr( "GROUPCOLOR_ERROR" );
+ }
+ else if (aCriterion == SMESH::FT_RangeOfIds ||
+ aCriterion == SMESH::FT_BelongToMeshGroup ||
+ aCriterion == SMESH::FT_BelongToGeom ||
+ aCriterion == SMESH::FT_BelongToPlane ||
+ aCriterion == SMESH::FT_BelongToCylinder ||
+ aCriterion == SMESH::FT_BelongToGenSurface ||
+ aCriterion == SMESH::FT_ElemGeomType ||
+ aCriterion == SMESH::FT_EntityType ||
+ aCriterion == SMESH::FT_CoplanarFaces ||
+ aCriterion == SMESH::FT_LyingOnGeom ||
+ aCriterion == SMESH::FT_ConnectedElements )
+ {
+ if (aTable->text(i, 2).isEmpty())
+ errMsg = tr( "ERROR" );
+ }
+ else // check correctness of a numeric value
+ {
+ bool aRes = false;
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals(true);
+ double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
+ aTable->blockSignals(isSignalsBlocked);
+
+ if (!aRes && aTable->isEditable(i, 2))
+ errMsg = tr( "ERROR" );
+ }
+
+ if (!errMsg.isEmpty()) {
+ if (theMess)
+ SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"), errMsg );
+ return false;
+ }
+
+ QTableWidgetItem* anItem = aTable->item(i, 0);
+ if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
+ return false;
+ }
+
+ return true;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetValidity
+// Purpose : Set validity of the table
+//=======================================================================
+void SMESHGUI_FilterTable::SetValidity (const bool isValid)
+{
+ myIsValid = isValid;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::GetType
+// Purpose : Get current entity type
+//=======================================================================
+int SMESHGUI_FilterTable::GetType() const
+{
+ return myEntityType;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetType
+// Purpose : Set current entity type
+//=======================================================================
+void SMESHGUI_FilterTable::SetType (const int type)
+{
+ myEntityTypeGrp->button(type)->setChecked(true);
+ onEntityType(type);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::RestorePreviousEntityType
+// Purpose : Restore previous entity type
+//=======================================================================
+void SMESHGUI_FilterTable::RestorePreviousEntityType()
+{
+ SetType(myEntityType);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::GetCriterionType
+// Purpose : Get type of criterion from specified row (corresponding enums in h-file)
+//=======================================================================
+int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
+{
+ int aType = theType == -1 ? GetType() : theType;
+ Table* aTable = myTables[ aType ];
+ ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
+ return anItem != 0 ? anItem->value() : SMESH::FT_Undefined;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::GetCriterion
+// Purpose : Get parameters of criterion from specified row
+//=======================================================================
+void SMESHGUI_FilterTable::GetCriterion (const int theRow,
+ SMESH::Filter::Criterion& theCriterion,
+ const int theEntityType) const
+{
+ int aType = theEntityType == -1 ? GetType() : theEntityType;
+ Table* aTable = myTables[ aType ];
+
+ theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->value();
+ theCriterion.UnaryOp = ((CheckItem*)aTable->item(theRow, 3))->checked() ? SMESH::FT_LogicalNOT : SMESH::FT_Undefined;
+ theCriterion.BinaryOp = theRow != aTable->rowCount() - 1 ?
+ ((ComboItem*)aTable->item(theRow, 4))->value() : SMESH::FT_Undefined;
+ theCriterion.TypeOfElement = (SMESH::ElementType)aType;
+
+ int aCriterionType = GetCriterionType(theRow, aType);
+
+ if ( aCriterionType == SMESH::FT_GroupColor )
+ {
+ QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
+ if ( clrBtn )
+ {
+ Kernel_Utils::Localizer loc;
+ const QColor qClr = clrBtn->color();
+ QString clrStr = QString( "%1;%2;%3" ).
+ arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
+ theCriterion.ThresholdStr = clrStr.toLatin1().constData();
+ }
+ }
+ else if ( aCriterionType == SMESH::FT_ElemGeomType ||
+ aCriterionType == SMESH::FT_EntityType )
+ {
+ theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
+ }
+ else if ( aCriterionType == SMESH::FT_CoplanarFaces )
+ {
+ theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
+ }
+ else if ( aCriterionType == SMESH::FT_ConnectedElements )
+ {
+ QString id = aTable->text(theRow, 5);
+ if ( !id.isEmpty() ) // shape ID
+ {
+ theCriterion.ThresholdID = id.toLatin1().constData();
+ }
+ else
+ {
+ QString text = aTable->text(theRow, 2).trimmed();
+ QString workText = text;
+ for ( char c = '0'; c <= '9'; ++c )
+ workText.remove( c );
+
+ if ( workText.isEmpty() ) // node ID
+ theCriterion.Threshold = text.toDouble();
+ else // point coordinates
+ theCriterion.ThresholdStr = text.toLatin1().constData();
+ }
+ }
+ else if ( aCriterionType != SMESH::FT_RangeOfIds &&
+ aCriterionType != SMESH::FT_BelongToMeshGroup &&
+ aCriterionType != SMESH::FT_BelongToGeom &&
+ aCriterionType != SMESH::FT_BelongToPlane &&
+ aCriterionType != SMESH::FT_BelongToCylinder &&
+ aCriterionType != SMESH::FT_BelongToGenSurface &&
+ aCriterionType != SMESH::FT_LyingOnGeom )
+ {
+ theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->value();
+ theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
+ }
+ else
+ {
+ theCriterion.ThresholdStr = aTable->text(theRow, 2).toLatin1().constData();
+ if ( aCriterionType != SMESH::FT_RangeOfIds )
+ theCriterion.ThresholdID = aTable->text( theRow, 5 ).toLatin1().constData();
+ }
+
+ QTableWidgetItem* anItem = aTable->item(theRow, 0);
+ if (myAddWidgets.contains(anItem))
+ theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetCriterion
+// Purpose : Set parameters of criterion of specified row
+//=======================================================================
+void SMESHGUI_FilterTable::SetCriterion (const int theRow,
+ const SMESH::Filter::Criterion& theCriterion,
+ const int theEntityType)
+{
+ int aType = theEntityType == -1 ? GetType() : theEntityType;
+
+ Table* aTable = myTables[ aType ];
+
+ if (theRow > aTable->rowCount() - 1)
+ return;
+
+ ((ComboItem*)aTable->item(theRow, 0))->setValue(theCriterion.Type);
+ onCriterionChanged(theRow, 0, aType);
+ if ( theCriterion.Compare == SMESH::FT_Undefined )
+ ((ComboItem*)aTable->item(theRow, 1))->setValue( SMESH::FT_EqualTo );
+ else
+ ((ComboItem*)aTable->item(theRow, 1))->setValue(theCriterion.Compare);
+ ((CheckItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == SMESH::FT_LogicalNOT);
+
+ if (theCriterion.BinaryOp != SMESH::FT_Undefined)
+ {
+ if (!aTable->isEditable(theRow, 4))
+ aTable->setItem(theRow, 4, getBinaryItem());
+ ((ComboItem*)aTable->item(theRow, 4))->setValue(theCriterion.BinaryOp);
+ }
+ else
+ aTable->setEditable(false, theRow, 4);
+
+ if (theCriterion.Type == SMESH::FT_GroupColor )
+ {
+ QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
+ if ( clrBtn )
+ {
+ QColor qClr;
+ QString clrStr( theCriterion.ThresholdStr );
+ QStringList clrVals = clrStr.split( ";" );
+ if ( clrVals.count() > 2 )
+ qClr.setRgb( (int)256*clrVals[0].toDouble(),
+ (int)256*clrVals[1].toDouble(),
+ (int)256*clrVals[2].toDouble() );
+ clrBtn->setColor( qClr );
+ }
+ }
+ else if (theCriterion.Type == SMESH::FT_ElemGeomType ||
+ theCriterion.Type == SMESH::FT_EntityType )
+ {
+ ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
+ typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
+ }
+ else if (theCriterion.Type == SMESH::FT_CoplanarFaces )
+ {
+ aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
+ }
+ else if (theCriterion.Type == SMESH::FT_ConnectedElements )
+ {
+ if ( strlen( theCriterion.ThresholdID ) > 0 ) // shape ID -> name
+ {
+ _PTR(SObject) sobj =
+ SMESH::GetActiveStudyDocument()->FindObjectID( theCriterion.ThresholdID.in() );
+ if ( !sobj )
+ aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
+ else
+ aTable->item( theRow, 2 )->setText( QString( sobj->GetName().c_str() ));
+ }
+ else if ( strlen( theCriterion.ThresholdStr ) > 0 ) // point coords
+ {
+ aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdStr ));
+ }
+ else // node ID
+ {
+ aTable->item( theRow, 2 )->setText( QString("%1").arg((int) theCriterion.Threshold ));
+ }
+ }
+ else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
+ theCriterion.Type != SMESH::FT_BelongToMeshGroup &&
+ theCriterion.Type != SMESH::FT_BelongToGeom &&
+ theCriterion.Type != SMESH::FT_BelongToPlane &&
+ theCriterion.Type != SMESH::FT_BelongToCylinder &&
+ theCriterion.Type != SMESH::FT_BelongToGenSurface &&
+ theCriterion.Type != SMESH::FT_LyingOnGeom &&
+ theCriterion.Type != SMESH::FT_FreeBorders &&
+ theCriterion.Type != SMESH::FT_FreeEdges &&
+ theCriterion.Type != SMESH::FT_FreeNodes &&
+ theCriterion.Type != SMESH::FT_FreeFaces &&
+ theCriterion.Type != SMESH::FT_BadOrientedVolume &&
+ theCriterion.Type != SMESH::FT_BareBorderFace &&
+ theCriterion.Type != SMESH::FT_BareBorderVolume &&
+ theCriterion.Type != SMESH::FT_OverConstrainedFace &&
+ theCriterion.Type != SMESH::FT_OverConstrainedVolume &&
+ theCriterion.Type != SMESH::FT_LinearOrQuadratic)
+ {
+ // Numberic criterion
+ aTable->item( theRow, 2 )->setText(QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
+ }
+ else
+ {
+ aTable->item( theRow, 2 )->setText(QString(theCriterion.ThresholdStr));
+ if ( theCriterion.Type != SMESH::FT_RangeOfIds )
+ aTable->item( theRow, 5 )->setText( QString( theCriterion.ThresholdID ) );
+ }
+
+ if (theCriterion.Compare == SMESH::FT_EqualTo ||
+ theCriterion.Type == SMESH::FT_BelongToPlane ||
+ theCriterion.Type == SMESH::FT_BelongToCylinder ||
+ theCriterion.Type == SMESH::FT_BelongToGenSurface ||
+ theCriterion.Type == SMESH::FT_BelongToGeom ||
+ theCriterion.Type == SMESH::FT_LyingOnGeom ||
+ theCriterion.Type == SMESH::FT_CoplanarFaces ||
+ theCriterion.Type == SMESH::FT_EqualNodes)
+ {
+ QTableWidgetItem* anItem = aTable->item(theRow, 0);
+ if (!myAddWidgets.contains(anItem))
+ {
+ myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
+ myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( theCriterion.Type ) );
+ myWgStack->addWidget(myAddWidgets[ anItem ]);
+ }
+ myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
+ }
+
+ emit CriterionChanged(theRow, aType);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Update
+// Purpose : Update table
+//=======================================================================
+void SMESHGUI_FilterTable::Update()
+{
+ Table* aTable = myTables[ GetType() ];
+ int aCurrRow = aTable->currentRow();
+ int numRows = aTable->rowCount();
+ if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
+ aTable->setCurrentCell(0, 0);
+ updateAdditionalWidget();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::AddCriterion
+// Purpose : Add criterion with parameters
+//=======================================================================
+void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
+ const int theEntityType)
+{
+ int aType = theEntityType == -1 ? GetType() : theEntityType;
+ Table* aTable = myTables[ aType ];
+ addRow(aTable, aType);
+ SetCriterion(aTable->rowCount() - 1, theCriterion);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::NumRows
+// Purpose : Get number of criterions of current type
+//=======================================================================
+int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
+{
+ return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->rowCount();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Clear
+// Purpose : Clear current table
+//=======================================================================
+void SMESHGUI_FilterTable::Clear (const int theType)
+{
+ int aType = theType == -1 ? GetType() : theType;
+ Table* aTable = myTables[ aType ];
+
+ if (aTable->rowCount() == 0)
+ return;
+
+ while (aTable->rowCount() > 0)
+ {
+ removeAdditionalWidget(aTable, 0);
+ aTable->removeRow(0);
+ }
+
+ updateBtnState();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onAddBtn
+// Purpose : SLOT. Called then "Add" button pressed.
+// Adds new string to table
+//=======================================================================
+void SMESHGUI_FilterTable::onAddBtn()
+{
+ int aType = GetType();
+ addRow(myTables[ aType ], aType);
+
+ Update();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onInsertBtn
+// Purpose : SLOT. Called then "Insert" button pressed.
+// Inserts new string before current one
+//=======================================================================
+void SMESHGUI_FilterTable::onInsertBtn()
+{
+ addRow(myTables[ GetType() ], GetType(), false);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onRemoveBtn
+// Purpose : SLOT. Called then "Remove" button pressed.
+// Removes current string from table
+//=======================================================================
+void SMESHGUI_FilterTable::onRemoveBtn()
+{
+ Table* aTable = myTables[ GetType() ];
+
+ if (aTable->rowCount() == 0)
+ return;
+
+ QList<QTableWidgetItem*> items = aTable->selectedItems();
+
+ QList<int> aRows = aTable->selectedRows(); // already sorted
+ int i;
+ foreach( i, aRows )
+ {
+ removeAdditionalWidget(aTable, i);
+ aTable->removeRow(i);
+ }
+
+ // remove control of binary logical operation from last row
+ if (aTable->rowCount() > 0)
+ aTable->setEditable(false, aTable->rowCount() - 1, 4);
+
+ updateBtnState();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::updateAdditionalWidget
+// Purpose : Enable/Disable widget with additonal parameters
+//=======================================================================
+void SMESHGUI_FilterTable::updateAdditionalWidget()
+{
+ Table* aTable = myTables[ GetType() ];
+ int aRow = aTable->currentRow();
+ if (aRow < 0 || aRow >= aTable->rowCount())
+ {
+ myWgStack->setEnabled(false);
+ return;
+ }
+
+ ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
+ int aCriterion = GetCriterionType(aRow);
+ bool isDbl = ( aCriterion == SMESH::FT_AspectRatio ||
+ aCriterion == SMESH::FT_AspectRatio3D ||
+ aCriterion == SMESH::FT_Warping ||
+ aCriterion == SMESH::FT_MinimumAngle ||
+ aCriterion == SMESH::FT_Taper ||
+ aCriterion == SMESH::FT_Skew ||
+ aCriterion == SMESH::FT_Area ||
+ aCriterion == SMESH::FT_Volume3D ||
+ aCriterion == SMESH::FT_MaxElementLength2D ||
+ aCriterion == SMESH::FT_MaxElementLength3D ||
+ aCriterion == SMESH::FT_Length ||
+ aCriterion == SMESH::FT_Length2D ||
+ aCriterion == SMESH::FT_BallDiameter );
+
+ bool toEnable = (( isDbl && ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo) ||
+ aCriterion == SMESH::FT_BelongToPlane ||
+ aCriterion == SMESH::FT_BelongToCylinder ||
+ aCriterion == SMESH::FT_BelongToGenSurface ||
+ aCriterion == SMESH::FT_BelongToGeom ||
+ aCriterion == SMESH::FT_LyingOnGeom ||
+ aCriterion == SMESH::FT_CoplanarFaces ||
+ aCriterion == SMESH::FT_EqualNodes);
+
+ if (!myAddWidgets.contains(anItem))
+ {
+ myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
+ myWgStack->addWidget(myAddWidgets[ anItem ]);
+ }
+
+ myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
+ myAddWidgets[ anItem ]->SetPrecision( AdditionalWidget::Tolerance, getPrecision( aCriterion ) );
+ myWgStack->setEnabled(toEnable);
+}
+
+const char* SMESHGUI_FilterTable::getPrecision( const int aType )
+{
+ const char* retval = 0;
+ switch ( aType ) {
+ case SMESH::FT_AspectRatio:
+ case SMESH::FT_AspectRatio3D:
+ case SMESH::FT_Taper:
+ retval = "parametric_precision"; break;
+ case SMESH::FT_Warping:
+ case SMESH::FT_MinimumAngle:
+ case SMESH::FT_Skew:
+ case SMESH::FT_CoplanarFaces:
+ retval = "angle_precision"; break;
+ case SMESH::FT_Area:
+ retval = "area_precision"; break;
+ case SMESH::FT_BelongToGeom:
+ case SMESH::FT_BelongToPlane:
+ case SMESH::FT_BelongToCylinder:
+ case SMESH::FT_BelongToGenSurface:
+ case SMESH::FT_LyingOnGeom:
+ case SMESH::FT_EqualNodes:
+ retval = "len_tol_precision"; break;
+ case SMESH::FT_Length:
+ case SMESH::FT_Length2D:
+ case SMESH::FT_MaxElementLength2D:
+ case SMESH::FT_MaxElementLength3D:
+ case SMESH::FT_BallDiameter:
+ retval = "length_precision"; break;
+ case SMESH::FT_Volume3D:
+ retval = "vol_precision"; break;
+ default:
+ break;
+ }
+ return retval;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::removeAdditionalWidget
+// Purpose : Remove widgets containing additional parameters from widget
+// stack and internal map
+//=======================================================================
+void SMESHGUI_FilterTable::removeAdditionalWidget (QTableWidget* theTable, const int theRow)
+{
+ QTableWidgetItem* anItem = theTable->item(theRow, 0);
+ if (myAddWidgets.contains(anItem))
+ {
+ myWgStack->removeWidget(myAddWidgets[ anItem ]);
+ myAddWidgets[ anItem ]->setParent(0);
+ delete myAddWidgets[ anItem ];
+ myAddWidgets.remove(anItem);
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onClearBtn
+// Purpose : SLOT. Called then "Clear" button pressed.
+// Removes all strings from table
+//=======================================================================
+void SMESHGUI_FilterTable::onClearBtn()
+{
+ Table* aTable = myTables[ GetType() ];
+
+ if (aTable->rowCount() == 0)
+ return;
+
+ while (aTable->rowCount() > 0)
+ {
+ removeAdditionalWidget(aTable, 0);
+ aTable->removeRow(0);
+ }
+
+ updateBtnState();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onCurrentChanged()
+// Purpose : SLOT. Called when current cell changed
+//=======================================================================
+void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
+{
+ if( !myIsLocked )
+ updateAdditionalWidget();
+ emit CurrentChanged(theRow, theCol);
+}
+
+//=======================================================================
+// name : geomTypes
+// Purpose : returns available geometry types of elements
+//=======================================================================
+static QList<int> geomTypes( const int theType )
+{
+ QList<int> typeIds;
+ if ( theType == SMESH::NODE )
+ typeIds.append( SMESH::Geom_POINT );
+ if ( theType == SMESH::ALL || theType == SMESH::EDGE )
+ typeIds.append( SMESH::Geom_EDGE );
+ if ( theType == SMESH::ALL || theType == SMESH::FACE )
+ {
+ typeIds.append( SMESH::Geom_TRIANGLE );
+ typeIds.append( SMESH::Geom_QUADRANGLE );
+ typeIds.append( SMESH::Geom_POLYGON );
+ }
+ if ( theType == SMESH::ALL || theType == SMESH::VOLUME )
+ {
+ typeIds.append( SMESH::Geom_TETRA );
+ typeIds.append( SMESH::Geom_PYRAMID );
+ typeIds.append( SMESH::Geom_HEXA );
+ typeIds.append( SMESH::Geom_PENTA );
+ typeIds.append( SMESH::Geom_HEXAGONAL_PRISM );
+ typeIds.append( SMESH::Geom_POLYHEDRA );
+ }
+ if ( theType == SMESH::ALL || theType == SMESH::ELEM0D )
+ {
+ typeIds.append( SMESH::Geom_POINT );
+ }
+ if ( theType == SMESH::ALL || theType == SMESH::BALL )
+ {
+ typeIds.append( SMESH::Geom_BALL );
+ }
+ return typeIds;
+}
+
+//=======================================================================
+// name : entityTypes
+// Purpose : returns available entity types of elements
+//=======================================================================
+
+static QList<int> entityTypes( const int theType )
+{
+ QList<int> typeIds;
+
+ switch ( theType )
+ {
+ case SMESH::NODE:
+ typeIds.append( SMDSEntity_Node );
+ case SMESH::EDGE:
+ typeIds.append( SMDSEntity_Edge );
+ typeIds.append( SMDSEntity_Quad_Edge );
+ break;
+ case SMESH::FACE:
+ typeIds.append( SMDSEntity_Triangle );
+ typeIds.append( SMDSEntity_Quad_Triangle );
+ typeIds.append( SMDSEntity_BiQuad_Triangle );
+ typeIds.append( SMDSEntity_Quadrangle );
+ typeIds.append( SMDSEntity_Quad_Quadrangle );
+ typeIds.append( SMDSEntity_BiQuad_Quadrangle );
+ typeIds.append( SMDSEntity_Polygon );
+ typeIds.append( SMDSEntity_Quad_Polygon );
+ break;
+ case SMESH::VOLUME:
+ typeIds.append( SMDSEntity_Tetra );
+ typeIds.append( SMDSEntity_Quad_Tetra );
+ typeIds.append( SMDSEntity_Pyramid );
+ typeIds.append( SMDSEntity_Quad_Pyramid );
+ typeIds.append( SMDSEntity_Hexa );
+ typeIds.append( SMDSEntity_Quad_Hexa );
+ typeIds.append( SMDSEntity_TriQuad_Hexa );
+ typeIds.append( SMDSEntity_Penta );
+ typeIds.append( SMDSEntity_Quad_Penta );
+ typeIds.append( SMDSEntity_Hexagonal_Prism );
+ typeIds.append( SMDSEntity_Polyhedra );
+ //typeIds.append( SMDSEntity_Quad_Polyhedra );
+ break;
+ case SMESH::ELEM0D:
+ typeIds.append( SMDSEntity_0D );
+ break;
+ case SMESH::BALL:
+ typeIds.append( SMDSEntity_Ball );
+ break;
+ }
+ return typeIds;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onCriterionChanged()
+// Purpose : Provides reaction on change of criterion
+//=======================================================================
+
+void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
+{
+ int aType = entityType == -1 ? GetType() : entityType;
+ Table* aTable = myTables[ aType ];
+ ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
+
+ // find out type of a existing threshould table item
+ QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
+ bool isComboItem = false;
+ bool isIntSpinItem = false;
+ bool isDoubleSpinItem = false;
+ if ( QTableWidgetItem* aTableItem = aTable->item(row, 2) )
+ {
+ int aTableType = aTableItem->type();
+ isComboItem = ( aTableType == ComboItem::Type() );
+ isIntSpinItem = ( aTableType == IntSpinItem::Type() );
+ isDoubleSpinItem = ( aTableType == DoubleSpinItem::Type() );
+ }
+
+ // find out a type of item required by a new criterion and other table features
+ int aCriterionType = GetCriterionType(row);
+ bool anIsDoubleCriterion = false;
+ bool anIsIntCriterion = false;
+ bool anIsComboCriterion = false;
+ // other features:
+ QList<int> comboIDs; // values to show in a combo item
+ int nbCompareSigns = 0; // possible values are 0,1,3
+ bool isThresholdEditable = false; // actual for "simple" item types
+ switch ( aCriterionType )
+ {
+ case SMESH::FT_AspectRatio:
+ case SMESH::FT_AspectRatio3D:
+ case SMESH::FT_Warping:
+ case SMESH::FT_MinimumAngle:
+ case SMESH::FT_Taper:
+ case SMESH::FT_Skew:
+ case SMESH::FT_Area:
+ case SMESH::FT_Volume3D:
+ case SMESH::FT_MaxElementLength2D:
+ case SMESH::FT_MaxElementLength3D:
+ anIsDoubleCriterion = true; break;
+
+ case SMESH::FT_FreeBorders:
+ case SMESH::FT_FreeEdges:
+ case SMESH::FT_FreeNodes:
+ case SMESH::FT_FreeFaces:
+ case SMESH::FT_EqualNodes:
+ case SMESH::FT_EqualEdges:
+ case SMESH::FT_EqualFaces:
+ case SMESH::FT_EqualVolumes: break;
+
+ case SMESH::FT_MultiConnection:
+ case SMESH::FT_MultiConnection2D: anIsIntCriterion = true; nbCompareSigns = 3; break;
+
+ case SMESH::FT_Length:
+ case SMESH::FT_Length2D: anIsDoubleCriterion = true; break;
+
+ case SMESH::FT_BelongToMeshGroup: break;
+
+ case SMESH::FT_BelongToGeom:
+ case SMESH::FT_BelongToPlane:
+ case SMESH::FT_BelongToCylinder:
+ case SMESH::FT_BelongToGenSurface:
+ case SMESH::FT_LyingOnGeom: nbCompareSigns = 0; isThresholdEditable = true; break;
+
+ case SMESH::FT_RangeOfIds: nbCompareSigns = 0; isThresholdEditable = true; break;
+
+ case SMESH::FT_BadOrientedVolume:
+ case SMESH::FT_BareBorderVolume:
+ case SMESH::FT_BareBorderFace:
+ case SMESH::FT_OverConstrainedVolume:
+ case SMESH::FT_OverConstrainedFace:
+ case SMESH::FT_LinearOrQuadratic: break;
+
+ case SMESH::FT_GroupColor: nbCompareSigns = 1; isThresholdEditable = true; break;
+
+ case SMESH::FT_ElemGeomType:
+ comboIDs = geomTypes( aType ); anIsComboCriterion = true; nbCompareSigns = 1; break;
+
+ case SMESH::FT_EntityType:
+ comboIDs = entityTypes( aType ); anIsComboCriterion = true; nbCompareSigns = 1; break;
+
+ case SMESH::FT_CoplanarFaces: isThresholdEditable = true; break;
+
+ case SMESH::FT_BallDiameter: anIsDoubleCriterion = true; break;
+
+ case SMESH::FT_ConnectedElements: isThresholdEditable = true; break;
+
+ case SMESH::FT_LessThan:
+ case SMESH::FT_MoreThan:
+ case SMESH::FT_EqualTo:
+ case SMESH::FT_LogicalNOT:
+ case SMESH::FT_LogicalAND:
+ case SMESH::FT_LogicalOR:
+ case SMESH::FT_Undefined:
+ default: return;
+ }
+
+ // get a precision of a double criterion
+ int aPrecision = 0;
+ if ( anIsDoubleCriterion ) {
+ const char* aPrecisionType = getPrecision( aCriterionType );
+ SUIT_ResourceMgr* aResourceMgr = SMESH::GetResourceMgr( mySMESHGUI );
+ if( aPrecisionType && aResourceMgr )
+ aPrecision = aResourceMgr->integerValue( "SMESH", aPrecisionType, aPrecision );
+ }
+
+ // check if the current item type satisfies the criterion
+ bool itemTypeKO =
+ ( aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
+ ( anIsComboCriterion && !isComboItem ) ||
+ ( anIsIntCriterion && !isIntSpinItem ) ||
+ ( anIsDoubleCriterion && !isDoubleSpinItem );
+
+ if ( !itemTypeKO )
+ {
+ if ( anIsDoubleCriterion )
+ {
+ // if the precision is to be changed we should remove the existing
+ // spin item and create another one with new precision
+ if ( DoubleSpinItem* aDoubleSpinItem = dynamic_cast<DoubleSpinItem*>( aTable->item( row, 2 )))
+ itemTypeKO = ( aDoubleSpinItem->precision() != aPrecision );
+ else
+ itemTypeKO = true;
+ }
+ else if ( anIsComboCriterion )
+ {
+ if ( ComboItem* aComboItem = dynamic_cast<ComboItem*>( aTable->item( row, 2 )))
+ itemTypeKO = ( aComboItem->count() != comboIDs.count() );
+ else
+ itemTypeKO = true;
+ }
+ else if ( !anIsIntCriterion && aCriterionType != SMESH::FT_GroupColor )
+ {
+ itemTypeKO = ( clrBtn || isComboItem || isIntSpinItem || isDoubleSpinItem );
+ }
+ }
+
+ // update the table row
+
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals( true );
+
+ // update threshold table item
+ if ( itemTypeKO )
+ {
+ aTable->removeCellWidget( row, 2 );
+
+ if ( aCriterionType == SMESH::FT_GroupColor ) // ---------------------- QtxColorButton
+ {
+ aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
+ }
+ else if ( anIsComboCriterion ) // -------------------------------------------ComboItem
+ {
+ QString msgPrefix
+ ( aCriterionType == SMESH::FT_ElemGeomType ? "GEOM_TYPE_%1" : "ENTITY_TYPE_%1" );
+ QMap<int, QString> names;
+ QList<int>::const_iterator id = comboIDs.begin();
+ for ( ; id != comboIDs.end(); ++id )
+ {
+ QString name = msgPrefix.arg( *id );
+ names[ *id ] = tr( name.toLatin1().data() );
+ }
+ ComboItem* comboBox = new ComboItem( names );
+ aTable->setItem( row, 2, comboBox );
+ }
+ else if ( anIsIntCriterion ) // ------------------------------------------ IntSpinItem
+ {
+ IntSpinItem* intSpin = new IntSpinItem( 0 );
+ aTable->setItem( row, 2, intSpin );
+ }
+ else if ( anIsDoubleCriterion ) // -------------------------------------DoubleSpinItem
+ {
+ DoubleSpinItem* dblSpin = new DoubleSpinItem( 0 );
+ dblSpin->setPrecision( aPrecision );
+ aTable->setItem( row, 2, dblSpin );
+ }
+ else // --------------------------------------------------------------QTableWidgetItem
+ {
+ aTable->setItem( row, 2, new QTableWidgetItem() );
+ }
+ }
+
+ // set Compare
+ if ( anIsDoubleCriterion )
+ nbCompareSigns = 3;
+ if ( aCompareItem->count() != nbCompareSigns )
+ {
+ switch ( nbCompareSigns ) {
+ case 0: {
+ aCompareItem->clear();
+ break;
+ }
+ case 1: {
+ QMap<int, QString> aMap;
+ aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
+ aCompareItem->setItems(aMap);
+ break;
+ }
+ case 3: {
+ int oldValue = aCompareItem->value();
+ aCompareItem->setItems(getCompare());
+ if ( oldValue >= 0 )
+ aCompareItem->setValue( oldValue );
+ break;
+ }
+ }
+ }
+ aTable->setEditable( nbCompareSigns == 3, row, 1);
+
+ // enable/desable Threshold
+ if ( aCriterionType == SMESH::FT_GroupColor ||
+ anIsComboCriterion ||
+ anIsIntCriterion ||
+ anIsDoubleCriterion )
+ {
+ isThresholdEditable = true;
+ }
+ if ( !isThresholdEditable )
+ {
+ aTable->setItem( row, 2, new QTableWidgetItem() );
+ }
+ aTable->setEditable( isThresholdEditable, row, 2);
+
+
+ aTable->blockSignals( isSignalsBlocked );
+
+ updateAdditionalWidget();
+
+ emit CriterionChanged(row, entityType);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onCriterionChanged()
+// Purpose : SLOT. Called then contents of table changed
+// Provides reaction on change of criterion
+//=======================================================================
+void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
+{
+ if( col == 0 )
+ onCriterionChanged(row, col, -1);
+ else if ( col == 2 )
+ emit ThresholdChanged(row, GetType());
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getFirstSelectedRow
+// Purpose : Get first selected row
+//=======================================================================
+int SMESHGUI_FilterTable::getFirstSelectedRow() const
+{
+ Table* aTable = myTables[ GetType() ];
+
+ QList<int> selRows = aTable->selectedRows(); // already sorted
+ int aRow = selRows.count() > 0 ? selRows[0] : aTable->currentRow();
+
+ return aRow >= 0 && aRow < aTable->rowCount() ? aRow : -1;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::addRow
+// Purpose : Add row at the end of table
+//=======================================================================
+void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
+{
+ int aCurrRow = 0;
+ int aSelectedRow = getFirstSelectedRow();
+ int aCurrCol = theTable->currentColumn();
+
+ myIsLocked = true;
+ if (toTheEnd || aSelectedRow == -1)
+ {
+ theTable->insertRows(theTable->rowCount());
+ aCurrRow = theTable->rowCount() - 1;
+ }
+ else
+ {
+ theTable->insertRows(aSelectedRow);
+ aCurrRow = aSelectedRow;
+ }
+ myIsLocked = false;
+
+ // IPAL19372 - to prevent calling onCriterionChaged() slot before completion of setItem()
+ bool isSignalsBlocked = theTable->signalsBlocked();
+ theTable->blockSignals( true );
+
+ // Criteria
+ theTable->setItem(aCurrRow, 0, getCriterionItem(theType));
+
+ // Compare
+ theTable->setItem(aCurrRow, 1, getCompareItem());
+
+ // Threshold
+ theTable->setItem(aCurrRow, 2, new QTableWidgetItem());
+
+ // Logical operation NOT
+ theTable->setItem(aCurrRow, 3, getUnaryItem());
+
+ // Logical operation AND / OR
+ theTable->setItem(aCurrRow, 4, new QTableWidgetItem());
+
+ theTable->setItem(aCurrRow, 5, new QTableWidgetItem());
+
+ theTable->blockSignals( isSignalsBlocked );
+
+ // Logical binary operation for previous value
+ int anAddBinOpStr = -1;
+ if (aCurrRow == theTable->rowCount() - 1)
+ anAddBinOpStr = aCurrRow - 1;
+ else if (aCurrRow >= 0 )
+ anAddBinOpStr = aCurrRow;
+
+ if (theTable->item(aCurrRow, 4) == 0 ||
+ theTable->item(aCurrRow, 4)->type() != ComboItem::Type())
+ {
+ if (anAddBinOpStr >= 0 &&
+ (theTable->item(anAddBinOpStr, 4) == 0 ||
+ theTable->item(anAddBinOpStr, 4)->type() != ComboItem::Type()))
+ theTable->setItem(anAddBinOpStr, 4, getBinaryItem());
+ }
+
+ theTable->setEditable(false, theTable->rowCount() - 1, 4);
+
+ if (aCurrRow >=0 && aCurrRow < theTable->rowCount() &&
+ aCurrCol >=0 && aCurrCol < theTable->rowCount())
+ theTable->setCurrentCell(aCurrRow, aCurrCol);
+
+ onCriterionChanged(aCurrRow, 0);
+
+ updateBtnState();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getCriterionItem
+// Purpose : Get combo table item for criteria of specified type
+//=======================================================================
+QTableWidgetItem* SMESHGUI_FilterTable::getCriterionItem (const int theType) const
+{
+ return new ComboItem(getCriteria(theType));
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getCompareItem
+// Purpose : Get combo table item for operation of comparision
+//=======================================================================
+QTableWidgetItem* SMESHGUI_FilterTable::getCompareItem () const
+{
+ return new ComboItem(getCompare());
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getBinaryItem
+// Purpose :
+//=======================================================================
+QTableWidgetItem* SMESHGUI_FilterTable::getBinaryItem () const
+{
+ static QMap<int, QString> aMap;
+ if (aMap.isEmpty())
+ {
+ aMap[ SMESH::FT_LogicalAND ] = tr("AND");
+ aMap[ SMESH::FT_LogicalOR ] = tr("OR");
+ }
+
+ return new ComboItem(aMap);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getUnaryItem
+// Purpose : Get check table item
+//=======================================================================
+QTableWidgetItem* SMESHGUI_FilterTable::getUnaryItem () const
+{
+ return new CheckItem(tr("NOT"));
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getSupportedTypes
+// Purpose : Get all supported type
+//=======================================================================
+const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
+{
+ static QMap<int, QString> aTypes;
+ if (aTypes.isEmpty())
+ {
+ aTypes[ SMESH::NODE ] = tr("NODES");
+ aTypes[ SMESH::ELEM0D ] = tr("ELEM0D");
+ aTypes[ SMESH::BALL ] = tr("BALLS");
+ aTypes[ SMESH::EDGE ] = tr("EDGES");
+ aTypes[ SMESH::FACE ] = tr("FACES");
+ aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
+ aTypes[ SMESH::ALL ] = tr("ELEMENTS");
+ }
+
+ return aTypes;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getCriteria
+// Purpose : Get criteria for specified type
+//=======================================================================
+const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
+{
+ if (theType == SMESH::NODE)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_FreeNodes ] = tr("FREE_NODES");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_EqualNodes ] = tr("EQUAL_NODE");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::EDGE)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
+ aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
+ aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ aCriteria[ SMESH::FT_EqualEdges ] = tr("EQUAL_EDGE");
+ aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::FACE)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
+ aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
+ aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
+ aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
+ aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
+ aCriteria[ SMESH::FT_Area ] = tr("AREA");
+ aCriteria[ SMESH::FT_MaxElementLength2D ] = tr("MAX_ELEMENT_LENGTH_2D");
+ aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
+ aCriteria[ SMESH::FT_MultiConnection2D ] = tr("MULTI2D_BORDERS");
+ aCriteria[ SMESH::FT_FreeFaces ] = tr("FREE_FACES");
+ aCriteria[ SMESH::FT_BareBorderFace ] = tr("BARE_BORDER_FACE");
+ aCriteria[ SMESH::FT_OverConstrainedFace] = tr("OVER_CONSTRAINED_FACE");
+ aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ aCriteria[ SMESH::FT_CoplanarFaces ] = tr("COPLANAR_FACES");
+ aCriteria[ SMESH::FT_EqualFaces ] = tr("EQUAL_FACE");
+ aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::VOLUME)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_AspectRatio3D ] = tr("ASPECT_RATIO_3D");
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
+ aCriteria[ SMESH::FT_BareBorderVolume ] = tr("BARE_BORDER_VOLUME");
+ aCriteria[ SMESH::FT_OverConstrainedVolume] = tr("OVER_CONSTRAINED_VOLUME");
+ aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
+ aCriteria[ SMESH::FT_MaxElementLength3D ] = tr("MAX_ELEMENT_LENGTH_3D");
+ aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ aCriteria[ SMESH::FT_EqualVolumes ] = tr("EQUAL_VOLUME");
+ aCriteria[ SMESH::FT_EntityType ] = tr("ENTITY_TYPE");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::ELEM0D)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::BALL)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_BallDiameter ] = tr("BALL_DIAMETER");
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else if (theType == SMESH::ELEM0D)
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
+ aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
+ aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+ return aCriteria;
+ }
+ else // SMESH::ALL
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ aCriteria[ SMESH::FT_BelongToMeshGroup ] = tr("BELONG_TO_MESH_GROUP");
+ aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ aCriteria[ SMESH::FT_ConnectedElements ] = tr("CONNECTED_ELEMS");
+ }
+
+ return aCriteria;
+ }
+}
+
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::getCompare
+// Purpose : Get operation of comparison
+//=======================================================================
+const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
+{
+ static QMap<int, QString> aMap;
+
+ if (aMap.isEmpty())
+ {
+ aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
+ aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
+ aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
+ }
+
+ return aMap;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::createTable
+// Purpose : Create table
+//=======================================================================
+SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
+ const int theType)
+{
+ // create table
+ Table* aTable= new Table(0, 6, theParent);
+
+ QHeaderView* aHeaders = aTable->horizontalHeader();
+
+ QFontMetrics aMetrics(aHeaders->font());
+
+ // append spaces to the header of criteria in order to
+ // provide visibility of criterion inside comboboxes
+ static int aMaxLenCr = 0;
+
+ if (aMaxLenCr == 0)
+ {
+ const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
+ QMap<int, QString>::const_iterator anIter;
+ for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
+ aMaxLenCr = qMax(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
+ }
+
+ static int aLenCr = qAbs( aMaxLenCr -
+ aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
+
+ QString aCrStr;
+ aCrStr.fill(' ', aLenCr);
+ QString aCoStr;
+ aCoStr.fill(' ', 10);
+
+ QStringList aHeaderLabels;
+ aHeaderLabels.append( tr("CRITERION") + aCrStr );
+ aHeaderLabels.append( tr("COMPARE") + aCoStr );
+ aHeaderLabels.append( tr("THRESHOLD_VALUE") );
+ aHeaderLabels.append( tr("UNARY") );
+ aHeaderLabels.append( tr("BINARY") + " " );
+ aHeaderLabels.append( tr("ID") );
+ aTable->setHorizontalHeaderLabels( aHeaderLabels );
+
+ // set geometry of the table
+ for (int i = 0; i <= 4; i++)
+ aTable->resizeColumnToContents(i);
+
+ // set the ID column invisible
+ aTable->hideColumn( 5 );
+
+ aTable->updateGeometry();
+ QSize aSize = aTable->sizeHint();
+ int aWidth = aSize.width();
+ aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
+ aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
+
+ connect(aTable, SIGNAL(cellChanged(int, int)),
+ this, SLOT(onCriterionChanged(int, int)));
+
+ connect(aTable, SIGNAL(currentCellChanged(int, int, int, int)),
+ this, SLOT(onCurrentChanged(int, int)));
+
+ return aTable;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::updateBtnState
+// Purpose : Update button state
+//=======================================================================
+void SMESHGUI_FilterTable::updateBtnState()
+{
+ myRemoveBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
+ myClearBtn->setEnabled(myTables[ GetType() ]->rowCount() > 0);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetEditable
+// Purpose : Set read only flag for tables. Show/hide buttons for work with rows
+//=======================================================================
+void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
+{
+ TableMap::iterator anIter;
+ for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
+ {
+ anIter.value()->setReadOnly(!isEditable);
+
+ // Set Flags for CheckItems directly IPAL 19974
+ Table* aTable = anIter.value();
+ for (int i = 0, n = aTable->rowCount(); i < n; i++)
+ for (int j = 0, m = aTable->columnCount(); j < m; j++)
+ {
+ QTableWidgetItem* anItem = aTable->item(i, j);
+ if ( dynamic_cast<SMESHGUI_FilterTable::CheckItem*>( anItem ) ) {
+ Qt::ItemFlags f = anItem->flags();
+ if (!isEditable) f = f & ~Qt::ItemIsUserCheckable;
+ else f = f | Qt::ItemIsUserCheckable;
+ anItem->setFlags( f );
+ }
+ }
+ //end of IPAL19974
+
+ if (isEditable)
+ {
+ myAddBtn->show();
+ myInsertBtn->show();
+ myRemoveBtn->show();
+ myClearBtn->show();
+ }
+ else
+ {
+ myAddBtn->hide();
+ myInsertBtn->hide();
+ myRemoveBtn->hide();
+ myClearBtn->hide();
+ }
+ }
+
+ QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
+ for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
+ anIter2.value()->SetEditable(isEditable);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetEnabled
+// Purpose : Enable/Disable table. Switching type of elements already enabled
+//=======================================================================
+void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
+{
+ myAddBtn->setEnabled(isEnabled);
+ myInsertBtn->setEnabled(isEnabled);
+ myRemoveBtn->setEnabled(isEnabled);
+ myClearBtn->setEnabled(isEnabled);
+
+ if (isEnabled)
+ updateBtnState();
+
+ QMap<QTableWidgetItem*, AdditionalWidget*>::iterator anIter2;
+ for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
+ anIter2.value()->setEnabled(isEnabled);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::IsEditable
+// Purpose : Verify whether table is editable
+//=======================================================================
+bool SMESHGUI_FilterTable::IsEditable() const
+{
+ return !myTables[ GetType() ]->isReadOnly();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetLibsEnabled
+// Purpose : Show/hide buttons for work with libraries
+//=======================================================================
+void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
+{
+ if (isEnabled)
+ {
+ myCopyFromBtn->show();
+ myAddToBtn->show();
+ }
+ else
+ {
+ myCopyFromBtn->hide();
+ myAddToBtn->hide();
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onCopyFromBtn
+// Purpose : SLOT. Called the "Copy from ..." button clicked
+// Display filter library dialog
+//=======================================================================
+void SMESHGUI_FilterTable::onCopyFromBtn()
+{
+ if (myLibDlg == 0)
+ myLibDlg = new SMESHGUI_FilterLibraryDlg(
+ mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
+ else
+ myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
+
+ if (myLibDlg->exec() == QDialog::Accepted)
+ {
+ Copy(myLibDlg->GetTable());
+ Update();
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::onAddToBtn
+// Purpose : SLOT. Called the "Add to ..." button clicked
+// Display filter library dialog
+//=======================================================================
+void SMESHGUI_FilterTable::onAddToBtn()
+{
+ if (!IsValid(true))
+ return;
+ if (myLibDlg == 0)
+ myLibDlg = new SMESHGUI_FilterLibraryDlg(
+ mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
+ else
+ myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
+
+ myLibDlg->SetTable(this);