Salome HOME
0022106: EDF 2464 SMESH : Split quadrangles in 4 triangles
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_FilterDlg.cxx
index d29ae2c82a064b9d19c6b322ac2adb369bfc9851..07f8a30a5cb2a966b399583e6d9c5976f109111b 100755 (executable)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #include "SMESHGUI_FilterLibraryDlg.h"
 #include "SMESHGUI_SpinBox.h"
 
-#include <SMESH_Actor.h>
-#include <SMESH_NumberFilter.hxx>
-#include <SMESH_TypeFilter.hxx>
+#include "SMESH_Actor.h"
+#include "SMESH_NumberFilter.hxx"
+#include "SMESH_TypeFilter.hxx"
+#include "SMESH_LogicalFilter.hxx"
 
 // SALOME GEOM includes
 #include <GEOMBase.h>
@@ -67,6 +68,7 @@
 
 // SALOME KERNEL includes
 #include <SALOMEDSClient_Study.hxx>
+#include <Basics_Utils.hxx>
 
 // OCCT includes
 #include <StdSelect_TypeOfFace.hxx>
@@ -1002,6 +1004,17 @@ void SMESHGUI_FilterTable::Init (const QList<int>& theTypes)
 
     myLibDlg = 0;
   }
+  else
+  {
+    QList<int>::const_iterator typeIt = theTypes.begin();
+    for ( ; typeIt != theTypes.end(); ++typeIt ) {
+      if ( !myTables[ *typeIt ] ) {
+        Table* aTable = createTable(mySwitchTableGrp, *typeIt);
+        myTables[ *typeIt ] = aTable;
+        ((QVBoxLayout*)mySwitchTableGrp->layout())->addWidget(myTables[ *typeIt ]);
+      }
+    }
+  }
 
   // Hide buttons of entity types if necessary
   const QMap<int, QString>& aSupportedTypes = getSupportedTypes();
@@ -1115,7 +1128,8 @@ bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType)
   {
     int aCriterion = GetCriterionType(i, aType);
     QString errMsg;
-    if (aCriterion == SMESH::FT_GroupColor ) {
+    if (aCriterion == SMESH::FT_GroupColor )
+    {
       QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(i, 2));
       if (clrBtn && !clrBtn->color().isValid())
         errMsg = tr( "GROUPCOLOR_ERROR" );
@@ -1126,13 +1140,16 @@ bool SMESHGUI_FilterTable::IsValid (const bool theMess, const int theEntityType)
              aCriterion == SMESH::FT_BelongToCylinder ||
              aCriterion == SMESH::FT_BelongToGenSurface ||
              aCriterion == SMESH::FT_ElemGeomType ||
+             aCriterion == SMESH::FT_EntityType ||
              aCriterion == SMESH::FT_CoplanarFaces ||
-             aCriterion == SMESH::FT_LyingOnGeom)
+             aCriterion == SMESH::FT_LyingOnGeom ||
+             aCriterion == SMESH::FT_ConnectedElements )
     {
       if (aTable->text(i, 2).isEmpty())
         errMsg = tr( "ERROR" );
     }
-    else {
+    else
+    {
       bool aRes = false;
       bool isSignalsBlocked = aTable->signalsBlocked();
       aTable->blockSignals(true);
@@ -1234,16 +1251,42 @@ void SMESHGUI_FilterTable::GetCriterion (const int                 theRow,
     QtxColorButton* clrBtn = qobject_cast<QtxColorButton*>(aTable->cellWidget(theRow, 2));
     if ( clrBtn )
     {
+      Kernel_Utils::Localizer loc;
       const QColor qClr = clrBtn->color();
       QString clrStr = QString( "%1;%2;%3" ).
         arg( qClr.red()/256. ).arg( qClr.green()/256. ).arg( qClr.blue()/256. );
       theCriterion.ThresholdStr = clrStr.toLatin1().constData();
     }
   }
-  else if ( aCriterionType == SMESH::FT_ElemGeomType )
+  else if ( aCriterionType == SMESH::FT_ElemGeomType ||
+            aCriterionType == SMESH::FT_EntityType )
+  {
     theCriterion.Threshold = (double)((ComboItem*)aTable->item(theRow, 2))->value();
+  }
   else if ( aCriterionType == SMESH::FT_CoplanarFaces )
+  {
     theCriterion.ThresholdID = aTable->text(theRow, 2).toLatin1().constData();
+  }
+  else if ( aCriterionType == SMESH::FT_ConnectedElements )
+  {
+    QString id = aTable->text(theRow, 5);
+    if ( !id.isEmpty() ) // shape ID
+    {
+      theCriterion.ThresholdID = id.toLatin1().constData();
+    }
+    else
+    {
+      QString text = aTable->text(theRow, 2).trimmed();
+      QString workText = text;
+      for ( char c = '0'; c <= '9'; ++c )
+        workText.remove( c );
+
+      if ( workText.isEmpty() ) // node ID
+        theCriterion.Threshold = text.toDouble();
+      else // point coordinates
+        theCriterion.ThresholdStr = text.toLatin1().constData();
+    }
+  }
   else if ( aCriterionType != SMESH::FT_RangeOfIds &&
             aCriterionType != SMESH::FT_BelongToGeom &&
             aCriterionType != SMESH::FT_BelongToPlane &&
@@ -1313,7 +1356,8 @@ void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
       clrBtn->setColor( qClr );
     }
   }
-  else if (theCriterion.Type == SMESH::FT_ElemGeomType )
+  else if (theCriterion.Type == SMESH::FT_ElemGeomType || 
+           theCriterion.Type == SMESH::FT_EntityType )
   {
     ComboItem* typeBox = (ComboItem*)aTable->item(theRow, 2);
     typeBox->setValue( (int)(theCriterion.Threshold + 0.5) );
@@ -1322,13 +1366,32 @@ void SMESHGUI_FilterTable::SetCriterion (const int                       theRow,
   {
     aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
   }
+  else if (theCriterion.Type == SMESH::FT_ConnectedElements )
+  {
+    if ( strlen( theCriterion.ThresholdID ) > 0 ) // shape ID -> name
+    {
+      _PTR(SObject) sobj =
+        SMESH::GetActiveStudyDocument()->FindObjectID( theCriterion.ThresholdID.in() );
+      if ( !sobj )
+        aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdID ) );
+      else
+        aTable->item( theRow, 2 )->setText( QString( sobj->GetName().c_str() ));
+    }
+    else if ( strlen( theCriterion.ThresholdStr ) > 0 ) // point coords
+    {
+      aTable->item( theRow, 2 )->setText( QString( theCriterion.ThresholdStr ));
+    }
+    else // node ID
+    {
+      aTable->item( theRow, 2 )->setText( QString("%1").arg((int) theCriterion.Threshold ));
+    }
+  }
   else if (theCriterion.Type != SMESH::FT_RangeOfIds &&
            theCriterion.Type != SMESH::FT_BelongToGeom &&
            theCriterion.Type != SMESH::FT_BelongToPlane &&
            theCriterion.Type != SMESH::FT_BelongToCylinder &&
            theCriterion.Type != SMESH::FT_BelongToGenSurface &&
            theCriterion.Type != SMESH::FT_LyingOnGeom &&
-           theCriterion.Type != SMESH::FT_CoplanarFaces &&
            theCriterion.Type != SMESH::FT_FreeBorders &&
            theCriterion.Type != SMESH::FT_FreeEdges &&
            theCriterion.Type != SMESH::FT_FreeNodes &&
@@ -1640,10 +1703,62 @@ static QList<int> geomTypes( const int theType )
   return typeIds;
 }
 
+//=======================================================================
+// name    : entityTypes
+// Purpose : returns available entity types of elements
+//=======================================================================
+
+static QList<int> entityTypes( const int theType )
+{
+  QList<int> typeIds;
+
+  switch ( theType )
+  {
+  case SMESH::NODE:
+    typeIds.append( SMDSEntity_Node );
+  case SMESH::EDGE:
+    typeIds.append( SMDSEntity_Edge );
+    typeIds.append( SMDSEntity_Quad_Edge );
+    break;
+  case SMESH::FACE:
+    typeIds.append( SMDSEntity_Triangle );
+    typeIds.append( SMDSEntity_Quad_Triangle );
+    typeIds.append( SMDSEntity_BiQuad_Triangle );
+    typeIds.append( SMDSEntity_Quadrangle );
+    typeIds.append( SMDSEntity_Quad_Quadrangle );
+    typeIds.append( SMDSEntity_BiQuad_Quadrangle );
+    typeIds.append( SMDSEntity_Polygon );
+    //typeIds.append( SMDSEntity_Quad_Polygon );
+    break;
+  case SMESH::VOLUME:
+    typeIds.append( SMDSEntity_Tetra );
+    typeIds.append( SMDSEntity_Quad_Tetra );
+    typeIds.append( SMDSEntity_Pyramid );
+    typeIds.append( SMDSEntity_Quad_Pyramid );
+    typeIds.append( SMDSEntity_Hexa );
+    typeIds.append( SMDSEntity_Quad_Hexa );
+    typeIds.append( SMDSEntity_TriQuad_Hexa );
+    typeIds.append( SMDSEntity_Penta );
+    typeIds.append( SMDSEntity_Quad_Penta );
+    typeIds.append( SMDSEntity_Hexagonal_Prism );
+    typeIds.append( SMDSEntity_Polyhedra );
+    //typeIds.append( SMDSEntity_Quad_Polyhedra );
+    break;
+  case SMESH::ELEM0D:
+    typeIds.append( SMDSEntity_0D );
+    break;
+  case SMESH::BALL:
+    typeIds.append( SMDSEntity_Ball );
+    break;
+  }
+  return typeIds;
+}
+
 //=======================================================================
 // name    : SMESHGUI_FilterTable::onCriterionChanged()
 // Purpose : Provides reaction on change of criterion
 //=======================================================================
+
 void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, const int entityType)
 {
   int aType = entityType == -1 ? GetType() : entityType;
@@ -1678,8 +1793,8 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
     aCriterionType == SMESH::FT_Length2D ||
     aCriterionType == SMESH::FT_MaxElementLength2D ||
     aCriterionType == SMESH::FT_MaxElementLength3D ||
-    aCriterionType == SMESH::FT_Volume3D;
-
+    aCriterionType == SMESH::FT_Volume3D ||
+    aCriterionType == SMESH::FT_EntityType;
   int aPrecision = 0;
   if ( anIsDoubleCriterion ) {
     const char* aPrecisionType = getPrecision( aCriterionType );
@@ -1699,6 +1814,7 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
 
   if ( (aCriterionType != SMESH::FT_GroupColor && clrBtn) ||
        (aCriterionType != SMESH::FT_ElemGeomType && isComboItem) ||
+       (aCriterionType != SMESH::FT_EntityType && isComboItem) ||
        (aCriterionType != SMESH::FT_MultiConnection && isIntSpinItem) ||
        (!anIsDoubleCriterion && isDoubleSpinItem) ||
        anIsPrecisionChanged )
@@ -1711,6 +1827,7 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
   }
   if ( (aCriterionType == SMESH::FT_GroupColor && !clrBtn) ||
        (aCriterionType == SMESH::FT_ElemGeomType && !isComboItem) ||
+       (aCriterionType == SMESH::FT_EntityType && !isComboItem) ||
        (aCriterionType == SMESH::FT_MultiConnection && !isIntSpinItem) ||
        (anIsDoubleCriterion && !isDoubleSpinItem) ||
        anIsPrecisionChanged )
@@ -1731,6 +1848,18 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
       ComboItem* typeBox = new ComboItem( typeNames );
       aTable->setItem( row, 2, typeBox );
     }
+    else if ( aCriterionType == SMESH::FT_EntityType ) {
+      QList<int> typeIds = entityTypes( aType );
+      QMap<int, QString> typeNames;
+      QList<int>::const_iterator anIter = typeIds.begin();
+      for ( int i = 0; anIter != typeIds.end(); ++anIter, ++i)
+      {
+        QString typeKey = QString( "ENTITY_TYPE_%1" ).arg( *anIter );
+        typeNames[ *anIter ] = tr( typeKey.toLatin1().data() );
+      }
+      ComboItem* typeBox = new ComboItem( typeNames );
+      aTable->setItem( row, 2, typeBox );
+    }
     else if ( aCriterionType == SMESH::FT_MultiConnection ) {
       IntSpinItem* intSpin = new IntSpinItem( 0 );
       aTable->setItem( row, 2, intSpin );
@@ -1743,6 +1872,7 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
     aTable->blockSignals( isSignalsBlocked );
   }
 
+  // set Compare and enable/desable Threshold
   if ((aType == SMESH::NODE && (aCriterionType == SMESH::FT_FreeNodes               ||
                                 aCriterionType == SMESH::FT_EqualNodes ))           ||
       (aType == SMESH::EDGE && (aCriterionType == SMESH::FT_FreeBorders             ||
@@ -1757,51 +1887,51 @@ void SMESHGUI_FilterTable::onCriterionChanged (const int row, const int col, con
                                   aCriterionType == SMESH::FT_BareBorderVolume      ||
                                   aCriterionType == SMESH::FT_EqualVolumes ))       ||
       aCriterionType == SMESH::FT_LinearOrQuadratic ||
-      aCriterionType == SMESH::FT_GroupColor ||
-      aCriterionType == SMESH::FT_ElemGeomType ||
-      aCriterionType == SMESH::FT_CoplanarFaces
+      aCriterionType == SMESH::FT_CoplanarFaces ||
+      aCriterionType == SMESH::FT_ConnectedElements
       )
   {
+    // - No compare
     bool isSignalsBlocked = aTable->signalsBlocked();
     aTable->blockSignals( true );
 
     if (aCompareItem->count() > 0)
       aCompareItem->clear();
     aTable->setEditable(false, row, 1);
+    // - Threshold is NOT editable for most of criteria
     aTable->item(row, 2)->setText( QString("") );
-    aTable->setEditable(aCriterionType == SMESH::FT_GroupColor ||
-                        aCriterionType == SMESH::FT_ElemGeomType ||
-                        aCriterionType == SMESH::FT_CoplanarFaces, row, 2);
+    aTable->setEditable(( aCriterionType == SMESH::FT_ConnectedElements ||
+                          aCriterionType == SMESH::FT_CoplanarFaces       ), row, 2);
     aTable->blockSignals( isSignalsBlocked );
   }
   else if (aCriterionType == SMESH::FT_RangeOfIds ||
+           aCriterionType == SMESH::FT_GroupColor ||
+           aCriterionType == SMESH::FT_ElemGeomType ||
+           aCriterionType == SMESH::FT_EntityType ||
            aCriterionType == SMESH::FT_BelongToGeom ||
            aCriterionType == SMESH::FT_BelongToPlane ||
            aCriterionType == SMESH::FT_BelongToCylinder ||
            aCriterionType == SMESH::FT_BelongToGenSurface ||
            aCriterionType == SMESH::FT_LyingOnGeom)
   {
+    // - EQUAL_TO compare ONLY
     QMap<int, QString> aMap;
     aMap[ SMESH::FT_EqualTo ] = tr("EQUAL_TO");
     aCompareItem->setItems(aMap);
-    if (!aTable->isEditable(row, 2))
-      aTable->setEditable(true, row, 1);
-    if (!aTable->isEditable(row, 2))
-      aTable->setEditable(true, row, 2);
-  }
-  else if (aCriterionType == SMESH::FT_GroupColor ||
-           aCriterionType == SMESH::FT_ElemGeomType)
-  {
+    // if (!aTable->isEditable(row, 2))
+    aTable->setEditable(false, row, 1);
+    // - Threshold is editable
     if (!aTable->isEditable(row, 2))
       aTable->setEditable(true, row, 2);
   }
   else
   {
+    // All compare signs
     if (aCompareItem && aCompareItem->count() != 3)
     {
       aCompareItem->setItems(getCompare());
     }
-
+    // Threshold is editable
     if (aTable->item( row, 2 )) {
       QString aText = aTable->text(row, 2);
       bool isOk = false;
@@ -1828,6 +1958,8 @@ void SMESHGUI_FilterTable::onCriterionChanged (int row, int col)
 {
   if( col == 0 )
     onCriterionChanged(row, col, -1);
+  else if ( col == 2 )
+    emit ThresholdChanged(row, GetType());
 }
 
 //=======================================================================
@@ -1970,6 +2102,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getSupportedTypes() const
   if (aTypes.isEmpty())
   {
     aTypes[ SMESH::NODE   ] = tr("NODES");
+    aTypes[ SMESH::ELEM0D ] = tr("ELEM0D");
     aTypes[ SMESH::BALL   ] = tr("BALLS");
     aTypes[ SMESH::EDGE   ] = tr("EDGES");
     aTypes[ SMESH::FACE   ] = tr("FACES");
@@ -2000,6 +2133,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_FreeNodes          ] = tr("FREE_NODES");
       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
       aCriteria[ SMESH::FT_EqualNodes         ] = tr("EQUAL_NODE");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2021,6 +2155,8 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
       aCriteria[ SMESH::FT_EqualEdges         ] = tr("EQUAL_EDGE");
+      aCriteria[ SMESH::FT_EntityType         ] = tr("ENTITY_TYPE");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2053,6 +2189,8 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
       aCriteria[ SMESH::FT_CoplanarFaces      ] = tr("COPLANAR_FACES");
       aCriteria[ SMESH::FT_EqualFaces         ] = tr("EQUAL_FACE");
+      aCriteria[ SMESH::FT_EntityType         ] = tr("ENTITY_TYPE");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2074,6 +2212,8 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_GroupColor           ] = tr("GROUP_COLOR");
       aCriteria[ SMESH::FT_ElemGeomType         ] = tr("GEOM_TYPE");
       aCriteria[ SMESH::FT_EqualVolumes         ] = tr("EQUAL_VOLUME");
+      aCriteria[ SMESH::FT_EntityType           ] = tr("ENTITY_TYPE");
+      aCriteria[ SMESH::FT_ConnectedElements    ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2088,6 +2228,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2103,6 +2244,22 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
       aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
+    }
+    return aCriteria;
+  }
+  else if (theType == SMESH::ELEM0D)
+  {
+    static QMap<int, QString> aCriteria;
+    if (aCriteria.isEmpty())
+    {
+      aCriteria[ SMESH::FT_RangeOfIds         ] = tr("RANGE_OF_IDS");
+      aCriteria[ SMESH::FT_BelongToGeom       ] = tr("BELONG_TO_GEOM");
+      aCriteria[ SMESH::FT_BelongToPlane      ] = tr("BELONG_TO_PLANE");
+      aCriteria[ SMESH::FT_BelongToCylinder   ] = tr("BELONG_TO_CYLINDER");
+      aCriteria[ SMESH::FT_BelongToGenSurface ] = tr("BELONG_TO_GENSURFACE");
+      aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
     return aCriteria;
   }
@@ -2117,6 +2274,7 @@ const QMap<int, QString>& SMESHGUI_FilterTable::getCriteria (const int theType)
       aCriteria[ SMESH::FT_LinearOrQuadratic  ] = tr("LINEAR");
       aCriteria[ SMESH::FT_GroupColor         ] = tr("GROUP_COLOR");
       aCriteria[ SMESH::FT_ElemGeomType       ] = tr("GEOM_TYPE");
+      aCriteria[ SMESH::FT_ConnectedElements  ] = tr("CONNECTED_ELEMS");
     }
 
     return aCriteria;
@@ -2386,7 +2544,13 @@ void SMESHGUI_FilterTable::SetThreshold (const int      theRow,
                                          const int      theEntityType)
 {
   Table* aTable = myTables[ theEntityType == -1 ? GetType() : theEntityType ];
+
+  bool isSignalsBlocked = aTable->signalsBlocked();
+  aTable->blockSignals(true);
+  
   aTable->item( theRow, 2 )->setText(theText);
+
+  aTable->blockSignals(isSignalsBlocked);
 }
 
 //=======================================================================
@@ -2626,7 +2790,7 @@ QWidget* SMESHGUI_FilterDlg::createButtonFrame (QWidget* theParent)
   aLay->addWidget(myButtons[ BTN_Help   ]);
 
   connect(myButtons[ BTN_OK     ], SIGNAL(clicked()), SLOT(onOk()));
-  connect(myButtons[ BTN_Close  ], SIGNAL(clicked()), SLOT(onClose()));
+  connect(myButtons[ BTN_Close  ], SIGNAL(clicked()), SLOT(reject()));
   connect(myButtons[ BTN_Apply  ], SIGNAL(clicked()), SLOT(onApply()));
   connect(myButtons[ BTN_Help   ], SIGNAL(clicked()), SLOT(onHelp()));
 
@@ -2665,6 +2829,7 @@ void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewe
   myMesh      = SMESH::SMESH_Mesh::_nil();
   myIObjects.Clear();
   myIsSelectionChanged = false;
+  myToRestoreSelMode = false;
 
   myTable->Init(theTypes);
 
@@ -2673,6 +2838,8 @@ void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewe
   {
     int aType = theTypes.first();
     if      (aType == SMESH::NODE  ) setWindowTitle(tr("NODES_TLT"));
+    else if (aType == SMESH::ELEM0D) setWindowTitle(tr("ELEM0D_TLT"));
+    else if (aType == SMESH::BALL  ) setWindowTitle(tr("BALL_TLT"));
     else if (aType == SMESH::EDGE  ) setWindowTitle(tr("EDGES_TLT"));
     else if (aType == SMESH::FACE  ) setWindowTitle(tr("FACES_TLT"));
     else if (aType == SMESH::VOLUME) setWindowTitle(tr("VOLUMES_TLT"));
@@ -2689,7 +2856,7 @@ void SMESHGUI_FilterDlg::Init (const QList<int>& theTypes, const bool setInViewe
   mySMESHGUI->SetActiveDialogBox((QDialog*)this);
 
   connect(mySMESHGUI, SIGNAL(SignalDeactivateActiveDialog()), SLOT(onDeactivate()));
-  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(onClose()));
+  connect(mySMESHGUI, SIGNAL(SignalCloseAllDialogs()), SLOT(reject()));
   
   updateMainButtons();
   updateSelection();
@@ -2729,6 +2896,7 @@ void SMESHGUI_FilterDlg::onOk()
 {
   if (onApply())
   {
+    restoreSelMode();
     mySelectionMgr->clearFilters();
     disconnect(mySMESHGUI, 0, this, 0);
     disconnect(mySelectionMgr, 0, this, 0);
@@ -2739,11 +2907,12 @@ void SMESHGUI_FilterDlg::onOk()
 }
 
 //=======================================================================
-// name    : SMESHGUI_FilterDlg::onClose
+// name    : SMESHGUI_FilterDlg::reject
 // Purpose : SLOT called when "Close" button pressed. Close dialog
 //=======================================================================
-void SMESHGUI_FilterDlg::onClose()
+void SMESHGUI_FilterDlg::reject()
 {
+  restoreSelMode();
   // Restore previously selected object
   if (mySelectionMgr)
   {
@@ -2770,8 +2939,7 @@ void SMESHGUI_FilterDlg::onClose()
   disconnect(mySMESHGUI, 0, this, 0);
   disconnect(mySelectionMgr, 0, this, 0);
   mySMESHGUI->ResetState();
-  reject();
-  return;
+  QDialog::reject();
 }
 
 //=================================================================================
@@ -2819,15 +2987,6 @@ void SMESHGUI_FilterDlg::enterEvent (QEvent*)
   setEnabled(true);
 }
 
-//=======================================================================
-// name    : closeEvent()
-// Purpose :
-//=======================================================================
-void SMESHGUI_FilterDlg::closeEvent (QCloseEvent*)
-{
-  onClose();
-}
-
 //=======================================================================
 // name    : SMESHGUI_FilterDlg::getIdsFromWg
 // Purpose : Retrieve list of ids from given widget
@@ -2879,6 +3038,8 @@ Selection_Mode SMESHGUI_FilterDlg::getSelMode (const int theType) const
   switch (theType)
   {
     case SMESH::NODE   : return NodeSelection;
+    case SMESH::ELEM0D : return Elem0DSelection;
+    case SMESH::BALL   : return BallSelection;
     case SMESH::EDGE   : return EdgeSelection;
     case SMESH::FACE   : return FaceSelection;
     case SMESH::VOLUME : return VolumeSelection;
@@ -3093,9 +3254,11 @@ bool SMESHGUI_FilterDlg::onApply()
   catch(const SALOME::SALOME_Exception& S_ex)
   {
     SalomeApp_Tools::QtCatchCorbaException(S_ex);
+    return false;
   }
   catch(...)
   {
+    return false;
   }
 
   return true;
@@ -3324,8 +3487,7 @@ void SMESHGUI_FilterDlg::selectInViewer (const int theType, const QList<int>& th
   if ( aViewWindow && aViewWindow->SelectionMode()!=aSelMode) {
     mySelectionMgr->clearSelected();
     mySelectionMgr->clearFilters();
-    if (aSelMode == NodeSelection)
-      SMESH::SetPointRepresentation(true);
+    SMESH::SetPointRepresentation( aSelMode == NodeSelection );
     aViewWindow->SetSelectionMode(aSelMode);
   }
 
@@ -3395,42 +3557,64 @@ SMESH::Filter::Criterion SMESHGUI_FilterDlg::createCriterion()
 //=======================================================================
 void SMESHGUI_FilterDlg::onSelectionDone()
 {
-  int aRow, aCol;
   const SALOME_ListIO& aList = mySelector->StoredIObjects();
-
-  if ( myMesh->_is_nil() && aList.Extent()>0 ) {
+  if ( myMesh->_is_nil() && aList.Extent()>0 )
+  {
     myMesh = SMESH::IObjectToInterface<SMESH::SMESH_Mesh>(aList.First());
     if ( !(myMesh->_is_nil()) ) {
       myButtons[BTN_OK]->setEnabled(true);
       myButtons[BTN_Apply]->setEnabled(true);
     }
   }
+  int aRow, aCol;
+  if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol))
+    return;
 
+  const int type = myTable->GetCriterionType(aRow);
   QList<int> types; 
   types << SMESH::FT_BelongToGeom     << SMESH::FT_BelongToPlane 
         << SMESH::FT_BelongToCylinder << SMESH::FT_BelongToGenSurface
-        << SMESH::FT_LyingOnGeom      << SMESH::FT_CoplanarFaces;
-  if (aList.Extent() != 1 || !myTable->CurrentCell(aRow, aCol) || 
-      !types.contains(myTable->GetCriterionType(aRow)))
+        << SMESH::FT_LyingOnGeom      << SMESH::FT_CoplanarFaces
+        << SMESH::FT_ConnectedElements;
+  if ( !types.contains( type ))
     return;
 
-  if ( myTable->GetCriterionType(aRow) == SMESH::FT_CoplanarFaces )
-  {
-    QString aString;
-    int nbElems = SMESH::GetNameOfSelectedElements(mySelector,//myViewWindow->GetSelector(),
-                                                   aList.First(), aString);
-    if (nbElems == 1)
-      myTable->SetThreshold(aRow, aString);
-  }
-  else
+  Handle(SALOME_InteractiveObject) anIO = aList.First();
+  switch ( type )
   {
-    Handle(SALOME_InteractiveObject) anIO = aList.First();
-    GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
-    if (!anObj->_is_nil())
+  case SMESH::FT_CoplanarFaces: // get ID of a selected mesh face
     {
-      myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
-      //myTable->SetID( aRow, GEOMBase::GetIORFromObject(anObj));
-      myTable->SetID(aRow, anIO->getEntry());
+      QString aString;
+      int nbElems = SMESH::GetNameOfSelectedElements(mySelector, anIO, aString);
+      if (nbElems == 1)
+        myTable->SetThreshold(aRow, aString);
+      break;
+    }
+  case SMESH::FT_ConnectedElements: // get either VERTEX or a node ID
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID       (aRow, anIO->getEntry());
+      }
+      else
+      {
+        QString aString;
+        int nbElems = SMESH::GetNameOfSelectedElements(mySelector, anIO, aString);
+        if (nbElems == 1)
+          myTable->SetThreshold(aRow, aString);
+      }
+      break;
+    }
+  default: // get a GEOM object
+    {
+      GEOM::GEOM_Object_var anObj = SMESH::IObjectToInterface<GEOM::GEOM_Object>(anIO);
+      if (!anObj->_is_nil())
+      {
+        myTable->SetThreshold(aRow, GEOMBase::GetName(anObj));
+        myTable->SetID(aRow, anIO->getEntry());
+      }
     }
   }
 }
@@ -3445,6 +3629,20 @@ void SMESHGUI_FilterDlg::onCriterionChanged (const int, const int)
   updateSelection();
 }
 
+//=======================================================================
+// name    : SMESHGUI_FilterDlg::onThresholdChanged
+// Purpose : SLOT called when a threshold value is changed by the user and
+//           not by myTable->SetThreshold()
+//=======================================================================
+void SMESHGUI_FilterDlg::onThresholdChanged( const int row, const int type )
+{
+  if ( myTable->GetCriterionType( row, type ) == SMESH::FT_ConnectedElements )
+  {
+    // to differ the text entered by the user from that got from selection
+    myTable->SetID( row, "", type );
+  }
+}
+
 //=======================================================================
 // name    : SMESHGUI_FilterDlg::onCurrentChanged
 // Purpose : SLOT called when current row changed. Update selection
@@ -3470,6 +3668,7 @@ void SMESHGUI_FilterDlg::updateSelection()
   if( !aStudy )
     return;
 
+  restoreSelMode();
 
   mySelectionMgr->clearFilters();
 
@@ -3499,6 +3698,24 @@ void SMESHGUI_FilterDlg::updateSelection()
     myIsSelectionChanged = true;
 
   }
+  else if ( aCriterionType == SMESH::FT_ConnectedElements )
+  {
+    QList<SUIT_SelectionFilter*> fList;
+    fList.push_back( new SMESH_NumberFilter( "GEOM", TopAbs_SHAPE, 1, TopAbs_VERTEX ));
+    fList.push_back( new SMESH_TypeFilter( SMESH::IDSOURCE ));
+    mySelectionMgr->installFilter
+      ( new SMESH_LogicalFilter( fList, SMESH_LogicalFilter::LO_OR,
+                                 !mySelectionMgr->autoDeleteFilter() ));
+
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+    {
+      mySelModeToRestore = aViewWindow->SelectionMode();
+      aViewWindow->SetSelectionMode( NodeSelection );
+      myToRestoreSelMode = ( mySelModeToRestore != NodeSelection );
+      if ( myToRestoreSelMode )
+        SMESH::SetPointRepresentation( true );
+    }
+  }
   else
   {
     mySelector->SetSelectionMode( getSelMode( myTable->GetType() ));
@@ -3525,3 +3742,22 @@ void SMESHGUI_FilterDlg::keyPressEvent( QKeyEvent* e )
     onHelp();
   }
 }
+
+//================================================================================
+/*!
+ * \brief Restores a selection mode if it was changed to set up some criterion
+ */
+//================================================================================
+
+void SMESHGUI_FilterDlg::restoreSelMode()
+{
+  if ( myToRestoreSelMode )
+  {
+    SMESH::SetPointRepresentation( mySelModeToRestore == NodeSelection );
+
+    if ( SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( mySMESHGUI ))
+      aViewWindow->SetSelectionMode( mySelModeToRestore );
+
+    myToRestoreSelMode = false;
+  }
+}