tools/epro2/kicad: PCB Phase-2 — POUR → (zone), CoreBoard unconnected -43%

Phase-1 left 75-358 unconnected_items per board (DRC), dominated by
GND/AGND/POWER nets that EPRO2 routes through copper pour, not discrete
traces. Phase-2 lands those:

  - pcb_writer._decode_zone_path handles the three POUR.path encodings
    seen in ESP-VoCat: rectangle (['R', x, y, w, h, ...]), circle
    (['CIRCLE', cx, cy, r]) approximated as a 36-segment polygon, and
    polyline (numeric pairs with 'L'/'ARC' verb tokens).
  - Each POUR on a copper layer turns into a (zone (polygon ...) ...)
    block plus a (filled_polygon ...) that mirrors the boundary.

Why mirror, not auto-fill: kicad-cli pcb drc does NOT run the zone
filler before checking — only the KiCad GUI does. Without a
pre-computed (filled_polygon ...), DRC sees zones as empty regions and
reports the entire net as unconnected. Mirroring the boundary as the
fill is "connectivity-correct, clearance-imprecise" — KiCad users can
still hit Edit > Fill Zones to refine thermals and pad clearances. We
chose this over reading EPRO2's POURED.pourFill (the editor's own
post-fill polygons) because POURED paths use ARC tokens we'd need to
fully decode, and the user-drawn POUR boundary is already the
authoritative "intended copper" region.

ESP-VoCat DRC totals: 883 → 730 unconnected_items (-17% project-wide).
CoreBoard, the 4-layer board with the most pour coverage, drops 358 →
205 (-43%). Other boards see no movement because their unconnected
items are non-pour issues — pads outside the user-drawn POUR
rectangle, or internal $1N nets via vias on the wrong net (separate
problem, separate fix).

65 → 68 unit tests pass.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-29 00:27:33 +08:00
parent eee1a9b97e
commit adc5dc5e1b
4 changed files with 245 additions and 1 deletions

60
log.md
View File

@@ -4,6 +4,66 @@
---
## 2026-04-29 02:00 PCB Phase-2POUR → KiCad zoneCoreBoard unconnected -43%
**Claude 会话**
`e614044`。Phase-1 PCB 6 板都解析了但 DRC 报很多 unconnected——大头是 GND/AGND 走 POUR 覆铜没导出来。补 zone 导出。
### 做的
`pcb_writer.py``_decode_zone_path` 处理 EPRO2 POUR.path 三种形态:
- `[['R', x, y, w, h, ...]]` — 矩形实测最常见CoreBoard/MicBoard 全是这个)
- `[['CIRCLE', cx, cy, r]]` — 圆形(按 36 段近似成 polygon
- `[[x1, y1, 'L', x2, y2, ...]]` — polylineARC token 跳过 4 个 token按弦近似
每个 POUR 输出 `(zone (net N) (net_name "..." ) (layer "F.Cu") (polygon (pts ...)) (filled_polygon (pts ...)))`
### 关键坑:必须 emit `(filled_polygon)` 块
第一次只发 `(zone)``(polygon)` 边界的版本DRC 完全不变——`kicad-cli pcb drc` **不**自动跑 zone fill只有 GUI 的"填充覆铜"会跑。所以 file 必须自己声明已填充。简单做法:用 boundary polygon 当 filled_polygon= "整个 pour 区域都是铜",忽略 pad clearance/thermal
### ESP-VoCat 6 板 DRC 对比unconnected_items count
| 板 | before zones | after zones | Δ |
|---|---:|---:|---:|
| BaseBoard | 227 | 227 | 0 |
| CoreBoard | 358 | **205** | **-43%** |
| MicBoard | 75 | 75 | 0 |
| LCD-BD | 43 | 43 | 0 |
| Mainboard | 179 | 179 | 0 |
| Sub-board | 1 | 1 | 0 |
| **TOTAL** | **883** | **730** | **-17%** |
### 为什么只 CoreBoard 改善明显
抽样 MicBoard 残留 75 unconnected
- AGND 94 个 item 里很多 pad 在 zone boundary 之外——POUR 矩形是 (72.3, 112.3)→(126.8, 126.0),但 AGND pad 在 y=107 上方
- 大量 `$1N1865` 这种内部网——根因是 via 没绑对网(不是 POUR 能解决的)
EPRO2 用户画 POUR 时通常只覆元件密集区,不覆全板;外围 trace 自己接。zone 解决"靠 pour 接到 GND"的 pad但解不了"trace 路由不通"或"via 网漂移"。
CoreBoard zones=74-layerGND+POWER+AGND 各一对),覆盖面广,效果明显。其它板 zones 多是 2 个,覆盖小。
### 决策Why
- **filled_polygon = boundary 不做 clearance/thermal 计算**:自己实现 zone fill 算法工作量爆炸KiCad 实现是 C++ 几千行。boundary fill 是"连通性正确clearance 不精确"——KiCad GUI 一键 refill 即可矫正。这条路保留 EPRO2 user-drawn boundary 作为 single source of truth。
- **不读 POURED.pourFill**POURED 是 EPRO2 自己 fill 算法的输出path 含 ARC 难解析、坐标系跟 POUR 不一定对齐。boundary 直接用更可靠。
- **ARC 在 polyline 里按弦近似**:跟 Phase-1 ARC 处理一致KiCad 解析得了,几何稍偏(不会比 POUR 不导更糟)。
- **不强行优化 MicBoard 那种 zone 之外的 pad**:那是 EPRO2 source 本身的连通方式trace + via不是 zone 能修的。
### 测试
65 → 68 单测全过rectangle path → 4 corners + filled_polygon mirror / circle → 36-seg polygon / 非 copper layer skip。
### 下一步建议
- **ARC 圆心反推**(中等工作量):消 invalid_outline 警告 + zone polyline 里 ARC 段更准。需要三点定圆。
- **schematic + PCB 同时跑**小工作量CLI 加 `--all` 同时输出两套,目录配对。
- **`.kicad_pro` 项目文件**(小工作量):双击就能打开 KiCad GUIschematic 和 PCB 自动配对。
---
## 2026-04-29 01:30 KiCad 导出 Phase 3 PCB6/6 .kicad_pcb 全部 kicad-cli 通过
**Claude 会话**