From ab4abab53d6cc81ffe834d7a34620f8fae4f3c6e Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Sep 2023 20:38:08 +0200 Subject: [PATCH] Sketch: fix a few minor issues: * fix compiler warning about unused variable * fix const correctness * fix access type of setExpression() * removed duplicated method --- src/Mod/Sketcher/App/SketchObject.cpp | 22 +++++---------------- src/Mod/Sketcher/App/SketchObject.h | 13 +++++------- src/Mod/Sketcher/Gui/CommandConstraints.cpp | 2 ++ 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/src/Mod/Sketcher/App/SketchObject.cpp b/src/Mod/Sketcher/App/SketchObject.cpp index bb9d831ad3..7984b24ee8 100644 --- a/src/Mod/Sketcher/App/SketchObject.cpp +++ b/src/Mod/Sketcher/App/SketchObject.cpp @@ -682,7 +682,7 @@ void SketchObject::reverseAngleConstraintToSupplementary(Constraint* constr, int } } -bool SketchObject::constraintHasExpression(int constNum) +bool SketchObject::constraintHasExpression(int constNum) const { App::ObjectIdentifier path = Constraints.createPath(constNum); auto info = getExpression(path); @@ -692,7 +692,7 @@ bool SketchObject::constraintHasExpression(int constNum) return false; } -std::string SketchObject::getConstraintExpression(int constNum) +std::string SketchObject::getConstraintExpression(int constNum) const { App::ObjectIdentifier path = Constraints.createPath(constNum); auto info = getExpression(path); @@ -701,19 +701,17 @@ std::string SketchObject::getConstraintExpression(int constNum) return expression; } - return ""; + return {}; } -void SketchObject::setConstraintExpression(int constNum, std::string& newExpression) +void SketchObject::setConstraintExpression(int constNum, const std::string& newExpression) { App::ObjectIdentifier path = Constraints.createPath(constNum); auto info = getExpression(path); if (info.expression) { try { std::shared_ptr expr(App::Expression::parse(this, newExpression)); - // there is a bug in the SketchObject API because setExpression() is protected but public in DocumentObject - App::DocumentObject* base = this; - base->setExpression(path, expr); + setExpression(path, expr); } catch (const Base::Exception&) { Base::Console().Error("Failed to set constraint expression."); @@ -9160,16 +9158,6 @@ int SketchObject::changeConstraintsLocking(bool bLock) return cntSuccess; } -bool SketchObject::constraintHasExpression(int constrid) const -{ - App::ObjectIdentifier spath = this->Constraints.createPath(constrid); - - App::PropertyExpressionEngine::ExpressionInfo expr_info = this->getExpression(spath); - - return (expr_info.expression != nullptr); -} - - /*! * \brief SketchObject::port_reversedExternalArcs finds constraints that link to endpoints of * external-geometry arcs, and swaps the endpoints in the constraints. This is needed after CCW diff --git a/src/Mod/Sketcher/App/SketchObject.h b/src/Mod/Sketcher/App/SketchObject.h index 66277754e1..aeadd97fc9 100644 --- a/src/Mod/Sketcher/App/SketchObject.h +++ b/src/Mod/Sketcher/App/SketchObject.h @@ -273,11 +273,13 @@ public: void reverseAngleConstraintToSupplementary(Constraint* constr, int constNum); // Check if a constraint has an expression associated. - bool constraintHasExpression(int constNum); + bool constraintHasExpression(int constNum) const; // Get a constraint associated expression - std::string getConstraintExpression(int constNum); + std::string getConstraintExpression(int constNum) const; // Set a constraint associated expression - void setConstraintExpression(int constNum, std::string& newExpression); + void setConstraintExpression(int constNum, const std::string& newExpression); + void setExpression(const App::ObjectIdentifier& path, + std::shared_ptr expr) override; /// set the driving status of this constraint and solve int setVirtualSpace(int ConstrId, bool isinvirtualspace); @@ -471,8 +473,6 @@ public: bool isPointOnCurve(int geoIdCurve, double px, double py); double calculateConstraintError(int ConstrId); int changeConstraintsLocking(bool bLock); - /// returns whether a given constraint has an associated expression or not - bool constraintHasExpression(int constrid) const; /// porting functions int port_reversedExternalArcs(bool justAnalyze); @@ -735,9 +735,6 @@ protected: void buildShape(); - void setExpression(const App::ObjectIdentifier& path, - std::shared_ptr expr) override; - std::string validateExpression(const App::ObjectIdentifier& path, std::shared_ptr expr); diff --git a/src/Mod/Sketcher/Gui/CommandConstraints.cpp b/src/Mod/Sketcher/Gui/CommandConstraints.cpp index 347a689f33..658e29a5a6 100644 --- a/src/Mod/Sketcher/Gui/CommandConstraints.cpp +++ b/src/Mod/Sketcher/Gui/CommandConstraints.cpp @@ -1795,6 +1795,8 @@ protected: void makeCts_1Circle(bool& selAllowed, Base::Vector2d onSketchPos) { const Part::Geometry* geom = Obj->getGeometry(selCircleArc[0].GeoId); + Q_UNUSED(geom) + if (availableConstraint == AvailableConstraint::FIRST || availableConstraint == AvailableConstraint::SECOND) { //Radius/diameter. Mode changes in createRadiusDiameterConstrain.