add CAM custom gcode operator
This commit is contained in:
parent
bc3e738a8d
commit
c67d641e43
10 changed files with 94 additions and 14 deletions
|
|
@ -169,6 +169,7 @@ CAM.init = function(kiri, api) {
|
|||
let settings = API.conf.get();
|
||||
let { process, device } = settings;
|
||||
switch (ev.target.innerText) {
|
||||
case "gcode": return func.opAddGCode();
|
||||
case "level": return func.opAddLevel();
|
||||
case "rough": return func.opAddRough();
|
||||
case "outline": return func.opAddOutline();
|
||||
|
|
@ -195,6 +196,10 @@ CAM.init = function(kiri, api) {
|
|||
}
|
||||
};
|
||||
|
||||
func.opAddGCode = () => {
|
||||
func.opAdd(popOp.gcode.new());
|
||||
};
|
||||
|
||||
func.opAddLevel = () => {
|
||||
func.opAdd(popOp.level.new());
|
||||
};
|
||||
|
|
@ -421,6 +426,25 @@ CAM.init = function(kiri, api) {
|
|||
}
|
||||
});
|
||||
|
||||
func.opGCode = () => {
|
||||
API.dialog.show('any');
|
||||
const { c_gcode } = h.bind(
|
||||
$('mod-any'), h.div({ id: "camop_dialog" }, [
|
||||
h.label('custom gcode operation'),
|
||||
h.textarea({ id: "c_gcode", rows: 15, cols: 50 }),
|
||||
h.button({ _: 'done', onclick: () => {
|
||||
API.dialog.hide();
|
||||
API.conf.save();
|
||||
} })
|
||||
])
|
||||
);
|
||||
c_gcode.value = poppedRec.gcode || '';
|
||||
c_gcode.onkeyup = (el) => {
|
||||
poppedRec.gcode = c_gcode.value;
|
||||
};
|
||||
c_gcode.focus();
|
||||
};
|
||||
|
||||
func.opFlip = () => {
|
||||
let widgets = API.widgets.all();
|
||||
let { process } = current;
|
||||
|
|
@ -932,6 +956,12 @@ CAM.init = function(kiri, api) {
|
|||
return current.device.spindleMax > 0;
|
||||
}
|
||||
|
||||
createPopOp('gcode', {
|
||||
gcode: 'camCustomGcode',
|
||||
}).inputs = {
|
||||
action: UC.newRow([ UC.newButton(LANG.edit, func.opGCode) ], {class:"ext-buttons f-row"})
|
||||
};
|
||||
|
||||
createPopOp('level', {
|
||||
tool: 'camLevelTool',
|
||||
spindle: 'camLevelSpindle',
|
||||
|
|
|
|||
|
|
@ -275,9 +275,11 @@ CAM.export = function(print, online) {
|
|||
|
||||
// collect tool info to add to header
|
||||
let toolz = {}, ctool;
|
||||
|
||||
// remap points as necessary for origins, offsets, inversions
|
||||
print.output.forEach(function(layer) {
|
||||
if (!Array.isArray(layer)) {
|
||||
return;
|
||||
}
|
||||
layer.forEach(function(out) {
|
||||
if (out.tool && out.tool !== ctool) {
|
||||
ctool = toolByNumber(out.tool);
|
||||
|
|
@ -311,6 +313,10 @@ CAM.export = function(print, online) {
|
|||
|
||||
// emit all points in layer/point order
|
||||
for (let layerout of print.output) {
|
||||
if (!Array.isArray(layerout)) {
|
||||
append(layerout.toString().trim());
|
||||
continue;
|
||||
}
|
||||
if (mode !== layerout.mode || consts.tool !== layerout[0].tool) {
|
||||
if (mode && !stripComments) {
|
||||
append("; ending " + mode + " op after " + Math.round(time/60) + " seconds");
|
||||
|
|
|
|||
|
|
@ -38,6 +38,18 @@ class CamOp {
|
|||
prepare() { }
|
||||
}
|
||||
|
||||
class OpGCode extends CamOp {
|
||||
constructor(state, op) {
|
||||
super(state, op);
|
||||
}
|
||||
|
||||
prepare(ops, progress) {
|
||||
if (this.op.gcode) {
|
||||
ops.addGCode(this.op.gcode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OpLevel extends CamOp {
|
||||
constructor(state, op) {
|
||||
super(state, op);
|
||||
|
|
@ -1504,6 +1516,7 @@ CAM.OPS = CamOp.MAP = {
|
|||
"trace": OpTrace,
|
||||
"drill": OpDrill,
|
||||
"register": OpRegister,
|
||||
"gcode": OpGCode,
|
||||
"flip": CamOp
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -41,7 +41,8 @@ CAM.prepare = function(widgets, settings, update) {
|
|||
});
|
||||
});
|
||||
|
||||
print.render = render.path(print.output, (progress, layer) => {
|
||||
const output = print.output.filter(level => Array.isArray(level));
|
||||
print.render = render.path(output, (progress, layer) => {
|
||||
update(0.75 + progress * 0.25, "render", layer);
|
||||
}, {
|
||||
thin: true,
|
||||
|
|
@ -127,6 +128,15 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
|||
layerOut.spindle = spindle;
|
||||
}
|
||||
|
||||
function addGCode(text) {
|
||||
newOutput.push(text);
|
||||
if (layerOut.length) {
|
||||
layerOut = [];
|
||||
layerOut.mode = lastMode;
|
||||
layerOut.spindle = spindle;
|
||||
}
|
||||
}
|
||||
|
||||
// non-zero means contouring
|
||||
function setTolerance(dist) {
|
||||
tolerance = dist;
|
||||
|
|
@ -372,6 +382,7 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
|||
setPrintPoint,
|
||||
printPoint,
|
||||
newLayer,
|
||||
addGCode,
|
||||
camOut,
|
||||
polyEmit,
|
||||
poly2polyEmit,
|
||||
|
|
@ -505,9 +516,13 @@ function prepEach(widget, settings, print, firstPoint, update) {
|
|||
}
|
||||
|
||||
// last layer/move is to zmax
|
||||
// injected into the last layer generated
|
||||
if (lastPoint && newOutput.length)
|
||||
print.addOutput(newOutput[newOutput.length-1], printPoint = lastPoint.clone().setZ(zmax_outer), 0, 0, tool.getNumber());
|
||||
// re-inject that point into the last layer generated
|
||||
if (lastPoint && newOutput.length) {
|
||||
let lastLayer = newOutput.filter(layer => Array.isArray(layer)).peek();
|
||||
if (Array.isArray(lastLayer)) {
|
||||
print.addOutput(lastLayer, printPoint = lastPoint.clone().setZ(zmax_outer), 0, 0, tool.getNumber());
|
||||
}
|
||||
}
|
||||
|
||||
// replace output single flattened layer with all points
|
||||
print.output = newOutput;
|
||||
|
|
|
|||
Loading…
Reference in a new issue