LCS migration : replace warning by a QMessageBox.

This commit is contained in:
PaddleStroke
2024-12-11 11:22:47 +01:00
parent 1ce8f2c859
commit e517400ed9
4 changed files with 57 additions and 17 deletions

View File

@@ -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<App::DatumElement>() &&
strcmp(static_cast<App::DatumElement*>(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;
}
}
// ----------------------------------------------------------------------------

View File

@@ -205,6 +205,8 @@ public:
// Axis links
PropertyLinkList OriginFeatures;
bool migrated;
protected:
/// Checks integrity of the LCS
App::DocumentObjectExecReturn* execute() override;

View File

@@ -26,6 +26,8 @@
#ifndef _PreComp_
# include <Inventor/nodes/SoLightModel.h>
# include <Inventor/nodes/SoSeparator.h>
# include <QMessageBox>
# include <QCheckBox>
#endif
#include <App/Document.h>
@@ -83,6 +85,50 @@ void ViewProviderCoordinateSystem::attach(App::DocumentObject* pcObject)
addDisplayMaskMode(pcGroupChildren, "Base");
}
void ViewProviderCoordinateSystem::finishRestoring()
{
showMigrationDialog();
}
void ViewProviderCoordinateSystem::showMigrationDialog()
{
auto lcs = dynamic_cast<App::LocalCoordinateSystem*>(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<std::string> ViewProviderCoordinateSystem::getDisplayModes() const
{
return { "Base" };

View File

@@ -83,7 +83,11 @@ protected:
void updateData(const App::Property*) override;
bool onDelete(const std::vector<std::string> &) override;
void finishRestoring() override;
private:
void showMigrationDialog();
SoGroup *pcGroupChildren;
std::map<Gui::ViewProvider*, bool> tempVisMap;