+ 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 containing
+ - 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 ),
+ mySMESHGUI( theModule ),
+ myIsLocked( false )
+{
+ 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 ),
+ mySMESHGUI( theModule ),
+ myIsLocked( false )
+{
+ 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 =*/ 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::getStudy()->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 additional 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_Deflection2D ||
+ 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_Deflection2D:
+ 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;
+