+ 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, 5, theParent);
+
+ QHeader* 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 = Max(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
+ }
+
+ static int aLenCr = abs( aMaxLenCr -
+ aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
+
+ QString aCrStr;
+ aCrStr.fill(' ', aLenCr);
+ QString aCoStr;
+ aCoStr.fill(' ', 10);
+
+ aHeaders->setLabel(0, tr("CRITERION") + aCrStr);
+ aHeaders->setLabel(1, tr("COMPARE") + aCoStr);
+ aHeaders->setLabel(2, tr("THRESHOLD_VALUE"));
+ aHeaders->setLabel(3, tr("UNARY"));
+ aHeaders->setLabel(4, tr("BINARY") + " ");
+
+ // set geometry of the table
+ for (int i = 0; i <= 4; i++)
+ aTable->adjustColumn(i);
+
+ 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(valueChanged(int, int)),
+ this, SLOT(onCriterionChanged(int, int)));
+
+ connect(aTable, SIGNAL(currentChanged(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() ]->numRows() > 0);
+ myClearBtn->setEnabled(myTables[ GetType() ]->numRows() > 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.data()->setReadOnly(!isEditable);
+
+ if (isEditable)
+ {
+ myAddBtn->show();
+ myInsertBtn->show();
+ myRemoveBtn->show();
+ myClearBtn->show();
+ }
+ else
+ {
+ myAddBtn->hide();
+ myInsertBtn->hide();
+ myRemoveBtn->hide();
+ myClearBtn->hide();
+ }
+ }
+
+ QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
+ for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
+ anIter2.data()->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<QTableItem*, AdditionalWidget*>::iterator anIter2;
+ for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
+ anIter2.data()->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->setText(theRow, 2, 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 ];
+ QTableItem* anItem = aTable->item(theRow, 2);
+ 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 QValueList<int>& theTypes,
+ const char* theName)
+: QDialog( SMESH::GetDesktop( theModule ), theName, false,
+ WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+ mySMESHGUI( theModule ),
+ mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+{
+ 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,
+ const char* theName)
+: QDialog( SMESH::GetDesktop( theModule ), theName, false,
+ WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
+ mySMESHGUI( theModule ),
+ mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
+{
+ if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+ mySelector = aViewWindow->GetSelector();
+ QValueList<int> aTypes;
+ aTypes.append(theType);
+ construct(aTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::construct
+// Purpose : Construct dialog (called by constructor)
+//=======================================================================
+void SMESHGUI_FilterDlg::construct (const QValueList<int>& theTypes)
+{
+ myTypes = theTypes;
+
+ setCaption(tr("CAPTION"));
+
+ QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
+
+ myMainFrame = createMainFrame (this);
+ QFrame* aBtnFrame = createButtonFrame(this);
+
+ aDlgLay->addWidget(myMainFrame);
+ aDlgLay->addWidget(aBtnFrame);
+
+ aDlgLay->setStretchFactor(myMainFrame, 1);
+
+ Init(myTypes);
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::createMainFrame
+// Purpose : Create frame containing dialog's input fields
+//=======================================================================
+QFrame* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
+{
+ QGroupBox* aMainFrame = new QGroupBox(1, Qt::Horizontal, theParent);
+ aMainFrame->setFrameStyle(QFrame::NoFrame);
+ aMainFrame->setInsideMargin(0);
+
+ // filter frame
+
+ myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
+ myTable->SetLibsEnabled(true);
+
+ QFrame* aLine = new QFrame(myTable->GetTableGrp());
+ aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
+
+ mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), myTable->GetTableGrp());
+ mySetInViewer->setChecked(true);
+
+ // other controls
+ mySourceGrp = 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)));
+
+ return aMainFrame;
+}
+
+//=======================================================================
+// name : SMESHGUI_FilterDlg::createSourceFrame
+// Purpose : Create frame containing source radio button
+//=======================================================================
+QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
+{
+ QButtonGroup* aGrp = new QButtonGroup(1, Qt::Vertical, tr("SOURCE"), theParent);
+
+ QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aGrp);
+ QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aGrp);
+ QRadioButton* aGrpBtn = new QRadioButton(tr("CURRENT_GROUP"), aGrp);
+
+ aGrp->insert(aMeshBtn, Mesh);
+ aGrp->insert(aSelBtn, Selection);
+ aGrp->insert(aGrpBtn, Dialog);
+
+ aGrp->setButton(Selection);
+
+ return aGrp;
+}
+
+//=======================================================================
+// 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
+//=======================================================================
+QFrame* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
+{
+ QGroupBox* aGrp = new QGroupBox(1, Qt::Vertical, theParent);
+
+ myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_OK" ), aGrp);
+ myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
+
+ QLabel* aLbl = new QLabel(aGrp);
+ aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
+
+ myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
+ myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);