0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-11-24 18:17:56 +01:00

Check gcode generation feasibility check to prevent iPad/iPhone crashes

This commit is contained in:
peteruithoven 2013-10-16 22:25:15 +02:00
parent b1ded5d41b
commit ff14078d46
3 changed files with 27 additions and 21 deletions

View File

@ -212,7 +212,6 @@ function print(e) {
//$(".btnPrint").css("display","none");
if (_points.length > 2) {
//setState(Printer.BUFFERING_STATE,printer.hasControl);
@ -224,11 +223,15 @@ function print(e) {
// so that for example the print button is disabled right away
clearTimeout(gcodeGenerateDelayer);
gcodeGenerateDelayer = setTimeout(function() {
var gcode = generate_gcode();
//startPrint(gencode);
var gcode = generate_gcode();
if (sendPrintCommands) {
if(gcode.length > 0) {
printer.print(gcode);
} else {
printer.overruleState(Printer.IDLE_STATE);
printer.startStatusCheckInterval();
}
} else {
console.log("sendPrintCommands is false: not sending print command to 3dprinter");
}

View File

@ -25,8 +25,10 @@ gcodeEnd.push("G90"); // absolute positioning
gcodeEnd.push("M117 Done "); // display message (20 characters to clear whole screen)*/
var MAX_POINTS_TO_PRINT = 400000; //80000; //40000;
var gcode = [];
function generate_gcode(callback) {
function generate_gcode() {
console.log("f:generategcode()");
var startGcode = [];
@ -124,7 +126,6 @@ function generate_gcode(callback) {
// copy array without reference -> http://stackoverflow.com/questions/9885821/copying-of-an-array-of-objects-to-another-array-without-object-reference-in-java
var points = JSON.parse(JSON.stringify(_points));
console.log("f:generategcode() >> points.length: " + points.length);
// console.log("f:generategcode() >> paths: " + paths.toString());
// console.log("paths.toString(): " + paths.toString());
@ -153,6 +154,19 @@ function generate_gcode(callback) {
console.log("f:generategcode() >> layers: " + layers);
if (layers == Infinity) return;
// check feasibility of design
var pointsToPrint = points.length * layers*(objectHeight/maxObjectHeight)
//console.log(" points.length: ",points.length);
//console.log(" numLayers: ",(layers*(objectHeight/maxObjectHeight)));
//console.log(" pointsToPrint: ",pointsToPrint);
//console.log(" MAX_POINTS_TO_PRINT: ",MAX_POINTS_TO_PRINT);
if(pointsToPrint > MAX_POINTS_TO_PRINT) {
alert("Sorry, your doodle to to complex and / or to high");
console.log("WARNING: to many points to convert to gcode");
return [];
}
for (var layer = 0; layer < layers; layer++) {
var p = JSON.parse(JSON.stringify(points)); // [].concat(points);
@ -262,21 +276,10 @@ function generate_gcode(callback) {
break;
}
}
// add gcode end commands
gcode = gcode.concat(endGcode);
// debug
// var _gc = gc.join("\n");
// console.log("f:generategcode() >> _gc = " + _gc);
// Return the gcode array, joined to one string with '\n' (line break) as the join parameter
// This should result in a nice long string with line breaks
if (callback == undefined) {
return gcode;
} else {
// post
}
}
function scaleFunction(percent) {