拆分仿真测试程序目录

结论:将内置 G-code 测试程序从 simulation-app.js 移入 runtime/ui/simulation/programs/,建立一程序一模块的目录化程序库,并保持页面 API 与验证 gate 兼容。
This commit is contained in:
2026-06-16 22:03:06 +08:00
parent db83ad29f3
commit 163a68ff42
12 changed files with 193 additions and 95 deletions

View File

@@ -1,87 +1,19 @@
import { createLinuxCncInterpSdk } from "../../sdk/src/index.js";
import {
DEFAULT_SIMULATION_PROGRAM,
DEFAULT_SIMULATION_PROGRAM_ID,
SIMULATION_TEST_PROGRAMS,
getSimulationTestProgram,
getSimulationTestPrograms,
} from "./programs/index.js";
export const SIMULATION_TEST_PROGRAMS = [
{
id: "square-linear",
label: "Square contour",
category: "Linear",
text: [
"G90 G17 G0 X0 Y0 Z0",
"G1 X1 Y0 Z0 F100",
"G1 X1 Y1 Z0",
"G1 X0 Y1 Z0",
"G1 X0 Y0 Z0",
"M2",
"",
].join("\n"),
expectedMotionTypes: ["STRAIGHT_TRAVERSE", "STRAIGHT_FEED"],
},
{
id: "pocket-z",
label: "Pocket with Z moves",
category: "Linear",
text: [
"G90 G17 G0 X0 Y0 Z1",
"G1 Z-0.25 F40",
"G1 X2 Y0 F120",
"G1 X2 Y1",
"G1 X0 Y1",
"G1 X0 Y0",
"G0 Z1",
"M2",
"",
].join("\n"),
expectedMotionTypes: ["STRAIGHT_TRAVERSE", "STRAIGHT_FEED"],
},
{
id: "incremental-loop",
label: "Incremental loop",
category: "Modal",
text: [
"G90 G17 G0 X0 Y0 Z0",
"G91 G1 X0.5 Y0 F60",
"G1 X0 Y0.5",
"G1 X-0.5 Y0",
"G90 G0 X0 Y0 Z0",
"M2",
"",
].join("\n"),
expectedMotionTypes: ["STRAIGHT_TRAVERSE", "STRAIGHT_FEED"],
},
{
id: "arc-g2-g3",
label: "G2/G3 arc path",
category: "Arc",
text: [
"G90 G17 G0 X0 Y0 Z0",
"G91.1",
"G2 X1 Y1 I1 J0 F80",
"G3 X0 Y0 I0 J-1",
"M2",
"",
].join("\n"),
expectedMotionTypes: ["STRAIGHT_TRAVERSE", "ARC_FEED"],
},
{
id: "drill-g81",
label: "G81 drill pattern",
category: "Cycle",
text: [
"G90 G17 G0 X0 Y0 Z1",
"G81 X0.5 Y0.5 Z-0.25 R0.1 F20",
"X1.0 Y0.5",
"X1.0 Y1.0",
"G80",
"G0 X0 Y0 Z1",
"M2",
"",
].join("\n"),
expectedMotionTypes: ["STRAIGHT_TRAVERSE", "STRAIGHT_FEED"],
},
];
export const DEFAULT_SIMULATION_PROGRAM_ID = SIMULATION_TEST_PROGRAMS[0].id;
export const DEFAULT_SIMULATION_PROGRAM = SIMULATION_TEST_PROGRAMS[0].text;
export {
DEFAULT_SIMULATION_PROGRAM,
DEFAULT_SIMULATION_PROGRAM_ID,
SIMULATION_TEST_PROGRAMS,
getSimulationTestProgram,
getSimulationTestPrograms,
};
const AXES = ["x", "y", "z", "a", "b", "c", "u", "v", "w"];
const PLANE_AXIS_MAP = {
@@ -383,18 +315,6 @@ export function renderSimulationState(documentRef, state) {
renderSimulationPlaybackFrame(documentRef, state, state.motion.length - 1);
}
export function getSimulationTestPrograms() {
return SIMULATION_TEST_PROGRAMS.map((program) => ({ ...program }));
}
export function getSimulationTestProgram(programId = DEFAULT_SIMULATION_PROGRAM_ID) {
const program = SIMULATION_TEST_PROGRAMS.find(({ id }) => id === programId);
if (!program) {
throw new Error(`unknown simulation test program: ${programId}`);
}
return program;
}
export async function runRealBrowserSimulation({
documentRef = document,
programId = DEFAULT_SIMULATION_PROGRAM_ID,