推进 INI 面板 run readiness workflow helper

This commit is contained in:
2026-06-15 05:21:01 +08:00
parent a883af2d3e
commit 4a307f63f6
8 changed files with 322 additions and 11 deletions

View File

@@ -32,6 +32,7 @@ import {
summarizeRunResult,
} from "./run-summary.js";
import {
createRunSessionReadinessState,
runGcodeSessionWorkflow,
} from "./run-workflow.js";
import {
@@ -772,8 +773,28 @@ document.getElementById("restore-load-session").addEventListener("click", async
document.getElementById("run-gcode").addEventListener("click", async () => {
try {
if (!loadedSession) {
throw new Error("Load a machine session before running G-code.");
const readiness = createRunSessionReadinessState({
loadedSession,
snapshot: restoredSessionSnapshot,
defaultFilename: UI_SESSION.defaultGcodeFilename,
defaultOpfsPath: defaultGcodeOpfsPath(),
wasmPath: UI_SESSION.gcodeWasmPath,
gcodeFilenameFromProgramPath,
});
updatePanelMachineSessionState({
runReadiness: readiness,
selectedProgram: readiness.program,
fields: {
sessionGcode: readiness.program.opfsPath,
runSource: readiness.program.source,
runOpfsPath: readiness.program.opfsPath,
runWasmPath: readiness.program.wasmPath,
},
lastAction: "run-gcode-readiness",
error: readiness.runButton.reason,
});
if (!readiness.canRun) {
throw new Error(readiness.runButton.reason ?? "Load a machine session before running G-code.");
}
const interp = requireInterpSdk();
clearRunPlayback();
@@ -803,6 +824,7 @@ document.getElementById("run-gcode").addEventListener("click", async () => {
setField("runStatus", workflow.fields.runStatus);
setLastRunSummary(workflow.summary);
updatePanelMachineSessionState({
runReadiness: workflow.readiness,
selectedProgram: {
source: workflow.program.source,
opfsPath: workflow.program.opfsPath,

View File

@@ -4,6 +4,7 @@ export function createIniPanelStateSummary({
machineFiles = null,
sessionSnapshot = null,
sessionLoad = null,
runReadiness = null,
run = null,
fiveaxisRemap = null,
} = {}) {
@@ -17,6 +18,7 @@ export function createIniPanelStateSummary({
machineFiles,
sessionSnapshot,
sessionLoad,
runReadiness,
run,
fiveaxisRemap: fiveaxisRemap ?? null,
};
@@ -28,6 +30,7 @@ export function createMachineSessionStateSnapshot({
machineFiles = null,
sessionSnapshot = null,
sessionLoad = null,
runReadiness = null,
selectedProgram = null,
run = null,
fields = {},
@@ -42,6 +45,7 @@ export function createMachineSessionStateSnapshot({
machineFiles,
sessionSnapshot,
sessionLoad,
runReadiness,
run,
fiveaxisRemap,
}),
@@ -69,6 +73,7 @@ export function createMachineSessionStateReport(state = {}) {
const fields = state.fields ?? {};
const sessionSnapshot = state.sessionSnapshot ?? {};
const sessionLoad = state.sessionLoad ?? {};
const runReadiness = state.runReadiness ?? {};
const selectedProgram = state.selectedProgram ?? {};
const run = state.run ?? {};
return {
@@ -95,6 +100,17 @@ export function createMachineSessionStateReport(state = {}) {
opfsPath: selectedProgram.opfsPath ?? run.programOpfsPath ?? fields.runOpfsPath ?? null,
wasmPath: selectedProgram.wasmPath ?? run.programWasmPath ?? fields.runWasmPath ?? null,
},
runReadiness: {
phase: runReadiness.phase ?? null,
canRun: Boolean(runReadiness.canRun),
missing: Array.isArray(runReadiness.missing) ? runReadiness.missing : [],
buttonEnabled: Boolean(runReadiness.runButton?.enabled),
buttonReason: runReadiness.runButton?.reason ?? null,
programSource: runReadiness.program?.source ?? null,
programOpfsPath: runReadiness.program?.opfsPath ?? null,
programWasmPath: runReadiness.program?.wasmPath ?? null,
iniWasmPath: runReadiness.loadedSession?.iniWasmPath ?? null,
},
run: {
status: run.runStatus ?? fields.runStatus ?? null,
canonicalEventCount: run.canonicalEventCount ?? 0,
@@ -123,6 +139,7 @@ export function createMachineSessionWorkflowStatus(state = {}) {
const report = createMachineSessionStateReport(state);
return {
readiness: report.readiness,
runReadiness: report.runReadiness,
lastAction: report.status.lastAction,
error: report.status.error,
session: report.session,
@@ -145,6 +162,7 @@ export function createMachineSessionControlView(bundle = {}) {
const report = bundle.report ?? {};
const workflowStatus = bundle.workflowStatus ?? {};
const session = workflowStatus.session ?? report.session ?? {};
const runReadiness = workflowStatus.runReadiness ?? report.runReadiness ?? {};
const run = workflowStatus.run ?? report.run ?? {};
return {
status: {
@@ -176,6 +194,8 @@ export function createMachineSessionControlView(bundle = {}) {
id: "run",
title: "Run",
rows: [
{ label: "Ready", value: runReadiness.phase ?? null },
{ label: "Button", value: runReadiness.buttonEnabled ? "enabled" : "disabled" },
{ label: "Status", value: run.status ?? null },
{ label: "Canonical events", value: run.canonicalEventCount ?? 0 },
{ label: "Motion snapshots", value: run.motionSnapshotCount ?? 0 },

View File

@@ -34,6 +34,55 @@ export function selectSessionGcodeProgram({
};
}
export function createRunSessionReadinessState({
loadedSession = null,
snapshot = null,
defaultFilename,
defaultOpfsPath,
wasmPath,
gcodeFilenameFromProgramPath,
}) {
const program = selectSessionGcodeProgram({
snapshot,
defaultFilename,
defaultOpfsPath,
wasmPath,
gcodeFilenameFromProgramPath,
});
const missing = [];
if (!loadedSession?.ini?.wasmPath) {
missing.push("loaded-session");
}
if (!program.filename || !program.opfsPath || !program.wasmPath) {
missing.push("gcode-program");
}
const canRun = missing.length === 0;
return {
phase: canRun ? "ready" : "blocked",
canRun,
missing,
loadedSession: {
iniWasmPath: loadedSession?.ini?.wasmPath ?? null,
},
snapshot: {
present: Boolean(snapshot),
label: snapshot?.metadata?.snapshotLabel ?? snapshot?.sessionId ?? null,
workflow: snapshot?.metadata?.workflow ?? null,
gcodeOpfsPath: snapshot?.payload?.files?.gcode ?? null,
},
defaultProgram: {
filename: defaultFilename ?? null,
opfsPath: defaultOpfsPath ?? null,
wasmPath: wasmPath ?? null,
},
program,
runButton: {
enabled: canRun,
reason: canRun ? null : `Missing ${missing.join(", ")}.`,
},
};
}
export function runSessionContextLogLines(program, snapshot = null, snapshotLabel = null) {
const summary = createSessionSnapshotSummary({
metadata: snapshot?.metadata ?? {},
@@ -58,16 +107,18 @@ export async function runGcodeSessionWorkflow({
summarizeRun = () => ({}),
snapshotLabel = null,
}) {
if (!loadedSession) {
throw new Error("Load a machine session before running G-code.");
}
const program = selectSessionGcodeProgram({
const readiness = createRunSessionReadinessState({
loadedSession,
snapshot,
defaultFilename,
defaultOpfsPath,
wasmPath,
gcodeFilenameFromProgramPath,
});
if (!readiness.canRun) {
throw new Error("Load a machine session before running G-code.");
}
const program = readiness.program;
const programText = await loadGcodeProgram(program.filename);
interp.writeTextFile(program.wasmPath, programText);
const resultText = interp.runFileWithIni(program.wasmPath, loadedSession.ini.wasmPath).trim();
@@ -91,6 +142,7 @@ export async function runGcodeSessionWorkflow({
resultText,
motionSnapshots,
summary,
readiness,
fields: {
sessionGcode: program.opfsPath,
runStatus: summary.runStatus,