新增真实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

@@ -81,6 +81,12 @@ wasm-port/runtime/ui/simulation/programs/index.js
- `linuxCncRealSimulationApi.runProgramText(programText, metadata)`;
- `linuxCncRealSimulationApi.loadProgramFile(file)`;
- toolbar `Open` file input for `.ngc/.nc/.tap/.gcode/.txt`.
- Editable AXIS-style G-code pane:
- loaded file/custom/built-in program text is visible in a textarea;
- editor text can be changed before execution;
- toolbar `Run Editor Text` executes the current editor contents;
- `getProgramText()`, `setProgramText()`, and `runEditorProgramText()` are
exposed on the browser API.
- Program source metadata:
- `program.source`;
- `program.sourceLabel`;
@@ -102,6 +108,9 @@ Current methods:
- `runProgramById(programId)`
- `runProgramText(programText, metadata)`
- `loadProgramFile(file)`
- `getProgramText()`
- `setProgramText(text, metadata)`
- `runEditorProgramText()`
- `getPlaybackFrame()`
- `resetPlayback()`
- `stepPlayback(delta)`
@@ -169,7 +178,9 @@ Browser code must not implement:
### 1. Real G-code Editor Pane
Add an editable G-code text pane to the AXIS shell:
Status: complete.
Implemented:
- show loaded file/custom text in an editor area;
- allow editing before run;
@@ -177,12 +188,12 @@ Add an editable G-code text pane to the AXIS shell:
- preserve line numbers and active-line highlighting;
- expose `linuxCncRealSimulationApi.getProgramText()`;
- expose `linuxCncRealSimulationApi.setProgramText(text, metadata)`.
- expose `linuxCncRealSimulationApi.runEditorProgramText()`.
Validation:
- browser smoke edits a line, runs it, and verifies changed LinuxCNC canonical
output;
- Node smoke verifies editor text state helpers if factored into JS modules.
- browser smoke sets editor text, runs it, and verifies changed LinuxCNC
canonical output.
### 2. OPFS Program Persistence
@@ -287,6 +298,48 @@ http://154.8.160.151:3000/wangdequan/cnc_wams.git
## Immediate Suggested Start
Start with "Real G-code Editor Pane" because the page can already execute
operator-provided text/files, but the text is not yet visible/editable inside
the AXIS shell after loading.
Start with "OPFS Program Persistence" because the page can now load, edit, and
run real G-code text/files, but programs are not yet saved to or restored from
OPFS from within the AXIS shell.
## Execution Record
### 一、2026-06-16 Real G-code Editor Pane
按 `text16.txt` 的 Immediate Suggested Start 推进,完成 AXIS shell 内真实 G-code 编辑区。
本批新增实质能力:
- `runtime/ui/simulation/index.html` 新增 editable G-code pane
- `data-axis-shell="program-editor"`
- `textarea[data-program-editor]`
- `data-program-editor-status`
- 工具栏新增:
- `Run Editor Text`
- 页面状态新增 `programEditorState`
- 内置程序加载、真实文本执行、真实文件加载都会同步到 editor textarea
- editor textarea 修改后可直接运行;
- `window.linuxCncRealSimulationApi` 新增:
- `getProgramText()`
- `setProgramText(text, metadata)`
- `runEditorProgramText()`
- browser smoke 新增验证:
- 初始内置程序会同步到 editor
- `runProgramText()` 后 editor 同步自定义文本;
- `loadProgramFile()` 后 editor 同步文件文本和 filename metadata
- `setProgramText()` 修改 editor 内容;
- `runEditorProgramText()` 通过 LinuxCNC WASM 执行修改后的 G-code并验证 canonical output
出现修改后的坐标。
关键验证:
```text
browser_real_simulation_page_smoke=ok
real_simulation_programs_node_smoke=ok
```
语义边界:
- editor 只保存和显示 G-code 文本;
- G-code 执行仍通过 LinuxCNC-backed WASM
- JS 不解释 G-code、不规划刀路、不推导 modal/machine semantics。