From a56357e0ff3323a5264bfe440f1ec120f2b26ae3 Mon Sep 17 00:00:00 2001 From: tarman3 Date: Tue, 3 Jun 2025 08:51:09 +0300 Subject: [PATCH] CAM: Engrave - Fix step down for closed profile --- src/Mod/CAM/Path/Op/EngraveBase.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/Mod/CAM/Path/Op/EngraveBase.py b/src/Mod/CAM/Path/Op/EngraveBase.py index 1c4248695a..add09f6eca 100644 --- a/src/Mod/CAM/Path/Op/EngraveBase.py +++ b/src/Mod/CAM/Path/Op/EngraveBase.py @@ -24,7 +24,9 @@ from lazy_loader.lazy_loader import LazyLoader import Path import Path.Op.Base as PathOp import Path.Op.Util as PathOpUtil -import copy +import PathScripts.PathUtils as PathUtils + +# import copy __doc__ = "Base class for all ops in the engrave family." @@ -61,6 +63,15 @@ class ObjectOp(PathOp.ObjectOp): """buildpathocc(obj, wires, zValues, relZ=False) ... internal helper function to generate engraving commands.""" Path.Log.track(obj.Label, len(wires), zValues) + # sort wires, adapted from Area.py + if len(wires) > 1: + locations = [] + for w in wires: + locations.append({"x": w.BoundBox.Center.x, "y": w.BoundBox.Center.y, "wire": w}) + + locations = PathUtils.sort_locations(locations, ["x", "y"]) + wires = [j["wire"] for j in locations] + decomposewires = [] for wire in wires: decomposewires.extend(PathOpUtil.makeWires(wire.Edges)) @@ -83,7 +94,8 @@ class ObjectOp(PathOp.ObjectOp): for z in zValues: Path.Log.debug(z) - if last: + if last and wire.isClosed(): + # Add step down to next Z for closed profile self.appendCommand( Path.Command("G1", {"X": last.x, "Y": last.y, "Z": last.z}), z, @@ -108,7 +120,7 @@ class ObjectOp(PathOp.ObjectOp): ) if first and (not last or not wire.isClosed()): Path.Log.debug("processing first edge entry") - # we set the first move to our first point + # Add moves to first point of wire last = edge.Vertexes[0].Point self.commandlist.append( @@ -133,13 +145,18 @@ class ObjectOp(PathOp.ObjectOp): if Path.Geom.pointsCoincide(last, edge.valueAt(edge.FirstParameter)): # if Path.Geom.pointsCoincide(last, edge.Vertexes[0].Point): + # Edge not reversed for cmd in Path.Geom.cmdsForEdge(edge): + # Add gcode for edge self.appendCommand(cmd, z, relZ, self.horizFeed) last = edge.Vertexes[-1].Point else: + # Edge reversed for cmd in Path.Geom.cmdsForEdge(edge, True): + # Add gcode for reversed edge self.appendCommand(cmd, z, relZ, self.horizFeed) last = edge.Vertexes[0].Point + self.commandlist.append( Path.Command("G0", {"Z": obj.ClearanceHeight.Value, "F": self.vertRapid}) )