From 0a5a049c87530bd8ecf35b7def71ac7eed51ae3e Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 26 May 2024 23:26:07 +0200 Subject: [PATCH] Sketcher: Fixes #14240 --- src/Mod/Sketcher/App/SketchAnalysis.cpp | 20 ++++++++----------- src/Mod/Sketcher/App/SketchObject.cpp | 10 ++++++++++ src/Mod/Sketcher/App/SketchObject.h | 5 +++++ .../Sketcher/Gui/TaskSketcherValidation.cpp | 12 +++++------ src/Mod/Sketcher/Gui/TaskSketcherValidation.h | 2 -- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchAnalysis.cpp b/src/Mod/Sketcher/App/SketchAnalysis.cpp index c51e6db205..5a09e5a7ad 100644 --- a/src/Mod/Sketcher/App/SketchAnalysis.cpp +++ b/src/Mod/Sketcher/App/SketchAnalysis.cpp @@ -445,21 +445,18 @@ void SketchAnalysis::analyseMissingPointOnPointCoincident(double angleprecision) } } - void SketchAnalysis::makeMissingPointOnPointCoincident(bool onebyone) { int status, dofs; std::vector constr; - for (std::vector::iterator it = vertexConstraints.begin(); - it != vertexConstraints.end(); - ++it) { + for (const auto& it : vertexConstraints) { Sketcher::Constraint* c = new Sketcher::Constraint(); - c->Type = it->Type; - c->First = it->First; - c->Second = it->Second; - c->FirstPos = it->FirstPos; - c->SecondPos = it->SecondPos; + c->Type = it.Type; + c->First = it.First; + c->Second = it.Second; + c->FirstPos = it.FirstPos; + c->SecondPos = it.SecondPos; if (onebyone) { // addConstraint() creates a clone @@ -492,9 +489,8 @@ void SketchAnalysis::makeMissingPointOnPointCoincident(bool onebyone) vertexConstraints.clear(); - for (std::vector::iterator it = constr.begin(); it != constr.end(); - ++it) { - delete *it; + for (auto it : constr) { + delete it; } } diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index 49e93488d3..d27557d78a 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -9837,6 +9837,16 @@ void SketchObject::makeMissingEquality(bool onebyone) analyser->makeMissingEquality(onebyone); } +int SketchObject::detectDegeneratedGeometries(double tolerance) +{ + return analyser->detectDegeneratedGeometries(tolerance); +} + +int SketchObject::removeDegeneratedGeometries(double tolerance) +{ + return analyser->removeDegeneratedGeometries(tolerance); +} + int SketchObject::autoRemoveRedundants(bool updategeo) { auto redundants = getLastRedundant(); diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 1867d7b04d..2a5ab1b713 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -750,6 +750,11 @@ public: void makeMissingVerticalHorizontal(bool onebyone = false); void makeMissingEquality(bool onebyone = true); + /// Detect degenerated geometries + int detectDegeneratedGeometries(double tolerance); + /// Remove degenerated geometries + int removeDegeneratedGeometries(double tolerance); + // helper /// returns the number of redundant constraints detected int autoRemoveRedundants(bool updategeo = true); diff --git a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp index f98f04176d..7fdfceb51f 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp +++ b/src/Mod/Sketcher/Gui/TaskSketcherValidation.cpp @@ -59,7 +59,6 @@ SketcherValidation::SketcherValidation(Sketcher::SketchObject* Obj, QWidget* par : QWidget(parent) , ui(new Ui_TaskSketcherValidation()) , sketch(Obj) - , sketchAnalyser(Obj) , coincidenceRoot(nullptr) { ui->setupUi(this); @@ -160,12 +159,11 @@ void SketcherValidation::onFindButtonClicked() } } - sketchAnalyser.detectMissingPointOnPointConstraints( - prec, - !ui->checkBoxIgnoreConstruction->isChecked()); + sketch->detectMissingPointOnPointConstraints(prec, + !ui->checkBoxIgnoreConstruction->isChecked()); std::vector& vertexConstraints = - sketchAnalyser.getMissingPointOnPointConstraints(); + sketch->getMissingPointOnPointConstraints(); std::vector points; points.reserve(vertexConstraints.size()); @@ -222,7 +220,7 @@ void SketcherValidation::onHighlightButtonClicked() std::vector points; - points = sketchAnalyser.getOpenVertices(); + points = sketch->getOpenVertices(); hidePoints(); if (!points.empty()) { @@ -475,7 +473,7 @@ void SketcherValidation::onFindDegeneratedClicked() } double prec = Precision::Confusion(); - int count = sketchAnalyser.detectDegeneratedGeometries(prec); + int count = sketch->detectDegeneratedGeometries(prec); if (count == 0) { Gui::TranslatedNotification(*sketch, diff --git a/src/Mod/Sketcher/Gui/TaskSketcherValidation.h b/src/Mod/Sketcher/Gui/TaskSketcherValidation.h index 610b4b7255..c22c889dd0 100644 --- a/src/Mod/Sketcher/Gui/TaskSketcherValidation.h +++ b/src/Mod/Sketcher/Gui/TaskSketcherValidation.h @@ -29,7 +29,6 @@ #include #include #include -#include class SoGroup; @@ -75,7 +74,6 @@ private: private: std::unique_ptr ui; App::WeakPtrT sketch; - Sketcher::SketchAnalysis sketchAnalyser; SoGroup* coincidenceRoot; };