diff --git a/src/App/Document.cpp b/src/App/Document.cpp
index 737b2fed7..3c493bd8d 100644
--- a/src/App/Document.cpp
+++ b/src/App/Document.cpp
@@ -75,6 +75,7 @@ recompute path. Also enables more complicated dependencies beyond trees.
#include "Application.h"
#include "DocumentObject.h"
#include "PropertyLinks.h"
+#include "MergeDocuments.h"
#include
#include
@@ -1656,92 +1657,34 @@ void Document::breakDependency(DocumentObject* pcObject, bool clear)
}
}
-DocumentObject* Document::_copyObject(DocumentObject* obj, std::map& copy_map, bool recursive,
- bool keepdigitsatend)
+DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive, bool /*keepdigitsatend*/)
{
- if (!obj) return 0;
- // remove number from end to avoid lengthy names
- std::string objname = obj->getNameInDocument();
- if (!keepdigitsatend) {
- size_t lastpos = objname.length()-1;
- while (objname[lastpos] >= 48 && objname[lastpos] <= 57)
- lastpos--;
- objname = objname.substr(0, lastpos+1);
- }
- DocumentObject* copy = addObject(obj->getTypeId().getName(),objname.c_str());
- if (!copy) return 0;
- copy->addDynamicProperties(obj);
+ std::vector objs;
+ objs.push_back(obj);
- copy_map[obj] = copy;
-
- std::map props;
- copy->getPropertyMap(props);
- for (std::map::iterator it = props.begin(); it != props.end(); ++it) {
- App::Property* prop = obj->getPropertyByName(it->first.c_str());
- if (prop && prop->getTypeId() == it->second->getTypeId()) {
- if (prop->getTypeId() == PropertyLink::getClassTypeId()) {
- DocumentObject* link = static_cast(prop)->getValue();
- std::map::iterator pt = copy_map.find(link);
- if (pt != copy_map.end()) {
- // the object has already been copied
- static_cast(it->second)->setValue(pt->second);
- }
- else if (recursive) {
- DocumentObject* link_copy = _copyObject(link, copy_map, recursive, keepdigitsatend);
- copy_map[link] = link_copy;
- static_cast(it->second)->setValue(link_copy);
- }
- else if (link && link->getDocument() == this) {
- //static_cast(it->second)->setValue(link);
- }
- }
- else if (prop->getTypeId() == PropertyLinkList::getClassTypeId()) {
- std::vector links = static_cast(prop)->getValues();
- if (recursive) {
- std::vector links_copy;
- for (std::vector::iterator jt = links.begin(); jt != links.end(); ++jt) {
- std::map::iterator pt = copy_map.find(*jt);
- if (pt != copy_map.end()) {
- // the object has already been copied
- links_copy.push_back(pt->second);
- }
- else {
- links_copy.push_back(_copyObject(*jt, copy_map, recursive, keepdigitsatend));
- copy_map[*jt] = links_copy.back();
- }
- }
- static_cast(it->second)->setValues(links_copy);
- }
- else {
- std::vector links_ref;
- //for (std::vector::iterator jt = links.begin(); jt != links.end(); ++jt) {
- // if ((*jt)->getDocument() == this)
- // links_ref.push_back(*jt);
- //}
- static_cast(it->second)->setValues(links_ref);
- }
- }
- else {
- std::auto_ptr data(prop->Copy());
- if (data.get()) {
- it->second->Paste(*data);
- }
- }
- }
+ MergeDocuments md(this);
+ if (recursive) {
+ objs = getDependencyList(objs);
}
- // unmark to be not re-computed later
- copy->onFinishDuplicating();
- copy->purgeTouched();
- return copy;
-}
+ unsigned int memsize=1000; // ~ for the meta-information
+ for (std::vector::iterator it = objs.begin(); it != objs.end(); ++it)
+ memsize += (*it)->getMemSize();
-DocumentObject* Document::copyObject(DocumentObject* obj, bool recursive, bool keepdigitsatend)
-{
- std::map copy_map;
- DocumentObject* copy = _copyObject(obj, copy_map, recursive, keepdigitsatend);
- return copy;
+ QByteArray res;
+ res.reserve(memsize);
+ Base::ByteArrayOStreambuf obuf(res);
+ std::ostream ostr(&obuf);
+ this->exportObjects(objs, ostr);
+
+ Base::ByteArrayIStreambuf ibuf(res);
+ std::istream istr(0);
+ istr.rdbuf(&ibuf);
+ std::vector newObj = md.importObjects(istr);
+ if (newObj.empty())
+ return 0;
+ else
+ return newObj.back();
}
DocumentObject* Document::moveObject(DocumentObject* obj, bool recursive)
diff --git a/src/App/Document.h b/src/App/Document.h
index bd7f63023..af1acb71e 100644
--- a/src/App/Document.h
+++ b/src/App/Document.h
@@ -294,8 +294,6 @@ protected:
void _remObject(DocumentObject* pcObject);
void _addObject(DocumentObject* pcObject, const char* pObjectName);
- DocumentObject* _copyObject(DocumentObject* obj, std::map&, bool recursive=false, bool keepdigitsatend=false);
/// checks if a valid transaction is open
void _checkTransaction(DocumentObject* pcObject);
void breakDependency(DocumentObject* pcObject, bool clear);
diff --git a/src/App/DocumentObject.h b/src/App/DocumentObject.h
index 8d8ad091f..22b096cc2 100644
--- a/src/App/DocumentObject.h
+++ b/src/App/DocumentObject.h
@@ -196,8 +196,6 @@ protected:
virtual void onChanged(const Property* prop);
/// get called after a document has been fully restored
virtual void onDocumentRestored() {}
- /// get called after duplicating an object
- virtual void onFinishDuplicating() {}
/// get called after setting the document
virtual void onSettingDocument() {}
diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp
index 059cdfb44..05e2f9b48 100644
--- a/src/Mod/Sketcher/App/SketchObject.cpp
+++ b/src/Mod/Sketcher/App/SketchObject.cpp
@@ -1656,13 +1656,6 @@ void SketchObject::onDocumentRestored()
}
}
-void SketchObject::onFinishDuplicating()
-{
- Constraints.acceptGeometry(getCompleteGeometry());
- rebuildVertexIndex();
- onDocumentRestored();
-}
-
void SketchObject::getGeoVertexIndex(int VertexId, int &GeoId, PointPos &PosId) const
{
if (VertexId < 0 || VertexId >= int(VertexId2GeoId.size())) {
diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h
index 0abac2f99..c04859fb5 100644
--- a/src/Mod/Sketcher/App/SketchObject.h
+++ b/src/Mod/Sketcher/App/SketchObject.h
@@ -163,7 +163,6 @@ protected:
/// get called by the container when a property has changed
virtual void onChanged(const App::Property* /*prop*/);
virtual void onDocumentRestored();
- virtual void onFinishDuplicating();
private:
std::vector ExternalGeo;