From 445a8846822a17a25646ce38648b8c71906ab2d7 Mon Sep 17 00:00:00 2001 From: "Zheng, Lei" Date: Sat, 14 Sep 2024 09:08:04 -0400 Subject: [PATCH] Transfer in LS3 code --- src/App/Document.cpp | 1 + src/App/Document.h | 1 + src/Gui/Application.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/App/Document.cpp b/src/App/Document.cpp index 91b330bdb8..c3e3f921d5 100644 --- a/src/App/Document.cpp +++ b/src/App/Document.cpp @@ -1475,6 +1475,7 @@ Document::readObjects(Base::XMLReader& reader) void Document::addRecomputeObject(DocumentObject *obj) { if(testStatus(Status::Restoring) && obj) { + setStatus(Status::RecomputeOnRestore, true); d->touchedObjs.insert(obj); obj->touch(); } diff --git a/src/App/Document.h b/src/App/Document.h index c178df04e9..76bc7da902 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -77,6 +77,7 @@ public: RestoreError = 10, LinkStampChanged = 11, // Indicates during restore time if any linked document's time stamp has changed IgnoreErrorOnRecompute = 12, // Don't report errors if the recompute failed + RecomputeOnRestore = 13, // Mark pending recompute on restore for migration purpose }; /** @name Properties */ diff --git a/src/Gui/Application.cpp b/src/Gui/Application.cpp index cd46f0b4a2..f2a0dae48a 100644 --- a/src/Gui/Application.cpp +++ b/src/Gui/Application.cpp @@ -379,6 +379,40 @@ Application::Application(bool GUIenabled) App::GetApplication().signalShowHidden.connect( std::bind(&Gui::Application::slotShowHidden, this, sp::_1)); // NOLINTEND + App::GetApplication().signalFinishOpenDocument.connect([]() { + std::vector docs; + for(auto doc : App::GetApplication().getDocuments()) { + if(doc->testStatus(App::Document::RecomputeOnRestore)) { + docs.push_back(doc); + doc->setStatus(App::Document::RecomputeOnRestore, false); + } + } + if(docs.empty() || !App::DocumentParams::getWarnRecomputeOnRestore()) + return; + WaitCursor wc; + wc.restoreCursor(); + auto res = QMessageBox::warning(getMainWindow(), QObject::tr("Recompution required"), + QObject::tr("Some document(s) require recomputation for migration purpose. " + "It is highly recommended to perform a recomputation before " + "any modification to avoid compatibility problem.\n\n" + "Do you want to recompute now?"), + QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes); + if(res != QMessageBox::Yes) + return; + bool hasError = false; + for(auto doc : App::Document::getDependentDocuments(docs,true)) { + try { + doc->recompute({},false,&hasError); + } catch (Base::Exception &e) { + e.ReportException(); + hasError = true; + } + } + if(hasError) + QMessageBox::critical(getMainWindow(), QObject::tr("Recompute error"), + QObject::tr("Failed to recompute some document(s).\n" + "Please check report view for more details.")); + }); // install the last active language ParameterGrp::handle hPGrp = App::GetApplication().GetUserParameter().GetGroup("BaseApp");