Salome HOME
52459: Viscous layers are not normal to the surface.
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index 6ab4d0850818ffdd8f84b63bad8f237c458b2ba6..d81f7f667faa5ea81bd417a9acafd1ef577fb002 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2013  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2014  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
 //
 // 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
 // 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
 //
 // This library is distributed in the hope that it will be useful,
 // but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -33,6 +33,7 @@
 #include "SMDS_MeshNode.hxx"
 #include "SMESHDS_Mesh.hxx"
 #include "SMESH_Gen_i.hxx"
 #include "SMDS_MeshNode.hxx"
 #include "SMESHDS_Mesh.hxx"
 #include "SMESH_Gen_i.hxx"
+#include "SMESH_Group_i.hxx"
 #include "SMESH_PythonDump.hxx"
 
 #include <SALOMEDS_wrap.hxx>
 #include "SMESH_PythonDump.hxx"
 
 #include <SALOMEDS_wrap.hxx>
 #include <TColStd_ListOfReal.hxx>
 #include <TColStd_SequenceOfHAsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
 #include <TColStd_ListOfReal.hxx>
 #include <TColStd_SequenceOfHAsciiString.hxx>
 #include <TCollection_HAsciiString.hxx>
-#include <TopExp.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
 #include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
-#include <TopoDS_Face.hxx>
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Shape.hxx>
-#include <TopTools_IndexedMapOfShape.hxx>
 
 using namespace SMESH;
 using namespace SMESH::Controls;
 
 using namespace SMESH;
 using namespace SMESH::Controls;
@@ -74,358 +72,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
 */
 /*
                             AUXILIARY METHODS
 */
@@ -588,12 +234,64 @@ SMESH::Histogram* NumericalFunctor_i::GetHistogram(CORBA::Short nbIntervals, COR
   std::vector<int> elements;
   myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
 
   std::vector<int> elements;
   myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
 
-#ifdef WIN32
-  nbIntervals = CORBA::Short( min( nbEvents.size(), funValues.size() - 1));
-#else
-  nbIntervals = CORBA::Short( std::min( nbEvents.size(), funValues.size() - 1));
-#endif
   SMESH::Histogram_var histogram = new SMESH::Histogram;
   SMESH::Histogram_var histogram = new SMESH::Histogram;
+
+  nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
+                                   int( funValues.size() - 1 )));
+  if ( nbIntervals > 0 )
+  {
+    histogram->length( nbIntervals );
+    for ( int i = 0; i < nbIntervals; ++i )
+    {
+      HistogramRectangle& rect = histogram[i];
+      rect.nbEvents = nbEvents[i];
+      rect.min = funValues[i];
+      rect.max = funValues[i+1];
+    }
+  }
+  return histogram._retn();
+}
+
+SMESH::Histogram* NumericalFunctor_i::GetLocalHistogram(CORBA::Short              nbIntervals,
+                                                        CORBA::Boolean            isLogarithmic,
+                                                        SMESH::SMESH_IDSource_ptr object)
+{
+  SMESH::Histogram_var histogram = new SMESH::Histogram;
+
+  std::vector<int>    nbEvents;
+  std::vector<double> funValues;
+  std::vector<int>    elements;
+
+  SMDS_ElemIteratorPtr elemIt;
+  if ( SMESH::DownCast< SMESH_GroupOnFilter_i* >( object ) ||
+       SMESH::DownCast< SMESH::Filter_i* >( object ))
+  {
+    elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
+    if ( !elemIt ) return histogram._retn();
+  }
+  else
+  {
+    SMESH::SMESH_Mesh_var        mesh = object->GetMesh();
+    SMESH::long_array_var  objNbElems = object->GetNbElementsByType();
+    SMESH::long_array_var meshNbElems = mesh->  GetNbElementsByType();
+    if ( meshNbElems[ GetElementType() ] !=
+         objNbElems [ GetElementType() ] )
+    {
+      elements.reserve( objNbElems[ GetElementType() ]);
+      elemIt = SMESH_Mesh_i::GetElements( object, GetElementType() );
+    }
+  }
+  if ( elemIt )
+  {
+    while ( elemIt->more() )
+      elements.push_back( elemIt->next()->GetID() );
+    if ( elements.empty() ) return histogram._retn();
+  }
+
+  myNumericalFunctorPtr->GetHistogram(nbIntervals,nbEvents,funValues,elements,0,isLogarithmic);
+
+  nbIntervals = CORBA::Short( Min( int( nbEvents.size()),
+                                   int( funValues.size() - 1 )));
   if ( nbIntervals > 0 )
   {
     histogram->length( nbIntervals );
   if ( nbIntervals > 0 )
   {
     histogram->length( nbIntervals );
@@ -920,6 +618,29 @@ CORBA::Boolean Predicate_i::IsSatisfy( CORBA::Long theId )
   return myPredicatePtr->IsSatisfy( theId );
 }
 
   return myPredicatePtr->IsSatisfy( theId );
 }
 
+CORBA::Long Predicate_i::NbSatisfying( SMESH::SMESH_IDSource_ptr obj )
+{
+  SMESH::SMESH_Mesh_var meshVar = obj->GetMesh();
+  const SMDS_Mesh*       meshDS = MeshPtr2SMDSMesh( meshVar );
+  if ( !meshDS )
+    return 0;
+  myPredicatePtr->SetMesh( meshDS );
+
+  SMDSAbs_ElementType elemType = SMDSAbs_ElementType( GetElementType() );
+
+  int nb = 0;
+  SMDS_ElemIteratorPtr elemIt =
+    SMESH::DownCast<SMESH_Mesh_i*>( meshVar )->GetElements( obj, GetElementType() );
+  if ( elemIt )
+    while ( elemIt->more() )
+    {
+      const SMDS_MeshElement* e = elemIt->next();
+      if ( e && e->GetType() == elemType )
+        nb += myPredicatePtr->IsSatisfy( e->GetID() );
+    }
+  return nb;
+}
+
 Controls::PredicatePtr Predicate_i::GetPredicate()
 {
   return myPredicatePtr;
 Controls::PredicatePtr Predicate_i::GetPredicate()
 {
   return myPredicatePtr;
@@ -2702,59 +2423,63 @@ GetElementsId( SMESH_Mesh_ptr theMesh )
   return anArray._retn();
 }
 
   return anArray._retn();
 }
 
-template<class TElement, class TIterator, class TPredicate>
-static void collectMeshInfo(const TIterator& theItr,
-                            TPredicate& thePred,
-                            SMESH::long_array& theRes)
-{         
-  if (!theItr)
-    return;
-  while (theItr->more()) {
-    const SMDS_MeshElement* anElem = theItr->next();
-    if ( thePred->IsSatisfy( anElem->GetID() ) )
-      theRes[ anElem->GetEntityType() ]++;
+//=============================================================================
+/*!
+ * \brief Returns number of mesh elements per each \a EntityType
+ */
+//=============================================================================
+
+SMESH::long_array* ::Filter_i::GetMeshInfo()
+{
+  SMESH::long_array_var aRes = new SMESH::long_array();
+  aRes->length(SMESH::Entity_Last);
+  for (int i = 0; i < SMESH::Entity_Last; i++)
+    aRes[i] = 0;
+
+  if ( !CORBA::is_nil(myMesh) && myPredicate )
+  {
+    const SMDS_Mesh*  aMesh = MeshPtr2SMDSMesh(myMesh);
+    SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
+    while ( it->more() )
+    {
+      const SMDS_MeshElement* anElem = it->next();
+      if ( myPredicate->IsSatisfy( anElem->GetID() ) )
+        aRes[ anElem->GetEntityType() ]++;
+    }
   }
   }
+
+  return aRes._retn();  
 }
 
 //=============================================================================
 /*!
 }
 
 //=============================================================================
 /*!
- * \brief Returns statistic of mesh elements
+ * \brief Returns number of mesh elements of each \a ElementType
  */
 //=============================================================================
  */
 //=============================================================================
-SMESH::long_array* ::Filter_i::GetMeshInfo()
+
+SMESH::long_array* ::Filter_i::GetNbElementsByType()
 {
   SMESH::long_array_var aRes = new SMESH::long_array();
 {
   SMESH::long_array_var aRes = new SMESH::long_array();
-  aRes->length(SMESH::Entity_Last);
-  for (int i = SMESH::Entity_Node; i < SMESH::Entity_Last; i++)
+  aRes->length(SMESH::NB_ELEMENT_TYPES);
+  for (int i = 0; i < SMESH::NB_ELEMENT_TYPES; i++)
     aRes[i] = 0;
 
     aRes[i] = 0;
 
-  if(!CORBA::is_nil(myMesh) && myPredicate) {
-    const SMDS_Mesh* aMesh = MeshPtr2SMDSMesh(myMesh);
-    SMDS_ElemIteratorPtr it;
-    switch( GetElementType() )
+  if ( !CORBA::is_nil(myMesh) && myPredicate ) {
+    const SMDS_Mesh*  aMesh = MeshPtr2SMDSMesh(myMesh);
+    SMDS_ElemIteratorPtr it = aMesh->elementsIterator( SMDSAbs_ElementType( GetElementType() ));
+    CORBA::Long& nbElems = aRes[ GetElementType() ];
+    while ( it->more() )
     {
     {
-    case SMDSAbs_Node:
-      collectMeshInfo<const SMDS_MeshNode*>(aMesh->nodesIterator(),myPredicate,aRes);
-      break;
-    case SMDSAbs_Edge:
-      collectMeshInfo<const SMDS_MeshElement*>(aMesh->edgesIterator(),myPredicate,aRes);
-      break;
-    case SMDSAbs_Face:
-      collectMeshInfo<const SMDS_MeshElement*>(aMesh->facesIterator(),myPredicate,aRes);
-      break;
-    case SMDSAbs_Volume:
-      collectMeshInfo<const SMDS_MeshElement*>(aMesh->volumesIterator(),myPredicate,aRes);
-      break;
-    case SMDSAbs_All:
-    default:
-      collectMeshInfo<const SMDS_MeshElement*>(aMesh->elementsIterator(),myPredicate,aRes);
-      break;
+      const SMDS_MeshElement* anElem = it->next();
+      if ( myPredicate->IsSatisfy( anElem->GetID() ) )
+        nbElems++;
     }
   }
 
   return aRes._retn();  
 }
 
     }
   }
 
   return aRes._retn();  
 }
 
+
 //================================================================================
 /*!
  * \brief Return GetElementType() within an array
 //================================================================================
 /*!
  * \brief Return GetElementType() within an array
@@ -2991,8 +2716,7 @@ CORBA::Boolean Filter_i::GetCriteria( SMESH::Filter::Criteria_out theCriteria )
 //=======================================================================
 CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& 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();
 
   SMESH::FilterManager_i* aFilter = new SMESH::FilterManager_i();
   FilterManager_ptr aFilterMgr = aFilter->_this();
@@ -3344,6 +3068,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
   }
 
   SetPredicate( aResPredicate );
   }
 
   SetPredicate( aResPredicate );
+  if ( !aResPredicate->_is_nil() )
+    aResPredicate->UnRegister();
 
   return !aResPredicate->_is_nil();
 }
 
   return !aResPredicate->_is_nil();
 }