Single arrows work

This commit is contained in:
Daniel Rojas 2020-10-24 12:09:42 +02:00
parent faa72df625
commit e62e08ac0e
3 changed files with 78 additions and 1 deletions

View File

@ -291,3 +291,17 @@ class Connection:
via_port: Wire
to_name: Optional[Designator]
to_port: Optional[Pin]
@dataclass
class MatePin:
from_name: Designator
from_port: Pin
to_name: Designator
to_port: Pin
shape: str
@dataclass
class MateComponent:
from_name: Designator
to_name: Designator
shape: str

View File

@ -19,6 +19,7 @@ from wireviz.wv_html import generate_html_output
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, flatten2d, \
open_file_read, open_file_write
arrows = ['<--','<->','-->','<==','<=>','==>']
class Harness:
@ -27,6 +28,8 @@ class Harness:
self.mini_bom_mode = True
self.connectors = {}
self.cables = {}
self.mates_pin = []
self.mates_component = []
self._bom = [] # Internal Cache for generated bom
self.additional_bom_items = []
@ -36,6 +39,17 @@ class Harness:
def add_cable(self, name: str, *args, **kwargs) -> None:
self.cables[name] = Cable(name, *args, **kwargs)
def add_mate_pin(self, *args, **kwargs) -> None:
mate = MatePin(*args, **kwargs)
self.mates_pin.append(mate)
self.connectors[mate.from_name].activate_pin(mate.from_port)
self.connectors[mate.from_name].ports_right = True
self.connectors[mate.to_name].activate_pin(mate.to_port)
self.connectors[mate.to_name].ports_left = True
def add_mate_component(self, *args, **kwargs) -> None:
self.mates_component.append(MateComponent(*args, **kwargs))
def add_bom_item(self, item: dict) -> None:
self.additional_bom_items.append(item)
@ -62,7 +76,13 @@ class Harness:
raise Exception(f'{name}:{pin} not found.')
# check via cable
if via_name in self.cables:
if via_name in arrows:
if '-' in via_name:
self.mates[(from_name, from_pin, to_name, to_pin)] = via_name
elif '=' in via_name:
self.mates[(from_name, to_name)] = via_name
print(self.mates)
elif 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:
@ -108,6 +128,11 @@ class Harness:
self.connectors[connection_color.from_name].ports_right = True
if connection_color.to_port is not None: # connect to right
self.connectors[connection_color.to_name].ports_left = True
for mate in self.mates_pin:
self.connectors[mate.from_name].ports_right = True
self.connectors[mate.from_name].activate_pin(mate.from_port)
self.connectors[mate.to_name].ports_left = True
self.connectors[mate.to_name].activate_pin(mate.to_port)
for connector in self.connectors.values():
@ -329,6 +354,21 @@ class Harness:
dot.node(cable.name, label=f'<\n{html}\n>', shape='box',
style='filled,dashed' if cable.category == 'bundle' else '', margin='0', fillcolor='white')
for mate in self.mates_pin:
if mate.shape == '<--':
dir = 'back'
elif mate.shape == '-->':
dir = 'forward'
elif mate.shape == '<->':
dir = 'both'
dot.attr('edge', color='#000000', style='dashed', dir=dir)
from_port = f':p{mate.from_port}r' if self.connectors[mate.from_name].style != 'simple' else ''
code_from = f'{mate.from_name}{from_port}:e'
to_port = f':p{mate.to_port}l' if self.connectors[mate.to_name].style != 'simple' else ''
code_to = f'{mate.to_name}{to_port}:w'
print(mate, '---', code_from, '---', code_to)
dot.edge(code_from, code_to)
return dot
@property

View File

@ -97,6 +97,8 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
designators_and_templates[designator] = template
return (template, designator)
arrows = ['<--','<->','-->','<==','<=>','==>']
connection_sets = yaml_data['connections']
for connection_set in connection_sets:
print('')
@ -160,6 +162,8 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
designator = list(entry.keys())[0]
pinlist = expand(entry[designator])
connection_set[index] = [{designator: pin} for pin in pinlist]
else:
pass # string entries have been expanded in previous step
print('connection set @3:', connection_set)
@ -214,6 +218,25 @@ def parse(yaml_input: str, file_out: (str, Path) = None, return_types: (None, st
to_pin = connection_set[index_connection][index_item+1][to_name]
print(' > connect ', from_name, from_pin, via_name, via_pin, to_name, to_pin)
harness.connect(from_name, from_pin, via_name, via_pin, to_name, to_pin)
elif designator in arrows:
print(f' - {designator} is an arrow')
if index_item == 0: # list startess with an arrow
raise Exception('An arrow cannot be at the start of a connection set')
elif index_item == len(connection) - 1: # list ends with an arrow
raise Exception('An arrow cannot be at the end of a connection set')
if '-' in designator: # join pin by pin
from_name = list(connection_set[index_connection][index_item-1].keys())[0]
from_pin = connection_set[index_connection][index_item-1][from_name]
via_name = designator
via_pin = None
to_name = list(connection_set[index_connection][index_item+1].keys())[0]
to_pin = connection_set[index_connection][index_item+1][to_name]
print(f' Mate {from_name}:{from_pin} {designator} {to_name}:{to_pin}')
# harness.connect(from_name, from_pin, designator, None, to_name, to_pin)
harness.add_mate_pin(from_name, from_pin, to_name, to_pin, designator)
elif '=' in designator: # mate connectors as a whole
pass
if "additional_bom_items" in yaml_data: