fix: correct pin location calculation and symbol reference dedup in kicad-skip

Three bugs fixed in the schematic component and pin locator pipeline:

1. component_schematic: remove redundant symbol.append() after clone()
   kicad-skip's clone() already inserts the raw element into the schematic
   tree. The subsequent NamedCollection.append() detects the reference as
   already registered (from the elementRename triggered by setting
   property.Reference.value) and renames it "R1_" with a trailing
   underscore, causing all subsequent pin lookups to fail.

2. pin_locator: negate lib y coordinate before rotation
   lib_symbols in .kicad_sch use library y-up convention; schematic
   coordinates use y-down. get_pin_location now negates pin_rel_y before
   applying rotation, matching KiCad's own transform order (same approach
   as _transform_local_point in schematic_analysis.py).

3. pin_locator: add .rstrip("_") guard in all symbol reference lookups
   Defensive guard against any residual cases where kicad-skip writes a
   trailing underscore to the Reference property value.

Also fixes the self-test script to use template_with_symbols.kicad_sch
(which contains placed _TEMPLATE_* symbols) rather than the expanded
template (which only contains lib_symbols definitions and has no cloneable
instances).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Noah Piqué
2026-04-15 16:20:38 +02:00
parent e164f12ffa
commit ef42eb60bb

View File

@@ -167,6 +167,10 @@ class PinLocator:
cos_a = math.cos(angle_rad)
sin_a = math.sin(angle_rad)
# Standard counter-clockwise rotation (math convention, Y-up).
# Callers are responsible for any y-axis negation required to convert
# library coordinates (y-up) to schematic coordinates (y-down) before
# passing values here — see get_pin_location and _transform_local_point.
rotated_x = x * cos_a - y * sin_a
rotated_y = x * sin_a + y * cos_a