diff --git a/src/App/Application.cpp b/src/App/Application.cpp index b10f81af1d..b76a8a3b11 100644 --- a/src/App/Application.cpp +++ b/src/App/Application.cpp @@ -911,6 +911,7 @@ std::vector Application::openDocuments(const std::vector FC_DURATION_LOG(timing.d2, doc.getDocumentName() << " postprocess"); } FC_TIME_LOG(t,"total"); + PropertyLinkBase::updateAllElementReferences(); _isRestoring = false; signalFinishOpenDocument(); diff --git a/src/App/PropertyLinks.cpp b/src/App/PropertyLinks.cpp index c5c80cbf4c..341484375a 100644 --- a/src/App/PropertyLinks.cpp +++ b/src/App/PropertyLinks.cpp @@ -299,6 +299,27 @@ void PropertyLinkBase::updateElementReferences(DocumentObject* feature, bool rev } } +void PropertyLinkBase::updateAllElementReferences(bool reverse) +{ + for (auto reference : _ElementRefMap) { + for (auto prop : reference.second) { + if (prop->getContainer()) { + try { + prop->updateElementReference(reference.first, reverse, true); + } + catch (Base::Exception& e) { + e.reportException(); + FC_ERR("Failed to update element reference of " << propertyName(prop)); + } + catch (std::exception& e) { + FC_ERR("Failed to update element reference of " << propertyName(prop) << ": " + << e.what()); + } + } + } + } +} + void PropertyLinkBase::_registerElementReference(App::DocumentObject* obj, std::string& sub, ShadowSub& shadow) @@ -1573,7 +1594,6 @@ void PropertyLinkSub::onContainerRestored() for (std::size_t i = 0; i < _cSubList.size(); ++i) { _registerElementReference(_pcLinkSub, _cSubList[i], _ShadowSubList[i]); } - updateElementReferences(_pcLinkSub); } void PropertyLinkSub::updateElementReference(DocumentObject* feature, bool reverse, bool notify) @@ -4086,7 +4106,7 @@ void PropertyXLink::onContainerRestored() _registerElementReference(_pcLink, _SubList[i], _ShadowSubList[i]); } - updateElementReferences(_pcLink); + // updateElementReferences(_pcLink); } void PropertyXLink::updateElementReference(DocumentObject* feature, bool reverse, bool notify) diff --git a/src/App/PropertyLinks.h b/src/App/PropertyLinks.h index 587f0d22dd..1466958948 100644 --- a/src/App/PropertyLinks.h +++ b/src/App/PropertyLinks.h @@ -385,6 +385,9 @@ public: /// Update all element references in all link properties of \a feature static void updateElementReferences(DocumentObject* feature, bool reverse = false); + + /// Update all element references in the _ElementRefMap + static void updateAllElementReferences(bool reverse = false); /// Obtain link properties that contain element references to a given object static const std::unordered_set& getElementReferences(DocumentObject*);