Update Jumper code, thanks @SnowMB
This commit is contained in:
parent
3e4353e62a
commit
7ef8a0fc52
@ -312,8 +312,9 @@ class Connector(TopLevelGraphicalComponent):
|
|||||||
# connector-specific properties
|
# connector-specific properties
|
||||||
style: Optional[str] = None
|
style: Optional[str] = None
|
||||||
# TODO: Move shorts and loops to PinClass
|
# TODO: Move shorts and loops to PinClass
|
||||||
loops: Dict[str, List[int]] = field(default_factory=dict)
|
loops: Union[Dict[str, List[int]], List[List[int]]] = field(default_factory=dict)
|
||||||
shorts: Dict[str, 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
|
# pin information in particular
|
||||||
pincount: Optional[int] = None
|
pincount: Optional[int] = None
|
||||||
pins: List[Pin] = field(default_factory=list) # legacy
|
pins: List[Pin] = field(default_factory=list) # legacy
|
||||||
@ -418,6 +419,23 @@ class Connector(TopLevelGraphicalComponent):
|
|||||||
# hide pincount for simple (1 pin) connectors by default
|
# hide pincount for simple (1 pin) connectors by default
|
||||||
self.show_pincount = self.style != "simple"
|
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,
|
# TODO: allow using pin labels in addition to pin numbers,
|
||||||
# just like when defining regular connections
|
# just like when defining regular connections
|
||||||
# TODO: include properties of wire used to create the loop
|
# TODO: include properties of wire used to create the loop
|
||||||
|
|||||||
@ -263,21 +263,22 @@ def nested_table_dict(d: dict) -> Table:
|
|||||||
def gv_shorts_info_row(component) -> Tr:
|
def gv_shorts_info_row(component) -> Tr:
|
||||||
shorts_info = []
|
shorts_info = []
|
||||||
if component.ports_left:
|
if component.ports_left:
|
||||||
shorts_info.append(Td(f''))
|
shorts_info.append(Td(f""))
|
||||||
if component.pinlabels:
|
if component.pinlabels:
|
||||||
shorts_info.append(Td(f''))
|
shorts_info.append(Td(f""))
|
||||||
|
|
||||||
for short in component.shorts:
|
for short in component.shorts:
|
||||||
shorts_info.append(Td(f'{short}'))
|
shorts_info.append(Td(f"{short}"))
|
||||||
|
|
||||||
if component.ports_right:
|
if component.ports_right:
|
||||||
shorts_info.append(Td(f''))
|
shorts_info.append(Td(f""))
|
||||||
return Tr(shorts_info)
|
return Tr(shorts_info)
|
||||||
|
|
||||||
|
|
||||||
def gv_pin_table(component) -> Table:
|
def gv_pin_table(component) -> Table:
|
||||||
pin_rows = []
|
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))
|
pin_rows.append(gv_shorts_info_row(component))
|
||||||
|
|
||||||
for pin in component.pin_objects.values():
|
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:
|
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():
|
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"))
|
short_row.append(Td("", port=f"p{pin.index+1}j"))
|
||||||
else:
|
else:
|
||||||
short_row.append(Td(""))
|
short_row.append(Td(""))
|
||||||
return short_row
|
return short_row if len(short_row) > 0 else None
|
||||||
|
|
||||||
|
|
||||||
def gv_pin_row(pin, connector) -> Tr:
|
def gv_pin_row(pin, connector) -> Tr:
|
||||||
@ -343,9 +344,9 @@ def gv_connector_shorts(connector: Connector) -> List:
|
|||||||
|
|
||||||
for short, shPins in connector.shorts.items():
|
for short, shPins in connector.shorts.items():
|
||||||
comp = getAddCompFromRef(short, connector)
|
comp = getAddCompFromRef(short, connector)
|
||||||
shColor = "#000000"
|
shColor = "#FFFFFF:#000000:#FFFFFF"
|
||||||
if comp != None and comp.color != None:
|
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)):
|
for i in range(1, len(shPins)):
|
||||||
head = f"{connector.designator}:p{shPins[i - 1]}j:c"
|
head = f"{connector.designator}:p{shPins[i - 1]}j:c"
|
||||||
@ -354,7 +355,6 @@ def gv_connector_shorts(connector: Connector) -> List:
|
|||||||
return short_edges
|
return short_edges
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def gv_conductor_table(cable) -> Table:
|
def gv_conductor_table(cable) -> Table:
|
||||||
rows = []
|
rows = []
|
||||||
rows.append(Tr(Td(" "))) # spacer row on top
|
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:
|
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 = {
|
wire_outer_cell_attribs = {
|
||||||
"border": 0,
|
"border": 0,
|
||||||
"cellspacing": 0,
|
"cellspacing": 0,
|
||||||
"cellpadding": 0,
|
"cellpadding": 0,
|
||||||
"colspan": colspan,
|
"colspan": colspan,
|
||||||
"height": 2 * len(color_list),
|
"height": 6,
|
||||||
"port": f"w{wire.index+1}",
|
"port": f"w{wire.index+1}",
|
||||||
}
|
}
|
||||||
# ports in GraphViz are 1-indexed for more natural maping to pin/wire numbers
|
# 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
|
return wire_outer_cell
|
||||||
|
|
||||||
dot.attr("edge", headclip="true", tailclip="true", style="bold") # TODO: ?
|
dot.attr("edge", headclip="true", tailclip="true", style="bold") # TODO: ?
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# color, l1, l2, r1, r2
|
# color, l1, l2, r1, r2
|
||||||
def gv_edge_wire(harness, cable, connection) -> Tuple[str, str, str, str, str]:
|
def gv_edge_wire(harness, cable, connection) -> Tuple[str, str, str, str, str]:
|
||||||
if connection.via.color:
|
if connection.via.color:
|
||||||
|
|||||||
@ -6,7 +6,7 @@ from collections import defaultdict
|
|||||||
from dataclasses import dataclass, field, asdict
|
from dataclasses import dataclass, field, asdict
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
from distutils.spawn import find_executable
|
#from distutils.spawn import find_executable
|
||||||
|
|
||||||
from graphviz import Graph
|
from graphviz import Graph
|
||||||
|
|
||||||
@ -339,7 +339,7 @@ class Harness:
|
|||||||
color=color,
|
color=color,
|
||||||
straight="straight",
|
straight="straight",
|
||||||
addPTS=".18", # Size of the point at the end of the straight line/edge, it also enables the drawing of it
|
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")
|
headclip="false", tailclip="false")
|
||||||
|
|
||||||
# determine if there are double- or triple-colored wires in the harness;
|
# determine if there are double- or triple-colored wires in the harness;
|
||||||
@ -416,7 +416,7 @@ class Harness:
|
|||||||
|
|
||||||
def graphRender(self, type, filename, graph):
|
def graphRender(self, type, filename, graph):
|
||||||
# Chack if the needed commands are existing
|
# 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
|
# Set enviorments variable to path of this file
|
||||||
os.environ['GVPRPATH'] = str(Path(__file__).parent)
|
os.environ['GVPRPATH'] = str(Path(__file__).parent)
|
||||||
# Export the gv output to a temporay file
|
# Export the gv output to a temporay file
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user