Salome HOME
Added unit-test that checks the issue #1379 is fixed
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 9633826011ce623cb10f03dc8b2073b19a1bd2b1..1a8ea5507f9518ca3810ac4bb6ba615e21bbfe6d 100755 (executable)
@@ -360,13 +360,19 @@ void Model_BodyBuilder::loadDeletedShapes (GeomAlgoAPI_MakeShape* theMS,
   TopoDS_Shape aShapeIn = theShapeIn->impl<TopoDS_Shape>();
   TopTools_MapOfShape aView;
   TopExp_Explorer ShapeExplorer (aShapeIn, (TopAbs_ShapeEnum)theKindOfShape);
+  GeomShapePtr aResultShape = shape();
   for (; ShapeExplorer.More(); ShapeExplorer.Next ()) {
     const TopoDS_Shape& aRoot = ShapeExplorer.Current ();
     if (!aView.Add(aRoot)) continue;
     std::shared_ptr<GeomAPI_Shape> aRShape(new GeomAPI_Shape());
     aRShape->setImpl((new TopoDS_Shape(aRoot)));
     if (theMS->isDeleted (aRShape)) {
-      builder(theTag)->Delete(aRoot);
+      if (!aResultShape->isSubShape(aRShape, false)) {
+          ListOfShape aHist;
+          theMS->modified(aRShape, aHist);
+          if (aHist.size() == 0 || (aHist.size() == 1 && aHist.front()->isSame(aRShape)))
+            builder(theTag)->Delete(aRoot);
+      }
     }
   }
 }
@@ -379,7 +385,9 @@ static void keepTopLevelShapes(ListOfShape& theShapes, const TopoDS_Shape& theRo
   ListOfShape::iterator anIt = theShapes.begin();
   while (anIt != theShapes.end()) {
     TopoDS_Shape aNewShape = (*anIt)->impl<TopoDS_Shape>();
-    if (theRoot.IsSame(aNewShape) || (theResultShape &&
+    bool aSkip = aNewShape.IsNull() ||
+      (aNewShape.ShapeType() == TopAbs_EDGE && BRep_Tool::Degenerated(TopoDS::Edge(aNewShape)));
+    if (aSkip || theRoot.IsSame(aNewShape) || (theResultShape &&
         (!theResultShape->isSubShape(*anIt, false) || theResultShape->isSame(*anIt)))) {
       ListOfShape::iterator aRemoveIt = anIt++;
       theShapes.erase(aRemoveIt);