main
John Lauer Save native two-sided contact artwork and recorded GLB material correction; qualification remains open 57e2489
#!/usr/bin/env python3
"""Refresh all final candidate extents from KiCad, including rotated groups."""
import json,subprocess
from pathlib import Path
P=Path(__file__).resolve().parents[1]/'design/silkscreen-review';s=json.loads((P/'bottom-candidates.json').read_text());l=json.loads((P/'bottom-layout.json').read_text());identity=json.loads((P/'bottom-identity.json').read_text());alltext=[c for g in l['placements'] for c in g['children']]+identity['texts'];defs=[]
for i,c in enumerate(alltext):
 size=c.get('size',c.get('height'));defs.append(dict(id=str(i),text=c['text'],x=c['x'],y=c['y'],height=size,width=c.get('width',size),stroke=c['stroke'],mirrored=True,rotation=c.get('angle',c.get('rotation',0))))
changes=[]
for start in range(0,len(defs),40):
 r=json.loads(subprocess.check_output(['adom-bridge','--target','AdomLapper','--ai-thread','adom-custom-load','kicad_text_bounds',json.dumps(dict(filePath='C:/Users/john/adom-projects/adom-custom-electronic-load/kicad/adom-custom-electronic-load.kicad_pcb',expectedRevision=s['nativeRevision'],texts=defs[start:start+40]))],text=True));assert r['success'];(P/f'final-native-extents-{start:03}.json').write_text(json.dumps(r,indent=2)+'\n')
 for t in r['texts']:
  c=alltext[int(t['id'])];err=max(abs(a-b) for a,b in zip(c['box'],t['box']))
  if err>1e-5:changes.append(dict(text=c['text'],reference=c.get('reference'),maximumBoundDifferenceMm=err,before=c['box'],after=t['box']))
  c['box']=t['box']
for g in l['placements']:
 b=[c['box'] for c in g['children']];g['boxes']=b;g['box']=[min(q[0] for q in b),min(q[1] for q in b),max(q[2] for q in b),max(q[3] for q in b)]
(P/'bottom-layout.json').write_text(json.dumps(l,indent=2)+'\n');(P/'bottom-identity.json').write_text(json.dumps(identity,indent=2)+'\n');(P/'bottom-extents-corrections.json').write_text(json.dumps(changes,indent=2)+'\n');print(json.dumps(changes,indent=2))