1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

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()
This commit is contained in:
abv 2016-11-07 15:06:32 +03:00 committed by apn
parent 44fae8b193
commit c5ec75471a

View File

@ -1117,9 +1117,36 @@ void TObj_Object::setArray (const Handle(TColStd_HArray1OfExtendedString)& theAr
anArrAttribute->ChangeArray( theArray ); 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 //function : Clone
//purpose : method. //purpose :
//======================================================================= //=======================================================================
Handle(TObj_Object) TObj_Object::Clone Handle(TObj_Object) TObj_Object::Clone
@ -1160,23 +1187,14 @@ Handle(TObj_Object) TObj_Object::Clone
// copy the data // copy the data
copyData (aNewObj); copyData (aNewObj);
// copy the references // copy children
// changed by van // copyReferences (aNewObj);
// references have to be coped after coping all objects and models
TDF_Label aTargetLabel = aNewObj->GetChildLabel(); TDF_Label aTargetLabel = aNewObj->GetChildLabel();
CopyChildren(aTargetLabel, aRelocTable); CopyChildren(aTargetLabel, aRelocTable);
// copy TagSource for the children // copy TagSource for the children
TDF_Label aChildLabel = GetChildLabel(); copyTagSources (GetChildLabel(), aTargetLabel);
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());
}
// copy the references
if(theRelocTable.IsNull()) if(theRelocTable.IsNull())
CopyReferences(aNewObj, aRelocTable); CopyReferences(aNewObj, aRelocTable);
} }
@ -1221,21 +1239,14 @@ void TObj_Object::CopyChildren
(TDF_Label& theTargetLabel, (TDF_Label& theTargetLabel,
const Handle(TDF_RelocationTable)& theRelocTable) 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(); 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()) for(;aChildren->More(); aChildren->Next())
{ {
Handle(TObj_Object) aChild = aChildren->Value(); Handle(TObj_Object) aChild = aChildren->Value();
if(!aChild.IsNull()) 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 // to support childs on sublabels of sublabel of child label
TColStd_SequenceOfInteger aTags; TColStd_SequenceOfInteger aTags;
TDF_Label aCurChildLab = aChild->GetLabel(); TDF_Label aCurChildLab = aChild->GetLabel();