Skip to content

Commit

Permalink
Squash feature/mate+autogenerate branch
Browse files Browse the repository at this point in the history
  • Loading branch information
formatc1702 committed Sep 23, 2021
1 parent a3eefe6 commit 74aeaa5
Show file tree
Hide file tree
Showing 15 changed files with 515 additions and 137 deletions.
5 changes: 2 additions & 3 deletions examples/demo02.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,8 @@ connectors:
X4:
<<: *molex_f
pinlabels: [GND, +12V, MISO, MOSI, SCK]
ferrule_crimp:
F:
style: simple
autogenerate: true
type: Crimp ferrule
subtype: 0.25 mm²
color: YE
Expand Down Expand Up @@ -64,6 +63,6 @@ connections:
- W3: [1-4]
- X4: [1,3-5]
-
- ferrule_crimp
- F.
- W4: [1,2]
- X4: [1,2]
7 changes: 3 additions & 4 deletions examples/ex04.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ cables:
category: bundle

connectors:
ferrule_crimp:
F:
style: simple
autogenerate: true
type: Crimp ferrule

connections:
-
- ferrule_crimp
- F.
- W1: [1-6]
- ferrule_crimp
- F.
28 changes: 22 additions & 6 deletions src/wireviz/DataClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ class Connector:
show_name: Optional[bool] = None
show_pincount: Optional[bool] = None
hide_disconnected_pins: bool = False
autogenerate: bool = False
loops: List[List[Pin]] = field(default_factory=list)
ignore_in_bom: bool = False
additional_components: List[AdditionalComponent] = field(default_factory=list)
Expand Down Expand Up @@ -173,7 +172,8 @@ def __post_init__(self) -> None:
raise Exception('Pins are not unique')

if self.show_name is None:
self.show_name = not self.autogenerate # hide auto-generated designators by default
# hide designators for simple and for auto-generated connectors by default
self.show_name = (self.style != 'simple' and self.name[0:2] != '__')

if self.show_pincount is None:
self.show_pincount = self.style != 'simple' # hide pincount for simple (1 pin) connectors by default
Expand Down Expand Up @@ -226,7 +226,7 @@ class Cable:
colors: List[Colors] = field(default_factory=list)
wirelabels: List[Wire] = field(default_factory=list)
color_code: Optional[ColorScheme] = None
show_name: bool = True
show_name: Optional[bool] = None
show_wirecount: bool = True
show_wirenumbers: Optional[bool] = None
ignore_in_bom: bool = False
Expand Down Expand Up @@ -309,9 +309,11 @@ def __post_init__(self) -> None:
else:
raise Exception('lists of part data are only supported for bundles')

# by default, show wire numbers for cables, hide for bundles
if self.show_wirenumbers is None:
self.show_wirenumbers = self.category != 'bundle'
if self.show_name is None:
self.show_name = self.name[0:2] != '__' # hide designators for auto-generated cables by default

if not self.show_wirenumbers:
self.show_wirenumbers = self.category != 'bundle' # by default, show wire numbers for cables, hide for bundles

for i, item in enumerate(self.additional_components):
if isinstance(item, dict):
Expand Down Expand Up @@ -350,3 +352,17 @@ class Connection:
via_port: Wire
to_name: Optional[Designator]
to_port: Optional[PinIndex]

@dataclass
class MatePin:
from_name: Designator
from_port: PinIndex
to_name: Designator
to_port: PinIndex
shape: str

@dataclass
class MateComponent:
from_name: Designator
to_name: Designator
shape: str
52 changes: 48 additions & 4 deletions src/wireviz/Harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import re

from wireviz import wv_colors, __version__, APP_NAME, APP_URL
from wireviz.DataClasses import Metadata, Options, Tweak, Connector, Cable
from wireviz.DataClasses import Cable, Connector, MatePin, MateComponent, Metadata, Options, Tweak
from wireviz.wv_colors import get_color_hex, translate_color
from wireviz.wv_gv_html import nested_html_table, html_colorbar, html_image, \
html_caption, remove_links, html_line_breaks
Expand All @@ -19,8 +19,7 @@
HEADER_PN, HEADER_MPN, HEADER_SPN
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

open_file_read, open_file_write, is_arrow

@dataclass
class Harness:
Expand All @@ -31,6 +30,7 @@ class Harness:
def __post_init__(self):
self.connectors = {}
self.cables = {}
self.mates = []
self._bom = [] # Internal Cache for generated bom
self.additional_bom_items = []

Expand All @@ -40,6 +40,12 @@ def add_connector(self, name: str, *args, **kwargs) -> None:
def add_cable(self, name: str, *args, **kwargs) -> None:
self.cables[name] = Cable(name, *args, **kwargs)

def add_mate_pin(self, *args, **kwargs) -> None:
self.mates.append(MatePin(*args, **kwargs))

def add_mate_component(self, *args, **kwargs) -> None:
self.mates.append(MateComponent(*args, **kwargs))

def add_bom_item(self, item: dict) -> None:
self.additional_bom_items.append(item)

Expand All @@ -66,7 +72,12 @@ def connect(self, from_name: str, from_pin: (int, str), via_name: str, via_wire:
raise Exception(f'{name}:{pin} not found.')

# check via cable
if via_name in self.cables:
if is_arrow(via_name):
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
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:
Expand Down Expand Up @@ -114,8 +125,17 @@ def create_graph(self) -> Graph:
for connection_color in cable.connections:
if connection_color.from_port is not None: # connect to left
self.connectors[connection_color.from_name].ports_right = True
self.connectors[connection_color.from_name].activate_pin(connection_color.from_port)
if connection_color.to_port is not None: # connect to right
self.connectors[connection_color.to_name].ports_left = True
self.connectors[connection_color.to_name].activate_pin(connection_color.to_port)

for mate in self.mates:
if isinstance(mate, MatePin):
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():

Expand Down Expand Up @@ -407,6 +427,30 @@ def typecheck(name: str, value: Any, expect: type) -> None:
typecheck('tweak.append', self.tweak.append, str)
dot.body.append(self.tweak.append)

for mate in self.mates:
if mate.shape[0] == '<' and mate.shape[-1] == '>':
dir = 'both'
elif mate.shape[0] == '<':
dir = 'back'
elif mate.shape[-1] == '>':
dir = 'forward'
else:
dir = 'none'

if isinstance(mate, MatePin):
color = '#000000'
elif isinstance(mate, MateComponent):
color = '#000000:#000000'
else:
raise Exception(f'{mate} is an unknown mate')

dot.attr('edge', color=color, style='dashed', dir=dir)
from_port = f':p{mate.from_port}r' if isinstance(mate, MatePin) and 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 isinstance(mate, MatePin) and self.connectors[mate.to_name].style != 'simple' else ''
code_to = f'{mate.to_name}{to_port}:w'
dot.edge(code_from, code_to)

return dot

@property
Expand Down
Loading

0 comments on commit 74aeaa5

Please sign in to comment.