From bbb98eda41970a37a55ea1c9be2db1ab61ccadf3 Mon Sep 17 00:00:00 2001 From: Stewart Allen Date: Thu, 8 Dec 2022 16:46:09 -0500 Subject: [PATCH] add comment rewrite option to support parenthesis fixes #231 --- src/kiri-mode/cam/export.js | 47 +++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 17 deletions(-) diff --git a/src/kiri-mode/cam/export.js b/src/kiri-mode/cam/export.js index ac6c29b6..9c567b96 100644 --- a/src/kiri-mode/cam/export.js +++ b/src/kiri-mode/cam/export.js @@ -53,6 +53,7 @@ CAM.export = function(print, online) { mode, point, points = 0, + rewrite_comments = false, lasering = false, laserOp, stock = settings.stock || { }, @@ -94,6 +95,16 @@ CAM.export = function(print, online) { if (line) { lines++; bytes += line.length; + if (rewrite_comments) { + const spos = line.indexOf(';'); + if (spos >= 0) { + const left = line.substring(0, spos); + const right = '(' + line.substring(spos) + .replace(/; /g,'') + .replace(/;/g,'') + ')'; + line = [ left, right ].join(''); + } + } output.append(line); } if (!line || output.length > 1000) { @@ -305,23 +316,6 @@ CAM.export = function(print, online) { points++; } - section('header'); - if (!stripComments) { - append(`; Generated by Kiri:Moto ${kiri.version}`); - append(`; ${new Date().toString()}`); - filterEmit(["; Bed left:{left} right:{right} top:{top} bottom:{bottom}"], consts); - if (hasStock) { - append(`; Stock X:${stock.x.round(2)} Y:${stock.y.round(2)} Z:${stock.z.round(2)}`); - } - append(`; Target: ${settings.filter[settings.mode]}`); - append("; --- process ---"); - for (let pk in spro) { - if (pk !== "ops" && pk !== "op2") { - append("; " + pk + " = " + spro[pk]); - } - } - } - // look for SCALE header directive let gcodePre = []; for (let line of device.gcodePre) { @@ -336,11 +330,30 @@ CAM.export = function(print, online) { } catch (e) { console.log('malformed scale directive', line); } + } else if (line.indexOf(';; REWRITE-COMMENTS-PARENS') === 0) { + rewrite_comments = true; } else { gcodePre.push(line); } } + section('header'); + if (!stripComments) { + append(`; Generated by Kiri:Moto ${kiri.version}`); + append(`; ${new Date().toString()}`); + filterEmit(["; Bed left:{left} right:{right} top:{top} bottom:{bottom}"], consts); + if (hasStock) { + append(`; Stock X:${stock.x.round(2)} Y:${stock.y.round(2)} Z:${stock.z.round(2)}`); + } + append(`; Target: ${settings.filter[settings.mode]}`); + append("; --- process ---"); + for (let pk in spro) { + if (pk !== "ops" && pk !== "op2") { + append("; " + pk + " = " + spro[pk]); + } + } + } + // collect tool info to add to header let toolz = {}, ctool; // remap points as necessary for origins, offsets, inversions