add optional slice ordering via selection

This commit is contained in:
Stewart Allen 2025-12-26 00:00:04 -05:00
commit de41b25fba
2 changed files with 12 additions and 2 deletions

View file

@ -12,6 +12,7 @@ import { exportFile } from './export.js';
* Properties: slice, preview, export * Properties: slice, preview, export
*/ */
let complete = {}; let complete = {};
let order;
/** /**
* Prepare and execute slicing for all widgets on the platform. * Prepare and execute slicing for all widgets on the platform.
@ -46,6 +47,10 @@ function prepareSlices(callback, scale = 1, offset = 0) {
callback = preparePreview; callback = preparePreview;
} }
order = api.selection.count() ?
Object.assign({}, ...api.selection.widgets().map((w,i) => ({[w.id]:i}))) :
undefined;
const widgets = api.widgets.all(); const widgets = api.widgets.all();
const settings = conf.get(); const settings = conf.get();
const { device, process, controller } = settings; const { device, process, controller } = settings;
@ -371,6 +376,7 @@ function preparePreview(callback, scale = 1, offset = 0) {
// pass preview mode to worker // pass preview mode to worker
settings.pmode = feature.pmode; settings.pmode = feature.pmode;
settings.render = true; settings.render = true;
settings.order = order;
client.prepare(settings, (progress, message, layer) => { client.prepare(settings, (progress, message, layer) => {
if (layer) { if (layer) {

View file

@ -28,7 +28,7 @@ export async function cam_prepare(widgets, settings, update) {
const count = active.length; const count = active.length;
const weight = 1 / count; const weight = 1 / count;
const print = self.kiri_worker.current.print = newPrint(settings, active); const print = self.kiri_worker.current.print = newPrint(settings, active);
const { origin } = settings; const { order, origin } = settings;
// wait for safe eval setup // wait for safe eval setup
await print.ready(); await print.ready();
@ -37,7 +37,11 @@ export async function cam_prepare(widgets, settings, update) {
print.output = []; print.output = [];
// sort output by distance to origin // sort output by distance to origin
if (origin) { if (order) {
active.sort((a,b) => {
return (order[a.id] ?? Infinity) - (order[b.id] ?? Infinity);
});
} else if (origin) {
let point = newPoint().move(origin); let point = newPoint().move(origin);
active.sort((w0,w1) => active.sort((w0,w1) =>
newPoint().move(w0.track.pos).distTo2D(point) - newPoint().move(w0.track.pos).distTo2D(point) -