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
committed by Eugene Mikhantyev
parent f494f5fb37
commit ab2500fb8d
3 changed files with 17 additions and 15 deletions

View File

@@ -255,8 +255,9 @@ class ComponentManager:
# Generate new UUID
new_symbol.uuid.value = str(uuid.uuid4())
# Append to schematic
schematic.symbol.append(new_symbol)
# NOTE: clone() already inserts the raw element into the schematic tree.
# Calling schematic.symbol.append() again causes NamedCollection to detect
# the reference as "taken" and rename it to "R1_" (trailing underscore).
logger.info(f"Successfully added component {reference} to schematic")
return new_symbol