2026-06-11 09:23:42 +02:00
|
|
|
import type { Segment, Alignment, PolyWarp } from '../types';
|
2026-06-08 22:37:35 +02:00
|
|
|
import { parseGcode } from '../gcode/parser';
|
|
|
|
|
import { projectSegments } from '../geometry/transform';
|
|
|
|
|
|
|
|
|
|
export interface AppState {
|
|
|
|
|
segments: Segment[];
|
|
|
|
|
alignment: Alignment;
|
2026-06-11 09:23:42 +02:00
|
|
|
warp: PolyWarp | null;
|
2026-06-08 22:37:35 +02:00
|
|
|
loadGcode(text: string): string[];
|
2026-06-11 09:23:42 +02:00
|
|
|
setWarp(w: PolyWarp | null): void;
|
2026-06-08 22:37:35 +02:00
|
|
|
projected(): Segment[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function createState(): AppState {
|
|
|
|
|
const state: AppState = {
|
|
|
|
|
segments: [],
|
|
|
|
|
alignment: { tx: 0, ty: 0, rot: 0 },
|
2026-06-11 09:23:42 +02:00
|
|
|
warp: null,
|
2026-06-08 22:37:35 +02:00
|
|
|
loadGcode(text: string): string[] {
|
|
|
|
|
const { segments, warnings } = parseGcode(text);
|
|
|
|
|
state.segments = segments;
|
|
|
|
|
return warnings;
|
|
|
|
|
},
|
2026-06-11 09:23:42 +02:00
|
|
|
setWarp(w: PolyWarp | null): void {
|
|
|
|
|
state.warp = w;
|
2026-06-08 22:37:35 +02:00
|
|
|
},
|
|
|
|
|
projected(): Segment[] {
|
2026-06-11 09:23:42 +02:00
|
|
|
if (!state.warp) return [];
|
|
|
|
|
return projectSegments(state.segments, state.alignment, state.warp);
|
2026-06-08 22:37:35 +02:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
return state;
|
|
|
|
|
}
|