From 7ef8a0fc52c01b181633c5d0f8770094cc5284b7 Mon Sep 17 00:00:00 2001 From: Tobias Falk Date: Wed, 12 Mar 2025 22:56:10 +0100 Subject: [PATCH] Update Jumper code, thanks @SnowMB --- src/wireviz/wv_dataclasses.py | 22 ++++++++++++++-- src/wireviz/wv_graphviz.py | 48 +++++++++++++---------------------- src/wireviz/wv_harness.py | 6 ++--- 3 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/wireviz/wv_dataclasses.py b/src/wireviz/wv_dataclasses.py index d5b0453..1009ade 100644 --- a/src/wireviz/wv_dataclasses.py +++ b/src/wireviz/wv_dataclasses.py @@ -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 @@ -418,6 +419,23 @@ class Connector(TopLevelGraphicalComponent): # 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 # TODO: include properties of wire used to create the loop diff --git a/src/wireviz/wv_graphviz.py b/src/wireviz/wv_graphviz.py index 8c2238e..29ab520 100644 --- a/src/wireviz/wv_graphviz.py +++ b/src/wireviz/wv_graphviz.py @@ -263,21 +263,22 @@ def nested_table_dict(d: dict) -> Table: def gv_shorts_info_row(component) -> Tr: shorts_info = [] if component.ports_left: - shorts_info.append(Td(f'')) + shorts_info.append(Td(f"")) if component.pinlabels: - shorts_info.append(Td(f'')) + shorts_info.append(Td(f"")) for short in component.shorts: - shorts_info.append(Td(f'{short}')) + shorts_info.append(Td(f"{short}")) if component.ports_right: - shorts_info.append(Td(f'')) + shorts_info.append(Td(f"")) return Tr(shorts_info) + 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(): @@ -291,13 +292,13 @@ def gv_pin_table(component) -> Table: def gv_short_row_part(pin, connector) -> List: - short_row = []# Td("ADA"), Td("DAD") + short_row = [] # Td("ADA"), Td("DAD") for short, shPins in connector.shorts.items(): - if pin.index+1 in shPins: + if pin.index + 1 in shPins: short_row.append(Td("", port=f"p{pin.index+1}j")) else: short_row.append(Td("")) - return short_row + return short_row if len(short_row) > 0 else None def gv_pin_row(pin, connector) -> Tr: @@ -324,7 +325,7 @@ def gv_connector_loops(connector: Connector) -> List: loop_dir = "e" else: raise Exception("No side for loops") - + for loop, loPins in connector.loops.items(): comp = getAddCompFromRef(loop, connector) loColor = "#000000" @@ -343,9 +344,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" @@ -354,7 +355,6 @@ def gv_connector_shorts(connector: Connector) -> List: return short_edges - def gv_conductor_table(cable) -> Table: rows = [] rows.append(Tr(Td(" "))) # spacer row on top @@ -417,37 +417,23 @@ def gv_conductor_table(cable) -> Table: def gv_wire_cell(wire: Union[WireClass, ShieldClass], colspan: int) -> Td: - if wire.color: - color_list = ["#000000"] + wire.color.html_padded_list + ["#000000"] - else: - color_list = ["#000000"] - - wire_inner_rows = [] - for j, bgcolor in enumerate(color_list[::-1]): - wire_inner_cell_attribs = { - "bgcolor": "#FFFFFF", # bgcolor if bgcolor != "" else "#000000", # TODO: More elegent solution for making black/whit space needed, since the wire is drawn as an actual edge - "border": 0, - "cellpadding": 0, - "colspan": colspan, - "height": 2, - } - wire_inner_rows.append(Tr(Td("", **wire_inner_cell_attribs))) - wire_inner_table = Table(wire_inner_rows, border=0, cellborder=0, cellspacing=0) wire_outer_cell_attribs = { "border": 0, "cellspacing": 0, "cellpadding": 0, "colspan": colspan, - "height": 2 * len(color_list), + "height": 6, "port": f"w{wire.index+1}", } # ports in GraphViz are 1-indexed for more natural maping to pin/wire numbers - wire_outer_cell = Td(wire_inner_table, **wire_outer_cell_attribs) + wire_outer_cell = Td(None, **wire_outer_cell_attribs) return wire_outer_cell dot.attr("edge", headclip="true", tailclip="true", style="bold") # TODO: ? + + # color, l1, l2, r1, r2 def gv_edge_wire(harness, cable, connection) -> Tuple[str, str, str, str, str]: if connection.via.color: @@ -488,7 +474,7 @@ def gv_edge_wire_inside(cable) -> List[Tuple[str, str, str]]: for wire in cable.wire_objects.values(): color = "#000000" if wire.color: - # check if it's an actual wire and not a shield + # check if it's an actual wire and not a shield color = f"#000000:{wire.color.html_padded}:#000000" else: # it's a shield connection color = "#000000" diff --git a/src/wireviz/wv_harness.py b/src/wireviz/wv_harness.py index d90575f..d870fc9 100644 --- a/src/wireviz/wv_harness.py +++ b/src/wireviz/wv_harness.py @@ -6,7 +6,7 @@ from collections import defaultdict from dataclasses import dataclass, field, asdict from pathlib import Path from typing import List, Union -from distutils.spawn import find_executable +#from distutils.spawn import find_executable from graphviz import Graph @@ -339,7 +339,7 @@ class Harness: 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; @@ -416,7 +416,7 @@ class Harness: def graphRender(self, type, filename, graph): # Chack if the needed commands are existing - if find_executable("dot") and find_executable("gvpr") and find_executable("neato"): + if shutil.which("dot") and shutil.which("gvpr") and shutil.which("neato"): # Set enviorments variable to path of this file os.environ['GVPRPATH'] = str(Path(__file__).parent) # Export the gv output to a temporay file