From 05448b980a35152eafe3990740a105b7fa556367 Mon Sep 17 00:00:00 2001 From: Ajinkya Dahale Date: Mon, 25 Nov 2024 23:32:55 +0530 Subject: [PATCH] [Part] Avoid `nullptr` when using `createArc` We could make `GeomCurve::createArc(...) = 0`, but then it needs to be implemented in many subclasses which cannot be incomplete. It is implemented for some of them, but others may need additional work (e.g. offsets), and would need some exception throwing similar to what is now used. --- src/Mod/Part/App/Geometry.cpp | 20 ++++++++++++++++++-- src/Mod/Part/App/Geometry.h | 8 +++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 95d3db67ef..9a47464e2b 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -795,7 +795,7 @@ GeomBSplineCurve* GeomCurve::toNurbs(double first, double last) const GeomCurve* GeomCurve::createArc([[maybe_unused]] double first, [[maybe_unused]] double last) const { - return nullptr; + THROWM(Base::NotImplementedError, "createArc: not implemented for this type of curve"); } bool GeomCurve::tangent(double u, gp_Dir& dir) const @@ -3606,13 +3606,21 @@ void GeomHyperbola::setHandle(const Handle(Geom_Hyperbola)& c) myCurve = Handle(Geom_Hyperbola)::DownCast(c->Copy()); } -Geometry *GeomHyperbola::copy() const +Geometry* GeomHyperbola::copy() const { GeomHyperbola *newHyp = new GeomHyperbola(myCurve); newHyp->copyNonTag(this); return newHyp; } +GeomCurve* GeomHyperbola::createArc(double first, double last) const +{ + auto newArc = new GeomArcOfHyperbola(Handle(Geom_Hyperbola)::DownCast(this->handle()->Copy())); + newArc->setRange(first, last, false); + + return newArc; +} + GeomBSplineCurve* GeomHyperbola::toNurbs(double first, double last) const { return GeomConic::toNurbs(first, last); @@ -4058,6 +4066,14 @@ Geometry *GeomParabola::copy() const return newPar; } +GeomCurve* GeomParabola::createArc(double first, double last) const +{ + auto newArc = new GeomArcOfParabola(Handle(Geom_Parabola)::DownCast(this->handle()->Copy())); + newArc->setRange(first, last, false); + + return newArc; +} + GeomBSplineCurve* GeomParabola::toNurbs(double first, double last) const { // the default implementation suffices because a non-rational B-spline with diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 1d78d24258..4af1809128 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -212,7 +212,7 @@ public: */ virtual GeomBSplineCurve* toNurbs(double first, double last) const; /*! - * \brief getArc Generates a curve that is an arc of this curve between given parameters + * \brief createArc Generates a curve that is an arc of this curve between given parameters * \param first Parameter at start of arc * \param last Parameter at end of arc. This may be < `first` for periodic curves. * \return the new curve @@ -653,7 +653,8 @@ public: GeomHyperbola(); explicit GeomHyperbola(const Handle(Geom_Hyperbola)&); ~GeomHyperbola() override; - Geometry *copy() const override; + Geometry* copy() const override; + GeomCurve* createArc(double first, double last) const override; double getMajorRadius() const; void setMajorRadius(double Radius); @@ -717,7 +718,8 @@ public: GeomParabola(); explicit GeomParabola(const Handle(Geom_Parabola)&); ~GeomParabola() override; - Geometry *copy() const override; + Geometry* copy() const override; + GeomCurve* createArc(double first, double last) const override; double getFocal() const; void setFocal(double length);