main
John Lauer
Review cumulative land candidates and correct complete STEP assembly clearance checks
ca3da55
"""Isolate three manufacturer-pattern variants atop the unadopted Bourns candidate."""
from pathlib import Path
import json,hashlib,copy,shutil
import sexp
R=Path(__file__).resolve().parents[1];O=R/'checkpoints/precision-land-review-v2';O.mkdir(exist_ok=True);B=R/'checkpoints/bourns-land-review-v2';src=B/'native-saved/bourns-land-candidate.kicad_pcb';S=sexp.Sym
assert hashlib.sha256(src.read_bytes()).hexdigest()=='8f490a02afb468af8a0691e906259f990f4fae69055f6a6d3c0d4ecc6f1a62f8'
for name in ['lib','3d']:shutil.copytree(B/name,O/name,dirs_exist_ok=True)
shutil.copy2(B/'fp-lib-table',O/'fp-lib-table')
for ext in ['kicad_pro','kicad_dru']:shutil.copy2(B/('bourns-land-candidate.'+ext),O/('precision-land-candidate.'+ext))
b=sexp.parse(src.read_text());rows=[]
for f in sexp.find(b,'footprint'):
props={v[1]:v[2] for v in sexp.find(f,'property')};ref=props['Reference']
if ref not in ['R7','R8','R9','R10']:continue
mpn=props['MPN'];cat=R/'components'/mpn.lower();cf=sexp.parse((cat/(mpn.lower()+'.kicad_mod')).read_text());mapping={str(p[1]):p for p in sexp.find(cf,'pad')}
assert set(mapping)=={'1','2'}
name='R_0402_'+('Panasonic_0402_Reflow' if ref in ['R7','R8'] else 'Vishay_TNPW_IPC');before=[]
for p in sexp.find(f,'pad'):
a=sexp.first(p,'at');z=sexp.first(p,'size');before.append({'pin':p[1],'at':a[1:],'size':z[1:]});c=mapping[str(p[1])]
a[1:3]=copy.deepcopy(sexp.first(c,'at')[1:3]);z[1:]=copy.deepcopy(sexp.first(c,'size')[1:]);p[3]=S('rect');p[:]=[v for v in p if not(isinstance(v,list)and v and v[0]=='roundrect_rratio')]
f[1]='Load:'+name;sexp.first(f,'descr')[1]='Manufacturer recommended reflow lands; see project precision-land-review. Physical process qualification pending.'
lib=copy.deepcopy(f);lib[1]=name;lib[:]=[v for v in lib if not(isinstance(v,list)and v and(v[0]in ['at','uuid']or(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]=name
for p in sexp.find(lib,'pad'):
a=sexp.first(p,'at');a[1:]=a[1:3];p[:]=[v for v in p if not(isinstance(v,list)and v and v[0]in ['net','uuid'])]
(O/'lib/Load.pretty'/(name+'.kicad_mod')).write_text(sexp.dump(lib)+'\n')
rows.append({'reference':ref,'mpn':mpn,'binding':f[1],'before':before,'after':[{'pin':p[1],'at':sexp.first(p,'at')[1:],'size':sexp.first(p,'size')[1:]}for p in sexp.find(f,'pad')],'catalogFootprintSha256':hashlib.sha256((cat/(mpn.lower()+'.kicad_mod')).read_bytes()).hexdigest()})
assert len(rows)==4
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')]
p=O/'precision-land-candidate.kicad_pcb';p.write_text(sexp.dump(b)+'\n')
for source in B.glob('*.kicad_sch'):
t=sexp.parse(source.read_text())
for sy in sexp.find(t,'symbol'):
props={p[1]:p for p in sexp.find(sy,'property')};ref=props.get('Reference',[None,None,None])[2]
if ref in ['R7','R8','R9','R10']:props['Footprint'][2]=next(r['binding']for r in rows if r['reference']==ref)
(O/source.name).write_text(sexp.dump(t)+'\n')
e={'adopted':False,'sourceBoard':str(src.relative_to(R)),'sourceSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidateSha256':hashlib.sha256(p.read_bytes()).hexdigest(),'inheritedUnadoptedChanges':'31 Bourns resistors; no physical board changes','references':rows,'sources':['https://industrial.panasonic.com/cdbs/www-data/pdf/RDM0000/DMM0000COL17.pdf','https://www.vishay.com/doc?28950'],'preserved':'Placement, net membership, models, traces, vias, project rules','limits':'Native DRC, native 2D/3D visual review, schematic parity and process review required. No acceptance gate advanced.'};(O/'selection-review.json').write_text(json.dumps(e,indent=2)+'\n');print('Prepared isolated R7/R8/R9/R10 candidate with full project context')