add comment rewrite option to support parenthesis fixes #231

This commit is contained in:
Stewart Allen 2022-12-08 16:46:09 -05:00
commit bbb98eda41

View file

@ -53,6 +53,7 @@ CAM.export = function(print, online) {
mode, mode,
point, point,
points = 0, points = 0,
rewrite_comments = false,
lasering = false, lasering = false,
laserOp, laserOp,
stock = settings.stock || { }, stock = settings.stock || { },
@ -94,6 +95,16 @@ CAM.export = function(print, online) {
if (line) { if (line) {
lines++; lines++;
bytes += line.length; 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); output.append(line);
} }
if (!line || output.length > 1000) { if (!line || output.length > 1000) {
@ -305,23 +316,6 @@ CAM.export = function(print, online) {
points++; 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 // look for SCALE header directive
let gcodePre = []; let gcodePre = [];
for (let line of device.gcodePre) { for (let line of device.gcodePre) {
@ -336,11 +330,30 @@ CAM.export = function(print, online) {
} catch (e) { } catch (e) {
console.log('malformed scale directive', line); console.log('malformed scale directive', line);
} }
} else if (line.indexOf(';; REWRITE-COMMENTS-PARENS') === 0) {
rewrite_comments = true;
} else { } else {
gcodePre.push(line); 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 // collect tool info to add to header
let toolz = {}, ctool; let toolz = {}, ctool;
// remap points as necessary for origins, offsets, inversions // remap points as necessary for origins, offsets, inversions