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

0028908: Improvement on attachment of attributes to the label

This commit is contained in:
vro 2017-07-24 08:47:30 +03:00 committed by bugmaster
parent bbf03a4e8e
commit 0f3d1d7c22
5 changed files with 24 additions and 12 deletions

View File

@ -53,6 +53,7 @@
#include <ViewerTest.hxx> #include <ViewerTest.hxx>
#include <XmlDrivers_DocumentRetrievalDriver.hxx> #include <XmlDrivers_DocumentRetrievalDriver.hxx>
#include <XmlDrivers_DocumentStorageDriver.hxx> #include <XmlDrivers_DocumentStorageDriver.hxx>
#include <TDataStd_Real.hxx>
#include <cstdio> #include <cstdio>
#include <cmath> #include <cmath>
@ -1924,15 +1925,22 @@ static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, cons
Handle(TDocStd_Document) aDoc; Handle(TDocStd_Document) aDoc;
anApp->NewDocument ("BinOcaf", aDoc); anApp->NewDocument ("BinOcaf", aDoc);
TDF_Label aLab = aDoc->Main(); TDF_Label aLab = aDoc->Main();
// Prepend an int value.
TDataStd_Integer::Set (aLab, 0); TDataStd_Integer::Set (aLab, 0);
// Prepend a name.
TDataStd_Name::Set (aLab, "test"); TDataStd_Name::Set (aLab, "test");
// Append a double value.
aLab.AddAttribute(new TDataStd_Real(), true/*append*/);
TDF_AttributeIterator i (aLab); TDF_AttributeIterator i (aLab);
Handle(TDF_Attribute) anAttr = i.Value(); 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); QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Integer)), Standard_True);
i.Next(); i.Next();
anAttr = i.Value(); anAttr = i.Value();
QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Name)), Standard_True); QCOMPARE (anAttr->IsKind (STANDARD_TYPE (TDataStd_Real)), Standard_True);
return 0; return 0;
} }

View File

@ -186,7 +186,7 @@ void TDF_CopyTool::CopyAttributes
tAtt = sAtt->NewEmpty(); tAtt = sAtt->NewEmpty();
if(tAtt->ID() != id) if(tAtt->ID() != id)
tAtt->SetID(id);// tAtt->SetID(id);//
aTargetLabel.AddAttribute(tAtt); aTargetLabel.AddAttribute(tAtt, Standard_True);
aAttMap.Bind(sAtt,tAtt); aAttMap.Bind(sAtt,tAtt);
} }
else { else {

View File

@ -412,8 +412,9 @@ Standard_Boolean TDF_Label::HasGreaterNode(const TDF_Label& aLabel) const
//purpose : //purpose :
//======================================================================= //=======================================================================
void TDF_Label::AddAttribute (const Handle(TDF_Attribute)& anAttribute) const void TDF_Label::AddAttribute (const Handle(TDF_Attribute)& anAttribute,
{ AddToNode(myLabelNode,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, 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 // check that modification is allowed
if ( !toNode->Data()->IsModificationAllowed() ) { if ( !toNode->Data()->IsModificationAllowed() ) {
@ -555,8 +557,10 @@ void TDF_Label::AddToNode (const TDF_LabelNodePtr& toNode,
//append to the end of the attribute list //append to the end of the attribute list
dummyAtt.Nullify(); dummyAtt.Nullify();
for (TDF_AttributeIterator itr (toNode); itr.More(); itr.Next()) if (append) {
dummyAtt = itr.Value(); for (TDF_AttributeIterator itr (toNode); itr.More(); itr.Next())
dummyAtt = itr.Value();
}
toNode->AddAttribute(dummyAtt,anAttribute); toNode->AddAttribute(dummyAtt,anAttribute);
toNode->AttributesModified(anAttribute->myTransaction != 0); toNode->AttributesModified(anAttribute->myTransaction != 0);
@ -605,7 +609,7 @@ void TDF_Label::ForgetFromNode (const TDF_LabelNodePtr& fromNode,
anAttribute->BeforeRemoval(); anAttribute->BeforeRemoval();
} }
fromNode->RemoveAttribute(lastAtt,anAttribute); fromNode->RemoveAttribute(lastAtt,anAttribute);
anAttribute->Forget(fromNode->Data()->Transaction()); // vro anAttribute->Forget(fromNode->Data()->Transaction());
break; break;
} }
lastAtt = itr.Value(); lastAtt = itr.Value();
@ -638,7 +642,7 @@ void TDF_Label::ResumeToNode (const TDF_LabelNodePtr& toNode,
if (!anAttribute->IsForgotten()) if (!anAttribute->IsForgotten())
throw Standard_DomainError("Cannot resume an unforgotten attribute."); throw Standard_DomainError("Cannot resume an unforgotten attribute.");
AddToNode(toNode, anAttribute); // vro AddToNode(toNode, anAttribute, Standard_False);
anAttribute->Resume(); anAttribute->Resume();
if (toNode->Data()->NotUndoMode()) anAttribute->AfterResume(); if (toNode->Data()->NotUndoMode()) anAttribute->AfterResume();
} }

View File

@ -117,7 +117,7 @@ public:
//! Adds an Attribute to the current label. Raises if //! Adds an Attribute to the current label. Raises if
//! there is already one. //! 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, //! Forgets an Attribute from the current label,
//! setting its forgotten status true and its valid //! setting its forgotten status true and its valid
@ -283,7 +283,7 @@ private:
//! Adds an Attribute to <toNode>. Raises if there is //! Adds an Attribute to <toNode>. Raises if there is
//! already one. //! 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 <fromNode>. Raises if //! Forgets an Attribute from <fromNode>. Raises if
//! the attribute is not in the structure. //! the attribute is not in the structure.

View File

@ -65,7 +65,7 @@ Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set
if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) ) if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) )
{ {
aPresentation = new TPrsStd_AISPresentation(); aPresentation = new TPrsStd_AISPresentation();
theLabel.AddAttribute(aPresentation); theLabel.AddAttribute(aPresentation, Standard_True);
} }
return aPresentation; return aPresentation;