main
John Lauer
Document silkscreen export warning isolation and prepare narrated results review
46fcaab
"""Locate native STEP wire warnings against the saved board without changing it."""
from pathlib import Path
import hashlib,json,math,re
import sexp
R=Path(__file__).resolve().parents[1];board=R/'aiflow/run/board-32.kicad_pcb';b=sexp.parse(board.read_text())
refs=[]
for f in sexp.find(b,'footprint'):
props={x[1]:x[2] for x in sexp.find(f,'property')};at=sexp.first(f,'at')
refs.append({'ref':props['Reference'],'mpn':props.get('MPN'),'xy':[float(at[1]),float(at[2])]})
log=json.loads((R/'mechanical/board32-review/native-export.json').read_text())['stdout'];warnings=[]
for match in re.finditer(r'z: ([\d.-]+); bounding box: x0: ([\d.-]+); y0: ([\d.-]+); x1: ([\d.-]+); y1: ([\d.-]+)',log):
z,x0,y0,x1,y1=map(float,match.groups());xy=[(x0+x1)/2,(y0+y1)/2]
nearest=sorted(refs,key=lambda r:math.dist(r['xy'],xy))[:3]
warnings.append({'exportZ':z,'boardXYBounds':[x0,y0,x1,y1],'nearbyFootprints':[dict(r,distanceMm=math.dist(r['xy'],xy)) for r in nearest]})
out={'boardSha256':hashlib.sha256(board.read_bytes()).hexdigest(),'warnings':warnings,'scope':'Location aid only. Nearby references do not establish which geometric primitive caused the warning or whether copper was omitted.'}
(R/'checkpoints/board32-step-export/warning-locations.json').write_text(json.dumps(out,indent=2)+'\n');print(json.dumps(out,indent=2))