Full solder joint at every populated THT pad, read from KiCad
Build PCM package / build (push) Successful in 8s

No size-threshold guessing: whether a hole is a via or a THT pad
already comes from KiCad (board.get_vias vs drilled board.get_pads).
Every populated THT pad of the net now carries the complete joint the
contacts got: solder-filled barrel, average-thickness coat over a
pad-diameter disc on the outer layers, and the protruding-lead cone on
the side opposite its owning footprint. The footprint side and the
Do-not-populate flag are read from KiCad (footprint pads store absolute
positions, so owner lookup is an exact (x, y, number) map); DNP pads
stay plating-only with no joint. Contact pads are deduplicated by
barrel center so their cone/coat is never applied twice.

Barrels are now gathered in single-layer runs too: via rings and drill
mouths perforate a lone plane, THT joints stiffen it locally.

ViaLink gains solder_filled + protrusion_side (legacy dumps load with
the old every-THT-pad-filled semantics).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
janik
2026-07-16 19:00:09 +07:00
parent 9e307f2818
commit b2277f65bf
7 changed files with 236 additions and 60 deletions
+81 -37
View File
@@ -23,7 +23,8 @@ from . import config
from .errors import ApiVersionError, CandidateError, SelectionError
from .geometry import (Electrode, LayerFill, Polygon, Problem, Rect,
SurfaceBuildup, TrackSeg, ViaLink,
contact_solder_buildups, linearize_ring)
contact_solder_buildups, linearize_ring,
tht_joint_buildups)
MASK_TO_COPPER = {"F.Mask": "F.Cu", "B.Mask": "B.Cu"}
@@ -180,29 +181,42 @@ def _pad_polygons(board: Board, pad: Pad, contact: str) -> list[Polygon] | None:
return None
def _tht_protrusion_side(pad: Pad, footprints) -> str:
"""Outer layer where the clipped THT lead protrudes (tent + solder
cone): the side OPPOSITE the component. Footprint pads are stored
with absolute positions, so the owning footprint is matched by pad
number + position. Unknown owner -> assume the component sits on
F.Cu (lead tents on B.Cu)."""
try:
for fp in footprints or []:
def _footprint_pad_map(footprints) -> dict:
"""(x, y, number) -> owning FootprintInstance. Footprint pads are
stored with absolute positions, so the lookup is exact."""
out = {}
for fp in footprints or []:
try:
for fpad in fp.definition.pads:
if fpad.number == pad.number \
and fpad.position.x == pad.position.x \
and fpad.position.y == pad.position.y:
side = canonical_name(fp.layer)
return "F.Cu" if side == "B.Cu" else "B.Cu"
except Exception:
pass
print(f"note: no footprint found for pad {pad.number} - assuming its "
f"lead protrudes on B.Cu")
out[(fpad.position.x, fpad.position.y, fpad.number)] = fp
except Exception:
continue
return out
def _pad_owner(pad: Pad, pad_map: dict):
return pad_map.get((pad.position.x, pad.position.y, pad.number))
def _tht_protrusion_side(pad: Pad, pad_map: dict, quiet: bool = False) -> str:
"""Outer layer where the clipped THT lead protrudes (tent + solder
cone): the side OPPOSITE the component. Unknown owner -> assume the
component sits on F.Cu (lead tents on B.Cu)."""
fp = _pad_owner(pad, pad_map)
if fp is not None:
try:
side = canonical_name(fp.layer)
return "F.Cu" if side == "B.Cu" else "B.Cu"
except Exception:
pass
if not quiet:
print(f"note: no footprint found for pad {pad.number} - assuming "
f"its lead protrudes on B.Cu")
return "B.Cu"
def _to_electrode(board: Board, item, stackup: StackupInfo | None = None,
footprints=None) -> Electrode:
pad_map: dict | None = None) -> Electrode:
if isinstance(item, BoardRectangle):
tl, br = item.top_left, item.bottom_right
rect = Rect.normalized(tl.x, tl.y, br.x, br.y,
@@ -245,7 +259,7 @@ def _to_electrode(board: Board, item, stackup: StackupInfo | None = None,
drill_nm=drill, pad_nm=_padstack_pad_nm(pad),
center=(pad.position.x, pad.position.y),
solder=drill > 0,
protrusion_side=(_tht_protrusion_side(pad, footprints)
protrusion_side=(_tht_protrusion_side(pad, pad_map or {})
if drill > 0 else None))
@@ -282,9 +296,9 @@ def get_electrodes(board: Board, stackup: StackupInfo | None = None
rects = [s for s in selection if isinstance(s, BoardRectangle)]
pads = [s for s in selection if isinstance(s, (Pad, Via))]
# protrusion-side lookup needs the owning footprints (THT pads only)
footprints = (board.get_footprints()
if any(isinstance(s, Pad) and _pad_drill_nm(s) > 0
for s in pads) else None)
pad_map = (_footprint_pad_map(board.get_footprints())
if any(isinstance(s, Pad) and _pad_drill_nm(s) > 0
for s in pads) else {})
if not selection:
allr = [s for s in board.get_shapes() if isinstance(s, BoardRectangle)]
@@ -320,7 +334,7 @@ def get_electrodes(board: Board, stackup: StackupInfo | None = None
f"only for a side that has none."
)
if pads:
pad_parts = [_to_electrode(board, p, stackup, footprints)
pad_parts = [_to_electrode(board, p, stackup, pad_map)
for p in pads]
if not es1:
es1 = pad_parts
@@ -335,8 +349,8 @@ def get_electrodes(board: Board, stackup: StackupInfo | None = None
items = rects + pads
if len(items) == 2:
return ([_to_electrode(board, items[0], stackup, footprints)],
[_to_electrode(board, items[1], stackup, footprints)],
return ([_to_electrode(board, items[0], stackup, pad_map)],
[_to_electrode(board, items[1], stackup, pad_map)],
_net_hint_of(pads))
raise SelectionError(
f"The selection has {len(rects)} rectangle(s) (none on the marker "
@@ -503,16 +517,35 @@ def gather_barrels(board: Board, net_name: str,
z_bot_nm=z_bot, kind="via",
pad_nm=_padstack_pad_nm(via)))
if config.INCLUDE_TH_PADS:
for pad in board.get_pads():
if pad.net is None or pad.net.name != net_name:
continue
drill = _pad_drill_nm(pad)
if drill <= 0:
continue
barrels.append(ViaLink(x=pad.position.x, y=pad.position.y,
drill_nm=drill, z_top_nm=-1,
z_bot_nm=stackup.z_bot_nm + 1, kind="pad",
pad_nm=_padstack_pad_nm(pad)))
net_pads = [pad for pad in board.get_pads()
if pad.net is not None and pad.net.name == net_name
and _pad_drill_nm(pad) > 0]
# populated (non-DNP) THT pads carry a soldered joint: filled
# hole + coat + lead cone on the side opposite the component
pad_map = (_footprint_pad_map(board.get_footprints())
if net_pads else {})
unknown = 0
for pad in net_pads:
fp = _pad_owner(pad, pad_map)
unknown += fp is None
populated = True
if fp is not None:
try:
populated = not fp.attributes.do_not_populate
except Exception:
pass
barrels.append(ViaLink(
x=pad.position.x, y=pad.position.y,
drill_nm=_pad_drill_nm(pad), z_top_nm=-1,
z_bot_nm=stackup.z_bot_nm + 1, kind="pad",
pad_nm=_padstack_pad_nm(pad),
solder_filled=populated,
protrusion_side=(_tht_protrusion_side(pad, pad_map,
quiet=True)
if populated else None)))
if unknown:
print(f"note: {unknown} THT pad(s) without an identifiable "
f"footprint - assumed populated, leads on B.Cu")
return barrels
@@ -550,7 +583,9 @@ def build_problem(board: Board, net: str, layer_names: list[str],
f"Net {net} has no fill on any of the selected layers "
f"({', '.join(layer_names)})."
)
vias = gather_barrels(board, net, stackup) if len(layers) > 1 else []
# barrels matter on a single layer too: via rings + drill mouths
# perforate the plane, THT joints locally stiffen it
vias = gather_barrels(board, net, stackup)
included = {l.layer_name for l in layers}
buildup_list = [
SurfaceBuildup(layer_name=name, polygons=polys)
@@ -597,6 +632,15 @@ def build_problem(board: Board, net: str, layer_names: list[str],
print(f"THT contact(s): solder-filled hole + "
f"{config.SOLDER_THICKNESS_UM:g} um average solder coat on the "
f"pad face ({', '.join(solder_layers)}){cone}")
tht_joint_buildups(problem)
n_joint = sum(1 for v in problem.vias
if v.kind == "pad" and v.solder_filled)
n_dnp = sum(1 for v in problem.vias
if v.kind == "pad" and not v.solder_filled)
if n_joint or n_dnp:
print(f"{n_joint} populated THT pad joint(s): solder-filled hole + "
f"coat + lead cone"
+ (f"; {n_dnp} DNP pad(s) plating-only" if n_dnp else ""))
return problem
+45 -1
View File
@@ -134,6 +134,14 @@ class ViaLink:
z_bot_nm: int
kind: str = "via" # "via" | "pad"
pad_nm: int = 0 # pad/annular diameter; 0 = unknown
solder_filled: bool = False # populated THT pad: the hole is
# solder-filled (core in parallel
# with the plating); False for
# vias and DNP footprints
protrusion_side: str | None = None # populated THT pad: outer layer
# where the clipped lead tents
# (solder cone), opposite the
# component side
def spans(self, z_nm: int) -> bool:
return self.z_top_nm - 1 <= z_nm <= self.z_bot_nm + 1
@@ -227,6 +235,38 @@ def contact_solder_buildups(problem: Problem) -> list[str]:
return sorted(set(touched))
def _disc_polygon(x_nm: float, y_nm: float, r_nm: float,
n: int = 32) -> Polygon:
th = np.linspace(0.0, 2.0 * math.pi, n, endpoint=False)
return Polygon(outline=np.round(np.stack(
[x_nm + r_nm * np.cos(th), y_nm + r_nm * np.sin(th)],
axis=1)).astype(np.int64))
def tht_joint_buildups(problem: Problem) -> list[str]:
"""Solder coat of the net's populated STITCHING through-hole pads
(ViaLink kind 'pad' with solder_filled): one pad-diameter disc per
outer layer - the exact pad shape is unknown for non-contact pads,
and the coat intersects the modeled copper at raster time anyway.
Contact pads are skipped: contact_solder_buildups already coats
them with the exact pad shape. Returns the affected layer names."""
included = {l.layer_name for l in problem.layers}
outer = [n for n in ("F.Cu", "B.Cu") if n in included]
contacts = {e.center for e in problem.electrodes1 + problem.electrodes2
if e.drill_nm > 0 and e.center is not None}
touched = []
for v in problem.vias:
if v.kind != "pad" or not v.solder_filled \
or v.pad_nm <= v.drill_nm or (v.x, v.y) in contacts:
continue
disc = _disc_polygon(v.x, v.y, v.pad_nm / 2.0)
for name in outer:
problem.buildups.append(
SurfaceBuildup(layer_name=name, polygons=[disc]))
touched.append(name)
return sorted(set(touched))
def _arc_params(start, mid, end) -> tuple[float, float, float, float, float] | None:
"""Circle through three points: (cx, cy, r, a0, sweep) with a0 the
start angle and sweep signed; None if the points are collinear."""
@@ -485,7 +525,11 @@ def problem_from_json(d: dict) -> Problem:
ViaLink(x=int(vd["x"]), y=int(vd["y"]), drill_nm=int(vd["drill_nm"]),
z_top_nm=int(vd["z_top_nm"]), z_bot_nm=int(vd["z_bot_nm"]),
kind=vd.get("kind", "via"),
pad_nm=int(vd.get("pad_nm", 0)))
pad_nm=int(vd.get("pad_nm", 0)),
# older dumps: every THT pad counted as solder-filled
solder_filled=bool(vd.get(
"solder_filled", vd.get("kind", "via") == "pad")),
protrusion_side=vd.get("protrusion_side"))
for vd in d["vias"]
],
electrodes1=(
+23 -8
View File
@@ -238,9 +238,10 @@ def rasterize_stack(problem: Problem, h_nm: float) -> RasterStack:
def _paint_lead_fillets(stack: RasterStack, problem: Problem) -> None:
"""Protruding THT leads of soldered barrel contacts: the clipped
lead sticks tht_protrusion_nm out of the hole on the side opposite
the component, wrapped by a solder cone - full protrusion height at
"""Protruding THT leads (barrel contacts AND the net's populated
stitching through-hole pads): the clipped lead sticks
tht_protrusion_nm out of the hole on the side opposite the
component, wrapped by a solder cone - full protrusion height at
the drill wall, tapering linearly to zero at the pad edge. Modeled
as extra conduction-equivalent copper via stack.thick_scale: the
tall solder column next to the wall pulls those cells to lead
@@ -254,18 +255,32 @@ def _paint_lead_fillets(stack: RasterStack, problem: Problem) -> None:
ny, nx = stack.shape2d
h = stack.h_nm
index = {name: li for li, name in enumerate(stack.layer_names)}
# one cone per joint: contact electrodes first (exact data), then the
# net's populated stitching THT pads, skipping the contacts' barrels
jobs = []
seen = set()
for e in problem.electrodes1 + problem.electrodes2:
if not (e.solder and e.drill_nm > 0 and e.protrusion_side):
continue
li = index.get(e.protrusion_side)
if li is None or e.pad_nm <= e.drill_nm:
if e.drill_nm <= 0:
continue
if e.center is not None:
x, y = e.center
else:
x = (e.rect.x0 + e.rect.x1) / 2.0
y = (e.rect.y0 + e.rect.y1) / 2.0
ra, rb = e.drill_nm / 2.0, e.pad_nm / 2.0
seen.add((int(x), int(y)))
if e.solder and e.protrusion_side:
jobs.append((x, y, e.drill_nm, e.pad_nm, e.protrusion_side))
for v in problem.vias:
if v.kind == "pad" and v.solder_filled and v.protrusion_side \
and (v.x, v.y) not in seen:
jobs.append((v.x, v.y, v.drill_nm, v.pad_nm, v.protrusion_side))
for x, y, drill_nm, pad_nm, side in jobs:
li = index.get(side)
if li is None or pad_nm <= drill_nm:
continue
ra, rb = drill_nm / 2.0, pad_nm / 2.0
j0 = max(0, math.floor((x - rb - stack.x0_nm) / h))
j1 = min(nx, math.floor((x + rb - stack.x0_nm) / h) + 1)
i0 = max(0, math.floor((y - rb - stack.y0_nm) / h))
+4 -3
View File
@@ -178,12 +178,13 @@ def _barrel_links(stack: RasterStack, problem: Problem
length = problem.layers[lb].z_nm - problem.layers[la].z_nm
if length <= 0:
continue
# THT pads carry a soldered component lead: the hole is
# solder-filled, the core conducts in parallel with the plating
# populated THT pads carry a soldered component lead: the hole
# is solder-filled, the core conducts in parallel with the
# plating (DNP pads and vias stay plating-only)
r_dc = via.barrel_resistance(
length, problem.rho_ohm_m, problem.plating_nm,
solder_rho_ohm_m=(problem.solder_rho_ohm_m
if via.kind == "pad" else None))
if via.solder_filled else None))
links.append((vi, la, ia, ja, lb, ib, jb, r_dc))
return links, dead