Skip to content

Commit 706ab17

Browse files
author
devbisme
committed
Expand indices and account for pin aliases when removing, swapping, renumbering, renaming pins.
1 parent 580c537 commit 706ab17

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/skidl/mixins.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
PinMixin: Adds pin management functionality to parts and other objects.
1010
"""
1111

12+
import sys
1213
from .logger import active_logger
1314
from .skidlbaseobj import SkidlBaseObject
1415
from .utilities import (
@@ -385,12 +386,17 @@ def rmv_pins(self, *pin_ids):
385386
>>> part.rmv_pins('VCC', 'GND') # Remove power pins
386387
"""
387388

389+
# Expand pin_ids to a flat list of individual pin numbers/names.
390+
pin_ids = list(set(expand_indices(0, sys.maxsize, False, *pin_ids)))
391+
388392
# All pin numbers and names are stored as strings, so convert ids to strings.
389393
pin_ids = [str(pin_id) for pin_id in pin_ids]
390394

391395
# Remove pins in reverse order to avoid index shifting issues.
392396
for i, pin in reversed(tuple(enumerate(self))):
393-
if pin.num in pin_ids or pin.name in pin_ids:
397+
# Look for an intersection of the pin name and aliases with the pin_ids to remove.
398+
pin_id = set((pin.num, *pin.aliases))
399+
if not pin_id.isdisjoint(pin_ids):
394400
del self.pins[i]
395401

396402
def swap_pins(self, pin_id1, pin_id2):
@@ -417,7 +423,7 @@ def swap_pins(self, pin_id1, pin_id2):
417423
pins = self.pins
418424
i1, i2 = None, None
419425
for i, pin in enumerate(pins):
420-
pin_num_name = (pin.num, pin.name)
426+
pin_num_name = (pin.num, *pin.aliases)
421427
if pin_id1 in pin_num_name:
422428
i1 = i
423429
elif pin_id2 in pin_num_name:
@@ -452,7 +458,7 @@ def rename_pin(self, pin_id, new_pin_name):
452458
# All pin numbers and names are stored as strings, so convert id to string.
453459
pin_id = str(pin_id)
454460
for pin in self:
455-
if pin_id in (pin.num, pin.name):
461+
if pin_id in (pin.num, *pin.aliases):
456462
# Found pin so change its name
457463
pin.name = new_pin_name
458464
return
@@ -476,7 +482,7 @@ def renumber_pin(self, pin_id, new_pin_num):
476482
# All pin numbers and names are stored as strings, so convert id to string.
477483
pin_id = str(pin_id)
478484
for pin in self:
479-
if pin_id in (pin.num, pin.name):
485+
if pin_id in (pin.num, *pin.aliases):
480486
# Found pin so change its number
481487
pin.num = new_pin_num
482488
return

0 commit comments

Comments
 (0)