From 0d4e7ac27fd09b62157da5808efa1e216dec7a9a Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 15 Dec 2024 16:46:03 +0100 Subject: [PATCH] Core: Move LCS migration warning to Std_Open command --- src/App/Datums.cpp | 4 +- src/App/Datums.h | 4 +- src/App/Document.h | 1 + src/Gui/CommandDoc.cpp | 66 ++++++++++++++++++++---- src/Gui/ViewProviderCoordinateSystem.cpp | 44 ---------------- src/Gui/ViewProviderCoordinateSystem.h | 4 -- 6 files changed, 59 insertions(+), 64 deletions(-) diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index ab972e3506..a551381c45 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -309,8 +309,6 @@ void LocalCoordinateSystem::migrateXAxisPlacement() constexpr const double tolerance = 1e-5; auto features = OriginFeatures.getValues(); - migrated = false; - const auto& setupData = getSetupData(); for (auto* obj : features) { auto* feature = dynamic_cast (obj); @@ -320,7 +318,7 @@ void LocalCoordinateSystem::migrateXAxisPlacement() if (std::strcmp(feature->Role.getValue(), data.role) == 0) { if (!feature->Placement.getValue().getRotation().isSame(data.rot, tolerance)) { feature->Placement.setValue(Base::Placement(Base::Vector3d(), data.rot)); - migrated = true; + getDocument()->setStatus(App::Document::MigrateLCS, true); } break; } diff --git a/src/App/Datums.h b/src/App/Datums.h index 43c08a285e..b199ffebd8 100644 --- a/src/App/Datums.h +++ b/src/App/Datums.h @@ -200,13 +200,11 @@ public: virtual bool isOrigin() { return false; - }; + } // Axis links PropertyLinkList OriginFeatures; - bool migrated; - protected: /// Checks integrity of the LCS App::DocumentObjectExecReturn* execute() override; diff --git a/src/App/Document.h b/src/App/Document.h index 36a878ee10..d5fe85b47c 100644 --- a/src/App/Document.h +++ b/src/App/Document.h @@ -77,6 +77,7 @@ public: 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 purposes + MigrateLCS = 14 // Migrate local coordinate system of older versions }; // clang-format on diff --git a/src/Gui/CommandDoc.cpp b/src/Gui/CommandDoc.cpp index b38065d151..f6791360ad 100644 --- a/src/Gui/CommandDoc.cpp +++ b/src/Gui/CommandDoc.cpp @@ -25,6 +25,7 @@ #ifndef _PreComp_ # include # include +# include # include # include # include @@ -95,6 +96,56 @@ StdCmdOpen::StdCmdOpen() void StdCmdOpen::activated(int iMsg) { + // clang-format off + auto checkPartialRestore = [](App::Document* doc) { + if (doc && doc->testStatus(App::Document::PartialRestore)) { + QMessageBox::critical(getMainWindow(), QObject::tr("Error"), + QObject::tr("There were errors while loading the file. Some data might have been " + "modified or not recovered at all. Look in the report view for more " + "specific information about the objects involved.")); + } + }; + + auto checkRestoreError = [](App::Document* doc) { + if (doc && doc->testStatus(App::Document::RestoreError)) { + QMessageBox::critical(getMainWindow(), QObject::tr("Error"), + QObject::tr("There were serious errors while loading the file. Some data might have " + "been modified or not recovered at all. Saving the project will most " + "likely result in loss of data.")); + } + }; + + auto checkMigrationLCS = [](App::Document* doc) { + if (doc && doc->testStatus(App::Document::MigrateLCS)) { + auto grp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + if (!grp->GetBool("ShowLCSMigrationWarning", true)) { + return; + } + + // Display the warning message + QMessageBox msgBox(QMessageBox::Warning, + QObject::tr("File Migration Warning"), + QObject::tr("This file was created with an older version of %1. " + "Origin axes had incorrect placements, which have now been corrected.\n\n" + "However, if you save this file in the current version and reopen it in an" + " older version of %1, the origin axes will be misaligned. Additionally, " + "if your file references these origin axes, your file will likely be broken.") + .arg(QApplication::applicationName()), + QMessageBox::Ok); + + QCheckBox* checkBox = new QCheckBox(QObject::tr("Don't show this warning again")); + msgBox.setCheckBox(checkBox); + + msgBox.exec(); + + // Save preference if the user selects "Don't show again" + if (checkBox->isChecked()) { + grp->SetBool("ShowLCSMigrationWarning", false); + } + } + }; + // clang-format on + Q_UNUSED(iMsg); // fill the list of registered endings @@ -139,8 +190,9 @@ void StdCmdOpen::activated(int iMsg) QString selectedFilter; QStringList fileList = FileDialog::getOpenFileNames(getMainWindow(), QObject::tr("Open document"), QString(), formatList, &selectedFilter); - if (fileList.isEmpty()) + if (fileList.isEmpty()) { return; + } // load the files with the associated modules SelectModule::Dict dict = SelectModule::importHandler(fileList, selectedFilter); @@ -161,15 +213,9 @@ void StdCmdOpen::activated(int iMsg) App::Document *doc = App::GetApplication().getActiveDocument(); - if(doc && doc->testStatus(App::Document::PartialRestore)) { - QMessageBox::critical(getMainWindow(), QObject::tr("Error"), - QObject::tr("There were errors while loading the file. Some data might have been modified or not recovered at all. Look in the report view for more specific information about the objects involved.")); - } - - if(doc && doc->testStatus(App::Document::RestoreError)) { - QMessageBox::critical(getMainWindow(), QObject::tr("Error"), - QObject::tr("There were serious errors while loading the file. Some data might have been modified or not recovered at all. Saving the project will most likely result in loss of data.")); - } + checkPartialRestore(doc); + checkRestoreError(doc); + checkMigrationLCS(doc); } } } diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 45d8707524..689c51aef4 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -85,50 +85,6 @@ void ViewProviderCoordinateSystem::attach(App::DocumentObject* pcObject) addDisplayMaskMode(pcGroupChildren, "Base"); } -void ViewProviderCoordinateSystem::finishRestoring() -{ - showMigrationDialog(); -} - -void ViewProviderCoordinateSystem::showMigrationDialog() -{ - auto lcs = dynamic_cast(getObject()); - if (!lcs || !lcs->migrated) { - return; - } - - static bool userWarned = false; - - if (userWarned || !App::GetApplication().GetParameterGroupByPath( - "User parameter:BaseApp/Preferences/View")->GetBool("ShowLCSMigrationWarning", true)) { - return; - } - - // Display the warning message - QMessageBox msgBox(QMessageBox::Warning, - QObject::tr("File Migration Warning"), - QObject::tr("This file was created with an older version of FreeCAD. " - "Origin axes had incorrect placements, which have now been corrected.\n\n" - "However, if you save this file in the current version and reopen it in an" - " older version of FreeCAD, the origin axes will be misaligned. Additionally, " - "if your file references these origin axes, your file will likely be broken."), - QMessageBox::Ok); - - QCheckBox* checkBox = new QCheckBox(QObject::tr("Don't show this warning again")); - msgBox.setCheckBox(checkBox); - - msgBox.exec(); - - // Update static flag if the user has seen the warning - userWarned = true; - - // Save preference if the user selects "Don't show again" - if (checkBox->isChecked()) { - App::GetApplication().GetParameterGroupByPath( - "User parameter:BaseApp/Preferences/View")->SetBool("ShowLCSMigrationWarning", false); - } -} - std::vector ViewProviderCoordinateSystem::getDisplayModes() const { return { "Base" }; diff --git a/src/Gui/ViewProviderCoordinateSystem.h b/src/Gui/ViewProviderCoordinateSystem.h index 2448bc6acf..02a392d4e1 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -83,11 +83,7 @@ protected: void updateData(const App::Property*) override; bool onDelete(const std::vector &) override; - void finishRestoring() override; - private: - void showMigrationDialog(); - SoGroup *pcGroupChildren; std::map tempVisMap;