main
John Lauer
Add dedicated fan and Kelvin-minus probe pads; verify native schematic and PCB; correct thermal budget
65667a5
"""Native KiCad placement candidate; never overwrites the staged source board."""
import pcbnew as k,json,os,math
P=os.path.dirname(os.path.abspath(__file__));board=k.LoadBoard(os.path.join(P,'placement-source.kicad_pcb'));mm=k.FromMM;to=k.ToMM
moves=json.load(open(os.path.join(P,'placement-moves.json')))
# Mechanical/decoupling review corrections; native DRC rechecks every candidate.
changes={'TP12':(104,66,0),'TP13':(108,66,0),'J8':(158.905,43,90),'R31':(149.7,44.8,0),'R32':(149.7,46.5,0),'R29':(153,36.5,0),'R30':(153,38.5,0),'C8':(151,67,90),'C9':(145,67,90),'C10':(118,69.3,0),'C17':(105,49.7,90)}
for r,(x,y,a) in changes.items():moves[r]={'x':x,'y':y,'rotation':a}
for fp in list(board.GetFootprints()):
ref=fp.GetReference()
if ref in moves:
m=moves[ref];fp.SetPosition(k.VECTOR2I(mm(m['x']),mm(m['y'])));fp.SetOrientationDegrees(m['rotation'])
latest={c['ref']:c for c in json.load(open(os.path.join(P,'netlist.json')))['components']}
for fp in board.GetFootprints():
c=latest[fp.GetReference()];fp.SetValue(c['value']);fp.SetField('MPN',c['mpn'])
# Native text bounds against complete courtyard/pad/drill envelopes. Model overhangs
# beyond courtyards remain an explicit unresolved assembled-visibility review.
def bbox(obj):
b=obj.GetBoundingBox();return tuple(to(v) for v in [b.GetLeft(),b.GetTop(),b.GetRight(),b.GetBottom()])
def overlaps(a,b,g=.18):return a[0]<b[2]+g and b[0]<a[2]+g and a[1]<b[3]+g and b[1]<a[3]+g
obstacles=[]
for fp in board.GetFootprints():
pts=[]
for g in fp.GraphicalItems():
if g.GetLayer() in (k.F_CrtYd,k.B_CrtYd):pts.append(bbox(g))
for pad in fp.Pads():pts.append(bbox(pad))
if pts:obstacles.append((fp.GetReference(),(min(b[0] for b in pts),min(b[1] for b in pts),max(b[2] for b in pts),max(b[3] for b in pts))))
placed=[];unresolved=[]
for fp in sorted(board.GetFootprints(),key=lambda f:(not f.GetReference().startswith(('J','MP','TP')),f.GetReference())):
text=fp.Reference();text.SetTextSize(k.VECTOR2I(mm(.8),mm(.8)));text.SetTextThickness(mm(.12));text.SetTextAngle(k.EDA_ANGLE(0,k.DEGREES_T));text.SetVisible(True)
x,y=to(fp.GetPosition().x),to(fp.GetPosition().y);body=next(b for ref,b in obstacles if ref==fp.GetReference());found=False
candidates=[]
for gap in [.9,1.4,2.0,2.7,3.5,4.5]:
candidates += [(x,body[1]-gap),(x,body[3]+gap),(body[0]-gap,y),(body[2]+gap,y)]
# Local two-dimensional search after preferred cardinal candidates.
grid=[(x+i*.4,y+j*.4)for i in range(-15,16)for j in range(-15,16)]
grid.sort(key=lambda q:(q[0]-x)**2+(q[1]-y)**2)
candidates+=grid
for xx,yy in candidates:
text.SetPosition(k.VECTOR2I(mm(xx),mm(yy)));b=bbox(text)
if b[0]<98.3 or b[2]>161.7 or b[1]<30.3 or b[3]>101.7:continue
if any(overlaps(b,bb) for _,bb in obstacles) or any(overlaps(b,bb,.2)for bb in placed):continue
placed.append(b);found=True;break
if not found:unresolved.append(fp.GetReference())
# Show identity in otherwise free space; not a fabrication claim.
note=k.PCB_TEXT(board);note.SetText('ADOM LOAD R0 / UNROUTED');note.SetTextSize(k.VECTOR2I(mm(1),mm(1)));note.SetTextThickness(mm(.15));note.SetPosition(k.VECTOR2I(mm(129),mm(35)));note.SetLayer(k.F_SilkS);board.Add(note)
path=os.path.join(P,'placement-candidate.kicad_pcb');k.SaveBoard(path,board)
json.dump({'candidate':path,'footprints':len(list(board.GetFootprints())),'moves':len(moves),'unresolved_reference_positions':unresolved,'limits':'Courtyard/pad/drill-based preliminary text placement. Fitted model overhang and heatsink assembly are not audited.'},open(os.path.join(P,'placement-candidate.json'),'w'),indent=2)
print('Candidate saved; unresolved labels:',unresolved)