From 9842a0e43c66ca54007f7d539212d7871c458973 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 8 Nov 2020 20:19:50 -0500 Subject: [PATCH] restore laser slice, preview, export --- src/kiri/export.js | 35 +++++++++----- src/kiri/print.js | 99 ---------------------------------------- src/kiri/render.js | 5 +- src/mode/fdm/prepare.js | 10 ++-- src/mode/laser/driver.js | 71 ++++++++++++++-------------- 5 files changed, 71 insertions(+), 149 deletions(-) diff --git a/src/kiri/export.js b/src/kiri/export.js index 50b1b948..49765bd7 100644 --- a/src/kiri/export.js +++ b/src/kiri/export.js @@ -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); diff --git a/src/kiri/print.js b/src/kiri/print.js index eb49c94c..75142dab 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -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; } diff --git a/src/kiri/render.js b/src/kiri/render.js index ee81bc2e..78f96aef 100644 --- a/src/kiri/render.js +++ b/src/kiri/render.js @@ -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; diff --git a/src/mode/fdm/prepare.js b/src/mode/fdm/prepare.js index ed1ec4cc..bef76d73 100644 --- a/src/mode/fdm/prepare.js +++ b/src/mode/fdm/prepare.js @@ -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); diff --git a/src/mode/laser/driver.js b/src/mode/laser/driver.js index 23724fcd..3aea0a0f 100644 --- a/src/mode/laser/driver.js +++ b/src/mode/laser/driver.js @@ -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