Analysis now done in frontend, taking also into account centre origin

This commit is contained in:
Javierma87 committed 2016-03-08 17:46:40 +00:00
1 parent e742e74475
commit 3baf9d7fc0
3 files changed
+102 -29

No files matched your search

+1 -3
View File
@@ -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:
+72 -13
View File
@@ -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"]) + "<br>";
if(self.loginState.isUser()&&data["gcodeAnalysis"]["warning"])
if(self.loginState.isUser())
{
var warning = "<p>" + gettext("Object exceeds printing area") + "</p>";
warning += pnotifyAdditionalInfo("<pre>Object or objects in file '"+data["name"]+"' exceed/s the printing area</pre>");
new PNotify({
title: "Object dimensions",
text: warning,
type: "warning",
hide: false
});
var profileItems=self.printerProfiles.profiles.items();
var count=0;
while(count<profileItems.length && !profileItems[count].current)
{
count++;
}
if(count<profileItems.length)
{
var warn=false;
var volumeInfo=profileItems[count].volume;
var printingArea=data["gcodeAnalysis"]["printingArea"];
if(volumeInfo.origin=="lowerleft")
{
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))
{
warn=true;
}
}
}
if(warn)
{
var warning = "<p>" + gettext("Revise file ")+ data["name"] + "</p>";
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("<pre>"+info+"</pre>");
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"]
]);
});
+29 -13
View File
@@ -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: