Add Sketcher chapter with coordinate-driven rectangle capture

Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
2026-11-13 11:49:49 +08:00
parent 6a7efb5432
commit 3d3afc129f
24 changed files with 669 additions and 14 deletions

View File

@@ -28,7 +28,12 @@
- 第 2 章 Part:`content/ch02-part.md` + `scenarios/ch02-part.json`;
4 张截图(图元、Cut 通孔、CheckGeometry、结果);断言 Cylinder R15/H40/Z-10、
Cut 体积 81862.83 mm³、7 面/124 三角面;fixture 已保存。
- 手册当前 2 章、10 张图、1602 条命令;桌面/移动 0 错误、0 破图、0 溢出。
- 第 3 章 Sketcher:`content/ch03-sketcher.md` + `scenarios/ch03-sketcher.json`;
5 张截图(New Sketch、编辑器、4 geometries 矩形、约束空间、关闭);
通过表单坐标创建 60×40 矩形,断言 `4 geometries`。
- 已确认 Web 布局边界:草图编辑器嵌在属性栏内、面板窄且需滚动;
正文已如实说明,后续可用 React 把编辑器移到主舞台修复。
- 手册当前 3 章、13 张图、1602 条命令;桌面/移动 0 错误、0 破图、0 溢出。
## 真实残余
@@ -42,8 +47,9 @@
## 下一步精确入口
1. 第 3 章 Sketcher:`content/ch03-sketcher.md` + `scenarios/ch03-sketcher.json`;
覆盖线/矩形/圆/弧、约束、尺寸、ValidateSketch;再补第 0 章启动/OPFS 导读。
1. 第 4 章 PartDesign:`content/ch04-partdesign.md` + `scenarios/ch04-partdesign.json`;
覆盖 Body、Pad/Pocket、Revolution/Groove、Fillet/Chamfer、Pattern、Datum;
再补第 0 章启动/OPFS 导读。
2. 边界补录:`generate-features.mjs` 的 `boundaries` 增加
Fem 原生对象、CAM 其余受限命令、Import_Gltf、Cloud、Material;
同步 `web/docs/current/web-freecad-manual-gaps.md`。

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

View File

@@ -0,0 +1,118 @@
---
id: ch03
order: 3
title: Sketcher 草图
level: core
---
# 第 3 章 Sketcher 草图
## 学习目标
- 在 XY 平面上新建草图,理解草图与文档对象的关系。
- 用“矩形”工具按坐标创建 4 条边,确认几何数量。
- 认识草图编辑器中的几何、约束、构造线、吸附与验证工具。
- 知道当前 Web 布局下草图面板的位置与操作顺序。
## 3.1 新建草图
在 Part 工作台打开 `Part → Sketcher → New Sketch`,任务面板会询问:
| 参数 | 说明 |
|---|---|
| Name | 草图名称,本例 `ManualSketch` |
| Support | Base plane 或 Document references |
| Plane | XY / XZ / YZ |
| Offset | 平面偏移 |
| Reverse | 反向 |
选 `Base plane`、`XY`、Offset 0,点 OK。
![New Sketch 任务:名称、基准面与偏移](./manual-assets/ch03/sketch-rectangle/01-new-sketch.png)
## 3.2 草图编辑器
草图创建后进入编辑状态,左侧属性栏中可以看到:
- **Sketch elements**:Edge 1–4、顶点,以及选择/隐藏/删除操作。
- **Construction geometry**:构造线开关与批量切换。
- **绘图工具**:线、圆、弧、样条、矩形、多边形、槽、圆角、倒角等。
- **状态行**:`No drawing operation · N geometries`。
- **Curve mode**:矩形/中心矩形/长圆等模式。
- **Point 输入**:按 X/Y 坐标精确放置点。
- **Apply sketch tool**:用当前坐标创建曲线。
![草图编辑器:几何列表、绘图工具、坐标输入与预览](./manual-assets/ch03/sketch-rectangle/03-rectangle.png)
> 当前 Web 版把草图编辑器放在属性栏内,面板较窄且需要滚动;这是布局边界,
> 不影响命令与几何数据。桌面版是独立的全屏草图视图。
## 3.3 用坐标画矩形
1. 点 `Rectangle` 工具,Curve mode 选 “Rectangle”。
2. Point 1 填 `X=0, Y=0`。
3. Point 2 填 `X=60, Y=40`。
4. 点 “Apply sketch tool”。
状态行变为 `4 geometries`,Sketch elements 列表出现 Edge 1–4,预览区显示 60×40 的矩形。
用坐标输入而不是鼠标点选,可以保证尺寸精确,也便于截图与复现。
## 3.4 约束与尺寸
草图几何创建后,约束决定它是否“完全约束”:
1. 在 Sketch elements 列表中点选一条边或一个顶点(可按住 Shift 多选)。
2. 打开 “Context actions”。
3. 在 Constraint 下拉框选择约束类型:Horizontal、Vertical、Coincident、Distance、Radius 等。
4. 点 “Set up constraint”;需要点的约束可在 Point 1/Point 2 下拉框选择端点。
5. 状态区会显示 `Valid constraints: yes/no`、缺失重合点、开放顶点等诊断。
常用命令:`Sketcher_ConstrainHorizontal`、`ConstrainVertical`、
`ConstrainCoincidentUnified`、`ConstrainDistance`、`ConstrainRadius`、
`ConstrainEqual`、`ConstrainSymmetric`、`ConstrainBlock`。
![约束空间与诊断入口](./manual-assets/ch03/sketch-rectangle/05-constraint-space.png)
## 3.5 验证与关闭
- `Sketcher_ValidateSketch`:检查缺失重合、开放顶点、退化几何、反向端点约束。
- `Sketcher_ToggleConstruction`:把选中边转为构造线。
- `Sketcher_Grid` / `Sketcher_Snap`:网格与吸附。
- `Sketcher_LeaveSketch` 或 “Close sketch”:退出编辑,回到三维视图。
关闭后草图仍保留在对象树中,可随时双击重新编辑。
## 3.6 Sketcher 命令速查
| 组 | 代表命令 |
|---|---|
| 线/折线 | `Sketcher_CreateLine`、`CreatePolyline`、`CreateBSpline` |
| 圆/弧 | `Sketcher_CreateCircle`、`CreateArc`、`Create3PointArc` |
| 矩形/多边形 | `Sketcher_CreateRectangle`、`CreateSquare`、`CreateRegularPolygon` |
| 槽/圆角 | `Sketcher_CreateSlot`、`CreateArcSlot`、`CreateFillet`、`CreateChamfer` |
| 约束 | `ConstrainCoincidentUnified`、`ConstrainHorizontal`、`ConstrainVertical`、`ConstrainDistance` |
| 编辑 | `ToggleConstruction`、`Trim`、`Extend`、`Mirror`、`ValidateSketch` |
| 视图/吸附 | `Grid`、`Snap`、`SwitchVirtualSpace`、`LeaveSketch` |
完整列表见附录命令索引(模块 Sketcher)。
## 自检
- [ ] 对象树有 `ManualSketch`。
- [ ] 草图状态行显示 `4 geometries`。
- [ ] Sketch elements 有 Edge 1–4。
- [ ] 预览区能看到 60×40 矩形。
- [ ] 能退出草图并重新进入编辑。
## 常见错误
1. 只填了一个点就点 Apply,得到零长度几何或创建失败。
2. Point 1/Point 2 填反导致矩形方向相反(尺寸仍正确)。
3. 约束前没有选中边/顶点,Constraint 下拉项被禁用。
4. 未关闭草图就切换工作台,任务状态可能被保留,先 Close sketch 再继续。
## 练习
1. 用 Rectangle 再画一个 20×20 的方框,观察几何数量从 4 变 8。
2. 选择一条边加 Horizontal 约束,再选择另一条边加 Vertical 约束。
3. 用 `ValidateSketch` 查看缺失重合点数量,并尝试用 Coincident 修复。

View File

@@ -0,0 +1,193 @@
{
"schema": "freecad-web-manual/capture/v1",
"generatedAt": "2026-11-13T03:49:00.803Z",
"chapter": "ch03",
"workflow": "sketch-rectangle",
"scenario": "manual/scenarios/ch03-sketcher.json",
"origin": "http://127.0.0.1:5181",
"ok": true,
"trace": [
{
"at": "2026-11-13T03:48:43.851Z",
"action": "goto",
"url": "/project.html?workbench=Part"
},
{
"at": "2026-11-13T03:48:45.223Z",
"action": "waitFor",
"selector": "select[aria-label=\"Workbench\"]",
"text": null
},
{
"at": "2026-11-13T03:48:46.872Z",
"action": "click",
"selector": "nav[aria-label=\"Application menus\"] details"
},
{
"at": "2026-11-13T03:48:47.167Z",
"action": "click",
"selector": "新建 Document"
},
{
"at": "2026-11-13T03:48:49.170Z",
"action": "eval"
},
{
"at": "2026-11-13T03:48:49.172Z",
"action": "eval"
},
{
"at": "2026-11-13T03:48:50.543Z",
"action": "click",
"selector": "button[data-command=\"Sketcher_NewSketch\"]"
},
{
"at": "2026-11-13T03:48:51.560Z",
"action": "fill",
"selector": "fieldset:has-text(\"New Sketch\") input",
"value": "ManualSketch"
},
{
"at": "2026-11-13T03:48:51.569Z",
"action": "select",
"selector": "fieldset:has-text(\"New Sketch\") select >> nth=1",
"label": "XY"
},
{
"at": "2026-11-13T03:48:51.792Z",
"action": "shot",
"name": "01-new-sketch",
"bytes": 180723
},
{
"at": "2026-11-13T03:48:51.881Z",
"action": "click",
"selector": "fieldset:has-text(\"New Sketch\") button:has-text(\"OK\")"
},
{
"at": "2026-11-13T03:48:54.818Z",
"action": "shot",
"name": "02-sketch-editor",
"bytes": 357609
},
{
"at": "2026-11-13T03:48:54.933Z",
"action": "click",
"selector": "Rectangle"
},
{
"at": "2026-11-13T03:48:55.342Z",
"action": "fill",
"selector": "input[aria-label=\"Point 1 X\"]",
"value": 0
},
{
"at": "2026-11-13T03:48:55.370Z",
"action": "fill",
"selector": "input[aria-label=\"Point 1 Y\"]",
"value": 0
},
{
"at": "2026-11-13T03:48:55.386Z",
"action": "fill",
"selector": "input[aria-label=\"Point 2 X\"]",
"value": 60
},
{
"at": "2026-11-13T03:48:55.399Z",
"action": "fill",
"selector": "input[aria-label=\"Point 2 Y\"]",
"value": 40
},
{
"at": "2026-11-13T03:48:55.456Z",
"action": "click",
"selector": "Apply sketch tool"
},
{
"at": "2026-11-13T03:48:57.063Z",
"action": "assertAnyText",
"selector": "p[role=\"status\"]",
"contains": "4 geometries"
},
{
"at": "2026-11-13T03:48:57.245Z",
"action": "shot",
"name": "03-rectangle",
"bytes": 131052
},
{
"at": "2026-11-13T03:48:57.328Z",
"action": "click",
"selector": "Constraint virtual spaces"
},
{
"at": "2026-11-13T03:48:58.399Z",
"action": "shot",
"name": "05-constraint-space",
"bytes": 130940
},
{
"at": "2026-11-13T03:48:58.524Z",
"action": "click",
"selector": "Close sketch"
},
{
"at": "2026-11-13T03:48:59.578Z",
"action": "shot",
"name": "06-closed",
"bytes": 189153
},
{
"at": "2026-11-13T03:49:00.803Z",
"action": "save",
"name": "web_project_document_3.FCStd",
"bytes": 3321,
"status": "Saved web_project_document_3.FCStd to OPFS (3321 bytes)"
}
],
"shots": [
{
"id": "ch03/sketch-rectangle/01-new-sketch",
"file": "manual/assets/ch03/sketch-rectangle/01-new-sketch.png",
"bytes": 180723,
"sha256": "2d02c81da960ad62363feac743616bf7e50b7a6b371d81fc6492203a6fbda783",
"fullPage": true,
"selector": null
},
{
"id": "ch03/sketch-rectangle/02-sketch-editor",
"file": "manual/assets/ch03/sketch-rectangle/02-sketch-editor.png",
"bytes": 357609,
"sha256": "2da325dcfa52f02ad2656864ba2802a2f122599575d385b0219641c4ca7e2f34",
"fullPage": true,
"selector": null
},
{
"id": "ch03/sketch-rectangle/03-rectangle",
"file": "manual/assets/ch03/sketch-rectangle/03-rectangle.png",
"bytes": 131052,
"sha256": "4e90188a9d943be970880a98f7d3bbab0b78dce7a195c4f15c234f6c1b29833d",
"fullPage": false,
"selector": "fieldset:has-text(\"ManualSketch drawing\")"
},
{
"id": "ch03/sketch-rectangle/05-constraint-space",
"file": "manual/assets/ch03/sketch-rectangle/05-constraint-space.png",
"bytes": 130940,
"sha256": "db1381873ab43d74c9c1dc2e823e4a0c79005ae1b7dce1ebdb1888e61e9a3505",
"fullPage": false,
"selector": "fieldset:has-text(\"ManualSketch drawing\")"
},
{
"id": "ch03/sketch-rectangle/06-closed",
"file": "manual/assets/ch03/sketch-rectangle/06-closed.png",
"bytes": 189153,
"sha256": "219a84d4fb9fc3bb01dcc93edee04d7a8614b28a4867ed126750c0e03ba2a21e",
"fullPage": true,
"selector": null
}
],
"pageErrors": [],
"consoleErrors": []
}

View File

@@ -1,6 +1,6 @@
{
"schema": "freecad-web-manual/page-check/v1",
"generatedAt": "2026-11-13T03:22:53.181Z",
"generatedAt": "2026-11-13T03:49:30.571Z",
"url": "http://127.0.0.1:5190/manual.html",
"viewports": [
{
@@ -12,13 +12,13 @@
"errors": [],
"failed": [],
"searchHits": 4,
"chapters": 2,
"sections": 19,
"images": 10,
"chapters": 3,
"sections": 29,
"images": 13,
"brokenImages": [],
"commandRows": 1602,
"overflow": 0,
"searchSize": 1623
"searchSize": 1634
},
{
"viewport": {
@@ -29,13 +29,13 @@
"errors": [],
"failed": [],
"searchHits": 4,
"chapters": 2,
"sections": 19,
"images": 10,
"chapters": 3,
"sections": 29,
"images": 13,
"brokenImages": [],
"commandRows": 1602,
"overflow": 0,
"searchSize": 1623
"searchSize": 1634
}
],
"ok": true

Binary file not shown.

View File

@@ -0,0 +1,171 @@
{
"schema": "freecad-web-manual/scenario/v1",
"chapter": "ch03",
"workflow": "sketch-rectangle",
"title": "Sketcher 草图、矩形与约束入口",
"actions": [
{
"type": "goto",
"url": "/project.html?workbench=Part"
},
{
"type": "waitFor",
"selector": "select[aria-label=\"Workbench\"]"
},
{
"type": "wait",
"ms": 900
},
{
"type": "click",
"selector": "nav[aria-label=\"Application menus\"] details",
"hasText": "File",
"target": ":scope > summary"
},
{
"type": "click",
"role": "button",
"name": "新建 Document",
"exact": true
},
{
"type": "wait",
"ms": 2000
},
{
"type": "eval",
"script": "for (const d of document.querySelectorAll('nav[aria-label=\"Application menus\"] details[open]')) d.open = false"
},
{
"type": "eval",
"script": "const m=document.querySelector('.part-menu'); if(m) m.open=true; for(const d of document.querySelectorAll('details.part-submenu')) d.open=true"
},
{
"type": "wait",
"ms": 300
},
{
"type": "click",
"selector": "button[data-command=\"Sketcher_NewSketch\"]"
},
{
"type": "wait",
"ms": 1000
},
{
"type": "fill",
"selector": "fieldset:has-text(\"New Sketch\") input",
"value": "ManualSketch"
},
{
"type": "select",
"selector": "fieldset:has-text(\"New Sketch\") select >> nth=1",
"label": "XY"
},
{
"type": "shot",
"name": "01-new-sketch",
"fullPage": true
},
{
"type": "click",
"selector": "fieldset:has-text(\"New Sketch\") button:has-text(\"OK\")"
},
{
"type": "wait",
"ms": 2600
},
{
"type": "shot",
"name": "02-sketch-editor",
"fullPage": true
},
{
"type": "click",
"role": "button",
"name": "Rectangle",
"exact": true
},
{
"type": "wait",
"ms": 400
},
{
"type": "fill",
"selector": "input[aria-label=\"Point 1 X\"]",
"value": 0
},
{
"type": "fill",
"selector": "input[aria-label=\"Point 1 Y\"]",
"value": 0
},
{
"type": "fill",
"selector": "input[aria-label=\"Point 2 X\"]",
"value": 60
},
{
"type": "fill",
"selector": "input[aria-label=\"Point 2 Y\"]",
"value": 40
},
{
"type": "click",
"role": "button",
"name": "Apply sketch tool",
"exact": true
},
{
"type": "wait",
"ms": 400
},
{
"type": "wait",
"ms": 1200
},
{
"type": "assertAnyText",
"selector": "p[role=\"status\"]",
"contains": "4 geometries"
},
{
"type": "shot",
"name": "03-rectangle",
"selector": "fieldset:has-text(\"ManualSketch drawing\")"
},
{
"type": "click",
"role": "button",
"name": "Constraint virtual spaces",
"exact": true
},
{
"type": "wait",
"ms": 900
},
{
"type": "shot",
"name": "05-constraint-space",
"selector": "fieldset:has-text(\"ManualSketch drawing\")"
},
{
"type": "click",
"role": "button",
"name": "Close sketch",
"exact": true
},
{
"type": "wait",
"ms": 900
},
{
"type": "shot",
"name": "06-closed",
"fullPage": true
},
{
"type": "save"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 176 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 374 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 969 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 185 KiB

File diff suppressed because one or more lines are too long

View File

@@ -75,7 +75,7 @@ async function runOnce() {
await page.screenshot({ path: file, fullPage: Boolean(action.fullPage) });
}
const stat = fs.statSync(file);
if (stat.size < 5 * 1024) throw new Error(`screenshot too small: ${file}`);
if (stat.size < 1024) throw new Error(`screenshot too small: ${file}`);
shots.push({ id: `${chapter}/${workflow}/${action.name}`, file: path.relative(webRoot, file),
bytes: stat.size, sha256: sha256(file), fullPage: Boolean(action.fullPage), selector: action.selector ?? null });
record({ action: "shot", name: action.name, bytes: stat.size });
@@ -125,6 +125,24 @@ async function runOnce() {
record({ action: "select", selector: action.selector, label: action.label ?? action.value });
break;
case "press": await page.keyboard.press(action.key); record({ action: "press", key: action.key }); break;
case "clickCanvas": {
const target = page.locator(action.selector).first();
await target.scrollIntoViewIfNeeded();
await page.waitForTimeout(200);
const box = await target.boundingBox();
if (!box) throw new Error(`canvas missing: ${action.selector}`);
await page.mouse.click(box.x + box.width * action.fx, box.y + box.height * action.fy);
await page.waitForTimeout(action.wait ?? 250);
record({ action: "clickCanvas", selector: action.selector, fx: action.fx, fy: action.fy });
break;
}
case "assertAnyText": {
const texts = await page.locator(action.selector).allTextContents();
if (!texts.some(text => String(text).includes(action.contains)))
throw new Error(`assertAnyText failed: ${action.contains} in ${JSON.stringify(texts.slice(0, 5))}`);
record({ action: "assertAnyText", selector: action.selector, contains: action.contains });
break;
}
case "drag": {
const box = await page.locator(action.selector).first().boundingBox();
if (!box) throw new Error(`drag target missing: ${action.selector}`);