main
John Lauer Adopt DRC-clean v85 and passing exact-board current screen; retain open cooling validation and reviewed build clips a897f04
"""Remove a contained duplicate conductor in v84; preserve its complete physical copper."""
import pcbnew,sys,json,hashlib
from pathlib import Path
source=Path(sys.argv[1]).parent/'candidate-v84.kicad_pcb';out=Path(sys.argv[2])
assert hashlib.sha256(source.read_bytes()).hexdigest()=='6b705624e4947fd4a33dc22e9e90678a91bac1b48a850afe66f2af689ad7a3e0'
# Edit exactly one serialized item before native load. Avoid KiCad SWIG's
# invalidated track-container wrapper following Remove() in this native build.
import re
text=source.read_text()
uid='1545dafb-f4b1-41cf-ab31-0923b764b28f'
segments=list(re.finditer(r'\n\t\(segment\n.*?\n\t\)',text,re.S))
match=[m for m in segments if uid in m.group()]
assert len(match)==1
item=match[0].group()
assert '(start 110.6 91)' in item and '(end 110.6 90.618)' in item and '(width 1)' in item
retained=[m.group() for m in segments if '29677628-bdf8-4692-bd50-e61f84fe60af' in m.group()]
assert len(retained)==1 and '(start 110.6 91)' in retained[0] and '(end 110.6 88.65)' in retained[0] and '(width 1.2)' in retained[0]
out.write_text(text[:match[0].start()]+text[match[0].end():])
b=pcbnew.LoadBoard(str(out));removed=[uid]
expected={t.m_Uuid.AsString():t.GetNetname() for t in b.GetTracks()}
for z in b.Zones():z.UnFill();z.SetNeedRefill(True)
b.BuildConnectivity();assert expected=={t.m_Uuid.AsString():t.GetNetname() for t in b.GetTracks()}
pcbnew.ZONE_FILLER(b).Fill(b.Zones());pcbnew.SaveBoard(str(out),b)
r=pcbnew.LoadBoard(str(out));assert expected=={t.m_Uuid.AsString():t.GetNetname() for t in r.GetTracks()}
out.with_suffix('.changes.json').write_text(json.dumps({'source':str(source),'candidate':str(out),'removedContainedTrack':removed,'note':'The removed 1 mm segment lies entirely inside the retained 1.2 mm segment. No physical copper is removed; avoid double-counting in the branch resistor graph.'},indent=2)+'\n')