Skip to content

Commit d9e1566

Browse files
lfyyshclaude
andcommitted
schematic: revert IC redistribution — breaks connectivity-aware placement
The redistribution shifted IC groups apart vertically, disconnecting related components (switches from their shift registers, etc.). The wider step_size from mm-to-mils conversion is the right fix for stagger spacing; moving ICs post-placement is too aggressive. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 9a3c613 commit d9e1566

1 file changed

Lines changed: 1 addition & 99 deletions

File tree

src/skidl/tools/kicad9/gen_schematic.py

Lines changed: 1 addition & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -722,9 +722,6 @@ def _pin_sort_key(entry, _ic_part=ic_part, _ic_dir=ic_dir):
722722
anti = anti_perp.get(perp_dir, perp_dir)
723723
extend_dirs = [perp_dir, anti] if parts_per_pin >= 2 else [perp_dir]
724724

725-
group_parts = []
726-
group_wires = []
727-
728725
for pin_idx, (ic_pin, parts_list) in enumerate(matching):
729726
ic_pin_world = ic_pin.pt * ic_part.tx
730727

@@ -742,109 +739,14 @@ def _pin_sort_key(entry, _ic_part=ic_part, _ic_dir=ic_dir):
742739
)
743740
snapped.add(id(part))
744741
suppressed_pins.add(id(my_pin))
745-
group_parts.append(part)
746-
747-
group_wires.append(
742+
junction_wires.append(
748743
(ic_pin_world.x, ic_pin_world.y, ox, oy)
749744
)
750745

751-
stagger_groups.append({
752-
"ic_part": ic_part,
753-
"parts": group_parts,
754-
"wires": group_wires,
755-
"ic_dir": ic_dir,
756-
"n_pins": len(matching),
757-
"step_size": step_size,
758-
})
759-
760-
# Redistribute IC groups vertically so stagger fans don't overlap.
761-
if len(stagger_groups) > 1:
762-
_redistribute_stagger_groups(stagger_groups, node, snapped)
763-
764-
for grp in stagger_groups:
765-
junction_wires.extend(grp["wires"])
766-
767746
node._tjunction_wires = junction_wires
768747
node._tjunction_suppressed_pins = suppressed_pins
769748

770749

771-
def _redistribute_stagger_groups(groups, node, snapped):
772-
"""Shift IC groups vertically so their stagger fans don't overlap."""
773-
774-
for grp in groups:
775-
_collect_ic_dependents(grp, node, snapped)
776-
777-
def _group_bbox(grp):
778-
all_parts = [grp["ic_part"]] + grp["all_deps"]
779-
min_y = float("inf")
780-
max_y = float("-inf")
781-
782-
for part in all_parts:
783-
for pin in part.pins:
784-
w = pin.pt * part.tx
785-
min_y = min(min_y, w.y)
786-
max_y = max(max_y, w.y)
787-
788-
return min_y, max_y
789-
790-
groups.sort(key=lambda g: _group_bbox(g)[0])
791-
792-
margin = 200
793-
prev_max_y = None
794-
795-
for grp in groups:
796-
min_y, max_y = _group_bbox(grp)
797-
798-
if prev_max_y is not None and min_y < prev_max_y + margin:
799-
shift = (prev_max_y + margin) - min_y
800-
_shift_group(grp, 0, shift)
801-
min_y += shift
802-
max_y += shift
803-
804-
prev_max_y = max_y
805-
806-
807-
def _collect_ic_dependents(grp, node, snapped):
808-
"""Find all snapped 2-pin parts connected to this IC (not just stagger parts)."""
809-
ic = grp["ic_part"]
810-
ic_id = id(ic)
811-
deps = set(id(p) for p in grp["parts"])
812-
deps.add(ic_id)
813-
814-
for part in node.parts:
815-
if id(part) in deps or id(part) not in snapped:
816-
continue
817-
if not _is_two_pin_part(part):
818-
continue
819-
for pin in part.pins:
820-
net = getattr(pin, "net", None)
821-
if not net:
822-
continue
823-
for net_pin in net.pins:
824-
if net_pin.part is ic:
825-
deps.add(id(part))
826-
break
827-
if id(part) in deps:
828-
break
829-
830-
grp["all_deps"] = [p for p in node.parts if id(p) in deps and p is not ic]
831-
832-
833-
def _shift_group(grp, dx, dy):
834-
"""Shift an IC and all its dependent parts by (dx, dy)."""
835-
vec = Point(dx, dy)
836-
all_parts = [grp["ic_part"]] + grp["all_deps"]
837-
shifted_ids = set()
838-
for part in all_parts:
839-
if id(part) not in shifted_ids:
840-
part.tx = part.tx.move(vec)
841-
shifted_ids.add(id(part))
842-
grp["wires"] = [
843-
(x1 + dx, y1 + dy, x2 + dx, y2 + dy)
844-
for (x1, y1, x2, y2) in grp["wires"]
845-
]
846-
847-
848750
def _stub_all_non_explicit(circuit):
849751
"""Stub all nets that weren't explicitly set by the user (labels-only fallback).
850752

0 commit comments

Comments
 (0)