# -*- coding: utf-8 -*- u"""补线器:在**板上现有铜**之上只布没接完的那几个网(不动其它任何线)。 /c/Python314/python .claude/r2/repair_route.py # 只算 /c/Python314/python .claude/r2/repair_route.py --push # 追加下发(只推新增的段/孔) 现有铜从 `_m6_board_copper.json`(pcb 读回)来,按网名打进占用图 —— 同网可穿, 所以 A* 从没接上的焊盘出发,碰到本网已有的铜就算到了。 """ import io, json, os, sys, math sys.stdout.reconfigure(encoding='utf-8') HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, os.path.dirname(HERE)); sys.path.insert(0, HERE) import router as RT import pcb_rules as R NETS = [a for a in sys.argv[1:] if not a.startswith('--')] or \ ['VDAC', '$1N147', '$1N156', 'EFUSE_PG', '$1N165', 'VO', '+3V3', 'VBUS', 'SDA'] cp = json.load(io.open(os.path.join(HERE, '_m6_board_copper.json'), encoding='utf-8')) segs = [tuple(s) for s in cp['segs']] vias = [tuple(v) for v in cp['vias']] pads = RT.load_pads() auto = R.resolve_auto() board_vias = [(v[0], v[1], v[2], RT.VIA_D) for v in vias if v[2] == 'GND'] _fs, _fv, launch = RT.finger_escape() bypad = {} for p in pads: if p[0] == 'J1' or not p[7] or p[7] in RT.SKIP: continue bypad.setdefault(p[7], []).append(p) for net, pts in launch.items(): for (lay, x, y) in pts: bypad.setdefault(net, []).append(['J1', 'launch', x, y, 0.3, 0.3, lay, net, 'RECT']) n0, v0 = len(segs), len(vias) logs = RT.route_groups(bypad, pads, segs, vias, board_vias, auto, priority=tuple(NETS), only=set(NETS)) new_s, new_v = segs[n0:], vias[v0:] print(u'新增 %d 段 / %d 孔' % (len(new_s), len(new_v))) for m in logs: print(u' [!] ' + m) left = RT.check_connected(pads, segs, vias) print(u'连通性复查:%s' % (u'全通' if not left else left)) json.dump({'segs': new_s, 'vias': new_v}, io.open(os.path.join(HERE, '_m6_repair.json'), 'w', encoding='utf-8')) if '--push' in sys.argv and new_s: RT.push(new_s, new_v)