Salome HOME
52459: Viscous layers are not normal to the surface.
[modules/smesh.git] / src / SMESH_I / SMESH_Filter_i.cxx
index b7b0e53e1e75b0691300d99ae3a4b5b5a437b204..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
@@ -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
 #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 +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
 */
@@ -622,6 +267,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
   {
@@ -3070,8 +2716,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();
@@ -3423,6 +3068,8 @@ CORBA::Boolean Filter_i::SetCriteria( const SMESH::Filter::Criteria& theCriteria
   }
 
   SetPredicate( aResPredicate );
+  if ( !aResPredicate->_is_nil() )
+    aResPredicate->UnRegister();
 
   return !aResPredicate->_is_nil();
 }