main
John Lauer
Preserve board29, component assets and scaffold-fit correction candidate with reviewed footage
c54169e
"""Native isolated candidate: widen only segments clear in previous complete-width gates."""
import pcbnew as k,json,shutil,subprocess,sys
from pathlib import Path
p=Path(__file__).parent;b=k.LoadBoard(str(p/'source.kicad_pcb'))
blocked={}
for label in ['1p5','2p0']:
d=json.loads((p/f'power-width-{label}-drc.json').read_text());blocked[label]={i['uuid'] for v in d['violations'] if v.get('severity')=='error' for i in v.get('items',[])}
changes=[]
for t in b.GetTracks():
if isinstance(t,k.PCB_VIA) or t.GetNetname() not in ['DUT_POS','DUT_FUSED','LOAD_POS','SHUNT_P'] or abs(k.ToMM(t.GetWidth())-1.2)>1e-6:continue
uid=str(t.m_Uuid.AsString());width=2.0 if uid not in blocked['2p0'] else 1.5 if uid not in blocked['1p5'] else 1.2
if width>1.2:changes.append({'uuid':uid,'net':t.GetNetname(),'oldWidthMm':1.2,'newWidthMm':width});t.SetWidth(k.FromMM(width))
# Previous native selective gate exposed a short not individually listed by the all-wide gate.
# Retain the original width of that LOAD_POS segment; no rule exemptions.
restore = {'1b9d37ad-e751-4897-a919-0a444c463830','55df3ee6-d160-4173-b09c-a845da5b2b81','2ed0b746-6fda-4a09-bf17-5bcef36e1a34'}
for t in b.GetTracks():
if str(t.m_Uuid.AsString()) in restore: t.SetWidth(k.FromMM(1.2))
changes = [c for c in changes if c['uuid'] not in restore]
name='power-width-selective-v3'
for ext in ['kicad_dru','kicad_pro']:
if (p/('source.'+ext)).exists():shutil.copy2(p/('source.'+ext),p/(name+'.'+ext))
k.ZONE_FILLER(b).Fill(b.Zones());k.SaveBoard(str(p/(name+'.kicad_pcb')),b)
subprocess.run([str(Path(sys.executable).parent/'kicad-cli.exe'),'pcb','drc','--format','json','-o',str(p/(name+'-drc.json')),str(p/(name+'.kicad_pcb'))],check=False)
d=json.loads((p/(name+'-drc.json')).read_text());r={'changes':changes,'errors':sum(x.get('severity')=='error' for x in d['violations']),'warnings':sum(x.get('severity')=='warning' for x in d['violations']),'unconnected':len(d.get('unconnected_items',[]))};(p/'selective-review.json').write_text(json.dumps(r,indent=2));print(json.dumps({k:(len(v)if k=='changes'else v)for k,v in r.items()}))