新增真实G代码编辑区

结论:AXIS 风格浏览器仿真页面新增可编辑 G-code pane、Run Editor Text、get/setProgramText 和 runEditorProgramText,编辑后的真实 G-code 继续通过 LinuxCNC WASM 执行并纳入 browser gate。
This commit is contained in:
2026-06-16 22:28:08 +08:00
parent 042f9be2c3
commit d6a623308b
5 changed files with 233 additions and 10 deletions

View File

@@ -78,6 +78,7 @@
"preview-dro",
"active-codes",
"gcode-pane",
"program-editor",
"machine-state",
"statusbar",
]) {
@@ -133,6 +134,9 @@
if (!api?.runProgramText || !api?.loadProgramFile) {
throw new Error("simulation API missing real G-code loading controls");
}
if (!api?.getProgramText || !api?.setProgramText || !api?.runEditorProgramText) {
throw new Error("simulation API missing editor text controls");
}
if (!api?.resetPlayback || !api?.stepPlayback || !api?.finishPlayback) {
throw new Error("simulation API missing playback controls");
}
@@ -143,6 +147,13 @@
if (!doc.querySelector("[data-open-program]") || !doc.querySelector("[data-open-program-file]")) {
throw new Error("simulation page missing open program controls");
}
if (!doc.querySelector("[data-program-editor]") || !doc.querySelector("[data-run-editor-program]")) {
throw new Error("simulation page missing editable G-code controls");
}
const initialEditor = api.getProgramText();
if (!initialEditor.text.includes("G1 X1 Y0 Z0 F100")) {
throw new Error("simulation editor did not receive initial built-in program text");
}
doc.querySelector('[data-axis-tab="mdi"]')?.click();
if (!doc.querySelector('[data-axis-panel="manual"]')?.hidden || doc.querySelector('[data-axis-panel="mdi"]')?.hidden) {
@@ -261,6 +272,9 @@
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");
}
if (!api.getProgramText().text.includes("G1 X2.5 Y0.5 Z0 F75")) {
throw new Error("custom text program did not sync into editable G-code pane");
}
const fileProgram = new frame.contentWindow.File(
[customProgramText.replace("X2.5", "X3.25")],
@@ -275,6 +289,35 @@
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");
}
if (!api.getProgramText().metadata.filename || !api.getProgramText().text.includes("G1 X3.25 Y0.5 Z0 F75")) {
throw new Error("loaded file program did not sync into editor state");
}
api.setProgramText(
[
"G90 G17 G0 X0 Y0 Z0",
"G1 X4.75 Y2.25 Z0 F95",
"M2",
"",
].join("\n"),
{
label: "edited-in-axis-pane.ngc",
source: "editor",
sourceLabel: "Editor text",
},
);
const editorState = api.getProgramText();
if (!editorState.text.includes("X4.75") || editorState.metadata.label !== "edited-in-axis-pane.ngc") {
throw new Error("simulation editable G-code state did not accept setProgramText");
}
const editorRunState = await api.runEditorProgramText();
assertRenderedState(doc, editorRunState);
if (!editorRunState.resultText.includes("canon_event=STRAIGHT_FEED line=2 x=4.75 y=2.25 z=0")) {
throw new Error("editor G-code did not execute changed text through LinuxCNC WASM");
}
if (!doc.querySelector("[data-program-editor]")?.value.includes("X4.75")) {
throw new Error("editor DOM did not retain edited G-code text");
}
status.textContent = "browser_real_simulation_page_smoke=ok";
} catch (error) {