#include <Events_Error.h>
#include <TDataStd_Name.hxx>
+#include <TDF_AttributeIterator.hxx>
+#include <TDF_ChildIterator.hxx>
#include <string>
}
}
}
+
+/// 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<ModelAPI_Data> theTarget)
+{
+ TDF_Label aTargetRoot = std::dynamic_pointer_cast<Model_Data>(theTarget)->label();
+ copyAttrs(myLab, aTargetRoot);
+}
MODEL_EXPORT virtual void referencesToObjects(
std::list<std::pair<std::string, std::list<ObjectPtr> > >& theRefs);
+ /// Copies all atributes content into theTarget data
+ MODEL_EXPORT virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget);
+
private:
/// removes all information about back references
void eraseBackReferences();
/// 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<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) = 0;
+ std::list<std::pair<std::string, std::list<std::shared_ptr<ModelAPI_Object> > > >& theRefs) =0;
+
+ /// Copies all atributes content into theTarget data
+ virtual void copyTo(std::shared_ptr<ModelAPI_Data> theTarget) = 0;
+
protected:
/// Objects are created for features automatically
ModelAPI_Data();