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 cce5e33..30a532f 100644 (file)
@@ -53,6 +53,7 @@
 #include <ViewerTest.hxx>
 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
 #include <XmlDrivers_DocumentStorageDriver.hxx>
 #include <ViewerTest.hxx>
 #include <XmlDrivers_DocumentRetrievalDriver.hxx>
 #include <XmlDrivers_DocumentStorageDriver.hxx>
+#include <TDataStd_Real.hxx>
 
 #include <cstdio>
 #include <cmath>
 
 #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();
   Handle(TDocStd_Document) aDoc;
   anApp->NewDocument ("BinOcaf", aDoc);
   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);
   Handle(TDF_Attribute) anAttr = i.Value();
 
   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_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;
 }
 
   return 0;
 }
index 2a17a47..331830c 100644 (file)
@@ -186,7 +186,7 @@ void TDF_CopyTool::CopyAttributes
         tAtt = sAtt->NewEmpty();
         if(tAtt->ID() != id) 
           tAtt->SetID(id);//
         tAtt = sAtt->NewEmpty();
         if(tAtt->ID() != id) 
           tAtt->SetID(id);//
-        aTargetLabel.AddAttribute(tAtt);
+        aTargetLabel.AddAttribute(tAtt, Standard_True);
         aAttMap.Bind(sAtt,tAtt);
       }
       else {
         aAttMap.Bind(sAtt,tAtt);
       }
       else {
index 13093a7..838a44b 100644 (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
-{ 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,
 //=======================================================================
 
 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() ) {
 {
   // 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();
 
   //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);
 
   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->BeforeRemoval();
           }
           fromNode->RemoveAttribute(lastAtt,anAttribute);
-         anAttribute->Forget(fromNode->Data()->Transaction()); // vro
+          anAttribute->Forget(fromNode->Data()->Transaction());
           break;
         }
         lastAtt = itr.Value();
           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.");
 
   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();
 }
   anAttribute->Resume();
   if (toNode->Data()->NotUndoMode()) anAttribute->AfterResume();
 }
index ac2fa19..00f7522 100644 (file)
@@ -117,7 +117,7 @@ public:
   
   //! Adds an Attribute  to the current label. Raises if
   //! there is already one.
   
   //! 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
   
   //! 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.
   
   //! 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.
   
   //! Forgets an Attribute from <fromNode>.  Raises if
   //! the attribute is not in the structure.
index 5da1459..8297fbe 100644 (file)
@@ -65,7 +65,7 @@ Handle(TPrsStd_AISPresentation) TPrsStd_AISPresentation::Set
   if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) )
   {
     aPresentation = new TPrsStd_AISPresentation();
   if ( !theLabel.FindAttribute(TPrsStd_AISPresentation::GetID(), aPresentation) )
   {
     aPresentation = new TPrsStd_AISPresentation();
-    theLabel.AddAttribute(aPresentation);
+    theLabel.AddAttribute(aPresentation, Standard_True);
   }
 
   return aPresentation;
   }
 
   return aPresentation;