Salome HOME
#19078 [CEA] Mesh Group - Group on filter
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index b7b0e53e1e75b0691300d99ae3a4b5b5a437b204..ae97ce1c664fd6f444e9127a111055f543ae2a02 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2020  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
@@ -6,7 +6,7 @@
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 // License as published by the Free Software Foundation; either
-// version 2.1 of the License.
+// version 2.1 of the License, or (at your option) any later version.
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -20,7 +20,7 @@
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's calsses
+//  SMESH SMESH_I : idl implementation based on 'SMESH' unit's classes
 //  File   : SMESH_Filter_i.cxx
 //  Author : Alexey Petrov, OCC
 //  Module : SMESH
@@ -31,6 +31,7 @@
 #include "SMDS_Mesh.hxx"
 #include "SMDS_MeshElement.hxx"
 #include "SMDS_MeshNode.hxx"
+#include "SMESHDS_GroupBase.hxx"
 #include "SMESHDS_Mesh.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMESH_Group_i.hxx"
 #include <TColStd_ListOfReal.hxx>
 #include <TColStd_SequenceOfHAsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
-#include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
 
 using namespace SMESH;
 using namespace SMESH::Controls;
@@ -75,358 +73,6 @@ namespace SMESH
   }
 }
 
-
-/*
-  Class       : BelongToGeom
-  Description : Predicate for verifying whether entity belongs to
-                specified geometrical support
-*/
-
-Controls::BelongToGeom::BelongToGeom()
-  : myMeshDS(NULL),
-    myType(SMDSAbs_All),
-    myIsSubshape(false),
-    myTolerance(Precision::Confusion())
-{}
-
-void Controls::BelongToGeom::SetMesh( const SMDS_Mesh* theMesh )
-{
-  myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
-  init();
-}
-
-void Controls::BelongToGeom::SetGeom( const TopoDS_Shape& theShape )
-{
-  myShape = theShape;
-  init();
-}
-
-static bool IsSubShape (const TopTools_IndexedMapOfShape& theMap,
-                        const TopoDS_Shape& theShape)
-{
-  if (theMap.Contains(theShape)) return true;
-
-  if (theShape.ShapeType() == TopAbs_COMPOUND ||
-      theShape.ShapeType() == TopAbs_COMPSOLID)
-  {
-    TopoDS_Iterator anIt (theShape, Standard_True, Standard_True);
-    for (; anIt.More(); anIt.Next())
-    {
-      if (!IsSubShape(theMap, anIt.Value())) {
-        return false;
-      }
-    }
-    return true;
-  }
-
-  return false;
-}
-
-void Controls::BelongToGeom::init()
-{
-  if (!myMeshDS || myShape.IsNull()) return;
-
-  // is sub-shape of main shape?
-  TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
-  if (aMainShape.IsNull()) {
-    myIsSubshape = false;
-  }
-  else {
-    TopTools_IndexedMapOfShape aMap;
-    TopExp::MapShapes(aMainShape, aMap);
-    myIsSubshape = IsSubShape(aMap, myShape);
-  }
-
-  if (!myIsSubshape)
-  {
-    myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
-    myElementsOnShapePtr->SetTolerance(myTolerance);
-    myElementsOnShapePtr->SetAllNodes(true); // belong, while false means "lays on"
-    myElementsOnShapePtr->SetMesh(myMeshDS);
-    myElementsOnShapePtr->SetShape(myShape, myType);
-  }
-}
-
-static bool IsContains( const SMESHDS_Mesh*     theMeshDS,
-                        const TopoDS_Shape&     theShape,
-                        const SMDS_MeshElement* theElem,
-                        TopAbs_ShapeEnum        theFindShapeEnum,
-                        TopAbs_ShapeEnum        theAvoidShapeEnum = TopAbs_SHAPE )
-{
-  TopExp_Explorer anExp( theShape,theFindShapeEnum,theAvoidShapeEnum );
-
-  while( anExp.More() )
-  {
-    const TopoDS_Shape& aShape = anExp.Current();
-    if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
-      if( aSubMesh->Contains( theElem ) )
-        return true;
-    }
-    anExp.Next();
-  }
-  return false;
-}
-
-bool Controls::BelongToGeom::IsSatisfy (long theId)
-{
-  if (myMeshDS == 0 || myShape.IsNull())
-    return false;
-
-  if (!myIsSubshape)
-  {
-    return myElementsOnShapePtr->IsSatisfy(theId);
-  }
-
-  // Case of submesh
-  if (myType == SMDSAbs_Node)
-  {
-    if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
-    {
-      const SMDS_PositionPtr& aPosition = aNode->GetPosition();
-      SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
-      switch( aTypeOfPosition )
-      {
-      case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
-      case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
-      case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
-      case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
-      }
-    }
-  }
-  else
-  {
-    if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
-    {
-      if( myType == SMDSAbs_All )
-      {
-        return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
-               IsContains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
-               IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
-               IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
-      }
-      else if( myType == anElem->GetType() )
-      {
-        switch( myType )
-        {
-        case SMDSAbs_Edge  : return IsContains( myMeshDS,myShape,anElem,TopAbs_EDGE );
-        case SMDSAbs_Face  : return IsContains( myMeshDS,myShape,anElem,TopAbs_FACE );
-        case SMDSAbs_Volume: return IsContains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
-                                    IsContains( myMeshDS,myShape,anElem,TopAbs_SOLID );
-        }
-      }
-    }
-  }
-
-  return false;
-}
-
-void Controls::BelongToGeom::SetType (SMDSAbs_ElementType theType)
-{
-  myType = theType;
-  init();
-}
-
-SMDSAbs_ElementType Controls::BelongToGeom::GetType() const
-{
-  return myType;
-}
-
-TopoDS_Shape Controls::BelongToGeom::GetShape()
-{
-  return myShape;
-}
-
-const SMESHDS_Mesh* Controls::BelongToGeom::GetMeshDS() const
-{
-  return myMeshDS;
-}
-
-void Controls::BelongToGeom::SetTolerance (double theTolerance)
-{
-  myTolerance = theTolerance;
-  if (!myIsSubshape)
-    init();
-}
-
-double Controls::BelongToGeom::GetTolerance()
-{
-  return myTolerance;
-}
-
-/*
-  Class       : LyingOnGeom
-  Description : Predicate for verifying whether entiy lying or partially lying on
-                specified geometrical support
-*/
-
-Controls::LyingOnGeom::LyingOnGeom()
-  : myMeshDS(NULL),
-    myType(SMDSAbs_All),
-    myIsSubshape(false),
-    myTolerance(Precision::Confusion())
-{}
-
-void Controls::LyingOnGeom::SetMesh( const SMDS_Mesh* theMesh )
-{
-  myMeshDS = dynamic_cast<const SMESHDS_Mesh*>(theMesh);
-  init();
-}
-
-void Controls::LyingOnGeom::SetGeom( const TopoDS_Shape& theShape )
-{
-  myShape = theShape;
-  init();
-}
-
-void Controls::LyingOnGeom::init()
-{
-  if (!myMeshDS || myShape.IsNull()) return;
-
-  // is sub-shape of main shape?
-  TopoDS_Shape aMainShape = myMeshDS->ShapeToMesh();
-  if (aMainShape.IsNull()) {
-    myIsSubshape = false;
-  }
-  else {
-    TopTools_IndexedMapOfShape aMap;
-    TopExp::MapShapes(aMainShape, aMap);
-    myIsSubshape = IsSubShape(aMap, myShape);
-  }
-
-  if (!myIsSubshape)
-  {
-    myElementsOnShapePtr.reset(new Controls::ElementsOnShape());
-    myElementsOnShapePtr->SetTolerance(myTolerance);
-    myElementsOnShapePtr->SetAllNodes(false); // lays on, while true means "belong"
-    myElementsOnShapePtr->SetMesh(myMeshDS);
-    myElementsOnShapePtr->SetShape(myShape, myType);
-  }
-}
-
-bool Controls::LyingOnGeom::IsSatisfy( long theId )
-{
-  if ( myMeshDS == 0 || myShape.IsNull() )
-    return false;
-
-  if (!myIsSubshape)
-  {
-    return myElementsOnShapePtr->IsSatisfy(theId);
-  }
-
-  // Case of submesh
-  if( myType == SMDSAbs_Node )
-  {
-    if( const SMDS_MeshNode* aNode = myMeshDS->FindNode( theId ) )
-    {
-      const SMDS_PositionPtr& aPosition = aNode->GetPosition();
-      SMDS_TypeOfPosition aTypeOfPosition = aPosition->GetTypeOfPosition();
-      switch( aTypeOfPosition )
-      {
-      case SMDS_TOP_VERTEX : return IsContains( myMeshDS,myShape,aNode,TopAbs_VERTEX );
-      case SMDS_TOP_EDGE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_EDGE );
-      case SMDS_TOP_FACE   : return IsContains( myMeshDS,myShape,aNode,TopAbs_FACE );
-      case SMDS_TOP_3DSPACE: return IsContains( myMeshDS,myShape,aNode,TopAbs_SHELL );
-      }
-    }
-  }
-  else
-  {
-    if( const SMDS_MeshElement* anElem = myMeshDS->FindElement( theId ) )
-    {
-      if( myType == SMDSAbs_All )
-      {
-        return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE ) ||
-               Contains( myMeshDS,myShape,anElem,TopAbs_FACE ) ||
-               Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
-               Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
-      }
-      else if( myType == anElem->GetType() )
-      {
-        switch( myType )
-        {
-        case SMDSAbs_Edge  : return Contains( myMeshDS,myShape,anElem,TopAbs_EDGE );
-        case SMDSAbs_Face  : return Contains( myMeshDS,myShape,anElem,TopAbs_FACE );
-        case SMDSAbs_Volume: return Contains( myMeshDS,myShape,anElem,TopAbs_SHELL )||
-                                    Contains( myMeshDS,myShape,anElem,TopAbs_SOLID );
-        }
-      }
-    }
-  }
-
-  return false;
-}
-
-void Controls::LyingOnGeom::SetType( SMDSAbs_ElementType theType )
-{
-  myType = theType;
-  init();
-}
-
-SMDSAbs_ElementType Controls::LyingOnGeom::GetType() const
-{
-  return myType;
-}
-
-TopoDS_Shape Controls::LyingOnGeom::GetShape()
-{
-  return myShape;
-}
-
-const SMESHDS_Mesh* Controls::LyingOnGeom::GetMeshDS() const
-{
-  return myMeshDS;
-}
-
-void Controls::LyingOnGeom::SetTolerance (double theTolerance)
-{
-  myTolerance = theTolerance;
-  if (!myIsSubshape)
-    init();
-}
-
-double Controls::LyingOnGeom::GetTolerance()
-{
-  return myTolerance;
-}
-
-bool Controls::LyingOnGeom::Contains( const SMESHDS_Mesh*     theMeshDS,
-                                      const TopoDS_Shape&     theShape,
-                                      const SMDS_MeshElement* theElem,
-                                      TopAbs_ShapeEnum        theFindShapeEnum,
-                                      TopAbs_ShapeEnum        theAvoidShapeEnum )
-{
-  if (IsContains(theMeshDS, theShape, theElem, theFindShapeEnum, theAvoidShapeEnum))
-    return true;
-
-  TopTools_IndexedMapOfShape aSubShapes;
-  TopExp::MapShapes( theShape, aSubShapes );
-
-  for (int i = 1; i <= aSubShapes.Extent(); i++)
-  {
-    const TopoDS_Shape& aShape = aSubShapes.FindKey(i);
-
-    if( SMESHDS_SubMesh* aSubMesh = theMeshDS->MeshElements( aShape ) ){
-      if( aSubMesh->Contains( theElem ) )
-        return true;
-
-      SMDS_NodeIteratorPtr aNodeIt = aSubMesh->GetNodes();
-      while ( aNodeIt->more() )
-      {
-        const SMDS_MeshNode* aNode = static_cast<const SMDS_MeshNode*>(aNodeIt->next());
-        SMDS_ElemIteratorPtr anElemIt = aNode->GetInverseElementIterator();
-        while ( anElemIt->more() )
-        {
-          const SMDS_MeshElement* anElement = static_cast<const SMDS_MeshElement*>(anElemIt->next());
-          if (anElement == theElem)
-            return true;
-        }
-      }
-    }
-  }
-  return false;
-}
-
-
 /*
                             AUXILIARY METHODS
 */
@@ -490,18 +136,16 @@ static TopoDS_Shape getShapeByName( const char* theName )
   if ( theName != 0 )
   {
     SMESH_Gen_i* aSMESHGen     = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-    if ( !aStudy->_is_nil() )
+    SALOMEDS::Study::ListOfSObject_var aList = SMESH_Gen_i::getStudyServant()->FindObjectByName( theName, "GEOM" );
+    if ( aList->length() == 0 )
+      aList = SMESH_Gen_i::getStudyServant()->FindObjectByName( theName, "SHAPERSTUDY" );
+    if ( aList->length() > 0 )
     {
-      SALOMEDS::Study::ListOfSObject_var aList = aStudy->FindObjectByName( theName, "GEOM" );
-      if ( aList->length() > 0 )
-      {
-        CORBA::Object_var        anObj = aList[ 0 ]->GetObject();
-        GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
-        TopoDS_Shape             shape = aSMESHGen->GeomObjectToShape( aGeomObj );
-        SALOME::UnRegister( aList ); // UnRegister() objects in aList
-        return shape;
-      }
+      CORBA::Object_var        anObj = aList[ 0 ]->GetObject();
+      GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow( anObj );
+      TopoDS_Shape             shape = aSMESHGen->GeomObjectToShape( aGeomObj );
+      SALOME::UnRegister( aList ); // UnRegister() objects in aList
+      return shape;
     }
   }
   return TopoDS_Shape();
@@ -511,34 +155,27 @@ static TopoDS_Shape getShapeByID (const char* theID)
 {
   if ( theID && strlen( theID ) > 0 ) {
     SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-    if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
-      if ( !aSObj->_is_nil() ) {
-        CORBA::Object_var          obj = aSObj->GetObject();
-        GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
-        return aSMESHGen->GeomObjectToShape( aGeomObj );
-      }
+    SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
+    if ( !aSObj->_is_nil() ) {
+      CORBA::Object_var          obj = aSObj->GetObject();
+      GEOM::GEOM_Object_var aGeomObj = GEOM::GEOM_Object::_narrow(obj);
+      return aSMESHGen->GeomObjectToShape( aGeomObj );
     }
   }
   return TopoDS_Shape();
 }
 
-static std::string getShapeNameByID (const char* theID)
-{
-  if ( theID && strlen( theID ) > 0 ) {
-    SMESH_Gen_i*     aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-    SALOMEDS::Study_var aStudy = aSMESHGen->GetCurrentStudy();
-    if ( !aStudy->_is_nil() ) {
-      SALOMEDS::SObject_wrap aSObj = aStudy->FindObjectID(theID);
-      if ( !aSObj->_is_nil() ) {
-        CORBA::String_var name = aSObj->GetName();
-        return name.in();
-      }
-    }
-  }
-  return "";
-}
+// static std::string getShapeNameByID (const char* theID)
+// {
+//   if ( theID && strlen( theID ) > 0 ) {
+//     SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID(theID);
+//     if ( !aSObj->_is_nil() ) {
+//       CORBA::String_var name = aSObj->GetName();
+//       return name.in();
+//     }
+//   }
+//   return "";
+// }
 
 /*
                                 FUNCTORS
@@ -546,7 +183,7 @@ static std::string getShapeNameByID (const char* theID)
 
 /*
   Class       : Functor_i
-  Description : An abstact class for all functors
+  Description : An abstract class for all functors
 */
 Functor_i::Functor_i():
   SALOME::GenericObj_i( SMESH_Gen_i::GetPOA() )
@@ -582,6 +219,11 @@ CORBA::Double NumericalFunctor_i::GetValue( CORBA::Long theId )
   return myNumericalFunctorPtr->GetValue( theId );
 }
 
+CORBA::Boolean NumericalFunctor_i::IsApplicable( CORBA::Long theElementId )
+{
+  return myNumericalFunctorPtr->IsApplicable( theElementId );
+}
+
 SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, CORBA::Boolean isLogarithmic)
 {
   std::vector<int> nbEvents;
@@ -622,6 +264,7 @@ SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short
        SMESH::DownCast< SMESH::Filter_i* >( object ))
   {
     elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
+    if ( !elemIt ) return histogram._retn();
   }
   else
   {
@@ -863,7 +506,6 @@ FunctorType Length2D_i::GetFunctorType()
 
 SMESH::Length2D::Values* Length2D_i::GetValues()
 {
-  INFOS("Length2D_i::GetValues");
   SMESH::Controls::Length2D::TValues aValues;
   (dynamic_cast<SMESH::Controls::Length2D*>(myFunctorPtr.get()))->GetValues( aValues );
 
@@ -883,10 +525,64 @@ SMESH::Length2D::Values* Length2D_i::GetValues()
     aValue.myPnt2 = aVal.myPntId[ 1 ];
   }
 
-  INFOS("Length2D_i::GetValuess~");
   return aResult._retn();
 }
 
+
+/*
+  Class       : Length3D_i
+  Description : Functor for calculating length of edge
+*/
+Length3D_i::Length3D_i()
+{
+  myNumericalFunctorPtr.reset( new Controls::Length3D() );
+  myFunctorPtr = myNumericalFunctorPtr;
+}
+
+FunctorType Length3D_i::GetFunctorType()
+{
+  return SMESH::FT_Length3D;
+}
+
+// SMESH::Length3D::Values* Length3D_i::GetValues()
+// {
+//   SMESH::Controls::Length3D::TValues aValues;
+//   (dynamic_cast<SMESH::Controls::Length3D*>(myFunctorPtr.get()))->GetValues( aValues );
+
+//   long i = 0, iEnd = aValues.size();
+
+//   SMESH::Length3D::Values_var aResult = new SMESH::Length3D::Values(iEnd);
+//   aResult->length(iEnd);
+
+//   SMESH::Controls::Length3D::TValues::const_iterator anIter;
+//   for ( anIter = aValues.begin() ; anIter != aValues.end(); anIter++, i++ )
+//   {
+//     const SMESH::Controls::Length3D::Value&  aVal = *anIter;
+//     SMESH::Length3D::Value &aValue = aResult[ i ];
+
+//     aValue.myLength = aVal.myLength;
+//     aValue.myPnt1 = aVal.myPntId[ 0 ];
+//     aValue.myPnt2 = aVal.myPntId[ 1 ];
+//   }
+
+//   return aResult._retn();
+// }
+
+/*
+  Class       : Deflection2D_i
+  Description : Functor for calculating distance between a face and geometry
+*/
+Deflection2D_i::Deflection2D_i()
+{
+  myNumericalFunctorPtr.reset( new Controls::Deflection2D() );
+  myFunctorPtr = myNumericalFunctorPtr;
+}
+
+FunctorType Deflection2D_i::GetFunctorType()
+{
+  return SMESH::FT_Deflection2D;
+}
+
 /*
   Class       : MultiConnection_i
   Description : Functor for calculating number of faces conneted to the edge
@@ -917,6 +613,21 @@ FunctorType BallDiameter_i::GetFunctorType()
   return SMESH::FT_BallDiameter;
 }
 
+/*
+  Class       : NodeConnectivityNumber_i
+  Description : Functor returning diameter of a ball element
+*/
+NodeConnectivityNumber_i::NodeConnectivityNumber_i()
+{
+  myNumericalFunctorPtr.reset( new Controls::NodeConnectivityNumber() );
+  myFunctorPtr = myNumericalFunctorPtr;
+}
+
+FunctorType NodeConnectivityNumber_i::GetFunctorType()
+{
+  return SMESH::FT_NodeConnectivityNumber;
+}
+
 /*
   Class       : MultiConnection2D_i
   Description : Functor for calculating number of faces conneted to the edge
@@ -934,7 +645,6 @@ FunctorType MultiConnection2D_i::GetFunctorType()
 
 SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
 {
-  INFOS("MultiConnection2D_i::GetValues");
   SMESH::Controls::MultiConnection2D::MValues aValues;
   (dynamic_cast<SMESH::Controls::MultiConnection2D*>(myFunctorPtr.get()))->GetValues( aValues );
   
@@ -954,7 +664,6 @@ SMESH::MultiConnection2D::Values* MultiConnection2D_i::GetValues()
     aValue.myNbConnects = (*anIter).second;
   }
 
-  INFOS("Multiconnection2D_i::GetValuess~");
   return aResult._retn();
 }
 
@@ -1076,6 +785,104 @@ FunctorType OverConstrainedFace_i::GetFunctorType()
   return SMESH::FT_OverConstrainedFace;
 }
 
+/*
+  Class       : BelongToMeshGroup_i
+  Description : Verify whether a mesh element is included into a mesh group
+*/
+BelongToMeshGroup_i::BelongToMeshGroup_i()
+{
+  myBelongToMeshGroup = Controls::BelongToMeshGroupPtr( new Controls::BelongToMeshGroup() );
+  myFunctorPtr = myPredicatePtr = myBelongToMeshGroup;
+}
+
+BelongToMeshGroup_i::~BelongToMeshGroup_i()
+{
+  SetGroup( SMESH::SMESH_GroupBase::_nil() );
+}
+
+void BelongToMeshGroup_i::SetGroup( SMESH::SMESH_GroupBase_ptr theGroup )
+{
+  if ( myGroup->_is_equivalent( theGroup ))
+    return;
+
+  if ( ! myGroup->_is_nil() )
+    myGroup->UnRegister();
+
+  myGroup = SMESH_GroupBase::_duplicate( theGroup );
+
+  myBelongToMeshGroup->SetGroup( 0 );
+  if ( SMESH_GroupBase_i* gr_i = SMESH::DownCast< SMESH_GroupBase_i* >( myGroup ))
+  {
+    myBelongToMeshGroup->SetGroup( gr_i->GetGroupDS() );
+    myGroup->Register();
+  }
+}
+
+void BelongToMeshGroup_i::SetGroupID( const char* theID ) // IOR or StoreName
+{
+  myID = theID;
+  if ( strncmp( "IOR:", myID.c_str(), 4 ) == 0 ) // transient mode, no GUI
+  {
+    CORBA::Object_var obj = SMESH_Gen_i::GetORB()->string_to_object( myID.c_str() );
+    SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
+  }
+  else if ( strncmp( "0:", myID.c_str(), 2 ) == 0 ) // transient mode + GUI
+  {
+    SALOMEDS::SObject_wrap aSObj = SMESH_Gen_i::getStudyServant()->FindObjectID( myID.c_str() );
+    if ( !aSObj->_is_nil() ) {
+      CORBA::Object_var obj = aSObj->GetObject();
+      SetGroup( SMESH::SMESH_GroupBase::_narrow( obj ));
+    }
+  }
+  else if ( !myID.empty() ) // persistent mode
+  {
+    myBelongToMeshGroup->SetStoreName( myID );
+  }
+}
+
+std::string BelongToMeshGroup_i::GetGroupID()
+{
+  if ( myGroup->_is_nil() )
+    SMESH::SMESH_GroupBase_var( GetGroup() );
+
+  if ( !myGroup->_is_nil() )
+    myID = SMESH_Gen_i::GetORB()->object_to_string( myGroup );
+
+  return myID;
+}
+
+SMESH::SMESH_GroupBase_ptr BelongToMeshGroup_i::GetGroup()
+{
+  if ( myGroup->_is_nil() && myBelongToMeshGroup->GetGroup() )
+  {
+    // search for a group in a current study
+    SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
+    if ( StudyContext*  sc = aSMESHGen->GetStudyContext() )
+    {
+      int id = 1;
+      std::string ior;
+      while (true)
+      {
+        ior = sc->getIORbyId( id++ );
+        if ( ior.empty() ) break;
+        CORBA::Object_var obj = aSMESHGen->GetORB()->string_to_object( ior.c_str() );
+        if ( SMESH_GroupBase_i* g_i = SMESH::DownCast<SMESH_GroupBase_i*>( obj ))
+          if ( g_i->GetGroupDS() == myBelongToMeshGroup->GetGroup() )
+          {
+            SetGroup( g_i->_this() );
+            break;
+          }
+      }
+    }
+  }
+  return SMESH::SMESH_GroupBase::_duplicate( myGroup );
+}
+
+FunctorType BelongToMeshGroup_i::GetFunctorType()
+{
+  return SMESH::FT_BelongToMeshGroup;
+}
+
 /*
   Class       : BelongToGeom_i
   Description : Predicate for selection on geometrical support
@@ -1090,17 +897,15 @@ BelongToGeom_i::BelongToGeom_i()
 
 BelongToGeom_i::~BelongToGeom_i()
 {
-  delete myShapeName;
-  delete myShapeID;
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID );
 }
 
 void BelongToGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
 {
   if ( theGeom->_is_nil() )
     return;
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
-  TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
+  TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
   myBelongToGeomPtr->SetGeom( aLocShape );
   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
 }
@@ -1110,7 +915,8 @@ void BelongToGeom_i::SetGeom( const TopoDS_Shape& theShape )
   myBelongToGeomPtr->SetGeom( theShape );
 }
 
-void BelongToGeom_i::SetElementType(ElementType theType){
+void BelongToGeom_i::SetElementType(ElementType theType)
+{
   myBelongToGeomPtr->SetType(SMDSAbs_ElementType(theType));
   TPythonDump()<<this<<".SetElementType("<<theType<<")";
 }
@@ -1122,26 +928,33 @@ FunctorType BelongToGeom_i::GetFunctorType()
 
 void BelongToGeom_i::SetShapeName( const char* theName )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
+  CORBA::string_free( myShapeName );
+  myShapeName = CORBA::string_dup( theName );
   myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
 }
 
 void BelongToGeom_i::SetShape( const char* theID, const char* theName )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
-  delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID );
+  myShapeName = CORBA::string_dup( theName );
+  myShapeID   = CORBA::string_dup( theID );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0] );
 
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myBelongToGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myBelongToGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myBelongToGeomPtr->SetGeom( S );
 }
 
 char* BelongToGeom_i::GetShapeName()
@@ -1180,17 +993,15 @@ BelongToSurface_i::BelongToSurface_i( const Handle(Standard_Type)& theSurfaceTyp
 
 BelongToSurface_i::~BelongToSurface_i()
 {
-  delete myShapeName;
-  delete myShapeID;
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID );
 }
 
 void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType theType )
 {
   if ( theGeom->_is_nil() )
     return;
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
-  TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
+  TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
 
   if ( aLocShape.ShapeType() == TopAbs_FACE )
   {
@@ -1207,26 +1018,33 @@ void BelongToSurface_i::SetSurface( GEOM::GEOM_Object_ptr theGeom, ElementType t
 
 void BelongToSurface_i::SetShapeName( const char* theName, ElementType theType )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
+  CORBA::string_free( myShapeName );
+  myShapeName = CORBA::string_dup( theName );
   myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
   TPythonDump()<<this<<".SetShapeName('"<<theName<<"',"<<theType<<")";
 }
 
 void BelongToSurface_i::SetShape( const char* theID,  const char* theName, ElementType theType )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
-  delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
-  
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myElementsOnSurfacePtr->SetSurface( getShapeByID(myShapeID), (SMDSAbs_ElementType)theType );
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID );
+  myShapeName = CORBA::string_dup( theName );
+  myShapeID   = CORBA::string_dup( theID );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0] );
+
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myElementsOnSurfacePtr->SetSurface( getShapeByName( myShapeName ), (SMDSAbs_ElementType)theType );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myElementsOnSurfacePtr->SetSurface( S, (SMDSAbs_ElementType)theType );
 }
 
 char* BelongToSurface_i::GetShapeName()
@@ -1345,17 +1163,15 @@ LyingOnGeom_i::LyingOnGeom_i()
 
 LyingOnGeom_i::~LyingOnGeom_i()
 {
-  delete myShapeName;
-  delete myShapeID;
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID );
 }
 
 void LyingOnGeom_i::SetGeom( GEOM::GEOM_Object_ptr theGeom )
 {
   if ( theGeom->_is_nil() )
     return;
-  SMESH_Gen_i* aSMESHGen = SMESH_Gen_i::GetSMESHGen();
-  GEOM::GEOM_Gen_ptr aGEOMGen = SMESH_Gen_i::GetGeomEngine();
-  TopoDS_Shape aLocShape = aSMESHGen->GetShapeReader()->GetShape( aGEOMGen, theGeom );
+  TopoDS_Shape aLocShape = SMESH_Gen_i::GetSMESHGen()->GeomObjectToShape( theGeom );
   myLyingOnGeomPtr->SetGeom( aLocShape );
   TPythonDump()<<this<<".SetGeom("<<theGeom<<")";
 }
@@ -1377,26 +1193,33 @@ FunctorType LyingOnGeom_i::GetFunctorType()
 
 void LyingOnGeom_i::SetShapeName( const char* theName )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
+  CORBA::string_free( myShapeName );
+  myShapeName = CORBA::string_dup( theName );
   myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
   TPythonDump()<<this<<".SetShapeName('"<<theName<<"')";
 }
 
 void LyingOnGeom_i::SetShape( const char* theID, const char* theName )
 {
-  delete myShapeName;
-  myShapeName = strdup( theName );
-  delete myShapeID;
-  if ( theID )
-    myShapeID = strdup( theID );
-  else
-    myShapeID = 0;
-  
-  if ( myShapeID && myShapeName == getShapeNameByID(myShapeID))
-    myLyingOnGeomPtr->SetGeom( getShapeByID(myShapeID) );
+  CORBA::string_free( myShapeName );
+  CORBA::string_free( myShapeID   );
+  myShapeName = CORBA::string_dup( theName );
+  myShapeID   = CORBA::string_dup( theID   );
+  bool hasName = ( theName && theName[0] );
+  bool hasID   = ( theID   && theID[0]   );
+
+  TopoDS_Shape S;
+  if ( hasName && hasID )
+  {
+    S = getShapeByID( myShapeID );
+    if ( S.IsNull() )
+      S = getShapeByName( myShapeName );
+  }
   else
-    myLyingOnGeomPtr->SetGeom( getShapeByName( myShapeName ) );
+  {
+    S = hasID ? getShapeByID( myShapeID ) : getShapeByName( myShapeName );
+  }
+  myLyingOnGeomPtr->SetGeom( S );
 }
 
 char* LyingOnGeom_i::GetShapeName()
@@ -1447,7 +1270,6 @@ FreeEdges_i::FreeEdges_i()
 
 SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
 {
-  INFOS("FreeEdges_i::GetBorders");
   SMESH::Controls::FreeEdges::TBorders aBorders;
   myFreeEdgesPtr->GetBoreders( aBorders );
 
@@ -1466,8 +1288,6 @@ SMESH::FreeEdges::Borders* FreeEdges_i::GetBorders()
     aBorder.myPnt1 = aBord.myPntId[ 0 ];
     aBorder.myPnt2 = aBord.myPntId[ 1 ];
   }
-
-  INFOS("FreeEdges_i::GetBorders~");
   return aResult._retn();
 }
 
@@ -1648,7 +1468,7 @@ FunctorType LinearOrQuadratic_i::GetFunctorType()
 
 /*
   Class       : GroupColor_i
-  Description : Functor for check color of group to whic mesh element belongs to
+  Description : Functor for check color of group to which mesh element belongs to
 */
 GroupColor_i::GroupColor_i()
 {
@@ -1864,7 +1684,7 @@ void ConnectedElements_i::SetThreshold ( const char*
   {
   case SMESH::ConnectedElements::POINT: // read 3 node coordinates ///////////////////
     {
-      vector< double > xyz;
+      std::vector< double > xyz;
       char* endptr;
       do
       {
@@ -1896,16 +1716,12 @@ void ConnectedElements_i::SetThreshold ( const char*
     }
   case SMESH::ConnectedElements::VERTEX: // get a VERTEX by its entry /////////////////
     {
-      SALOMEDS::Study_var study = SMESH_Gen_i::GetSMESHGen()->GetCurrentStudy();
-      if ( study->_is_nil() )
-        THROW_SALOME_CORBA_EXCEPTION
-          ( "ConnectedElements_i::SetThreshold(): NULL current study", SALOME::BAD_PARAM );
-      SALOMEDS::SObject_wrap sobj = study->FindObjectID( threshold );
+      SALOMEDS::SObject_wrap sobj = SMESH_Gen_i::getStudyServant()->FindObjectID( threshold );
       if ( sobj->_is_nil() )
         THROW_SALOME_CORBA_EXCEPTION
           ( "ConnectedElements_i::SetThreshold(): invalid vertex study entry", SALOME::BAD_PARAM );
-      CORBA::Object_var         obj = sobj->GetObject();
-      GEOM::GEOM_Object_wrap vertex = GEOM::GEOM_Object::_narrow( obj );
+      CORBA::Object_var        obj = sobj->GetObject();
+      GEOM::GEOM_Object_var vertex = GEOM::GEOM_Object::_narrow( obj );
       if ( vertex->_is_nil() )
         THROW_SALOME_CORBA_EXCEPTION
           ( "ConnectedElements_i::SetThreshold(): no GEOM_Object in SObject", SALOME::BAD_PARAM );
@@ -2066,9 +1882,9 @@ FunctorType EqualTo_i::GetFunctorType()
   Class       : LogicalNOT_i
   Description : Logical NOT predicate
 */
-LogicalNOT_i::LogicalNOT_i()
-: myPredicate( NULL ),
-  myLogicalNOTPtr( new Controls::LogicalNOT() )
+LogicalNOT_i::LogicalNOT_i():
+  myLogicalNOTPtr( new Controls::LogicalNOT() ),
+  myPredicate( NULL )
 {
   myFunctorPtr = myPredicatePtr = myLogicalNOTPtr;
 }
@@ -2104,6 +1920,7 @@ Predicate_i* LogicalNOT_i::GetPredicate_i()
 }
 
 
+
 /*
   Class       : LogicalBinary_i
   Description : Base class for binary logical predicate
@@ -2331,6 +2148,22 @@ Length2D_ptr FilterManager_i::CreateLength2D()
   return anObj._retn();
 }
 
+Length3D_ptr FilterManager_i::CreateLength3D()
+{
+  SMESH::Length3D_i* aServant = new SMESH::Length3D_i();
+  SMESH::Length3D_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateLength3D()";
+  return anObj._retn();
+}
+
+Deflection2D_ptr FilterManager_i::CreateDeflection2D()
+{
+  SMESH::Deflection2D_i* aServant = new SMESH::Deflection2D_i();
+  SMESH::Deflection2D_var   anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateDeflection2D()";
+  return anObj._retn();
+}
+
 MultiConnection_ptr FilterManager_i::CreateMultiConnection()
 {
   SMESH::MultiConnection_i* aServant = new SMESH::MultiConnection_i();
@@ -2355,6 +2188,22 @@ BallDiameter_ptr FilterManager_i::CreateBallDiameter()
   return anObj._retn();
 }
 
+NodeConnectivityNumber_ptr FilterManager_i::CreateNodeConnectivityNumber()
+{
+  SMESH::NodeConnectivityNumber_i* aServant = new SMESH::NodeConnectivityNumber_i();
+  SMESH::NodeConnectivityNumber_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateNodeConnectivityNumber()";
+  return anObj._retn();
+}
+
+BelongToMeshGroup_ptr FilterManager_i::CreateBelongToMeshGroup()
+{
+  SMESH::BelongToMeshGroup_i* aServant = new SMESH::BelongToMeshGroup_i();
+  SMESH::BelongToMeshGroup_var anObj = aServant->_this();
+  TPythonDump()<<aServant<<" = "<<this<<".CreateBelongToMeshGroup()";
+  return anObj._retn();
+}
+
 BelongToGeom_ptr FilterManager_i::CreateBelongToGeom()
 {
   SMESH::BelongToGeom_i* aServant = new SMESH::BelongToGeom_i();
@@ -2671,7 +2520,8 @@ Filter_i::~Filter_i()
   if(!CORBA::is_nil(myMesh))
     myMesh->UnRegister();
 
-  //TPythonDump()<<this<<".UnRegister()";
+  myPredicate = 0;
+  FindBaseObjects();
 }
 
 //=======================================================================
@@ -2693,9 +2543,7 @@ void Filter_i::SetPredicate( Predicate_ptr thePredicate )
       myPredicate->GetPredicate()->SetMesh( aMesh );
     TPythonDump()<<this<<".SetPredicate("<<myPredicate<<")";
   }
-  std::list<TPredicateChangeWaiter*>::iterator i = myWaiters.begin();
-  for ( ; i != myWaiters.end(); ++i )
-    (*i)->PredicateChanged();
+  NotifyerAndWaiter::Modified();
 }
 
 //=======================================================================
@@ -2767,6 +2615,7 @@ GetElementsId( SMESH_Mesh_ptr theMesh )
 {
   SMESH::long_array_var anArray = new SMESH::long_array;
   if(!CORBA::is_nil(theMesh) && myPredicate){
+    theMesh->Load();
     Controls::Filter::TIdSequence aSequence;
     GetElementsId(myPredicate,theMesh,aSequence);
     long i = 0, iEnd = aSequence.size();
@@ -2777,6 +2626,36 @@ GetElementsId( SMESH_Mesh_ptr theMesh )
   return anArray._retn();
 }
 
+SMESH::long_array*
+Filter_i::
+GetElementsIdFromParts( const ListOfIDSources& theParts )
+{
+  SMESH::long_array_var array = new SMESH::long_array;
+  if ( theParts.length() > 0 && myPredicate )
+  {
+    SMESH_Mesh_ptr mesh = theParts[0]->GetMesh();
+    mesh->Load();
+    const SMDS_Mesh* meshDS = MeshPtr2SMDSMesh( mesh );
+    Controls::Filter::TIdSequence totalSequence;
+    for ( CORBA::ULong i = 0; i < theParts.length(); ++i )
+    {
+      if ( SMESH::Filter_i* filter = SMESH::DownCast<SMESH::Filter_i*>( theParts[i] ))
+        filter->SetMesh( mesh );
+      SMDS_ElemIteratorPtr iter = SMESH_Mesh_i::GetElements( theParts[i], GetElementType() );
+      if ( iter && meshDS )
+      {
+        Controls::Filter::TIdSequence sequence;
+        Controls::Filter::GetElementsId( meshDS, myPredicate->GetPredicate(), sequence, iter );
+        totalSequence.insert( totalSequence.end(), sequence.begin(), sequence.end() );
+      }
+    }
+    array->length( totalSequence.size() );
+    for ( size_t i = 0; i < totalSequence.size(); ++i )
+      array[ i ] = totalSequence[ i ];
+  }
+  return array._retn();
+}
+
 //=============================================================================
 /*!
  * \brief Returns number of mesh elements per each \a EntityType
@@ -2871,27 +2750,45 @@ SMESH::SMESH_Mesh_ptr Filter_i::GetMesh()
   return SMESH_Mesh::_duplicate( myMesh );
 }
 
-//================================================================================
-/*!
- * \brief Stores an object to be notified on change of predicate
- */
-//================================================================================
+//=======================================================================
+//function : GetVtkUgStream
+//purpose  : Return data vtk unstructured grid (not implemented)
+//=======================================================================
 
-void Filter_i::AddWaiter( TPredicateChangeWaiter* waiter )
+SALOMEDS::TMPFile* Filter_i::GetVtkUgStream()
 {
-  if ( waiter )
-    myWaiters.push_back( waiter );
+  SALOMEDS::TMPFile_var SeqFile;
+  return SeqFile._retn();
 }
-
-//================================================================================
-/*!
- * \brief Removes an object to be notified on change of predicate
- */
-//================================================================================
-
-void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
+//=======================================================================
+// name    : getCriteria
+// Purpose : Retrieve criterions from predicate
+//=======================================================================
+static inline void getPrediacates( Predicate_i*                thePred,
+                                   std::vector<Predicate_i*> & thePredVec )
 {
-  myWaiters.remove( waiter );
+  const int aFType = thePred->GetFunctorType();
+
+  switch ( aFType )
+  {
+  case FT_LogicalNOT:
+  {
+    Predicate_i* aPred = ( dynamic_cast<LogicalNOT_i*>( thePred ) )->GetPredicate_i();
+    getPrediacates( aPred, thePredVec );
+    break;
+  }
+  case FT_LogicalAND:
+  case FT_LogicalOR:
+  {
+    Predicate_i* aPred1 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate1_i();
+    Predicate_i* aPred2 = ( dynamic_cast<LogicalBinary_i*>( thePred ) )->GetPredicate2_i();
+    getPrediacates( aPred1, thePredVec );
+    getPrediacates( aPred2, thePredVec );
+    break;
+   }
+  default:;
+  }
+  thePredVec.push_back( thePred );
 }
 
 //=======================================================================
@@ -2901,7 +2798,7 @@ void Filter_i::RemoveWaiter( TPredicateChangeWaiter* waiter )
 static inline bool getCriteria( Predicate_i*                thePred,
                                 SMESH::Filter::Criteria_out theCriteria )
 {
-  int aFType = thePred->GetFunctorType();
+  const int aFType = thePred->GetFunctorType();
 
   switch ( aFType )
   {
@@ -2955,6 +2852,17 @@ static inline bool getCriteria( Predicate_i*                thePred,
     {
       return true;
     }
+  case FT_BelongToMeshGroup:
+    {
+      BelongToMeshGroup_i* aPred = dynamic_cast<BelongToMeshGroup_i*>( thePred );
+      SMESH::SMESH_GroupBase_var grp = aPred->GetGroup();
+      if ( !grp->_is_nil() )
+      {
+        theCriteria[ i ].ThresholdStr = grp->GetName();
+        theCriteria[ i ].ThresholdID  = aPred->GetGroupID().c_str();
+      }
+      return true;
+    }
   case FT_BelongToGeom:
     {
       BelongToGeom_i* aPred = dynamic_cast<BelongToGeom_i*>( thePred );
@@ -3070,8 +2978,7 @@ CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
 //=======================================================================
 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria )
 {
-  if ( myPredicate != 0 )
-    myPredicate->UnRegister();
+  SetPredicate( SMESH::Predicate::_nil() );
 
   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
   FilterManager_ptr aFilterMgr = aFilter->_this();
@@ -3130,6 +3037,12 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
       case SMESH::FT_Length2D:
         aFunctor = aFilterMgr->CreateLength2D();
         break;
+      case SMESH::FT_Length3D:
+        aFunctor = aFilterMgr->CreateLength3D();
+        break;
+      case SMESH::FT_Deflection2D:
+        aFunctor = aFilterMgr->CreateDeflection2D();
+        break;
       case SMESH::FT_AspectRatio:
         aFunctor = aFilterMgr->CreateAspectRatio();
         break;
@@ -3163,6 +3076,9 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
       case SMESH::FT_BallDiameter:
         aFunctor = aFilterMgr->CreateBallDiameter();
         break;
+      case SMESH::FT_NodeConnectivityNumber:
+        aFunctor = aFilterMgr->CreateNodeConnectivityNumber();
+        break;
 
       // Predicates
 
@@ -3194,6 +3110,13 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
       case SMESH::FT_EqualVolumes:
         aPredicate = aFilterMgr->CreateEqualVolumes();
         break;
+      case SMESH::FT_BelongToMeshGroup:
+        {
+          SMESH::BelongToMeshGroup_ptr tmpPred = aFilterMgr->CreateBelongToMeshGroup();
+          tmpPred->SetGroupID( aThresholdID );
+          aPredicate = tmpPred;
+        }
+        break;
       case SMESH::FT_BelongToGeom:
         {
           SMESH::BelongToGeom_ptr tmpPred = aFilterMgr->CreateBelongToGeom();
@@ -3375,6 +3298,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
 
   SMESH::Predicate_ptr aPrevPredicate = SMESH::Predicate::_nil();
   int aPrevBinary = SMESH::FT_Undefined;
+  if ( !aBinaries.empty() )
+    aBinaries.back() = SMESH::FT_Undefined;
 
   for ( aPredIter = aPredicates.begin(), aBinaryIter = aBinaries.begin();
         aPredIter != aPredicates.end() && aBinaryIter != aBinaries.end();
@@ -3423,6 +3348,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
   }
 
   SetPredicate( aResPredicate );
+  if ( !aResPredicate->_is_nil() )
+    aResPredicate->UnRegister();
 
   return !aResPredicate->_is_nil();
 }
@@ -3453,6 +3380,75 @@ Predicate_ptr Filter_i::GetPredicate()
   }
 }
 
+//================================================================================
+/*!
+ * \brief Find groups it depends on
+ */
+//================================================================================
+
+void Filter_i::FindBaseObjects()
+{
+  // release current groups
+  for ( size_t i = 0; i < myBaseGroups.size(); ++i )
+    if ( myBaseGroups[i] )
+    {
+      myBaseGroups[i]->RemoveModifWaiter( this );
+      myBaseGroups[i]->UnRegister();
+    }
+
+  // remember new groups
+  myBaseGroups.clear();
+  if ( myPredicate )
+  {
+    std::vector<Predicate_i*> predicates;
+    getPrediacates( myPredicate, predicates );
+    for ( size_t i = 0; i < predicates.size(); ++i )
+      if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
+      {
+        SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
+        SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
+        if ( g_i )
+        {
+          g_i->AddModifWaiter( this );
+          g_i->Register();
+          myBaseGroups.push_back( g_i );
+        }
+      }
+  }
+}
+
+//================================================================================
+/*!
+ * \brief When notified on removal of myBaseGroups[i], remove a reference to a
+ *        group from a predicate
+ */
+//================================================================================
+
+void Filter_i::OnBaseObjModified(NotifyerAndWaiter* group, bool removed)
+{
+  if ( !removed )
+    return; // a GroupOnFilter holding this filter is notified automatically
+
+  if ( myPredicate )
+  {
+    std::vector<Predicate_i*> predicates;
+    getPrediacates( myPredicate, predicates );
+    for ( size_t i = 0; i < predicates.size(); ++i )
+      if ( BelongToMeshGroup_i* bmg = dynamic_cast< BelongToMeshGroup_i* >( predicates[i] ))
+      {
+        SMESH::SMESH_GroupBase_var g = bmg->GetGroup();
+        SMESH_GroupBase_i* g_i = SMESH::DownCast< SMESH_GroupBase_i*>( g );
+        if ( g_i == group )
+        {
+          bmg->SetGroup( SMESH::SMESH_GroupBase::_nil() );
+          bmg->SetGroupID( "" );
+        }
+      }
+  }
+
+  FindBaseObjects(); // release and update myBaseGroups;
+}
+
 /*
                             FILTER LIBRARY
 */
@@ -3512,50 +3508,53 @@ static inline LDOMString toString( CORBA::Long theType )
 {
   switch ( theType )
   {
-    case FT_AspectRatio     : return "Aspect ratio";
-    case FT_Warping         : return "Warping";
-    case FT_MinimumAngle    : return "Minimum angle";
-    case FT_Taper           : return "Taper";
-    case FT_Skew            : return "Skew";
-    case FT_Area            : return "Area";
-    case FT_Volume3D        : return "Volume3D";
-    case FT_MaxElementLength2D: return "Max element length 2D";
-    case FT_MaxElementLength3D: return "Max element length 3D";
-    case FT_BelongToGeom    : return "Belong to Geom";
-    case FT_BelongToPlane   : return "Belong to Plane";
-    case FT_BelongToCylinder: return "Belong to Cylinder";
-    case FT_BelongToGenSurface: return "Belong to Generic Surface";
-    case FT_LyingOnGeom     : return "Lying on Geom";
-    case FT_BadOrientedVolume:return "Bad Oriented Volume";
-    case FT_BareBorderVolume: return "Volumes with bare border";
-    case FT_BareBorderFace  : return "Faces with bare border";
-    case FT_OverConstrainedVolume: return "Over-constrained Volumes";
-    case FT_OverConstrainedFace  : return "Over-constrained Faces";
-    case FT_RangeOfIds      : return "Range of IDs";
-    case FT_FreeBorders     : return "Free borders";
-    case FT_FreeEdges       : return "Free edges";
-    case FT_FreeFaces       : return "Free faces";
-    case FT_FreeNodes       : return "Free nodes";
-    case FT_EqualNodes      : return "Equal nodes";
-    case FT_EqualEdges      : return "Equal edges";
-    case FT_EqualFaces      : return "Equal faces";
-    case FT_EqualVolumes    : return "Equal volumes";
-    case FT_MultiConnection : return "Borders at multi-connections";
-    case FT_MultiConnection2D:return "Borders at multi-connections 2D";
-    case FT_Length          : return "Length";
-    case FT_Length2D        : return "Length 2D";
-    case FT_LessThan        : return "Less than";
-    case FT_MoreThan        : return "More than";
-    case FT_EqualTo         : return "Equal to";
-    case FT_LogicalNOT      : return "Not";
-    case FT_LogicalAND      : return "And";
-    case FT_LogicalOR       : return "Or";
-    case FT_GroupColor      : return "Color of Group";
-    case FT_LinearOrQuadratic : return "Linear or Quadratic";
-    case FT_ElemGeomType    : return "Element geomtry type";
-    case FT_EntityType      : return "Entity type";
-    case FT_Undefined       : return "";
-    default                 : return "";
+    case FT_AspectRatio           : return "Aspect ratio";
+    case FT_Warping               : return "Warping";
+    case FT_MinimumAngle          : return "Minimum angle";
+    case FT_Taper                 : return "Taper";
+    case FT_Skew                  : return "Skew";
+    case FT_Area                  : return "Area";
+    case FT_Volume3D              : return "Volume3D";
+    case FT_MaxElementLength2D    : return "Max element length 2D";
+    case FT_MaxElementLength3D    : return "Max element length 3D";
+    case FT_BelongToMeshGroup     : return "Belong to Mesh Group";
+    case FT_BelongToGeom          : return "Belong to Geom";
+    case FT_BelongToPlane         : return "Belong to Plane";
+    case FT_BelongToCylinder      : return "Belong to Cylinder";
+    case FT_BelongToGenSurface    : return "Belong to Generic Surface";
+    case FT_LyingOnGeom           : return "Lying on Geom";
+    case FT_BadOrientedVolume     : return "Bad Oriented Volume";
+    case FT_BareBorderVolume      : return "Volumes with bare border";
+    case FT_BareBorderFace        : return "Faces with bare border";
+    case FT_OverConstrainedVolume : return "Over-constrained Volumes";
+    case FT_OverConstrainedFace   : return "Over-constrained Faces";
+    case FT_RangeOfIds            : return "Range of IDs";
+    case FT_FreeBorders           : return "Free borders";
+    case FT_FreeEdges             : return "Free edges";
+    case FT_FreeFaces             : return "Free faces";
+    case FT_FreeNodes             : return "Free nodes";
+    case FT_EqualNodes            : return "Equal nodes";
+    case FT_EqualEdges            : return "Equal edges";
+    case FT_EqualFaces            : return "Equal faces";
+    case FT_EqualVolumes          : return "Equal volumes";
+    case FT_MultiConnection       : return "Borders at multi-connections";
+    case FT_MultiConnection2D     : return "Borders at multi-connections 2D";
+    case FT_Length                : return "Length";
+    case FT_Length2D              : return "Length 2D";
+    case FT_Length3D              : return "Length 3D";
+    case FT_Deflection2D          : return "Deflection 2D";
+    case FT_LessThan              : return "Less than";
+    case FT_MoreThan              : return "More than";
+    case FT_EqualTo               : return "Equal to";
+    case FT_LogicalNOT            : return "Not";
+    case FT_LogicalAND            : return "And";
+    case FT_LogicalOR             : return "Or";
+    case FT_GroupColor            : return "Color of Group";
+    case FT_LinearOrQuadratic     : return "Linear or Quadratic";
+    case FT_ElemGeomType          : return "Element geometry type";
+    case FT_EntityType            : return "Entity type";
+    case FT_Undefined             : return "";
+    default                       : return "";
   }
 }
 
@@ -3574,6 +3573,7 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
   else if ( theStr.equals( "Volume3D"                     ) ) return FT_Volume3D;
   else if ( theStr.equals( "Max element length 2D"        ) ) return FT_MaxElementLength2D;
   else if ( theStr.equals( "Max element length 3D"        ) ) return FT_MaxElementLength3D;
+  else if ( theStr.equals( "Belong to Mesh Group"         ) ) return FT_BelongToMeshGroup;
   else if ( theStr.equals( "Belong to Geom"               ) ) return FT_BelongToGeom;
   else if ( theStr.equals( "Belong to Plane"              ) ) return FT_BelongToPlane;
   else if ( theStr.equals( "Belong to Cylinder"           ) ) return FT_BelongToCylinder;
@@ -3591,6 +3591,8 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
   //  else if ( theStr.equals( "Borders at multi-connections 2D" ) ) return FT_MultiConnection2D;
   else if ( theStr.equals( "Length"                       ) ) return FT_Length;
   //  else if ( theStr.equals( "Length2D"                     ) ) return FT_Length2D;
+  //  else if ( theStr.equals( "Length3D"                     ) ) return FT_Length3D;
+  else if ( theStr.equals( "Deflection"                   ) ) return FT_Deflection2D;
   else if ( theStr.equals( "Range of IDs"                 ) ) return FT_RangeOfIds;
   else if ( theStr.equals( "Bad Oriented Volume"          ) ) return FT_BadOrientedVolume;
   else if ( theStr.equals( "Volumes with bare border"     ) ) return FT_BareBorderVolume;
@@ -3605,7 +3607,7 @@ static inline SMESH::FunctorType toFunctorType( const LDOMString& theStr )
   else if ( theStr.equals( "Or"                           ) ) return FT_LogicalOR;
   else if ( theStr.equals( "Color of Group"               ) ) return FT_GroupColor;
   else if ( theStr.equals( "Linear or Quadratic"          ) ) return FT_LinearOrQuadratic;
-  else if ( theStr.equals( "Element geomtry type"         ) ) return FT_ElemGeomType;
+  else if ( theStr.equals( "Element geometry type"        ) ) return FT_ElemGeomType;
   else if ( theStr.equals( "Entity type"                  ) ) return FT_EntityType;
   else if ( theStr.equals( ""                             ) ) return FT_Undefined;
   else  return FT_Undefined;
@@ -3782,7 +3784,7 @@ static LDOM_Element createFilterItem( const char*       theName,
 //=======================================================================
 FilterLibrary_i::FilterLibrary_i( const char* theFileName )
 {
-  myFileName = strdup( theFileName );
+  myFileName = CORBA::string_dup( theFileName );
   SMESH::FilterManager_i* aFilterMgr = new SMESH::FilterManager_i();
   myFilterMgr = aFilterMgr->_this();
 
@@ -3823,7 +3825,7 @@ FilterLibrary_i::FilterLibrary_i()
 
 FilterLibrary_i::~FilterLibrary_i()
 {
-  delete myFileName;
+  CORBA::string_free( myFileName );
   //TPythonDump()<<this<<".UnRegister()";
 }
 
@@ -3875,7 +3877,7 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
     {
       char a[ 255 ];
       sprintf( a, "%d", val );
-      aCriterion.ThresholdStr = strdup( a );
+      aCriterion.ThresholdStr = CORBA::string_dup( a );
     }
     else
       aCriterion.ThresholdStr = str.GetString();
@@ -3906,8 +3908,8 @@ Filter_ptr FilterLibrary_i::Copy( const char* theFilterName )
 //=======================================================================
 void FilterLibrary_i::SetFileName( const char* theFileName )
 {
-  delete myFileName;
-  myFileName = strdup( theFileName );
+  CORBA::string_free( myFileName );
+  myFileName = CORBA::string_dup( theFileName );
   TPythonDump()<<this<<".SetFileName('"<<theFileName<<"')";
 }
 
@@ -4030,14 +4032,15 @@ CORBA::Boolean FilterLibrary_i::Save()
   if ( myFileName == 0 || strlen( myFileName ) == 0 )
     return false;
 
-  FILE* aOutFile = fopen( myFileName, "wt" );
-  if ( !aOutFile )
-    return false;
+  std::filebuf fb;
+  fb.open( myFileName, std::ios::out );
+
+  Standard_OStream os( &fb );
 
-  LDOM_XmlWriter aWriter( aOutFile );
+  LDOM_XmlWriter aWriter;
   aWriter.SetIndentation( 2 );
-  aWriter << myDoc;
-  fclose( aOutFile );
+  aWriter.Write( os, myDoc );
+  fb.close();
 
   TPythonDump()<<this<<".Save()";
   return true;
@@ -4130,7 +4133,7 @@ string_array* FilterLibrary_i::GetAllNames()
 
 static const char** getFunctNames()
 {
-  static const char* functName[ SMESH::FT_Undefined + 1 ] = {
+  static const char* functName[] = {
     // IT's necessary to update this array according to enum FunctorType (SMESH_Filter.idl)
     // The order is IMPORTANT !!!
     "FT_AspectRatio",
@@ -4155,6 +4158,10 @@ static const char** getFunctNames()
     "FT_MultiConnection2D",
     "FT_Length",
     "FT_Length2D",
+    "FT_Length3D",
+    "FT_Deflection2D",
+    "FT_NodeConnectivityNumber",
+    "FT_BelongToMeshGroup",
     "FT_BelongToGeom",
     "FT_BelongToPlane",
     "FT_BelongToCylinder",
@@ -4169,7 +4176,7 @@ static const char** getFunctNames()
     "FT_LinearOrQuadratic",
     "FT_GroupColor",
     "FT_ElemGeomType",
-    "FT_EntityType", 
+    "FT_EntityType",
     "FT_CoplanarFaces",
     "FT_BallDiameter",
     "FT_ConnectedElements",
@@ -4180,6 +4187,13 @@ static const char** getFunctNames()
     "FT_LogicalAND",
     "FT_LogicalOR",
     "FT_Undefined"};
+
+#ifdef _DEBUG_
+  // check if functName is complete, compilation failure means that enum FunctorType changed
+  const int nbFunctors = sizeof(functName) / sizeof(const char*);
+  int _assert[( nbFunctors == SMESH::FT_Undefined + 1 ) ? 2 : -1 ]; _assert[0]=_assert[1]=0;
+#endif
+
   return functName;
 }
 
@@ -4215,3 +4229,62 @@ SMESH::FunctorType SMESH::StringToFunctorType(const char* str)
 
   return SMESH::FunctorType( ft );
 }
+
+//================================================================================
+/*!
+ * \brief calls OnBaseObjModified(), if who != this, and myWaiters[i]->Modified(who)
+ */
+//================================================================================
+
+void NotifyerAndWaiter::Modified( bool removed, NotifyerAndWaiter* who )
+{
+  if ( who != 0 && who != this )
+    OnBaseObjModified( who, removed );
+  else
+    who = this;
+
+  std::list<NotifyerAndWaiter*> waiters = myWaiters; // myWaiters can be changed by Modified()
+  std::list<NotifyerAndWaiter*>::iterator i = waiters.begin();
+  for ( ; i != waiters.end(); ++i )
+    (*i)->Modified( removed, who );
+}
+
+//================================================================================
+/*!
+ * \brief Stores an object to be notified on change of predicate
+ */
+//================================================================================
+
+void NotifyerAndWaiter::AddModifWaiter( NotifyerAndWaiter* waiter )
+{
+  if ( waiter )
+    myWaiters.push_back( waiter );
+}
+
+//================================================================================
+/*!
+ * \brief Removes an object to be notified on change of predicate
+ */
+//================================================================================
+
+void NotifyerAndWaiter::RemoveModifWaiter( NotifyerAndWaiter* waiter )
+{
+  myWaiters.remove( waiter );
+}
+
+//================================================================================
+/*!
+ * \brief Checks if a waiter is among myWaiters, maybe nested
+ */
+//================================================================================
+
+bool NotifyerAndWaiter::ContainModifWaiter( NotifyerAndWaiter* waiter )
+{
+  bool is = ( waiter == this );
+
+  std::list<NotifyerAndWaiter*>::iterator w = myWaiters.begin();
+  for ( ; !is && w != myWaiters.end(); ++w )
+    is = (*w)->ContainModifWaiter( waiter );
+
+  return is;
+}