0031517: Data Exchange - wrong result of ShapeTool::UpdateAssemblies()
authorika <ika@opencascade.com>
Thu, 23 Apr 2020 14:58:59 +0000 (17:58 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 29 Apr 2020 17:45:52 +0000 (20:45 +0300)
Get rid of problem with updating of parents shared one assembly.

src/XCAFDoc/XCAFDoc_ShapeTool.cxx
src/XCAFDoc/XCAFDoc_ShapeTool.hxx
tests/bugs/xde/bug31517 [new file with mode: 0644]

index 767175f..1d6677f 100644 (file)
@@ -1012,6 +1012,7 @@ void XCAFDoc_ShapeTool::UpdateAssemblies()
   GetFreeShapes(aRootLabels);
 
   // Iterate over the free shapes
   GetFreeShapes(aRootLabels);
 
   // Iterate over the free shapes
+  TDF_LabelMap anUpdated;
   for ( TDF_LabelSequence::Iterator anIt(aRootLabels); anIt.More(); anIt.Next() )
   {
     TDF_Label aRefLabel = anIt.Value();
   for ( TDF_LabelSequence::Iterator anIt(aRootLabels); anIt.More(); anIt.Next() )
   {
     TDF_Label aRefLabel = anIt.Value();
@@ -1021,7 +1022,7 @@ void XCAFDoc_ShapeTool::UpdateAssemblies()
     }
     const TDF_Label& aRootLab = aRefLabel;
     TopoDS_Shape anAssemblyShape;
     }
     const TDF_Label& aRootLab = aRefLabel;
     TopoDS_Shape anAssemblyShape;
-    updateComponent(aRootLab, anAssemblyShape);
+    updateComponent(aRootLab, anAssemblyShape, anUpdated);
   }
 }
 
   }
 }
 
@@ -2003,7 +2004,8 @@ void XCAFDoc_ShapeTool::makeSubShape (const TDF_Label& theMainShapeL,
 //=======================================================================
 
 Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabel,
 //=======================================================================
 
 Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabel,
-                                                    TopoDS_Shape&    theUpdatedShape) const
+                                                    TopoDS_Shape&    theUpdatedShape,
+                                                    TDF_LabelMap&    theUpdated) const
 {
   if ( !IsAssembly(theItemLabel) )
     return Standard_False; // Do nothing for non-assemblies
 {
   if ( !IsAssembly(theItemLabel) )
     return Standard_False; // Do nothing for non-assemblies
@@ -2011,6 +2013,13 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe
   // Get the currently stored compound for the assembly
   TopoDS_Shape aCurrentRootShape;
   GetShape(theItemLabel, aCurrentRootShape);
   // Get the currently stored compound for the assembly
   TopoDS_Shape aCurrentRootShape;
   GetShape(theItemLabel, aCurrentRootShape);
+
+  // Check if the given assembly is already updated
+  if (theUpdated.Contains(theItemLabel)) {
+    theUpdatedShape = aCurrentRootShape;
+    return Standard_True;
+  }
+  
   TopTools_MapOfOrientedShape aCurrentRootShapeMap (aCurrentRootShape.NbChildren());
 
   // Get components of the assembly
   TopTools_MapOfOrientedShape aCurrentRootShapeMap (aCurrentRootShape.NbChildren());
 
   // Get components of the assembly
@@ -2051,11 +2060,9 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe
     if ( IsAssembly(aComponentRefLab) )
     {
       // Recursive call
     if ( IsAssembly(aComponentRefLab) )
     {
       // Recursive call
-      if ( updateComponent(aComponentRefLab, aComponentShape) )
+      if ( updateComponent(aComponentRefLab, aComponentShape, theUpdated) )
       {
       {
-        if ( !isModified )
-          isModified = Standard_True;
-
+        isModified = Standard_True;
         aComponentShape.Location(aComponentLoc); // Apply placement
       }
     }
         aComponentShape.Location(aComponentLoc); // Apply placement
       }
     }
@@ -2106,6 +2113,9 @@ Standard_Boolean XCAFDoc_ShapeTool::updateComponent(const TDF_Label& theItemLabe
     NB.Generated(theUpdatedShape);
   }
 
     NB.Generated(theUpdatedShape);
   }
 
+  if (isModified)
+    theUpdated.Add(theItemLabel);
+
   return isModified;
 }
 
   return isModified;
 }
 
index 7f66a4b..90caaf1 100644 (file)
@@ -23,6 +23,7 @@
 #include <Standard_Boolean.hxx>
 #include <TDataStd_NamedData.hxx>
 #include <TDF_Attribute.hxx>
 #include <Standard_Boolean.hxx>
 #include <TDataStd_NamedData.hxx>
 #include <TDF_Attribute.hxx>
+#include <TDF_LabelMap.hxx>
 #include <TDF_LabelSequence.hxx>
 #include <Standard_Integer.hxx>
 #include <Standard_OStream.hxx>
 #include <TDF_LabelSequence.hxx>
 #include <Standard_Integer.hxx>
 #include <Standard_OStream.hxx>
@@ -441,7 +442,8 @@ private:
   //! associated compound is updated. Returns true if the assembly item is
   //! modified, false -- otherwise.
   Standard_EXPORT Standard_Boolean updateComponent(const TDF_Label& theAssmLabel,
   //! associated compound is updated. Returns true if the assembly item is
   //! modified, false -- otherwise.
   Standard_EXPORT Standard_Boolean updateComponent(const TDF_Label& theAssmLabel,
-                                                   TopoDS_Shape&    theUpdatedShape) const;
+                                                   TopoDS_Shape&    theUpdatedShape,
+                                                   TDF_LabelMap&    theUpdated) const;
 
   //! Adds a new top-level (creates and returns a new label)
   //! For internal use. Used by public method AddShape.
 
   //! Adds a new top-level (creates and returns a new label)
   //! For internal use. Used by public method AddShape.
diff --git a/tests/bugs/xde/bug31517 b/tests/bugs/xde/bug31517
new file mode 100644 (file)
index 0000000..f482937
--- /dev/null
@@ -0,0 +1,36 @@
+puts "======================================================================"
+puts "0031517: Data Exchange - wrong result of ShapeTool::UpdateAssemblies()"
+puts "======================================================================"
+puts ""
+
+pload DCAF
+
+# make structure with two assemblies linked to one original assembly (2 * 3 boxes)
+box b1 1 1 1
+box b2 2 0 0 1 1 1
+box b3 -2 0 0 1 1 1
+compound b1 b2 b3 bs
+copy bs bs1
+ttranslate bs1 0 2 0
+copy bs bs2
+ttranslate bs2 0 -2 0
+compound bs1 r1
+compound bs2 r2
+compound r1 r2 root
+XNewDoc D
+XAddShape D root
+
+# delete one of boxes in common assembly (should be 2 * 2 boxes)
+XRemoveComponent D 0:1:1:3:1
+XRemoveShape D 0:1:1:4
+XUpdateAssemblies D
+XGetOneShape upd D
+
+# check number of boxes
+set boxes [explode upd so]
+if {$boxes != "upd_1 upd_2 upd_3 upd_4"} {
+puts "Error: wrong result of UpdateAssemblies."
+}
+
+Close D
+