Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 8446d00cb0d548dc711a9de6c1da1a3868e86d05..212d9d1b4d1f8a0251845ffb2b74d7124ba0a7da 100755 (executable)
@@ -153,7 +153,8 @@ void Model_BodyBuilder::store(const GeomShapePtr& theShape,
 
     if(!theIsStoreSameShapes) {
       Handle(TNaming_NamedShape) aNS = TNaming_Tool::NamedShape(aShape, aShapeLab);
-      if(!aNS.IsNull() && !aNS->IsEmpty()) {
+      // the last condition is for the issue 2751 : existing shape may be found in compound-NS
+      if(!aNS.IsNull() && !aNS->IsEmpty() && aNS->Get().IsSame(aShape)) {
         // This shape is already in document, store reference instead of shape;
         const TDF_Label aFoundLabel = aNS->Label();
         TDF_Reference::Set(aShapeLab, aFoundLabel);
@@ -317,14 +318,16 @@ void Model_BodyBuilder::buildName(const int theTag, const std::string& theName)
 
   TDataStd_Name::Set(builder(theTag)->NamedShape()->Label(), aName.c_str());
 }
-void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
-                                  const std::string& theName)
+bool Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
+                                  const std::string& theName,
+                                  const bool theCheckIsInResult)
 {
   GeomShapePtr aResultShape = shape();
-
-  bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false);
-  if (aNewShapeIsNotInResultShape) {
-    return;
+  if (theCheckIsInResult) {
+    bool aNewShapeIsNotInResultShape = !aResultShape->isSubShape(theNewShape, false);
+    if (aNewShapeIsNotInResultShape) {
+      return false;
+    }
   }
 
   TopoDS_Shape aShape = theNewShape->impl<TopoDS_Shape>();
@@ -349,6 +352,7 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
     buildName(myFreePrimitiveTag, aName);
   }
   ++myFreePrimitiveTag;
+  return true;
 }
 
 void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape,