diff --git a/src/octoprint/cli/analysis.py b/src/octoprint/cli/analysis.py index 98155753a..bf40b53b4 100644 --- a/src/octoprint/cli/analysis.py +++ b/src/octoprint/cli/analysis.py @@ -69,6 +69,7 @@ def util(): @click.option("--offset", "offset", type=(float, float), multiple=True) @click.option("--max-t", "maxt", type=int, default=10) @click.option("--g90-extruder", "g90_extruder", is_flag=True) +@click.option("--bed-z", "bedz", type=float, default=0) @click.option("--progress", "progress", is_flag=True) @click.argument("path", type=click.Path()) def gcode_command( @@ -81,6 +82,7 @@ def gcode_command( throttle, throttle_lines, g90_extruder, + bedz, progress, ): """Runs a GCODE file analysis.""" @@ -127,6 +129,7 @@ def gcode_command( throttle=throttle_callback, max_extruders=maxt, g90_extruder=g90_extruder, + bed_z=bedz, ) click.echo("DONE:{}s".format(monotonic_time() - start_time)) diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index 5b62230ca..e0923e7c5 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -419,6 +419,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): throttle_lines = settings().getInt(["gcodeAnalysis", "throttle_lines"]) max_extruders = settings().getInt(["gcodeAnalysis", "maxExtruders"]) g90_extruder = settings().getBoolean(["feature", "g90InfluencesExtruder"]) + bed_z = settings().getFloat(["gcodeAnalysis", "bedZ"]) speedx = self._current.printer_profile["axes"]["x"]["speed"] speedy = self._current.printer_profile["axes"]["y"]["speed"] offsets = self._current.printer_profile["extruder"]["offsets"] @@ -434,6 +435,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): "--max-t={}".format(max_extruders), "--throttle={}".format(throttle), "--throttle-lines={}".format(throttle_lines), + "--bed-z={}".format(bed_z), ] for offset in offsets[1:]: command += ["--offset", str(offset[0]), str(offset[1])] diff --git a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js index 5f194574a..9986b0b8a 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/gcodeviewer.js @@ -365,7 +365,8 @@ $(function () { onLayerSelected: self._onLayerSelected, bed: self._retrieveBedDimensions(), toolOffsets: self._retrieveToolOffsets(), - invertAxes: self._retrieveAxesConfiguration() + invertAxes: self._retrieveAxesConfiguration(), + bedZ: self.settings.settings.gcodeAnalysis.bedZ() }); if (!initResult) { diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js index 48dd4e49c..507976f8a 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/reader.js @@ -39,7 +39,8 @@ GCODE.gCodeReader = (function () { centeredOrigin: undefined }, ignoreOutsideBed: false, - g90InfluencesExtruder: false + g90InfluencesExtruder: false, + bedZ: 0 }; var percentageTree = undefined; @@ -166,7 +167,8 @@ GCODE.gCodeReader = (function () { toolOffsets: gCodeOptions["toolOffsets"], bed: gCodeOptions["bed"], ignoreOutsideBed: gCodeOptions["ignoreOutsideBed"], - g90InfluencesExtruder: gCodeOptions["g90InfluencesExtruder"] + g90InfluencesExtruder: gCodeOptions["g90InfluencesExtruder"], + bedZ: gCodeOptions["bedZ"] } } }); @@ -174,11 +176,11 @@ GCODE.gCodeReader = (function () { setOption: function (options) { var dirty = false; - for (var opt in options) { - if (options[opt] === undefined) continue; - dirty = dirty || gCodeOptions[opt] != options[opt]; - gCodeOptions[opt] = options[opt]; - } + _.forOwn(options, function (value, key) { + if (value === undefined) return; + dirty = dirty || gCodeOptions[key] !== value; + gCodeOptions[key] = value; + }); if (dirty) { if (model && model.length > 0) this.passDataToRenderer(); } diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js index e8c3863ee..50e1410b5 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/ui.js @@ -156,7 +156,8 @@ GCODE.ui = (function () { }); GCODE.gCodeReader.setOption({ toolOffsets: options.toolOffsets, - bed: options.bed + bed: options.bed, + bedZ: options.bedZ }); GCODE.renderer.render(0, 0); diff --git a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js index 350102285..b75b7f15e 100644 --- a/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js +++ b/src/octoprint/plugins/gcodeviewer/static/js/viewer/worker.js @@ -715,6 +715,7 @@ var parseGCode = function (message) { bed = message.options.bed; ignoreOutsideBed = message.options.ignoreOutsideBed; g90InfluencesExtruder = message.options.g90InfluencesExtruder; + boundingBox.minZ = min.z = message.options.bedZ; doParse(); gcode = []; diff --git a/src/octoprint/server/api/settings.py b/src/octoprint/server/api/settings.py index 7c80590a2..11ebe6c6f 100644 --- a/src/octoprint/server/api/settings.py +++ b/src/octoprint/server/api/settings.py @@ -153,7 +153,10 @@ def getSettings(): "g90InfluencesExtruder": s.getBoolean(["feature", "g90InfluencesExtruder"]), "autoUppercaseBlacklist": s.get(["feature", "autoUppercaseBlacklist"]), }, - "gcodeAnalysis": {"runAt": s.get(["gcodeAnalysis", "runAt"])}, + "gcodeAnalysis": { + "runAt": s.get(["gcodeAnalysis", "runAt"]), + "bedZ": s.getFloat(["gcodeAnalysis", "bedZ"]), + }, "serial": { "port": connectionOptions["portPreference"], "baudrate": connectionOptions["baudratePreference"], @@ -614,6 +617,8 @@ def _saveSettings(data): if "gcodeAnalysis" in data: if "runAt" in data["gcodeAnalysis"]: s.set(["gcodeAnalysis", "runAt"], data["gcodeAnalysis"]["runAt"]) + if "bedZ" in data["gcodeAnalysis"]: + s.setBoolean(["gcodeAnalysis", "bedZ"], data["gcodeAnalysis"]["bedZ"]) if "serial" in data: if "autoconnect" in data["serial"]: diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index 73a7fc3e4..103c0eb4a 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -270,6 +270,7 @@ default_settings = { "throttle_highprio": 0.0, "throttle_lines": 100, "runAt": "idle", # 'never', 'idle', 'always' + "bedZ": 0.0, }, "feature": { "temperatureGraph": True, diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index 2f076f23a..34f1520f8 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -146,11 +146,33 @@ class MinMax3D(object): >>> empty = MinMax3D() >>> empty.size == Vector3D(0.0, 0.0, 0.0) True + >>> weird = MinMax3D(min_z=-1.0) + >>> weird.record(Vector3D(2.0, 2.0, 2.0)) + >>> weird.record(Vector3D(1.0, 2.0, 3.0)) + >>> weird.min.z == -1.0 + True + >>> weird.size == Vector3D(1.0, 0.0, 4.0) + True """ - def __init__(self): - self.min = Vector3D(float("inf"), float("inf"), float("inf")) - self.max = Vector3D(-float("inf"), -float("inf"), -float("inf")) + def __init__( + self, + min_x=None, + min_y=None, + min_z=None, + max_x=None, + max_y=None, + max_z=None, + ): + min_x = min_x if min_x is not None else float("inf") + min_y = min_y if min_y is not None else float("inf") + min_z = min_z if min_z is not None else float("inf") + max_x = max_x if max_x is not None else -float("inf") + max_y = max_y if max_y is not None else -float("inf") + max_z = max_z if max_z is not None else -float("inf") + + self.min = Vector3D(min_x, min_y, min_z) + self.max = Vector3D(max_x, max_y, max_z) def record(self, coordinate): """ @@ -227,7 +249,9 @@ class gcode(object): offsets=None, max_extruders=10, g90_extruder=False, + bed_z=0.0, ): + self._minMax.min.z = bed_z if os.path.isfile(filename): self.filename = filename self._fileSize = os.stat(filename).st_size @@ -448,17 +472,17 @@ class gcode(object): x = getCodeFloat(line, "X") y = getCodeFloat(line, "Y") z = getCodeFloat(line, "Z") - center = Vector3D(0.0, 0.0, 0.0) + origin = Vector3D(0.0, 0.0, 0.0) if x is None and y is None and z is None: - pos = center + pos = origin else: pos = Vector3D(pos) if x is not None: - pos.x = center.x + pos.x = origin.x if y is not None: - pos.y = center.y + pos.y = origin.y if z is not None: - pos.z = center.z + pos.z = origin.z elif gcode == "G90": # Absolute position relativeMode = False if g90_extruder: