resolve gcode as array/text

This commit is contained in:
Stewart Allen 2022-10-18 21:57:27 -04:00
commit 91514aeb86
6 changed files with 44 additions and 19 deletions

View file

@ -2,8 +2,8 @@
"mode": "CAM",
"internal": 0,
"bedHeight": 2.5,
"bedWidth": 300,
"bedDepth": 300,
"bedWidth": 360,
"bedDepth": 240,
"originCenter": false,
"spindleMax": 12000,
"gcodePre": [

View file

@ -494,7 +494,6 @@ CAM.init = function(kiri, api) {
});
func.opGCode = (label, field = 'gcode') => {
console.log({label});
API.dialog.show('any');
const { c_gcode } = h.bind(
$('mod-any'), h.div({ id: "camop_dialog" }, [
@ -506,9 +505,10 @@ console.log({label});
} })
])
);
c_gcode.value = poppedRec[field] || '';
let av = poppedRec[field] || [];
c_gcode.value = typeof(av) === 'string' ? av : av.join('\n');
c_gcode.onkeyup = (el) => {
poppedRec[field] = c_gcode.value;
poppedRec[field] = c_gcode.value.trim().split('\n');
};
c_gcode.focus();
};

View file

@ -54,6 +54,7 @@ CAM.export = function(print, online) {
point,
points = 0,
lasering = false,
laserOp,
currentOp,
stock = settings.stock || { },
hasStock = spro.camStockOn && stock.x && stock.y && stock.z,
@ -167,17 +168,21 @@ CAM.export = function(print, online) {
pos.t = out.tool;
consts.tool = pos.t;
consts.tool_name = toolNameByNumber(out.tool);
filterEmit(cmdToolChange, { ...consts, spindle: newSpindle } );
if (!lasering) {
filterEmit(cmdToolChange, { ...consts, spindle: newSpindle } );
}
}
// on spindle change (deferred from layer transition so it's post-toolchange)
if ((changeTool && spindleMax) || (newSpindle && newSpindle !== spindle)) {
spindle = newSpindle;
if (spindle > 0) {
let speed = Math.abs(spindle);
filterEmit(cmdSpindle, { speed, spindle: speed, rpm: speed });
} else {
append("M4");
if (!lasering) {
if (spindle > 0) {
let speed = Math.abs(spindle);
filterEmit(cmdSpindle, { speed, spindle: speed, rpm: speed });
} else {
append("M4");
}
}
}
@ -250,7 +255,7 @@ CAM.export = function(print, online) {
if (!lasering && laser) {
// enable laser
filterEmit(currentOp.camLaserOn, consts);
filterEmit(laserOp.on, consts);
}
// if (laser && pos.emit !== out.emit) {
@ -264,7 +269,7 @@ CAM.export = function(print, online) {
if (lasering && !laser) {
// disable laser
filterEmit(currentOp.camLaserOff, consts);
filterEmit(laserOp.off, consts);
}
// update lasering state
@ -302,14 +307,21 @@ CAM.export = function(print, online) {
let toolz = {}, ctool;
// remap points as necessary for origins, offsets, inversions
print.output.forEach(function(layer) {
if (layer.op) {
console.log({ op: layer.op });
return;
}
if (!Array.isArray(layer)) {
return;
}
layer.forEach(function(out) {
if (out.op) {
if (out.op.type === 'laser on') {
laserOp = out.op;
// lasering = true;
// console.log('laser on');
} else if (out.op.type === 'laser off') {
// lasering = false;
// console.log('laser off');
}
return;
}
if (out.tool && out.tool !== ctool) {
ctool = toolByNumber(out.tool);
toolz[out.tool] = ctool;
@ -354,7 +366,7 @@ CAM.export = function(print, online) {
if (mode) {
section(`op-${opnum++}-${mode}`);
}
if (!stripComments) {
if (!stripComments && mode) {
append("; starting " + mode + " op");
}
}

View file

@ -56,6 +56,7 @@ class OpLaserOn extends CamOp {
prepare(ops, progress) {
ops.addGCode(this.op.enable);
ops.setLasering(true, this.op.power);
ops.newLayer();
}
}
@ -67,6 +68,7 @@ class OpLaserOff extends CamOp {
prepare(ops, progress) {
ops.addGCode(this.op.disable);
ops.setLasering(false);
ops.newLayer();
}
}

View file

@ -120,6 +120,8 @@ function prepEach(widget, settings, print, firstPoint, update) {
};
}) : zmax;
newOutput.push(layerOut);
function newLayer() {
if (layerOut.length < 2) {
return;
@ -134,6 +136,9 @@ function prepEach(widget, settings, print, firstPoint, update) {
if (!text || text.length === 0) {
return;
}
if (Array.isArray(text)) {
text = text.join('\r\n');
}
newOutput.push(text);
if (layerOut.length) {
layerOut = [];
@ -420,7 +425,8 @@ function prepEach(widget, settings, print, firstPoint, update) {
nextIsMove = true;
lastMode = op.op.type;
let weight = op.weight();
layerOut.push({ op });
newLayer();
layerOut.push({ op: op.op });
op.prepare(ops, (progress, message) => {
update((opSum + (progress * weight)) / opTot, message || op.type(), message);
});

View file

@ -203,6 +203,11 @@ async function path(levels, update, opts = {}) {
lastOut = out;
});
if (!lastOut) {
// laser levels alone
return;
}
lastEnd = lastOut;
// all moves with an emit at the very end (common in contouring)