文件
phonerail/.claude/pcb2_snapshot.py
T
zhou yang和Claude Opus 5 2bfe308b30 初始导入:PhoneRail 五路手机直供电源板
原理图/PCB 已在 EasyEDA 里做到 12 页跨页 0 漏接,固件刚完成骨架包 A1。
这次是把已有的一切一次性纳入版本控制,没有改动任何设计内容。

纳入:
- 设计与需求文档、PROGRESS.md、小米8 参考原理图 PDF 与追脚脚本
- .claude/ 下的 EasyEDA 桥接工具链与几何/网表缓存(eda-parts.json、
  pcb-parts.json、pcb-pads.json、p2-ch1.json 等,是重画各页的唯一事实来源)
- 117 张验证截图(本项目所有方向问题都是靠人眼看截图发现的,属于证据不是垃圾)
- firmware/ 的 A1 骨架与 site/ 文档站源码

.gitignore 排除:构建产物(firmware/build、host/build、sdkconfig)、
site/node_modules、__pycache__、桥接日志 _bridge.log、脚本自标的 *.stale。

.gitattributes 默认 `* -text`:现有 .py/.json 大多是 CRLF,原样存,
不让 git 重写行尾。唯一例外是 *.sh 强制 LF —— 带 \r 的 shell 脚本 bash 跑不了。

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QYuExfgyYa6DzRRcUso8M8
2026-09-06 18:18:14 +08:00

53 行
2.6 KiB
Python

# -*- coding: utf-8 -*-
u"""把载板 PCB2 当前的全部铜/元件状态落成一个 JSON(可回滚的安全网)。
/c/Python314/python .claude/pcb2_snapshot.py <out.json>
抓:元件 (位号,x,y,rot,layer)、导线、过孔、铺铜(含多边形)、自由焊盘、layer 11 多段线、填充。
单位 mil(EasyEDA 原生),不换算。
"""
import io, json, os, sys
HERE = os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
from eda import run
PCB = 'f126ffb29c92f9b2'
JS = u"""
await eda.dmt_EditorControl.openDocument('%s');
await new Promise(r=>setTimeout(r,1500));
const out = {comps:[], lines:[], vias:[], pours:[], fills:[], pads:[], polys:[], arcs:[]};
for (const c of await eda.pcb_PrimitiveComponent.getAll())
out.comps.push([c.getState_Designator(), c.getState_X(), c.getState_Y(), c.getState_Rotation(), c.getState_Layer()]);
for (const l of await eda.pcb_PrimitiveLine.getAll())
out.lines.push([l.layer, l.startX, l.startY, l.endX, l.endY, l.lineWidth, l.net]);
for (const a of await eda.pcb_PrimitiveArc.getAll())
out.arcs.push([a.layer, a.net, JSON.stringify(a).slice(0, 400)]);
for (const v of await eda.pcb_PrimitiveVia.getAll())
out.vias.push([v.x, v.y, v.holeDiameter, v.diameter, v.net]);
for (const p of await eda.pcb_PrimitivePour.getAll()) {
let poly = null; try { poly = p.complexPolygon; } catch(e) {}
out.pours.push({layer: p.layer, net: p.net, name: p.pourName, prio: p.pourPriority, fill: p.pourFillMethod,
poly: poly ? JSON.parse(JSON.stringify(poly)) : null});
}
for (const f of await eda.pcb_PrimitiveFill.getAll())
out.fills.push({layer: f.layer, net: f.net, raw: JSON.parse(JSON.stringify(f)).complexPolygon || null});
for (const p of await eda.pcb_PrimitivePad.getAll()) {
const pid = p.getState_PrimitiveId();
out.pads.push([pid, p.getState_PadNumber(), p.getState_Layer(), p.getState_X(), p.getState_Y(), p.getState_Net()]);
}
for (const p of await eda.pcb_PrimitivePolyline.getAll())
out.polys.push({layer: p.layer, raw: JSON.parse(JSON.stringify(p))});
return out;
""" % PCB
if __name__ == '__main__':
r = run(JS, timeout=300)
if not r.get('success'):
print(json.dumps(r, ensure_ascii=False)[:800]); sys.exit(1)
res = r['result']
out = os.path.join(HERE, sys.argv[1] if len(sys.argv) > 1 else '_pcb2_snap.json')
io.open(out, 'w', encoding='utf-8').write(json.dumps(res))
print(u'元件 %d / 导线 %d / 弧 %d / 过孔 %d / 铺铜 %d / 填充 %d / 焊盘 %d / 多段线 %d -> %s' % (
len(res['comps']), len(res['lines']), len(res['arcs']), len(res['vias']), len(res['pours']),
len(res['fills']), len(res['pads']), len(res['polys']), out))