main
John Lauer
Review component pin functions and validate isolated library model and hole corrections
7fb4d36
"""Screen larger Q1 holes/pads; horizontal forming and cooling stay unqualified."""
from pathlib import Path
import copy,json,hashlib,math,shutil
import sexp
root=Path(__file__).resolve().parents[1];base=root/'checkpoints/j11-hole-review';src=base/'j11-hole-candidate.kicad_pcb';out=root/'checkpoints/q1-hole-review';out.mkdir(exist_ok=True)
b=sexp.parse(src.read_text());old=copy.deepcopy(b);f=next(f for f in sexp.find(b,'footprint') if any(p[1:3]==['Reference','Q1'] for p in sexp.find(f,'property')))
oldName=f[1];variant='IXTP15N50L2_Horizontal_Hole1p4_Review';f[1]='Load:'+variant;changes=[]
for p in sexp.find(f,'pad'):
if not p[1]:continue
size=sexp.first(p,'size');drill=sexp.first(p,'drill');changes.append({'pin':p[1],'oldSize':size[1:].copy(),'oldDrill':drill[1]});size[1:]=[sexp.Sym('1.75' if p[1]=='2' else '1.905'),sexp.Sym('2')];drill[1]=sexp.Sym('1.4')
library=sexp.parse((root/'kicad/lib/Load.pretty/TO-220-3_Horizontal_TabUp_Drain1p6.kicad_mod').read_text());library[1]=variant
for p in sexp.find(library,'pad'):
if p[1]:
sexp.first(p,'size')[1:]=[sexp.Sym('1.75' if p[1]=='2' else '1.905'),sexp.Sym('2')];sexp.first(p,'drill')[1]=sexp.Sym('1.4')
for key in ['at','uuid','path','sheetname','sheetfile']:
for item in sexp.find(library,key):library.remove(item)
for p in sexp.find(library,'property'):
if p[1]=='Reference':p[2]='REF**'
if p[1]=='Value':p[2]=variant
def clean(n):
for i in list(n):
if isinstance(i,list):
if i and i[0] in ['uuid','net']:n.remove(i)
else:clean(i)
clean(library);board=out/'q1-hole-candidate.kicad_pcb';board.write_text(sexp.dump(b)+'\n');assert sexp.parse(board.read_text())==b
f[1]=oldName
for p in sexp.find(f,'pad'):
if not p[1]:continue
c=next(c for c in changes if c['pin']==p[1]);sexp.first(p,'size')[1:]=c['oldSize'];sexp.first(p,'drill')[1]=c['oldDrill']
assert b==old
for ext in ['kicad_pro','kicad_dru']:shutil.copyfile(base/('j11-hole-candidate.'+ext),out/('q1-hole-candidate.'+ext))
shutil.copyfile(base/'fp-lib-table',out/'fp-lib-table');shutil.copytree(base/'lib',out/'lib',dirs_exist_ok=True);(out/'lib/Load.pretty'/f'{variant}.kicad_mod').write_text(sexp.dump(library)+'\n')
r={'source':str(src.relative_to(root)),'sourceSha256':hashlib.sha256(src.read_bytes()).hexdigest(),'candidate':str(board.relative_to(root)),'candidateSha256':hashlib.sha256(board.read_bytes()).hexdigest(),'changes':changes,'newPadSizeMm':{'1':[1.905,2],'2':[1.75,2],'3':[1.905,2]},'newDrillMm':1.4,'maxLeadSectionMm':[1.02,.56],'maxLeadDiagonalMm':math.hypot(1.02,.56),'nominalDiametralClearanceMm':1.4-math.hypot(1.02,.56),'minimumNominalAnnulusMm':.175,'minimumNominalInterpadGapMm':.7125,'tracksViasZonesNetsUnchanged':True,'nativeApplied':False,'qualification':'Review only. Native DRC, finished-hole tolerance, lead forming, model, thermal assembly and current rerun unresolved.'}
(out/'review.json').write_text(json.dumps(r,indent=2)+'\n');print(json.dumps({'candidate':str(board),'tracksViasZonesNetsUnchanged':True}))