From: jfa Date: Thu, 18 Jun 2020 12:22:46 +0000 (+0300) Subject: Offset feature (partially working version) X-Git-Tag: V9_6_0a1~60^2~61 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=aa971ac5b18eebecbabb49735a94090aa51de115;p=modules%2Fshaper.git Offset feature (partially working version) --- 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);