Salome HOME
updated copyright message
[modules/shaper.git] / src / GeomAlgoAPI / GeomAlgoAPI_Offset.cpp
index b86bb42bca48b431d64b72f36eb2faba3078a3ed..bcd5ec60d78e9ff8df924202ed8bad82a82dc953 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2019-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -19,6 +19,8 @@
 
 #include "GeomAlgoAPI_Offset.h"
 
+#include <GeomAPI_Pln.h>
+
 #include <BRepOffsetAPI_MakeOffsetShape.hxx>
 #include <BRepOffsetAPI_MakeOffset.hxx>
 
@@ -60,18 +62,11 @@ void GeomAlgoAPI_Offset::generated(const GeomShapePtr theOldShape,
   }
 }
 
-//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)
+GeomAlgoAPI_Offset::GeomAlgoAPI_Offset(const GeomPlanePtr& thePlane,
+                                       const GeomShapePtr& theEdgeOrWire,
+                                       const double theOffsetValue,
+                                       const GeomAlgoAPI_OffsetJoint theJoint)
 {
-  GeomShapePtr aResult;
-
   // 1. Make wire from edge, if need
   TopoDS_Wire aWire;
   TopoDS_Shape anEdgeOrWire = theEdgeOrWire->impl<TopoDS_Shape>();
@@ -87,21 +82,31 @@ GeomShapePtr GeomAlgoAPI_Offset::OffsetInPlane (const std::shared_ptr<GeomAPI_Pl
     }
   }
   if (aWire.IsNull())
-    return aResult;
+    return;
 
   // 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());
+  BRepOffsetAPI_MakeOffset* aParal = new BRepOffsetAPI_MakeOffset;
+  setImpl(aParal);
+  setBuilderType(OCCT_BRepBuilderAPI_MakeShape);
+
+  // Joint type
+  GeomAbs_JoinType aJoin = GeomAbs_Arc; // default mode, corresponding to KeepDistance
+  if (theJoint == GeomAlgoAPI_OffsetJoint::Lines)
+    aJoin = GeomAbs_Intersection;
+  // for GeomAlgoAPI_OffsetJoint::Arcs do the same as for KeepDistance
+
+  Standard_Boolean isOpenResult = !aWire.Closed();
+  aParal->Init(aFace, aJoin, isOpenResult);
+  aParal->Perform(theOffsetValue, 0.);
+  if (aParal->IsDone()) {
+    TopoDS_Shape anOffset = aParal->Shape();
+    GeomShapePtr aResult(new GeomAPI_Shape());
     aResult->setImpl(new TopoDS_Shape(anOffset));
+    setShape(aResult);
+    setDone(true);
   }
-
-  return aResult;
 }