main
John Lauer
Record current-screen milestone, combined cooling study and physical-pad solver review
f2ec9fd
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
"""Run using native desktop KiCad Python; modifies only an isolated board copy."""
import pcbnew,sys,json
from pathlib import Path
source=Path(sys.argv[1]);out=Path(sys.argv[2]);board=pcbnew.LoadBoard(str(source));nets=board.GetNetsByName()
changes=[]
for net,x,y in [('GND',133.0,100.8),('GND',138.0,100.8),('GND',139.0,93.0),('GND',136.5,93.0),('GND',139.4,90.4),('GND',139.4,91.4),('GND',139.4,92.4)]:
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(x),pcbnew.FromMM(y)));via.SetWidth(pcbnew.FromMM(.8));via.SetDrill(pcbnew.FromMM(.4));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets[net]);board.Add(via);changes.append({'kind':'via','net':net,'at':[x,y],'sizeMm':.8,'drillMm':.4,'uuid':str(via.m_Uuid.AsString())})
for item in board.GetTracks():
uid=str(item.m_Uuid.AsString())
if uid=='32514162-b870-4c7a-95a2-b85b8db79257':
item.SetWidth(pcbnew.FromMM(1.0));item.SetDrill(pcbnew.FromMM(.6));changes.append({'kind':'resize-via','uuid':uid,'net':'LOAD_POS','sizeMm':1.0,'drillMm':.6})
for item in list(board.GetTracks()):
uid=str(item.m_Uuid.AsString())
if uid in ['91eed079-74e4-4863-8dc1-f211a19b6ee0','ad353074-a567-44a9-a20a-744b8057c5a9']:
board.Remove(item);changes.append({'kind':'remove-track','uuid':uid})
if uid=='aa6c5964-74d4-410e-a69e-ffb2cd9c9999':
item.SetWidth(pcbnew.FromMM(1.0));item.SetDrill(pcbnew.FromMM(.6));changes.append({'kind':'resize-via','uuid':uid,'sizeMm':1.0,'drillMm':.6})
def track(net,layer,a,b,width):
t=pcbnew.PCB_TRACK(board);t.SetStart(pcbnew.VECTOR2I(pcbnew.FromMM(a[0]),pcbnew.FromMM(a[1])));t.SetEnd(pcbnew.VECTOR2I(pcbnew.FromMM(b[0]),pcbnew.FromMM(b[1])));t.SetWidth(pcbnew.FromMM(width));t.SetLayer(layer);t.SetNet(nets[net]);board.Add(t);changes.append({'kind':'track','net':net,'start':a,'end':b,'widthMm':width,'layer':board.GetLayerName(layer)})
for a,b in [((127.46,82),(127.46,83.3)),((127.46,83.3),(126.4,84.36)),((126.4,84.36),(126.4,86.5))]:track('LOAD_POS',pcbnew.F_Cu,a,b,1.5)
for a,b in [((139.4,90.4),(139.4,92)),((139.4,92),(138.4,93)),((138.4,93),(136.5,93))]:track('GND',pcbnew.B_Cu,a,b,1.5)
for item in board.GetTracks():
if isinstance(item,pcbnew.PCB_VIA) and item.GetNetname()=='GND':
p=item.GetPosition();xy=(round(pcbnew.ToMM(p.x),3),round(pcbnew.ToMM(p.y),3))
if xy in [(139.4,86.8),(136.5,93.0),(139.4,90.4),(139.4,91.4),(139.4,92.4)]:item.SetWidth(pcbnew.FromMM(1));item.SetDrill(pcbnew.FromMM(.6));changes.append({'kind':'resize-via','at':xy,'sizeMm':1,'drillMm':.6})
for fp in board.GetFootprints():
delta={'Q2':-.3,'U3':.3,'R7':.1}.get(fp.GetReference())
if delta:
pos=fp.GetPosition();pos.x+=pcbnew.FromMM(delta);fp.SetPosition(pos);changes.append({'kind':'move-footprint','ref':fp.GetReference(),'dxMm':delta})
for item in list(board.GetTracks()):
if item.GetNetname()=='SHUNT_P_SENSE' and isinstance(item,pcbnew.PCB_VIA):
pos=item.GetPosition()
if abs(pcbnew.ToMM(pos.x)-123.6)<.001 and abs(pcbnew.ToMM(pos.y)-85.4)<.001:
pos.x=pcbnew.FromMM(123.3);item.SetPosition(pos);changes.append({'kind':'move-sense-via','from':[123.6,85.4],'to':[123.3,85.4]})
if isinstance(item,pcbnew.PCB_VIA):continue
if item.GetNetname()=='SHUNT_P_SENSE':
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
pos=getter()
if abs(pcbnew.ToMM(pos.x)-123.6)<.001 and abs(pcbnew.ToMM(pos.y)-85.4)<.001:pos.x=pcbnew.FromMM(123.3);setter(pos)
if item.GetNetname()=='SHUNT_N_SENSE' and item.GetLayer()==pcbnew.F_Cu:
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
pos=getter();x,y=pcbnew.ToMM(pos.x),pcbnew.ToMM(pos.y)
if 128.79<x<129.31 and 87.29<y<88.81:pos.x+=pcbnew.FromMM(.2);setter(pos)
for item in list(board.GetTracks()):
uid=str(item.m_Uuid.AsString())
if uid=='32514162-b870-4c7a-95a2-b85b8db79257':
item.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(126.4),pcbnew.FromMM(86.7)))
if uid=='13d2f936-e4d3-40cb-9bf7-1b6b26ca4cf2':
item.SetStart(pcbnew.VECTOR2I(pcbnew.FromMM(126.4),pcbnew.FromMM(86.7)));item.SetWidth(pcbnew.FromMM(1.5))
if uid=='f120f8db-288f-4938-acbf-98ff5e4065df':
item.SetStart(pcbnew.VECTOR2I(pcbnew.FromMM(133.5),pcbnew.FromMM(84.2)));item.SetEnd(pcbnew.VECTOR2I(pcbnew.FromMM(126.8),pcbnew.FromMM(84.2)));item.SetWidth(pcbnew.FromMM(1.9))
if not isinstance(item,pcbnew.PCB_VIA) and item.GetNetname()=='LOAD_POS' and item.GetLayer()==pcbnew.F_Cu:
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
p=getter()
if abs(pcbnew.ToMM(p.x)-126.4)<.001 and abs(pcbnew.ToMM(p.y)-86.5)<.001:p.y=pcbnew.FromMM(86.7);setter(p)
for item in board.GetTracks():
if isinstance(item,pcbnew.PCB_VIA) or item.GetLayer()!=pcbnew.B_Cu or item.GetNetname()!='SHUNT_P_SENSE':continue
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
p=getter();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(y-85.4)<.001 and (abs(x-123.3)<.001 or abs(x-132)<.001):
p.y=pcbnew.FromMM(85.6)
if abs(x-132)<.001:p.x=pcbnew.FromMM(132.2)
setter(p)
# Ease the drain right-angle turn; relocate its adjacent setpoint via with endpoints.
track('LOAD_POS',pcbnew.B_Cu,(126.35,89.0),(125.65,89.7),1.5)
# Preserve explicit branch junctions instead of overlapped dangling endpoints.
for item in list(board.GetTracks()):
uid=str(item.m_Uuid.AsString())
if uid=='32514162-b870-4c7a-95a2-b85b8db79257':
item.SetWidth(pcbnew.FromMM(.8));item.SetDrill(pcbnew.FromMM(.4));item.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(126.05),pcbnew.FromMM(86.7)))
if uid in ['b486fb59-b64e-41ee-a1a7-5a72fcf0a780','8e5d5e2b-78f3-4ed2-af96-409d2ea9d57b']:
a=item.GetStart();b=item.GetEnd();start=(pcbnew.ToMM(a.x),pcbnew.ToMM(a.y));end=(pcbnew.ToMM(b.x),pcbnew.ToMM(b.y))
mid=(126.35,89.0) if uid=='b486fb59-b64e-41ee-a1a7-5a72fcf0a780' else (125.65,89.7)
board.Remove(item);track('LOAD_POS',pcbnew.B_Cu,start,mid,1.5);track('LOAD_POS',pcbnew.B_Cu,mid,end,1.5)
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(126.8),pcbnew.FromMM(86.7)));via.SetWidth(pcbnew.FromMM(.8));via.SetDrill(pcbnew.FromMM(.4));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['LOAD_POS']);board.Add(via)
# Do not enlarge holes through narrow in-plane paths. Keep the three dedicated shunt thermal vias.
for item in list(board.GetTracks()):
uid=str(item.m_Uuid.AsString())
if uid in ['34d3207a-b14a-40d8-be82-5b108c2b867b','9a71af6b-ea83-4f97-b7f6-3f69253c7314']:
board.Remove(item);continue
if isinstance(item,pcbnew.PCB_VIA):
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if uid=='aa6c5964-74d4-410e-a69e-ffb2cd9c9999' or (item.GetNetname()=='GND' and abs(x-139.4)<.001 and abs(y-86.8)<.001):
item.SetWidth(pcbnew.FromMM(.8));item.SetDrill(pcbnew.FromMM(.4))
# Move the transfer hole off the center of the shunt bus; remove a nearly unused ground hole through the return neck.
for item in list(board.GetTracks()):
if not isinstance(item,pcbnew.PCB_VIA):continue
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if item.GetNetname()=='GND' and abs(x-139.4)<.001 and abs(y-86.8)<.001:board.Remove(item)
if str(item.m_Uuid.AsString())=='aa6c5964-74d4-410e-a69e-ffb2cd9c9999':item.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(133.7),pcbnew.FromMM(83.6)))
track('SHUNT_P',pcbnew.F_Cu,(133.7,83.6),(133.8,84.2),1.2)
# Preserve the full plated Q1 source connection; remove its redundant neck-drilling spur.
for item in list(board.GetTracks()):
uid=str(item.m_Uuid.AsString())
if uid in ['cd48c727-15bf-4276-b4b8-ae4d936d829d','30d9e8bc-805a-4b1d-8a79-ad625ee59388']:
board.Remove(item);continue
if isinstance(item,pcbnew.PCB_VIA) and item.GetNetname()=='GND':
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(x-139.4)<.001 and any(abs(y-t)<.001 for t in [90.4,91.4,92.4]):p.x=pcbnew.FromMM(139.8);item.SetPosition(p)
# Share vertical current with smaller holes and widen the plated-source exit.
for item in board.GetTracks():
uid=str(item.m_Uuid.AsString())
if uid in ['2f235494-7976-4048-be2d-b71507b2b45e','ec56cc46-09f5-4ff9-a1b6-61699db68686']:item.SetWidth(pcbnew.FromMM(1.75))
if isinstance(item,pcbnew.PCB_VIA) and item.GetNetname()=='GND':
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(x-139.8)<.001 and any(abs(y-t)<.001 for t in [90.4,91.4,92.4]):
p.x=pcbnew.FromMM(139.4);item.SetPosition(p);item.SetWidth(pcbnew.FromMM(.6));item.SetDrill(pcbnew.FromMM(.3))
for item in board.GetTracks():
if str(item.m_Uuid.AsString())=='f120f8db-288f-4938-acbf-98ff5e4065df':
item.SetStart(pcbnew.VECTOR2I(pcbnew.FromMM(133.5),pcbnew.FromMM(84.25)));item.SetEnd(pcbnew.VECTOR2I(pcbnew.FromMM(126.8),pcbnew.FromMM(84.25)));item.SetWidth(pcbnew.FromMM(2.0))
# Fine-grid hotspot revision: spread the return transfer and soften the two power necks.
for item in board.GetTracks():
if isinstance(item,pcbnew.PCB_VIA):
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if item.GetNetname()=='GND' and abs(x-139.4)<.001 and abs(y-90.4)<.001:
p.x=pcbnew.FromMM(139.0);item.SetPosition(p)
continue
uid=str(item.m_Uuid.AsString())
if uid in ['32cd5f76-8c9c-4680-a071-fe4f71064f23','cecc8caa-bb93-470d-a793-50ae2c93732f']:item.SetWidth(pcbnew.FromMM(1.6))
if item.GetNetname()=='LOAD_POS' and item.GetLayer()==pcbnew.B_Cu:
a=item.GetStart();b=item.GetEnd()
if abs(pcbnew.ToMM(a.y)-89.7)<.001 and abs(pcbnew.ToMM(b.y)-89.7)<.001:item.SetWidth(pcbnew.FromMM(1.75))
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(139.8),pcbnew.FromMM(90.4)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['GND']);board.Add(via)
track('GND',pcbnew.B_Cu,(139.0,90.4),(139.8,90.4),1.2)
# Keep clearance beside the setpoint via; widen only the diode-spread junction.
for item in list(board.GetTracks()):
if isinstance(item,pcbnew.PCB_VIA) or item.GetNetname()!='LOAD_POS' or item.GetLayer()!=pcbnew.B_Cu:continue
a=item.GetStart();b=item.GetEnd();ax,ay=pcbnew.ToMM(a.x),pcbnew.ToMM(a.y);bx,by=pcbnew.ToMM(b.x),pcbnew.ToMM(b.y)
if abs(ay-89.7)<.001 and abs(by-89.7)<.001:
item.SetWidth(pcbnew.FromMM(1.5))
if min(ax,bx)<120 and max(ax,bx)>125:
board.Remove(item);track('LOAD_POS',pcbnew.B_Cu,(119.8,89.7),(123.0,89.7),1.75);track('LOAD_POS',pcbnew.B_Cu,(123.0,89.7),(125.65,89.7),1.5)
# Fill the inside shunt-bus bend with a diagonal copper path.
track('SHUNT_P',pcbnew.B_Cu,(133.0,84.7),(134.7,85.5),1.2)
# Spread the plated-source exit without moving the gate or clamp circuit.
track('SHUNT_P',pcbnew.B_Cu,(125.1,81.8),(125.35,82.7),1.9)
for item in board.GetTracks():
if isinstance(item,pcbnew.PCB_VIA):continue
if item.GetNetname()=='LOAD_POS' and item.GetLayer()==pcbnew.B_Cu:
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
p=getter();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(x-126.35)<.001 and abs(y-89)<.001:p.y=pcbnew.FromMM(88.85);setter(p)
if abs(x-125.65)<.001 and abs(y-89.7)<.001:p.x=pcbnew.FromMM(125.5);setter(p)
for x in [139.0,139.8]:
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(x),pcbnew.FromMM(89.9)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['GND']);board.Add(via)
track('GND',pcbnew.B_Cu,(139,89.9),(139.8,89.9),.6)
track('GND',pcbnew.B_Cu,(139.4,89.9),(139.4,90.4),.6)
# Give the ground transfer more uninterrupted top copper; keep UART endpoints fixed.
for item in list(board.GetTracks()):
if isinstance(item,pcbnew.PCB_VIA) or item.GetLayer()!=pcbnew.F_Cu:continue
a=item.GetStart();b=item.GetEnd();ax,ay=pcbnew.ToMM(a.x),pcbnew.ToMM(a.y);bx,by=pcbnew.ToMM(b.x),pcbnew.ToMM(b.y)
if item.GetNetname()=='UART_RX' and abs(ax-140.7)<.001 and abs(bx-140.7)<.001 and abs(ay-83.5)<.001 and abs(by-93.2)<.001:
board.Remove(item)
points=[(140.7,83.5),(140.7,88.0),(141.0,88.3),(141.0,91.8),(140.7,92.1),(140.7,93.2)]
for p,q in zip(points,points[1:]):track('UART_RX',pcbnew.F_Cu,p,q,.25)
if item.GetNetname()=='UART_TX' and abs(ax-137.9)<.001 and abs(bx-137.9)<.001 and abs(ay-83.7)<.001 and abs(by-98.1)<.001:
board.Remove(item)
points=[(137.9,83.7),(137.9,89.0),(137.4,89.5),(137.4,93.3),(137.9,93.8),(137.9,98.1)]
for p,q in zip(points,points[1:]):track('UART_TX',pcbnew.F_Cu,p,q,.25)
# Move the setpoint layer transfer clear of a wider drain bend, preserving its net/endpoints.
for item in board.GetTracks():
if item.GetNetname()=='I_SET':
endpoints=[(item.GetPosition,item.SetPosition)] if isinstance(item,pcbnew.PCB_VIA) else [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]
for getter,setter in endpoints:
p=getter()
if abs(pcbnew.ToMM(p.x)-125)<.001 and abs(pcbnew.ToMM(p.y)-88.4)<.001:p.y=pcbnew.FromMM(88);setter(p)
if isinstance(item,pcbnew.PCB_VIA) or item.GetNetname()!='LOAD_POS' or item.GetLayer()!=pcbnew.B_Cu:continue
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
p=getter();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(x-126.35)<.001 and abs(y-88.85)<.001:p.y=pcbnew.FromMM(89);setter(p)
if abs(x-125.5)<.001 and abs(y-89.7)<.001:p.x=pcbnew.FromMM(125.65);setter(p)
a=item.GetStart();b=item.GetEnd();ax,ay=pcbnew.ToMM(a.x),pcbnew.ToMM(a.y);bx,by=pcbnew.ToMM(b.x),pcbnew.ToMM(b.y)
if abs(ay-89.7)<.001 and abs(by-89.7)<.001:item.SetWidth(pcbnew.FromMM(1.75))
if abs(ax-bx)>.1 and abs(ay-by)>.1 and min(ax,bx)>125 and max(ax,bx)<127 and min(ay,by)>88.8 and max(ay,by)<89.8:item.SetWidth(pcbnew.FromMM(1.75))
# This local gate-drive segment carries the servo/gate current, not DUT current.
# Keep 0.5 mm copper and create clearance to the small setpoint via.
for item in board.GetTracks():
if str(item.m_Uuid.AsString())=='a4e6790e-b900-47a1-bf1e-b5fb98adc8c7':item.SetWidth(pcbnew.FromMM(.5))
# Separate thermal-spread experiment, not a replacement of the accepted zone plan.
for z in list(board.Zones()):
if not z.GetZoneName().startswith('D1 relocated heat spread'):continue
layer=z.GetLayer();name=z.GetZoneName();board.Remove(z)
z=pcbnew.ZONE(board);z.SetLayer(layer);z.SetNet(nets['LOAD_POS']);z.SetZoneName(name);z.SetAssignedPriority(3);z.SetLocalClearance(pcbnew.FromMM(.2));z.SetMinThickness(pcbnew.FromMM(.25));z.SetPadConnection(pcbnew.ZONE_CONNECTION_FULL);z.Outline().NewOutline()
points=[(114,82),(132,82),(132,99),(104,99),(104,89.4),(114,89.4)] if layer==pcbnew.F_Cu else [(118.8,70),(132,70),(132,99),(104,99),(104,89.4),(114,89.4),(114,84),(118.8,84)]
for x,y in points:z.Outline().Append(pcbnew.FromMM(x),pcbnew.FromMM(y))
board.Add(z)
# Shorter board-to-board heat paths beside the diode cathode, outside its solder pad.
for x in [115.6,119.2]:
for y in ([90.2,90.9] if x==115.6 else [90.2,91.4]):
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(x),pcbnew.FromMM(y)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['LOAD_POS']);board.Add(via)
# Clearance-aware ground connection to the existing lower return plane.
track('GND',pcbnew.F_Cu,(112.728,88.696),(112.7,88.8),.4)
track('GND',pcbnew.F_Cu,(112.7,88.8),(112.7,99.5),.4)
# Restore the displaced signal-ground region; native checks remain mandatory.
track('GND',pcbnew.B_Cu,(117.1, 77.2),(116.0, 77.2),.25)
track('GND',pcbnew.B_Cu,(116.0, 77.2),(115.4, 77.8),.25)
track('GND',pcbnew.B_Cu,(115.4, 77.8),(114.9, 77.8),.25)
track('GND',pcbnew.B_Cu,(114.9, 77.8),(113.8, 78.9),.25)
track('GND',pcbnew.B_Cu,(113.8, 78.9),(106.4, 78.9),.25)
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(106.4),pcbnew.FromMM(78.9)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['GND']);board.Add(via)
track('GND',pcbnew.F_Cu,(106.4, 78.9),(105.9, 79.4),.25)
track('GND',pcbnew.F_Cu,(105.9, 79.4),(105.9, 79.5),.25)
track('GND',pcbnew.F_Cu,(105.9, 79.5),(105.8, 79.6),.25)
track('GND',pcbnew.F_Cu,(105.8, 79.6),(105.8, 80.1),.25)
track('GND',pcbnew.F_Cu,(105.8, 80.1),(105.3, 80.6),.25)
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(105.3),pcbnew.FromMM(80.6)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['GND']);board.Add(via)
# Isolated SDT10A45P5-7 feasibility layout; schematic/BOM are not changed here.
old=next(fp for fp in board.GetFootprints() if fp.GetReference()=='D1')
new=pcbnew.FootprintLoad('C:/Users/john/AppData/Local/Programs/KiCad/10.0/share/kicad/footprints/Diode_SMD.pretty','D_PowerDI-5')
assert new is not None
new.SetReference('D1');new.SetValue('SDT10A45P5-7');new.SetFPID(pcbnew.LIB_ID('Diode_SMD','D_PowerDI-5'))
board.Add(new);new.SetOrientationDegrees(180);new.SetPosition(old.GetPosition())
for a,b in [(new.Reference(),old.Reference()),(new.Value(),old.Value())]:
a.SetPosition(b.GetPosition());a.SetTextAngle(b.GetTextAngle());a.SetTextSize(b.GetTextSize());a.SetTextThickness(b.GetTextThickness());a.SetVisible(b.IsVisible())
for pad in new.Pads():pad.SetNet(nets['LOAD_POS' if pad.GetNumber()=='1' else 'DUT_FUSED'])
board.Remove(old)
# Keep unfilled vias outside the new exposed cathode solder land.
for item in list(board.GetTracks()):
if item.GetNetname()=='LOAD_POS' and isinstance(item,pcbnew.PCB_VIA):
p=item.GetPosition();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if 112.39<x<117.85 and 89.02<y<92.98:board.Remove(item);continue
if item.GetNetname()=='GND' and not isinstance(item,pcbnew.PCB_VIA) and item.GetLayer()==pcbnew.F_Cu:
for getter,setter in [(item.GetStart,item.SetStart),(item.GetEnd,item.SetEnd)]:
p=getter();x,y=pcbnew.ToMM(p.x),pcbnew.ToMM(p.y)
if abs(x-112.7)<.001:
p.x=pcbnew.FromMM(112.25)
if abs(y-88.8)<.001:p.y=pcbnew.FromMM(89.174)
setter(p)
# Both anodes explicitly join the existing fused-input junction.
for path in [[(110.6,91),(110.6,90.618),(111.138,90.08)],[(110.6,91),(110.6,91.382),(111.138,91.92)]]:
for a,b in zip(path,path[1:]):track('DUT_FUSED',pcbnew.F_Cu,a,b,1.0)
changes.append({'kind':'feasibility-replace-footprint','reference':'D1','candidateMPN':'SDT10A45P5-7','footprint':'Diode_SMD:D_PowerDI-5','adopted':False})
for x,y in [[115.2, 93.2], [114.2, 93.2], [116.2, 93.2], [116.6, 88.8], [118.0, 91.0], [113.2, 93.2], [115.0, 94.0], [118.0, 90.0]]:
via=pcbnew.PCB_VIA(board);via.SetPosition(pcbnew.VECTOR2I(pcbnew.FromMM(x),pcbnew.FromMM(y)));via.SetWidth(pcbnew.FromMM(.6));via.SetDrill(pcbnew.FromMM(.3));via.SetLayerPair(pcbnew.F_Cu,pcbnew.B_Cu);via.SetNet(nets['LOAD_POS']);board.Add(via)
expected_nets={str(item.m_Uuid.AsString()):item.GetNetname() for item in board.GetTracks()}
for zone in board.Zones():
zone.UnFill()
zone.SetNeedRefill(True)
board.BuildConnectivity()
actual_nets={str(item.m_Uuid.AsString()):item.GetNetname() for item in board.GetTracks()}
assert actual_nets==expected_nets, {'unexpectedNetChanges':[(k,v,actual_nets.get(k)) for k,v in expected_nets.items() if actual_nets.get(k)!=v]}
for zone in board.Zones():zone.SetNeedRefill(True)
pcbnew.ZONE_FILLER(board).Fill(board.Zones());assert {str(item.m_Uuid.AsString()):item.GetNetname() for item in board.GetTracks()}==expected_nets, 'Zone fill changed copper nets'
pcbnew.SaveBoard(str(out),board)
readback=pcbnew.LoadBoard(str(out))
assert {str(item.m_Uuid.AsString()):item.GetNetname() for item in readback.GetTracks()}==expected_nets, 'Save/readback changed copper nets'
out.with_suffix('.changes.json').write_text(json.dumps({'source':str(source),'candidate':str(out),'changes':changes},indent=2));print(json.dumps({'saved':str(out),'changes':changes}))