Skip to content

Commit

Permalink
Added List syntax for shorts and loops
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasfalk committed Jul 20, 2024
1 parent 57386a9 commit bb475ea
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 13 deletions.
9 changes: 8 additions & 1 deletion docs/syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ tweak: # optional tweaking of .gv output
# on the connector that are to be shorted with a cable loop
# more information about the loop can be added by additional
# components definition (see below)
# OR
- <List> # a list of pins to be looped
# Shorts
shorts: # a list(dict) of shorts
- <str>: <List> # every list item is itself a list of pins
<str>: <List> # every list item is itself a list of pins
# on the connector that are to be shorted represented inside
# the connector table
# more information about the loop can be added by additional
# components definition (see below)
# OR
- <List> # a list of pins to be shorted
# it is not posable to combine those two
shorts_hide_lable: <bool> # A Boolean to control if the lable of the shorts should be shown, if a list is used this is automatically turned true.

```
## Cable attributes
Expand Down
12 changes: 6 additions & 6 deletions examples/ex15.gv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions examples/ex15.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified examples/ex15.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 12 additions & 0 deletions examples/ex15.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 20 additions & 2 deletions src/wireviz/wv_dataclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ class Connector(TopLevelGraphicalComponent):
# connector-specific properties
style: Optional[str] = None
# TODO: Move shorts and loops to PinClass
loops: Dict[str, List[int]] = field(default_factory=dict)
shorts: Dict[str, List[int]] = field(default_factory=dict)
loops: Union[Dict[str, List[int]], List[List[int]]] = field(default_factory=dict)
shorts: Union[Dict[str, List[int]], List[List[int]]] = field(default_factory=dict)
shorts_hide_lable: bool = False
# pin information in particular
pincount: Optional[int] = None
pins: List[Pin] = field(default_factory=list) # legacy
Expand Down Expand Up @@ -417,6 +418,23 @@ def __post_init__(self) -> None:
if self.show_pincount is None:
# hide pincount for simple (1 pin) connectors by default
self.show_pincount = self.style != "simple"

# Convert short List to Short Dict
if type(self.shorts) == list:
self.shorts_hide_lable = True
shDict = dict()
for shIndex in range(0, len(self.shorts)):
key = "AutoSH" + str(shIndex)
shDict[key] = self.shorts[shIndex]
self.shorts = shDict

# Convert loop List to loop Dict
if type(self.loops) == list:
loDict = dict()
for loIndex in range(0, len(self.loops)):
key = "AutoLO" + str(loIndex)
loDict[key] = self.loops[loIndex]
self.loops = loDict

# TODO: allow using pin labels in addition to pin numbers,
# just like when defining regular connections
Expand Down
6 changes: 3 additions & 3 deletions src/wireviz/wv_graphviz.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ def gv_shorts_info_row(component) -> Tr:
def gv_pin_table(component) -> Table:
pin_rows = []

if len(component.shorts) > 0:
if len(component.shorts) > 0 and not component.shorts_hide_lable:
pin_rows.append(gv_shorts_info_row(component))

for pin in component.pin_objects.values():
Expand Down Expand Up @@ -343,9 +343,9 @@ def gv_connector_shorts(connector: Connector) -> List:

for short, shPins in connector.shorts.items():
comp = getAddCompFromRef(short, connector)
shColor = "#000000"
shColor = "#FFFFFF:#000000:#FFFFFF"
if comp != None and comp.color != None:
shColor = comp.color.html
shColor = f"#FFFFFF:{comp.color.html}:#FFFFFF"

for i in range(1, len(shPins)):
head = f"{connector.designator}:p{shPins[i - 1]}j:c"
Expand Down
2 changes: 1 addition & 1 deletion src/wireviz/wv_harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def create_graph(self) -> Graph:
color=color,
straight="straight",
addPTS=".18", # Size of the point at the end of the straight line/edge, it also enables the drawing of it
colorPTS=color,
colorPTS=color.replace("#FFFFFF:", ""),
headclip="false", tailclip="false")

# determine if there are double- or triple-colored wires in the harness;
Expand Down

0 comments on commit bb475ea

Please sign in to comment.