main
John Lauer Preserve adopted board30 and validated resistor library candidates with native-render dependency 7fa0c9c
"""Match Bourns CR0402 recommended lands without changing placement, nets or routing."""
from pathlib import Path
import json,copy,shutil,hashlib
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/bourns-land-review-v2';O.mkdir(exist_ok=True);src=R/'aiflow/run/board-30.kicad_pcb';dst=O/'bourns-land-candidate.kicad_pcb';S=sexp.Sym
for name in ['3d','lib']:shutil.copytree(R/'aiflow/run'/name,O/name,dirs_exist_ok=True)
shutil.copy2(R/'aiflow/run/fp-lib-table',O/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copy2(src.with_suffix('.'+ext),dst.with_suffix('.'+ext))
b=sexp.parse(src.read_text());rows=[];lib=None
for f in sexp.find(b,'footprint'):
 props={p[1]:p[2]for p in sexp.find(f,'property')}
 if not props.get('MPN','').startswith('CR0402-'):continue
 before=[]
 for pad in sexp.find(f,'pad'):
  assert pad[1]in ['1','2']and pad[2]=='smd';before.append({'pin':pad[1],'at':sexp.first(pad,'at')[1:],'size':sexp.first(pad,'size')[1:]});pad[3]=S('rect');sexp.first(pad,'at')[1:3]=[S('-.5'if pad[1]=='1'else '.5'),S('0')];sexp.first(pad,'size')[1:]=[S('.5'),S('.5')];pad[:]=[v for v in pad if not(isinstance(v,list)and v and v[0]=='roundrect_rratio')]
 f[1]='Load:R_0402_Bourns_CR_1.00x0.50mm';sexp.first(f,'descr')[1]='Bourns CR0402, manufacturer recommended nominal lands: gap0.50, overall1.50, width0.50mm; https://www.bourns.com/docs/product-datasheets/cr.pdf p2'
 rows.append({'reference':props['Reference'],'mpn':props['MPN'],'before':before,'after':{'centersX':[-.5,.5],'padSize':[.5,.5],'gap':.5,'overallSpan':1.5,'shape':'rect'}})
 if lib is None:lib=copy.deepcopy(f)
assert len(rows)==31
lib[1]='R_0402_Bourns_CR_1.00x0.50mm';lib[:]=[v for v in lib if not(isinstance(v,list)and v and v[0]in ['at','uuid'])]
lib[:]=[v for v in lib if not(isinstance(v,list)and v and v[0]=='property'and v[1]not in ['Reference','Value','Datasheet','Description'])]
for p in sexp.find(lib,'property'):
 if p[1]=='Reference':p[2]='REF**';sexp.first(p,'at')[1:]=[S('0'),S('-1'),S('0')]
 if p[1]=='Value':p[2]='R_0402_Bourns_CR'
for pad in sexp.find(lib,'pad'):
 sexp.first(pad,'at')[1:]=sexp.first(pad,'at')[1:3]
 pad[:]=[v for v in pad if not(isinstance(v,list)and v and v[0]in ['net','uuid'])]
(O/'lib/Load.pretty/R_0402_Bourns_CR_1.00x0.50mm.kicad_mod').write_text(sexp.dump(lib)+'\n')
for z in sexp.find(b,'zone'):z[:]=[v for v in z if not(isinstance(v,list)and v and v[0]=='filled_polygon')]
dst.write_text(sexp.dump(b)+'\n')
r={'adopted':False,'sourceBoardSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256(dst.read_bytes()).hexdigest(),'source':'https://www.bourns.com/docs/product-datasheets/cr.pdf?sfvrsn=574d41f6_17','datasheetPage':2,'recommendedRangesMm':{'gap':[.5,.6],'overall':[1.4,1.6],'width':[.4,.6]},'references':rows,'scope':'31 CR0402 land patterns only; placement, signal assignments, existing traces/vias and models preserved. Native refill/DRC and visual review required; no assembly qualification.'};(O/'selection-review.json').write_text(json.dumps(r,indent=2)+'\n');print('Prepared31-reference isolated land-pattern candidate')