1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_FilterDlg.cxx
24 // Author : Sergey LITONIN
27 #include "SMESHGUI_FilterDlg.h"
30 #include "SMESHGUI_Utils.h"
31 #include "SMESHGUI_VTKUtils.h"
32 #include "SMESHGUI_Filter.h"
33 #include "SMESHGUI_FilterUtils.h"
34 #include "SMESHGUI_FilterLibraryDlg.h"
36 #include "SMESH_Actor.h"
37 #include "SMESH_NumberFilter.hxx"
38 #include "SMESH_TypeFilter.hxx"
41 #include "GEOM_FaceFilter.h"
42 #include "GEOM_TypeFilter.h"
44 #include "SUIT_Desktop.h"
45 #include "SUIT_ResourceMgr.h"
46 #include "SUIT_Session.h"
47 #include "SUIT_MessageBox.h"
49 #include "LightApp_Application.h"
50 #include "SalomeApp_Tools.h"
51 #include "SalomeApp_Study.h"
53 #include "SALOME_ListIO.hxx"
54 #include "SALOME_ListIteratorOfListIO.hxx"
55 #include "SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger.hxx"
56 #include "SALOMEDSClient_Study.hxx"
58 #include "SVTK_ViewWindow.h"
59 #include "SVTK_Selector.h"
62 #include <StdSelect_TypeOfFace.hxx>
63 #include <BRep_Tool.hxx>
65 #include <TopoDS_Face.hxx>
66 #include <TopoDS_Shape.hxx>
67 #include <Geom_Plane.hxx>
68 #include <Geom_CylindricalSurface.hxx>
69 #include <Precision.hxx>
70 #include <TColStd_MapOfInteger.hxx>
71 #include <TColStd_IndexedMapOfInteger.hxx>
72 #include <TColStd_MapIteratorOfMapOfInteger.hxx>
77 #include <qlineedit.h>
78 #include <qpushbutton.h>
79 #include <qgroupbox.h>
81 #include <qstringlist.h>
83 #include <qwidgetstack.h>
84 #include <qapplication.h>
85 #include <qcombobox.h>
86 #include <qfontmetrics.h>
87 #include <qmessagebox.h>
89 #include <qbuttongroup.h>
90 #include <qradiobutton.h>
93 #include <qcheckbox.h>
94 #include <qobjectlist.h>
95 #include <qvalidator.h>
98 #include "SALOMEconfig.h"
99 #include CORBA_SERVER_HEADER(SMESH_Group)
104 using namespace SMESH;
106 static int maxLength (const QMap<int, QString> theMap, const QFontMetrics& theMetrics)
109 QMap<int, QString>::const_iterator anIter;
110 for (anIter = theMap.begin(); anIter != theMap.end(); ++anIter)
111 aRes = Max(aRes, theMetrics.width(anIter.data()));
115 static int getFilterId (SMESH::ElementType theType)
119 case SMESH::NODE : return SMESHGUI_NodeFilter;
120 case SMESH::EDGE : return SMESHGUI_EdgeFilter;
121 case SMESH::FACE : return SMESHGUI_FaceFilter;
122 case SMESH::VOLUME : return SMESHGUI_VolumeFilter;
123 case SMESH::ALL : return SMESHGUI_AllElementsFilter;
124 default : return SMESHGUI_UnknownFilter;
129 Class : SMESHGUI_FilterTable::AdditionalWidget
130 Description : Class for storing additional parameters of criterion
133 class SMESHGUI_FilterTable::AdditionalWidget : public QFrame
140 AdditionalWidget(QWidget* theParent);
141 virtual ~AdditionalWidget();
143 virtual void GetParameters(QValueList<int>&) const;
144 virtual bool IsValid(const bool theMsg = true) const;
145 virtual double GetDouble(const int theId) const;
146 virtual int GetInteger(const int theId) const;
147 virtual QString GetString(const int theId) const;
148 virtual void SetDouble(const int theId, const double theVal);
149 virtual void SetInteger(const int theId, const int theVal);
150 virtual void SetString(const int theId, const QString& theVal);
151 void SetEditable(const int theId, const bool isEditable);
152 void SetEditable(const bool isEditable);
155 QMap< int, QLineEdit* > myLineEdits;
158 SMESHGUI_FilterTable::AdditionalWidget::AdditionalWidget (QWidget* theParent)
161 QLabel* aLabel = new QLabel(tr("SMESH_TOLERANCE"), this);
162 myLineEdits[ Tolerance ] = new QLineEdit(this);
163 QDoubleValidator* aValidator = new QDoubleValidator(myLineEdits[ Tolerance ]);
164 aValidator->setBottom(0);
165 myLineEdits[ Tolerance ]->setValidator(aValidator);
167 QHBoxLayout* aLay = new QHBoxLayout(this, 0, SPACING);
168 aLay->addWidget(aLabel);
169 aLay->addWidget(myLineEdits[ Tolerance ]);
171 QSpacerItem* aSpacer = new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum);
172 aLay->addItem(aSpacer);
174 QString aText = QString("%1").arg(Precision::Confusion());
175 myLineEdits[ Tolerance ]->setText(aText);
178 SMESHGUI_FilterTable::AdditionalWidget::~AdditionalWidget()
182 void SMESHGUI_FilterTable::AdditionalWidget::GetParameters (QValueList<int>& theList) const
185 theList.append(Tolerance);
188 bool SMESHGUI_FilterTable::AdditionalWidget::IsValid (const bool theMsg) const
193 QValueList<int> aParams;
194 GetParameters(aParams);
195 QValueList<int>::const_iterator anIter;
196 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter) {
197 const QLineEdit* aWg = myLineEdits[ *anIter ];
199 QString aText = aWg->text();
200 if (aWg->isEnabled() && aWg->validator()->validate(aText, p) != QValidator::Acceptable) {
202 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
203 tr("SMESHGUI_INVALID_PARAMETERS"), QMessageBox::Ok);
211 double SMESHGUI_FilterTable::AdditionalWidget::GetDouble (const int theId) const
213 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toDouble() : 0;
216 int SMESHGUI_FilterTable::AdditionalWidget::GetInteger (const int theId) const
218 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text().toInt() : 0;
221 QString SMESHGUI_FilterTable::AdditionalWidget::GetString (const int theId) const
223 return myLineEdits.contains(theId) ? myLineEdits[ theId ]->text() : QString("");
226 void SMESHGUI_FilterTable::AdditionalWidget::SetDouble (const int theId, const double theVal)
228 if (myLineEdits.contains(theId))
229 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
232 void SMESHGUI_FilterTable::AdditionalWidget::SetInteger (const int theId, const int theVal)
234 if (myLineEdits.contains(theId))
235 myLineEdits[ theId ]->setText(QString("%1").arg(theVal));
238 void SMESHGUI_FilterTable::AdditionalWidget::SetString (const int theId, const QString& theVal)
240 if (myLineEdits.contains(theId))
241 myLineEdits[ theId ]->setText(theVal);
244 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const int theId, const bool isEditable)
246 if (myLineEdits.contains(theId))
247 myLineEdits[ theId ]->setEdited(isEditable);
250 void SMESHGUI_FilterTable::AdditionalWidget::SetEditable (const bool isEditable)
252 QValueList<int> aParams;
253 GetParameters(aParams);
254 QValueList<int>::const_iterator anIter;
255 for (anIter = aParams.begin(); anIter != aParams.end(); ++anIter)
256 myLineEdits[ *anIter ]->setEdited(isEditable);
260 Class : SMESHGUI_FilterTable::ComboItem
261 Description : Combo table item. Identificator corresponding to string may be assigned
264 class SMESHGUI_FilterTable::ComboItem : public QComboTableItem
267 ComboItem(QTable*, const QMap<int, QString>&);
268 virtual ~ComboItem();
270 virtual void setStringList (const QStringList & l);
271 void setStringList(const QMap<int, QString>& theIds);
273 int GetValue() const;
274 void SetValue(const int);
278 QMap<int, int> myNumToId;
279 QMap<int, int> myIdToNum;
282 SMESHGUI_FilterTable::ComboItem::ComboItem (QTable* theParent,
283 const QMap<int, QString>& theIds)
284 : QComboTableItem(theParent, QStringList())
286 setStringList(theIds);
289 void SMESHGUI_FilterTable::ComboItem::setStringList (const QStringList & l)
291 QComboTableItem::setStringList(l);
294 void SMESHGUI_FilterTable::ComboItem::setStringList (const QMap<int, QString>& theIds)
298 QMap<int, QString>::const_iterator anIter;
299 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
300 myNumToId[ i ] = anIter.key();
301 myIdToNum[ anIter.key() ] = i;
302 aList.append(anIter.data());
306 setStringList(aList);
309 SMESHGUI_FilterTable::ComboItem::~ComboItem()
313 int SMESHGUI_FilterTable::ComboItem::GetValue() const
315 return myNumToId[ currentItem() ];
318 void SMESHGUI_FilterTable::ComboItem::SetValue (const int theVal)
320 setCurrentItem(myIdToNum[ theVal ]);
325 Class : SMESHGUI_FilterTable::Table
326 Description : Table used by this widget
329 class SMESHGUI_FilterTable::Table : public QTable
332 Table(QWidget* parent);
333 Table(int numRows, int numCols, QWidget* parent = 0);
336 void SetEditable(const bool state, const int row, const int col);
337 bool IsEditable(const int row, const int col) const;
339 virtual void insertRows(int row, int count = 1);
340 virtual QString text(int row, int col) const;
343 //=======================================================================
344 // name : SMESHGUI_FilterTable::Table::Table
345 // Purpose : Constructor
346 //=======================================================================
347 SMESHGUI_FilterTable::Table::Table (QWidget* parent)
348 : QTable(parent, "SMESHGUI_FilterTable::Table")
352 SMESHGUI_FilterTable::Table::Table (int numRows, int numCols, QWidget* parent)
353 : QTable(numRows, numCols, parent, "SMESHGUI_FilterTable::Table")
357 SMESHGUI_FilterTable::Table::~Table()
361 //=======================================================================
362 // name : SMESHGUI_FilterTable::Table::SetEditable
363 // Purpose : Set editable of specified cell
364 //=======================================================================
365 void SMESHGUI_FilterTable::Table::SetEditable (const bool isEditable,
366 const int row, const int col)
368 QTableItem* anItem = item(row, col);
373 setItem(row, col, new QTableItem(this, QTableItem::Never, ""));
375 setItem(row, col, new QTableItem(this, QTableItem::OnTyping, ""));
378 //=======================================================================
379 // name : SMESHGUI_FilterTable::Table::IsEditable
380 // Purpose : Verify wheter cell is editable
381 //=======================================================================
382 bool SMESHGUI_FilterTable::Table::IsEditable (const int row, const int col) const
384 QTableItem* anItem = item(row, col);
385 return anItem == 0 || anItem->editType() != QTableItem::Never;
388 //=======================================================================
389 // name : SMESHGUI_FilterTable::Table::insertRows
390 // Purpose : Insert rows (virtual redefined)
391 //=======================================================================
392 void SMESHGUI_FilterTable::Table::insertRows (int row, int count)
394 int anEditRow = currEditRow();
395 int anEditCol = currEditCol();
397 if (anEditRow >= 0 && anEditCol >= 0)
398 endEdit(anEditRow, anEditCol, true, false);
400 QTable::insertRows( row, count );
403 //=======================================================================
404 // name : SMESHGUI_FilterTable::Table::text
405 // Purpose : Get text from cell (virtual redefined)
406 //=======================================================================
407 QString SMESHGUI_FilterTable::Table::text (int row, int col) const
409 int anEditRow = currEditRow();
410 int anEditCol = currEditCol();
412 if (anEditRow >= 0 && anEditCol >= 0 && anEditRow == row && anEditCol == col)
413 ((Table*)this)->endEdit(row, col, true, false);
415 return QTable::text(row, col);
420 Class : SMESHGUI_FilterTable
421 Description : Frame containig
422 - Button group for switching entity type
423 - Table for displaying filter criterions
424 - Buttons for editing table and filter libraries
427 //=======================================================================
428 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
429 // Purpose : Constructor
430 //=======================================================================
431 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
436 mySMESHGUI( theModule )
442 //=======================================================================
443 // name : SMESHGUI_FilterTable::SMESHGUI_FilterTable
444 // Purpose : Constructor
445 //=======================================================================
446 SMESHGUI_FilterTable::SMESHGUI_FilterTable( SMESHGUI* theModule,
448 const QValueList<int>& types)
451 mySMESHGUI( theModule )
457 SMESHGUI_FilterTable::~SMESHGUI_FilterTable()
461 //=======================================================================
462 // name : SMESHGUI_FilterTable::Init
463 // Purpose : Create table corresponding to the specified type
464 //=======================================================================
465 void SMESHGUI_FilterTable::Init (const int type)
467 QValueList<int> aTypes;
472 //=======================================================================
473 // name : SMESHGUI_FilterTable::Init
474 // Purpose : Create table corresponding to the specified type
475 //=======================================================================
476 void SMESHGUI_FilterTable::Init (const QValueList<int>& theTypes)
478 if (theTypes.isEmpty())
481 // Create buttons if necessary
483 if (myTables.isEmpty())
485 int aType = theTypes.first();
487 // create main layout
488 QVBoxLayout* aMainLay = new QVBoxLayout(this);
489 QGroupBox* aMainGrp = new QGroupBox(1, Qt::Horizontal, this);
490 aMainGrp->setFrameStyle(QFrame::NoFrame);
491 aMainGrp->setInsideMargin(0);
492 aMainLay->addWidget(aMainGrp);
494 // create switch of entity types
495 myEntityTypeGrp = new QButtonGroup(1, Qt::Vertical, tr("ENTITY_TYPE"), aMainGrp);
496 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
497 QMap<int, QString>::const_iterator anIter;
498 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
500 QRadioButton* aBtn = new QRadioButton(anIter.data(), myEntityTypeGrp);
501 myEntityTypeGrp->insert(aBtn, anIter.key());
504 myTableGrp = new QGroupBox(1, Qt::Horizontal, tr("FILTER"), aMainGrp );
505 QFrame* aTableFrame = new QFrame(myTableGrp);
508 mySwitchTableGrp = new QGroupBox(1, Qt::Horizontal, aTableFrame);
509 mySwitchTableGrp->setFrameStyle(QFrame::NoFrame);
510 mySwitchTableGrp->setInsideMargin(0);
512 myTables[ aType ] = createTable(mySwitchTableGrp, aType);
515 myAddBtn = new QPushButton(tr("ADD"), aTableFrame);
516 myRemoveBtn = new QPushButton(tr("REMOVE"), aTableFrame);
517 myClearBtn = new QPushButton(tr("CLEAR"), aTableFrame);
518 myInsertBtn = new QPushButton(tr("INSERT"), aTableFrame);
519 myCopyFromBtn = new QPushButton(tr("COPY_FROM"), aTableFrame);
520 myAddToBtn = new QPushButton(tr("ADD_TO"), aTableFrame);
522 myAddBtn->setAutoDefault(false);
523 myRemoveBtn->setAutoDefault(false);
524 myClearBtn->setAutoDefault(false);
525 myInsertBtn->setAutoDefault(false);
526 myCopyFromBtn->setAutoDefault(false);
527 myAddToBtn->setAutoDefault(false);
529 myCopyFromBtn->hide();
533 QGridLayout* aLay = new QGridLayout(aTableFrame, 8, 2, 0, SPACING);
535 aLay->addMultiCellWidget(mySwitchTableGrp, 0, 6, 0, 0);
536 aLay->addWidget(myAddBtn, 0, 1);
537 aLay->addWidget(myInsertBtn, 1, 1);
538 aLay->addWidget(myRemoveBtn, 2, 1);
539 aLay->addWidget(myClearBtn, 3, 1);
540 aLay->addWidget(myCopyFromBtn, 5, 1);
541 aLay->addWidget(myAddToBtn, 6, 1);
542 aLay->addMultiCellWidget(createAdditionalFrame(aTableFrame), 7, 7, 0, 1 );
544 aLay->setColStretch(0, 1);
545 aLay->setColStretch(1, 0);
547 QSpacerItem* aVSpacer = new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding);
548 aLay->addItem(aVSpacer, 4, 1);
551 connect(myAddBtn, SIGNAL(clicked()), this, SLOT(onAddBtn()));
552 connect(myInsertBtn, SIGNAL(clicked()), this, SLOT(onInsertBtn()));
553 connect(myRemoveBtn, SIGNAL(clicked()), this, SLOT(onRemoveBtn()));
554 connect(myClearBtn, SIGNAL(clicked()), this, SLOT(onClearBtn()));
556 connect(myCopyFromBtn, SIGNAL(clicked()), this, SLOT(onCopyFromBtn()));
557 connect(myAddToBtn, SIGNAL(clicked()), this, SLOT(onAddToBtn()));
559 connect(myEntityTypeGrp, SIGNAL(clicked(int)), this, SLOT(onEntityType(int)));
564 // Hide buttons of entity types if necessary
565 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
566 QMap<int, QString>::const_iterator anIt;
567 for (anIt = aSupportedTypes.begin(); anIt != aSupportedTypes.end(); ++anIt)
569 QButton* aBtn = myEntityTypeGrp->find(anIt.key());
570 theTypes.contains(anIt.key()) ? aBtn->show() : aBtn->hide();
573 // select first button if there is no selected buttons or it is hidden
574 QButton* aBtn = myEntityTypeGrp->selected();
575 if ( aBtn == 0 || theTypes.find(myEntityTypeGrp->id(aBtn)) == theTypes.end())
576 myEntityTypeGrp->setButton(theTypes.first());
578 if (theTypes.count() == 1)
579 myEntityTypeGrp->hide();
581 myEntityTypeGrp->show();
583 myTableGrp->updateGeometry();
584 int aType = myEntityTypeGrp->id(myEntityTypeGrp->selected());
588 //=======================================================================
589 // name : SMESHGUI_FilterTable::GetTableGrp
590 // Purpose : Get group box containing table. May be used for adding new widgets in it
591 //=======================================================================
592 QWidget* SMESHGUI_FilterTable::createAdditionalFrame (QWidget* theParent)
594 QFrame* aFrame = new QFrame(theParent);
596 QFrame* aLine1 = new QFrame(aFrame);
597 QFrame* aLine2 = new QFrame(aFrame);
598 aLine1->setFrameStyle(QFrame::HLine | QFrame::Sunken);
599 aLine2->setFrameStyle(QFrame::HLine | QFrame::Sunken);
600 aLine1->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
601 aLine2->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
603 QLabel* aLabel = new QLabel(tr("ADDITIONAL_PARAMETERS"), aFrame);
605 myWgStack = new QWidgetStack(aFrame);
607 QGridLayout* aLay = new QGridLayout(aFrame, 2, 3, 0, SPACING);
608 aLay->addWidget(aLine1, 0, 0);
609 aLay->addWidget(aLabel, 0, 1);
610 aLay->addWidget(aLine2, 0, 2);
611 aLay->addMultiCellWidget(myWgStack, 1, 1, 0, 2);
616 //=======================================================================
617 // name : SMESHGUI_FilterTable::GetTableGrp
618 // Purpose : Get group box containing table. May be used for adding new widgets in it
619 //=======================================================================
620 QGroupBox* SMESHGUI_FilterTable::GetTableGrp()
625 //=======================================================================
626 // name : SMESHGUI_FilterTable::onEntityType
627 // Purpose : SLOT. Called when entity type changed.
628 // Display corresponding table
629 //=======================================================================
630 void SMESHGUI_FilterTable::onEntityType (int theType)
632 if (myEntityType == theType)
636 emit NeedValidation();
639 myEntityTypeGrp->setButton(myEntityType);
643 myEntityType = theType;
645 if (!myTables.contains(theType))
646 myTables[ theType ] = createTable(mySwitchTableGrp, theType);
648 TableMap::iterator anIter;
649 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
650 myEntityType == anIter.key() ? anIter.data()->show() : anIter.data()->hide();
653 qApp->processEvents();
654 myTables[ myEntityType ]->updateGeometry();
657 emit EntityTypeChanged(theType);
661 //=======================================================================
662 // name : SMESHGUI_FilterTable::IsValid
663 // Purpose : Verify validity of entered data
664 //=======================================================================
665 bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType) const
667 int aType = theEntityType == -1 ? GetType() : theEntityType;
669 Table* aTable = myTables[ aType ];
670 for (int i = 0, n = aTable->numRows(); i < n; i++)
672 int aCriterion = GetCriterionType(i, aType);
674 if (aCriterion == FT_RangeOfIds ||
675 aCriterion == FT_BelongToGeom ||
676 aCriterion == FT_BelongToPlane ||
677 aCriterion == FT_BelongToCylinder ||
678 aCriterion == FT_BelongToGenSurface ||
679 aCriterion == FT_LyingOnGeom) {
680 if (aTable->text(i, 2).isEmpty()) {
682 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
683 tr("ERROR"), QMessageBox::Ok);
688 aTable->blockSignals(true);
689 double aThreshold = (int)aTable->text(i, 2).toDouble(&aRes);
690 aTable->blockSignals(false);
692 if (!aRes && aTable->IsEditable(i, 2)) {
694 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
695 tr("ERROR"), QMessageBox::Ok);
698 else if (aType == SMESH::EDGE &&
699 GetCriterionType(i, aType) == SMESH::FT_MultiConnection &&
703 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
704 tr("MULTIEDGES_ERROR"), QMessageBox::Ok);
709 QTableItem* anItem = aTable->item(i, 0);
710 if (myAddWidgets.contains(anItem) && !myAddWidgets[ anItem ]->IsValid())
717 //=======================================================================
718 // name : SMESHGUI_FilterTable::SetValidity
719 // Purpose : Set validity of the table
720 //=======================================================================
721 void SMESHGUI_FilterTable::SetValidity (const bool isValid)
726 //=======================================================================
727 // name : SMESHGUI_FilterTable::GetType
728 // Purpose : Get current entity type
729 //=======================================================================
730 int SMESHGUI_FilterTable::GetType() const
735 //=======================================================================
736 // name : SMESHGUI_FilterTable::SetType
737 // Purpose : Set current entity type
738 //=======================================================================
739 void SMESHGUI_FilterTable::SetType (const int type)
741 myEntityTypeGrp->setButton(type);
745 //=======================================================================
746 // name : SMESHGUI_FilterTable::RestorePreviousEntityType
747 // Purpose : Restore previous entity type
748 //=======================================================================
749 void SMESHGUI_FilterTable::RestorePreviousEntityType()
751 SetType(myEntityType);
754 //=======================================================================
755 // name : SMESHGUI_FilterTable::GetCriterionType
756 // Purpose : Get type of criterion from specified row (corresponding enums in h-file)
757 //=======================================================================
758 int SMESHGUI_FilterTable::GetCriterionType (const int theRow, const int theType) const
760 int aType = theType == -1 ? GetType() : theType;
761 Table* aTable = myTables[ aType ];
762 ComboItem* anItem = (ComboItem*)aTable->item(theRow, 0);
763 return anItem != 0 ? anItem->GetValue() : FT_Undefined;
766 //=======================================================================
767 // name : SMESHGUI_FilterTable::GetCriterion
768 // Purpose : Get parameters of criterion from specified row
769 //=======================================================================
770 void SMESHGUI_FilterTable::GetCriterion (const int theRow,
771 SMESH::Filter::Criterion& theCriterion,
772 const int theEntityType) const
774 int aType = theEntityType == -1 ? GetType() : theEntityType;
775 Table* aTable = myTables[ aType ];
777 theCriterion.Type = ((ComboItem*)aTable->item(theRow, 0))->GetValue();
778 theCriterion.UnaryOp = ((QCheckTableItem*)aTable->item(theRow, 3))->isChecked() ? FT_LogicalNOT : FT_Undefined;
779 theCriterion.BinaryOp = theRow != aTable->numRows() - 1 ?
780 ((ComboItem*)aTable->item(theRow, 4))->GetValue() : FT_Undefined;
781 theCriterion.TypeOfElement = (ElementType)aType;
783 int aCriterionType = GetCriterionType(theRow, aType);
785 if (aCriterionType != FT_RangeOfIds &&
786 aCriterionType != FT_BelongToGeom &&
787 aCriterionType != FT_BelongToPlane &&
788 aCriterionType != FT_BelongToCylinder &&
789 aCriterionType != FT_BelongToGenSurface &&
790 aCriterionType != FT_LyingOnGeom)
792 theCriterion.Compare = ((ComboItem*)aTable->item(theRow, 1))->GetValue();
793 theCriterion.Threshold = aTable->item(theRow, 2)->text().toDouble();
797 theCriterion.ThresholdStr = aTable->text(theRow, 2).latin1();
798 if ( aCriterionType != FT_RangeOfIds )
799 theCriterion.ThresholdID = aTable->text( theRow, 5 ).latin1();
802 QTableItem* anItem = aTable->item(theRow, 0);
803 if (myAddWidgets.contains(anItem))
804 theCriterion.Tolerance = myAddWidgets[ anItem ]->GetDouble(AdditionalWidget::Tolerance);
807 //=======================================================================
808 // name : SMESHGUI_FilterTable::SetCriterion
809 // Purpose : Set parameters of criterion of specified row
810 //=======================================================================
811 void SMESHGUI_FilterTable::SetCriterion (const int theRow,
812 const SMESH::Filter::Criterion& theCriterion,
813 const int theEntityType)
815 int aType = theEntityType == -1 ? GetType() : theEntityType;
817 Table* aTable = myTables[ aType ];
819 if (theRow > aTable->numRows() - 1)
822 ((ComboItem*)aTable->item(theRow, 0))->SetValue(theCriterion.Type);
823 onCriterionChanged(theRow, 0, aType);
824 ((ComboItem*)aTable->item(theRow, 1))->SetValue(theCriterion.Compare);
825 ((QCheckTableItem*)aTable->item(theRow, 3))->setChecked(theCriterion.UnaryOp == FT_LogicalNOT);
827 if (theCriterion.BinaryOp != FT_Undefined)
829 if (!aTable->IsEditable(theRow, 4))
830 aTable->setItem(theRow, 4, getBinaryItem(aTable));
831 ((ComboItem*)aTable->item(theRow, 4))->SetValue(theCriterion.BinaryOp);
834 aTable->SetEditable(false, theRow, 4);
836 if (theCriterion.Type != FT_RangeOfIds &&
837 theCriterion.Type != FT_BelongToGeom &&
838 theCriterion.Type != FT_BelongToPlane &&
839 theCriterion.Type != FT_BelongToCylinder &&
840 theCriterion.Type != FT_BelongToGenSurface &&
841 theCriterion.Type != FT_LyingOnGeom &&
842 theCriterion.Type != FT_FreeBorders &&
843 theCriterion.Type != FT_FreeEdges &&
844 theCriterion.Type != FT_BadOrientedVolume)
845 aTable->setText(theRow, 2, QString("%1").arg(theCriterion.Threshold, 0, 'g', 15));
848 aTable->setText(theRow, 2, QString(theCriterion.ThresholdStr));
849 if ( theCriterion.Type != FT_RangeOfIds )
850 aTable->setText( theRow, 5, QString( theCriterion.ThresholdID ) );
853 if (theCriterion.Compare == FT_EqualTo ||
854 theCriterion.Type == FT_BelongToPlane ||
855 theCriterion.Type == FT_BelongToCylinder ||
856 theCriterion.Type == FT_BelongToGenSurface ||
857 theCriterion.Type == FT_BelongToGeom ||
858 theCriterion.Type == FT_LyingOnGeom)
860 QTableItem* anItem = aTable->item(theRow, 0);
861 if (!myAddWidgets.contains(anItem))
863 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
864 myWgStack->addWidget(myAddWidgets[ anItem ]);
866 myAddWidgets[ anItem ]->SetDouble(AdditionalWidget::Tolerance, theCriterion.Tolerance);
869 emit CriterionChanged(theRow, aType);
873 //=======================================================================
874 // name : SMESHGUI_FilterTable::Update
875 // Purpose : Update table
876 //=======================================================================
877 void SMESHGUI_FilterTable::Update()
879 Table* aTable = myTables[ GetType() ];
880 int aCurrRow = aTable->currentRow();
881 int numRows = aTable->numRows();
882 if ((aCurrRow < 0 || aCurrRow >= numRows) && numRows > 0)
883 aTable->setCurrentCell(0, 0);
884 updateAdditionalWidget();
887 //=======================================================================
888 // name : SMESHGUI_FilterTable::AddCriterion
889 // Purpose : Add criterion with parameters
890 //=======================================================================
891 void SMESHGUI_FilterTable::AddCriterion (const SMESH::Filter::Criterion& theCriterion,
892 const int theEntityType)
894 int aType = theEntityType == -1 ? GetType() : theEntityType;
895 Table* aTable = myTables[ aType ];
896 addRow(aTable, aType);
897 SetCriterion(aTable->numRows() - 1, theCriterion);
900 //=======================================================================
901 // name : SMESHGUI_FilterTable::NumRows
902 // Purpose : Get number of criterions of current type
903 //=======================================================================
904 int SMESHGUI_FilterTable::NumRows (const int theEntityType) const
906 return myTables[ theEntityType == -1 ? GetType() : theEntityType ]->numRows();
909 //=======================================================================
910 // name : SMESHGUI_FilterTable::Clear
911 // Purpose : Clear current table
912 //=======================================================================
913 void SMESHGUI_FilterTable::Clear (const int theType)
915 int aType = theType == -1 ? GetType() : theType;
916 QTable* aTable = myTables[ aType ];
918 if (aTable->numRows() == 0)
921 while (aTable->numRows() > 0)
923 removeAdditionalWidget(aTable, 0);
924 aTable->removeRow(0);
930 //=======================================================================
931 // name : SMESHGUI_FilterTable::onAddBtn
932 // Purpose : SLOT. Called then "Add" button pressed.
933 // Adds new string to table
934 //=======================================================================
935 void SMESHGUI_FilterTable::onAddBtn()
937 int aType = GetType();
938 addRow(myTables[ aType ], aType);
943 //=======================================================================
944 // name : SMESHGUI_FilterTable::onInsertBtn
945 // Purpose : SLOT. Called then "Insert" button pressed.
946 // Inserts new string before current one
947 //=======================================================================
948 void SMESHGUI_FilterTable::onInsertBtn()
950 addRow(myTables[ GetType() ], GetType(), false);
953 //=======================================================================
954 // name : SMESHGUI_FilterTable::onRemoveBtn
955 // Purpose : SLOT. Called then "Remove" button pressed.
956 // Removes current string from table
957 //=======================================================================
958 void SMESHGUI_FilterTable::onRemoveBtn()
960 Table* aTable = myTables[ GetType() ];
962 if (aTable->numRows() == 0)
965 QMemArray<int> aRows;
966 for (int i = 0, n = aTable->numRows(); i < n; i++)
968 if (aTable->isRowSelected(i))
970 aRows.resize(aRows.size() + 1);
971 aRows[ (int)(aRows.size() - 1) ] = i;
972 removeAdditionalWidget(aTable, i);
976 aTable->removeRows(aRows);
978 // remove control of binary logical operation from last row
979 if (aTable->numRows() > 0)
980 aTable->SetEditable(false, aTable->numRows() - 1, 4);
985 //=======================================================================
986 // name : SMESHGUI_FilterTable::updateAdditionalWidget
987 // Purpose : Enable/Disable widget with additonal parameters
988 //=======================================================================
989 void SMESHGUI_FilterTable::updateAdditionalWidget()
991 Table* aTable = myTables[ GetType() ];
992 int aRow = aTable->currentRow();
993 if (aRow < 0 || aRow >= aTable->numRows())
995 myWgStack->setEnabled(false);
999 ComboItem* anItem = ((ComboItem*)aTable->item(aRow, 0));
1000 bool toEnable = ((ComboItem*)aTable->item(aRow, 1))->GetValue() == FT_EqualTo &&
1001 GetCriterionType(aRow) != FT_RangeOfIds &&
1002 GetCriterionType(aRow) != FT_FreeEdges &&
1003 GetCriterionType(aRow) != FT_BadOrientedVolume;
1004 if (!myAddWidgets.contains(anItem))
1006 myAddWidgets[ anItem ] = new AdditionalWidget(myWgStack);
1007 myWgStack->addWidget(myAddWidgets[ anItem ]);
1010 myWgStack->raiseWidget(myWgStack->id(myAddWidgets[ anItem ]));
1011 myWgStack->setEnabled(toEnable);
1014 //=======================================================================
1015 // name : SMESHGUI_FilterTable::removeAdditionalWidget
1016 // Purpose : Remove widgets containing additional parameters from widget
1017 // stack and internal map
1018 //=======================================================================
1019 void SMESHGUI_FilterTable::removeAdditionalWidget (QTable* theTable, const int theRow)
1021 QTableItem* anItem = theTable->item(theRow, 0);
1022 if (myAddWidgets.contains(anItem))
1024 myWgStack->removeWidget(myAddWidgets[ anItem ]);
1025 myAddWidgets[ anItem ]->reparent(0, QPoint());
1026 delete myAddWidgets[ anItem ];
1027 myAddWidgets.remove(anItem);
1031 //=======================================================================
1032 // name : SMESHGUI_FilterTable::onClearBtn
1033 // Purpose : SLOT. Called then "Clear" button pressed.
1034 // Removes all strings from table
1035 //=======================================================================
1036 void SMESHGUI_FilterTable::onClearBtn()
1038 QTable* aTable = myTables[ GetType() ];
1040 if (aTable->numRows() == 0)
1043 while (aTable->numRows() > 0)
1045 removeAdditionalWidget(aTable, 0);
1046 aTable->removeRow(0);
1052 //=======================================================================
1053 // name : SMESHGUI_FilterTable::onCurrentChanged()
1054 // Purpose : SLOT. Called when current cell changed
1055 //=======================================================================
1056 void SMESHGUI_FilterTable::onCurrentChanged (int theRow, int theCol)
1059 updateAdditionalWidget();
1060 emit CurrentChanged(theRow, theCol);
1063 //=======================================================================
1064 // name : SMESHGUI_FilterTable::onCriterionChanged()
1065 // Purpose : Provides reaction on change of criterion
1066 //=======================================================================
1067 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
1069 int aType = entityType == -1 ? GetType() : entityType;
1070 Table* aTable = myTables[ aType ];
1071 ComboItem* aCompareItem = (ComboItem*)aTable->item(row, 1);
1073 int aCriterionType = GetCriterionType(row);
1075 if (aType == SMESH::EDGE && aCriterionType == SMESH::FT_FreeBorders ||
1076 aType == SMESH::FACE && aCriterionType == SMESH::FT_FreeEdges ||
1077 aType == SMESH::VOLUME && aCriterionType == SMESH::FT_BadOrientedVolume)
1079 if (aCompareItem->count() > 0)
1080 aCompareItem->setStringList(QStringList());
1081 aTable->SetEditable(false, row, 2);
1083 else if (aCriterionType == SMESH::FT_RangeOfIds ||
1084 aCriterionType == SMESH::FT_BelongToGeom ||
1085 aCriterionType == SMESH::FT_BelongToPlane ||
1086 aCriterionType == SMESH::FT_BelongToCylinder ||
1087 aCriterionType == SMESH::FT_BelongToGenSurface ||
1088 aCriterionType == SMESH::FT_LyingOnGeom)
1090 QMap<int, QString> aMap;
1091 aMap[ FT_EqualTo ] = tr("EQUAL_TO");
1092 aCompareItem->setStringList(aMap);
1093 if (!aTable->IsEditable(row, 2))
1094 aTable->SetEditable(true, row, 2);
1098 if (aCompareItem->count() != 3)
1100 aCompareItem->setStringList(QStringList());
1101 aCompareItem->setStringList(getCompare());
1104 QString aText = aTable->text(row, 2);
1106 aText.toDouble(&isOk);
1107 aTable->setText(row, 2, isOk ? aText : QString(""));
1108 if (!aTable->IsEditable(row, 2))
1109 aTable->SetEditable(true, row, 2);
1112 updateAdditionalWidget();
1114 emit CriterionChanged(row, entityType);
1117 //=======================================================================
1118 // name : SMESHGUI_FilterTable::onCriterionChanged()
1119 // Purpose : SLOT. Called then contents of table changed
1120 // Provides reaction on change of criterion
1121 //=======================================================================
1122 void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
1124 onCriterionChanged(row, col, -1);
1127 //=======================================================================
1128 // name : SMESHGUI_FilterTable::getFirstSelectedRow
1129 // Purpose : Get first selected row
1130 //=======================================================================
1131 int SMESHGUI_FilterTable::getFirstSelectedRow() const
1133 QTable* aTable = myTables[ GetType() ];
1134 for (int i = 0, n = aTable->numRows(); i < n; i++)
1135 if (aTable->isRowSelected(i))
1138 int aRow = aTable->currentRow();
1139 return aRow >= 0 && aRow < aTable->numRows() ? aRow : -1;
1142 //=======================================================================
1143 // name : SMESHGUI_FilterTable::addRow
1144 // Purpose : Add row at the end of table
1145 //=======================================================================
1146 void SMESHGUI_FilterTable::addRow (Table* theTable, const int theType, const bool toTheEnd)
1149 int aSelectedRow = getFirstSelectedRow();
1150 int aCurrCol = theTable->currentColumn();
1153 if (toTheEnd || aSelectedRow == -1)
1155 theTable->insertRows(theTable->numRows());
1156 aCurrRow = theTable->numRows() - 1;
1160 theTable->insertRows(aSelectedRow);
1161 aCurrRow = aSelectedRow;
1166 theTable->setItem(aCurrRow, 0, getCriterionItem(theTable, theType));
1169 theTable->setItem(aCurrRow, 1, getCompareItem(theTable));
1172 //theTable->setItem(aCurrRow, 2, new QTableItem(theTable));
1174 //Logical operation NOT
1175 theTable->setItem(aCurrRow, 3, getUnaryItem(theTable));
1177 // Logical binary operation for previous value
1178 int anAddBinOpStr = -1;
1179 if (aCurrRow == theTable->numRows() - 1)
1180 anAddBinOpStr = aCurrRow - 1;
1181 else if (aCurrRow >= 0 )
1182 anAddBinOpStr = aCurrRow;
1184 if (theTable->item(aCurrRow, 4) == 0 ||
1185 theTable->item(aCurrRow, 4)->rtti() != 1)
1189 if (anAddBinOpStr >= 0 &&
1190 (theTable->item(anAddBinOpStr, 4) == 0 ||
1191 theTable->item(anAddBinOpStr, 4)->rtti() != 1))
1192 theTable->setItem(anAddBinOpStr, 4, getBinaryItem(theTable));
1195 theTable->SetEditable(false, theTable->numRows() - 1, 4);
1197 if (aCurrRow >=0 && aCurrRow < theTable->numRows() &&
1198 aCurrCol >=0 && aCurrCol < theTable->numRows())
1199 theTable->setCurrentCell(aCurrRow, aCurrCol);
1201 onCriterionChanged(aCurrRow, 0);
1206 //=======================================================================
1207 // name : SMESHGUI_FilterTable::getCriterionItem
1208 // Purpose : Get combo table item for criteria of specified type
1209 //=======================================================================
1210 QTableItem* SMESHGUI_FilterTable::getCriterionItem (QTable* theParent , const int theType)
1212 return new ComboItem(theParent, getCriteria(theType));
1215 //=======================================================================
1216 // name : SMESHGUI_FilterTable::getCompareItem
1217 // Purpose : Get combo table item for operation of comparision
1218 //=======================================================================
1219 QTableItem* SMESHGUI_FilterTable::getCompareItem (QTable* theParent)
1221 return new ComboItem(theParent, getCompare());
1224 //=======================================================================
1225 // name : SMESHGUI_FilterTable::getBinaryItem
1227 //=======================================================================
1228 QTableItem* SMESHGUI_FilterTable::getBinaryItem (QTable* theParent)
1230 static QMap<int, QString> aMap;
1233 aMap[ SMESH::FT_LogicalAND ] = tr("AND");
1234 aMap[ SMESH::FT_LogicalOR ] = tr("OR");
1237 return new ComboItem(theParent, aMap);
1240 //=======================================================================
1241 // name : SMESHGUI_FilterTable::getUnaryItem
1242 // Purpose : Get check table item
1243 //=======================================================================
1244 QTableItem* SMESHGUI_FilterTable::getUnaryItem (QTable* theParent)
1246 return new QCheckTableItem(theParent, tr("NOT"));
1249 //=======================================================================
1250 // name : SMESHGUI_FilterTable::getSupportedTypes
1251 // Purpose : Get all supported type
1252 //=======================================================================
1253 const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
1255 static QMap<int, QString> aTypes;
1256 if (aTypes.isEmpty())
1258 aTypes[ SMESH::NODE ] = tr("NODES");
1259 aTypes[ SMESH::EDGE ] = tr("EDGES");
1260 aTypes[ SMESH::FACE ] = tr("FACES");
1261 aTypes[ SMESH::VOLUME ] = tr("VOLUMES");
1267 //=======================================================================
1268 // name : SMESHGUI_FilterTable::getCriteria
1269 // Purpose : Get criteria for specified type
1270 //=======================================================================
1271 const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType) const
1273 if (theType == SMESH::NODE)
1275 static QMap<int, QString> aCriteria;
1276 if (aCriteria.isEmpty())
1278 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1279 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1280 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1281 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1282 aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
1283 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1287 else if (theType == SMESH::EDGE)
1289 static QMap<int, QString> aCriteria;
1290 if (aCriteria.isEmpty())
1292 aCriteria[ SMESH::FT_FreeBorders ] = tr("FREE_BORDERS");
1293 aCriteria[ SMESH::FT_MultiConnection ] = tr("MULTI_BORDERS");
1294 aCriteria[ SMESH::FT_Length ] = tr("LENGTH");
1295 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1296 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1297 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1298 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1299 aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
1300 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1304 else if (theType == SMESH::FACE)
1306 static QMap<int, QString> aCriteria;
1307 if (aCriteria.isEmpty())
1309 aCriteria[ SMESH::FT_AspectRatio ] = tr("ASPECT_RATIO");
1310 aCriteria[ SMESH::FT_Warping ] = tr("WARPING");
1311 aCriteria[ SMESH::FT_MinimumAngle ] = tr("MINIMUM_ANGLE");
1312 aCriteria[ SMESH::FT_Taper ] = tr("TAPER");
1313 aCriteria[ SMESH::FT_Skew ] = tr("SKEW");
1314 aCriteria[ SMESH::FT_Area ] = tr("AREA");
1315 aCriteria[ SMESH::FT_FreeEdges ] = tr("FREE_EDGES");
1316 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1317 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1318 aCriteria[ SMESH::FT_BelongToPlane ] = tr("BELONG_TO_PLANE");
1319 aCriteria[ SMESH::FT_BelongToCylinder ] = tr("BELONG_TO_CYLINDER");
1320 aCriteria[ SMESH::FT_BelongToGenSurface]= tr("BELONG_TO_GENSURFACE");
1321 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1322 aCriteria[ SMESH::FT_Length2D ] = tr("LENGTH2D");
1323 aCriteria[ SMESH::FT_MultiConnection2D] = tr("MULTI2D_BORDERS");
1327 else if (theType == SMESH::VOLUME)
1329 static QMap<int, QString> aCriteria;
1330 if (aCriteria.isEmpty())
1332 aCriteria[ SMESH::FT_AspectRatio3D] = tr("ASPECT_RATIO_3D");
1333 aCriteria[ SMESH::FT_RangeOfIds ] = tr("RANGE_OF_IDS");
1334 aCriteria[ SMESH::FT_BelongToGeom ] = tr("BELONG_TO_GEOM");
1335 aCriteria[ SMESH::FT_LyingOnGeom ] = tr("LYING_ON_GEOM");
1336 aCriteria[ SMESH::FT_BadOrientedVolume ] = tr("BAD_ORIENTED_VOLUME");
1337 aCriteria[ SMESH::FT_Volume3D ] = tr("VOLUME_3D");
1343 static QMap<int, QString> aCriteria;
1349 //=======================================================================
1350 // name : SMESHGUI_FilterTable::getCompare
1351 // Purpose : Get operation of comparison
1352 //=======================================================================
1353 const QMap<int, QString>& SMESHGUI_FilterTable::getCompare() const
1355 static QMap<int, QString> aMap;
1359 aMap[ SMESH::FT_LessThan ] = tr("LESS_THAN");
1360 aMap[ SMESH::FT_MoreThan ] = tr("MORE_THAN");
1361 aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO" );
1367 //=======================================================================
1368 // name : SMESHGUI_FilterTable::createTable
1369 // Purpose : Create table
1370 //=======================================================================
1371 SMESHGUI_FilterTable::Table* SMESHGUI_FilterTable::createTable (QWidget* theParent,
1375 Table* aTable= new Table(0, 6, theParent);
1377 QHeader* aHeaders = aTable->horizontalHeader();
1379 QFontMetrics aMetrics(aHeaders->font());
1381 // append spaces to the header of criteria in order to
1382 // provide visibility of criterion inside comboboxes
1383 static int aMaxLenCr = 0;
1387 const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
1388 QMap<int, QString>::const_iterator anIter;
1389 for (anIter = aSupportedTypes.begin(); anIter != aSupportedTypes.end(); ++anIter)
1390 aMaxLenCr = Max(maxLength(getCriteria(anIter.key()), aMetrics), aMaxLenCr);
1393 static int aLenCr = abs( aMaxLenCr -
1394 aMetrics.width(tr("CRITERION"))) / aMetrics.width(' ') + 5;
1397 aCrStr.fill(' ', aLenCr);
1399 aCoStr.fill(' ', 10);
1401 aHeaders->setLabel(0, tr("CRITERION") + aCrStr);
1402 aHeaders->setLabel(1, tr("COMPARE") + aCoStr);
1403 aHeaders->setLabel(2, tr("THRESHOLD_VALUE"));
1404 aHeaders->setLabel(3, tr("UNARY"));
1405 aHeaders->setLabel(4, tr("BINARY") + " ");
1406 aHeaders->setLabel( 5, tr( "ID" ) );
1408 // set geometry of the table
1409 for (int i = 0; i <= 4; i++)
1410 aTable->adjustColumn(i);
1412 // set the ID column invisible
1413 aTable->hideColumn( 5 );
1415 aTable->updateGeometry();
1416 QSize aSize = aTable->sizeHint();
1417 int aWidth = aSize.width();
1418 aTable->setMinimumSize(QSize(aWidth, aWidth / 2));
1419 aTable->setSizePolicy(QSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::MinimumExpanding));
1421 connect(aTable, SIGNAL(valueChanged(int, int)),
1422 this, SLOT(onCriterionChanged(int, int)));
1424 connect(aTable, SIGNAL(currentChanged(int, int)),
1425 this, SLOT(onCurrentChanged(int, int)));
1430 //=======================================================================
1431 // name : SMESHGUI_FilterTable::updateBtnState
1432 // Purpose : Update button state
1433 //=======================================================================
1434 void SMESHGUI_FilterTable::updateBtnState()
1436 myRemoveBtn->setEnabled(myTables[ GetType() ]->numRows() > 0);
1437 myClearBtn->setEnabled(myTables[ GetType() ]->numRows() > 0);
1440 //=======================================================================
1441 // name : SMESHGUI_FilterTable::SetEditable
1442 // Purpose : Set read only flag for tables. Show/hide buttons for work with rows
1443 //=======================================================================
1444 void SMESHGUI_FilterTable::SetEditable (const bool isEditable)
1446 TableMap::iterator anIter;
1447 for (anIter = myTables.begin(); anIter != myTables.end(); ++anIter)
1449 anIter.data()->setReadOnly(!isEditable);
1454 myInsertBtn->show();
1455 myRemoveBtn->show();
1461 myInsertBtn->hide();
1462 myRemoveBtn->hide();
1467 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1468 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1469 anIter2.data()->SetEditable(isEditable);
1472 //=======================================================================
1473 // name : SMESHGUI_FilterTable::SetEnabled
1474 // Purpose : Enable/Disable table. Switching type of elements already enabled
1475 //=======================================================================
1476 void SMESHGUI_FilterTable::SetEnabled (const bool isEnabled)
1478 myAddBtn->setEnabled(isEnabled);
1479 myInsertBtn->setEnabled(isEnabled);
1480 myRemoveBtn->setEnabled(isEnabled);
1481 myClearBtn->setEnabled(isEnabled);
1486 QMap<QTableItem*, AdditionalWidget*>::iterator anIter2;
1487 for (anIter2 = myAddWidgets.begin(); anIter2 != myAddWidgets.end(); ++anIter2)
1488 anIter2.data()->setEnabled(isEnabled);
1491 //=======================================================================
1492 // name : SMESHGUI_FilterTable::IsEditable
1493 // Purpose : Verify whether table is editable
1494 //=======================================================================
1495 bool SMESHGUI_FilterTable::IsEditable() const
1497 return !myTables[ GetType() ]->isReadOnly();
1500 //=======================================================================
1501 // name : SMESHGUI_FilterTable::SetLibsEnabled
1502 // Purpose : Show/hide buttons for work with libraries
1503 //=======================================================================
1504 void SMESHGUI_FilterTable::SetLibsEnabled (const bool isEnabled)
1508 myCopyFromBtn->show();
1513 myCopyFromBtn->hide();
1518 //=======================================================================
1519 // name : SMESHGUI_FilterTable::onCopyFromBtn
1520 // Purpose : SLOT. Called the "Copy from ..." button clicked
1521 // Display filter library dialog
1522 //=======================================================================
1523 void SMESHGUI_FilterTable::onCopyFromBtn()
1526 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1527 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1529 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::COPY_FROM);
1531 if (myLibDlg->exec() == QDialog::Accepted)
1533 Copy(myLibDlg->GetTable());
1538 //=======================================================================
1539 // name : SMESHGUI_FilterTable::onAddToBtn
1540 // Purpose : SLOT. Called the "Add to ..." button clicked
1541 // Display filter library dialog
1542 //=======================================================================
1543 void SMESHGUI_FilterTable::onAddToBtn()
1548 myLibDlg = new SMESHGUI_FilterLibraryDlg(
1549 mySMESHGUI, this, GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1551 myLibDlg->Init(GetType(), SMESHGUI_FilterLibraryDlg::ADD_TO);
1553 myLibDlg->SetTable(this);
1558 //=======================================================================
1559 // name : SMESHGUI_FilterTable::Copy
1560 // Purpose : Initialise table with values of other table
1561 //=======================================================================
1562 void SMESHGUI_FilterTable::Copy (const SMESHGUI_FilterTable* theTable)
1566 for (int i = 0, n = theTable->NumRows(); i < n; i++)
1568 SMESH::Filter::Criterion aCriterion = SMESHGUI_FilterDlg::createCriterion();
1569 theTable->GetCriterion(i, aCriterion);
1570 AddCriterion(aCriterion);
1574 //=======================================================================
1575 // name : SMESHGUI_FilterTable::CurrentCell
1576 // Purpose : Returns current cell
1577 //=======================================================================
1578 bool SMESHGUI_FilterTable::CurrentCell (int& theRow, int& theCol) const
1580 theRow = myTables[ GetType() ]->currentRow();
1581 theCol = myTables[ GetType() ]->currentColumn();
1582 return theRow >= 0 && theCol >= 0;
1585 //=======================================================================
1586 // name : SMESHGUI_FilterTable::SetText
1587 // Purpose : Set text and internal value in cell of threshold value
1588 //=======================================================================
1589 void SMESHGUI_FilterTable::SetThreshold (const int theRow,
1590 const QString& theText,
1591 const int theEntityType)
1593 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1594 aTable->setText(theRow, 2, theText);
1597 //=======================================================================
1598 // name : SMESHGUI_FilterTable::SetText
1599 // Purpose : Get text and internal value from cell of threshold value
1600 //=======================================================================
1601 bool SMESHGUI_FilterTable::GetThreshold (const int theRow,
1603 const int theEntityType)
1605 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1606 QTableItem* anItem = aTable->item(theRow, 2);
1609 theText = anItem->text();
1616 //=======================================================================
1617 // name : SMESHGUI_FilterTable::SetID
1618 // Purpose : Set text and internal value in cell of ID value
1619 //=======================================================================
1620 void SMESHGUI_FilterTable::SetID( const int theRow,
1621 const QString& theText,
1622 const int theEntityType )
1624 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1625 aTable->setText( theRow, 5, theText );
1628 //=======================================================================
1629 // name : SMESHGUI_FilterTable::GetID
1630 // Purpose : Get text and internal value from cell of ID value
1631 //=======================================================================
1632 bool SMESHGUI_FilterTable::GetID( const int theRow,
1634 const int theEntityType )
1636 Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
1637 QTableItem* anItem = aTable->item( theRow, 5 );
1640 theText = anItem->text();
1648 Class : SMESHGUI_FilterDlg
1649 Description : Dialog to specify filters for VTK viewer
1653 //=======================================================================
1654 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1655 // Purpose : Constructor
1656 //=======================================================================
1657 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1658 const QValueList<int>& theTypes,
1659 const char* theName)
1660 : QDialog( SMESH::GetDesktop( theModule ), theName, false,
1661 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
1662 mySMESHGUI( theModule ),
1663 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
1665 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1666 mySelector = aViewWindow->GetSelector();
1668 construct(theTypes);
1671 //=======================================================================
1672 // name : SMESHGUI_FilterDlg::SMESHGUI_FilterDlg
1673 // Purpose : Constructor
1674 //=======================================================================
1675 SMESHGUI_FilterDlg::SMESHGUI_FilterDlg( SMESHGUI* theModule,
1677 const char* theName)
1678 : QDialog( SMESH::GetDesktop( theModule ), theName, false,
1679 WStyle_Customize | WStyle_NormalBorder | WStyle_Title | WStyle_SysMenu),
1680 mySMESHGUI( theModule ),
1681 mySelectionMgr( SMESH::GetSelectionMgr( theModule ) )
1683 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1684 mySelector = aViewWindow->GetSelector();
1685 QValueList<int> aTypes;
1686 aTypes.append(theType);
1690 //=======================================================================
1691 // name : SMESHGUI_FilterDlg::construct
1692 // Purpose : Construct dialog (called by constructor)
1693 //=======================================================================
1694 void SMESHGUI_FilterDlg::construct (const QValueList<int>& theTypes)
1698 setCaption(tr("CAPTION"));
1700 QVBoxLayout* aDlgLay = new QVBoxLayout (this, MARGIN, SPACING);
1702 myMainFrame = createMainFrame (this);
1703 QFrame* aBtnFrame = createButtonFrame(this);
1705 aDlgLay->addWidget(myMainFrame);
1706 aDlgLay->addWidget(aBtnFrame);
1708 aDlgLay->setStretchFactor(myMainFrame, 1);
1710 myHelpFileName = "selection_filter_library_page.html";
1715 //=======================================================================
1716 // name : SMESHGUI_FilterDlg::createMainFrame
1717 // Purpose : Create frame containing dialog's input fields
1718 //=======================================================================
1719 QFrame* SMESHGUI_FilterDlg::createMainFrame (QWidget* theParent)
1721 QGroupBox* aMainFrame = new QGroupBox(1, Qt::Horizontal, theParent);
1722 aMainFrame->setFrameStyle(QFrame::NoFrame);
1723 aMainFrame->setInsideMargin(0);
1727 myTable = new SMESHGUI_FilterTable( mySMESHGUI, aMainFrame, myTypes );
1728 myTable->SetLibsEnabled(true);
1730 QFrame* aLine = new QFrame(myTable->GetTableGrp());
1731 aLine->setFrameStyle(QFrame::HLine | QFrame::Sunken);
1733 mySetInViewer = new QCheckBox(tr("SET_IN_VIEWER"), myTable->GetTableGrp());
1734 mySetInViewer->setChecked(true);
1737 mySourceGrp = createSourceGroup(aMainFrame);
1739 connect(myTable, SIGNAL(CriterionChanged(const int, const int)),
1740 SLOT(onCriterionChanged(const int, const int)));
1742 connect(myTable, SIGNAL(CurrentChanged(int, int)),
1743 SLOT(onCurrentChanged(int, int)));
1748 //=======================================================================
1749 // name : SMESHGUI_FilterDlg::createSourceFrame
1750 // Purpose : Create frame containing source radio button
1751 //=======================================================================
1752 QButtonGroup* SMESHGUI_FilterDlg::createSourceGroup (QWidget* theParent)
1754 QButtonGroup* aGrp = new QButtonGroup(1, Qt::Vertical, tr("SOURCE"), theParent);
1756 QRadioButton* aMeshBtn = new QRadioButton(tr("MESH"), aGrp);
1757 QRadioButton* aSelBtn = new QRadioButton(tr("SELECTION"), aGrp);
1758 QRadioButton* aGrpBtn = new QRadioButton(tr("CURRENT_GROUP"), aGrp);
1760 aGrp->insert(aMeshBtn, Mesh);
1761 aGrp->insert(aSelBtn, Selection);
1762 aGrp->insert(aGrpBtn, Dialog);
1764 aGrp->setButton(Selection);
1769 //=======================================================================
1770 // name : SMESHGUI_FilterDlg::updateMainButtons
1771 // Purpose : Update visibility of main buttons (OK, Cancel, Close ...)
1772 //=======================================================================
1773 void SMESHGUI_FilterDlg::updateMainButtons()
1775 if (myTypes.count() == 1)
1777 myButtons[ BTN_Cancel ]->show();
1778 myButtons[ BTN_Apply ]->hide();
1779 myButtons[ BTN_Close ]->hide();
1783 myButtons[ BTN_Cancel ]->hide();
1784 myButtons[ BTN_Apply ]->show();
1785 myButtons[ BTN_Close ]->show();
1788 // updateGeometry();
1791 //=======================================================================
1792 // name : SMESHGUI_FilterDlg::createButtonFrame
1793 // Purpose : Create frame containing buttons
1794 //=======================================================================
1795 QFrame* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
1797 QGroupBox* aGrp = new QGroupBox(1, Qt::Vertical, theParent);
1799 myButtons[ BTN_OK ] = new QPushButton(tr("SMESH_BUT_APPLY_AND_CLOSE"), aGrp);
1800 myButtons[ BTN_Apply ] = new QPushButton(tr("SMESH_BUT_APPLY"), aGrp);
1802 QLabel* aLbl = new QLabel(aGrp);
1803 aLbl->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
1805 myButtons[ BTN_Cancel ] = new QPushButton(tr("SMESH_BUT_CANCEL"), aGrp);
1806 myButtons[ BTN_Close ] = new QPushButton(tr("SMESH_BUT_CLOSE"), aGrp);
1807 myButtons[ BTN_Help ] = new QPushButton(tr("SMESH_BUT_HELP"), aGrp);
1809 connect(myButtons[ BTN_OK ], SIGNAL(clicked()), SLOT(onOk()));
1810 connect(myButtons[ BTN_Cancel ], SIGNAL(clicked()), SLOT(onClose()));
1811 connect(myButtons[ BTN_Close ], SIGNAL(clicked()), SLOT(onClose()));
1812 connect(myButtons[ BTN_Apply ], SIGNAL(clicked()), SLOT(onApply()));
1813 connect(myButtons[ BTN_Help ], SIGNAL(clicked()), SLOT(onHelp()));
1815 updateMainButtons();
1820 //=======================================================================
1821 // name : SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg
1822 // Purpose : Destructor
1823 //=======================================================================
1824 SMESHGUI_FilterDlg::~SMESHGUI_FilterDlg()
1828 //=======================================================================
1829 // name : SMESHGUI_FilterDlg::Init
1830 // Purpose : Init dialog fields, connect signals and slots, show dialog
1831 //=======================================================================
1832 void SMESHGUI_FilterDlg::Init (const int type)
1834 QValueList<int> aTypes;
1835 aTypes.append(type);
1839 //=======================================================================
1840 // name : SMESHGUI_FilterDlg::Init
1841 // Purpose : Init dialog fields, connect signals and slots, show dialog
1842 //=======================================================================
1843 void SMESHGUI_FilterDlg::Init (const QValueList<int>& theTypes)
1847 myMesh = SMESH::SMESH_Mesh::_nil();
1849 myIsSelectionChanged = false;
1851 myTable->Init(theTypes);
1854 if (theTypes.count() == 1)
1856 int aType = theTypes.first();
1857 if (aType == SMESH::NODE ) setCaption(tr("NODES_TLT"));
1858 else if (aType == SMESH::EDGE ) setCaption(tr("EDGES_TLT"));
1859 else if (aType == SMESH::FACE ) setCaption(tr("FACES_TLT"));
1860 else if (aType == SMESH::VOLUME) setCaption(tr("VOLUMES_TLT"));
1863 setCaption(tr("TLT"));
1865 qApp->processEvents();
1870 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1872 connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
1873 connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
1875 updateMainButtons();
1878 // Initialise filter table with values of previous filter
1879 QValueList<int>::const_iterator anIter;
1880 for (anIter = theTypes.begin(); anIter != theTypes.end(); ++anIter)
1882 myTable->Clear(*anIter);
1883 if (!myFilter[ *anIter ]->_is_nil())
1885 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
1886 if (myFilter[ *anIter ]->GetCriteria(aCriteria))
1888 for (int i = 0, n = aCriteria->length(); i < n; i++)
1889 myTable->AddCriterion(aCriteria[ i ], *anIter);
1894 if (myInsertState.contains(theTypes.first()))
1895 mySetInViewer->setChecked(myInsertState[ theTypes.first() ]);
1897 mySetInViewer->setChecked(true);
1898 if (myApplyToState.contains(theTypes.first()))
1899 mySourceGrp->setButton(myApplyToState[ theTypes.first() ]);
1901 mySourceGrp->setButton(Selection);
1904 //=======================================================================
1905 // name : SMESHGUI_FilterDlg::onOk
1906 // Purpose : SLOT called when "Ok" button pressed.
1907 // Assign filters VTK viewer and close dialog
1908 //=======================================================================
1909 void SMESHGUI_FilterDlg::onOk()
1913 mySelectionMgr->clearFilters();
1914 disconnect(mySMESHGUI, 0, this, 0);
1915 disconnect(mySelectionMgr, 0, this, 0);
1916 mySMESHGUI->ResetState();
1922 //=======================================================================
1923 // name : SMESHGUI_FilterDlg::onClose
1924 // Purpose : SLOT called when "Close" button pressed. Close dialog
1925 //=======================================================================
1926 void SMESHGUI_FilterDlg::onClose()
1928 // Restore previously selected object
1931 SALOME_ListIO aList;
1932 mySelectionMgr->clearFilters();
1933 mySelectionMgr->clearSelected();
1934 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter (myIObjects);
1935 for (; anIter.More(); anIter.Next())
1937 aList.Append(anIter.Key());
1939 TColStd_MapOfInteger aResMap;
1940 const TColStd_IndexedMapOfInteger& anIndMap = anIter.Value();
1941 for (int i = 1, n = anIndMap.Extent(); i <= n; i++)
1942 aResMap.Add(anIndMap(i));
1944 mySelector->AddOrRemoveIndex( anIter.Key(), aResMap, false);
1945 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
1946 aViewWindow->highlight( anIter.Key(), true, true );
1948 mySelectionMgr->setSelectedObjects(aList, false);
1951 disconnect(mySMESHGUI, 0, this, 0);
1952 disconnect(mySelectionMgr, 0, this, 0);
1953 mySMESHGUI->ResetState();
1958 //=================================================================================
1959 // function : onHelp()
1961 //=================================================================================
1962 void SMESHGUI_FilterDlg::onHelp()
1964 LightApp_Application* app = (LightApp_Application*)(SUIT_Session::session()->activeApplication());
1966 app->onHelpContextModule(mySMESHGUI ? app->moduleName(mySMESHGUI->moduleName()) : QString(""), myHelpFileName);
1970 platform = "winapplication";
1972 platform = "application";
1974 SUIT_MessageBox::warn1(0, QObject::tr("WRN_WARNING"),
1975 QObject::tr("EXTERNAL_BROWSER_CANNOT_SHOW_PAGE").
1976 arg(app->resourceMgr()->stringValue("ExternalBrowser", platform)).arg(myHelpFileName),
1977 QObject::tr("BUT_OK"));
1981 //=======================================================================
1982 // name : SMESHGUI_FilterDlg::onDeactivate
1983 // Purpose : SLOT called when dialog must be deativated
1984 //=======================================================================
1985 void SMESHGUI_FilterDlg::onDeactivate()
1990 //=======================================================================
1991 // name : SMESHGUI_FilterDlg::enterEvent
1992 // Purpose : Event filter
1993 //=======================================================================
1994 void SMESHGUI_FilterDlg::enterEvent (QEvent*)
1996 // mySMESHGUI->EmitSignalDeactivateDialog();
1997 mySMESHGUI->SetActiveDialogBox((QDialog*)this);
1998 mySMESHGUI->ResetState();
2002 //=======================================================================
2003 // name : closeEvent()
2005 //=======================================================================
2006 void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
2011 //=======================================================================
2012 // name : SMESHGUI_FilterDlg::getIdsFromWg
2013 // Purpose : Retrieve list of ids from given widget
2014 //=======================================================================
2015 void SMESHGUI_FilterDlg::getIdsFromWg (const QWidget* theWg, QValueList<int>& theRes) const
2021 if (theWg->inherits("QListBox"))
2023 QListBox* aListBox = (QListBox*)theWg;
2025 for (int i = 0, n = aListBox->count(); i < n; i++)
2027 int anId = aListBox->text(i).toInt(&b);
2029 theRes.append(anId);
2032 else if (theWg->inherits("QLineEdit"))
2034 QLineEdit* aLineEdit = (QLineEdit*)theWg;
2035 QString aStr = aLineEdit->text();
2036 QRegExp aRegExp("(\\d+)");
2041 aPos = aRegExp.search(aStr, aPos);
2044 int anId = aRegExp.cap(1).toInt(&b);
2046 theRes.append(anId);
2047 aPos += aRegExp.matchedLength();
2053 //=======================================================================
2054 // name : SMESHGUI_FilterDlg::getSelMode
2055 // Purpose : Get selection mode of specified type
2056 //=======================================================================
2057 Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
2061 case SMESH::NODE : return NodeSelection;
2062 case SMESH::EDGE : return EdgeSelection;
2063 case SMESH::FACE : return FaceSelection;
2064 case SMESH::VOLUME : return VolumeSelection;
2065 default : return ActorSelection;
2070 //=======================================================================
2071 // name : SMESHGUI_FilterDlg::setIdsToWg
2072 // Purpose : Insert identifiers in specified widgets
2073 //=======================================================================
2074 void SMESHGUI_FilterDlg::setIdsToWg (QWidget* theWg, const QValueList<int>& theIds)
2079 if (theWg->inherits("QListBox"))
2081 QListBox* aListBox = (QListBox*)theWg;
2084 QStringList aStrList;
2085 QValueList<int>::const_iterator anIter;
2086 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter)
2087 aStrList.append(QString("%1").arg(*anIter));
2089 aListBox->insertStringList(aStrList);
2091 else if (theWg->inherits("QLineEdit"))
2093 QLineEdit* aLineEdit = (QLineEdit*)theWg;
2095 QValueList<int>::const_iterator anIter;
2097 for (anIter = theIds.begin(); anIter != theIds.end(); ++ anIter)
2098 aStr += QString("%1 ").arg(*anIter);
2100 if (!aStr.isEmpty())
2101 aStr.remove(aStr.length() - 1, 1);
2103 aLineEdit->setText(aStr);
2107 //=======================================================================
2108 // name : SMESHGUI_FilterDlg::isValid
2109 // Purpose : Verify validity of input data
2110 //=======================================================================
2111 bool SMESHGUI_FilterDlg::isValid() const
2113 if (!myTable->IsValid())
2116 for (int i = 0, n = myTable->NumRows(); i < n; i++)
2118 int aType = myTable->GetCriterionType(i);
2119 if (aType == FT_BelongToGeom ||
2120 aType == FT_BelongToPlane ||
2121 aType == FT_BelongToCylinder ||
2122 aType == FT_BelongToGenSurface ||
2123 aType == FT_LyingOnGeom) {
2125 myTable->GetThreshold(i, aName);
2127 std::vector<_PTR(SObject)> aList =
2128 SMESH::GetActiveStudyDocument()->FindObjectByName(aName.latin1(), "GEOM");
2129 if (aList.size() == 0) {
2130 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2131 tr("BAD_SHAPE_NAME").arg(aName), QMessageBox::Ok);
2135 if (aType == FT_BelongToCylinder ||
2136 aType == FT_BelongToPlane ||
2137 aType == FT_BelongToGenSurface ) {
2138 CORBA::Object_var anObject = SMESH::SObjectToObject(aList[ 0 ]);
2139 //GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(aList[ 0 ]->GetObject());
2140 GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(anObject);
2141 if (!aGeomObj->_is_nil()) {
2143 if (!GEOMBase::GetShape(aGeomObj, aFace) ||
2145 aFace.ShapeType() != TopAbs_FACE) {
2146 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2147 tr("SHAPE_IS_NOT_A_FACE").arg(aName), QMessageBox::Ok);
2151 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(TopoDS::Face(aFace));
2152 if (aSurf.IsNull()) {
2153 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2154 tr("SHAPE_IS_NOT_A_FACE").arg(aName), QMessageBox::Ok);
2158 if (aType == FT_BelongToPlane && !aSurf->IsKind(STANDARD_TYPE(Geom_Plane))) {
2159 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2160 tr("SHAPE_IS_NOT_A_PLANE").arg(aName), QMessageBox::Ok);
2164 if (aType == FT_BelongToCylinder && !aSurf->IsKind(STANDARD_TYPE(Geom_CylindricalSurface))) {
2165 QMessageBox::information(SMESHGUI::desktop(), tr("SMESH_INSUFFICIENT_DATA"),
2166 tr("SHAPE_IS_NOT_A_CYLINDER").arg(aName), QMessageBox::Ok);
2177 //=======================================================================
2178 // name : SMESHGUI_FilterDlg::SetSourceWg
2179 // Purpose : Set widget of parent dialog containing idsto be filtered if
2180 // user select corresponding source radio button
2181 //=======================================================================
2182 void SMESHGUI_FilterDlg::SetSourceWg (QWidget* theWg)
2187 //=======================================================================
2188 // name : SMESHGUI_FilterDlg::SetGroupIds
2189 // Purpose : Set mesh
2190 //=======================================================================
2191 void SMESHGUI_FilterDlg::SetMesh (SMESH::SMESH_Mesh_var theMesh)
2194 if ( myMesh->_is_nil() ) {
2195 myButtons[BTN_OK]->setEnabled(false);
2196 myButtons[BTN_Apply]->setEnabled(false);
2200 //=======================================================================
2201 // name : SMESHGUI_FilterDlg::SetSelection
2202 // Purpose : Get filtered ids
2203 //=======================================================================
2204 void SMESHGUI_FilterDlg::SetSelection()
2207 disconnect(mySelectionMgr, SIGNAL(currentSelectionChanged()), this, SLOT(onSelectionDone()));
2209 if (mySelectionMgr) {
2211 const SALOME_ListIO& anObjs = mySelector->StoredIObjects();
2212 SALOME_ListIteratorOfListIO anIter (anObjs);
2213 for (; anIter.More(); anIter.Next()) {
2214 TColStd_IndexedMapOfInteger aMap;
2215 mySelector->GetIndex(anIter.Value(), aMap);
2216 myIObjects.Bind(anIter.Value(), aMap);
2219 connect(mySelectionMgr, SIGNAL(currentSelectionChanged()), SLOT(onSelectionDone()));
2227 //=======================================================================
2228 // name : SMESHGUI_FilterDlg::onApply
2229 // Purpose : SLOT called when "Apply" button pressed.
2230 // Assign filters to VTK viewer
2231 //=======================================================================
2232 bool SMESHGUI_FilterDlg::onApply()
2238 int aCurrType = myTable->GetType();
2240 if (!createFilter(aCurrType))
2243 insertFilterInViewer();
2245 if (!myFilter[ aCurrType ]->GetPredicate()->_is_nil()) {
2246 QValueList<int> aResultIds;
2247 filterSource(aCurrType, aResultIds);
2248 selectInViewer(aCurrType, aResultIds);
2251 myInsertState[ aCurrType ] = mySetInViewer->isChecked();
2252 myApplyToState[ aCurrType ] = mySourceGrp->id(mySourceGrp->selected());
2254 catch(const SALOME::SALOME_Exception& S_ex)
2256 SalomeApp_Tools::QtCatchCorbaException(S_ex);
2265 //=======================================================================
2266 // name : SMESHGUI_FilterDlg::createFilter
2267 // Purpose : Create predicate for given type
2268 //=======================================================================
2269 bool SMESHGUI_FilterDlg::createFilter (const int theType)
2271 SMESH::FilterManager_var aFilterMgr = SMESH::GetFilterManager();
2272 if (aFilterMgr->_is_nil())
2275 int n = myTable->NumRows();
2277 SMESH::Filter::Criteria_var aCriteria = new SMESH::Filter::Criteria;
2278 aCriteria->length(n);
2280 long aPrecision = -1;
2281 SUIT_ResourceMgr* mgr = SMESH::GetResourceMgr( mySMESHGUI );
2283 if ( mgr && mgr->booleanValue( "SMESH", "use_precision", false ) )
2284 aPrecision = mgr->integerValue( "SMESH", "controls_precision", aPrecision );
2286 for (CORBA::ULong i = 0; i < n; i++) {
2287 SMESH::Filter::Criterion aCriterion = createCriterion();
2288 myTable->GetCriterion(i, aCriterion);
2289 aCriterion.Precision = aPrecision;
2290 aCriteria[ i ] = aCriterion;
2293 myFilter[ theType ] = aFilterMgr->CreateFilter();
2294 myFilter[ theType ]->SetCriteria(aCriteria.inout());
2299 //=======================================================================
2300 // name : SMESHGUI_FilterDlg::insertFilterInViewer
2301 // Purpose : Insert filter in viewer
2302 //=======================================================================
2303 void SMESHGUI_FilterDlg::insertFilterInViewer()
2305 if (SVTK_Selector* aSelector = SMESH::GetSelector()) {
2306 SMESH::ElementType anEntType = (SMESH::ElementType)myTable->GetType();
2308 if (myFilter[ myTable->GetType() ]->_is_nil() ||
2309 myFilter[ myTable->GetType() ]->GetPredicate()->_is_nil() ||
2310 !mySetInViewer->isChecked()) {
2311 SMESH::RemoveFilter(getFilterId(anEntType), aSelector);
2314 Handle(SMESHGUI_PredicateFilter) aFilter = new SMESHGUI_PredicateFilter();
2315 aFilter->SetPredicate(myFilter[ myTable->GetType() ]->GetPredicate());
2316 SMESH::RemoveFilter(getFilterId(anEntType), aSelector); //skl for IPAL12631
2317 SMESH::SetFilter(aFilter, aSelector);
2322 //=======================================================================
2323 // name : SMESHGUI_FilterDlg::filterSource
2324 // Purpose : Filter source ids
2325 //=======================================================================
2326 void SMESHGUI_FilterDlg::filterSource (const int theType,
2327 QValueList<int>& theResIds)
2330 if (myFilter[ theType ]->_is_nil())
2333 int aSourceId = mySourceGrp->id(mySourceGrp->selected());
2335 if (aSourceId == Mesh)
2337 if (myMesh->_is_nil())
2339 SMESH::long_array_var anIds = myFilter[ theType ]->GetElementsId(myMesh);
2340 for (int i = 0, n = anIds->length(); i < n; i++)
2341 theResIds.append(anIds[ i ]);
2343 else if (aSourceId == Selection)
2345 filterSelectionSource(theType, theResIds);
2347 else if (aSourceId == Dialog)
2349 // retrieve ids from dialog
2350 QValueList<int> aDialogIds;
2351 getIdsFromWg(mySourceWg, aDialogIds);
2353 if (myMesh->_is_nil())
2355 theResIds = aDialogIds;
2360 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2361 aPred->SetMesh(myMesh);
2362 QValueList<int>::const_iterator anIter;
2363 for (anIter = aDialogIds.begin(); anIter != aDialogIds.end(); ++ anIter)
2364 if (aPred->IsSatisfy(*anIter))
2365 theResIds.append(*anIter);
2367 // set ids to the dialog
2368 setIdsToWg(mySourceWg, theResIds);
2372 //=======================================================================
2373 // name : SMESHGUI_FilterDlg::filterSelectionSource
2374 // Purpose : Filter source selection
2375 //=======================================================================
2376 void SMESHGUI_FilterDlg::filterSelectionSource (const int theType,
2377 QValueList<int>& theResIds)
2380 if (myMesh->_is_nil() || mySelectionMgr == 0)
2383 // Create map of entities to be filtered
2384 TColStd_MapOfInteger aToBeFiltered;
2385 SALOME_DataMapIteratorOfDataMapOfIOMapOfInteger anIter(myIObjects);
2387 for (; anIter.More(); anIter.Next())
2390 SMESH::SMESH_subMesh_var aSubMesh = SMESH::IObjectToInterface<SMESH::SMESH_subMesh>(anIter.Key());
2391 if (!aSubMesh->_is_nil())
2393 if (aSubMesh->GetFather()->GetId() == myMesh->GetId())
2395 SMESH::long_array_var anIds =
2396 theType == SMESH::NODE ? aSubMesh->GetNodesId() : aSubMesh->GetElementsId();
2397 for (int i = 0, n = anIds->length(); i < n; i++)
2398 aToBeFiltered.Add(anIds[ i ]);
2403 SMESH::SMESH_GroupBase_var aGroup =
2404 SMESH::IObjectToInterface<SMESH::SMESH_GroupBase>(anIter.Key());
2405 if (!aGroup->_is_nil())
2407 if (aGroup->GetType() == theType && aGroup->GetMesh()->GetId() == myMesh->GetId())
2409 SMESH::long_array_var anIds = aGroup->GetListOfID();
2410 for (int i = 0, n = anIds->length(); i < n; i++)
2411 aToBeFiltered.Add(anIds[ i ]);
2416 SMESH::SMESH_Mesh_var aMeshPtr = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(anIter.Key());
2417 if (!aMeshPtr->_is_nil() && aMeshPtr->GetId() == myMesh->GetId())
2419 const TColStd_IndexedMapOfInteger& aSelMap = anIter.Value();
2421 if (aSelMap.Extent() > 0)
2423 if(SMESH::FindActorByEntry(anIter.Key()->getEntry()))
2425 for (int i = 1; i <= aSelMap.Extent(); i++)
2426 aToBeFiltered.Add(aSelMap(i));
2433 SMESH::Predicate_ptr aPred = myFilter[ theType ]->GetPredicate();
2434 aPred->SetMesh(myMesh);
2435 TColStd_MapIteratorOfMapOfInteger aResIter(aToBeFiltered);
2436 for (; aResIter.More(); aResIter.Next())
2437 if (aPred->IsSatisfy(aResIter.Key()))
2438 theResIds.append(aResIter.Key());
2441 //=======================================================================
2442 // name : SMESHGUI_FilterDlg::selectInViewer
2443 // Purpose : Select given entities in viewer
2444 //=======================================================================
2445 void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QValueList<int>& theIds)
2447 if (mySelectionMgr == 0 || myMesh->_is_nil())
2450 mySelectionMgr->clearFilters();
2452 // Set new selection mode if necessary
2453 Selection_Mode aSelMode = getSelMode(theType);
2454 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI );
2455 if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
2456 mySelectionMgr->clearSelected();
2457 mySelectionMgr->clearFilters();
2458 if (aSelMode == NodeSelection)
2459 SMESH::SetPointRepresentation(true);
2460 aViewWindow->SetSelectionMode(aSelMode);
2464 SMESH_Actor* anActor = SMESH::FindActorByObject(myMesh);
2465 if (!anActor || !anActor->hasIO())
2468 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
2469 //mySelectionMgr->clearSelected();
2470 //mySelectionMgr->AddIObject(anIO, false);
2471 SALOME_ListIO aList;
2473 mySelectionMgr->setSelectedObjects(aList, false);
2475 // Remove filter corresponding to the current type from viewer
2476 int aType = myTable->GetType();
2477 int aFilterId = SMESHGUI_UnknownFilter;
2478 if (aType == SMESH::EDGE ) aFilterId = SMESHGUI_EdgeFilter;
2479 else if (aType == SMESH::FACE ) aFilterId = SMESHGUI_FaceFilter;
2480 else if (aType == SMESH::VOLUME) aFilterId = SMESHGUI_VolumeFilter;
2481 Handle(VTKViewer_Filter) aFilter = SMESH::GetFilter(aFilterId);
2482 SMESH::RemoveFilter(aFilterId);
2485 TColStd_MapOfInteger aMap;
2486 QValueList<int>::const_iterator anIter;
2487 for (anIter = theIds.begin(); anIter != theIds.end(); ++anIter) {
2491 // Set new selection
2492 mySelector->AddOrRemoveIndex(anIO, aMap, false);
2493 if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
2494 aViewWindow->highlight( anIO, true, true );
2496 // insert previously stored filter in viewer if necessary
2497 if (!aFilter.IsNull())
2498 SMESH::SetFilter(aFilter);
2501 //=======================================================================
2502 // name : SMESHGUI_FilterDlg::createCriterion
2503 // Purpose : Create criterion structure with default values
2504 //=======================================================================
2505 SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
2507 SMESH::Filter::Criterion aCriterion;
2509 aCriterion.Type = FT_Undefined;
2510 aCriterion.Compare = FT_Undefined;
2511 aCriterion.Threshold = 0;
2512 aCriterion.UnaryOp = FT_Undefined;
2513 aCriterion.BinaryOp = FT_Undefined;
2514 aCriterion.ThresholdStr = "";
2515 aCriterion.ThresholdID = "";
2516 aCriterion.TypeOfElement = SMESH::ALL;
2521 //=======================================================================
2522 // name : SMESHGUI_FilterDlg::onSelectionDone
2523 // Purpose : SLOT called when selection changed.
2524 // If current cell corresponds to the threshold value of
2525 // BelongToGeom criterion name of selected object is set in this cell
2526 //=======================================================================
2527 void SMESHGUI_FilterDlg::onSelectionDone()
2530 const SALOME_ListIO& aList = mySelector->StoredIObjects();
2532 if ( myMesh->_is_nil() && aList.Extent()>0 ) {
2533 myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
2534 if ( !(myMesh->_is_nil()) ) {
2535 myButtons[BTN_OK]->setEnabled(true);
2536 myButtons[BTN_Apply]->setEnabled(true);
2540 if (aList.Extent() != 1 ||
2541 !myTable->CurrentCell(aRow, aCol) ||
2542 myTable->GetCriterionType(aRow) != FT_BelongToGeom &&
2543 myTable->GetCriterionType(aRow) != FT_BelongToPlane &&
2544 myTable->GetCriterionType(aRow) != FT_BelongToCylinder &&
2545 myTable->GetCriterionType(aRow) != FT_BelongToGenSurface &&
2546 myTable->GetCriterionType(aRow) != FT_LyingOnGeom)
2549 Handle(SALOME_InteractiveObject) anIO = aList.First();
2550 GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
2551 if (!anObj->_is_nil())
2553 myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
2554 //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
2555 myTable->SetID(aRow, anIO->getEntry());
2560 //=======================================================================
2561 // name : SMESHGUI_FilterDlg::onCriterionChanged
2562 // Purpose : SLOT called when cretarion of current row changed. Update selection
2563 //=======================================================================
2564 void SMESHGUI_FilterDlg::onCriterionChanged (const int , const int)
2569 //=======================================================================
2570 // name : SMESHGUI_FilterDlg::onCurrentChanged
2571 // Purpose : SLOT called when current row changed. Update selection
2572 //=======================================================================
2573 void SMESHGUI_FilterDlg::onCurrentChanged (int, int)
2578 //=======================================================================
2579 // name : SMESHGUI_FilterDlg::updateSelection
2580 // Purpose : UpdateSelection in accordance with current row
2581 //=======================================================================
2582 void SMESHGUI_FilterDlg::updateSelection()
2584 if (mySelectionMgr == 0)
2587 TColStd_MapOfInteger allTypes;
2588 for( int i=0; i<10; i++ )
2590 SalomeApp_Study* aStudy = dynamic_cast<SalomeApp_Study*>( mySMESHGUI->application()->activeStudy() );
2595 mySelectionMgr->clearFilters();
2599 if (myTable->CurrentCell(aRow, aCol) &&
2600 (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
2601 myTable->GetCriterionType(aRow) == FT_BelongToPlane ||
2602 myTable->GetCriterionType(aRow) == FT_BelongToCylinder ||
2603 myTable->GetCriterionType(aRow) == FT_BelongToGenSurface ||
2604 myTable->GetCriterionType(aRow) == FT_LyingOnGeom)) {
2606 if (myTable->GetCriterionType(aRow) == FT_BelongToGeom ||
2607 myTable->GetCriterionType(aRow) == FT_BelongToGenSurface ||
2608 myTable->GetCriterionType(aRow) == FT_LyingOnGeom) {
2610 mySelectionMgr->installFilter(new GEOM_SelectionFilter( aStudy, true ));
2612 } else if (myTable->GetCriterionType(aRow) == FT_BelongToPlane) {
2613 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Plane ) );
2615 } else if (myTable->GetCriterionType(aRow) == FT_BelongToCylinder) {
2616 mySelectionMgr->installFilter(new GEOM_FaceFilter( aStudy, StdSelect_Cylinder ) );
2618 myIsSelectionChanged = true;
2621 if (myIsSelectionChanged) {
2622 mySelectionMgr->installFilter( new GEOM_TypeFilter( aStudy, -1 ) ); // This filter deactivates selection
2627 //=================================================================================
2628 // function : keyPressEvent()
2630 //=================================================================================
2631 void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
2633 QDialog::keyPressEvent( e );
2634 if ( e->isAccepted() )
2637 if ( e->key() == Key_F1 )