diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 3db5e438c3..bfe0493b41 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1835,8 +1835,15 @@ void Document::exportObjects(const std::vector& obj, std:: if(FC_LOG_INSTANCE.isEnabled(FC_LOGLEVEL_LOG)) { for(auto o : obj) { - if(o && o->getNameInDocument()) + if(o && o->getNameInDocument()) { FC_LOG("exporting " << o->getFullName()); + if (!o->getPropertyByName("_ObjectUUID")) { + auto prop = static_cast(o->addDynamicProperty( + "App::PropertyUUID", "_ObjectUUID", nullptr, nullptr, + Prop_Output | Prop_Hidden)); + prop->setValue(Base::Uuid::createUuid()); + } + } } } @@ -2195,6 +2202,19 @@ Document::importObjects(Base::XMLReader& reader) if(o && o->getNameInDocument()) { o->setStatus(App::ObjImporting,true); FC_LOG("importing " << o->getFullName()); + if (auto propUUID = Base::freecad_dynamic_cast( + o->getPropertyByName("_ObjectUUID"))) + { + auto propSource = Base::freecad_dynamic_cast( + o->getPropertyByName("_SourceUUID")); + if (!propSource) + propSource = static_cast(o->addDynamicProperty( + "App::PropertyUUID", "_SourceUUID", nullptr, nullptr, + Prop_Output | Prop_Hidden)); + if (propSource) + propSource->setValue(propUUID->getValue()); + propUUID->setValue(Base::Uuid::createUuid()); + } } } diff --git a/src/Base/Uuid.h b/src/Base/Uuid.h index 93e7d1986e..1e68a533ce 100644 --- a/src/Base/Uuid.h +++ b/src/Base/Uuid.h @@ -50,6 +50,9 @@ public: const std::string& getValue(void) const; static std::string createUuid(void); + bool operator==(const Uuid &other) const {return _uuid == other._uuid;} + bool operator<(const Uuid &other) const {return _uuid < other._uuid;} + private: std::string _uuid; };