From 6e474d9096dd6e7cae79eb9ee917f548f430c5da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Tue, 10 Jan 2017 12:16:33 +0100 Subject: [PATCH] Fix model size calculation during GCODE analysis * Properly handle G0/G1 with no X, Y, Z coordinates in relative mode instead of duplicating coordinates - should fix #1675 * Only take move commands with X, Y, Z coordinates into account for model size calculation - this makes our internal GCODE analysis behave like the GCODE viewer's analysis and produce the same model size. The downside is that extrusions on the origin are no longer taken into account for checking if a model is within bounds of the print bed, but that should hopefully not produce any issues in the real world. --- src/octoprint/util/gcodeInterpreter.py | 28 +++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index d06766b8..0cc0aab2 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -294,15 +294,28 @@ class gcode(object): e = getCodeFloat(line, 'E') f = getCodeFloat(line, 'F') + if x is not None or y is not None or z is not None: + # this is a move + move = True + else: + # print head stays on position + move = False + oldPos = pos - newPos = Vector3D(x if x is not None else pos.x, - y if y is not None else pos.y, - z if z is not None else pos.z) + + # Use new coordinates if provided. If not provided, use prior coordinates in absolute + # and 0.0 in relative mode. + newPos = Vector3D(x if x is not None else (pos.x if posAbs else 0.0), + y if y is not None else (pos.y if posAbs else 0.0), + z if z is not None else (pos.z if posAbs else 0.0)) if posAbs: + # Absolute mode: scale coordinates and apply offsets pos = newPos * scale + posOffset else: + # Relative mode: scale and add to current position pos += newPos * scale + if f is not None and f != 0: feedrate = f @@ -310,10 +323,12 @@ class gcode(object): if absoluteE: # make sure e is relative e -= currentE[currentExtruder] - # If move includes extrusion, calculate new min/max coordinates of model - if e > 0.0: - # extrusion -> relevant for print area & dimensions + + # If move with extrusion, calculate new min/max coordinates of model + if e > 0.0 and move: + # extrusion and move -> relevant for print area & dimensions self._minMax.record(pos) + totalExtrusion[currentExtruder] += e currentE[currentExtruder] += e maxExtrusion[currentExtruder] = max(maxExtrusion[currentExtruder], @@ -417,7 +432,6 @@ class gcode(object): if throttle is not None: throttle() - if self.progressCallback is not None: self.progressCallback(100.0)