From 3baf9d7fc0b05a336e17a3920fd5d267423959b3 Mon Sep 17 00:00:00 2001 From: Javierma87 Date: Tue, 8 Mar 2016 17:46:40 +0000 Subject: [PATCH] Analysis now done in frontend, taking also into account centre origin --- src/octoprint/filemanager/analysis.py | 4 +- .../static/js/app/viewmodels/files.js | 85 ++++++++++++++++--- src/octoprint/util/gcodeInterpreter.py | 42 ++++++--- 3 files changed, 102 insertions(+), 29 deletions(-) diff --git a/src/octoprint/filemanager/analysis.py b/src/octoprint/filemanager/analysis.py index f5cd2b410..0fe659a41 100644 --- a/src/octoprint/filemanager/analysis.py +++ b/src/octoprint/filemanager/analysis.py @@ -17,8 +17,6 @@ from octoprint.events import Events, eventManager import octoprint.util.gcodeInterpreter as gcodeInterpreter -#Added to check if object exceeds printing area -from octoprint.printer.profile import PrinterProfileManager class QueueEntry(collections.namedtuple("QueueEntry", "path, type, location, absolute_path, printer_profile")): """ @@ -262,7 +260,7 @@ class GcodeAnalysisQueue(AbstractAnalysisQueue): self._gcode.load(self._current.absolute_path, self._current.printer_profile, throttle=throttle_callback) result = dict() - result["warning"]=self._gcode.getWarning() + 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 bb961e91c..fed4f08f6 100644 --- a/src/octoprint/static/js/app/viewmodels/files.js +++ b/src/octoprint/static/js/app/viewmodels/files.js @@ -6,6 +6,7 @@ $(function() { self.loginState = parameters[1]; self.printerState = parameters[2]; self.slicing = parameters[3]; + self.printerProfiles=parameters[4]; self.isErrorOrClosed = ko.observable(undefined); self.isOperational = ko.observable(undefined); @@ -423,16 +424,74 @@ $(function() { } } output += gettext("Estimated Print Time") + ": " + formatDuration(data["gcodeAnalysis"]["estimatedPrintTime"]) + "
"; - if(self.loginState.isUser()&&data["gcodeAnalysis"]["warning"]) + if(self.loginState.isUser()) { - var warning = "

" + gettext("Object exceeds printing area") + "

"; - warning += pnotifyAdditionalInfo("
Object or objects in file '"+data["name"]+"' exceed/s the printing area
"); - new PNotify({ - title: "Object dimensions", - text: warning, - type: "warning", - hide: false - }); + var profileItems=self.printerProfiles.profiles.items(); + var count=0; + while(countvolumeInfo.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)) + { + warn=true; + } + } + } + if(warn) + { + var warning = "

" + gettext("Revise file ")+ data["name"] + "

"; + var info=""; + if(volumeInfo.origin=="lowerleft" && printingArea["maxX"]>volumeInfo.width) + { + info=info+"Profile's width: "+volumeInfo.width+"\n Object's width: "+ printingArea["maxX"]+"\n"; + } + if(volumeInfo.origin=="lowerleft" && printingArea["maxY"]>volumeInfo.depth) + { + info=info+"Profile's depth: "+volumeInfo.depth+"\n Object's depth: "+ printingArea["maxY"]+"\n"; + } + if(volumeInfo.origin=="center" && printingArea["maxX"]>(volumeInfo.width/2)) + { + info=info+"Profile's width (center origin): "+(volumeInfo.width/2)+"\n Object's width: "+ printingArea["maxX"]+"\n"; + } + if(volumeInfo.origin=="center" && Math.abs(printingArea["minX"])>(volumeInfo.width/2)) + { + info=info+"Profile's width (center origin): "+(volumeInfo.width/2)+"\n Object's width: "+ printingArea["minX"]+"\n"; + } + if(volumeInfo.origin=="center" && printingArea["maxY"]>(volumeInfo.depth/2)) + { + info=info+"Profile's depth (center origin): "+(volumeInfo.depth/2)+"\n Object's depth: "+ printingArea["maxY"]+"\n"; + } + if(volumeInfo.origin=="center" && Math.abs(printingArea["minY"])>(volumeInfo.depth/2)) + { + info=info+"Profile's depth (center origin): "+(volumeInfo.depth/2)+"\n Object's depth: "+ printingArea["minY"]+"\n"; + } + if(printingArea["maxZ"]>volumeInfo.height) + { + info=info+"Profile's height: "+volumeInfo.height+"\n Object's height: "+ printingArea["maxZ"]+"\n"; + } + warning += pnotifyAdditionalInfo("
"+info+"
"); + new PNotify({ + title: "Object exceeds the printing area", + text: warning, + type: "warning", + hide: false + }); + } } } if (data["prints"] && data["prints"]["last"]) { @@ -640,7 +699,7 @@ $(function() { self.requestData(filename, location, self.currentPath()); if (data.result.done) { - selef._setProgressBar(0, "", false); + self._setProgressBar(0, "", false); } }; @@ -653,14 +712,14 @@ $(function() { type: "error", hide: false }); - self.setProgressBar(0, "", false); + self._setProgressBar(0, "", false); }; self._handleUploadProgress = function(e, data) { var progress = parseInt(data.loaded / data.total * 100, 10); var uploaded = progress >= 100; - self.setProgressBar(progress, uploaded ? gettext("Saving ...") : gettext("Uploading ..."), uploaded); + self._setProgressBar(progress, uploaded ? gettext("Saving ...") : gettext("Uploading ..."), uploaded); }; self._handleDragNDrop = function (e) { @@ -734,7 +793,7 @@ $(function() { OCTOPRINT_VIEWMODELS.push([ GcodeFilesViewModel, - ["settingsViewModel", "loginStateViewModel", "printerStateViewModel", "slicingViewModel"], + ["settingsViewModel", "loginStateViewModel", "printerStateViewModel", "slicingViewModel","printerProfilesViewModel"], ["#files_wrapper", "#add_folder_dialog"] ]); }); diff --git a/src/octoprint/util/gcodeInterpreter.py b/src/octoprint/util/gcodeInterpreter.py index aa6f4ffb8..007f99618 100644 --- a/src/octoprint/util/gcodeInterpreter.py +++ b/src/octoprint/util/gcodeInterpreter.py @@ -21,7 +21,6 @@ class AnalysisAborted(Exception): class gcode(object): def __init__(self): self._logger = logging.getLogger(__name__) - self.layerList = None self.extrusionAmount = [0] self.extrusionVolume = [0] @@ -30,8 +29,13 @@ class gcode(object): self.progressCallback = None self._abort = False self._filamentDiameter = 0 - #Parameters for object size checking - self.warn=False + #Parameters for object size check + self.minX=None + self.minY=None + self.minZ=None + self.maxX=None + self.maxY=None + self.maxZ=None def load(self, filename, printer_profile, throttle=None): if os.path.isfile(filename): @@ -46,6 +50,10 @@ class gcode(object): self._abort = True 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] @@ -122,13 +130,15 @@ class gcode(object): z = getCodeFloat(line, 'Z') e = getCodeFloat(line, 'E') f = getCodeFloat(line, 'F') - #Check if x,y or z exceeds printing area - width=float(printer_profile["volume"]["width"]) - depth=float(printer_profile["volume"]["depth"]) - height=float(printer_profile["volume"]["height"]) - if not self.warn and (x>width or y>depth or z>height): - self.warn=True - self._logger.warn("Object is bigger than the printing area") + #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 z is not None: + zList.append(z) oldPos = pos pos = pos[:] if posAbs: @@ -220,6 +230,7 @@ class gcode(object): e = getCodeFloat(line, 'E') if e is not None: currentE[currentExtruder] = e + previousE=e if x is not None: posOffset[0] = pos[0] - x if y is not None: @@ -267,6 +278,14 @@ 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) @@ -280,9 +299,6 @@ class gcode(object): def _parseCuraProfileString(self, comment, prefix): return {key: value for (key, value) in map(lambda x: x.split("=", 1), zlib.decompress(base64.b64decode(comment[len(prefix):])).split("\b"))} - def getWarning(self): - return self.warn - def getCodeInt(line, code): n = line.find(code) + 1 if n < 1: