Rename connector attributes (#77)
Rename `pinnumbers` to `pins`. Rename `pinout` to `pinlabels`.
This commit is contained in:
parent
6468c0e2a5
commit
a1881eb49d
@ -19,8 +19,8 @@ class Connector:
|
|||||||
subtype: Optional[str] = None
|
subtype: Optional[str] = None
|
||||||
pincount: Optional[int] = None
|
pincount: Optional[int] = None
|
||||||
notes: Optional[str] = None
|
notes: Optional[str] = None
|
||||||
pinout: List[Any] = field(default_factory=list)
|
pinlabels: List[Any] = field(default_factory=list)
|
||||||
pinnumbers: List[Any] = field(default_factory=list)
|
pins: List[Any] = field(default_factory=list)
|
||||||
color: Optional[str] = None
|
color: Optional[str] = None
|
||||||
show_name: bool = None
|
show_name: bool = None
|
||||||
show_pincount: bool = None
|
show_pincount: bool = None
|
||||||
@ -39,25 +39,25 @@ class Connector:
|
|||||||
self.pincount = 1
|
self.pincount = 1
|
||||||
|
|
||||||
if self.pincount is None:
|
if self.pincount is None:
|
||||||
if self.pinout:
|
if self.pinlabels:
|
||||||
self.pincount = len(self.pinout)
|
self.pincount = len(self.pinlabels)
|
||||||
elif self.pinnumbers:
|
elif self.pins:
|
||||||
self.pincount = len(self.pinnumbers)
|
self.pincount = len(self.pins)
|
||||||
else:
|
else:
|
||||||
raise Exception('You need to specify at least one, pincount, pinout or pinnumbers')
|
raise Exception('You need to specify at least one, pincount, pins or pinlabels')
|
||||||
|
|
||||||
if self.pinout and self.pinnumbers:
|
if self.pinlabels and self.pins:
|
||||||
if len(self.pinout) != len(self.pinnumbers):
|
if len(self.pinlabels) != len(self.pins):
|
||||||
raise Exception('Given pinout and pinnumbers size mismatch')
|
raise Exception('Given pins and pinlabels size mismatch')
|
||||||
|
|
||||||
# create default lists for pinnumbers (sequential) and pinouts (blank) if not specified
|
# create default lists for pins (sequential) and pinlabels (blank) if not specified
|
||||||
if not self.pinnumbers:
|
if not self.pins:
|
||||||
self.pinnumbers = list(range(1, self.pincount + 1))
|
self.pins = list(range(1, self.pincount + 1))
|
||||||
if not self.pinout:
|
if not self.pinlabels:
|
||||||
self.pinout = [''] * self.pincount
|
self.pinlabels = [''] * self.pincount
|
||||||
|
|
||||||
if len(self.pinnumbers) != len(set(self.pinnumbers)):
|
if len(self.pins) != len(set(self.pins)):
|
||||||
raise Exception('Pin numbers are not unique')
|
raise Exception('Pins are not unique')
|
||||||
|
|
||||||
if self.show_name is None:
|
if self.show_name is None:
|
||||||
self.show_name = not self.autogenerate # hide auto-generated designators by default
|
self.show_name = not self.autogenerate # hide auto-generated designators by default
|
||||||
|
|||||||
@ -35,23 +35,23 @@ class Harness:
|
|||||||
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors
|
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors
|
||||||
if name is not None and name in self.connectors:
|
if name is not None and name in self.connectors:
|
||||||
connector = self.connectors[name]
|
connector = self.connectors[name]
|
||||||
if pin in connector.pinnumbers and pin in connector.pinout:
|
if pin in connector.pins and pin in connector.pinlabels:
|
||||||
if connector.pinnumbers.index(pin) == connector.pinout.index(pin):
|
if connector.pins.index(pin) == connector.pinlabels.index(pin):
|
||||||
# TODO: Maybe issue a warning? It's not worthy of an exception if it's unambiguous, but maybe risky?
|
# TODO: Maybe issue a warning? It's not worthy of an exception if it's unambiguous, but maybe risky?
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
raise Exception(f'{name}:{pin} is defined both in pinout and pinnumbers, for different pins.')
|
raise Exception(f'{name}:{pin} is defined both in pinlabels and pins, for different pins.')
|
||||||
if pin in connector.pinout:
|
if pin in connector.pinlabels:
|
||||||
if connector.pinout.count(pin) > 1:
|
if connector.pinlabels.count(pin) > 1:
|
||||||
raise Exception(f'{name}:{pin} is defined more than once.')
|
raise Exception(f'{name}:{pin} is defined more than once.')
|
||||||
else:
|
else:
|
||||||
index = connector.pinout.index(pin)
|
index = connector.pinlabels.index(pin)
|
||||||
pin = connector.pinnumbers[index] # map pin name to pin number
|
pin = connector.pins[index] # map pin name to pin number
|
||||||
if name == from_name:
|
if name == from_name:
|
||||||
from_pin = pin
|
from_pin = pin
|
||||||
if name == to_name:
|
if name == to_name:
|
||||||
to_pin = pin
|
to_pin = pin
|
||||||
if not pin in connector.pinnumbers:
|
if not pin in connector.pins:
|
||||||
raise Exception(f'{name}:{pin} not found.')
|
raise Exception(f'{name}:{pin} not found.')
|
||||||
|
|
||||||
self.cables[via_name].connect(from_name, from_pin, via_pin, to_name, to_pin)
|
self.cables[via_name].connect(from_name, from_pin, via_pin, to_name, to_pin)
|
||||||
@ -104,16 +104,16 @@ class Harness:
|
|||||||
html = html.replace('><!-- colorbar --></td>', colorbar)
|
html = html.replace('><!-- colorbar --></td>', colorbar)
|
||||||
|
|
||||||
if connector.style != 'simple':
|
if connector.style != 'simple':
|
||||||
pinouts = []
|
pinlist = []
|
||||||
for pinnumber, pinname in zip(connector.pinnumbers, connector.pinout):
|
for pin, pinlabel in zip(connector.pins, connector.pinlabels):
|
||||||
if connector.hide_disconnected_pins and not connector.visible_pins.get(pinnumber, False):
|
if connector.hide_disconnected_pins and not connector.visible_pins.get(pin, False):
|
||||||
continue
|
continue
|
||||||
pinouts.append([f'<td port="p{pinnumber}l">{pinnumber}</td>' if connector.ports_left else None,
|
pinlist.append([f'<td port="p{pin}l">{pin}</td>' if connector.ports_left else None,
|
||||||
f'<td>{pinname}</td>' if pinname else '',
|
f'<td>{pinlabel}</td>' if pinlabel else '',
|
||||||
f'<td port="p{pinnumber}r">{pinnumber}</td>' if connector.ports_right else None])
|
f'<td port="p{pin}r">{pin}</td>' if connector.ports_right else None])
|
||||||
|
|
||||||
pinhtml = '<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
|
pinhtml = '<table border="0" cellspacing="0" cellpadding="3" cellborder="1">'
|
||||||
for i, pin in enumerate(pinouts):
|
for i, pin in enumerate(pinlist):
|
||||||
pinhtml = f'{pinhtml}<tr>'
|
pinhtml = f'{pinhtml}<tr>'
|
||||||
for column in pin:
|
for column in pin:
|
||||||
if column is not None:
|
if column is not None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user