+ 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_BelongToGeom ||
+ aCriterion == SMESH::FT_BelongToPlane ||
+ aCriterion == SMESH::FT_BelongToCylinder ||
+ aCriterion == SMESH::FT_BelongToGenSurface ||
+ aCriterion == SMESH::FT_ElemGeomType ||
+ aCriterion == SMESH::FT_LyingOnGeom) {
+ if (aTable->text(i, 2).isEmpty())
+ errMsg = tr( "ERROR" );
+ }
+ else {
+ 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" );
+ else if (aType == SMESH::EDGE &&
+ GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
+ aThreshold == 1)
+ errMsg = tr( "MULTIEDGES_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 )
+ {
+ 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 )
+ theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
+ else if ( aCriterionType != SMESH::FT_RangeOfIds &&
+ 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);
+ ((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 )
+ {
+ ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
+ typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
+ }
+ else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
+ 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_LinearOrQuadratic)
+ 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)
+ {
+ QTableWidgetItem* anItem = aTable->item(theRow, 0);
+ if (!myAddWidgets.contains(anItem))
+ {
+ myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
+ 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 toEnable = ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
+ aCriterion != SMESH::FT_RangeOfIds &&
+ aCriterion != SMESH::FT_FreeEdges &&
+ aCriterion != SMESH::FT_FreeFaces &&
+ aCriterion != SMESH::FT_BadOrientedVolume;
+
+ if (!myAddWidgets.contains(anItem))
+ {
+ myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
+ myWgStack->addWidget(myAddWidgets[ anItem ]);
+ }
+
+ myWgStack->setCurrentWidget(myAddWidgets[ anItem ]);
+ myWgStack->setEnabled(toEnable);
+}
+
+//=======================================================================
+// 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_POLYHEDRA );
+ }
+ 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);
+
+ int aCriterionType = GetCriterionType(row);
+ QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(row, 2));
+ bool isComboItem = aTable->item(row, 2)->type() == ComboItem::Type();
+
+ if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
+ (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) )
+ {
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals( true );
+ aTable->removeCellWidget( row, 2 );
+ aTable->setItem( row, 2, new QTableWidgetItem() );
+ aTable->blockSignals( isSignalsBlocked );
+ }
+ if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
+ (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) )
+ {
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals( true );
+ if ( aCriterionType == SMESH::FT_GroupColor )
+ aTable->setCellWidget( row, 2, new QtxColorButton( aTable ) );
+ else {
+ QList<int> typeIds = geomTypes( aType );
+ QMap<int, QString> typeNames;
+ QList<int>::const_iterator anIter = typeIds.begin();
+ for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
+ {
+ QString typeKey = QString( "GEOM_TYPE_%1" ).arg( *anIter );
+ typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
+ }
+ ComboItem* typeBox = new ComboItem( typeNames );
+ aTable->setItem( row, 2, typeBox );
+ }
+ aTable->blockSignals( isSignalsBlocked );
+ }
+
+ if (aType == SMESH::NODE && aCriterionType == SMESH::FT_FreeNodes ||
+ aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
+ aType == SMESH::FACE && (aCriterionType == SMESH::FT_FreeEdges ||
+ aCriterionType == SMESH::FT_FreeFaces) ||
+ aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume ||
+ aCriterionType == SMESH::FT_LinearOrQuadratic ||
+ aCriterionType == SMESH::FT_GroupColor ||
+ aCriterionType == SMESH::FT_ElemGeomType)
+ {
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals( true );
+
+ if (aCompareItem->count() > 0)
+ aCompareItem->clear();
+ aTable->setEditable(false, row, 1);
+ aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
+ aCriterionType == SMESH::FT_ElemGeomType, row, 2);
+ aTable->blockSignals( isSignalsBlocked );
+ }
+ else if (aCriterionType == SMESH::FT_RangeOfIds ||
+ aCriterionType == SMESH::FT_BelongToGeom ||
+ aCriterionType == SMESH::FT_BelongToPlane ||
+ aCriterionType == SMESH::FT_BelongToCylinder ||
+ aCriterionType == SMESH::FT_BelongToGenSurface ||
+ aCriterionType == SMESH::FT_LyingOnGeom)
+ {
+ QMap<int, QString> aMap;
+ aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
+ aCompareItem->setItems(aMap);
+ if (!aTable->isEditable(row, 2))
+ aTable->setEditable(true, row, 1);
+ if (!aTable->isEditable(row, 2))
+ aTable->setEditable(true, row, 2);
+ }
+ else if (aCriterionType == SMESH::FT_GroupColor ||
+ aCriterionType == SMESH::FT_ElemGeomType)
+ {
+ if (!aTable->isEditable(row, 2))
+ aTable->setEditable(true, row, 2);
+ }
+ else
+ {
+ if (aCompareItem->count() != 3)
+ {
+ aCompareItem->setItems(getCompare());
+ }
+
+ QString aText = aTable->text(row, 2);
+ bool isOk = false;
+ aText.toDouble(&isOk);
+ aTable->item( row, 2 )->setText(isOk ? aText : QString(""));
+ if (!aTable->isEditable(row, 1))
+ aTable->setEditable(true, row, 1);
+ if (!aTable->isEditable(row, 2))
+ aTable->setEditable(true, row, 2);
+ }
+
+ 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)
+{
+ onCriterionChanged(row, col, -1);
+}
+
+//=======================================================================
+// 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::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_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");
+ }
+ 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_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");
+ }
+ 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_FreeEdges ] = tr("FREE_EDGES");
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ 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_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ }
+ 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_BelongToGeom ] = tr("BELONG_TO_GEOM");
+ aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
+ aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
+ aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
+ aCriteria[ SMESH::FT_LinearOrQuadratic ] = tr("LINEAR");
+ aCriteria[ SMESH::FT_GroupColor ] = tr("GROUP_COLOR");
+ aCriteria[ SMESH::FT_ElemGeomType ] = tr("GEOM_TYPE");
+ }
+ return aCriteria;
+ }
+ else // SMESH::ALL
+ {
+ static QMap<int, QString> aCriteria;
+ if (aCriteria.isEmpty())
+ {
+ aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
+ 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");
+ }
+
+ 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);
+
+ myLibDlg->exec();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::Copy
+// Purpose : Initialise table with values of other table
+//=======================================================================
+void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
+{
+ Clear();
+
+ for (int i = 0, n = theTable->NumRows(); i < n; i++)
+ {
+ SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
+ theTable->GetCriterion(i, aCriterion);
+ AddCriterion(aCriterion);
+ }
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::CurrentCell
+// Purpose : Returns current cell
+//=======================================================================
+bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
+{
+ theRow = myTables[ GetType() ]->currentRow();
+ theCol = myTables[ GetType() ]->currentColumn();
+ return theRow >= 0 && theCol >= 0;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetText
+// Purpose : Set text and internal value in cell of threshold value
+//=======================================================================
+void SMESHGUI_FilterTable::SetThreshold (const int theRow,
+ const QString& theText,
+ const int theEntityType)
+{
+ Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+ aTable->item( theRow, 2 )->setText(theText);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetText
+// Purpose : Get text and internal value from cell of threshold value
+//=======================================================================
+bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
+ QString& theText,
+ const int theEntityType)
+{
+ Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+ QTableWidgetItem* anItem = aTable->item(theRow, 2);
+ if (anItem != 0)
+ {
+ theText = anItem->text();
+ return true;
+ }
+ else
+ return false;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::SetID
+// Purpose : Set text and internal value in cell of ID value
+//=======================================================================
+void SMESHGUI_FilterTable::SetID( const int theRow,
+ const QString& theText,
+ const int theEntityType )
+{
+ Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+ aTable->item( theRow, 5 )->setText( theText );
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterTable::GetID
+// Purpose : Get text and internal value from cell of ID value
+//=======================================================================
+bool SMESHGUI_FilterTable::GetID( const int theRow,
+ QString& theText,
+ const int theEntityType )
+{
+ Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+ QTableWidgetItem* anItem = aTable->item( theRow, 5 );
+ if ( anItem != 0 )
+ {
+ theText = anItem->text();
+ return true;
+ }
+ else
+ return false;
+}
+
+/*
+ Class : SMESHGUI_FilterDlg
+ Description : Dialog to specify filters for VTK viewer
+*/
+
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
+ const QList<int>& theTypes )
+: QDialog( SMESH::GetDesktop( theModule ) ),
+ mySMESHGUI( theModule ),
+ mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+ myInitSourceWgOnApply( true )
+{
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ mySelector = aViewWindow->GetSelector();
+
+ construct(theTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
+// Purpose : Constructor
+//=======================================================================
+SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
+ const int theType )
+: QDialog( SMESH::GetDesktop( theModule ) ),
+ mySMESHGUI( theModule ),
+ mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
+ myInitSourceWgOnApply( true )
+{
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ mySelector = aViewWindow->GetSelector();
+ QList<int> aTypes;
+ aTypes.append(theType);
+ construct(aTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::construct
+// Purpose : Construct dialog (called by constructor)
+//=======================================================================
+void SMESHGUI_FilterDlg::construct (const QList<int>& theTypes)
+{
+ myTypes = theTypes;
+
+ setModal(false);
+ //setAttribute(Qt::WA_DeleteOnClose, true); // VSR ??? is it required?
+ setWindowTitle(tr("CAPTION"));
+
+ QVBoxLayout* aDlgLay = new QVBoxLayout (this);
+ aDlgLay->setMargin(MARGIN);
+ aDlgLay->setSpacing(SPACING);
+
+ myMainFrame = createMainFrame (this);
+ QWidget* aBtnFrame = createButtonFrame(this);
+
+ aDlgLay->addWidget(myMainFrame);
+ aDlgLay->addWidget(aBtnFrame);
+
+ aDlgLay->setStretchFactor(myMainFrame, 1);
+
+ myHelpFileName = "selection_filter_library_page.html";
+
+ Init(myTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::createMainFrame
+// Purpose : Create frame containing dialog's input fields
+//=======================================================================
+QWidget* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
+{
+ QWidget* aMainFrame = new QWidget(theParent);
+ QVBoxLayout* aMainLay = new QVBoxLayout(aMainFrame);
+ aMainLay->setMargin(0);
+ aMainLay->setSpacing(SPACING);
+
+ // filter frame
+
+ myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
+ myTable->SetLibsEnabled(true);
+
+ QGroupBox* aGrp = myTable->GetTableGrp();
+ QGridLayout* aLay = qobject_cast<QGridLayout*>( aGrp->layout() );
+ int rows = aLay->rowCount();
+ int cols = aLay->columnCount();
+
+ QFrame* aLine = new QFrame(aGrp);
+ aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
+ aLay->addWidget(aLine, rows++, 0, 1, cols);
+
+ mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), aGrp);
+ mySetInViewer->setChecked(true);
+ aLay->addWidget(mySetInViewer, rows++, 0, 1, cols);
+
+ // other controls
+ QWidget* aSourceGrp = createSourceGroup(aMainFrame);
+
+ connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
+ SLOT(onCriterionChanged(const int, const int)));
+
+ connect(myTable, SIGNAL(CurrentChanged(int, int)),
+ SLOT(onCurrentChanged(int, int)));
+
+ aMainLay->addWidget(myTable);
+ aMainLay->addWidget(aSourceGrp);
+
+ return aMainFrame;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::createSourceFrame
+// Purpose : Create frame containing source radio button
+//=======================================================================
+QWidget* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
+{
+ QGroupBox* aBox = new QGroupBox(tr("SOURCE"), theParent);
+ QHBoxLayout* aLay = new QHBoxLayout(aBox);
+ aLay->setMargin(MARGIN);
+ aLay->setSpacing(SPACING);
+
+ mySourceGrp = new QButtonGroup(theParent);
+
+ QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aBox);
+ QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aBox);
+ QRadioButton* aDlgBtn = new QRadioButton(tr("CURRENT_DIALOG"),aBox);
+
+ aLay->addWidget(aMeshBtn);
+ aLay->addWidget(aSelBtn);
+ aLay->addWidget(aDlgBtn);
+
+ mySourceGrp->addButton(aMeshBtn, Mesh);
+ mySourceGrp->addButton(aSelBtn, Selection);
+ mySourceGrp->addButton(aDlgBtn, Dialog);
+
+ aSelBtn->setChecked(true);
+
+ return aBox;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::updateMainButtons
+// Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
+//=======================================================================
+void SMESHGUI_FilterDlg::updateMainButtons()
+{
+ if (myTypes.count() == 1)
+ {
+ myButtons[ BTN_Cancel ]->show();
+ myButtons[ BTN_Apply ]->hide();
+ myButtons[ BTN_Close ]->hide();
+ }
+ else
+ {
+ myButtons[ BTN_Cancel ]->hide();
+ myButtons[ BTN_Apply ]->show();
+ myButtons[ BTN_Close ]->show();
+ }
+
+// updateGeometry();
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::createButtonFrame
+// Purpose : Create frame containing buttons
+//=======================================================================
+QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
+{
+ QGroupBox* aGrp = new QGroupBox(theParent);
+ QHBoxLayout* aLay = new QHBoxLayout(aGrp);
+ aLay->setMargin(MARGIN);
+ aLay->setSpacing(SPACING);
+
+ myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
+ myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
+ myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
+ myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
+ myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
+
+ aLay->addWidget(myButtons[ BTN_OK ]);
+ aLay->addSpacing(10);
+ aLay->addWidget(myButtons[ BTN_Apply ]);
+ aLay->addSpacing(10);
+ aLay->addStretch();
+ aLay->addWidget(myButtons[ BTN_Cancel ]);
+ aLay->addWidget(myButtons[ BTN_Close ]);
+ aLay->addWidget(myButtons[ BTN_Help ]);
+
+ connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
+ connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
+ connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
+ connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
+ connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
+
+ updateMainButtons();
+
+ return aGrp;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
+// Purpose : Destructor
+//=======================================================================
+SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
+{
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::Init
+// Purpose : Init dialog fields, connect signals and slots, show dialog
+//=======================================================================
+void SMESHGUI_FilterDlg::Init (const int type)
+{
+ QList<int> aTypes;
+ aTypes.append(type);
+ Init(aTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::Init
+// Purpose : Init dialog fields, connect signals and slots, show dialog
+//=======================================================================
+void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes)
+{
+ mySourceWg = 0;
+ myTypes = theTypes;
+ myMesh = SMESH::SMESH_Mesh::_nil();
+ myIObjects.Clear();
+ myIsSelectionChanged = false;
+
+ myTable->Init(theTypes);
+
+ // set caption
+ if (theTypes.count() == 1)
+ {
+ int aType = theTypes.first();
+ if (aType == SMESH::NODE ) setWindowTitle(tr("NODES_TLT"));
+ else if (aType == SMESH::EDGE ) setWindowTitle(tr("EDGES_TLT"));
+ else if (aType == SMESH::FACE ) setWindowTitle(tr("FACES_TLT"));
+ else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
+ else if (aType == SMESH::ALL) setWindowTitle(tr("TLT"));
+ }
+ else
+ setWindowTitle(tr("TLT"));
+
+ qApp->processEvents();
+ updateGeometry();
+ adjustSize();
+ setEnabled(true);
+
+ mySMESHGUI->SetActiveDialogBox((QDialog*)this);
+
+ connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
+ connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
+
+ updateMainButtons();
+ updateSelection();
+
+ // Initialise filter table with values of previous filter
+ QList<int>::const_iterator anIter;
+ for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)