+ 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);
+
+ if (aCriterion == SMESH::FT_RangeOfIds ||
+ aCriterion == SMESH::FT_BelongToGeom ||
+ aCriterion == SMESH::FT_BelongToPlane ||
+ aCriterion == SMESH::FT_BelongToCylinder ||
+ aCriterion == SMESH::FT_BelongToGenSurface ||
+ aCriterion == SMESH::FT_LyingOnGeom) {
+ if (aTable->text(i, 2).isEmpty()) {
+ if (theMess)
+ SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
+ tr("ERROR"));
+ return false;
+ }
+ } 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)) {
+ if (theMess)
+ SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
+ tr("ERROR"));
+ return false;
+ }
+ else if (aType == SMESH::EDGE &&
+ GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
+ aThreshold == 1)
+ {
+ if (theMess)
+ SUIT_MessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
+ tr("MULTIEDGES_ERROR"));
+ 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_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_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_BadOrientedVolume)
+ 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)
+ {
+ 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));
+ bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->value() == SMESH::FT_EqualTo &&
+ GetCriterionType(aRow) != SMESH::FT_BelongToGeom &&
+ GetCriterionType(aRow) != SMESH::FT_LyingOnGeom &&
+ GetCriterionType(aRow) != SMESH::FT_RangeOfIds &&
+ GetCriterionType(aRow) != SMESH::FT_FreeEdges &&
+ GetCriterionType(aRow) != 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 : 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);
+
+ if (aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
+ aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
+ aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume)
+ {
+ bool isSignalsBlocked = aTable->signalsBlocked();
+ aTable->blockSignals( true );
+
+ if (aCompareItem->count() > 0)
+ aCompareItem->clear();
+ aTable->setEditable(false, 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, 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, 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");
+ }
+
+ 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");
+ }
+ 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");
+ }
+ 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");
+ }
+ 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");
+ }
+ return aCriteria;
+ }
+ else
+ {
+ static QMap<int, QString> aCriteria;
+ 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);
+
+ if (isEditable)