main
John Lauer
Record native sense routing, rejected bulk plans, and cooling review; prototype remains unrouted
2457b02
"""Native saved-file candidate; preserves the live board and existing copper."""
import pcbnew as k,json
from pathlib import Path
p=Path(__file__).resolve().parent
b=k.LoadBoard(str(p/'adom-custom-electronic-load.kicad_pcb'))
moves=json.load(open(p/'precision-switch-moves.json'));mm=k.FromMM;to=k.ToMM
for f in b.GetFootprints():
if f.GetReference() in moves:
m=moves[f.GetReference()];f.SetPosition(k.VECTOR2I(mm(m['x']),mm(m['y'])));f.SetOrientationDegrees(m['rotation'])
def box(o):
a=o.GetBoundingBox();return tuple(to(v) for v in (a.GetLeft(),a.GetTop(),a.GetRight(),a.GetBottom()))
def overlap(a,b,g=.2):return a[0]<b[2]+g and b[0]<a[2]+g and a[1]<b[3]+g and b[1]<a[3]+g
affected=set(moves)|{"R37"}
obstacles=[];texts=[]
for f in b.GetFootprints():
obstacles.extend(box(o) for o in f.GraphicalItems() if o.GetLayer() in (k.F_CrtYd,k.B_CrtYd,k.F_SilkS))
obstacles.extend(box(o) for o in f.Pads())
if f.GetReference() not in affected:texts.append(box(f.Reference()))
for o in b.GetDrawings():
if o.GetLayer()==k.F_SilkS:obstacles.append(box(o))
changed=[]
for f in b.GetFootprints():
if f.GetReference() not in affected:continue
t=f.Reference();t.SetTextAngle(k.EDA_ANGLE(0,k.DEGREES_T))
x,y=to(f.GetPosition().x),to(f.GetPosition().y)
points=[(x+i*.25,y+j*.25) for i in range(-24,25) for j in range(-24,25)]
points.sort(key=lambda q:(q[0]-x)**2+(q[1]-y)**2)
for xx,yy in points:
t.SetPosition(k.VECTOR2I(mm(xx),mm(yy)));a=box(t)
if a[0]<98.3 or a[2]>161.7 or a[1]<30.3 or a[3]>101.7:continue
if any(overlap(a,c) for c in obstacles+texts):continue
texts.append(a);changed.append({'ref':f.GetReference(),'text':[xx,yy]});break
else:raise RuntimeError('No local label position: '+f.GetReference())
k.SaveBoard(str(p/'precision-candidate.kicad_pcb'),b)
print(json.dumps({'changed':changed,'footprints':len(list(b.GetFootprints())),'note':'Preliminary courtyard and native graphics check, not assembled model visibility qualification'}))