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

View file

@ -212,105 +212,6 @@
scope.bytes = gcode.length; 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) { function pref(a,b) {
return a !== undefined ? a : b; return a !== undefined ? a : b;
} }

View file

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

View file

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

View file

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