tools/epro2/kicad: --all emits paired .kicad_pro + .kicad_sch + .kicad_pcb per BOARD
KiCad pairs project files purely by basename + same directory: a folder
holding `Foo.kicad_pro`, `Foo.kicad_sch`, `Foo.kicad_pcb` opens as one
project on double-click of the .kicad_pro, with cross-tool navigation
(open footprint from schematic etc) wired up automatically.
- pro_writer.write_kicad_pro() renders the minimal KiCad 8 JSON we
need: meta.filename pinning the basename, sheets=[[<root_uuid>,
""]] binding the schematic root, and stub blocks for board /
schematic / net_settings / erc that KiCad expects to find on the
first GUI load.
- root_sch_writer.write_root_sheet() now accepts an optional
root_uuid so the caller can pass the same uuid into the .kicad_pro
and .kicad_sch (the binding fails silently with mismatched ids).
- CLI gains `--all`: groups SCH/PCB docs by their META.board uuid
(1:1 in EPRO2), strips SCH-/PCB- editor prefixes from titles to
derive a shared project basename, and emits one directory per
BOARD with paired files. BOARDs whose SCH is DELETE_DOC (LCD-BD on
ESP-VoCat) still get a .kicad_pro with sheets:[] + .kicad_pcb so
pcbnew opens cleanly.
ESP-VoCat smoke: 6 boards → 6 project dirs, all pairs validated by
kicad-cli sch erc / pcb export svg. The CoreBoard pro/sch/pcb trio
shares root uuid 366d3e53...c2fccbe4330b end-to-end.
68 → 71 unit tests pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
78
log.md
78
log.md
@@ -4,6 +4,84 @@
|
||||
|
||||
---
|
||||
|
||||
## 2026-04-29 02:30 KiCad 工程文件 + `--all` 一键导:双击 .kicad_pro 打开 GUI
|
||||
|
||||
**Claude 会话**
|
||||
|
||||
接 `adc5dc5`。两件小事一起做:发 `.kicad_pro` + CLI 加 `--all`。目标是让消费者(咱们的 ML 训练代码 / 下游同学)双击就能在 KiCad GUI 里同时打开 schematic + PCB 配对。
|
||||
|
||||
### 1. `tools/epro2/kicad/pro_writer.py`
|
||||
|
||||
KiCad 8 的 .kicad_pro 是 JSON。最小可用集:
|
||||
```json
|
||||
{
|
||||
"meta": {"filename": "<basename>.kicad_pro", "version": 1},
|
||||
"sheets": [["<root_sheet_uuid>", ""]], // 绑 schematic 根 sheet
|
||||
"board": {...}, "schematic": {...}, "net_settings": {...}, ...
|
||||
}
|
||||
```
|
||||
|
||||
只要 .kicad_pro / .kicad_sch / .kicad_pcb **三个文件同名同目录**,KiCad 自动配对——双击 .kicad_pro 同时弹两个编辑器。`sheets` 数组里的 uuid 必须和 .kicad_sch 的 `(uuid ...)` 对得上,所以 `write_root_sheet` 加了 `root_uuid` 参数让调用方注入确定值。
|
||||
|
||||
### 2. CLI `--all`
|
||||
|
||||
按 BOARD uuid 分组 SCH 和 PCB(两边的 META 都带 `board: <uuid>`,自动 1:1 对应),每个 BOARD 一个目录:
|
||||
|
||||
```
|
||||
out/
|
||||
├── EchoEar-BaseBoard-V1_0/
|
||||
│ ├── EchoEar-BaseBoard-V1_0.kicad_pro
|
||||
│ ├── EchoEar-BaseBoard-V1_0.kicad_sch (root)
|
||||
│ ├── EchoEar-BaseBoard-V1_0.kicad_pcb
|
||||
│ └── P1_45092758.kicad_sch (子页)
|
||||
├── EchoEar-CoreBoard-V1_0/
|
||||
│ ├── EchoEar-CoreBoard-V1_0.kicad_pro
|
||||
│ ├── EchoEar-CoreBoard-V1_0.kicad_sch
|
||||
│ ├── EchoEar-CoreBoard-V1_0.kicad_pcb
|
||||
│ ├── Overview_dc13d6d2.kicad_sch (4 个子页)
|
||||
│ ├── MCU_510cff33.kicad_sch
|
||||
│ ├── Interface_b336a7c7.kicad_sch
|
||||
│ └── codec_0b0163fa.kicad_sch
|
||||
... (5 boards total)
|
||||
```
|
||||
|
||||
basename 从 SCH/PCB title 剥掉 `SCH-`/`PCB-` 前缀(`SCH-EchoEar-CoreBoard-V1_0` → `EchoEar-CoreBoard-V1_0`),schematic 和 PCB 自然 collapse 到一个项目。
|
||||
|
||||
### ESP-VoCat 实测
|
||||
|
||||
6 个 BOARD(含 LCD-BD 那个 SCH 被删的——只有 PCB,照样生成 `.kicad_pro` 和 `.kicad_pcb`,sheets:[]):
|
||||
|
||||
| 项目 | sch 解析 | pcb 渲染 |
|
||||
|---|:-:|:-:|
|
||||
| EchoEar-BaseBoard-V1_0 | ✓ ERC 485 | ✓ |
|
||||
| EchoEar-CoreBoard-V1_0 | ✓ ERC 1205 | ✓ |
|
||||
| EchoEar-Rotating-Base-LCD-BD-V1_0 | (no sch) | ✓ |
|
||||
| EchoEar-Rotating-Base-Mainboard-V1_0 | ✓ ERC 412 | ✓ |
|
||||
| ESP-VoCat-MicBoard-V1_0 | ✓ ERC 133 | ✓ |
|
||||
| ESP-VoCat-Rotating-Base-Sub-board-V1_0 | ✓ ERC 30 | ✓ |
|
||||
|
||||
`pro.sheets[0][0]` 跟 `.kicad_sch` 第一行 `(uuid ...)` 字符串相等(验证过 CoreBoard:`366d3e53-5167-4e17-9325-c2fccbe4330b`)。
|
||||
|
||||
### 决策(Why)
|
||||
|
||||
- **basename 对齐 = KiCad pairing 的全部**:KiCad 不读 .kicad_pro 里的 `boards`/`schematic` 字段去找文件,纯靠**同目录同 basename**自动配对。其它字段都是项目 settings,缺了 KiCad 用 default 兜底。
|
||||
- **`sheets: []` 兜底 LCD-BD**:SCH 被 DELETE_DOC 的板子没 schematic root,pro 里空数组兜底,KiCad 打开时只显示 pcbnew,不会卡。
|
||||
- **`--all` 不替代 `--all-sch` / `--all-pcb`**:保留两个细粒度命令——只想看 schematic 或只想 batch-export PCB 时不必生成 .kicad_pro 噪音。
|
||||
|
||||
### 测试
|
||||
|
||||
68 → 71 单测全过:pro_writer 3 个(filename + root uuid 绑定 / sheets 空数组 fallback / KiCad 8 顶层 key 完整性)。
|
||||
|
||||
### 下游交付
|
||||
|
||||
下游同学的 Wokwi pipeline 不吃的 5 个 Pro 项目(3 块 EPRO2 AES + 2 块 Pro 2.x)现在一条命令就能转:
|
||||
```
|
||||
uv run python -m tools.epro2.kicad data/raw/oshwhub/<uuid> --all --out <dst>
|
||||
```
|
||||
每个项目目录拷贝到他们 corpus 即可。
|
||||
|
||||
---
|
||||
|
||||
## 2026-04-29 02:00 PCB Phase-2:POUR → KiCad zone,CoreBoard unconnected -43%
|
||||
|
||||
**Claude 会话**
|
||||
|
||||
Reference in New Issue
Block a user