Files
FreeCADWasmDev/tools/fcweb/README.md
wangdequan 300c8efb01 docs(web): full UI surface inventory, illustrated manual, panel screenshots
Interface design document and manual now share one authoritative surface
inventory (333 surfaces across 9 categories, gap 0), and every chapter carries
real Playwright screenshots of the panels it documents.

- tools/fcweb: ui-surface-scan/ui-surface-inventory (deterministic --check),
  build-ui-doc renders panel catalog, workbench matrix and mapping tables;
  blank toolbar crops (<1 KB) are skipped and pruned instead of embedded
- web/tools/manual: generate-panel-index (ch16), audit-ui-gaps,
  generate-final-status, generate-gaps-doc; pager is per-chapter so the manual
  no longer overflows horizontally
- manual: 130 screenshot references / 128 PNGs, panel sections for ch02-ch13
- web/src: utility menus stop click propagation (menu reopened on item click);
  workbench shell gains an OPFS document picker so workbench.html can bind a
  real document instead of the fixed workbench-document id; Sketcher panel
  moves from the command column to the main stage

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-23 01:30:31 +08:00

126 lines
4.9 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# fcweb — 建零件与装配的通用工具库
把二级减速器教程里反复出现的建零件、建装配机制收成一层可复用的内核客户端。
不依赖任何案例目录,自带自检门。
```js
import { openPart, openPartDesign, openAssembly } from "<repo>/tools/fcweb/index.mjs";
```
完整中文指南:`web/teaching/fcweb-toolkit.html`
## 目录
| 文件 | 作用 |
| --- | --- |
| `index.mjs` | 统一出口;含旧接口适配器 `openPartLegacy` |
| `kernel.mjs` | 唯一的 `ccall` 触点:探针定位、会话、trace |
| `part.mjs` | `part.document` — 图元、布尔、定位、导入导出 |
| `partdesign.mjs` | `partdesign.document` — Body、草图、Pad/Pocket、齿轮 |
| `assembly.mjs` | `assembly.*` — 装配对象、原生插入链接、求解 |
| `opfs.mjs` | OPFS 契约(目录 `freecad-exports`,根可配置) |
| `capture.mjs` | Chromium 启动、截图、页面健康检查 |
| `selftest.mjs` | 内核自检门,32 项,无浏览器无 fixture |
| `ui-inventory.mjs` | UI 静态清单:工作台、菜单、工具栏、任务面板、命令矩阵 |
| `ui-capture.mjs` | 逐工作台驱动外壳并截图 |
| `build-ui-doc.mjs` | 由清单与截图汇编 UI 设计文档 |
## 探针
| 命令族 | 探针产物 |
| --- | --- |
| `part.document` | `FreeCADWebDocumentProbe` |
| `partdesign.document` | `FreeCADWebPartDesignRuntimeProbe` |
| `assembly.*` | `FreeCADWebAssemblyProbe` |
第三个的名字和源码文件名(`AssemblyRuntimeProbe.cpp`)不一致——源码里
`AssemblyRuntimeProbe.cpp:642` 定义命令,但 `CMakeLists.txt:798` 把它编进
`FreeCADWebAssemblyProbe`。
探针优先从 `web/public/kernel` 取,其次 `web/dist/kernel`。两处产物不一致时打警告。
## 快速例子
```js
import { openPart, openPartDesign, openAssembly, storeRoot } from "./index.mjs";
// 零件
const part = await openPart("Block");
try {
part.create();
part.box("Base", { length: 40, width: 30, height: 10 });
part.primitive("Bore", { kind: "Cylinder",
parameters: { Radius: 5, Height: 30, Angle: 360, FirstAngle: 0, SecondAngle: 0 },
placement: { position: [20, 15, -10] } });
part.cut({ object: "Bored", base: "Base", tool: "Bore" });
part.saveDocument();
} finally {
try { part.close(); } catch {}
part.dispose();
}
// 装配
const asm = await openAssembly({ document: "Asm", label: "总装" });
try {
asm.create();
asm.insertLinks([{ file: `${storeRoot()}/Block.FCStd`,
sourceDocument: "Block", sourceObject: "Base", position: [0, 0, 0] }]);
asm.solve();
} finally {
asm.dispose();
}
```
## 契约要点
- **图元参数键不同**:Part 用 `primitive`,PartDesign 用 `primitiveType`;
Part 位置用 `primitivePlacement`,PartDesign 用 `position: [x,y,z]`。
- **`volume` 可为 `null`**:草图、基准、2D 齿轮轮廓没有体积。
- **编辑动作回复不带几何**:`volumeOf` / `objectOf` 内部走 `snapshot`。
- **内核 `/tmp` 是 MEMFS**:导出暂存与读取都用 `part.kernel.FS`。
- **`close()` ≠ `dispose()`**:前者关文档,后者终止 pthread 池;后者必须调用,
否则 Node 不退出;且不可在会话中途调用。
## UI 设计文档管线
三个工具把「界面清单 → 实拍截图 → HTML 文档」串起来:
```bash
# 1. 静态清单(无浏览器):31 模块 / 746 命令元数据 / 144 任务面板 / 1492 条矩阵
node tools/fcweb/ui-inventory.mjs
# 2. 逐工作台截图(需先启动应用:web/ 下 npx vite preview --port 5182)
node tools/fcweb/ui-capture.mjs --all
node tools/fcweb/ui-capture.mjs --only Part,Fem --headed # 单个排查
# 3. 汇编文档
node tools/fcweb/build-ui-doc.mjs # 生成 docs/current/web-freecad-ui-layout-and-functions.html
node tools/fcweb/build-ui-doc.mjs --check # 幂等性检查
```
- 工作台状态(可渲染 / 回退 / 不可达 / 需前置条件)由 `docs/current/ui-design/data/workbench-overrides.json` 统一维护;矩阵里出现的 OpenSCAD 命令一律排除。
- 手写正文章节在 `docs/current/ui-design/source.html`,构建只替换三个占位符,重复构建字节一致。
- 校验:`node web/tools/manual/check-ui-design-doc.mjs`(两个视口、零溢出、零断图、零重复 id、附录行数匹配)。
## 自检
```bash
node tools/fcweb/selftest.mjs
node tools/fcweb/selftest.mjs --json tools/fcweb/out/selftest.json
```
失败即非零退出,报告写到 `tools/fcweb/out/selftest.json`。
## 迁移既有案例
旧案例用的是 `web/teaching/cases/secondary-reducer-pro/parts/buildPart.mjs` 的
`openPart(document, {snapshots})`,返回 `{document, kernel, call, timed, timings, trace}`。
本库的 `openPartLegacy(document, options)` 返回同样的形状:
```diff
- import { openPart } from "./buildPart.mjs";
+ import { openPartLegacy as openPart } from "<repo>/tools/fcweb/index.mjs";
```
现有案例脚本**未**改动;迁移是逐案决定的事。