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;

View file

@ -447,11 +447,15 @@
const output = new KIRI.Render();
layers.push(output);
output.setLayer('move', moveColor).addPolys(moves);
output
.setLayer('move', moveColor)
.addPolys(moves, { thin: true, z: opts.z });
Object.values(prints).forEach(array => {
output
.setLayer('print', printColor)
.addPolys(array, thin ? null : { offset: array.width, height })
.setLayer(opts.action || 'print', printColor)
.addPolys(array, thin ?
{ thin, z: opts.z } :
{ offset: array.width, height, z: opts.z })
});
update(index / output.length);

View file

@ -11,11 +11,12 @@
BASE = self.base,
UTIL = BASE.util,
POLY = BASE.polygons,
DBUG = BASE.debug,
FDM = KIRI.driver.FDM,
CAM = KIRI.driver.CAM,
LASER = KIRI.driver.LASER = {
slice,
sliceRender,
printSetup,
prepare,
export: exportLaser,
printRender,
exportGCode,
exportSVG,
@ -46,7 +47,8 @@
}, function(slices) {
widget.slices = slices;
slices.forEach(function(slice, index) {
slice.doShells(1, -proc.laserOffset);
FDM.share.doShells(slice, 1, -proc.laserOffset);
slice.output().setLayer("slice").addPolys(slice.topPolys());
onupdate(0.80 + (index/slices.length) * 0.20);
});
ondone();
@ -55,10 +57,6 @@
});
};
function sliceRender(widget) {
return KIRI.driver.CAM.sliceRender(widget);
}
function sliceEmitObjects(print, slice, groups) {
let start = newPoint(0,0,0);
let process = print.settings.process;
@ -83,15 +81,13 @@
}
}
slice.tops.forEach(function(top) {
laserOut(top.innerTraces(), group);
laserOut(top.traces, group);
if (!grouped) {
groups.push(group);
group = [];
group.thick = slice.thick;
}
});
laserOut(slice.topPolyInners(), group);
laserOut(slice.topShells(), group);
if (!grouped) {
groups.push(group);
group = [];
group.thick = slice.thick;
}
if (grouped) {
groups.push(group);
@ -104,12 +100,11 @@
* @param {Object} print state object
* @param {Function} update incremental callback
*/
function printSetup(print, update) {
let widgets = print.widgets,
settings = print.settings,
device = settings.device,
function prepare(widgets, settings, update) {
let device = settings.device,
process = settings.process,
output = print.output,
print = self.worker.print = KIRI.newPrint(settings, widgets),
output = print.output = [],
totalSlices = 0,
slices = 0;
@ -125,7 +120,7 @@
let merged = [];
widget.slices.forEach(function(slice) {
let polys = [];
slice.gatherTopPolys([]).forEach(p => p.flattenTo(polys));
slice.topPolys().clone(true).forEach(p => p.flattenTo(polys));
polys.forEach(p => {
let match = false;
for (let i=0; i<merged.length; i++) {
@ -214,14 +209,19 @@
// if (process.laserKnife) {
// console.log({laser_it: output});
// }
return print.render = FDM.prepareRender(output, update, { thin: true, z: 0, action: "cut" });
};
function exportLaser(print, online, ondone) {
ondone(print.output);
}
/**
*
*/
function exportElements(print, onpre, onpoly, onpost, onpoint, onlayer) {
let process = print.settings.process,
output = print.output,
function exportElements(settings, output, onpre, onpoly, onpost, onpoint, onlayer) {
let process = settings.process,
zcolor = process.outputLaserZColor,
last,
point,
@ -306,16 +306,17 @@
/**
*
*/
function exportGCode(print) {
function exportGCode(settings, data) {
let lines = [], dx = 0, dy = 0, z = 0, feedrate;
let dev = print.settings.device;
let dev = settings.device;
let space = dev.gcodeSpace ? ' ' : '';
let power = 255;
let laser_on = dev.gcodeLaserOn || [];
let laser_off = dev.gcodeLaserOff || [];
exportElements(
print,
settings,
data,
function(min, max, power, speed) {
let width = (max.x - min.x),
height = (max.y - min.y);
@ -370,8 +371,8 @@
/**
*
*/
function exportSVG(print, cut_color) {
let zcolor = print.settings.process.outputLaserZColor ? 1 : 0;
function exportSVG(settings, data, cut_color) {
let zcolor = settings.process.outputLaserZColor ? 1 : 0;
let lines = [], dx = 0, dy = 0, my, z = 0;
let colors = [
"black",
@ -386,7 +387,8 @@
];
exportElements(
print,
settings,
data,
function(min, max) {
let width = (max.x - min.x),
height = (max.y - min.y);
@ -425,11 +427,12 @@
/**
*
*/
function exportDXF(print) {
function exportDXF(settings, data) {
let lines = [];
exportElements(
print,
settings,
data,
function(min, max) {
lines.appendAll([
' 0',