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.
This commit is contained in:
Zheng, Lei
2021-07-21 17:10:05 +08:00
committed by Chris Hennes
parent d286a54fc1
commit b32369d185
2 changed files with 24 additions and 1 deletions

View File

@@ -1835,8 +1835,15 @@ void Document::exportObjects(const std::vector<App::DocumentObject*>& 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<PropertyUUID*>(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<PropertyUUID>(
o->getPropertyByName("_ObjectUUID")))
{
auto propSource = Base::freecad_dynamic_cast<PropertyUUID>(
o->getPropertyByName("_SourceUUID"));
if (!propSource)
propSource = static_cast<PropertyUUID*>(o->addDynamicProperty(
"App::PropertyUUID", "_SourceUUID", nullptr, nullptr,
Prop_Output | Prop_Hidden));
if (propSource)
propSource->setValue(propUUID->getValue());
propUUID->setValue(Base::Uuid::createUuid());
}
}
}

View File

@@ -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;
};