Salome HOME
Fix for the issue #2753 : error when dump/load script
[modules/shaper.git] / src / Model / Model_BodyBuilder.cpp
index 952309d8a39e55e6b933d75c52b8ec5062116471..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);
@@ -280,13 +281,10 @@ void Model_BodyBuilder::clean()
     return;
   std::map<int, TNaming_Builder*>::iterator aBuilder = myBuilders.begin();
   for(; aBuilder != myBuilders.end(); aBuilder++) {
+    Handle(TNaming_NamedShape) aNS = aBuilder->second->NamedShape();
     delete aBuilder->second;
-    // clear also shapes on cleaned sub-labels (#2241)
-    Handle(TNaming_NamedShape) aNS;
-    TDF_Label aSubLab = aLab.FindChild(aBuilder->first);
-    if (aSubLab.FindAttribute(TNaming_NamedShape::GetID(), aNS)) {
-      aNS->Clear();
-    }
+    if (!aNS.IsNull() && !aNS->Label().IsNull())
+      aNS->Label().ForgetAttribute(TNaming_NamedShape::GetID());
   }
   myBuilders.clear();
   myPrimitivesNamesIndexMap.clear();
@@ -320,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>();
@@ -352,6 +352,7 @@ void Model_BodyBuilder::generated(const GeomShapePtr& theNewShape,
     buildName(myFreePrimitiveTag, aName);
   }
   ++myFreePrimitiveTag;
+  return true;
 }
 
 void Model_BodyBuilder::generated(const GeomShapePtr& theOldShape,