]> OCCT Git - occt-copy.git/commitdiff
0028908: Improvement on attachment of attributes to the label
authorvro <vro@opencascade.com>
Mon, 24 Jul 2017 05:47:30 +0000 (08:47 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 27 Jul 2017 10:59:52 +0000 (13:59 +0300)
src/QABugs/QABugs_19.cxx
src/TDF/TDF_CopyTool.cxx
src/TDF/TDF_Label.cxx
src/TDF/TDF_Label.hxx
src/TPrsStd/TPrsStd_AISPresentation.cxx

index cce5e335818649455b7934153609ba3a3d64ef29..30a532fdc14201900d6b22d456b8bfef931c7078 100644 (file)
@@ -53,6 +53,7 @@
 #include <ViewerTest.hxx>
 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
 #include <XmlDrivers_DocumentStorageDriver.hxx>
+#include <TDataStd_Real.hxx>
 
 #include <cstdio>
 #include <cmath>
@@ -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;
 }
index 2a17a472923367f23e369c393c389dba90c457b2..331830cda4dcf25ca3799a00b8304c2b71277bdf 100644 (file)
@@ -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 {
index 13093a70ca7605f6998003ef9ff913562c884d0c..838a44b347ab10ce6e2364d2d3a36ce07a1f8edc 100644 (file)
@@ -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();
 }
index ac2fa195feff92dd6844c4d32b93a9d366f60ba7..00f7522c88b12c7b0228585a98e51dc43f4b4aa8 100644 (file)
@@ -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 <toNode>. 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 <fromNode>.  Raises if
   //! the attribute is not in the structure.
index 5da1459164275b909161c501acc53c7eca6d6da7..8297fbe0358c654272a2d2a0ee5d43a1222a5e31 100644 (file)
@@ -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;