Outsource gv_pin_table(), simplify padding
This commit is contained in:
parent
0078a18953
commit
064c7fd7c8
@ -60,6 +60,10 @@ class Options:
|
||||
color_mode: ColorMode = "SHORT"
|
||||
mini_bom_mode: bool = True
|
||||
template_separator: str = "."
|
||||
_pad: int = 0
|
||||
# TODO: resolve template and image paths during rendering, not during YAML parsing
|
||||
_template_paths: [List] = field(default_factory=list)
|
||||
_image_paths: [List] = field(default_factory=list)
|
||||
|
||||
def __post_init__(self):
|
||||
if not self.bgcolor_node:
|
||||
|
||||
@ -191,9 +191,11 @@ class Harness:
|
||||
for colorstr in cable.colors
|
||||
)
|
||||
|
||||
self.options._pad = pad
|
||||
|
||||
for cable in self.cables.values():
|
||||
|
||||
gv_html = gv_node_component(cable, self.options, pad)
|
||||
gv_html = gv_node_component(cable, self.options)
|
||||
dot.node(
|
||||
cable.name,
|
||||
label=f"<\n{gv_html}\n>",
|
||||
@ -205,32 +207,6 @@ class Harness:
|
||||
|
||||
html = []
|
||||
|
||||
# fmt: off
|
||||
rows = [[f'{html_bgcolor(cable.bgcolor_title)}{remove_links(cable.name)}'
|
||||
if cable.show_name else None],
|
||||
[pn_info_string(HEADER_PN, None,
|
||||
remove_links(cable.pn)) if not isinstance(cable.pn, list) else None,
|
||||
html_line_breaks(pn_info_string(HEADER_MPN,
|
||||
cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
|
||||
cable.mpn if not isinstance(cable.mpn, list) else None)),
|
||||
html_line_breaks(pn_info_string(HEADER_SPN,
|
||||
cable.supplier if not isinstance(cable.supplier, list) else None,
|
||||
cable.spn if not isinstance(cable.spn, list) else None))],
|
||||
[html_line_breaks(cable.type),
|
||||
f'{cable.wirecount}x' if cable.show_wirecount else None,
|
||||
cable.gauge_str,
|
||||
'+ S' if cable.shield else None,
|
||||
f'{cable.length} {cable.length_unit}' if cable.length > 0 else None,
|
||||
translate_color(cable.color, self.options.color_mode) if cable.color else None,
|
||||
html_colorbar(cable.color)],
|
||||
'<!-- wire table -->',
|
||||
[html_image(cable.image)],
|
||||
[html_caption(cable.image)]]
|
||||
# fmt: on
|
||||
|
||||
rows.extend(get_additional_component_table(self, cable))
|
||||
rows.append([html_line_breaks(cable.notes)])
|
||||
html.extend(nested_html_table(rows, html_bgcolor_attr(cable.bgcolor)))
|
||||
|
||||
wirehtml = []
|
||||
# conductor table
|
||||
|
||||
@ -53,38 +53,17 @@ def gv_node_component(
|
||||
]
|
||||
|
||||
line_image, line_image_caption = image_and_caption_cells(component)
|
||||
|
||||
# line_additional_component_table = get_additional_component_table(self, connector)
|
||||
line_additional_component_table = None
|
||||
line_notes = [html_line_breaks(component.notes)]
|
||||
|
||||
if isinstance(component, Connector):
|
||||
# pin table
|
||||
if component.style != "simple":
|
||||
pin_tuples = zip_longest(
|
||||
component.pins,
|
||||
component.pinlabels,
|
||||
component.pincolors,
|
||||
)
|
||||
|
||||
pin_rows = []
|
||||
for pinindex, (pinname, pinlabel, pincolor) in enumerate(pin_tuples):
|
||||
if component.should_show_pin(pinname):
|
||||
pin_rows.append(
|
||||
gv_pin_row(pinindex, pinname, pinlabel, pincolor, component)
|
||||
)
|
||||
|
||||
table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 3,
|
||||
"cellborder": 1,
|
||||
}
|
||||
line_ports = Table(pin_rows, attribs=table_attribs)
|
||||
line_ports = gv_pin_table(component)
|
||||
else:
|
||||
line_ports = None
|
||||
elif isinstance(component, Cable):
|
||||
line_ports = gv_conductor_table(component, harness_options, pad)
|
||||
line_ports = gv_conductor_table(component, harness_options)
|
||||
|
||||
lines = [
|
||||
line_name,
|
||||
@ -97,9 +76,7 @@ def gv_node_component(
|
||||
line_notes,
|
||||
]
|
||||
|
||||
cell_lists = [make_list_of_cells(line) for line in lines]
|
||||
|
||||
tbl = nested_table(cell_lists)
|
||||
tbl = nested_table(lines)
|
||||
|
||||
if component.bgcolor:
|
||||
tbl.attribs["bgcolor"] = translate_color(component.bgcolor, "HEX")
|
||||
@ -131,19 +108,8 @@ def make_list_of_cells(inp) -> List[Td]:
|
||||
return [Td(inp)]
|
||||
|
||||
|
||||
def nested_table(cell_lists: List[Td]) -> Table:
|
||||
outer_table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 0,
|
||||
}
|
||||
inner_table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 3,
|
||||
"cellborder": 1,
|
||||
}
|
||||
|
||||
def nested_table(lines: List[Td]) -> Table:
|
||||
cell_lists = [make_list_of_cells(line) for line in lines]
|
||||
rows = []
|
||||
for lst in cell_lists:
|
||||
if len(lst) == 0:
|
||||
@ -162,16 +128,51 @@ def nested_table(cell_lists: List[Td]) -> Table:
|
||||
inner_table = cells[0].contents
|
||||
else:
|
||||
# nest cell content inside a table
|
||||
inner_table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 3,
|
||||
"cellborder": 1,
|
||||
}
|
||||
inner_table = Table(Tr(cells), attribs=inner_table_attribs)
|
||||
rows.append(Tr(Td(inner_table)))
|
||||
if len(rows) == 0: # create dummy row to avoid GraphViz errors due to empty <table>
|
||||
rows = Tr(Td(""))
|
||||
outer_table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 0,
|
||||
}
|
||||
tbl = Table(rows, attribs=outer_table_attribs)
|
||||
|
||||
return tbl
|
||||
|
||||
|
||||
def gv_pin_row(pin_index, pin_name, pin_label, pin_color, connector):
|
||||
def gv_pin_table(component) -> Table:
|
||||
pin_tuples = zip_longest(
|
||||
component.pins,
|
||||
component.pinlabels,
|
||||
component.pincolors,
|
||||
)
|
||||
|
||||
pin_rows = []
|
||||
for pinindex, (pinname, pinlabel, pincolor) in enumerate(pin_tuples):
|
||||
if component.should_show_pin(pinname):
|
||||
pin_rows.append(
|
||||
gv_pin_row(pinindex, pinname, pinlabel, pincolor, component)
|
||||
)
|
||||
|
||||
table_attribs = {
|
||||
"border": 0,
|
||||
"cellspacing": 0,
|
||||
"cellpadding": 3,
|
||||
"cellborder": 1,
|
||||
}
|
||||
|
||||
return Table(pin_rows, attribs=table_attribs)
|
||||
|
||||
|
||||
def gv_pin_row(pin_index, pin_name, pin_label, pin_color, connector) -> Tr:
|
||||
cell_pin_left = Td(pin_name, attribs={"port": f"p{pin_index+1}l"})
|
||||
cell_pin_label = Td(pin_label, empty_is_none=True)
|
||||
cell_pin_right = Td(pin_name, attribs={"port": f"p{pin_index+1}r"})
|
||||
@ -201,7 +202,7 @@ def gv_connector_loops(connector: Connector) -> List:
|
||||
return loop_edges
|
||||
|
||||
|
||||
def gv_conductor_table(cable, harness_options, pad) -> Table:
|
||||
def gv_conductor_table(cable, harness_options) -> Table:
|
||||
|
||||
rows = []
|
||||
rows.append(Tr(Td(" ")))
|
||||
@ -228,7 +229,7 @@ def gv_conductor_table(cable, harness_options, pad) -> Table:
|
||||
rows.append(Tr(cells_above))
|
||||
|
||||
# the wire itself
|
||||
rows.append(Tr(gv_wire_cell(i, connection_color, pad)))
|
||||
rows.append(Tr(gv_wire_cell(i, connection_color, harness_options._pad)))
|
||||
|
||||
rows.append(Tr(Td(" ")))
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user