Merge pull request #103 from tecnovel/main
fix: correct pin location, symbol reference dedup, and ERC violation parsing
This commit is contained in:
@@ -193,6 +193,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
|
||||
|
||||
@@ -206,7 +210,7 @@ class PinLocator:
|
||||
self._schematic_cache[sch_key] = Schematic(sch_key)
|
||||
sch = self._schematic_cache[sch_key]
|
||||
for symbol in sch.symbol:
|
||||
if symbol.property.Reference.value == symbol_reference:
|
||||
if symbol.property.Reference.value.rstrip("_") == symbol_reference:
|
||||
return symbol.lib_id.value if hasattr(symbol, "lib_id") else None
|
||||
except Exception:
|
||||
pass
|
||||
@@ -229,7 +233,7 @@ class PinLocator:
|
||||
|
||||
target_symbol = None
|
||||
for symbol in sch.symbol:
|
||||
if symbol.property.Reference.value == symbol_reference:
|
||||
if symbol.property.Reference.value.rstrip("_") == symbol_reference:
|
||||
target_symbol = symbol
|
||||
break
|
||||
|
||||
@@ -302,10 +306,11 @@ class PinLocator:
|
||||
self._schematic_cache[sch_key] = Schematic(sch_key)
|
||||
sch = self._schematic_cache[sch_key]
|
||||
|
||||
# Find the symbol instance
|
||||
# Find the symbol instance.
|
||||
# skip may write references with a trailing "_" (e.g. "R1_") — strip it when comparing.
|
||||
target_symbol = None
|
||||
for symbol in sch.symbol:
|
||||
ref = symbol.property.Reference.value
|
||||
ref = symbol.property.Reference.value.rstrip("_")
|
||||
if ref == symbol_reference:
|
||||
target_symbol = symbol
|
||||
break
|
||||
@@ -371,9 +376,11 @@ class PinLocator:
|
||||
|
||||
pin_data = pins[pin_number]
|
||||
|
||||
# Get pin position relative to symbol origin
|
||||
# Get pin position relative to symbol origin.
|
||||
# lib_symbols uses library y-up convention; schematic uses y-down.
|
||||
# Negate y here before rotation, matching KiCad's transform order.
|
||||
pin_rel_x = pin_data["x"]
|
||||
pin_rel_y = pin_data["y"]
|
||||
pin_rel_y = -pin_data["y"]
|
||||
|
||||
logger.debug(f"Pin {pin_number} relative position: ({pin_rel_x}, {pin_rel_y})")
|
||||
|
||||
@@ -430,7 +437,7 @@ class PinLocator:
|
||||
# Find symbol
|
||||
target_symbol = None
|
||||
for symbol in sch.symbol:
|
||||
if symbol.property.Reference.value == symbol_reference:
|
||||
if symbol.property.Reference.value.rstrip("_") == symbol_reference:
|
||||
target_symbol = symbol
|
||||
break
|
||||
|
||||
@@ -481,9 +488,7 @@ if __name__ == "__main__":
|
||||
|
||||
# Create test schematic with components (cross-platform temp directory)
|
||||
test_path = Path(tempfile.gettempdir()) / "test_pin_locator.kicad_sch"
|
||||
template_path = (
|
||||
Path(__file__).parent.parent / "templates" / "template_with_symbols_expanded.kicad_sch"
|
||||
)
|
||||
template_path = Path(__file__).parent.parent / "templates" / "template_with_symbols.kicad_sch"
|
||||
|
||||
shutil.copy(template_path, test_path)
|
||||
print(f"\n✓ Created test schematic: {test_path}")
|
||||
|
||||
Reference in New Issue
Block a user