]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Offset feature (partially working version)
authorjfa <jfa@opencascade.com>
Thu, 18 Jun 2020 12:22:46 +0000 (15:22 +0300)
committerjfa <jfa@opencascade.com>
Thu, 18 Jun 2020 12:22:46 +0000 (15:22 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_Offset.cpp
src/GeomAlgoAPI/GeomAlgoAPI_Offset.h

index 7008b63fee30e4e0ba88639c986f259c8aa1289d..b86bb42bca48b431d64b72f36eb2faba3078a3ed 100644 (file)
 #include "GeomAlgoAPI_Offset.h"
 
 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
+#include <BRepOffsetAPI_MakeOffset.hxx>
 
+#include <BRepBuilderAPI_MakeWire.hxx>
+#include <BRepBuilderAPI_MakeFace.hxx>
+
+#include <TopoDS.hxx>
+#include <TopoDS_Wire.hxx>
 
 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<GeomAPI_Pln>& thePlane,
+//                                                const ListOfShape& theEdgesAndWires,
+//                                                const double theOffsetValue)
+//{
+//}
+
+GeomShapePtr GeomAlgoAPI_Offset::OffsetInPlane (const std::shared_ptr<GeomAPI_Pln>& thePlane,
+                                                const GeomShapePtr& theEdgeOrWire,
+                                                const double theOffsetValue)
+{
+  GeomShapePtr aResult;
+
+  // 1. Make wire from edge, if need
+  TopoDS_Wire aWire;
+  TopoDS_Shape anEdgeOrWire = theEdgeOrWire->impl<TopoDS_Shape>();
+  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<gp_Pln>(), 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;
+}
index 7939f04cdb76e478fa07581183f15831848de6f2..ee6d51062be446bc0171c595677ff6018dfd6fa2 100644 (file)
@@ -23,6 +23,8 @@
 #include <GeomAlgoAPI.h>
 #include <GeomAlgoAPI_MakeShape.h>
 
+#include <GeomAPI_Pln.h>
+
 /// \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<GeomAPI_Pln>& thePlane,
+  //                                                      const ListOfShape& theEdgesAndWires,
+  //                                                      const double theOffsetValue);
+  GEOMALGOAPI_EXPORT static GeomShapePtr OffsetInPlane (const std::shared_ptr<GeomAPI_Pln>& thePlane,
+                                                        const GeomShapePtr& theEdgeOrWire,
+                                                        const double theOffsetValue);
+
 private:
   /// \brief Perform offset operation
   void build(const GeomShapePtr& theShape, const double theOffsetValue);