- 新数据链 web/teaching/cases/carrier-partdesign:20 件零件(spec.json 唯一来源)、 内核建造器 parts/*.mjs、traces/FCStd/replay 全量产物;装配 20 插入 + 19 关节。 - 工具包 tools/carrier:catalog / preflight / create-part / create-assembly / create-all / list / self-test / README,按零件与装配拆分为独立工具。 - 共享驱动扩展 web/tools/cad-ui-rebuild:Loft/Pipe/Hole/Fillet/Chamfer/Mirrored/ LinearPattern 交互,Reversed 复选框补齐;装配 saveAssemblyBundle 先 Accept 再保存。 - 教学:lessons.mjs 新增 carrier 组(环境课 + 20 件 + 装配),suite-runner 增加 carrier-part/carrier-assembly,生成 carrier-toolkit.html 并接入 index 与控制台证据。 验证:20 件 210 步全部有头通过(P05 修复后 39640 m³;P06 回归 8/8); 装配 20/20 插入、19/19 关节、20 组件 0 畸形、0 mismatch;check:carrier、 check:reducer、check-console --live 全绿。 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
372 lines
19 KiB
JavaScript
372 lines
19 KiB
JavaScript
/**
|
||
* Teaching curriculum for the console.
|
||
*
|
||
* Data only — no Node APIs beyond nothing at all, so the builder can inline it
|
||
* into the page and the server can serve it verbatim.
|
||
*
|
||
* Every suite lesson names real case ids; `build-console.mjs` validates them
|
||
* against catalog.mjs and fails the build if one no longer exists.
|
||
*/
|
||
|
||
import { groups as reducerGroups, parts as reducerParts } from "../../../tools/reducer/catalog.mjs";
|
||
import { groups as carrierGroups, parts as carrierParts } from "../../../tools/carrier/catalog.mjs";
|
||
|
||
export const GROUPS = [
|
||
{ id: "basics", title: "准备:让环境可用", workbench: "系统", blurb: "先证明 dist、Chrome、显示和静态服务都就绪,再谈功能。" },
|
||
{ id: "reducer", title: "二级减速器:逐件建模", workbench: "Reducer", blurb: "23 个零件各自一课,在真实界面里从头建出来;最后是装配课。" },
|
||
{ id: "carrier", title: "航空母舰:逐件建模与装配", workbench: "Carrier", blurb: "20 个 PartDesign 零件(舰体、甲板、舰岛、舰载机…)各一课,再装配成整舰。" },
|
||
{ id: "shell", title: "壳层与入口", workbench: "Shell", blurb: "COOP/COEP 隔离、工作台外壳、命令面板与偏好——所有功能的前提。" },
|
||
{ id: "part", title: "Part:参数化零件", workbench: "Part", blurb: "图元、布尔、任务面板;最直观的建模入口。" },
|
||
{ id: "partdesign", title: "PartDesign:实体特征", workbench: "PartDesign", blurb: "Body、草图、Pad 与边缘特征、Thickness。" },
|
||
{ id: "sketcher", title: "Sketcher:草图与约束", workbench: "Sketcher", blurb: "草图编辑、约束面板与自由度读数。" },
|
||
{ id: "assembly", title: "Assembly:装配", workbench: "Assembly", blurb: "创建装配、插入链接、关节与任务面板。" },
|
||
{ id: "mesh", title: "Mesh:网格", workbench: "Mesh", blurb: "网格工作台与 MeshPart 转换;也是性能敏感区。" },
|
||
{ id: "bim", title: "BIM:建筑构件", workbench: "BIM", blurb: "BIM 工作台与任务面板。" },
|
||
{ id: "cam", title: "CAM:加工路径", workbench: "CAM", blurb: "Job、Profile、Pocket 与工具控制器。" },
|
||
{ id: "io", title: "导入导出", workbench: "Import", blurb: "Files 工具、OPFS 浏览器与格式导出。" },
|
||
{ id: "data", title: "表格与测量", workbench: "Spreadsheet", blurb: "电子表格与测量/检查面板。" },
|
||
{ id: "drawing", title: "制图与仿真", workbench: "TechDraw", blurb: "TechDraw 图纸与 FEM 分析。" },
|
||
{ id: "specialists", title: "专业模块", workbench: "Specialists", blurb: "Draft、Surface、Inspection、逆向、材料、机器人、Web。" },
|
||
{ id: "crosscut", title: "交叉能力", workbench: "Crosscut", blurb: "面板滚动、OPFS 往返、保存回开、导出格式、错误恢复、视口。" },
|
||
{ id: "practice", title: "自由练习", workbench: "自由练习", blurb: "在自己挑选的用例范围内组一次运行;参数仍受白名单约束。" },
|
||
];
|
||
|
||
/** Chapter id → group + one-line teaching blurb. */
|
||
const CHAPTER_NOTES = {
|
||
ch00: { group: "basics", blurb: "启动页、OPFS 文档与第一次保存。" },
|
||
ch01: { group: "shell", blurb: "界面、文档、对象树、属性、视图与保存。" },
|
||
ch02: { group: "part", blurb: "Part 图元、布尔与检查。" },
|
||
ch03: { group: "sketcher", blurb: "草图、矩形与约束入口。" },
|
||
ch04: { group: "partdesign", blurb: "PartDesign Body、草图与 Pad。" },
|
||
ch05: { group: "assembly", blurb: "创建装配与插入链接。" },
|
||
ch06: { group: "data", blurb: "电子表格驱动尺寸与测量读数。" },
|
||
ch07: { group: "io", blurb: "导入导出面板与文件工具。" },
|
||
ch08: { group: "mesh", blurb: "网格工作台全流程。" },
|
||
ch09: { group: "bim", blurb: "BIM 工作台构件流程。" },
|
||
ch10: { group: "cam", blurb: "CAM Job 与加工操作。" },
|
||
ch11: { group: "drawing", blurb: "TechDraw 页面与标注。" },
|
||
ch12: { group: "drawing", blurb: "FEM 分析与结果查看。" },
|
||
ch13: { group: "specialists", blurb: "专业模块工具集。" },
|
||
ch14: { group: "specialists", blurb: "生产线案例(复合装配)。" },
|
||
ch15: { group: "shell", blurb: "帮助与启动中心。" },
|
||
ch16: { group: "shell", blurb: "壳层区域、偏好、快捷键与命令面板。" },
|
||
};
|
||
|
||
/**
|
||
* Hand-written lessons. `job` kinds:
|
||
* preflight — no spawn, renders the server preflight report
|
||
* suite — runs tools/web-freecad-functional-suite.mjs with fixed flags
|
||
* probe — runs tools/layout-probe.mjs on one whitelisted page
|
||
* host — runs tools/static-host.mjs for 2 minutes (watch ORIGIN=)
|
||
*/
|
||
const CORE_LESSONS = [
|
||
{
|
||
id: "lesson-00-preflight",
|
||
groupId: "basics",
|
||
title: "第 0 课 · 环境自检",
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: "在执行任何产品用例之前,先确认四件事:dist 已构建、内核产物已同步、Chrome 可执行、DISPLAY 可用。缺失项按「前置失败」处理,而不是产品失败。",
|
||
sees: ["六项前置检查全部变绿", "每项失败都附带可直接复制的修复命令"],
|
||
expect: "前置面板全绿;若某项失败,页面禁用运行按钮并给出修复命令。",
|
||
job: { kind: "preflight" },
|
||
notes: ["铁律:前置条件未满足时不得执行产品断言。"],
|
||
},
|
||
{
|
||
id: "lesson-01-static-host",
|
||
groupId: "basics",
|
||
title: "第 1 课 · 静态服务与隔离头",
|
||
level: "入门",
|
||
durationMin: 2,
|
||
summary: "所有浏览器用例都跑在一个带 COOP/COEP 头的临时静态服务上。本课用 120 秒观察服务启动,并读出 ORIGIN——这是后面所有页面的地址。",
|
||
sees: ["终端出现 ORIGIN=、ROOT=、DOCUMENT=", "服务监听在 127.0.0.1 的临时端口"],
|
||
expect: "日志出现 `ORIGIN=` 即通过;2 分钟到点自动结束。",
|
||
job: { kind: "host" },
|
||
},
|
||
{
|
||
id: "lesson-02-layout-probe",
|
||
groupId: "basics",
|
||
title: "第 2 课 · 三栏布局探针",
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: "用探针确认 PartDesign 页面的三栏布局:页面本身不滚动、左右面板各自可滚动、注入内容后中间舞台不位移。",
|
||
sees: ["每项检查输出 page-scroll / aside-bounds / aside-scrolls / stage-stable", "失败时给出具体像素"],
|
||
expect: "全部检查为 ok;任一失败,探针退出码为 1。",
|
||
job: { kind: "probe", url: "/partdesign.html" },
|
||
},
|
||
{
|
||
id: "lesson-shell",
|
||
groupId: "shell",
|
||
title: "壳层冒烟:五个入口用例",
|
||
level: "入门",
|
||
durationMin: 2,
|
||
summary: "SHELL-01..05 验证所有功能的前提:入口可打开、COOP/COEP 隔离生效、SharedArrayBuffer 可用、工作台壳层与命令面板就位。",
|
||
sees: ["有头浏览器逐个打开 Part / Mesh / 工作台页面", "每个用例一行 `<id>: passed (Xs)`"],
|
||
expect: "5/5 通过;任何失败都先怀疑环境,再怀疑产品。",
|
||
job: { kind: "suite", only: ["SHELL-01", "SHELL-02", "SHELL-03", "SHELL-04", "SHELL-05"], slow: 150, highlight: true },
|
||
},
|
||
{
|
||
id: "lesson-part-boolean",
|
||
groupId: "part",
|
||
title: "Part · 图元、布尔与检查",
|
||
level: "入门",
|
||
durationMin: 2,
|
||
summary: "在工作台里创建一个立方体与圆柱,做布尔差集,并打开检查工具确认真实几何。",
|
||
sees: ["对象树出现布尔结果", "属性面板显示体积等真实数值"],
|
||
expect: "用例 CH-ch02-part-primitives-boolean 通过。",
|
||
job: { kind: "suite", only: ["CH-ch02-part-primitives-boolean"], slow: 200, highlight: true, screenshots: "all" },
|
||
},
|
||
{
|
||
id: "lesson-part-panels",
|
||
groupId: "part",
|
||
title: "Part · 任务面板(Shape Builder、Fillet)",
|
||
level: "进阶",
|
||
durationMin: 2,
|
||
summary: "任务面板是 Web 端最容易回归的区域:它们参与文档流,可能把三维舞台挤出视口。本课逐项操作并确认舞台稳定。",
|
||
sees: ["任务面板出现在底部停靠区", "舞台高度不变"],
|
||
expect: "用例 CH-ch02-part-task-panels 通过。",
|
||
job: { kind: "suite", only: ["CH-ch02-part-task-panels"], slow: 150, highlight: true },
|
||
},
|
||
{
|
||
id: "lesson-part-module",
|
||
groupId: "part",
|
||
title: "Part · 模块冒烟",
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: "P2 模块冒烟:加载模块壳体、暴露命令面、派发一条规范化 worker 命令。",
|
||
sees: ["一条 MOD-Part-01 记录", "命令返回结果而不只是挂载页面"],
|
||
expect: "用例 MOD-Part-01 通过。",
|
||
job: { kind: "suite", only: ["MOD-Part-01"] },
|
||
},
|
||
{
|
||
id: "lesson-robot-layout",
|
||
groupId: "specialists",
|
||
title: "Robot · 布局压力测试",
|
||
level: "进阶",
|
||
durationMin: 1,
|
||
summary: "Robot 工作台的任务面板最高,历史上曾把 `.layout` 压成几百像素。探针会注入内容并验证舞台不位移。",
|
||
sees: ["aside-bounds 与 stage-stable 检查", "Robot 页面 `layout {y,h}` 实测值"],
|
||
expect: "全部检查 ok;失败说明又出现了布局回归。",
|
||
job: { kind: "probe", url: "/workbench.html?module=Robot" },
|
||
},
|
||
{
|
||
id: "lesson-crosscut-scroll",
|
||
groupId: "crosscut",
|
||
title: "交叉 · 左右面板独立滚动",
|
||
level: "进阶",
|
||
durationMin: 1,
|
||
summary: "X-panel-scroll 是布局契约的端到端用例:页面锁定、面板自己滚动、内容不互相挤压。",
|
||
sees: ["注入 2000px 内容后面板仍可滚动", "页面文档本身不滚动"],
|
||
expect: "用例 X-panel-scroll 通过(约 20–30 秒)。",
|
||
job: { kind: "suite", only: ["X-panel-scroll"] },
|
||
},
|
||
{
|
||
id: "lesson-crosscut-opfs",
|
||
groupId: "crosscut",
|
||
title: "交叉 · OPFS 保存与回开",
|
||
level: "进阶",
|
||
durationMin: 2,
|
||
summary: "文档保存到 OPFS 的 freecad-documents,再次打开后对象与属性一致。OPFS 是本项目唯一的数据落盘位置。",
|
||
sees: ["列表中新增 .FCStd", "回开后对象树与属性一致"],
|
||
expect: "X-opfs-roundtrip 与 X-save-reopen 均通过。",
|
||
job: { kind: "suite", only: ["X-opfs-roundtrip", "X-save-reopen"], screenshots: "all" },
|
||
},
|
||
{
|
||
id: "lesson-crosscut-export",
|
||
groupId: "crosscut",
|
||
title: "交叉 · 导出格式",
|
||
level: "进阶",
|
||
durationMin: 2,
|
||
summary: "STEP/BREP/IGES/STL/GLB 导出到 freecad-exports;导出是显式动作,页面不会自动下载。",
|
||
sees: ["每种格式生成非空文件", "错误恢复路径可用"],
|
||
expect: "X-export-formats 与 X-error-recovery 通过。",
|
||
job: { kind: "suite", only: ["X-export-formats", "X-error-recovery"] },
|
||
},
|
||
{
|
||
id: "lesson-practice",
|
||
groupId: "practice",
|
||
title: "自由练习 · 组一次自己的运行",
|
||
level: "入门",
|
||
durationMin: 5,
|
||
summary: "在课程目录内勾选用例,生成受约束的命令并运行。页面绝不接受原始字符串:每个 id 都会先对照用例目录校验。",
|
||
sees: ["所选 id 与白名单一致", "实时日志与判定按用例汇总"],
|
||
expect: "所选用例全部 passed;blocked 会被单独标为前置失败。",
|
||
job: { kind: "suite", selectable: true, maxCases: 8 },
|
||
notes: ["慢速与高亮只用于观察,会显著拉长运行时间。"],
|
||
},
|
||
];
|
||
|
||
function chapterLessons(catalog) {
|
||
return catalog.chapters.map((chapter) => {
|
||
const note = CHAPTER_NOTES[chapter.chapter] ?? { group: "specialists", blurb: chapter.title };
|
||
return {
|
||
id: `lesson-${chapter.id.toLowerCase()}`,
|
||
groupId: note.group,
|
||
title: `${chapter.id} · ${chapter.title}`,
|
||
level: "入门",
|
||
durationMin: 2,
|
||
summary: `${note.blurb} 本课运行手册场景 ${chapter.chapter}/${chapter.workflow},按真实操作脚本逐步执行并截图。`,
|
||
sees: ["有头浏览器逐步执行场景动作", "失败时保留每一步的实际值与截图"],
|
||
expect: `用例 ${chapter.id} 通过。`,
|
||
job: { kind: "suite", only: [chapter.id], slow: 120, highlight: true },
|
||
};
|
||
});
|
||
}
|
||
|
||
function moduleLessons(catalog) {
|
||
return catalog.modules.map((name) => ({
|
||
id: `lesson-module-${name.toLowerCase()}`,
|
||
groupId: groupForModule(name),
|
||
title: `${name} · 模块冒烟`,
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: `P2 模块冒烟:${name} 的壳体加载、命令面暴露与一条规范化 worker 命令。它证明模块能真正执行,而不只是页面挂载。`,
|
||
sees: ["MOD- 用例记录中出现该模块", "命令返回结构而非错误"],
|
||
expect: `用例 MOD-${name}-01 通过。`,
|
||
job: { kind: "suite", only: [`MOD-${name}-01`] },
|
||
}));
|
||
}
|
||
|
||
function groupForModule(name) {
|
||
const map = {
|
||
Part: "part",
|
||
PartDesign: "partdesign",
|
||
Sketcher: "sketcher",
|
||
Assembly: "assembly",
|
||
Mesh: "mesh",
|
||
MeshPart: "mesh",
|
||
BIM: "bim",
|
||
CAM: "cam",
|
||
Import: "io",
|
||
Spreadsheet: "data",
|
||
Measure: "data",
|
||
Inspection: "specialists",
|
||
TechDraw: "drawing",
|
||
Fem: "drawing",
|
||
};
|
||
return map[name] ?? "specialists";
|
||
}
|
||
|
||
function crosscutLessons(catalog) {
|
||
return catalog.crosscut
|
||
.filter((id) => !["X-panel-scroll", "X-opfs-roundtrip", "X-save-reopen", "X-export-formats", "X-error-recovery"].includes(id))
|
||
.map((id) => ({
|
||
id: `lesson-${id.toLowerCase()}`,
|
||
groupId: "crosscut",
|
||
title: `${id} · 视口与布局`,
|
||
level: "进阶",
|
||
durationMin: 1,
|
||
summary: "视口尺寸契约:不同窗口尺寸下三维视口不被面板挤出,Canvas 尺寸与容器一致。",
|
||
sees: ["视口与容器尺寸一致", "无滚动条挤压"],
|
||
expect: `用例 ${id} 通过。`,
|
||
job: { kind: "suite", only: [id] },
|
||
}));
|
||
}
|
||
|
||
function volumeText(volume) {
|
||
return volume == null ? "—" : `${Math.round(volume).toLocaleString("en-US")} mm³`;
|
||
}
|
||
|
||
/**
|
||
* The 20-part carrier curriculum, read from tools/carrier/catalog.mjs.
|
||
*
|
||
* Same shape as the reducer, with two differences that matter to a beginner:
|
||
* every part lives in one shared ship coordinate system (so each one is shown
|
||
* where it sits on the vessel), and the last lesson assembles all 20 into one
|
||
* document with 19 fixed joints.
|
||
*/
|
||
function carrierLessons() {
|
||
const parts = carrierParts();
|
||
const byGroup = new Map(carrierGroups().map((group) => [group.id, group.label]));
|
||
const intro = {
|
||
id: "lesson-carrier-environment",
|
||
groupId: "carrier",
|
||
title: "航母 · 工具与前置自检(不启动浏览器)",
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: "先确认 20 件零件的界面步骤、构建记录与源文档齐全,再谈重建。本课用 dry run 只做前置检查,不打开 Chrome。",
|
||
sees: ["零件清单、步数、记录体积与缺失项", "缺项时可直接执行的修复命令"],
|
||
expect: "前置全部满足;缺项判「前置失败」,不算产品失败。",
|
||
job: { kind: "carrier-part", partId: parts[0]?.id ?? "P01", dry: true },
|
||
};
|
||
const perPart = parts.map((part) => {
|
||
const system = byGroup.get(part.system) ?? part.systemLabel ?? part.system;
|
||
const features = part.featureTypes?.length ? `特征:${part.featureTypes.join("、")}。` : "";
|
||
return {
|
||
id: `lesson-carrier-${part.id.toLowerCase()}`,
|
||
groupId: "carrier",
|
||
title: `${part.id} · ${part.title}`,
|
||
level: part.steps <= 4 ? "入门" : "进阶",
|
||
durationMin: Math.max(3, Math.round(part.steps * 1.5) + 2),
|
||
summary: `在真实界面里重建 ${part.document}(${system}):共 ${part.steps} 步。${features}完成后界面算出的体积应与构建记录 ${volumeText(part.volume)} 一致。`,
|
||
sees: ["PartDesign 草图 → 特征 → 修整的逐步骤操作", "每步截图与最终体积对比"],
|
||
expect: `create-part ${part.id} 判 pass(体积相对误差在引擎容差内)。`,
|
||
job: { kind: "carrier-part", partId: part.id },
|
||
};
|
||
});
|
||
const assembly = {
|
||
id: "lesson-carrier-assembly",
|
||
groupId: "carrier",
|
||
title: "装配 · 20 件合成航空母舰",
|
||
level: "进阶",
|
||
durationMin: 20,
|
||
summary: "新建装配文档 CarrierAssembly,按舰体坐标系逐个插入 20 个零件链接,接地舰体,为其余 19 件各建一个固定关节再求解。",
|
||
sees: ["插入面板逐个装载源文档并保持统一位姿", "19 个固定关节与求解后的组件位形"],
|
||
expect: "create-assembly 判 pass:插入 20/20、关节 19/19、求解组件无畸形、无失配。",
|
||
job: { kind: "carrier-assembly" },
|
||
};
|
||
return [intro, ...perPart, assembly];
|
||
}
|
||
|
||
/** The 23-part reducer curriculum comes from the toolkit catalog, not a copy. */
|
||
function reducerLessons() {
|
||
const parts = reducerParts();
|
||
const byGroup = new Map(reducerGroups().map((group) => [group.id, group.label]));
|
||
const intro = [
|
||
{
|
||
id: "lesson-reducer-environment",
|
||
groupId: "reducer",
|
||
title: "减速器 · 环境自检(不启动浏览器)",
|
||
level: "入门",
|
||
durationMin: 1,
|
||
summary: "23 个零件都有界面步骤与构建记录,但先要确认 dist、内核、Chrome、DISPLAY 就绪。本课用 dry run 只做前置检查。",
|
||
sees: ["八项前置检查的真实结果", "提示缺失项可直接执行的修复命令"],
|
||
expect: "前置全部满足;缺项时判定为「前置失败」,不启动浏览器。",
|
||
job: { kind: "reducer-part", partId: parts[0]?.id ?? "P01", dry: true },
|
||
},
|
||
];
|
||
const perPart = parts.map((part) => ({
|
||
id: `lesson-reducer-${part.id.toLowerCase()}`,
|
||
groupId: "reducer",
|
||
title: `${part.id} · ${part.title}`,
|
||
level: part.steps <= 2 ? "入门" : "进阶",
|
||
durationMin: Math.max(2, part.steps + 2),
|
||
summary: `在真实界面里重建 ${part.document}(${byGroup.get(part.group) ?? part.group}):共 ${part.steps} 步,完成后界面算出的体积应与构建记录 ${volumeText(part.volume)} 一致。`,
|
||
sees: ["有头 Chrome 打开 PartDesign 页面并逐步点击", "每步一张截图,最终体积与记录对比"],
|
||
expect: `create-part ${part.id} 判 pass(体积相对误差在引擎容差内)。`,
|
||
job: { kind: "reducer-part", partId: part.id },
|
||
}));
|
||
const assembly = {
|
||
id: "lesson-reducer-assembly",
|
||
groupId: "reducer",
|
||
title: "装配 · 23 件合成二级减速器",
|
||
level: "进阶",
|
||
durationMin: 15,
|
||
summary: "新建装配文档,按构建记录的位置与旋转逐个插入链接并接地。装配的输入就是前面 23 节课建出来的零件数据。",
|
||
sees: ["装配文档中出现全部零件链接", "插入数量与期望一致、无失配"],
|
||
expect: "create-assembly 判 pass;失配或插入不全判产品失败。",
|
||
job: { kind: "reducer-assembly" },
|
||
};
|
||
return [...intro, ...perPart, assembly];
|
||
}
|
||
|
||
export function buildLessons(catalog) {
|
||
const lessons = [...CORE_LESSONS, ...reducerLessons(), ...carrierLessons(), ...chapterLessons(catalog), ...moduleLessons(catalog), ...crosscutLessons(catalog)];
|
||
const seen = new Set();
|
||
for (const lesson of lessons) {
|
||
if (seen.has(lesson.id)) throw new Error(`课程 id 重复:${lesson.id}`);
|
||
seen.add(lesson.id);
|
||
}
|
||
return { schema: "freecad-web/teaching-console-lessons/v1", groups: GROUPS, lessons };
|
||
}
|