restore laser slice, preview, export

This commit is contained in:
Stewart Allen 2020-11-08 20:19:50 -05:00
commit 9842a0e43c
5 changed files with 71 additions and 149 deletions

View file

@ -25,11 +25,12 @@
function exportFile(options) {
if (isPrepared()) {
API.event.emit('export', API.mode.get());
switch (API.mode.get()) {
case 'LASER': return callExport();
case 'FDM': return callExport(options);
case 'CAM': return callExport(options);
const mode = API.mode.get();
API.event.emit('export', mode);
switch (mode) {
case 'LASER': return callExportLaser(options);
case 'FDM': return callExport(options, mode);
case 'CAM': return callExport(options, mode);
case 'SLA': return callExportSLA(options);
}
} else {
@ -39,7 +40,7 @@
}
}
function callExport(options) {
function callExport(options, mode) {
const gcode = [];
KIRI.client.export(API.conf.get(), (line) => {
gcode.push(line);
@ -48,6 +49,14 @@
});
}
function callExportLaser(options) {
KIRI.client.export(API.conf.get(), (line) => {
console.log({unexpected_line: line});
}, (output) => {
exportLaserDialog(output);
});
}
function callExportSLA(options) {
const preview = [];
KIRI.client.export(API.conf.get(), (line) => {
@ -61,37 +70,39 @@
});
}
function exportLaserDialog(currentPrint) {
function exportLaserDialog(data) {
if (!isPrepared()) {
return API.function.prepare(exportLaser);
}
let filename = "laser-"+(new Date().getTime().toString(36));
const filename = "laser-"+(new Date().getTime().toString(36));
const settings = API.conf.get();
const driver = KIRI.driver.LASER;
function download_svg() {
saveAs(new Blob(
[currentPrint.exportSVG()],
[driver.exportSVG(settings, data)],
{type:"application/octet-stream"}),
$('print-filename').value + ".svg");
}
function download_dxf() {
saveAs(new Blob(
[currentPrint.exportDXF()],
[driver.exportDXF(settings, data)],
{type:"application/octet-stream"}),
$('print-filename').value + ".dxf");
}
function download_gcode() {
saveAs(new Blob(
[currentPrint.exportLaserGCode()],
[driver.exportGCode(settings, data)],
{type:"application/octet-stream"}),
$('print-filename').value + ".gcode");
}
API.ajax("/kiri/output-laser.html", function(html) {
let segments = 0;
currentPrint.output.forEach(layer => { segments += layer.length });
data.forEach(layer => { segments += layer.length });
UI.print.innerHTML = html;
$('print-filename').value = filename;
$('print-lines').value = UTIL.comma(segments);

View file

@ -212,105 +212,6 @@
scope.bytes = gcode.length;
};
// more generic. only used by SLA at the moment
PRO.export = function(remote, online, ondone) {
let mode = this.settings.mode;
let driver = KIRI.driver[mode];
if (KIRI.client) {
// executed from kiri.js
KIRI.client.export(this.settings, online, ondone);
} else {
if (!(driver && driver.export)) {
console.log({missing_export_driver: mode});
ondone(null);
return;
}
// executed from kiri-worker.js
driver.printExport(this, online, ondone);
}
};
PRO.exportGCode = function(remote, ondone, online) {
let scope = this,
settings = scope.settings,
mode = settings.mode;
if (scope.imported) {
return ondone(scope.imported);
}
if (KIRI.client) {
// executed from kiri.js
KIRI.client.printGCode(function(reply) {
scope.lines = reply.lines;
scope.bytes = reply.bytes;
scope.bounds = reply.bounds;
scope.distance = reply.distance;
scope.time = reply.time;
ondone(reply.gcode);
});
} else {
// executed from kiri-worker.js
let driver = KIRI.driver[mode];
if (driver && driver.printExport) {
ondone(driver.printExport(scope, online));
} else {
console.log({missing_export_driver: mode});
ondone(null);
}
}
};
PRO.exportLaserGCode = function() {
return KIRI.driver.LASER.exportGCode(this);
};
PRO.exportSVG = function(cut_color) {
return KIRI.driver.LASER.exportSVG(this, cut_color);
};
PRO.exportDXF = function() {
return KIRI.driver.LASER.exportDXF(this);
};
PRO.encodeOutput = function() {
let newout = [], newlayer;
this.output.forEach(function(layerout) {
newlayer = [];
newout.push(newlayer);
layerout.forEach(function(out) {
if (out.point) {
// used for renderMoves client side. can drop non-essential
// data to speed up worker -> browser transfer. perhaps a
// more compact encoding (arrays, etc)
let push = { };
if (out.emit !== undefined) push.emit = out.emit;
if (out.speed !== undefined) push.speed = out.speed * 60;
if (out.retract !== undefined) push.retract = out.retract;
if (out.point !== undefined) push.point = {
x: out.point.x, y: out.point.y, z: out.point.z
};
if (out.tool !== undefined) push.tool = out.tool;
if (layerout.thick !== undefined) push.thick = layerout.thick;
newlayer.push(push);
// newlayer.push({
// emit: out.emit,
// speed: out.speed * 60,
// retract: out.retract,
// point: {x: out.point.x, y: out.point.y, z: out.point.z},
// tool: out.tool,
// thick: layerout.thick
// });
}
});
});
return newout;
};
function pref(a,b) {
return a !== undefined ? a : b;
}

View file

@ -73,10 +73,13 @@
if (options && options.flat) {
return this.addFlats(polys, options);
}
if (options) {
if (options && !options.thin) {
return this.addPaths(polys, options);
}
polys = flat(polys);
if (options && options.thin && options.z !== undefined) {
polys.forEach(p => p.setZ(options.z));
}
this.current.polys.appendAll(polys);
this.stats.line_poly += polys.length;
return this;