Salome HOME
PAL11992. fix cleanMesh()
authoreap <eap@opencascade.com>
Mon, 27 Mar 2006 13:34:04 +0000 (13:34 +0000)
committereap <eap@opencascade.com>
Mon, 27 Mar 2006 13:34:04 +0000 (13:34 +0000)
src/SMESH/SMESH_Pattern.cxx

index 3cf7d2eb55eda9f44a63592574fb444e575491f9..909e9f5a4aee8ae9af959132f4b80df3a2c7d96e 100644 (file)
@@ -3547,6 +3547,40 @@ bool SMESH_Pattern::
   return makePoly;
 }
 
+//=======================================================================
+//function : clearSubMesh
+//purpose  : 
+//=======================================================================
+
+static bool clearSubMesh( SMESH_Mesh*         theMesh,
+                          const TopoDS_Shape& theShape)
+{
+  bool removed = false;
+  if ( SMESH_subMesh * aSubMesh = theMesh->GetSubMeshContaining( theShape ))
+  {
+    if ( aSubMesh->GetSubMeshDS() ) {
+      removed =
+        aSubMesh->GetSubMeshDS()->NbElements() || aSubMesh->GetSubMeshDS()->NbNodes();
+      aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
+    }
+  }
+  else {
+    SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS();
+    if ( SMESHDS_SubMesh* aSubMeshDS = aMeshDS->MeshElements( theShape ))
+    {
+      SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
+      removed = eIt->more();
+      while ( eIt->more() )
+        aMeshDS->RemoveElement( eIt->next() );
+      SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes();
+      removed = removed || nIt->more();
+      while ( nIt->more() )
+        aMeshDS->RemoveNode( static_cast<const SMDS_MeshNode*>( nIt->next() ));
+    }
+  }
+  return removed;
+}
+
 //=======================================================================
 //function : clearMesh
 //purpose  : clear mesh elements existing on myShape in theMesh
@@ -3557,20 +3591,11 @@ void SMESH_Pattern::clearMesh(SMESH_Mesh* theMesh) const
 
   if ( !myShape.IsNull() )
   {
-    if ( SMESH_subMesh * aSubMesh = theMesh->GetSubMesh/*Containing*/( myShape ))
-    {
-      aSubMesh->ComputeStateEngine( SMESH_subMesh::CLEAN );
-    }
-    else {
-      SMESHDS_Mesh* aMeshDS = theMesh->GetMeshDS();
-      if ( SMESHDS_SubMesh* aSubMeshDS = aMeshDS->MeshElements( myShape ))
+    if ( !clearSubMesh( theMesh, myShape ) && !myIs2D ) { // myShape is SHELL but volumes may be bound to SOLID
+      TopTools_ListIteratorOfListOfShape it( theMesh->GetAncestors( myShape ));
+      for (; it.More() && it.Value().ShapeType() == TopAbs_SOLID; it.Next())
       {
-        SMDS_ElemIteratorPtr eIt = aSubMeshDS->GetElements();
-        while ( eIt->more() )
-          aMeshDS->RemoveElement( eIt->next() );
-        SMDS_NodeIteratorPtr nIt = aSubMeshDS->GetNodes();
-        while ( nIt->more() )
-          aMeshDS->RemoveNode( static_cast<const SMDS_MeshNode*>( nIt->next() ));
+        clearSubMesh( theMesh, it.Value() );
       }
     }
   }