diff --git a/src/App/Datums.cpp b/src/App/Datums.cpp index 3157ea4cd3..7afcf4b754 100644 --- a/src/App/Datums.cpp +++ b/src/App/Datums.cpp @@ -292,13 +292,11 @@ void LocalCoordinateSystem::migrateOriginPoint() { auto features = OriginFeatures.getValues(); - auto featIt = std::find_if(features.begin(), features.end(), - [](App::DocumentObject* obj) { - return obj->isDerivedFrom(App::DatumElement::getClassTypeId()) && + auto isOrigin = [](App::DocumentObject* obj) { + return obj->isDerivedFrom() && strcmp(static_cast(obj)->Role.getValue(), PointRoles[0]) == 0; - }); - if (featIt == features.end()) { - // origin point not found let's add it + }; + if (std::none_of(features.begin(), features.end(), isOrigin)) { auto data = getData(PointRoles[0]); auto* origin = createDatum(data); features.push_back(origin); @@ -310,7 +308,7 @@ void LocalCoordinateSystem::migrateXAxisPlacement() { auto features = OriginFeatures.getValues(); - bool migrated = false; + migrated = false; const auto& setupData = getSetupData(); for (auto* obj : features) { @@ -326,16 +324,6 @@ void LocalCoordinateSystem::migrateXAxisPlacement() } } } - - static bool warnedUser = false; - if (!warnedUser && migrated) { - Base::Console().Warning("This file was created with an older version of FreeCAD." - "It had some origin's X axis with incorrect placement, which is being fixed now.\n" - "But if you save the file here and open this file back in an " - "older version of FreeCAD, you will find the origin objects axis looking incorrect." - "And if your file is using the origin axis as references it will likely be broken.\n"); - warnedUser = true; - } } // ---------------------------------------------------------------------------- diff --git a/src/App/Datums.h b/src/App/Datums.h index 286e7353f3..43c08a285e 100644 --- a/src/App/Datums.h +++ b/src/App/Datums.h @@ -205,6 +205,8 @@ public: // Axis links PropertyLinkList OriginFeatures; + bool migrated; + protected: /// Checks integrity of the LCS App::DocumentObjectExecReturn* execute() override; diff --git a/src/Gui/ViewProviderCoordinateSystem.cpp b/src/Gui/ViewProviderCoordinateSystem.cpp index 15c686a023..45d8707524 100644 --- a/src/Gui/ViewProviderCoordinateSystem.cpp +++ b/src/Gui/ViewProviderCoordinateSystem.cpp @@ -26,6 +26,8 @@ #ifndef _PreComp_ # include # include +# include +# include #endif #include @@ -83,6 +85,50 @@ 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 02a392d4e1..2448bc6acf 100644 --- a/src/Gui/ViewProviderCoordinateSystem.h +++ b/src/Gui/ViewProviderCoordinateSystem.h @@ -83,7 +83,11 @@ protected: void updateData(const App::Property*) override; bool onDelete(const std::vector &) override; + void finishRestoring() override; + private: + void showMigrationDialog(); + SoGroup *pcGroupChildren; std::map tempVisMap;