Skip to content
This repository was archived by the owner on Mar 1, 2025. It is now read-only.

Commit e517400

Browse files
committed
LCS migration : replace warning by a QMessageBox.
1 parent 1ce8f2c commit e517400

File tree

4 files changed

+57
-17
lines changed

4 files changed

+57
-17
lines changed

src/App/Datums.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -292,13 +292,11 @@ void LocalCoordinateSystem::migrateOriginPoint()
292292
{
293293
auto features = OriginFeatures.getValues();
294294

295-
auto featIt = std::find_if(features.begin(), features.end(),
296-
[](App::DocumentObject* obj) {
297-
return obj->isDerivedFrom(App::DatumElement::getClassTypeId()) &&
295+
auto isOrigin = [](App::DocumentObject* obj) {
296+
return obj->isDerivedFrom<App::DatumElement>() &&
298297
strcmp(static_cast<App::DatumElement*>(obj)->Role.getValue(), PointRoles[0]) == 0;
299-
});
300-
if (featIt == features.end()) {
301-
// origin point not found let's add it
298+
};
299+
if (std::none_of(features.begin(), features.end(), isOrigin)) {
302300
auto data = getData(PointRoles[0]);
303301
auto* origin = createDatum(data);
304302
features.push_back(origin);
@@ -310,7 +308,7 @@ void LocalCoordinateSystem::migrateXAxisPlacement()
310308
{
311309
auto features = OriginFeatures.getValues();
312310

313-
bool migrated = false;
311+
migrated = false;
314312

315313
const auto& setupData = getSetupData();
316314
for (auto* obj : features) {
@@ -326,16 +324,6 @@ void LocalCoordinateSystem::migrateXAxisPlacement()
326324
}
327325
}
328326
}
329-
330-
static bool warnedUser = false;
331-
if (!warnedUser && migrated) {
332-
Base::Console().Warning("This file was created with an older version of FreeCAD."
333-
"It had some origin's X axis with incorrect placement, which is being fixed now.\n"
334-
"But if you save the file here and open this file back in an "
335-
"older version of FreeCAD, you will find the origin objects axis looking incorrect."
336-
"And if your file is using the origin axis as references it will likely be broken.\n");
337-
warnedUser = true;
338-
}
339327
}
340328

341329
// ----------------------------------------------------------------------------

src/App/Datums.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,8 @@ class AppExport LocalCoordinateSystem: public App::GeoFeature
205205
// Axis links
206206
PropertyLinkList OriginFeatures;
207207

208+
bool migrated;
209+
208210
protected:
209211
/// Checks integrity of the LCS
210212
App::DocumentObjectExecReturn* execute() override;

src/Gui/ViewProviderCoordinateSystem.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
#ifndef _PreComp_
2727
# include <Inventor/nodes/SoLightModel.h>
2828
# include <Inventor/nodes/SoSeparator.h>
29+
# include <QMessageBox>
30+
# include <QCheckBox>
2931
#endif
3032

3133
#include <App/Document.h>
@@ -83,6 +85,50 @@ void ViewProviderCoordinateSystem::attach(App::DocumentObject* pcObject)
8385
addDisplayMaskMode(pcGroupChildren, "Base");
8486
}
8587

88+
void ViewProviderCoordinateSystem::finishRestoring()
89+
{
90+
showMigrationDialog();
91+
}
92+
93+
void ViewProviderCoordinateSystem::showMigrationDialog()
94+
{
95+
auto lcs = dynamic_cast<App::LocalCoordinateSystem*>(getObject());
96+
if (!lcs || !lcs->migrated) {
97+
return;
98+
}
99+
100+
static bool userWarned = false;
101+
102+
if (userWarned || !App::GetApplication().GetParameterGroupByPath(
103+
"User parameter:BaseApp/Preferences/View")->GetBool("ShowLCSMigrationWarning", true)) {
104+
return;
105+
}
106+
107+
// Display the warning message
108+
QMessageBox msgBox(QMessageBox::Warning,
109+
QObject::tr("File Migration Warning"),
110+
QObject::tr("This file was created with an older version of FreeCAD. "
111+
"Origin axes had incorrect placements, which have now been corrected.\n\n"
112+
"However, if you save this file in the current version and reopen it in an"
113+
" older version of FreeCAD, the origin axes will be misaligned. Additionally, "
114+
"if your file references these origin axes, your file will likely be broken."),
115+
QMessageBox::Ok);
116+
117+
QCheckBox* checkBox = new QCheckBox(QObject::tr("Don't show this warning again"));
118+
msgBox.setCheckBox(checkBox);
119+
120+
msgBox.exec();
121+
122+
// Update static flag if the user has seen the warning
123+
userWarned = true;
124+
125+
// Save preference if the user selects "Don't show again"
126+
if (checkBox->isChecked()) {
127+
App::GetApplication().GetParameterGroupByPath(
128+
"User parameter:BaseApp/Preferences/View")->SetBool("ShowLCSMigrationWarning", false);
129+
}
130+
}
131+
86132
std::vector<std::string> ViewProviderCoordinateSystem::getDisplayModes() const
87133
{
88134
return { "Base" };

src/Gui/ViewProviderCoordinateSystem.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ class GuiExport ViewProviderCoordinateSystem : public ViewProviderGeoFeatureGrou
8383
void updateData(const App::Property*) override;
8484
bool onDelete(const std::vector<std::string> &) override;
8585

86+
void finishRestoring() override;
87+
8688
private:
89+
void showMigrationDialog();
90+
8791
SoGroup *pcGroupChildren;
8892

8993
std::map<Gui::ViewProvider*, bool> tempVisMap;

0 commit comments

Comments
 (0)