From fb1ed8f5e4256f53726975ab335ba98e76de4ba6 Mon Sep 17 00:00:00 2001 From: Roy-043 <70520633+Roy-043@users.noreply.github.com> Date: Thu, 12 Jan 2023 10:25:11 +0100 Subject: [PATCH] Draft: improve offsets.offsetWire (#8166) --- src/Mod/Draft/draftgeoutils/offsets.py | 31 ++++++++++++++------------ 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Mod/Draft/draftgeoutils/offsets.py b/src/Mod/Draft/draftgeoutils/offsets.py index dda8daac2c..359fb8c7e4 100644 --- a/src/Mod/Draft/draftgeoutils/offsets.py +++ b/src/Mod/Draft/draftgeoutils/offsets.py @@ -174,9 +174,8 @@ def offsetWire(wire, dvec, bind=False, occ=False, Parameters ---------- - wire as a list of edges (use the list directly), - or previously as a wire or a face (Draft Wire with MakeFace True - or False supported). + wire as a sorted list of edges (the list is used directly), or as a + wire or a face (Draft Wire with MakeFace True or False supported). The vector will be applied at the first vertex of the wire. If bind is True (and the shape is open), the original wire and the offsetted one @@ -207,19 +206,24 @@ def offsetWire(wire, dvec, bind=False, occ=False, in this function if widthList and alignList are provided - 'dvec' to be obsolete in future? """ - if isinstance(wire, Part.Wire) or isinstance(wire, Part.Face): - # Found Draft GuiOffset directly offset Sketch.Shape(wire) would fails - # thus need to sort its edges same order + if isinstance(wire, list) and isinstance(wire[0], Part.Edge): + edges = wire.copy() + wire = Part.Wire(edges) + closed = wire.isClosed() + elif isinstance(wire, Part.Wire): + # Draft_Offset can fail when directly offsetting a Sketch wire. We need + # to sort the edges. And because Part.__sortEdges__() can remove edges, + # we need to create a new wire as well. edges = Part.__sortEdges__(wire.Edges) - #edges = wire.Edges + wire = Part.Wire(edges) + closed = wire.isClosed() + elif isinstance(wire, Part.Face): + # We also need to sort the edges of a face. + edges = Part.__sortEdges__(wire.OuterWire.Edges) + closed = True elif isinstance(wire, Part.Edge): edges = [wire] - elif isinstance(wire, list): - if isinstance(wire[0], Part.Edge): - edges = wire.copy() - # How to avoid __sortEdges__ again? - # Make getNormal directly tackle edges? - wire = Part.Wire(Part.__sortEdges__(edges)) + closed = wire.isClosed() else: print("Either Part.Wire or Part.Edges should be provided, " "returning None") @@ -238,7 +242,6 @@ def offsetWire(wire, dvec, bind=False, occ=False, if norm is None: norm = App.Vector(0, 0, 1) - closed = isReallyClosed(wire) nedges = [] if occ: length = abs(dvec.Length)