get prepare displaying G2s

This commit is contained in:
bakedpotatolord 2025-05-31 18:40:14 -06:00
commit 47e312d486
5 changed files with 139 additions and 51 deletions

View file

@ -42,7 +42,8 @@ class Print {
this.widget = widget;
}
addOutput(array, point, emit, speed, tool, type) {
addOutput(array, point, emit, speed, tool, opts) {
const { type, retract, radius, arcPoints} = opts ?? {};
let { lastPoint, lastEmit, lastOut } = this;
// drop duplicates (usually intruced by FDM bisections)
if (lastPoint && point && type !== 'lerp') {
@ -55,10 +56,15 @@ class Print {
// if (emit && emit < 1) console.log(emit);
this.lastPoint = point;
this.lastEmit = emit;
this.lastOut = lastOut = new Output(point, emit, speed, tool, type || this.nextType);
this.lastOut = lastOut = new Output(point, emit, speed, tool, {
type: type ?? this.nextType,
radius,
arcPoints,
});
if (tool !== undefined) {
this.tools[tool] = true;
}
lastOut.retract = retract;
lastOut.widget = this.widget;
array.push(lastOut);
this.nextType = undefined;
@ -554,12 +560,31 @@ class Print {
}
class Output {
constructor(point, emit, speed, tool, type, radius) {
/**
* Construct a new output element.
*
* in cam, emit is the G code number (G0, G1, G2, G3)
*
* @param {Point} point point to emit, with x, y, and z properties
* @param {number} emit emit (feed for printers, power for lasers, cut for cam)
* @param {number} speed speed in mm/min
* @param {number} tool tool id
* @param {Object} options options object
* @param {string} [options.type] type of point
* @param {number} [options.radius] radius of arc
* @param {Point[]} [options.arcPoints] point based approximation of arc
*/
constructor(point, emit, speed, tool, options) {
const { type, radius, arcPoints } = (options ?? {});
//speed, tool, type, radius
this.point = point; // point to emit
this.emit = emit; // emit (feed for printers, power for lasers, cut for cam)
this.speed = speed;
this.tool = tool;
this.type = type;
this.radius = radius;
this.arcPoints = arcPoints;
// this.where = new Error().stack.split("\n");
}

View file

@ -44,6 +44,13 @@ function rate_to_color(rate, max) {
}
};
/**
* Generate visual representation of a gcode program.
* @param {Output[][]} levels - Array of arrays containing `Output` objects.
* @param {function} update - Called with a completion percentage and the rendered layer.
* @param {{tools: Object, flat: Boolean, thin: Boolean, speed: Boolean, lineWidth: Number, toolMode: Boolean, z: Number, action: String, other: String}} [opts] - Optional parameters.
* @returns {Promise.kiri.Layers[]} - Array of layers.
*/
async function path(levels, update, opts = {}) {
levels = levels.filter(level => level.length);
if (levels.length === 0) {
@ -183,7 +190,8 @@ async function path(levels, update, opts = {}) {
return;
}
if (lastOut) {
if (lastOut) { // if last outpoint is defined
if (arrowAll || lastOut.emit !== out.emit) {
heads.push({p1: lastOutPoint, p2: outPoint});
}
@ -193,7 +201,29 @@ async function path(levels, update, opts = {}) {
// Math.abs(op.y - lp.y),
// Math.abs(op.z - lp.z));
// if (moved < 0.0001) return;
if (out.emit) {
if( is_cam() && (out.emit == 2 || out.emit == 3 )) {
// cam arc emit
console.log('cam arc render woohoo!',out);
// checks if a new poly should be started
if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed) || lastEnd) {
current = newPolygon().setOpen();
current.push(lastOutPoint);
current.color = color(out);
pushPrint(out.tool, current);
}
out.arcPoints.forEach(p => {
current.push(p);
})
current.push(outPoint);
} else if (out.emit) {
// explicity G1 in CAM mode
// just a non-move in other modes
// checks if a new poly should be started
if (!lastOut.emit || (ckspeed && out.speed !== lastOut.speed) || lastEnd) {
current = newPolygon().setOpen();
current.push(lastOutPoint);