diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index 0fe659a41..8fed445a2 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -258,9 +258,10 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): self._gcode = gcodeInterpreter.gcode() self._gcode.load(self._current.absolute_path, self._current.printer_profile, throttle=throttle_callback) - + result = dict() - result["printingArea"]={"minX" : self._gcode.minX, "minY" : self._gcode.minY, "minZ" : self._gcode.minZ, "maxX" : self._gcode.maxX, "maxY" : self._gcode.maxY, "maxZ" : self._gcode.maxZ} + result["printingArea"] = {"minX" : self._gcode.minX, "minY" : self._gcode.minY, "minZ" : self._gcode.minZ, + "maxX" : self._gcode.maxX, "maxY" : self._gcode.maxY, "maxZ" : self._gcode.maxZ} if self._gcode.totalMoveTimeMinute: result["estimatedPrintTime"] = self._gcode.totalMoveTimeMinute * 60 if self._gcode.extrusionAmount: diff --git a/src/octoprint/static/js/app/viewmodels/files.js b/src/octoprint/static/js/app/viewmodels/files.js index 343af0137..3dc577cf8 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -6,7 +6,7 @@ $(function() { self.loginState = parameters[1]; self.printerState = parameters[2]; self.slicing = parameters[3]; - self.printerProfiles=parameters[4]; + self.printerProfiles=parameters[4]; self.isErrorOrClosed = ko.observable(undefined); self.isOperational = ko.observable(undefined); @@ -424,29 +424,32 @@ $(function() { } } output += gettext("Estimated Print Time") + ": " + formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"]) + "
"; - if(self.loginState.isUser()) - { + if (self.loginState.isUser()) + { var profileItems=self.printerProfiles.profiles.items(); var count=0; - while(countvolumeInfo.width || printingArea["maxY"]>volumeInfo.depth || printingArea["maxZ"]>volumeInfo.height) + if(printingArea["maxX"]>volumeInfo.width || printingArea["maxY"]>volumeInfo.depth || + printingArea["maxZ"]>volumeInfo.height) { warn=true; } } else //origin is centre { - if( printingArea["maxX"]>(volumeInfo.width/2) || printingArea["maxY"]>(volumeInfo.depth/2) || printingArea["maxZ"]>volumeInfo.height || Math.abs(printingArea["minX"])>(volumeInfo.width/2) || Math.abs(printingArea["minY"])>(volumeInfo.depth/2)) + if( printingArea["maxX"]>(volumeInfo.width/2) || printingArea["maxY"]>(volumeInfo.depth/2) || + printingArea["maxZ"]>volumeInfo.height || Math.abs(printingArea["minX"])>(volumeInfo.width/2) || + Math.abs(printingArea["minY"])>(volumeInfo.depth/2)) { warn=true; } @@ -456,44 +459,39 @@ $(function() { { var warning = "

" + _.sprintf(gettext("Revise file %s"), data["name"]) + "

"; var info=""; - if(volumeInfo.origin=="lowerleft") - { - if(printingArea["maxX"]>volumeInfo.width) - { - info=info+_.sprintf(gettext("Profile's max. X: %s\n Object's max. X: %s\n"),volumeInfo.width,printingArea["maxX"]); - } - if(printingArea["maxY"]>volumeInfo.depth) - { - info=info+_.sprintf(gettext("Profile's max. Y: %s\n Object's max. Y: %s\n"),volumeInfo.depth, printingArea["maxY"]); - } + + // set print volume boundaries + var boundaries = { + minX : 0, + maxX : volumeInfo.width, + minY : 0, + maxY : volumeInfo.depth, + minZ : 0, + maxZ : volumeInfo.height + }; + if (volumeInfo.origin === "center") { + boundaries["maxX"] = volumeInfo.width / 2; + boundaries["minX"] = -1 * boundaries["maxX"]; + boundaries["maxY"] = volumeInfo.depth / 2; + boundaries["minY"] = -1 * boundaries["maxY"]; } - else - { - if(volumeInfo.origin=="center") - { - if(Math.abs(printingArea["minX"])>(volumeInfo.width/2)) - { - info=info+_.sprintf(gettext("Profile's min. X: %s\n Object's min. X: %s\n"),-(volumeInfo.width/2),printingArea["minX"]); - } - if(printingArea["maxX"]>(volumeInfo.width/2)) - { - info=info+_.sprintf(gettext("Profile's max. X: %s\n Object's max. X: %s\n"),(volumeInfo.width/2),printingArea["maxX"]); - } - if(Math.abs(printingArea["minY"])>(volumeInfo.depth/2)) - { - info=info+_.sprintf(gettext("Profile's min. Y: %s\n Object's min. Y: %s\n"),-(volumeInfo.depth/2),printingArea["minY"]); - } - if(printingArea["maxY"]>(volumeInfo.depth/2)) - { - info=info+_.sprintf(gettext("Profile's max. Y: %s\n Object's max. Y: %s)\n"),(volumeInfo.depth/2),printingArea["maxY"]); - } - } + + // find exceeded dimensions + if (printingArea["minX"] < boundaries["minX"] || printingArea["maxX"] > boundaries["maxX"]) { + info += _.sprintf(gettext("Profile's width: ( %s, %s) vs object's width: (%s, %s)\n"), boundaries["minX"], + boundaries["maxX"],printingArea["minX"], printingArea["maxX"]); } - if(printingArea["maxZ"]>volumeInfo.height) - { - info=info+_.sprintf(gettext("Profile's max. Z: %s\n Object's max. Z: %s"),volumeInfo.height,printingArea["maxZ"]); + if (printingArea["minY"] < boundaries["minY"] || printingArea["maxY"] > boundaries["maxY"]) { + info += _.sprintf(gettext("Profile's depth: (%s, %s) vs object's depth: (%s, %s)\n"),boundaries["minY"], + boundaries["maxY"], printingArea["minY"], printingArea["maxY"]); } - warning += pnotifyAdditionalInfo("
"+info+"
"); + if (printingArea["minZ"] < boundaries["minZ"] || printingArea["maxZ"] > boundaries["maxZ"]) { + info += _.sprintf(gettext("Profile's height: (%s, %s) vs object's height: (%s, %s)\n"),boundaries["minZ"], + boundaries["maxZ"], printingArea["minZ"], printingArea["maxZ"]); + } + + //warn user + warning += pnotifyAdditionalInfo("
" + info + "
"); new PNotify({ title: "Object exceeds the printing area", text: warning, @@ -501,7 +499,7 @@ $(function() { hide: false }); } - } + } } if (data["prints"] && data["prints"]["last"]) { output += gettext("Last Printed") + ": " + formatTimeAgo(data["prints"]["last"]["date"]) + "
"; @@ -583,7 +581,7 @@ $(function() { if (_.endsWith(filename.toLowerCase(), ".stl")) { self.slicing.show(location, filename); } - + if (data.result.done) { $("#gcode_upload_progress .bar").css("width", "0%"); $("#gcode_upload_progress").removeClass("progress-striped").removeClass("active"); diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index 007f99618..2b85cca7b 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -51,9 +51,6 @@ class gcode(object): def _load(self, gcodeFile, printer_profile, throttle=None): previousE=0 - xList=list() - yList=list() - zList=list() filePos = 0 readBytes = 0 pos = [0.0, 0.0, 0.0] @@ -131,14 +128,16 @@ class gcode(object): e = getCodeFloat(line, 'E') f = getCodeFloat(line, 'F') #Add value to list in case move includes extrusion - if e is not None and (e-previousE)>0: - if x is not None: - xList.append(x) - if y is not None: - yList.append(y) - previousE=e + if e is not None and (e - previousE) > 0: + self.minX = x if self.minX is None or x < self.minX else self.minX + self.maxX = x if self.maxX is None or x > self.maxX else self.maxX + self.minY = y if self.minY is None or y < self.minY else self.minY + self.maxY = y if self.maxY is None or y > self.maxY else self.maxY + previousE = e + if z is not None: - zList.append(z) + self.minZ = z if self.minZ is None or z < self.minZ else self.minZ + self.maxZ = z if self.maxZ is None or z > self.maxZ else self.maxZ oldPos = pos pos = pos[:] if posAbs: @@ -278,14 +277,6 @@ class gcode(object): if throttle is not None: throttle() - #We are only interested in minimum and maximum values from the list - self.minX=min(xList) - self.maxX=max(xList) - self.minY=min(yList) - self.maxY=max(yList) - self.minZ=min(zList) - self.maxZ=max(zList) - if self.progressCallback is not None: self.progressCallback(100.0)