1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI_FilterDlg.cxx
25 // Author : Sergey LITONIN
28 #include "SMESHGUI_FilterDlg.h"
31 #include "SMESHGUI_Utils.h"
32 #include "SMESHGUI_VTKUtils.h"
33 #include "SMESHGUI_Filter.h"
34 #include "SMESHGUI_FilterUtils.h"
35 #include "SMESHGUI_FilterLibraryDlg.h"
37 #include "SMESH_Actor.h"
38 #include "SMESH_NumberFilter.hxx"
39 #include "SMESH_TypeFilter.hxx"
42 #include "GEOM_FaceFilter.h"
43 #include "GEOM_TypeFilter.h"
45 #include "SUIT_Desktop.h"
46 #include "SUIT_ResourceMgr.h"
48 #include "SalomeApp_Application.h"
49 #include "SalomeApp_Tools.h"
50 #include "SalomeApp_Study.h"
52 #include "SALOME_ListIO.hxx"
53 #include "SALOME_ListIteratorOfListIO.hxx"
54 #include "SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx"
55 #include "SALOMEDSClient_Study.hxx"
57 #include "SVTK_ViewWindow.h"
58 #include "SVTK_Selector.h"
61 #include <StdSelect_TypeOfFace.hxx>
62 #include <BRep_Tool.hxx>
64 #include <TopoDS_Face.hxx>
65 #include <TopoDS_Shape.hxx>
66 #include <Geom_Plane.hxx>
67 #include <Geom_CylindricalSurface.hxx>
68 #include <Precision.hxx>
69 #include <TColStd_MapOfInteger.hxx>
70 #include <TColStd_IndexedMapOfInteger.hxx>
71 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
76 #include <qlineedit.h>
77 #include <qpushbutton.h>
78 #include <qgroupbox.h>
80 #include <qstringlist.h>
82 #include <qwidgetstack.h>
83 #include <qapplication.h>
84 #include <qcombobox.h>
85 #include <qfontmetrics.h>
86 #include <qmessagebox.h>
88 #include <qbuttongroup.h>
89 #include <qradiobutton.h>
92 #include <qcheckbox.h>
93 #include <qobjectlist.h>
94 #include <qvalidator.h>
97 #include "SALOMEconfig.h"
98 #include CORBA_SERVER_HEADER(SMESH_Group)
103 using namespace SMESH;
105 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
108 QMap<int, QString>::const_iterator anIter;
109 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
110 aRes = Max(aRes, theMetrics.width(anIter.data()));
114 static int getFilterId (SMESH::ElementType theType)
118 case SMESH::NODE : return SMESHGUI_NodeFilter;
119 case SMESH::EDGE : return SMESHGUI_EdgeFilter;
120 case SMESH::FACE : return SMESHGUI_FaceFilter;
121 case SMESH::VOLUME : return SMESHGUI_VolumeFilter;
122 case SMESH::ALL : return SMESHGUI_AllElementsFilter;
123 default : return SMESHGUI_UnknownFilter;
128 Class : SMESHGUI_FilterTable::AdditionalWidget
129 Description : Class for storing additional parameters of criterion
132 class SMESHGUI_FilterTable::AdditionalWidget : public QFrame
139 AdditionalWidget(QWidget* theParent);
140 virtual ~AdditionalWidget();
142 virtual void GetParameters(QValueList<int>&) const;
143 virtual bool IsValid(const bool theMsg = true) const;
144 virtual double GetDouble(const int theId) const;
145 virtual int GetInteger(const int theId) const;
146 virtual QString GetString(const int theId) const;
147 virtual void SetDouble(const int theId, const double theVal);
148 virtual void SetInteger(const int theId, const int theVal);
149 virtual void SetString(const int theId, const QString& theVal);
150 void SetEditable(const int theId, const bool isEditable);
151 void SetEditable(const bool isEditable);
154 QMap< int, QLineEdit* > myLineEdits;
157 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
160 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
161 myLineEdits[ Tolerance ] = new QLineEdit(this);
162 QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]);
163 aValidator->setBottom(0);
164 myLineEdits[ Tolerance ]->setValidator(aValidator);
166 QHBoxLayout* aLay = new QHBoxLayout(this, 0, SPACING);
167 aLay->addWidget(aLabel);
168 aLay->addWidget(myLineEdits[ Tolerance ]);
170 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
171 aLay->addItem(aSpacer);
173 QString aText = QString("%1").arg(Precision::Confusion());
174 myLineEdits[ Tolerance ]->setText(aText);
177 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
181 void SMESHGUI_FilterTable::AdditionalWidget::GetParameters (QValueList<int>& theList) const
184 theList.append(Tolerance);
187 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
192 QValueList<int> aParams;
193 GetParameters(aParams);
194 QValueList<int>::const_iterator anIter;
195 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
196 const QLineEdit* aWg = myLineEdits[ *anIter ];
198 QString aText = aWg->text();
199 if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) {
201 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
202 tr("SMESHGUI_INVALID_PARAMETERS"), QMessageBox::Ok);
210 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
212 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toDouble() : 0;
215 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
217 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toInt() : 0;
220 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
222 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text() : QString("");
225 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
227 if (myLineEdits.contains(theId))
228 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
231 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
233 if (myLineEdits.contains(theId))
234 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
237 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
239 if (myLineEdits.contains(theId))
240 myLineEdits[ theId ]->setText(theVal);
243 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
245 if (myLineEdits.contains(theId))
246 myLineEdits[ theId ]->setEdited(isEditable);
249 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
251 QValueList<int> aParams;
252 GetParameters(aParams);
253 QValueList<int>::const_iterator anIter;
254 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
255 myLineEdits[ *anIter ]->setEdited(isEditable);
259 Class : SMESHGUI_FilterTable::ComboItem
260 Description : Combo table item. Identificator corresponding to string may be assigned
263 class SMESHGUI_FilterTable::ComboItem : public QComboTableItem
266 ComboItem(QTable*, const QMap<int, QString>&);
267 virtual ~ComboItem();
269 virtual void setStringList (const QStringList & l);
270 void setStringList(const QMap<int, QString>& theIds);
272 int GetValue() const;
273 void SetValue(const int);
277 QMap<int, int> myNumToId;
278 QMap<int, int> myIdToNum;
281 SMESHGUI_FilterTable::ComboItem::ComboItem (QTable* theParent,
282 const QMap<int, QString>& theIds)
283 : QComboTableItem(theParent, QStringList())
285 setStringList(theIds);
288 void SMESHGUI_FilterTable::ComboItem::setStringList (const QStringList & l)
290 QComboTableItem::setStringList(l);
293 void SMESHGUI_FilterTable::ComboItem::setStringList (const QMap<int, QString>& theIds)
297 QMap<int, QString>::const_iterator anIter;
298 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
299 myNumToId[ i ] = anIter.key();
300 myIdToNum[ anIter.key() ] = i;
301 aList.append(anIter.data());
305 setStringList(aList);
308 SMESHGUI_FilterTable::ComboItem::~ComboItem()
312 int SMESHGUI_FilterTable::ComboItem::GetValue() const
314 return myNumToId[ currentItem() ];
317 void SMESHGUI_FilterTable::ComboItem::SetValue (const int theVal)
319 setCurrentItem(myIdToNum[ theVal ]);
324 Class : SMESHGUI_FilterTable::Table
325 Description : Table used by this widget
328 class SMESHGUI_FilterTable::Table : public QTable
331 Table(QWidget* parent);
332 Table(int numRows, int numCols, QWidget* parent = 0);
335 void SetEditable(const bool state, const int row, const int col);
336 bool IsEditable(const int row, const int col) const;
338 virtual void insertRows(int row, int count = 1);
339 virtual QString text(int row, int col) const;
342 //=======================================================================
343 // name : SMESHGUI_FilterTable::Table::Table
344 // Purpose : Constructor
345 //=======================================================================
346 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
347 : QTable(parent, "SMESHGUI_FilterTable::Table")
351 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
352 : QTable(numRows, numCols, parent, "SMESHGUI_FilterTable::Table")
356 SMESHGUI_FilterTable::Table::~Table()
360 //=======================================================================
361 // name : SMESHGUI_FilterTable::Table::SetEditable
362 // Purpose : Set editable of specified cell
363 //=======================================================================
364 void SMESHGUI_FilterTable::Table::SetEditable (const bool isEditable,
365 const int row, const int col)
367 QTableItem* anItem = item(row, col);
372 setItem(row, col, new QTableItem(this, QTableItem::Never, ""));
374 setItem(row, col, new QTableItem(this, QTableItem::OnTyping, ""));
377 //=======================================================================
378 // name : SMESHGUI_FilterTable::Table::IsEditable
379 // Purpose : Verify wheter cell is editable
380 //=======================================================================
381 bool SMESHGUI_FilterTable::Table::IsEditable (const int row, const int col) const
383 QTableItem* anItem = item(row, col);
384 return anItem == 0 || anItem->editType() != QTableItem::Never;
387 //=======================================================================
388 // name : SMESHGUI_FilterTable::Table::insertRows
389 // Purpose : Insert rows (virtual redefined)
390 //=======================================================================
391 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
393 int anEditRow = currEditRow();
394 int anEditCol = currEditCol();
396 if (anEditRow >= 0 && anEditCol >= 0)
397 endEdit(anEditRow, anEditCol, true, false);
399 QTable::insertRows( row, count );
402 //=======================================================================
403 // name : SMESHGUI_FilterTable::Table::text
404 // Purpose : Get text from cell (virtual redefined)
405 //=======================================================================
406 QString SMESHGUI_FilterTable::Table::text (int row, int col) const
408 int anEditRow = currEditRow();
409 int anEditCol = currEditCol();
411 if (anEditRow >= 0 && anEditCol >= 0 && anEditRow == row && anEditCol == col)
412 ((Table*)this)->endEdit(row, col, true, false);
414 return QTable::text(row, col);
419 Class : SMESHGUI_FilterTable
420 Description : Frame containig
421 - Button group for switching entity type
422 - Table for displaying filter criterions
423 - Buttons for editing table and filter libraries
426 //=======================================================================
427 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
428 // Purpose : Constructor
429 //=======================================================================
430 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
435 mySMESHGUI( theModule )
441 //=======================================================================
442 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
443 // Purpose : Constructor
444 //=======================================================================
445 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
447 const QValueList<int>& types)
450 mySMESHGUI( theModule )
456 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
460 //=======================================================================
461 // name : SMESHGUI_FilterTable::Init
462 // Purpose : Create table corresponding to the specified type
463 //=======================================================================
464 void SMESHGUI_FilterTable::Init (const int type)
466 QValueList<int> aTypes;
471 //=======================================================================
472 // name : SMESHGUI_FilterTable::Init
473 // Purpose : Create table corresponding to the specified type
474 //=======================================================================
475 void SMESHGUI_FilterTable::Init (const QValueList<int>& theTypes)
477 if (theTypes.isEmpty())
480 // Create buttons if necessary
482 if (myTables.isEmpty())
484 int aType = theTypes.first();
486 // create main layout
487 QVBoxLayout* aMainLay = new QVBoxLayout(this);
488 QGroupBox* aMainGrp = new QGroupBox(1, Qt::Horizontal, this);
489 aMainGrp->setFrameStyle(QFrame::NoFrame);
490 aMainGrp->setInsideMargin(0);
491 aMainLay->addWidget(aMainGrp);
493 // create switch of entity types
494 myEntityTypeGrp = new QButtonGroup(1, Qt::Vertical, tr("ENTITY_TYPE"), aMainGrp);
495 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
496 QMap<int, QString>::const_iterator anIter;
497 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
499 QRadioButton* aBtn = new QRadioButton(anIter.data(), myEntityTypeGrp);
500 myEntityTypeGrp->insert(aBtn, anIter.key());
503 myTableGrp = new QGroupBox(1, Qt::Horizontal, tr("FILTER"), aMainGrp );
504 QFrame* aTableFrame = new QFrame(myTableGrp);
507 mySwitchTableGrp = new QGroupBox(1, Qt::Horizontal, aTableFrame);
508 mySwitchTableGrp->setFrameStyle(QFrame::NoFrame);
509 mySwitchTableGrp->setInsideMargin(0);
511 myTables[ aType ] = createTable(mySwitchTableGrp, aType);
514 myAddBtn = new QPushButton(tr("ADD"), aTableFrame);
515 myRemoveBtn = new QPushButton(tr("REMOVE"), aTableFrame);
516 myClearBtn = new QPushButton(tr("CLEAR"), aTableFrame);
517 myInsertBtn = new QPushButton(tr("INSERT"), aTableFrame);
518 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), aTableFrame);
519 myAddToBtn = new QPushButton(tr("ADD_TO"), aTableFrame);
521 myAddBtn->setAutoDefault(false);
522 myRemoveBtn->setAutoDefault(false);
523 myClearBtn->setAutoDefault(false);
524 myInsertBtn->setAutoDefault(false);
525 myCopyFromBtn->setAutoDefault(false);
526 myAddToBtn->setAutoDefault(false);
528 myCopyFromBtn->hide();
532 QGridLayout* aLay = new QGridLayout(aTableFrame, 8, 2, 0, SPACING);
534 aLay->addMultiCellWidget(mySwitchTableGrp, 0, 6, 0, 0);
535 aLay->addWidget(myAddBtn, 0, 1);
536 aLay->addWidget(myInsertBtn, 1, 1);
537 aLay->addWidget(myRemoveBtn, 2, 1);
538 aLay->addWidget(myClearBtn, 3, 1);
539 aLay->addWidget(myCopyFromBtn, 5, 1);
540 aLay->addWidget(myAddToBtn, 6, 1);
541 aLay->addMultiCellWidget(createAdditionalFrame(aTableFrame), 7, 7, 0, 1 );
543 aLay->setColStretch(0, 1);
544 aLay->setColStretch(1, 0);
546 QSpacerItem* aVSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
547 aLay->addItem(aVSpacer, 4, 1);
550 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
551 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
552 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
553 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
555 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
556 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
558 connect(myEntityTypeGrp, SIGNAL(clicked(int)), this, SLOT(onEntityType(int)));
563 // Hide buttons of entity types if necessary
564 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
565 QMap<int, QString>::const_iterator anIt;
566 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
568 QButton* aBtn = myEntityTypeGrp->find(anIt.key());
569 theTypes.contains(anIt.key()) ? aBtn->show() : aBtn->hide();
572 // select first button if there is no selected buttons or it is hidden
573 QButton* aBtn = myEntityTypeGrp->selected();
574 if ( aBtn == 0 || theTypes.find(myEntityTypeGrp->id(aBtn)) == theTypes.end())
575 myEntityTypeGrp->setButton(theTypes.first());
577 if (theTypes.count() == 1)
578 myEntityTypeGrp->hide();
580 myEntityTypeGrp->show();
582 myTableGrp->updateGeometry();
583 int aType = myEntityTypeGrp->id(myEntityTypeGrp->selected());
587 //=======================================================================
588 // name : SMESHGUI_FilterTable::GetTableGrp
589 // Purpose : Get group box containing table. May be used for adding new widgets in it
590 //=======================================================================
591 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
593 QFrame* aFrame = new QFrame(theParent);
595 QFrame* aLine1 = new QFrame(aFrame);
596 QFrame* aLine2 = new QFrame(aFrame);
597 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
598 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
599 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
600 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
602 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
604 myWgStack = new QWidgetStack(aFrame);
606 QGridLayout* aLay = new QGridLayout(aFrame, 2, 3, 0, SPACING);
607 aLay->addWidget(aLine1, 0, 0);
608 aLay->addWidget(aLabel, 0, 1);
609 aLay->addWidget(aLine2, 0, 2);
610 aLay->addMultiCellWidget(myWgStack, 1, 1, 0, 2);
615 //=======================================================================
616 // name : SMESHGUI_FilterTable::GetTableGrp
617 // Purpose : Get group box containing table. May be used for adding new widgets in it
618 //=======================================================================
619 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
624 //=======================================================================
625 // name : SMESHGUI_FilterTable::onEntityType
626 // Purpose : SLOT. Called when entity type changed.
627 // Display corresponding table
628 //=======================================================================
629 void SMESHGUI_FilterTable::onEntityType (int theType)
631 if (myEntityType == theType)
635 emit NeedValidation();
638 myEntityTypeGrp->setButton(myEntityType);
642 myEntityType = theType;
644 if (!myTables.contains(theType))
645 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
647 TableMap::iterator anIter;
648 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
649 myEntityType == anIter.key() ? anIter.data()->show() : anIter.data()->hide();
652 qApp->processEvents();
653 myTables[ myEntityType ]->updateGeometry();
656 emit EntityTypeChanged(theType);
660 //=======================================================================
661 // name : SMESHGUI_FilterTable::IsValid
662 // Purpose : Verify validity of entered data
663 //=======================================================================
664 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
666 int aType = theEntityType == -1 ? GetType() : theEntityType;
668 Table* aTable = myTables[ aType ];
669 for (int i = 0, n = aTable->numRows(); i < n; i++)
671 int aCriterion = GetCriterionType(i, aType);
673 if (aCriterion == FT_RangeOfIds ||
674 aCriterion == FT_BelongToGeom ||
675 aCriterion == FT_BelongToPlane ||
676 aCriterion == FT_BelongToCylinder ||
677 aCriterion == FT_LyingOnGeom) {
678 if (aTable->text(i, 2).isEmpty()) {
680 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
681 tr("ERROR"), QMessageBox::Ok);
686 aTable->blockSignals(true);
687 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
688 aTable->blockSignals(false);
690 if (!aRes && aTable->IsEditable(i, 2)) {
692 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
693 tr("ERROR"), QMessageBox::Ok);
696 else if (aType == SMESH::EDGE &&
697 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
701 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
702 tr("MULTIEDGES_ERROR"), QMessageBox::Ok);
707 QTableItem* anItem = aTable->item(i, 0);
708 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
715 //=======================================================================
716 // name : SMESHGUI_FilterTable::SetValidity
717 // Purpose : Set validity of the table
718 //=======================================================================
719 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
724 //=======================================================================
725 // name : SMESHGUI_FilterTable::GetType
726 // Purpose : Get current entity type
727 //=======================================================================
728 int SMESHGUI_FilterTable::GetType() const
733 //=======================================================================
734 // name : SMESHGUI_FilterTable::SetType
735 // Purpose : Set current entity type
736 //=======================================================================
737 void SMESHGUI_FilterTable::SetType (const int type)
739 myEntityTypeGrp->setButton(type);
743 //=======================================================================
744 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
745 // Purpose : Restore previous entity type
746 //=======================================================================
747 void SMESHGUI_FilterTable::RestorePreviousEntityType()
749 SetType(myEntityType);
752 //=======================================================================
753 // name : SMESHGUI_FilterTable::GetCriterionType
754 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
755 //=======================================================================
756 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
758 int aType = theType == -1 ? GetType() : theType;
759 Table* aTable = myTables[ aType ];
760 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
761 return anItem != 0 ? anItem->GetValue() : FT_Undefined;
764 //=======================================================================
765 // name : SMESHGUI_FilterTable::GetCriterion
766 // Purpose : Get parameters of criterion from specified row
767 //=======================================================================
768 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
769 SMESH::Filter::Criterion& theCriterion,
770 const int theEntityType) const
772 int aType = theEntityType == -1 ? GetType() : theEntityType;
773 Table* aTable = myTables[ aType ];
775 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->GetValue();
776 theCriterion.UnaryOp = ((QCheckTableItem*)aTable->item(theRow, 3))->isChecked() ? FT_LogicalNOT : FT_Undefined;
777 theCriterion.BinaryOp = theRow != aTable->numRows() - 1 ?
778 ((ComboItem*)aTable->item(theRow, 4))->GetValue() : FT_Undefined;
779 theCriterion.TypeOfElement = (ElementType)aType;
781 int aCriterionType = GetCriterionType(theRow, aType);
783 if (aCriterionType != FT_RangeOfIds &&
784 aCriterionType != FT_BelongToGeom &&
785 aCriterionType != FT_BelongToPlane &&
786 aCriterionType != FT_BelongToCylinder &&
787 aCriterionType != FT_LyingOnGeom)
789 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->GetValue();
790 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
793 theCriterion.ThresholdStr = aTable->text(theRow, 2).latin1();
795 QTableItem* anItem = aTable->item(theRow, 0);
796 if (myAddWidgets.contains(anItem))
797 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
800 //=======================================================================
801 // name : SMESHGUI_FilterTable::SetCriterion
802 // Purpose : Set parameters of criterion of specified row
803 //=======================================================================
804 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
805 const SMESH::Filter::Criterion& theCriterion,
806 const int theEntityType)
808 int aType = theEntityType == -1 ? GetType() : theEntityType;
810 Table* aTable = myTables[ aType ];
812 if (theRow > aTable->numRows() - 1)
815 ((ComboItem*)aTable->item(theRow, 0))->SetValue(theCriterion.Type);
816 onCriterionChanged(theRow, 0, aType);
817 ((ComboItem*)aTable->item(theRow, 1))->SetValue(theCriterion.Compare);
818 ((QCheckTableItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == FT_LogicalNOT);
820 if (theCriterion.BinaryOp != FT_Undefined)
822 if (!aTable->IsEditable(theRow, 4))
823 aTable->setItem(theRow, 4, getBinaryItem(aTable));
824 ((ComboItem*)aTable->item(theRow, 4))->SetValue(theCriterion.BinaryOp);
827 aTable->SetEditable(false, theRow, 4);
829 if (theCriterion.Type != FT_RangeOfIds &&
830 theCriterion.Type != FT_BelongToGeom &&
831 theCriterion.Type != FT_BelongToPlane &&
832 theCriterion.Type != FT_BelongToCylinder &&
833 theCriterion.Type != FT_LyingOnGeom)
834 aTable->setText(theRow, 2, QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
836 aTable->setText(theRow, 2, QString(theCriterion.ThresholdStr));
838 if (theCriterion.Compare == FT_EqualTo ||
839 theCriterion.Type == FT_BelongToPlane ||
840 theCriterion.Type == FT_BelongToCylinder)
842 QTableItem* anItem = aTable->item(theRow, 0);
843 if (!myAddWidgets.contains(anItem))
845 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
846 myWgStack->addWidget(myAddWidgets[ anItem ]);
848 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
851 emit CriterionChanged(theRow, aType);
855 //=======================================================================
856 // name : SMESHGUI_FilterTable::Update
857 // Purpose : Update table
858 //=======================================================================
859 void SMESHGUI_FilterTable::Update()
861 Table* aTable = myTables[ GetType() ];
862 int aCurrRow = aTable->currentRow();
863 int numRows = aTable->numRows();
864 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
865 aTable->setCurrentCell(0, 0);
866 updateAdditionalWidget();
869 //=======================================================================
870 // name : SMESHGUI_FilterTable::AddCriterion
871 // Purpose : Add criterion with parameters
872 //=======================================================================
873 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
874 const int theEntityType)
876 int aType = theEntityType == -1 ? GetType() : theEntityType;
877 Table* aTable = myTables[ aType ];
878 addRow(aTable, aType);
879 SetCriterion(aTable->numRows() - 1, theCriterion);
882 //=======================================================================
883 // name : SMESHGUI_FilterTable::NumRows
884 // Purpose : Get number of criterions of current type
885 //=======================================================================
886 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
888 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->numRows();
891 //=======================================================================
892 // name : SMESHGUI_FilterTable::Clear
893 // Purpose : Clear current table
894 //=======================================================================
895 void SMESHGUI_FilterTable::Clear (const int theType)
897 int aType = theType == -1 ? GetType() : theType;
898 QTable* aTable = myTables[ aType ];
900 if (aTable->numRows() == 0)
903 while (aTable->numRows() > 0)
905 removeAdditionalWidget(aTable, 0);
906 aTable->removeRow(0);
912 //=======================================================================
913 // name : SMESHGUI_FilterTable::onAddBtn
914 // Purpose : SLOT. Called then "Add" button pressed.
915 // Adds new string to table
916 //=======================================================================
917 void SMESHGUI_FilterTable::onAddBtn()
919 int aType = GetType();
920 addRow(myTables[ aType ], aType);
925 //=======================================================================
926 // name : SMESHGUI_FilterTable::onInsertBtn
927 // Purpose : SLOT. Called then "Insert" button pressed.
928 // Inserts new string before current one
929 //=======================================================================
930 void SMESHGUI_FilterTable::onInsertBtn()
932 addRow(myTables[ GetType() ], GetType(), false);
935 //=======================================================================
936 // name : SMESHGUI_FilterTable::onRemoveBtn
937 // Purpose : SLOT. Called then "Remove" button pressed.
938 // Removes current string from table
939 //=======================================================================
940 void SMESHGUI_FilterTable::onRemoveBtn()
942 Table* aTable = myTables[ GetType() ];
944 if (aTable->numRows() == 0)
947 QMemArray<int> aRows;
948 for (int i = 0, n = aTable->numRows(); i < n; i++)
950 if (aTable->isRowSelected(i))
952 aRows.resize(aRows.size() + 1);
953 aRows[ aRows.size() - 1 ] = i;
954 removeAdditionalWidget(aTable, i);
958 aTable->removeRows(aRows);
960 // remove control of binary logical operation from last row
961 if (aTable->numRows() > 0)
962 aTable->SetEditable(false, aTable->numRows() - 1, 4);
967 //=======================================================================
968 // name : SMESHGUI_FilterTable::updateAdditionalWidget
969 // Purpose : Enable/Disable widget with additonal parameters
970 //=======================================================================
971 void SMESHGUI_FilterTable::updateAdditionalWidget()
973 Table* aTable = myTables[ GetType() ];
974 int aRow = aTable->currentRow();
975 if (aRow < 0 || aRow >= aTable->numRows())
977 myWgStack->setEnabled(false);
981 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
982 bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->GetValue() == FT_EqualTo &&
983 GetCriterionType(aRow) != FT_BelongToGeom &&
984 GetCriterionType(aRow) != FT_LyingOnGeom &&
985 GetCriterionType(aRow) != FT_RangeOfIds &&
986 GetCriterionType(aRow) != FT_FreeEdges &&
987 GetCriterionType(aRow) != FT_BadOrientedVolume;
988 if (!myAddWidgets.contains(anItem))
990 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
991 myWgStack->addWidget(myAddWidgets[ anItem ]);
994 myWgStack->raiseWidget(myWgStack->id(myAddWidgets[ anItem ]));
995 myWgStack->setEnabled(toEnable);
998 //=======================================================================
999 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1000 // Purpose : Remove widgets containing additional parameters from widget
1001 // stack and internal map
1002 //=======================================================================
1003 void SMESHGUI_FilterTable::removeAdditionalWidget (QTable* theTable, const int theRow)
1005 QTableItem* anItem = theTable->item(theRow, 0);
1006 if (myAddWidgets.contains(anItem))
1008 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1009 myAddWidgets[ anItem ]->reparent(0, QPoint());
1010 delete myAddWidgets[ anItem ];
1011 myAddWidgets.remove(anItem);
1015 //=======================================================================
1016 // name : SMESHGUI_FilterTable::onClearBtn
1017 // Purpose : SLOT. Called then "Clear" button pressed.
1018 // Removes all strings from table
1019 //=======================================================================
1020 void SMESHGUI_FilterTable::onClearBtn()
1022 QTable* aTable = myTables[ GetType() ];
1024 if (aTable->numRows() == 0)
1027 while (aTable->numRows() > 0)
1029 removeAdditionalWidget(aTable, 0);
1030 aTable->removeRow(0);
1036 //=======================================================================
1037 // name : SMESHGUI_FilterTable::onCurrentChanged()
1038 // Purpose : SLOT. Called when current cell changed
1039 //=======================================================================
1040 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1043 updateAdditionalWidget();
1044 emit CurrentChanged(theRow, theCol);
1047 //=======================================================================
1048 // name : SMESHGUI_FilterTable::onCriterionChanged()
1049 // Purpose : Provides reaction on change of criterion
1050 //=======================================================================
1051 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1053 int aType = entityType == -1 ? GetType() : entityType;
1054 Table* aTable = myTables[ aType ];
1055 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1057 int aCriterionType = GetCriterionType(row);
1059 if (aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1060 aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
1061 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume)
1063 if (aCompareItem->count() > 0)
1064 aCompareItem->setStringList(QStringList());
1065 aTable->SetEditable(false, row, 2);
1067 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1068 aCriterionType == SMESH::FT_BelongToGeom ||
1069 aCriterionType == SMESH::FT_BelongToPlane ||
1070 aCriterionType == SMESH::FT_BelongToCylinder ||
1071 aCriterionType == SMESH::FT_LyingOnGeom)
1073 QMap<int, QString> aMap;
1074 aMap[ FT_EqualTo ] = tr("EQUAL_TO");
1075 aCompareItem->setStringList(aMap);
1076 if (!aTable->IsEditable(row, 2))
1077 aTable->SetEditable(true, row, 2);
1081 if (aCompareItem->count() != 3)
1083 aCompareItem->setStringList(QStringList());
1084 aCompareItem->setStringList(getCompare());
1087 QString aText = aTable->text(row, 2);
1089 aText.toDouble(&isOk);
1090 aTable->setText(row, 2, isOk ? aText : QString(""));
1091 if (!aTable->IsEditable(row, 2))
1092 aTable->SetEditable(true, row, 2);
1095 updateAdditionalWidget();
1097 emit CriterionChanged(row, entityType);
1100 //=======================================================================
1101 // name : SMESHGUI_FilterTable::onCriterionChanged()
1102 // Purpose : SLOT. Called then contents of table changed
1103 // Provides reaction on change of criterion
1104 //=======================================================================
1105 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1107 onCriterionChanged(row, col, -1);
1110 //=======================================================================
1111 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1112 // Purpose : Get first selected row
1113 //=======================================================================
1114 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1116 QTable* aTable = myTables[ GetType() ];
1117 for (int i = 0, n = aTable->numRows(); i < n; i++)
1118 if (aTable->isRowSelected(i))
1121 int aRow = aTable->currentRow();
1122 return aRow >= 0 && aRow < aTable->numRows() ? aRow : -1;
1125 //=======================================================================
1126 // name : SMESHGUI_FilterTable::addRow
1127 // Purpose : Add row at the end of table
1128 //=======================================================================
1129 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1132 int aSelectedRow = getFirstSelectedRow();
1133 int aCurrCol = theTable->currentColumn();
1136 if (toTheEnd || aSelectedRow == -1)
1138 theTable->insertRows(theTable->numRows());
1139 aCurrRow = theTable->numRows() - 1;
1143 theTable->insertRows(aSelectedRow);
1144 aCurrRow = aSelectedRow;
1149 theTable->setItem(aCurrRow, 0, getCriterionItem(theTable, theType));
1152 theTable->setItem(aCurrRow, 1, getCompareItem(theTable));
1155 //theTable->setItem(aCurrRow, 2, new QTableItem(theTable));
1157 //Logical operation NOT
1158 theTable->setItem(aCurrRow, 3, getUnaryItem(theTable));
1160 // Logical binary operation for previous value
1161 int anAddBinOpStr = -1;
1162 if (aCurrRow == theTable->numRows() - 1)
1163 anAddBinOpStr = aCurrRow - 1;
1164 else if (aCurrRow >= 0 )
1165 anAddBinOpStr = aCurrRow;
1167 if (theTable->item(aCurrRow, 4) == 0 ||
1168 theTable->item(aCurrRow, 4)->rtti() != 1)
1172 if (anAddBinOpStr >= 0 &&
1173 (theTable->item(anAddBinOpStr, 4) == 0 ||
1174 theTable->item(anAddBinOpStr, 4)->rtti() != 1))
1175 theTable->setItem(anAddBinOpStr, 4, getBinaryItem(theTable));
1178 theTable->SetEditable(false, theTable->numRows() - 1, 4);
1180 if (aCurrRow >=0 && aCurrRow < theTable->numRows() &&
1181 aCurrCol >=0 && aCurrCol < theTable->numRows())
1182 theTable->setCurrentCell(aCurrRow, aCurrCol);
1184 onCriterionChanged(aCurrRow, 0);
1189 //=======================================================================
1190 // name : SMESHGUI_FilterTable::getCriterionItem
1191 // Purpose : Get combo table item for criteria of specified type
1192 //=======================================================================
1193 QTableItem* SMESHGUI_FilterTable::getCriterionItem (QTable* theParent , const int theType)
1195 return new ComboItem(theParent, getCriteria(theType));
1198 //=======================================================================
1199 // name : SMESHGUI_FilterTable::getCompareItem
1200 // Purpose : Get combo table item for operation of comparision
1201 //=======================================================================
1202 QTableItem* SMESHGUI_FilterTable::getCompareItem (QTable* theParent)
1204 return new ComboItem(theParent, getCompare());
1207 //=======================================================================
1208 // name : SMESHGUI_FilterTable::getBinaryItem
1210 //=======================================================================
1211 QTableItem* SMESHGUI_FilterTable::getBinaryItem (QTable* theParent)
1213 static QMap<int, QString> aMap;
1216 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1217 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1220 return new ComboItem(theParent, aMap);
1223 //=======================================================================
1224 // name : SMESHGUI_FilterTable::getUnaryItem
1225 // Purpose : Get check table item
1226 //=======================================================================
1227 QTableItem* SMESHGUI_FilterTable::getUnaryItem (QTable* theParent)
1229 return new QCheckTableItem(theParent, tr("NOT"));
1232 //=======================================================================
1233 // name : SMESHGUI_FilterTable::getSupportedTypes
1234 // Purpose : Get all supported type
1235 //=======================================================================
1236 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1238 static QMap<int, QString> aTypes;
1239 if (aTypes.isEmpty())
1241 aTypes[ SMESH::NODE ] = tr("NODES");
1242 aTypes[ SMESH::EDGE ] = tr("EDGES");
1243 aTypes[ SMESH::FACE ] = tr("FACES");
1244 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1250 //=======================================================================
1251 // name : SMESHGUI_FilterTable::getCriteria
1252 // Purpose : Get criteria for specified type
1253 //=======================================================================
1254 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1256 if (theType == SMESH::NODE)
1258 static QMap<int, QString> aCriteria;
1259 if (aCriteria.isEmpty())
1261 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1262 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1263 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1264 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1265 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1269 else if (theType == SMESH::EDGE)
1271 static QMap<int, QString> aCriteria;
1272 if (aCriteria.isEmpty())
1274 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1275 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
1276 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
1277 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1278 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1279 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1280 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1281 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1285 else if (theType == SMESH::FACE)
1287 static QMap<int, QString> aCriteria;
1288 if (aCriteria.isEmpty())
1290 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
1291 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
1292 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
1293 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
1294 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
1295 aCriteria[ SMESH::FT_Area ] = tr("AREA");
1296 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
1297 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1298 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1299 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1300 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1301 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1302 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
1303 aCriteria[ SMESH::FT_MultiConnection2D] = tr("MULTI2D_BORDERS");
1307 else if (theType == SMESH::VOLUME)
1309 static QMap<int, QString> aCriteria;
1310 if (aCriteria.isEmpty())
1312 aCriteria[ SMESH::FT_AspectRatio3D] = tr("ASPECT_RATIO_3D");
1313 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1314 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1315 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1316 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
1322 static QMap<int, QString> aCriteria;
1328 //=======================================================================
1329 // name : SMESHGUI_FilterTable::getCompare
1330 // Purpose : Get operation of comparison
1331 //=======================================================================
1332 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1334 static QMap<int, QString> aMap;
1338 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
1339 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
1340 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
1346 //=======================================================================
1347 // name : SMESHGUI_FilterTable::createTable
1348 // Purpose : Create table
1349 //=======================================================================
1350 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
1354 Table* aTable= new Table(0, 5, theParent);
1356 QHeader* aHeaders = aTable->horizontalHeader();
1358 QFontMetrics aMetrics(aHeaders->font());
1360 // append spaces to the header of criteria in order to
1361 // provide visibility of criterion inside comboboxes
1362 static int aMaxLenCr = 0;
1366 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1367 QMap<int, QString>::const_iterator anIter;
1368 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
1369 aMaxLenCr = Max(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
1372 static int aLenCr = abs( aMaxLenCr -
1373 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
1376 aCrStr.fill(' ', aLenCr);
1378 aCoStr.fill(' ', 10);
1380 aHeaders->setLabel(0, tr("CRITERION") + aCrStr);
1381 aHeaders->setLabel(1, tr("COMPARE") + aCoStr);
1382 aHeaders->setLabel(2, tr("THRESHOLD_VALUE"));
1383 aHeaders->setLabel(3, tr("UNARY"));
1384 aHeaders->setLabel(4, tr("BINARY") + " ");
1386 // set geometry of the table
1387 for (int i = 0; i <= 4; i++)
1388 aTable->adjustColumn(i);
1390 aTable->updateGeometry();
1391 QSize aSize = aTable->sizeHint();
1392 int aWidth = aSize.width();
1393 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
1394 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
1396 connect(aTable, SIGNAL(valueChanged(int, int)),
1397 this, SLOT(onCriterionChanged(int, int)));
1399 connect(aTable, SIGNAL(currentChanged(int, int)),
1400 this, SLOT(onCurrentChanged(int, int)));
1405 //=======================================================================
1406 // name : SMESHGUI_FilterTable::updateBtnState
1407 // Purpose : Update button state
1408 //=======================================================================
1409 void SMESHGUI_FilterTable::updateBtnState()
1411 myRemoveBtn->setEnabled(myTables[ GetType() ]->numRows() > 0);
1412 myClearBtn->setEnabled(myTables[ GetType() ]->numRows() > 0);
1415 //=======================================================================
1416 // name : SMESHGUI_FilterTable::SetEditable
1417 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1418 //=======================================================================
1419 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
1421 TableMap::iterator anIter;
1422 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1424 anIter.data()->setReadOnly(!isEditable);
1429 myInsertBtn->show();
1430 myRemoveBtn->show();
1436 myInsertBtn->hide();
1437 myRemoveBtn->hide();
1442 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1443 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1444 anIter2.data()->SetEditable(isEditable);
1447 //=======================================================================
1448 // name : SMESHGUI_FilterTable::SetEnabled
1449 // Purpose : Enable/Disable table. Switching type of elements already enabled
1450 //=======================================================================
1451 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
1453 myAddBtn->setEnabled(isEnabled);
1454 myInsertBtn->setEnabled(isEnabled);
1455 myRemoveBtn->setEnabled(isEnabled);
1456 myClearBtn->setEnabled(isEnabled);
1461 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1462 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1463 anIter2.data()->setEnabled(isEnabled);
1466 //=======================================================================
1467 // name : SMESHGUI_FilterTable::IsEditable
1468 // Purpose : Verify whether table is editable
1469 //=======================================================================
1470 bool SMESHGUI_FilterTable::IsEditable() const
1472 return !myTables[ GetType() ]->isReadOnly();
1475 //=======================================================================
1476 // name : SMESHGUI_FilterTable::SetLibsEnabled
1477 // Purpose : Show/hide buttons for work with libraries
1478 //=======================================================================
1479 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
1483 myCopyFromBtn->show();
1488 myCopyFromBtn->hide();
1493 //=======================================================================
1494 // name : SMESHGUI_FilterTable::onCopyFromBtn
1495 // Purpose : SLOT. Called the "Copy from ..." button clicked
1496 // Display filter library dialog
1497 //=======================================================================
1498 void SMESHGUI_FilterTable::onCopyFromBtn()
1501 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1502 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1504 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1506 if (myLibDlg->exec() == QDialog::Accepted)
1508 Copy(myLibDlg->GetTable());
1513 //=======================================================================
1514 // name : SMESHGUI_FilterTable::onAddToBtn
1515 // Purpose : SLOT. Called the "Add to ..." button clicked
1516 // Display filter library dialog
1517 //=======================================================================
1518 void SMESHGUI_FilterTable::onAddToBtn()
1523 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1524 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1526 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1528 myLibDlg->SetTable(this);
1533 //=======================================================================
1534 // name : SMESHGUI_FilterTable::Copy
1535 // Purpose : Initialise table with values of other table
1536 //=======================================================================
1537 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
1541 for (int i = 0, n = theTable->NumRows(); i < n; i++)
1543 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1544 theTable->GetCriterion(i, aCriterion);
1545 AddCriterion(aCriterion);
1549 //=======================================================================
1550 // name : SMESHGUI_FilterTable::CurrentCell
1551 // Purpose : Returns current cell
1552 //=======================================================================
1553 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
1555 theRow = myTables[ GetType() ]->currentRow();
1556 theCol = myTables[ GetType() ]->currentColumn();
1557 return theRow >= 0 && theCol >= 0;
1560 //=======================================================================
1561 // name : SMESHGUI_FilterTable::SetText
1562 // Purpose : Set text and internal value in cell of threshold value
1563 //=======================================================================
1564 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
1565 const QString& theText,
1566 const int theEntityType)
1568 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1569 aTable->setText(theRow, 2, theText);
1572 //=======================================================================
1573 // name : SMESHGUI_FilterTable::SetText
1574 // Purpose : Get text and internal value from cell of threshold value
1575 //=======================================================================
1576 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
1578 const int theEntityType)
1580 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1581 QTableItem* anItem = aTable->item(theRow, 2);
1584 theText = anItem->text();
1592 Class : SMESHGUI_FilterDlg
1593 Description : Dialog to specify filters for VTK viewer
1597 //=======================================================================
1598 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1599 // Purpose : Constructor
1600 //=======================================================================
1601 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1602 const QValueList<int>& theTypes,
1603 const char* theName)
1604 : QDialog( SMESH::GetDesktop( theModule ), theName, false,
1605 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
1606 mySMESHGUI( theModule ),
1607 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) ),
1608 myViewWindow( SMESH::GetViewWindow( theModule ) ),
1609 mySelector( myViewWindow->GetSelector() )
1611 construct(theTypes);
1614 //=======================================================================
1615 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1616 // Purpose : Constructor
1617 //=======================================================================
1618 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1620 const char* theName)
1621 : QDialog( SMESH::GetDesktop( theModule ), theName, false,
1622 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
1623 mySMESHGUI( theModule ),
1624 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
1626 myViewWindow = SMESH::GetViewWindow( theModule );
1627 mySelector = myViewWindow->GetSelector();
1628 QValueList<int> aTypes;
1629 aTypes.append(theType);
1633 //=======================================================================
1634 // name : SMESHGUI_FilterDlg::construct
1635 // Purpose : Construct dialog (called by constructor)
1636 //=======================================================================
1637 void SMESHGUI_FilterDlg::construct (const QValueList<int>& theTypes)
1641 setCaption(tr("CAPTION"));
1643 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
1645 myMainFrame = createMainFrame (this);
1646 QFrame* aBtnFrame = createButtonFrame(this);
1648 aDlgLay->addWidget(myMainFrame);
1649 aDlgLay->addWidget(aBtnFrame);
1651 aDlgLay->setStretchFactor(myMainFrame, 1);
1656 //=======================================================================
1657 // name : SMESHGUI_FilterDlg::createMainFrame
1658 // Purpose : Create frame containing dialog's input fields
1659 //=======================================================================
1660 QFrame* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
1662 QGroupBox* aMainFrame = new QGroupBox(1, Qt::Horizontal, theParent);
1663 aMainFrame->setFrameStyle(QFrame::NoFrame);
1664 aMainFrame->setInsideMargin(0);
1668 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
1669 myTable->SetLibsEnabled(true);
1671 QFrame* aLine = new QFrame(myTable->GetTableGrp());
1672 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1674 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), myTable->GetTableGrp());
1675 mySetInViewer->setChecked(true);
1678 mySourceGrp = createSourceGroup(aMainFrame);
1680 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
1681 SLOT(onCriterionChanged(const int, const int)));
1683 connect(myTable, SIGNAL(CurrentChanged(int, int)),
1684 SLOT(onCurrentChanged(int, int)));
1689 //=======================================================================
1690 // name : SMESHGUI_FilterDlg::createSourceFrame
1691 // Purpose : Create frame containing source radio button
1692 //=======================================================================
1693 QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
1695 QButtonGroup* aGrp = new QButtonGroup(1, Qt::Vertical, tr("SOURCE"), theParent);
1697 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aGrp);
1698 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aGrp);
1699 QRadioButton* aGrpBtn = new QRadioButton(tr("CURRENT_GROUP"), aGrp);
1701 aGrp->insert(aMeshBtn, Mesh);
1702 aGrp->insert(aSelBtn, Selection);
1703 aGrp->insert(aGrpBtn, Dialog);
1705 aGrp->setButton(Selection);
1710 //=======================================================================
1711 // name : SMESHGUI_FilterDlg::updateMainButtons
1712 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
1713 //=======================================================================
1714 void SMESHGUI_FilterDlg::updateMainButtons()
1716 if (myTypes.count() == 1)
1718 myButtons[ BTN_Cancel ]->show();
1719 myButtons[ BTN_Apply ]->hide();
1720 myButtons[ BTN_Close ]->hide();
1724 myButtons[ BTN_Cancel ]->hide();
1725 myButtons[ BTN_Apply ]->show();
1726 myButtons[ BTN_Close ]->show();
1729 // updateGeometry();
1732 //=======================================================================
1733 // name : SMESHGUI_FilterDlg::createButtonFrame
1734 // Purpose : Create frame containing buttons
1735 //=======================================================================
1736 QFrame* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
1738 QGroupBox* aGrp = new QGroupBox(1, Qt::Vertical, theParent);
1740 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_OK" ), aGrp);
1741 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
1743 QLabel* aLbl = new QLabel(aGrp);
1744 aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1746 myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
1747 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
1749 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
1750 connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
1751 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
1752 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
1754 updateMainButtons();
1759 //=======================================================================
1760 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
1761 // Purpose : Destructor
1762 //=======================================================================
1763 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
1767 //=======================================================================
1768 // name : SMESHGUI_FilterDlg::Init
1769 // Purpose : Init dialog fields, connect signals and slots, show dialog
1770 //=======================================================================
1771 void SMESHGUI_FilterDlg::Init (const int type)
1773 QValueList<int> aTypes;
1774 aTypes.append(type);
1778 //=======================================================================
1779 // name : SMESHGUI_FilterDlg::Init
1780 // Purpose : Init dialog fields, connect signals and slots, show dialog
1781 //=======================================================================
1782 void SMESHGUI_FilterDlg::Init (const QValueList<int>& theTypes)
1786 myMesh = SMESH::SMESH_Mesh::_nil();
1788 myIsSelectionChanged = false;
1790 myTable->Init(theTypes);
1793 if (theTypes.count() == 1)
1795 int aType = theTypes.first();
1796 if (aType == SMESH::NODE ) setCaption(tr("NODES_TLT"));
1797 else if (aType == SMESH::EDGE ) setCaption(tr("EDGES_TLT"));
1798 else if (aType == SMESH::FACE ) setCaption(tr("FACES_TLT"));
1799 else if (aType == SMESH::VOLUME) setCaption(tr("VOLUMES_TLT"));
1802 setCaption(tr("TLT"));
1804 qApp->processEvents();
1809 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1811 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
1812 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
1815 mySMESHGUI->DefineDlgPosition(this, x, y);
1818 updateMainButtons();
1821 // Initialise filter table with values of previous filter
1822 QValueList<int>::const_iterator anIter;
1823 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
1825 myTable->Clear(*anIter);
1826 if (!myFilter[ *anIter ]->_is_nil())
1828 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1829 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
1831 for (int i = 0, n = aCriteria->length(); i < n; i++)
1832 myTable->AddCriterion(aCriteria[ i ], *anIter);
1837 if (myInsertState.contains(theTypes.first()))
1838 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
1840 mySetInViewer->setChecked(true);
1841 if (myApplyToState.contains(theTypes.first()))
1842 mySourceGrp->setButton(myApplyToState[ theTypes.first() ]);
1844 mySourceGrp->setButton(Selection);
1847 //=======================================================================
1848 // name : SMESHGUI_FilterDlg::onOk
1849 // Purpose : SLOT called when "Ok" button pressed.
1850 // Assign filters VTK viewer and close dialog
1851 //=======================================================================
1852 void SMESHGUI_FilterDlg::onOk()
1856 mySelectionMgr->clearFilters();
1857 disconnect(mySMESHGUI, 0, this, 0);
1858 disconnect(mySelectionMgr, 0, this, 0);
1859 mySMESHGUI->ResetState();
1865 //=======================================================================
1866 // name : SMESHGUI_FilterDlg::onClose
1867 // Purpose : SLOT called when "Close" button pressed. Close dialog
1868 //=======================================================================
1869 void SMESHGUI_FilterDlg::onClose()
1871 // Restore previously selected object
1874 SALOME_ListIO aList;
1875 mySelectionMgr->clearFilters();
1876 mySelectionMgr->clearSelected();
1877 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
1878 for (; anIter.More(); anIter.Next())
1880 aList.Append(anIter.Key());
1882 TColStd_MapOfInteger aResMap;
1883 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
1884 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
1885 aResMap.Add(anIndMap(i));
1887 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
1888 myViewWindow->highlight( anIter.Key(), true, true );
1890 mySelectionMgr->setSelectedObjects(aList, false);
1893 disconnect(mySMESHGUI, 0, this, 0);
1894 disconnect(mySelectionMgr, 0, this, 0);
1895 mySMESHGUI->ResetState();
1900 //=======================================================================
1901 // name : SMESHGUI_FilterDlg::onDeactivate
1902 // Purpose : SLOT called when dialog must be deativated
1903 //=======================================================================
1904 void SMESHGUI_FilterDlg::onDeactivate()
1909 //=======================================================================
1910 // name : SMESHGUI_FilterDlg::enterEvent
1911 // Purpose : Event filter
1912 //=======================================================================
1913 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
1915 // mySMESHGUI->EmitSignalDeactivateDialog();
1916 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1917 mySMESHGUI->ResetState();
1921 //=======================================================================
1922 // name : closeEvent()
1924 //=======================================================================
1925 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
1930 //=======================================================================
1931 // name : SMESHGUI_FilterDlg::getIdsFromWg
1932 // Purpose : Retrieve list of ids from given widget
1933 //=======================================================================
1934 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QValueList<int>& theRes) const
1940 if (theWg->inherits("QListBox"))
1942 QListBox* aListBox = (QListBox*)theWg;
1944 for (int i = 0, n = aListBox->count(); i < n; i++)
1946 int anId = aListBox->text(i).toInt(&b);
1948 theRes.append(anId);
1951 else if (theWg->inherits("QLineEdit"))
1953 QLineEdit* aLineEdit = (QLineEdit*)theWg;
1954 QString aStr = aLineEdit->text();
1955 QRegExp aRegExp("(\\d+)");
1960 aPos = aRegExp.search(aStr, aPos);
1963 int anId = aRegExp.cap(1).toInt(&b);
1965 theRes.append(anId);
1966 aPos += aRegExp.matchedLength();
1972 //=======================================================================
1973 // name : SMESHGUI_FilterDlg::getSelMode
1974 // Purpose : Get selection mode of specified type
1975 //=======================================================================
1976 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
1980 case SMESH::NODE : return NodeSelection;
1981 case SMESH::EDGE : return EdgeSelection;
1982 case SMESH::FACE : return FaceSelection;
1983 case SMESH::VOLUME : return VolumeSelection;
1984 default : return ActorSelection;
1989 //=======================================================================
1990 // name : SMESHGUI_FilterDlg::setIdsToWg
1991 // Purpose : Insert identifiers in specified widgets
1992 //=======================================================================
1993 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QValueList<int>& theIds)
1998 if (theWg->inherits("QListBox"))
2000 QListBox* aListBox = (QListBox*)theWg;
2003 QStringList aStrList;
2004 QValueList<int>::const_iterator anIter;
2005 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter)
2006 aStrList.append(QString("%1").arg(*anIter));
2008 aListBox->insertStringList(aStrList);
2010 else if (theWg->inherits("QLineEdit"))
2012 QLineEdit* aLineEdit = (QLineEdit*)theWg;
2014 QValueList<int>::const_iterator anIter;
2016 for (anIter = theIds.begin(); anIter != theIds.end(); ++ anIter)
2017 aStr += QString("%1 ").arg(*anIter);
2019 if (!aStr.isEmpty())
2020 aStr.remove(aStr.length() - 1, 1);
2022 aLineEdit->setText(aStr);
2026 //=======================================================================
2027 // name : SMESHGUI_FilterDlg::isValid
2028 // Purpose : Verify validity of input data
2029 //=======================================================================
2030 bool SMESHGUI_FilterDlg::isValid() const
2032 if (!myTable->IsValid())
2035 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2037 int aType = myTable->GetCriterionType(i);
2038 if (aType == FT_BelongToGeom ||
2039 aType == FT_BelongToPlane ||
2040 aType == FT_BelongToCylinder ||
2041 aType == FT_LyingOnGeom) {
2043 myTable->GetThreshold(i, aName);
2045 std::vector<_PTR(SObject)> aList =
2046 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.latin1(), "GEOM");
2047 if (aList.size() == 0) {
2048 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2049 tr("BAD_SHAPE_NAME").arg(aName), QMessageBox::Ok);
2053 if (aType == FT_BelongToCylinder || aType == FT_BelongToPlane) {
2054 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2055 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2056 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2057 if (!aGeomObj->_is_nil()) {
2059 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2061 aFace.ShapeType() != TopAbs_FACE) {
2062 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2063 tr("SHAPE_IS_NOT_A_FACE").arg(aName), QMessageBox::Ok);
2067 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2068 if (aSurf.IsNull()) {
2069 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2070 tr("SHAPE_IS_NOT_A_FACE").arg(aName), QMessageBox::Ok);
2074 if (aType == FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2075 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2076 tr("SHAPE_IS_NOT_A_PLANE").arg(aName), QMessageBox::Ok);
2080 if (aType == FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2081 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2082 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName), QMessageBox::Ok);
2093 //=======================================================================
2094 // name : SMESHGUI_FilterDlg::SetSourceWg
2095 // Purpose : Set widget of parent dialog containing idsto be filtered if
2096 // user select corresponding source radio button
2097 //=======================================================================
2098 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg)
2103 //=======================================================================
2104 // name : SMESHGUI_FilterDlg::SetGroupIds
2105 // Purpose : Set mesh
2106 //=======================================================================
2107 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_ptr theMesh)
2112 //=======================================================================
2113 // name : SMESHGUI_FilterDlg::SetSelection
2114 // Purpose : Get filtered ids
2115 //=======================================================================
2116 void SMESHGUI_FilterDlg::SetSelection()
2119 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
2121 if (mySelectionMgr) {
2123 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
2124 SALOME_ListIteratorOfListIO anIter (anObjs);
2125 for (; anIter.More(); anIter.Next()) {
2126 TColStd_IndexedMapOfInteger aMap;
2127 mySelector->GetIndex(anIter.Value(), aMap);
2128 myIObjects.Bind(anIter.Value(), aMap);
2131 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2139 //=======================================================================
2140 // name : SMESHGUI_FilterDlg::onApply
2141 // Purpose : SLOT called when "Apply" button pressed.
2142 // Assign filters to VTK viewer
2143 //=======================================================================
2144 bool SMESHGUI_FilterDlg::onApply()
2150 int aCurrType = myTable->GetType();
2152 if (!createFilter(aCurrType))
2155 insertFilterInViewer();
2157 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
2158 QValueList<int> aResultIds;
2159 filterSource(aCurrType, aResultIds);
2160 selectInViewer(aCurrType, aResultIds);
2163 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2164 myApplyToState[ aCurrType ] = mySourceGrp->id(mySourceGrp->selected());
2166 catch(const SALOME::SALOME_Exception& S_ex)
2168 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2177 //=======================================================================
2178 // name : SMESHGUI_FilterDlg::createFilter
2179 // Purpose : Create predicate for given type
2180 //=======================================================================
2181 bool SMESHGUI_FilterDlg::createFilter (const int theType)
2183 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2184 if (aFilterMgr->_is_nil())
2187 int n = myTable->NumRows();
2189 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2190 aCriteria->length(n);
2192 long aPrecision = -1;
2193 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2195 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
2196 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
2198 for (CORBA::ULong i = 0; i < n; i++) {
2199 SMESH::Filter::Criterion aCriterion = createCriterion();
2200 myTable->GetCriterion(i, aCriterion);
2201 aCriterion.Precision = aPrecision;
2202 aCriteria[ i ] = aCriterion;
2205 myFilter[ theType ] = aFilterMgr->CreateFilter();
2206 myFilter[ theType ]->SetCriteria(aCriteria.inout());
2211 //=======================================================================
2212 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2213 // Purpose : Insert filter in viewer
2214 //=======================================================================
2215 void SMESHGUI_FilterDlg::insertFilterInViewer()
2217 if (SVTK_InteractorStyle* aStyle = SMESH::GetInteractorStyle()) {
2218 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2220 if (myFilter[ myTable->GetType() ]->_is_nil() ||
2221 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2222 !mySetInViewer->isChecked()) {
2223 SMESH::RemoveFilter(getFilterId(anEntType), aStyle);
2225 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2226 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
2227 SMESH::SetFilter(aFilter, aStyle);
2232 //=======================================================================
2233 // name : SMESHGUI_FilterDlg::filterSource
2234 // Purpose : Filter source ids
2235 //=======================================================================
2236 void SMESHGUI_FilterDlg::filterSource (const int theType,
2237 QValueList<int>& theResIds)
2240 if (myFilter[ theType ]->_is_nil())
2243 int aSourceId = mySourceGrp->id(mySourceGrp->selected());
2245 if (aSourceId == Mesh)
2247 if (myMesh->_is_nil())
2249 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
2250 for (int i = 0, n = anIds->length(); i < n; i++)
2251 theResIds.append(anIds[ i ]);
2253 else if (aSourceId == Selection)
2255 filterSelectionSource(theType, theResIds);
2257 else if (aSourceId == Dialog)
2259 // retrieve ids from dialog
2260 QValueList<int> aDialogIds;
2261 getIdsFromWg(mySourceWg, aDialogIds);
2263 if (myMesh->_is_nil())
2265 theResIds = aDialogIds;
2270 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2271 aPred->SetMesh(myMesh);
2272 QValueList<int>::const_iterator anIter;
2273 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
2274 if (aPred->IsSatisfy(*anIter))
2275 theResIds.append(*anIter);
2277 // set ids to the dialog
2278 setIdsToWg(mySourceWg, theResIds);
2282 //=======================================================================
2283 // name : SMESHGUI_FilterDlg::filterSelectionSource
2284 // Purpose : Filter source selection
2285 //=======================================================================
2286 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
2287 QValueList<int>& theResIds)
2290 if (myMesh->_is_nil() || mySelectionMgr == 0)
2293 // Create map of entities to be filtered
2294 TColStd_MapOfInteger aToBeFiltered;
2295 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
2297 for (; anIter.More(); anIter.Next())
2300 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
2301 if (!aSubMesh->_is_nil())
2303 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
2305 SMESH::long_array_var anIds =
2306 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2307 for (int i = 0, n = anIds->length(); i < n; i++)
2308 aToBeFiltered.Add(anIds[ i ]);
2313 SMESH::SMESH_GroupBase_var aGroup =
2314 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
2315 if (!aGroup->_is_nil())
2317 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
2319 SMESH::long_array_var anIds = aGroup->GetListOfID();
2320 for (int i = 0, n = anIds->length(); i < n; i++)
2321 aToBeFiltered.Add(anIds[ i ]);
2326 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
2327 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
2329 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2331 if (aSelMap.Extent() > 0)
2333 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
2335 for (int i = 1; i <= aSelMap.Extent(); i++)
2336 aToBeFiltered.Add(aSelMap(i));
2343 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2344 aPred->SetMesh(myMesh);
2345 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
2346 for (; aResIter.More(); aResIter.Next())
2347 if (aPred->IsSatisfy(aResIter.Key()))
2348 theResIds.append(aResIter.Key());
2351 //=======================================================================
2352 // name : SMESHGUI_FilterDlg::selectInViewer
2353 // Purpose : Select given entities in viewer
2354 //=======================================================================
2355 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QValueList<int>& theIds)
2357 if (mySelectionMgr == 0 || myMesh->_is_nil())
2360 mySelectionMgr->clearFilters();
2362 // Set new selection mode if necessary
2363 Selection_Mode aSelMode = getSelMode(theType);
2364 if (myViewWindow->SelectionMode()!=aSelMode) {
2365 mySelectionMgr->clearSelected();
2366 mySelectionMgr->clearFilters();
2367 if (aSelMode == NodeSelection)
2368 SMESH::SetPointRepresentation(true);
2369 myViewWindow->SetSelectionMode(aSelMode);
2373 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2374 if (!anActor || !anActor->hasIO())
2377 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2378 //mySelectionMgr->clearSelected();
2379 //mySelectionMgr->AddIObject(anIO, false);
2380 SALOME_ListIO aList;
2382 mySelectionMgr->setSelectedObjects(aList, false);
2384 // Remove filter corresponding to the current type from viewer
2385 int aType = myTable->GetType();
2386 int aFilterId = SMESHGUI_UnknownFilter;
2387 if (aType == SMESH::EDGE ) aFilterId = SMESHGUI_EdgeFilter;
2388 else if (aType == SMESH::FACE ) aFilterId = SMESHGUI_FaceFilter;
2389 else if (aType == SMESH::VOLUME) aFilterId = SMESHGUI_VolumeFilter;
2390 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
2391 SMESH::RemoveFilter(aFilterId);
2394 TColStd_MapOfInteger aMap;
2395 QValueList<int>::const_iterator anIter;
2396 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
2400 // Set new selection
2401 mySelector->AddOrRemoveIndex(anIO, aMap, false);
2402 myViewWindow->highlight( anIO, true, true );
2404 // insert previously stored filter in viewer if necessary
2405 if (!aFilter.IsNull())
2406 SMESH::SetFilter(aFilter);
2409 //=======================================================================
2410 // name : SMESHGUI_FilterDlg::createCriterion
2411 // Purpose : Create criterion structure with default values
2412 //=======================================================================
2413 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2415 SMESH::Filter::Criterion aCriterion;
2417 aCriterion.Type = FT_Undefined;
2418 aCriterion.Compare = FT_Undefined;
2419 aCriterion.Threshold = 0;
2420 aCriterion.UnaryOp = FT_Undefined;
2421 aCriterion.BinaryOp = FT_Undefined;
2422 aCriterion.ThresholdStr = "";
2423 aCriterion.TypeOfElement = SMESH::ALL;
2428 //=======================================================================
2429 // name : SMESHGUI_FilterDlg::onSelectionDone
2430 // Purpose : SLOT called when selection changed.
2431 // If current cell corresponds to the threshold value of
2432 // BelongToGeom criterion name of selected object is set in this cell
2433 //=======================================================================
2434 void SMESHGUI_FilterDlg::onSelectionDone()
2437 const SALOME_ListIO& aList = mySelector->StoredIObjects();
2439 if (aList.Extent() != 1 ||
2440 !myTable->CurrentCell(aRow, aCol) ||
2441 myTable->GetCriterionType(aRow) != FT_BelongToGeom &&
2442 myTable->GetCriterionType(aRow) != FT_BelongToPlane &&
2443 myTable->GetCriterionType(aRow) != FT_BelongToCylinder &&
2444 myTable->GetCriterionType(aRow) != FT_LyingOnGeom)
2447 Handle(SALOME_InteractiveObject) anIO = aList.First();
2448 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
2449 if (!anObj->_is_nil())
2450 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
2453 //=======================================================================
2454 // name : SMESHGUI_FilterDlg::onCriterionChanged
2455 // Purpose : SLOT called when cretarion of current row changed. Update selection
2456 //=======================================================================
2457 void SMESHGUI_FilterDlg::onCriterionChanged (const int , const int)
2462 //=======================================================================
2463 // name : SMESHGUI_FilterDlg::onCurrentChanged
2464 // Purpose : SLOT called when current row changed. Update selection
2465 //=======================================================================
2466 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
2471 //=======================================================================
2472 // name : SMESHGUI_FilterDlg::updateSelection
2473 // Purpose : UpdateSelection in accordance with current row
2474 //=======================================================================
2475 void SMESHGUI_FilterDlg::updateSelection()
2477 if (mySelectionMgr == 0)
2480 TColStd_MapOfInteger allTypes;
2481 for( int i=0; i<10; i++ )
2483 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
2488 mySelectionMgr->clearFilters();
2492 if (myTable->CurrentCell(aRow, aCol) &&
2493 (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
2494 myTable->GetCriterionType(aRow) == FT_BelongToPlane ||
2495 myTable->GetCriterionType(aRow) == FT_BelongToCylinder ||
2496 myTable->GetCriterionType(aRow) == FT_LyingOnGeom)) {
2498 if (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
2499 myTable->GetCriterionType(aRow) == FT_LyingOnGeom) {
2501 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
2503 } else if (myTable->GetCriterionType(aRow) == FT_BelongToPlane) {
2504 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
2506 } else if (myTable->GetCriterionType(aRow) == FT_BelongToCylinder) {
2507 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
2509 myIsSelectionChanged = true;
2512 if (myIsSelectionChanged) {
2513 mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection