From 0f3d1d7c2299cca28952e98be29f158ba0c34937 Mon Sep 17 00:00:00 2001 From: vro Date: Mon, 24 Jul 2017 08:47:30 +0300 Subject: [PATCH] 0028908: Improvement on attachment of attributes to the label --- src/QABugs/QABugs_19.cxx | 10 +++++++++- src/TDF/TDF_CopyTool.cxx | 2 +- src/TDF/TDF_Label.cxx | 18 +++++++++++------- src/TDF/TDF_Label.hxx | 4 ++-- src/TPrsStd/TPrsStd_AISPresentation.cxx | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/QABugs/QABugs_19.cxx b/src/QABugs/QABugs_19.cxx index cce5e33581..30a532fdc1 100644 --- a/src/QABugs/QABugs_19.cxx +++ b/src/QABugs/QABugs_19.cxx @@ -53,6 +53,7 @@ #include #include #include +#include #include #include @@ -1924,15 +1925,22 @@ static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, cons Handle(TDocStd_Document) aDoc; anApp->NewDocument ("BinOcaf", aDoc); TDF_Label aLab = aDoc->Main(); + // Prepend an int value. TDataStd_Integer::Set (aLab, 0); + // Prepend a name. TDataStd_Name::Set (aLab, "test"); + // Append a double value. + aLab.AddAttribute(new TDataStd_Real(), true/*append*/); TDF_AttributeIterator i (aLab); Handle(TDF_Attribute) anAttr = i.Value(); + QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True); + i.Next(); + anAttr = i.Value(); QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Integer)), Standard_True); i.Next(); anAttr = i.Value(); - QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True); + QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Real)), Standard_True); return 0; } diff --git a/src/TDF/TDF_CopyTool.cxx b/src/TDF/TDF_CopyTool.cxx index 2a17a47292..331830cda4 100644 --- a/src/TDF/TDF_CopyTool.cxx +++ b/src/TDF/TDF_CopyTool.cxx @@ -186,7 +186,7 @@ void TDF_CopyTool::CopyAttributes tAtt = sAtt->NewEmpty(); if(tAtt->ID() != id) tAtt->SetID(id);// - aTargetLabel.AddAttribute(tAtt); + aTargetLabel.AddAttribute(tAtt, Standard_True); aAttMap.Bind(sAtt,tAtt); } else { diff --git a/src/TDF/TDF_Label.cxx b/src/TDF/TDF_Label.cxx index 13093a70ca..838a44b347 100644 --- a/src/TDF/TDF_Label.cxx +++ b/src/TDF/TDF_Label.cxx @@ -412,8 +412,9 @@ Standard_Boolean TDF_Label::HasGreaterNode(const TDF_Label& aLabel) const //purpose : //======================================================================= -void TDF_Label::AddAttribute (const Handle(TDF_Attribute)& anAttribute) const -{ AddToNode(myLabelNode,anAttribute); } +void TDF_Label::AddAttribute (const Handle(TDF_Attribute)& anAttribute, + const Standard_Boolean append/* = Standard_False*/) const +{ AddToNode(myLabelNode,anAttribute,append); } //======================================================================= @@ -532,7 +533,8 @@ void TDF_Label::ResumeAttribute (const Handle(TDF_Attribute)& anAttribute) cons //======================================================================= void TDF_Label::AddToNode (const TDF_LabelNodePtr& toNode, - const Handle(TDF_Attribute)& anAttribute) const + const Handle(TDF_Attribute)& anAttribute, + const Standard_Boolean append) const { // check that modification is allowed if ( !toNode->Data()->IsModificationAllowed() ) { @@ -555,8 +557,10 @@ void TDF_Label::AddToNode (const TDF_LabelNodePtr& toNode, //append to the end of the attribute list dummyAtt.Nullify(); - for (TDF_AttributeIterator itr (toNode); itr.More(); itr.Next()) - dummyAtt = itr.Value(); + if (append) { + for (TDF_AttributeIterator itr (toNode); itr.More(); itr.Next()) + dummyAtt = itr.Value(); + } toNode->AddAttribute(dummyAtt,anAttribute); toNode->AttributesModified(anAttribute->myTransaction != 0); @@ -605,7 +609,7 @@ void TDF_Label::ForgetFromNode (const TDF_LabelNodePtr& fromNode, anAttribute->BeforeRemoval(); } fromNode->RemoveAttribute(lastAtt,anAttribute); - anAttribute->Forget(fromNode->Data()->Transaction()); // vro + anAttribute->Forget(fromNode->Data()->Transaction()); break; } lastAtt = itr.Value(); @@ -638,7 +642,7 @@ void TDF_Label::ResumeToNode (const TDF_LabelNodePtr& toNode, if (!anAttribute->IsForgotten()) throw Standard_DomainError("Cannot resume an unforgotten attribute."); - AddToNode(toNode, anAttribute); // vro + AddToNode(toNode, anAttribute, Standard_False); anAttribute->Resume(); if (toNode->Data()->NotUndoMode()) anAttribute->AfterResume(); } diff --git a/src/TDF/TDF_Label.hxx b/src/TDF/TDF_Label.hxx index ac2fa195fe..00f7522c88 100644 --- a/src/TDF/TDF_Label.hxx +++ b/src/TDF/TDF_Label.hxx @@ -117,7 +117,7 @@ public: //! Adds an Attribute to the current label. Raises if //! there is already one. - Standard_EXPORT void AddAttribute (const Handle(TDF_Attribute)& anAttribute) const; + Standard_EXPORT void AddAttribute (const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append = Standard_False) const; //! Forgets an Attribute from the current label, //! setting its forgotten status true and its valid @@ -283,7 +283,7 @@ private: //! Adds an Attribute to . Raises if there is //! already one. - Standard_EXPORT void AddToNode (const TDF_LabelNodePtr& toNode, const Handle(TDF_Attribute)& anAttribute) const; + Standard_EXPORT void AddToNode (const TDF_LabelNodePtr& toNode, const Handle(TDF_Attribute)& anAttribute, const Standard_Boolean append) const; //! Forgets an Attribute from . Raises if //! the attribute is not in the structure. diff --git a/src/TPrsStd/TPrsStd_AISPresentation.cxx b/src/TPrsStd/TPrsStd_AISPresentation.cxx index 5da1459164..8297fbe035 100644 --- a/src/TPrsStd/TPrsStd_AISPresentation.cxx +++ b/src/TPrsStd/TPrsStd_AISPresentation.cxx @@ -65,7 +65,7 @@ Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) { aPresentation = new TPrsStd_AISPresentation(); - theLabel.AddAttribute(aPresentation); + theLabel.AddAttribute(aPresentation, Standard_True); } return aPresentation;