From b32369d1850f1ecc8f463e2e376dda74777bff9c Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Wed, 21 Jul 2021 17:10:05 +0800 Subject: [PATCH] App: insert UUID property to trace the source of copied object A property _ObjectUUID will be added to an object before it is being to copied, if the property does not exists. Anoter propert _SourceUUID property will be added to any copied object, with value set to its source objct's _ObjectUUID. --- src/App/Document.cpp | 22 +++++++++++++++++++++- src/Base/Uuid.h | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) 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; };