]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/Model/Model_BodyBuilder.cpp
Salome HOME
The fix based on DBC mail 04.03.2019. If the selected solid was not modified by the...
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 5c89b7cc31fa069cdcfb89defed73961c4f32af1..be65e0f403d277b5533790ffec305f4f7cf55a11 100644 (file)
@@ -380,8 +380,24 @@ void Model_BodyBuilder::storeModified(const std::list<GeomShapePtr>& theOldShape
       aStored = !aBuilder->NamedShape()->IsEmpty();
     }
   }
-  if (!aStored) { // store as PRIMITIVE, but clean in any way
-    store(theNewShape);
+  if (!aStored) {
+    // check the new shape is already in the tree, so, no need to store primitive, just reference
+    std::shared_ptr<Model_Data> aData = std::dynamic_pointer_cast<Model_Data>(data());
+    if (aData.get()) {
+      TDF_Label aShapeLab = aData->shapeLab();
+      TopoDS_Shape aShapeNew = theNewShape->impl<TopoDS_Shape>();
+      Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShapeNew, aShapeLab);
+      // the last condition is for the issue 2751 : existing shape may be found in compound-NS
+      if (!aNS.IsNull() && !aNS->IsEmpty() && aNS->Get().IsSame(aShapeNew)) {
+        // This shape is already in document, store reference instead of shape;
+        const TDF_Label aFoundLabel = aNS->Label();
+        TDF_Reference::Set(aShapeLab, aFoundLabel);
+        myBuilders.erase(0);
+        aShapeLab.ForgetAttribute(TNaming_NamedShape::GetID());
+        return;
+      }
+    }
+    store(theNewShape); // store as PRIMITIVE, but clean in any way
     return;
   }
 }