支持真实G代码程序执行

结论:AXIS 风格浏览器仿真页面新增 Open Program、runProgramText 和 loadProgramFile,支持用户提供的 G-code 文本/文件通过 LinuxCNC WASM 执行并参与回放。
This commit is contained in:
2026-06-16 22:14:34 +08:00
parent 163a68ff42
commit 69ccf931b1
8 changed files with 204 additions and 5 deletions

View File

@@ -130,6 +130,9 @@
if (!api?.getPrograms || !api?.runProgramById) {
throw new Error("simulation API missing program controls");
}
if (!api?.runProgramText || !api?.loadProgramFile) {
throw new Error("simulation API missing real G-code loading controls");
}
if (!api?.resetPlayback || !api?.stepPlayback || !api?.finishPlayback) {
throw new Error("simulation API missing playback controls");
}
@@ -137,6 +140,9 @@
if (programs.length < 5) {
throw new Error("simulation test program inventory too small");
}
if (!doc.querySelector("[data-open-program]") || !doc.querySelector("[data-open-program-file]")) {
throw new Error("simulation page missing open program controls");
}
doc.querySelector('[data-axis-tab="mdi"]')?.click();
if (!doc.querySelector('[data-axis-panel="manual"]')?.hidden || doc.querySelector('[data-axis-panel="mdi"]')?.hidden) {
@@ -230,6 +236,46 @@
throw new Error("drill simulation did not produce expected feed plunges");
}
const customProgramText = [
"G90 G17 G0 X0 Y0 Z0",
"G1 X2.5 Y0.5 Z0 F75",
"G1 X2.5 Y1.5 Z0",
"M2",
"",
].join("\n");
const customState = await api.runProgramText(customProgramText, {
label: "operator-real-part.ngc",
source: "text",
sourceLabel: "Operator pasted G-code",
});
assertRenderedState(doc, customState);
if (customState.program?.id !== "custom" || customState.program?.source !== "text") {
throw new Error("custom text program state metadata drift");
}
if (!customState.resultText.includes("canon_event=STRAIGHT_FEED line=2 x=2.5 y=0.5 z=0")) {
throw new Error("custom text program did not execute through LinuxCNC WASM");
}
if (doc.body.dataset.simulationProgramId !== "custom" || doc.body.dataset.simulationProgramSource !== "text") {
throw new Error("custom text program body dataset drift");
}
if (!doc.querySelector('[data-axis-shell="statusbar"]')?.textContent.includes("Operator pasted G-code")) {
throw new Error("custom text program source did not render in statusbar");
}
const fileProgram = new frame.contentWindow.File(
[customProgramText.replace("X2.5", "X3.25")],
"real-loaded-file.ngc",
{ type: "text/plain" },
);
const fileState = await api.loadProgramFile(fileProgram);
assertRenderedState(doc, fileState);
if (fileState.program?.source !== "file" || fileState.program?.filename !== "real-loaded-file.ngc") {
throw new Error("loaded file program metadata drift");
}
if (!fileState.resultText.includes("canon_event=STRAIGHT_FEED line=2 x=3.25 y=0.5 z=0")) {
throw new Error("loaded file program did not execute changed G-code through LinuxCNC WASM");
}
status.textContent = "browser_real_simulation_page_smoke=ok";
} catch (error) {
status.textContent = `browser_real_simulation_page_smoke=fail ${error.stack || error.message}`;