From aa971ac5b18eebecbabb49735a94090aa51de115 Mon Sep 17 00:00:00 2001 From: jfa Date: Thu, 18 Jun 2020 15:22:46 +0300 Subject: [PATCH] Offset feature (partially working version) --- src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp | 52 ++++++++++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_Offset.h | 13 +++++++ 2 files changed, 65 insertions(+) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp index 7008b63fe..b86bb42bc 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp @@ -20,7 +20,13 @@ #include "GeomAlgoAPI_Offset.h" #include +#include +#include +#include + +#include +#include GeomAlgoAPI_Offset::GeomAlgoAPI_Offset(const GeomShapePtr& theShape, const double theOffsetValue) @@ -53,3 +59,49 @@ void GeomAlgoAPI_Offset::generated(const GeomShapePtr theOldShape, // nothing is generated } } + +//GeomShapePtr GeomAlgoAPI_Offset::OffsetInPlane (const std::shared_ptr& thePlane, +// const ListOfShape& theEdgesAndWires, +// const double theOffsetValue) +//{ +//} + +GeomShapePtr GeomAlgoAPI_Offset::OffsetInPlane (const std::shared_ptr& thePlane, + const GeomShapePtr& theEdgeOrWire, + const double theOffsetValue) +{ + GeomShapePtr aResult; + + // 1. Make wire from edge, if need + TopoDS_Wire aWire; + TopoDS_Shape anEdgeOrWire = theEdgeOrWire->impl(); + if (anEdgeOrWire.ShapeType() == TopAbs_WIRE) { + aWire = TopoDS::Wire(anEdgeOrWire); + } else { + if (anEdgeOrWire.ShapeType() == TopAbs_EDGE) { + BRepBuilderAPI_MakeWire aWireBuilder; + aWireBuilder.Add(TopoDS::Edge(anEdgeOrWire)); + if (aWireBuilder.IsDone()) { + aWire = aWireBuilder.Wire(); + } + } + } + if (aWire.IsNull()) + return aResult; + + // 2. Make invalid face to pass it in Offset algorithm + BRepBuilderAPI_MakeFace aFaceBuilder (thePlane->impl(), aWire); + const TopoDS_Face& aFace = aFaceBuilder.Face(); + + // 3. Make Offset + BRepOffsetAPI_MakeOffset aParal; + aParal.Init(aFace, GeomAbs_Arc, Standard_True); + aParal.Perform(theOffsetValue, 0.); + if (aParal.IsDone()) { + TopoDS_Shape anOffset = aParal.Shape(); + aResult.reset(new GeomAPI_Shape()); + aResult->setImpl(new TopoDS_Shape(anOffset)); + } + + return aResult; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.h b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.h index 7939f04cd..ee6d51062 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Offset.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Offset.h @@ -23,6 +23,8 @@ #include #include +#include + /// \class GeomAlgoAPI_Offset /// \ingroup DataAlgo /// \brief Perform 3D offset for the shape @@ -39,6 +41,17 @@ public: GEOMALGOAPI_EXPORT virtual void generated(const GeomShapePtr theOldShape, ListOfShape& theNewShapes); + /// \return a compound of offset wires + /// \param[in] thePlane base plane for all offsets + /// \param[in] theEdgesAndWires base shapes + /// \param[in] theOffsetValue offset distance, it can be negative + //GEOMALGOAPI_EXPORT static GeomShapePtr OffsetInPlane (const std::shared_ptr& thePlane, + // const ListOfShape& theEdgesAndWires, + // const double theOffsetValue); + GEOMALGOAPI_EXPORT static GeomShapePtr OffsetInPlane (const std::shared_ptr& thePlane, + const GeomShapePtr& theEdgeOrWire, + const double theOffsetValue); + private: /// \brief Perform offset operation void build(const GeomShapePtr& theShape, const double theOffsetValue); -- 2.39.2