Allow referencing wires by color/label (#169,#193)
This commit is contained in:
parent
feff47f47b
commit
03e6077512
@ -181,9 +181,11 @@ class Cable:
|
|||||||
image: Optional[Image] = None
|
image: Optional[Image] = None
|
||||||
notes: Optional[MultilineHypertext] = None
|
notes: Optional[MultilineHypertext] = None
|
||||||
colors: List[Colors] = field(default_factory=list)
|
colors: List[Colors] = field(default_factory=list)
|
||||||
|
wirelabels: List[Wire] = field(default_factory=list)
|
||||||
color_code: Optional[ColorScheme] = None
|
color_code: Optional[ColorScheme] = None
|
||||||
show_name: bool = True
|
show_name: bool = True
|
||||||
show_wirecount: bool = True
|
show_wirecount: bool = True
|
||||||
|
show_wirenumbers: Optional[bool] = None
|
||||||
ignore_in_bom: bool = False
|
ignore_in_bom: bool = False
|
||||||
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
additional_components: List[AdditionalComponent] = field(default_factory=list)
|
||||||
|
|
||||||
@ -233,6 +235,10 @@ class Cable:
|
|||||||
raise Exception('Unknown number of wires. Must specify wirecount or colors (implicit length)')
|
raise Exception('Unknown number of wires. Must specify wirecount or colors (implicit length)')
|
||||||
self.wirecount = len(self.colors)
|
self.wirecount = len(self.colors)
|
||||||
|
|
||||||
|
if self.wirelabels:
|
||||||
|
if self.shield and 's' in self.wirelabels:
|
||||||
|
raise Exception('"s" may not be used as a wire label for a shielded cable.')
|
||||||
|
|
||||||
# if lists of part numbers are provided check this is a bundle and that it matches the wirecount.
|
# if lists of part numbers are provided check this is a bundle and that it matches the wirecount.
|
||||||
for idfield in [self.manufacturer, self.mpn, self.pn]:
|
for idfield in [self.manufacturer, self.mpn, self.pn]:
|
||||||
if isinstance(idfield, list):
|
if isinstance(idfield, list):
|
||||||
@ -243,21 +249,24 @@ class Cable:
|
|||||||
else:
|
else:
|
||||||
raise Exception('lists of part data are only supported for bundles')
|
raise Exception('lists of part data are only supported for bundles')
|
||||||
|
|
||||||
|
# by default, show wire numbers for cables, hide for bundles
|
||||||
|
if not self.show_wirenumbers:
|
||||||
|
self.show_wirenumbers = self.category != 'bundle'
|
||||||
|
|
||||||
for i, item in enumerate(self.additional_components):
|
for i, item in enumerate(self.additional_components):
|
||||||
if isinstance(item, dict):
|
if isinstance(item, dict):
|
||||||
self.additional_components[i] = AdditionalComponent(**item)
|
self.additional_components[i] = AdditionalComponent(**item)
|
||||||
|
|
||||||
# The *_pin arguments accept a tuple, but it seems not in use with the current code.
|
# The *_pin arguments accept a tuple, but it seems not in use with the current code.
|
||||||
def connect(self, from_name: Optional[Designator], from_pin: NoneOrMorePins, via_pin: OneOrMoreWires,
|
def connect(self, from_name: Optional[Designator], from_pin: NoneOrMorePins, via_wire: OneOrMoreWires,
|
||||||
to_name: Optional[Designator], to_pin: NoneOrMorePins) -> None:
|
to_name: Optional[Designator], to_pin: NoneOrMorePins) -> None:
|
||||||
from_pin = int2tuple(from_pin)
|
from_pin = int2tuple(from_pin)
|
||||||
via_pin = int2tuple(via_pin)
|
via_wire = int2tuple(via_wire)
|
||||||
to_pin = int2tuple(to_pin)
|
to_pin = int2tuple(to_pin)
|
||||||
if len(from_pin) != len(to_pin):
|
if len(from_pin) != len(to_pin):
|
||||||
raise Exception('from_pin must have the same number of elements as to_pin')
|
raise Exception('from_pin must have the same number of elements as to_pin')
|
||||||
for i, _ in enumerate(from_pin):
|
for i, _ in enumerate(from_pin):
|
||||||
# self.connections.append((from_name, from_pin[i], via_pin[i], to_name, to_pin[i]))
|
self.connections.append(Connection(from_name, from_pin[i], via_wire[i], to_name, to_pin[i]))
|
||||||
self.connections.append(Connection(from_name, from_pin[i], via_pin[i], to_name, to_pin[i]))
|
|
||||||
|
|
||||||
def get_qty_multiplier(self, qty_multiplier: Optional[CableMultiplier]) -> float:
|
def get_qty_multiplier(self, qty_multiplier: Optional[CableMultiplier]) -> float:
|
||||||
if not qty_multiplier:
|
if not qty_multiplier:
|
||||||
|
|||||||
@ -35,30 +35,46 @@ class Harness:
|
|||||||
def add_bom_item(self, item: dict) -> None:
|
def add_bom_item(self, item: dict) -> None:
|
||||||
self.additional_bom_items.append(item)
|
self.additional_bom_items.append(item)
|
||||||
|
|
||||||
def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_pin: (int, str), to_name: str, to_pin: (int, str)) -> None:
|
def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_wire: (int, str), to_name: str, to_pin: (int, str)) -> None:
|
||||||
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]): # check from and to connectors
|
# check from and to connectors
|
||||||
|
for (name, pin) in zip([from_name, to_name], [from_pin, to_pin]):
|
||||||
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]
|
||||||
|
# check if provided name is ambiguous
|
||||||
if pin in connector.pins and pin in connector.pinlabels:
|
if pin in connector.pins and pin in connector.pinlabels:
|
||||||
if connector.pins.index(pin) == connector.pinlabels.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?
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
raise Exception(f'{name}:{pin} is defined both in pinlabels and pins, for different pins.')
|
raise Exception(f'{name}:{pin} is defined both in pinlabels and pins, for different pins.')
|
||||||
|
# TODO: Maybe issue a warning if present in both lists but referencing the same pin?
|
||||||
if pin in connector.pinlabels:
|
if pin in connector.pinlabels:
|
||||||
if connector.pinlabels.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:
|
index = connector.pinlabels.index(pin)
|
||||||
index = connector.pinlabels.index(pin)
|
pin = connector.pins[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.pins:
|
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)
|
# check via cable
|
||||||
|
if via_name in self.cables:
|
||||||
|
cable = self.cables[via_name]
|
||||||
|
# check if provided name is ambiguous
|
||||||
|
if via_wire in cable.colors and via_wire in cable.wirelabels:
|
||||||
|
if cable.colors.index(via_wire) != cable.wirelabels.index(via_wire):
|
||||||
|
raise Exception(f'{via_name}:{via_wire} is defined both in colors and wirelabels, for different wires.')
|
||||||
|
# TODO: Maybe issue a warning if present in both lists but referencing the same wire?
|
||||||
|
if via_wire in cable.colors:
|
||||||
|
if cable.colors.count(via_wire) > 1:
|
||||||
|
raise Exception(f'{via_name}:{via_wire} is used for more than one wire.')
|
||||||
|
via_wire = cable.colors.index(via_wire) + 1 # list index starts at 0, wire IDs start at 1
|
||||||
|
elif via_wire in cable.wirelabels:
|
||||||
|
if cable.wirelabels.count(via_wire) > 1:
|
||||||
|
raise Exception(f'{via_name}:{via_wire} is used for more than one wire.')
|
||||||
|
via_wire = cable.wirelabels.index(via_wire) + 1 # list index starts at 0, wire IDs start at 1
|
||||||
|
|
||||||
|
self.cables[via_name].connect(from_name, from_pin, via_wire, to_name, to_pin)
|
||||||
if from_name in self.connectors:
|
if from_name in self.connectors:
|
||||||
self.connectors[from_name].activate_pin(from_pin)
|
self.connectors[from_name].activate_pin(from_pin)
|
||||||
if to_name in self.connectors:
|
if to_name in self.connectors:
|
||||||
@ -197,10 +213,22 @@ class Harness:
|
|||||||
wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table
|
wirehtml.append('<table border="0" cellspacing="0" cellborder="0">') # conductor table
|
||||||
wirehtml.append(' <tr><td> </td></tr>')
|
wirehtml.append(' <tr><td> </td></tr>')
|
||||||
|
|
||||||
for i, connection_color in enumerate(cable.colors, 1):
|
for i, (connection_color, wirelabel) in enumerate(zip_longest(cable.colors, cable.wirelabels), 1):
|
||||||
wirehtml.append(' <tr>')
|
wirehtml.append(' <tr>')
|
||||||
wirehtml.append(f' <td><!-- {i}_in --></td>')
|
wirehtml.append(f' <td><!-- {i}_in --></td>')
|
||||||
wirehtml.append(f' <td>{wv_colors.translate_color(connection_color, self.color_mode)}</td>')
|
wirehtml.append(f' <td>')
|
||||||
|
|
||||||
|
wireinfo = []
|
||||||
|
if cable.show_wirenumbers:
|
||||||
|
wireinfo.append(str(i))
|
||||||
|
colorstr = wv_colors.translate_color(connection_color, self.color_mode)
|
||||||
|
if colorstr:
|
||||||
|
wireinfo.append(colorstr)
|
||||||
|
if cable.wirelabels:
|
||||||
|
wireinfo.append(wirelabel if wirelabel is not None else '')
|
||||||
|
wirehtml.append(f' {":".join(wireinfo)}')
|
||||||
|
|
||||||
|
wirehtml.append(f' </td>')
|
||||||
wirehtml.append(f' <td><!-- {i}_out --></td>')
|
wirehtml.append(f' <td><!-- {i}_out --></td>')
|
||||||
wirehtml.append(' </tr>')
|
wirehtml.append(' </tr>')
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user