From: mpv Date: Wed, 18 Mar 2015 11:46:16 +0000 (+0300) Subject: Implementation of "copyTo" method for data X-Git-Tag: V_1.1.0~109^2~6^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=fc1ceede402063c995d9c6ed5e8e21db7dfd9be4;p=modules%2Fshaper.git Implementation of "copyTo" method for data --- diff --git a/src/Model/Model_Data.cpp b/src/Model/Model_Data.cpp index 6ded256f5..477bf0e83 100644 --- a/src/Model/Model_Data.cpp +++ b/src/Model/Model_Data.cpp @@ -29,6 +29,8 @@ #include #include +#include +#include #include @@ -304,3 +306,29 @@ void Model_Data::referencesToObjects( } } } + +/// makes copy of all attributes on the given label and all sub-labels +static void copyAttrs(TDF_Label theSource, TDF_Label theDestination) { + TDF_AttributeIterator anAttrIter(theSource); + for(; anAttrIter.More(); anAttrIter.Next()) { + Handle(TDF_Attribute) aTargetAttr; + if (!theDestination.FindAttribute(anAttrIter.Value()->ID(), aTargetAttr)) { + // create a new attribute if not yet exists in the destination + aTargetAttr = anAttrIter.Value()->NewEmpty(); + theDestination.AddAttribute(aTargetAttr); + } + Handle(TDF_RelocationTable) aRelocTable; // no relocation, empty map + anAttrIter.Value()->Paste(aTargetAttr, aRelocTable); + } + // copy the sub-labels content + TDF_ChildIterator aSubLabsIter(theSource); + for(; aSubLabsIter.More(); aSubLabsIter.Next()) { + copyAttrs(aSubLabsIter.Value(), theDestination.FindChild(aSubLabsIter.Value().Tag())); + } +} + +void Model_Data::copyTo(std::shared_ptr theTarget) +{ + TDF_Label aTargetRoot = std::dynamic_pointer_cast(theTarget)->label(); + copyAttrs(myLab, aTargetRoot); +} diff --git a/src/Model/Model_Data.h b/src/Model/Model_Data.h index 4695446ce..5a2f6296e 100644 --- a/src/Model/Model_Data.h +++ b/src/Model/Model_Data.h @@ -176,6 +176,9 @@ class Model_Data : public ModelAPI_Data MODEL_EXPORT virtual void referencesToObjects( std::list > >& theRefs); + /// Copies all atributes content into theTarget data + MODEL_EXPORT virtual void copyTo(std::shared_ptr theTarget); + private: /// removes all information about back references void eraseBackReferences(); diff --git a/src/ModelAPI/ModelAPI_Data.h b/src/ModelAPI/ModelAPI_Data.h index f9abb5367..3a922d506 100644 --- a/src/ModelAPI/ModelAPI_Data.h +++ b/src/ModelAPI/ModelAPI_Data.h @@ -136,7 +136,11 @@ class MODELAPI_EXPORT ModelAPI_Data /// returns all references by attributes of this data /// \param theRefs returned list of pairs: id of referenced attribute and list of referenced objects virtual void referencesToObjects( - std::list > > >& theRefs) = 0; + std::list > > >& theRefs) =0; + + /// Copies all atributes content into theTarget data + virtual void copyTo(std::shared_ptr theTarget) = 0; + protected: /// Objects are created for features automatically ModelAPI_Data();