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:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user