From 8627f54a9839550a683e3a35f2e870305fab4c69 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Sun, 27 Dec 2020 22:51:32 -0500 Subject: [PATCH] add flip operation for double-sided work --- notes.md | 1 - src/kiri/conf.js | 5 +++- src/kiri/main.js | 4 +-- src/kiri/ui.js | 6 +++- src/mode/cam/client.js | 63 +++++++++++++++++++++++++++++++++++++++++- src/mode/cam/ops.js | 3 +- web/kiri/index.html | 4 ++- web/kiri/lang/en.js | 1 + 8 files changed, 79 insertions(+), 8 deletions(-) diff --git a/notes.md b/notes.md index 491659d3..3e479568 100644 --- a/notes.md +++ b/notes.md @@ -5,7 +5,6 @@ # - revisit ease down # - split gcode output # - redo path planning -# - double-sided assistance # `fdm` # - bind process to z ranges or boxed regions diff --git a/src/kiri/conf.js b/src/kiri/conf.js index 421b3b7f..fa2d412c 100644 --- a/src/kiri/conf.js +++ b/src/kiri/conf.js @@ -456,6 +456,8 @@ camDrillDwell: 250, camDrillLift: 2, camDrillingOn: false, + camFlipAxis: "X", + camFlipOther: "", // camDrillReg: "none", camTabsWidth: 5, camTabsHeight: 5, @@ -480,7 +482,8 @@ outputOriginCenter: false, outputInvertX: false, outputInvertY: false, - ops: [] + ops: [], // current ops + op2: [] // flip ops } }, laser: { diff --git a/src/kiri/main.js b/src/kiri/main.js index 08e62446..37982ca7 100644 --- a/src/kiri/main.js +++ b/src/kiri/main.js @@ -1640,7 +1640,7 @@ ******************************************************************* */ // given a settings region, update values of matching bound UI fields - function updateFieldsFromSettings(setrec, uirec = UI) { + function updateFieldsFromSettings(setrec, uirec = UI, trace) { if (!setrec) { return console.trace("missing scope"); } @@ -1664,7 +1664,7 @@ } else if (typ === 'select-one') { uie.innerHTML = ''; let source = uie.parentNode.getAttribute('source'), - list = settings[source] || lists[source], + list = uie._source || settings[source] || lists[source], chosen = null; if (list) list.forEach(function(el, index) { let id = el.id || el.name; diff --git a/src/kiri/ui.js b/src/kiri/ui.js index 95dab981..16cf0e85 100644 --- a/src/kiri/ui.js +++ b/src/kiri/ui.js @@ -733,7 +733,11 @@ row.appendChild(newLabel(label)); row.appendChild(ip); - row.setAttribute("source", source || "tools"); + if (Array.isArray(source)) { + ip._source = source; + } else { + row.setAttribute("source", source || "tools"); + } row.setAttribute("class", "var-row"); row.style.display = hide ? 'none' : ''; if (options) { diff --git a/src/mode/cam/client.js b/src/mode/cam/client.js index 88408042..8b59309c 100644 --- a/src/mode/cam/client.js +++ b/src/mode/cam/client.js @@ -22,7 +22,8 @@ let zaxis = { x: 0, y: 0, z: 1 }, popOp = {}, - func = {}; + func = {}, + flipping; CAM.restoreTabs = restoreTabs; @@ -156,6 +157,14 @@ case "register": return func.opAddRegister('X', 2); case "drill": return func.opAddDrill(); case "trace": return func.opAddTrace(); + case "flip": + // only one flip op permitted + for (let op of current.process.ops) { + if (op.type === 'flip') { + return; + } + } + return func.opAddFlip(); } }; @@ -194,6 +203,10 @@ func.opAdd(rec); }; + func.opAddFlip = () => { + func.opAdd(popOp.flip.new()); + }; + // TAB/TRACE BUTTON HANDLERS api.event.on("button.click", target => { let process = API.conf.get().process; @@ -345,6 +358,41 @@ } }); + func.opFlip = () => { + let { process } = current; + let { ops, op2 } = process; + let add2 = op2.length === 0; // add flip singleton to b-side + let axis = poppedRec.axis; + flipping = true; + switch (axis) { + case 'X': + API.selection.rotate(Math.PI, 0, 0); + // API.widgets.all().forEach(widget => { + // widget.rotate(Math.PI, 0, 0); + // }); + break; + case 'Y': + API.selection.rotate(0, Math.PI, 0); + // API.widgets.all().forEach(widget => { + // widget.rotate(0, Math.PI, 0); + // }); + break; + } + flipping = false; + process.ops = op2; + process.op2 = ops; + for (let op of op2) { + if (op.type === 'flip') { + op.axis = poppedRec.axis; + } + } + if (add2) { + func.opAdd(poppedRec); + } else { + func.opRender(); + } + }; + // TAB FUNCS let showTab, lastTab, tab, iw, ic; api.event.on("cam.tabs.add", func.tabAdd = () => { @@ -628,6 +676,9 @@ func.traceDone(); } unselectTraces(widget); + if (flipping) { + return; + } if (x || y) { clearTabs(widget); } else { @@ -817,6 +868,16 @@ dwell: UC.newInput(LANG.cd_dwll_s, {title:LANG.cd_dwll_l, convert:UC.toFloat}), lift: UC.newInput(LANG.cd_lift_s, {title:LANG.cd_lift_l, convert:UC.toFloat, units:true}) }; + + createPopOp('flip', { + axis: 'camFlipAxis' + }).inputs = { + axis: UC.newSelect(LANG.cd_axis, {}, "regaxis"), + sep: UC.newBlank({class:"pop-sep"}), + action: UC.newRow([ + UC.newButton(LANG.cc_flip, func.opFlip) + ], {class:"ext-buttons f-row"}) + }; }; function createPopOp(type, map) { diff --git a/src/mode/cam/ops.js b/src/mode/cam/ops.js index cac6c931..dc136c1b 100644 --- a/src/mode/cam/ops.js +++ b/src/mode/cam/ops.js @@ -967,7 +967,8 @@ "contour": OpContour, "trace": OpTrace, "drill": OpDrill, - "register": OpRegister + "register": OpRegister, + "flip": CamOp }; })(); diff --git a/web/kiri/index.html b/web/kiri/index.html index 198d68d0..a497efde 100644 --- a/web/kiri/index.html +++ b/web/kiri/index.html @@ -422,9 +422,11 @@
rough
outline
contour
-
register
trace
drill
+
+
register
+
flip
diff --git a/web/kiri/lang/en.js b/web/kiri/lang/en.js index e863f721..1e72e7b7 100644 --- a/web/kiri/lang/en.js +++ b/web/kiri/lang/en.js @@ -273,6 +273,7 @@ kiri.lang['en-us'] = { // CNC COMMON cc_menu: "limits", + cc_flip: "flip", cc_rapd_s: "xy feed", cc_rapd_l: "max xy moves feedrate\nin workspace units / minute", cc_rzpd_s: "z feed",