diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h index 2aab721fc8..7fd191df0e 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h @@ -29,14 +29,15 @@ #include #include #include -#include #include +#include #include #include #include #include #include #include +#include #include @@ -118,6 +119,7 @@ public: , deleteOriginal(false) , offsetLengthSet(false) , offsetConstraint(false) + , onlySingleLines(true) , offsetLength(1.) {} @@ -203,7 +205,7 @@ private: Base::Vector2d endpoint, pointOnSourceWire; std::vector sourceWires; - bool deleteOriginal, offsetLengthSet, offsetConstraint; + bool deleteOriginal, offsetLengthSet, offsetConstraint, onlySingleLines; double offsetLength; int firstCurveCreated; @@ -213,7 +215,18 @@ private: short joinType = constructionMethod() == DrawSketchHandlerOffset::ConstructionMethod::Arc ? 0 : 2; - Part::BRepOffsetAPI_MakeOffsetFix mkOffset(GeomAbs_JoinType(joinType), allowOpenResult); + // Offset will fail for single lines if we don't set a plane in ctor. + // But if we set a plane, then the direction of offset is forced... + // so we set a plane if and only if there are not a single sourceWires with more than single + // line. + BRepOffsetAPI_MakeOffset mkOffset; + + if (onlySingleLines) { + TopoDS_Face workingPlane = BRepBuilderAPI_MakeFace(gp_Pln(gp::Origin(), gp::DZ())); + mkOffset = BRepOffsetAPI_MakeOffset(workingPlane); + } + mkOffset.Init(GeomAbs_JoinType(joinType), allowOpenResult); + for (TopoDS_Wire& wire : sourceWires) { mkOffset.AddWire(wire); } @@ -905,7 +918,15 @@ private: for (auto& curve : CC) { mkWire.Add(TopoDS::Edge(Obj->getGeometry(curve)->toShape())); } - sourceWires.push_back(mkWire.Wire()); + + // Here we make sure that if possible the first wire is not a single line. + if (CC.size() == 1 && isLineSegment(*Obj->getGeometry(CC[0]))) { + sourceWires.push_back(mkWire.Wire()); + } + else { + sourceWires.insert(sourceWires.begin(), mkWire.Wire()); + onlySingleLines = false; + } } }