From 7187943d6f7519185f386c17f934ec58d9a0bc34 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Tue, 9 Jun 2020 13:43:30 -0400 Subject: [PATCH] fix cam spindle. add printRender to fdm driver --- src/kiri/init.js | 15 ++------- src/kiri/print.js | 5 ++- src/mode/fdm/driver.js | 72 +++++++++++++++++++++++++++++++++++++++++- 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/src/kiri/init.js b/src/kiri/init.js index 8895468d..9dcc673a 100644 --- a/src/kiri/init.js +++ b/src/kiri/init.js @@ -601,7 +601,7 @@ UI.gcodeLayer, UI.extFilament, UI.extNozzle, - UI.deviceMaxSpindle, + UI.spindleMax, UI.gcodeSpindle, UI.gcodeDwell, UI.gcodeChange, @@ -621,16 +621,7 @@ e.disabled = !local; }); - // hide spindle fields when device doens't support it - if (mode === 'CAM') [ - UI.extrudeAbs, - UI.roughingSpindle, - UI.finishingSpindle, - UI.drillSpindle - ].forEach(function(e) { - e.parentNode.style.display = dev.spindleMax >= 0 ? 'none' : 'block'; - }); - + UI.extrudeAbs.style.display = mode === 'CAM' ? 'none' : 'flex'; UI.deviceSave.disabled = !local; UI.deviceDelete.disabled = !local; UI.deviceAdd.disabled = dev.noclone; @@ -1176,7 +1167,7 @@ bedWidth: UC.newInput(LANG.dv_bedw_s, {title:LANG.dv_bedw_l, convert:UC.toFloat, size:6}), bedDepth: UC.newInput(LANG.dv_bedd_s, {title:LANG.dv_bedd_l, convert:UC.toFloat, size:6}), maxHeight: UC.newInput(LANG.dv_bedh_s, {title:LANG.dv_bedh_l, convert:UC.toFloat, size:6, modes:FDM_SLA}), - deviceMaxSpindle: UC.newInput(LANG.dv_spmx_s, {title:LANG.dv_spmx_l, convert:UC.toInt, modes:CAM}), + spindleMax: UC.newInput(LANG.dv_spmx_s, {title:LANG.dv_spmx_l, convert:UC.toInt, modes:CAM}), deviceOrigin: UC.newBoolean(LANG.dv_orgc_s, onBooleanClick, {title:LANG.dv_orgc_l, modes:GCODE}), deviceOriginTop: UC.newBoolean(LANG.dv_orgt_s, onBooleanClick, {title:LANG.dv_orgt_l, modes:CAM}), deviceRound: UC.newBoolean(LANG.dv_bedc_s, onBooleanClick, {title:LANG.dv_bedc_l, modes:FDM}), diff --git a/src/kiri/print.js b/src/kiri/print.js index a4f4d558..c1b4cddd 100644 --- a/src/kiri/print.js +++ b/src/kiri/print.js @@ -50,6 +50,8 @@ this.distance = 0; this.bounds = null; this.imported = null; + + this.hsv2rgb = hsv2rgb; } PRO.addOutput = addOutput; @@ -339,7 +341,8 @@ break; case 'CAM': case 'FDM': - scope.renderMoves(true, 0x888888); + driver.printRender(scope); + // scope.renderMoves(true, 0x888888); break; case 'LASER': scope.renderMoves(false, 0x0088aa); diff --git a/src/mode/fdm/driver.js b/src/mode/fdm/driver.js index 1bbb6730..c910cf67 100644 --- a/src/mode/fdm/driver.js +++ b/src/mode/fdm/driver.js @@ -19,7 +19,7 @@ printSetup, printExport, // printDownload, - // printRender + printRender }, SLICER = KIRI.slicer, newPoint = BASE.newPoint; @@ -1226,4 +1226,74 @@ return online ? null : output.join("\n"); }; + function printRender(print) { + let debug = KIRI.api.const.LOCAL; + let scope = print, emits, moves, last; + // render layered output + scope.lines = 0; + scope.output.forEach(function(layerout) { + let move = [], print = {}, z; + layerout.forEach(function(out, index) { + let point = out.point; + if (last) { + if (UTIL.distSq(last, point) < 0.001 && point.z === last.z) { + return; + } + if (out.emit > 0) { + let spd = out.speed || 4000; + let arr = print[spd] || []; + print[spd] = arr; + arr.push(last); + arr.push(point); + } else { + move.push(last); + move.push(point); + } + // move direction arrow heads + if (debug && last.z == point.z) { + let rs = BASE.newSlope( + {x: point.x, y: point.y}, + {x: last.x, y: last.y} + ); + let ao1 = BASE.newSlopeFromAngle(rs.angle + 25); + let ao2 = BASE.newSlopeFromAngle(rs.angle - 25); + let sp = BASE.newPoint(point.x, point.y, point.z); + move.push(sp); + move.push(sp.projectOnSlope(ao1, 0.5)); + move.push(sp); + move.push(sp.projectOnSlope(ao2, 0.5)); + } + } else { + z = point.z; + } + last = point; + }); + // printing moves + emits = KIRI.newLayer(scope.group); + scope.printView.push(emits); + // non-printing moves + moves = KIRI.newLayer(scope.group); + moves.lines(move, 0x888888); + scope.movesView.push(moves); + moves.render(); + for (let speed in print) { + let sint = Math.min(6000, parseInt(speed)); + let rgb = scope.hsv2rgb({h:sint/6000, s:1, v:0.6}); + // emits.noodle_lines(print[speed], 0.2, + // ((rgb.r * 0xff) << 16) | + // ((rgb.g * 0xff) << 8) | + // ((rgb.b * 0xff) << 0), + // 0, print[speed][0].z + // ); + emits.lines(print[speed], + ((rgb.r * 0xff) << 16) | + ((rgb.g * 0xff) << 8) | + ((rgb.b * 0xff) << 0) + ); + } + emits.render(); + scope.lines += print.length; + }); + } + })();