]> OCCT Git - occt-copy.git/commitdiff
0029716: Some TDF and XCAFDoc labels-related issues
authordrazmyslovich <razmyslovich@volumegraphics.com>
Mon, 23 Apr 2018 13:47:52 +0000 (15:47 +0200)
committerbugmaster <bugmaster@opencascade.com>
Wed, 7 Nov 2018 15:16:51 +0000 (18:16 +0300)
1. "Descendants" closure mode is not taken into account by TDF closure tool
2. CopyTool always creates a new label at the target ignoring the relocation table
3. XCAFDoc_GraphNode throws an exception if Child of Father is not found during the unsetting

src/TDF/TDF_ClosureTool.cxx
src/TDF/TDF_CopyTool.cxx
src/XCAFDoc/XCAFDoc_GraphNode.cxx

index a6377c797a9ba977861a9a4f02a05234c2b73fde..b40402451da5deadb4b9d1e5c67d5e53b13ec960 100644 (file)
@@ -72,7 +72,8 @@ void TDF_ClosureTool::Closure
     const TDF_Label& lab = labLItr.Value();
     if (lab.HasAttribute())
       TDF_ClosureTool::LabelAttributes(lab,labMap,attMap,aFilter,aMode);
-    TDF_ClosureTool::Closure(lab,labMap,attMap,aFilter,aMode); 
+    if (aMode.Descendants())
+      TDF_ClosureTool::Closure(lab,labMap,attMap,aFilter,aMode); 
   }
 }
 
index 331830cda4dcf25ca3799a00b8304c2b71277bdf..66a024c948b0cd88d4ff6de347b8158e4431c047 100644 (file)
@@ -153,12 +153,25 @@ void TDF_CopyTool::CopyLabels
   // Does the same for the children.
   for (TDF_ChildIterator childItr(aSLabel); childItr.More(); childItr.Next()){
     const TDF_Label& childSLab = childItr.Value();
-    if (aSrcLabelMap.Contains(childSLab)) {
-      TDF_Label childTIns = aTargetLabel.FindChild(childSLab.Tag());
-      aLabMap.Bind(childSLab,childTIns);
-      TDF_CopyTool::CopyLabels(childSLab,childTIns,
-        aLabMap,aAttMap,
-        aSrcLabelMap,aSrcAttributeMap);
+    if (aSrcLabelMap.Contains(childSLab))
+    {
+      TDF_Label childTIns;
+      if (aLabMap.IsBound (childSLab))
+      {
+        childTIns = aLabMap.Find (childSLab);
+      }
+      else
+      {
+        childTIns = aTargetLabel.FindChild (childSLab.Tag ());
+        aLabMap.Bind (childSLab, childTIns);
+      }
+
+      TDF_CopyTool::CopyLabels
+        (
+          childSLab,childTIns,
+          aLabMap,aAttMap,
+          aSrcLabelMap,aSrcAttributeMap
+        );
     }
   }
 }
index 9aa7af0e55d9876593a57155bf019eb417744251..f83ad70e3c3aa18817e73c4cf8a218ee4b9b8921 100644 (file)
@@ -142,8 +142,10 @@ void XCAFDoc_GraphNode::UnSetFather(const Handle(XCAFDoc_GraphNode)& F)
 {
   Standard_Integer Findex = FatherIndex(F);
   if (Findex != 0)
-  F->UnSetChildlink(this);
-  UnSetFatherlink(F);
+  {
+    F->UnSetChildlink (this);
+    UnSetFatherlink (F);
+  }
 }
 
 
@@ -155,7 +157,9 @@ void XCAFDoc_GraphNode::UnSetFather(const Handle(XCAFDoc_GraphNode)& F)
 void XCAFDoc_GraphNode::UnSetFather(const Standard_Integer Findex) 
 {
   if (Findex != 0)
-  UnSetFather( GetFather(Findex) );
+  {
+    UnSetFather (GetFather (Findex));
+  }
 }
 
 
@@ -167,7 +171,11 @@ void XCAFDoc_GraphNode::UnSetFather(const Standard_Integer Findex)
 void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F) 
 {
   Backup();
-  myFathers.Remove( FatherIndex(F) );
+  Standard_Integer Findex = FatherIndex (F);
+  if (Findex != 0)
+  {
+    myFathers.Remove( Findex );
+  }
 }
 
 //=======================================================================
@@ -178,9 +186,11 @@ void XCAFDoc_GraphNode::UnSetFatherlink(const Handle(XCAFDoc_GraphNode)& F)
 void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch) 
 {
   Standard_Integer Chindex = ChildIndex(Ch);
-  if (Chindex != 0) 
-  Ch->UnSetFatherlink(this);
-  UnSetChildlink(Ch);
+  if (Chindex != 0)
+  {
+    Ch->UnSetFatherlink (this);
+    UnSetChildlink (Ch);
+  }
 }
 
 
@@ -191,8 +201,10 @@ void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch)
 
  void XCAFDoc_GraphNode::UnSetChild(const Standard_Integer Chindex) 
 {
-  if (Chindex != 0 )
-  UnSetChild( GetChild(Chindex) );
+  if (Chindex != 0)
+  {
+    UnSetChild (GetChild (Chindex));
+  }
 }
 
 
@@ -204,7 +216,11 @@ void XCAFDoc_GraphNode::UnSetChild(const Handle(XCAFDoc_GraphNode)& Ch)
 void XCAFDoc_GraphNode::UnSetChildlink(const Handle(XCAFDoc_GraphNode)& Ch) 
 {
   Backup();
-  myChildren.Remove( ChildIndex(Ch) );
+  Standard_Integer Chindex = ChildIndex (Ch);
+  if (Chindex != 0)
+  {
+    myChildren.Remove (Chindex);
+  }
 }
 
 //=======================================================================
@@ -237,9 +253,14 @@ void XCAFDoc_GraphNode::UnSetChildlink(const Handle(XCAFDoc_GraphNode)& Ch)
 Standard_Integer XCAFDoc_GraphNode::FatherIndex(const Handle(XCAFDoc_GraphNode)& F) const
 {
   Standard_Integer Findex = 0;
-  if (NbFathers()!=0) {
-    for (Findex = 1 ; Findex <= NbFathers(); Findex++) {
-      if ( F == myFathers.Value(Findex)) return Findex;
+  if (NbFathers() != 0)
+  {
+    for (Findex = 1 ; Findex <= NbFathers(); Findex++)
+    {
+      if (F == myFathers.Value (Findex))
+      {
+        return Findex;
+      }
     }
   }
   return 0;
@@ -253,9 +274,14 @@ Standard_Integer XCAFDoc_GraphNode::FatherIndex(const Handle(XCAFDoc_GraphNode)&
  Standard_Integer XCAFDoc_GraphNode::ChildIndex(const Handle(XCAFDoc_GraphNode)& Ch) const
 {
   Standard_Integer Chindex;
-  if (NbChildren()!=0) {
-    for (Chindex = 1; Chindex <= NbChildren(); Chindex++) {
-      if ( Ch == myChildren.Value(Chindex)) return Chindex;
+  if (NbChildren() != 0)
+  {
+    for (Chindex = 1; Chindex <= NbChildren(); Chindex++)
+    {
+      if (Ch == myChildren.Value (Chindex))
+      {
+        return Chindex;
+      }
     }
   }
   return 0;
@@ -345,18 +371,27 @@ void XCAFDoc_GraphNode::Paste(const Handle(TDF_Attribute)& into,
   Handle(XCAFDoc_GraphNode) func;
   Standard_Integer i = 1;
   for (; i <= NbFathers(); i++) {
-    if (!RT->HasRelocation(myFathers(i), func) && RT->AfterRelocate()) {
+    if (!RT->HasRelocation(myFathers(i), func) && RT->AfterRelocate())
+    {
       func.Nullify();
     }
-    intof->SetFather(func);
+    if (!func.IsNull())
+    {
+      intof->SetFather(func);
+    }
   }
 
   i = 1;
-  for (; i <= NbChildren(); i++) {
-    if (!RT->HasRelocation(myChildren(i), func) && RT->AfterRelocate()) {
+  for (; i <= NbChildren(); i++)
+  {
+    if (!RT->HasRelocation(myChildren(i), func) && RT->AfterRelocate())
+    {
       func.Nullify();
     }
-    intof->SetFather(func);
+    if (!func.IsNull())
+    {
+      intof->SetChild(func);
+    }
   }
   intof->SetGraphID(myGraphID);
 }
@@ -436,8 +471,12 @@ Standard_OStream& XCAFDoc_GraphNode::Dump (Standard_OStream& anOS) const
 
 void XCAFDoc_GraphNode::BeforeForget()
 {
-  while ( myFathers.Length() > 0 ) 
-    UnSetFather(1);
-  while ( myChildren.Length() > 0 )
-    UnSetChild(1);
+  while (myFathers.Length () > 0)
+  {
+    UnSetFather (1);
+  }
+  while (myChildren.Length () > 0)
+  {
+    UnSetChild (1);
+  }
 }