Salome HOME
Copyright update 2021
[modules/smesh.git] / src / SMESH / SMESH_HypoFilter.cxx
index f2aeb9a024a99b62ede198f57754bdd33cd6d17e..cb7ec14e99c142d397d61fd51f8c560faf2b0181 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2021  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
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-//  SMESH SMESH : implementaion of SMESH idl descriptions
+//  SMESH SMESH : implementation of SMESH idl descriptions
 //  File   : SMESH_HypoFilter.cxx
 //  Module : SMESH
 //
 #include "SMESH_HypoFilter.hxx"
 
+#include "SMESHDS_Mesh.hxx"
 #include "SMESH_Gen.hxx"
 #include "SMESH_Hypothesis.hxx"
+#include "SMESH_Mesh.hxx"
 #include "SMESH_MesherHelper.hxx"
 #include "SMESH_subMesh.hxx"
 
@@ -55,7 +57,7 @@ bool SMESH_HypoFilter::NamePredicate::IsOk (const SMESH_Hypothesis* aHyp,
 int SMESH_HypoFilter::TypePredicate::Value( const SMESH_Hypothesis* aHyp ) const
 {
   return aHyp->GetType();
-};
+}
 
 //=======================================================================
 //function : DimPredicate::Value
@@ -75,8 +77,8 @@ int SMESH_HypoFilter::DimPredicate::Value( const SMESH_Hypothesis* aHyp ) const
 bool SMESH_HypoFilter::ApplicablePredicate::IsOk(const SMESH_Hypothesis* aHyp,
                                                  const TopoDS_Shape&     /*aShape*/) const
 {
-  return SMESH_subMesh::IsApplicableHypotesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
-};
+  return SMESH_subMesh::IsApplicableHypothesis( aHyp, (TopAbs_ShapeEnum)_shapeType );
+}
 
 //=======================================================================
 //function : IsAuxiliaryPredicate::IsOk
@@ -87,7 +89,7 @@ bool SMESH_HypoFilter::IsAuxiliaryPredicate::IsOk(const SMESH_Hypothesis* aHyp,
                                                   const TopoDS_Shape&     /*aShape*/) const
 {
   return aHyp->IsAuxiliary();
-};
+}
 
 //=======================================================================
 //function : ApplicablePredicate::ApplicablePredicate
@@ -115,7 +117,7 @@ bool SMESH_HypoFilter::InstancePredicate::IsOk(const SMESH_Hypothesis* aHyp,
 //purpose  : 
 //=======================================================================
 
-bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* aHyp,
+bool SMESH_HypoFilter::IsAssignedToPredicate::IsOk(const SMESH_Hypothesis* /*aHyp*/,
                                                    const TopoDS_Shape&     aShape) const
 {
   return ( !_mainShape.IsNull() && !aShape.IsNull() && _mainShape.IsSame( aShape ));
@@ -154,7 +156,7 @@ void SMESH_HypoFilter::IsMoreLocalThanPredicate::findPreferable()
 
 //=======================================================================
 //function : IsMoreLocalThanPredicate::IsOk
-//purpose  : 
+//purpose  : Check if aShape is more local than this->_shape
 //=======================================================================
 
 bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aHyp,
@@ -167,16 +169,23 @@ bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aH
   if ( SMESH_MesherHelper::IsSubShape( aShape, /*mainShape=*/_shape ))
     return true;
 
-  if ( aShape.ShapeType() == TopAbs_COMPOUND && 
+  if ( aShape.ShapeType() == TopAbs_COMPOUND &&
        !SMESH_MesherHelper::IsSubShape( _shape, /*mainShape=*/aShape)) // issue 0020963
   {
-    for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
-      if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
-        for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
-          if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
-            return true;
+    // [bos#22320] compound of FACEs is MORE local than compound of SOLIDs
+    TopAbs_ShapeEnum givenType = SMESH_MesherHelper::GetGroupType( _shape );
+    TopAbs_ShapeEnum   hypType = SMESH_MesherHelper::GetGroupType( aShape );
+    if ( SMESH_Gen::GetShapeDim( givenType ) > SMESH_Gen::GetShapeDim( hypType ))
+    {
+      for ( int type = TopAbs_SOLID; type < TopAbs_SHAPE; ++type )
+        if ( aHyp->GetDim() == SMESH_Gen::GetShapeDim( TopAbs_ShapeEnum( type )))
+          for ( TopExp_Explorer exp( aShape, TopAbs_ShapeEnum( type )); exp.More(); exp.Next())
+            if ( SMESH_MesherHelper::IsSubShape( exp.Current(), /*mainShape=*/_shape ))
+              return true;
+    }
   }
 
+  // take forced sub-mesh priority into account
   if ( _preferableShapes.Contains( aShape ))
     return true; // issue 21559, Mesh_6
 
@@ -185,7 +194,7 @@ bool SMESH_HypoFilter::IsMoreLocalThanPredicate::IsOk(const SMESH_Hypothesis* aH
 
 //=======================================================================
 //function : SMESH_HypoFilter
-//purpose  : 
+//purpose  :
 //=======================================================================
 
 SMESH_HypoFilter::SMESH_HypoFilter()