main
John Lauer Improve 48 reference labels with preserved copper and native DRC; document saved-file fallback and review clips a4a06ac
#!/usr/bin/env python3
"""Submit a complete existing-field proposal to native DRC, without committing."""
import json
from pathlib import Path
import subprocess

ROOT=Path(__file__).resolve().parents[1]
P=ROOT/'design/silkscreen-review'
geometry=json.loads((P/'geometry.json').read_text())
layout=json.loads((P/'layout-F.json').read_text())
review=json.loads((P/'review.json').read_text())
assert not layout['unresolved'], 'Unresolved existing fields would remain in place; do not omit their occupancy.'
index={m['id']:m for m in geometry['marks']}
updates=[]
for c in layout['placements']:
    m=index[c['id']]; n=m['nativeInput']
    if m['reference']=='board':continue
    if sum(abs(c['position'][i]-n[k]) for i,k in enumerate(('x','y')))<1e-7 and c['font']==n['height']:continue
    updates.append(dict(id=m['id'],x=c['position'][0],y=c['position'][1],layer=m['layer'],height=c['font'],width=c['font']*n['width']/n['height'],stroke=n['stroke'],rotation=c.get('rotation',n['rotation']),align=n['align'],mirrored=n['mirrored'],visible=True))
payload=dict(filePath='C:/Users/john/adom-projects/adom-custom-electronic-load/kicad/adom-custom-electronic-load.kicad_pcb',expectedRevision=review['nativeRevision'],update=updates,dryRun=True,save=False)
(P/'candidate-fields.json').write_text(json.dumps(payload,indent=2)+'\n')
raw=subprocess.check_output(['adom-bridge','--target','AdomLapper','--ai-thread','adom-custom-load','kicad_silk_fields_batch',json.dumps(payload)],text=True)
result=json.loads(raw)
(P/'native-dry-run-complete.json').write_text(raw)
print(json.dumps({k:v for k,v in result.items() if k not in ('output','_reportIssues','_timeoutHint')},indent=2))
assert result.get('mutated') is False
raise SystemExit(0 if result.get('success') else 2)