From 74803c2a1d0fdc3fbae6dce019b83b515ce4d59d Mon Sep 17 00:00:00 2001 From: jfa Date: Fri, 26 Jun 2020 16:01:37 +0300 Subject: [PATCH] Sketcher Offset: closed offset for closed wire. --- src/GeomAPI/GeomAPI_BSpline.cpp | 24 ++++++++++++++++++------ src/GeomAPI/GeomAPI_BSpline.h | 15 ++++++++------- src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp | 3 ++- src/SketchPlugin/SketchPlugin_Offset.cpp | 16 ++++++++-------- 4 files changed, 36 insertions(+), 22 deletions(-) diff --git a/src/GeomAPI/GeomAPI_BSpline.cpp b/src/GeomAPI/GeomAPI_BSpline.cpp index 6b4c0fe84..b785aa77b 100644 --- a/src/GeomAPI/GeomAPI_BSpline.cpp +++ b/src/GeomAPI/GeomAPI_BSpline.cpp @@ -26,16 +26,11 @@ #define MY_BSPLINE (*(implPtr())) -GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve, - const bool isForced) +GeomAPI_BSpline::GeomAPI_BSpline (const GeomCurvePtr& theCurve) { GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve(); Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl(); Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve); - if (aBSpl.IsNull() && isForced) { - // convert to b-spline - aBSpl = GeomConvert::CurveToBSplineCurve(aCurve); - } if (aBSpl.IsNull()) throw Standard_ConstructionError("GeomAPI_BSpline: Curve is not a B-spline"); setImpl(new Handle_Geom_BSplineCurve(aBSpl)); @@ -83,3 +78,20 @@ bool GeomAPI_BSpline::isPeriodic() const { return MY_BSPLINE->IsPeriodic(); } + +GeomBSplinePtr GeomAPI_BSpline::convertToBSpline (const GeomCurvePtr& theCurve) +{ + GeomCurvePtr anUntrimmedCurve = theCurve->basisCurve(); + Handle(Geom_Curve) aCurve = anUntrimmedCurve->impl(); + Handle(Geom_BSplineCurve) aBSpl = Handle(Geom_BSplineCurve)::DownCast(aCurve); + if (aBSpl.IsNull()) { + // convert to b-spline + aBSpl = GeomConvert::CurveToBSplineCurve(aCurve); + } + if (aBSpl.IsNull()) + throw Standard_ConstructionError("GeomAPI_BSpline: Conversion to B-spline failed"); + GeomCurvePtr aResCurve (new GeomAPI_Curve()); + aResCurve->setImpl(new Handle_Geom_BSplineCurve(aBSpl)); + GeomBSplinePtr aResult (new GeomAPI_BSpline(aResCurve)); + return aResult; +} diff --git a/src/GeomAPI/GeomAPI_BSpline.h b/src/GeomAPI/GeomAPI_BSpline.h index 275b94dda..251122dd8 100644 --- a/src/GeomAPI/GeomAPI_BSpline.h +++ b/src/GeomAPI/GeomAPI_BSpline.h @@ -27,6 +27,10 @@ #include class GeomAPI_Pnt; +class GeomAPI_BSpline; + +//! Pointer on the object +typedef std::shared_ptr GeomBSplinePtr; /**\class GeomAPI_BSpline * \ingroup DataModel @@ -36,10 +40,7 @@ class GeomAPI_BSpline : public GeomAPI_Interface { public: /// Creation of B-spline defined by a curve - /// \param isForced if true and theCurve is not a b-spline - /// curve, theCurve is converted to b-spline - GEOMAPI_EXPORT GeomAPI_BSpline (const GeomCurvePtr& theCurve, - const bool isForced = false); + GEOMAPI_EXPORT GeomAPI_BSpline (const GeomCurvePtr& theCurve); /// Degree of B-spline curve GEOMAPI_EXPORT int degree() const; @@ -58,9 +59,9 @@ public: /// Return \c true if the curve is periodic GEOMAPI_EXPORT bool isPeriodic() const; -}; -//! Pointer on the object -typedef std::shared_ptr GeomBSplinePtr; + /// Convert any curve into a B-spline curve + GEOMAPI_EXPORT static GeomBSplinePtr convertToBSpline (const GeomCurvePtr& theCurve); +}; #endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp index 4b0bb4031..437a2a97c 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp @@ -92,7 +92,8 @@ GeomAlgoAPI_Offset::GeomAlgoAPI_Offset(const GeomPlanePtr& thePlane, setImpl(aParal); setBuilderType(OCCT_BRepBuilderAPI_MakeShape); - aParal->Init(aFace, GeomAbs_Arc, Standard_True); + Standard_Boolean isOpenResult = !aWire.Closed(); + aParal->Init(aFace, GeomAbs_Arc, isOpenResult); aParal->Perform(theOffsetValue, 0.); if (aParal->IsDone()) { TopoDS_Shape anOffset = aParal->Shape(); diff --git a/src/SketchPlugin/SketchPlugin_Offset.cpp b/src/SketchPlugin/SketchPlugin_Offset.cpp index cc5234943..97798f7a1 100644 --- a/src/SketchPlugin/SketchPlugin_Offset.cpp +++ b/src/SketchPlugin/SketchPlugin_Offset.cpp @@ -579,17 +579,17 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult, { GeomCurvePtr aCurve (new GeomAPI_Curve (theEdge)); // Forced conversion to b-spline, if aCurve is not b-spline - GeomAPI_BSpline aBSpline (aCurve, /*isForced*/true); + GeomBSplinePtr aBSpline = GeomAPI_BSpline::convertToBSpline(aCurve); - const std::string& aBSplineKind = aBSpline.isPeriodic() ? SketchPlugin_BSplinePeriodic::ID() - : SketchPlugin_BSpline::ID(); + const std::string& aBSplineKind = aBSpline->isPeriodic() ? SketchPlugin_BSplinePeriodic::ID() + : SketchPlugin_BSpline::ID(); findOrCreateFeatureByKind(sketch(), aBSplineKind, theResult, thePoolOfFeatures); - theResult->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline.degree()); + theResult->integer(SketchPlugin_BSpline::DEGREE_ID())->setValue(aBSpline->degree()); AttributePoint2DArrayPtr aPolesAttr = std::dynamic_pointer_cast (theResult->attribute(SketchPlugin_BSpline::POLES_ID())); - std::list aPoles = aBSpline.poles(); + std::list aPoles = aBSpline->poles(); aPolesAttr->setSize((int)aPoles.size()); std::list::iterator anIt = aPoles.begin(); for (int anIndex = 0; anIt != aPoles.end(); ++anIt, ++anIndex) { @@ -599,7 +599,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult, AttributeDoubleArrayPtr aWeightsAttr = theResult->data()->realArray(SketchPlugin_BSpline::WEIGHTS_ID()); - std::list aWeights = aBSpline.weights(); + std::list aWeights = aBSpline->weights(); if (aWeights.empty()) { // rational B-spline int aSize = (int)aPoles.size(); aWeightsAttr->setSize(aSize); @@ -615,7 +615,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult, AttributeDoubleArrayPtr aKnotsAttr = theResult->data()->realArray(SketchPlugin_BSpline::KNOTS_ID()); - std::list aKnots = aBSpline.knots(); + std::list aKnots = aBSpline->knots(); int aSize = (int)aKnots.size(); aKnotsAttr->setSize(aSize); std::list::iterator aKIt = aKnots.begin(); @@ -624,7 +624,7 @@ void SketchPlugin_Offset::mkBSpline (FeaturePtr& theResult, AttributeIntArrayPtr aMultsAttr = theResult->data()->intArray(SketchPlugin_BSpline::MULTS_ID()); - std::list aMultiplicities = aBSpline.mults(); + std::list aMultiplicities = aBSpline->mults(); aSize = (int)aMultiplicities.size(); aMultsAttr->setSize(aSize); std::list::iterator aMIt = aMultiplicities.begin(); -- 2.39.2