Salome HOME
Implementation of "copyTo" method for data
authormpv <mpv@opencascade.com>
Wed, 18 Mar 2015 11:46:16 +0000 (14:46 +0300)
committermpv <mpv@opencascade.com>
Wed, 18 Mar 2015 11:46:16 +0000 (14:46 +0300)
src/Model/Model_Data.cpp
src/Model/Model_Data.h
src/ModelAPI/ModelAPI_Data.h

index 6ded256f5cf138d69c886d63252e122c213e765c..477bf0e83c71dc514bf4472e97512d3d4d3372fd 100644 (file)
@@ -29,6 +29,8 @@
 #include <Events_Error.h>
 
 #include <TDataStd_Name.hxx>
+#include <TDF_AttributeIterator.hxx>
+#include <TDF_ChildIterator.hxx>
 
 #include <string>
 
@@ -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<ModelAPI_Data> theTarget)
+{
+  TDF_Label aTargetRoot = std::dynamic_pointer_cast<Model_Data>(theTarget)->label();
+  copyAttrs(myLab, aTargetRoot);
+}
index 4695446ce9b29eadd7e256b30c837d3f462338b3..5a2f6296e1a385745534e42fd2c56312aa4be27a 100644 (file)
@@ -176,6 +176,9 @@ class Model_Data : public ModelAPI_Data
   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();
index f9abb5367e33759dffbd10b0d77c896459339f91..3a922d5061e98579362ae38dc9e4aca4a221ef24 100644 (file)
@@ -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<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();