From c016e81a7faaf863da93178b2bfcfefaa4c59b76 Mon Sep 17 00:00:00 2001 From: Syres916 <46537884+Syres916@users.noreply.github.com> Date: Mon, 25 Nov 2024 16:50:58 +0000 Subject: [PATCH] [Part] [Post 1.0] Preferences > Shape view > Maximum angle deflection warn user... (#16007) * [Part] Preferences max angle deflection alert * [Part] Comment added as requested --- src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp | 65 +++++++++++++++---- src/Mod/Part/Gui/DlgSettings3DViewPartImp.h | 1 + 2 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp index cb6210b5cd..554051d968 100644 --- a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp +++ b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.cpp @@ -42,15 +42,27 @@ using namespace PartGui; * name 'name' and widget flags set to 'f' */ DlgSettings3DViewPart::DlgSettings3DViewPart(QWidget* parent) - : PreferencePage(parent), ui(new Ui_DlgSettings3DViewPart), checkValue(false) + : PreferencePage(parent) + , ui(new Ui_DlgSettings3DViewPart) + , checkValue(false) { ui->setupUi(this); - connect(ui->maxDeviation, qOverload(&QDoubleSpinBox::valueChanged), - this, &DlgSettings3DViewPart::onMaxDeviationValueChanged); - ParameterGrp::handle hPart = App::GetApplication().GetParameterGroupByPath - ("User parameter:BaseApp/Preferences/Mod/Part"); - double lowerLimit = hPart->GetFloat("MinimumDeviation", ui->maxDeviation->minimum()); - ui->maxDeviation->setMinimum(lowerLimit); + connect(ui->maxDeviation, + qOverload(&QDoubleSpinBox::valueChanged), + this, + &DlgSettings3DViewPart::onMaxDeviationValueChanged); + connect(ui->maxAngularDeflection, + qOverload(&QDoubleSpinBox::valueChanged), + this, + &DlgSettings3DViewPart::onMaxAngularDeflectionValueChanged); + ParameterGrp::handle hPart = App::GetApplication().GetParameterGroupByPath( + "User parameter:BaseApp/Preferences/Mod/Part"); + const double minDeviationlowerLimit = hPart->GetFloat( + "MinimumDeviation", ui->maxDeviation->minimum()); + ui->maxDeviation->setMinimum(minDeviationlowerLimit); + const double minAngleDeflectionlowerLimit = hPart->GetFloat( + "MinimumDeviation", ui->maxAngularDeflection->minimum()); + ui->maxAngularDeflection->setMinimum(minAngleDeflectionlowerLimit); } /** @@ -58,15 +70,40 @@ DlgSettings3DViewPart::DlgSettings3DViewPart(QWidget* parent) */ DlgSettings3DViewPart::~DlgSettings3DViewPart() = default; -void DlgSettings3DViewPart::onMaxDeviationValueChanged(double v) +void DlgSettings3DViewPart::onMaxDeviationValueChanged(double vMaxDev) { - if (!this->isVisible()) + if (!this->isVisible()) { return; - if (v < 0.01 && !checkValue) { + } + const double maxDevMinThreshold = 0.01; + if (vMaxDev < maxDevMinThreshold && !checkValue) { checkValue = true; - QMessageBox::warning(this, tr("Deviation"), + QMessageBox::warning( + this, + tr("Deviation"), tr("Setting a too small deviation causes the tessellation to take longer" - "and thus freezes or slows down the GUI.")); + " and thus freezes or slows down the GUI.")); + } +} + +void DlgSettings3DViewPart::onMaxAngularDeflectionValueChanged(double vMaxAngle) +{ + if (!this->isVisible()) { + return; + } + /** + * The lower threshold of 2.0 was determined by testing + * as laid out in the table as per comment hyperlink: + * https://github.com/FreeCAD/FreeCAD/issues/15951#issuecomment-2304308163 + */ + const double vMaxAngleMinThreshold = 2.0; + if (vMaxAngle < vMaxAngleMinThreshold && !checkValue) { + checkValue = true; + QMessageBox::warning( + this, + tr("Angle Deflection"), + tr("Setting a too small angle deviation causes the tessellation to take longer" + " and thus freezes or slows down the GUI.")); } } @@ -79,13 +116,13 @@ void DlgSettings3DViewPart::saveSettings() std::vector docs = App::GetApplication().getDocuments(); for (auto it : docs) { Gui::Document* doc = Gui::Application::Instance->getDocument(it); - std::vector views = doc->getViewProvidersOfType(ViewProviderPart::getClassTypeId()); + std::vector views = + doc->getViewProvidersOfType(ViewProviderPart::getClassTypeId()); for (auto view : views) { static_cast(view)->reload(); } } } - void DlgSettings3DViewPart::loadSettings() { ui->maxDeviation->onRestore(); diff --git a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.h b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.h index 3e62ee18f6..d3d9d5f304 100644 --- a/src/Mod/Part/Gui/DlgSettings3DViewPartImp.h +++ b/src/Mod/Part/Gui/DlgSettings3DViewPartImp.h @@ -49,6 +49,7 @@ protected: private: void onMaxDeviationValueChanged(double); + void onMaxAngularDeflectionValueChanged(double); private: std::unique_ptr ui;