From 3fc6b1e8cf1d2087457b5d41ebcb8d43b8d8c040 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Mon, 6 Jan 2014 17:52:05 +0100 Subject: [PATCH] If no tool offset is defined for the current extruder, just assume 0 instead of dying Hopefully this fixes #339 --- src/octoprint/util/gcodeInterpreter.py | 31 ++++++++++---------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index bbab8bc2..bf5ddb9e 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -1,5 +1,9 @@ from __future__ import absolute_import -__copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License" +# coding=utf-8 +__author__ = "Gina Häußge based on work by David Braam" +__license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agpl.html' +__copyright__ = "Copyright (C) 2013 David Braam, Gina Häußge - Released under terms of the AGPLv3 License" + import math import os @@ -9,24 +13,11 @@ import logging from octoprint.settings import settings -preferences = { - "extruder_offset_x1": 0.0, - "extruder_offset_y1": -21.6, - "extruder_offset_x2": 0.0, - "extruder_offset_y2": 0.0, - "extruder_offset_x3": 0.0, - "extruder_offset_y3": 0.0, -} - -def getPreference(key, default=None): - if preferences.has_key(key): - return preferences[key] - else: - return default class AnalysisAborted(Exception): pass + class gcode(object): def __init__(self): self._logger = logging.getLogger(__name__) @@ -94,13 +85,13 @@ class gcode(object): T = getCodeInt(line, 'T') if T is not None: - posOffset[0] -= offsets[currentExtruder]["x"] - posOffset[1] -= offsets[currentExtruder]["y"] + posOffset[0] -= offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 + posOffset[1] -= offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 currentExtruder = T - posOffset[0] += offsets[currentExtruder]["x"] - posOffset[1] += offsets[currentExtruder]["y"] + posOffset[0] += offsets[currentExtruder]["x"] if currentExtruder < len(offsets) else 0 + posOffset[1] += offsets[currentExtruder]["y"] if currentExtruder < len(offsets) else 0 if len(currentE) <= currentExtruder: for i in range(len(currentE), currentExtruder + 1): @@ -233,6 +224,7 @@ class gcode(object): def _parseCuraProfileString(self, comment): return {key: value for (key, value) in map(lambda x: x.split("=", 1), zlib.decompress(base64.b64decode(comment[len("CURA_PROFILE_STRING:"):])).split("\b"))} + def getCodeInt(line, code): n = line.find(code) + 1 if n < 1: @@ -245,6 +237,7 @@ def getCodeInt(line, code): except: return None + def getCodeFloat(line, code): n = line.find(code) + 1 if n < 1: