Merge manufacturer name and manufacturer part number fields in diagram

This commit is contained in:
Tyler Ward 2020-07-23 00:15:31 +01:00
parent aed777169b
commit b97e0eacc7
2 changed files with 18 additions and 11 deletions

View File

@ -7,7 +7,8 @@ from wireviz import wv_colors, wv_helper
from wireviz.wv_colors import get_color_hex from wireviz.wv_colors import get_color_hex
from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \ from wireviz.wv_helper import awg_equiv, mm2_equiv, tuplelist2tsv, \
nested_html_table, flatten2d, index_if_list, html_line_breaks, \ nested_html_table, flatten2d, index_if_list, html_line_breaks, \
graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write graphviz_line_breaks, remove_line_breaks, open_file_read, open_file_write, \
manufacturer_info_field
from collections import Counter from collections import Counter
from typing import List from typing import List
from pathlib import Path from pathlib import Path
@ -89,8 +90,7 @@ class Harness:
rows = [[connector.name if connector.show_name else None], rows = [[connector.name if connector.show_name else None],
[f'P/N: {connector.pn}' if connector.pn else None, [f'P/N: {connector.pn}' if connector.pn else None,
connector.manufacturer, manufacturer_info_field(connector.manufacturer, connector.mpn)],
f'MPN: {connector.mpn}' if connector.mpn else None],
[html_line_breaks(connector.type), [html_line_breaks(connector.type),
html_line_breaks(connector.subtype), html_line_breaks(connector.subtype),
f'{connector.pincount}-pin' if connector.show_pincount else None, f'{connector.pincount}-pin' if connector.show_pincount else None,
@ -152,9 +152,8 @@ class Harness:
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)' awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
identification = [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else '', identification = [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else '',
cable.manufacturer if not isinstance(cable.manufacturer, list) else '', manufacturer_info_field(cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
f'MPN: {cable.mpn}' if (cable.mpn and not isinstance(cable.mpn, list)) else '', cable.mpn if not isinstance(cable.mpn, list) else None)]
]
identification = list(filter(None, identification)) identification = list(filter(None, identification))
attributes = [html_line_breaks(cable.type) if cable.type else '', attributes = [html_line_breaks(cable.type) if cable.type else '',
@ -213,10 +212,10 @@ class Harness:
wireidentification = [] wireidentification = []
if isinstance(cable.pn, list): if isinstance(cable.pn, list):
wireidentification.append(f'P/N: {cable.pn[i - 1]}') wireidentification.append(f'P/N: {cable.pn[i - 1]}')
if isinstance(cable.manufacturer, list): manufacturer_info = manufacturer_info_field(cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None,
wireidentification.append(cable.manufacturer[i - 1]) cable.mpn[i - 1] if isinstance(cable.mpn, list) else None)
if isinstance(cable.mpn, list): if manufacturer_info:
wireidentification.append(f'MPN: {cable.mpn[i - 1]}') wireidentification.append(manufacturer_info)
# print parameters into a table row under the wire # print parameters into a table row under the wire
if(len(wireidentification) > 0): if(len(wireidentification) > 0):
html = f'{html}<tr><td colspan="{len(p)}"><table border="0" cellspacing="0" cellborder="0"><tr>' html = f'{html}<tr><td colspan="{len(p)}"><table border="0" cellspacing="0" cellborder="0"><tr>'

View File

@ -118,3 +118,11 @@ def open_file_read(filename):
def open_file_write(filename): def open_file_write(filename):
return open(filename, 'w', encoding='UTF-8') return open(filename, 'w', encoding='UTF-8')
def manufacturer_info_field(manufacturer, mpn):
if manufacturer:
part_number_component = f': {mpn}' if mpn else ''
return(f'{manufacturer}{part_number_component}')
else:
return(f'MPN: {mpn}' if mpn else None)