Core: Move LCS migration warning to Std_Open command
This commit is contained in:
@@ -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 <App::DatumElement*> (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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#ifndef _PreComp_
|
||||
# include <Inventor/nodes/SoCamera.h>
|
||||
# include <QApplication>
|
||||
# include <QCheckBox>
|
||||
# include <QClipboard>
|
||||
# include <QDateTime>
|
||||
# include <QMessageBox>
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,50 +85,6 @@ 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" };
|
||||
|
||||
@@ -83,11 +83,7 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user