From 5066dfdf0d84221f5346120711c31478cdbe8896 Mon Sep 17 00:00:00 2001 From: PaddleStroke Date: Fri, 5 Dec 2025 06:06:01 +0100 Subject: [PATCH] Sketcher: Offset: Fix failure if 2+ closed wires with different orientations (#25941) --- .../Sketcher/Gui/DrawSketchHandlerOffset.h | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h index 28a036b981..546903c1d4 100644 --- a/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h +++ b/src/Mod/Sketcher/Gui/DrawSketchHandlerOffset.h @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -965,12 +966,29 @@ private: mkWire.Add(TopoDS::Edge(geo->toShape())); } + TopoDS_Wire wire = mkWire.Wire(); + + // Fix orientation: ensure all closed wires are CCW relative to Sketch Plane (+Z) + if (wire.Closed()) { + BRepBuilderAPI_MakeFace mkFace(wire); + if (mkFace.IsDone()) { + TopoDS_Face face = mkFace.Face(); + BRepAdaptor_Surface surf(face); + if (surf.GetType() == GeomAbs_Plane) { + gp_Dir norm = surf.Plane().Axis().Direction(); + if (norm.Z() < 0) { + wire.Reverse(); + } + } + } + } + // 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()); + sourceWires.push_back(wire); } else { - sourceWires.insert(sourceWires.begin(), mkWire.Wire()); + sourceWires.insert(sourceWires.begin(), wire); onlySingleLines = false; } }