From c5ec75471a238ba040f207662b5c780671620b59 Mon Sep 17 00:00:00 2001 From: abv Date: Mon, 7 Nov 2016 15:06:32 +0300 Subject: [PATCH] 0028058: TObj_Object::Clone() does not copy TagSource attributes of children of second level Handling of children objects located on sub-labels of the main child label is enabled in method CopyChildren(); TagSource attributes for such children are copied in method Clone() --- src/TObj/TObj_Object.cxx | 55 ++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 22 deletions(-) diff --git a/src/TObj/TObj_Object.cxx b/src/TObj/TObj_Object.cxx index 210eef3d43..e364874886 100644 --- a/src/TObj/TObj_Object.cxx +++ b/src/TObj/TObj_Object.cxx @@ -1117,9 +1117,36 @@ void TObj_Object::setArray (const Handle(TColStd_HArray1OfExtendedString)& theAr anArrAttribute->ChangeArray( theArray ); } +//======================================================================= +//function : copyTagSources +//purpose : copy TagSource attributes on label and its sublabels +//======================================================================= + +static void copyTagSources (const TDF_Label& theSourceLabel, const TDF_Label& theTargetLabel) +{ + // copy tag source on current label + Handle(TDF_Attribute) anAttr; + if(theSourceLabel.FindAttribute(TDF_TagSource::GetID(), anAttr)) + { + Handle(TDF_TagSource) aTagSource = Handle(TDF_TagSource)::DownCast(anAttr); + Handle(TDF_TagSource) aTargetTagSource = TDF_TagSource::Set(theTargetLabel); + aTargetTagSource->Set(aTagSource->Get()); + } + + // copy recursively to sub-labels; note that iteration is made by target label, + // to avoid copying tag sources where data are not copied + TDF_ChildIterator aLI(theTargetLabel); + for(; aLI.More(); aLI.Next()) + { + TDF_Label aSourceLabel = theSourceLabel.FindChild(aLI.Value().Tag(), Standard_False); + if (! aSourceLabel.IsNull()) + copyTagSources (aSourceLabel, aLI.Value()); + } +} + //======================================================================= //function : Clone -//purpose : method. +//purpose : //======================================================================= Handle(TObj_Object) TObj_Object::Clone @@ -1160,23 +1187,14 @@ Handle(TObj_Object) TObj_Object::Clone // copy the data copyData (aNewObj); - // copy the references - // changed by van // copyReferences (aNewObj); - // references have to be coped after coping all objects and models - + // copy children TDF_Label aTargetLabel = aNewObj->GetChildLabel(); CopyChildren(aTargetLabel, aRelocTable); // copy TagSource for the children - TDF_Label aChildLabel = GetChildLabel(); - Handle(TDF_Attribute) anAttr; - if(aChildLabel.FindAttribute(TDF_TagSource::GetID(), anAttr)) - { - Handle(TDF_TagSource) aTagSource = Handle(TDF_TagSource)::DownCast(anAttr); - Handle(TDF_TagSource) aTargetTagSource = TDF_TagSource::Set(aTargetLabel); - aTargetTagSource->Set(aTagSource->Get()); - } + copyTagSources (GetChildLabel(), aTargetLabel); + // copy the references if(theRelocTable.IsNull()) CopyReferences(aNewObj, aRelocTable); } @@ -1221,21 +1239,14 @@ void TObj_Object::CopyChildren (TDF_Label& theTargetLabel, const Handle(TDF_RelocationTable)& theRelocTable) { - Handle(TObj_ObjectIterator) aChildren = /*TObj_Object::*/GetChildren(); - // to support childs on sublabels of sublabel of child label - //new TObj_ObjectIterator(GetChildLabel(), NULL, Standard_True); TDF_Label aSourceChildLabel = GetChildLabel(); + Handle(TObj_ObjectIterator) aChildren = // GetChildren(); + new TObj_OcafObjectIterator (aSourceChildLabel, NULL, Standard_True); // to support children on sublabels of child label for(;aChildren->More(); aChildren->Next()) { Handle(TObj_Object) aChild = aChildren->Value(); if(!aChild.IsNull()) { - /* only for one sub level of children - TDF_Label aChildLabel = - theTargetLabel.FindChild(aChild->GetLabel().Tag(), Standard_True); - aChild->Clone(aChildLabel, theRelocTable); - // to support childs on sublabels of sublabel of child label - */ // to support childs on sublabels of sublabel of child label TColStd_SequenceOfInteger aTags; TDF_Label aCurChildLab = aChild->GetLabel();