Shorten BOM field names (#121)
- Shorten `part_number` to `pn`
- Shorten `manufacturer_part_number` to `mpn`
- Show `manufacturer` and `mpn` in a single cell of the node
- Replace `manufacturer` with `'MPN'`within the node if no manufacturer is specified.
- Rearrange order of P/N fields within node
`{pn} | {manufacturer}: {mpn}`
This commit is contained in:
parent
f2f654854a
commit
b9a4783b6f
@ -11,8 +11,8 @@ from wireviz import wv_colors
|
|||||||
class Connector:
|
class Connector:
|
||||||
name: str
|
name: str
|
||||||
manufacturer: Optional[str] = None
|
manufacturer: Optional[str] = None
|
||||||
manufacturer_part_number: Optional[str] = None
|
mpn: Optional[str] = None
|
||||||
internal_part_number: Optional[str] = None
|
pn: Optional[str] = None
|
||||||
style: Optional[str] = None
|
style: Optional[str] = None
|
||||||
category: Optional[str] = None
|
category: Optional[str] = None
|
||||||
type: Optional[str] = None
|
type: Optional[str] = None
|
||||||
@ -80,8 +80,8 @@ class Connector:
|
|||||||
class Cable:
|
class Cable:
|
||||||
name: str
|
name: str
|
||||||
manufacturer: Optional[Union[str, List[str]]] = None
|
manufacturer: Optional[Union[str, List[str]]] = None
|
||||||
manufacturer_part_number: Optional[Union[str, List[str]]] = None
|
mpn: Optional[Union[str, List[str]]] = None
|
||||||
internal_part_number: Optional[Union[str, List[str]]] = None
|
pn: Optional[Union[str, List[str]]] = None
|
||||||
category: Optional[str] = None
|
category: Optional[str] = None
|
||||||
type: Optional[str] = None
|
type: Optional[str] = None
|
||||||
gauge: Optional[float] = None
|
gauge: Optional[float] = None
|
||||||
@ -140,7 +140,7 @@ class Cable:
|
|||||||
self.wirecount = len(self.colors)
|
self.wirecount = len(self.colors)
|
||||||
|
|
||||||
# if lists of part numbers are provided check this is a bundle and that it matches the wirecount.
|
# if lists of part numbers are provided check this is a bundle and that it matches the wirecount.
|
||||||
for idfield in [self.manufacturer, self.manufacturer_part_number, self.internal_part_number]:
|
for idfield in [self.manufacturer, self.mpn, self.pn]:
|
||||||
if isinstance(idfield, list):
|
if isinstance(idfield, list):
|
||||||
if self.category == "bundle":
|
if self.category == "bundle":
|
||||||
# check the length
|
# check the length
|
||||||
|
|||||||
@ -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
|
||||||
@ -88,9 +89,8 @@ class Harness:
|
|||||||
for key, connector in self.connectors.items():
|
for key, connector in self.connectors.items():
|
||||||
|
|
||||||
rows = [[connector.name if connector.show_name else None],
|
rows = [[connector.name if connector.show_name else None],
|
||||||
[connector.manufacturer,
|
[f'P/N: {connector.pn}' if connector.pn else None,
|
||||||
f'MPN: {connector.manufacturer_part_number}' if connector.manufacturer_part_number else None,
|
manufacturer_info_field(connector.manufacturer, connector.mpn)],
|
||||||
f'IPN: {connector.internal_part_number}' if connector.internal_part_number 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,
|
||||||
@ -151,9 +151,9 @@ class Harness:
|
|||||||
elif cable.gauge_unit.upper() == 'AWG':
|
elif cable.gauge_unit.upper() == 'AWG':
|
||||||
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
|
awg_fmt = f' ({mm2_equiv(cable.gauge)} mm\u00B2)'
|
||||||
|
|
||||||
identification = [cable.manufacturer if not isinstance(cable.manufacturer, list) else '',
|
identification = [f'P/N: {cable.pn}' if (cable.pn and not isinstance(cable.pn, list)) else '',
|
||||||
f'MPN: {cable.manufacturer_part_number}' if (cable.manufacturer_part_number and not isinstance(cable.manufacturer_part_number, list)) else '',
|
manufacturer_info_field(cable.manufacturer if not isinstance(cable.manufacturer, list) else None,
|
||||||
f'IPN: {cable.internal_part_number}' if (cable.internal_part_number and not isinstance(cable.internal_part_number, 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 '',
|
||||||
@ -210,12 +210,12 @@ class Harness:
|
|||||||
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
if(cable.category == 'bundle'): # for bundles individual wires can have part information
|
||||||
# create a list of wire parameters
|
# create a list of wire parameters
|
||||||
wireidentification = []
|
wireidentification = []
|
||||||
if isinstance(cable.manufacturer, list):
|
if isinstance(cable.pn, list):
|
||||||
wireidentification.append(cable.manufacturer[i - 1])
|
wireidentification.append(f'P/N: {cable.pn[i - 1]}')
|
||||||
if isinstance(cable.manufacturer_part_number, list):
|
manufacturer_info = manufacturer_info_field(cable.manufacturer[i - 1] if isinstance(cable.manufacturer, list) else None,
|
||||||
wireidentification.append(f'MPN: {cable.manufacturer_part_number[i - 1]}')
|
cable.mpn[i - 1] if isinstance(cable.mpn, list) else None)
|
||||||
if isinstance(cable.internal_part_number, list):
|
if manufacturer_info:
|
||||||
wireidentification.append(f'IPN: {cable.internal_part_number[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>'
|
||||||
@ -337,7 +337,7 @@ class Harness:
|
|||||||
bom_cables = []
|
bom_cables = []
|
||||||
bom_extra = []
|
bom_extra = []
|
||||||
# connectors
|
# connectors
|
||||||
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.manufacturer_part_number, c.internal_part_number)
|
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.mpn, c.pn)
|
||||||
for group in Counter([connector_group(v) for v in self.connectors.values()]):
|
for group in Counter([connector_group(v) for v in self.connectors.values()]):
|
||||||
items = {k: v for k, v in self.connectors.items() if connector_group(v) == group}
|
items = {k: v for k, v in self.connectors.items() if connector_group(v) == group}
|
||||||
shared = next(iter(items.values()))
|
shared = next(iter(items.values()))
|
||||||
@ -349,14 +349,14 @@ class Harness:
|
|||||||
conn_color = f', {shared.color}' if shared.color else ''
|
conn_color = f', {shared.color}' if shared.color else ''
|
||||||
name = f'Connector{conn_type}{conn_subtype}{conn_pincount}{conn_color}'
|
name = f'Connector{conn_type}{conn_subtype}{conn_pincount}{conn_color}'
|
||||||
item = {'item': name, 'qty': len(designators), 'unit': '', 'designators': designators if shared.show_name else '',
|
item = {'item': name, 'qty': len(designators), 'unit': '', 'designators': designators if shared.show_name else '',
|
||||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.manufacturer_part_number, 'internal part number': shared.internal_part_number}
|
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||||
bom_connectors.append(item)
|
bom_connectors.append(item)
|
||||||
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
bom_connectors = sorted(bom_connectors, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
||||||
bom.extend(bom_connectors)
|
bom.extend(bom_connectors)
|
||||||
# cables
|
# cables
|
||||||
# TODO: If category can have other non-empty values than 'bundle', maybe it should be part of item name?
|
# TODO: If category can have other non-empty values than 'bundle', maybe it should be part of item name?
|
||||||
# The category needs to be included in cable_group to keep the bundles excluded.
|
# The category needs to be included in cable_group to keep the bundles excluded.
|
||||||
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.wirecount, c.shield, c.manufacturer, c.manufacturer_part_number, c.internal_part_number)
|
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.wirecount, c.shield, c.manufacturer, c.mpn, c.pn)
|
||||||
for group in Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle']):
|
for group in Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle']):
|
||||||
items = {k: v for k, v in self.cables.items() if cable_group(v) == group}
|
items = {k: v for k, v in self.cables.items() if cable_group(v) == group}
|
||||||
shared = next(iter(items.values()))
|
shared = next(iter(items.values()))
|
||||||
@ -368,7 +368,7 @@ class Harness:
|
|||||||
shield_name = ' shielded' if shared.shield else ''
|
shield_name = ' shielded' if shared.shield else ''
|
||||||
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}'
|
name = f'Cable{cable_type}, {shared.wirecount}{gauge_name}{shield_name}'
|
||||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||||
'manufacturer': shared.manufacturer, 'manufacturer part number': shared.manufacturer_part_number, 'internal part number': shared.internal_part_number}
|
'manufacturer': shared.manufacturer, 'mpn': shared.mpn, 'pn': shared.pn}
|
||||||
bom_cables.append(item)
|
bom_cables.append(item)
|
||||||
# bundles (ignores wirecount)
|
# bundles (ignores wirecount)
|
||||||
wirelist = []
|
wirelist = []
|
||||||
@ -379,10 +379,10 @@ class Harness:
|
|||||||
for index, color in enumerate(bundle.colors, 0):
|
for index, color in enumerate(bundle.colors, 0):
|
||||||
wirelist.append({'type': bundle.type, 'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name,
|
wirelist.append({'type': bundle.type, 'gauge': bundle.gauge, 'gauge_unit': bundle.gauge_unit, 'length': bundle.length, 'color': color, 'designator': bundle.name,
|
||||||
'manufacturer': index_if_list(bundle.manufacturer, index),
|
'manufacturer': index_if_list(bundle.manufacturer, index),
|
||||||
'manufacturer part number': index_if_list(bundle.manufacturer_part_number, index),
|
'mpn': index_if_list(bundle.mpn, index),
|
||||||
'internal part number': index_if_list(bundle.internal_part_number, index)})
|
'pn': index_if_list(bundle.pn, index)})
|
||||||
# join similar wires from all the bundles to a single BOM item
|
# join similar wires from all the bundles to a single BOM item
|
||||||
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['manufacturer part number'], w['internal part number'])
|
wire_group = lambda w: (w.get('type', None), w['gauge'], w['gauge_unit'], w['color'], w['manufacturer'], w['mpn'], w['pn'])
|
||||||
for group in Counter([wire_group(v) for v in wirelist]):
|
for group in Counter([wire_group(v) for v in wirelist]):
|
||||||
items = [v for v in wirelist if wire_group(v) == group]
|
items = [v for v in wirelist if wire_group(v) == group]
|
||||||
shared = items[0]
|
shared = items[0]
|
||||||
@ -395,7 +395,7 @@ class Harness:
|
|||||||
gauge_color = f', {shared["color"]}' if 'color' in shared != '' else ''
|
gauge_color = f', {shared["color"]}' if 'color' in shared != '' else ''
|
||||||
name = f'Wire{wire_type}{gauge_name}{gauge_color}'
|
name = f'Wire{wire_type}{gauge_name}{gauge_color}'
|
||||||
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
item = {'item': name, 'qty': round(total_length, 3), 'unit': 'm', 'designators': designators,
|
||||||
'manufacturer': shared['manufacturer'], 'manufacturer part number': shared['manufacturer part number'], 'internal part number': shared['internal part number']}
|
'manufacturer': shared['manufacturer'], 'mpn': shared['mpn'], 'pn': shared['pn']}
|
||||||
bom_cables.append(item)
|
bom_cables.append(item)
|
||||||
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||||
bom.extend(bom_cables)
|
bom.extend(bom_cables)
|
||||||
@ -405,7 +405,7 @@ class Harness:
|
|||||||
if isinstance(item.get('designators', None), List):
|
if isinstance(item.get('designators', None), List):
|
||||||
item['designators'].sort() # sort designators if a list is provided
|
item['designators'].sort() # sort designators if a list is provided
|
||||||
item = {'item': name, 'qty': item.get('qty', None), 'unit': item.get('unit', None), 'designators': item.get('designators', None),
|
item = {'item': name, 'qty': item.get('qty', None), 'unit': item.get('unit', None), 'designators': item.get('designators', None),
|
||||||
'manufacturer': item.get('manufacturer', None), 'manufacturer part number': item.get('manufacturer_part_number', None), 'internal part number': item.get('internal_part_number', None)}
|
'manufacturer': item.get('manufacturer', None), 'mpn': item.get('mpn', None), 'pn': item.get('pn', None)}
|
||||||
bom_extra.append(item)
|
bom_extra.append(item)
|
||||||
bom_extra = sorted(bom_extra, key=lambda k: k['item'])
|
bom_extra = sorted(bom_extra, key=lambda k: k['item'])
|
||||||
bom.extend(bom_extra)
|
bom.extend(bom_extra)
|
||||||
@ -414,11 +414,16 @@ class Harness:
|
|||||||
def bom_list(self):
|
def bom_list(self):
|
||||||
bom = self.bom()
|
bom = self.bom()
|
||||||
keys = ['item', 'qty', 'unit', 'designators'] # these BOM columns will always be included
|
keys = ['item', 'qty', 'unit', 'designators'] # these BOM columns will always be included
|
||||||
for fieldname in ['manufacturer', 'manufacturer part number', 'internal part number']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
for fieldname in ['pn', 'manufacturer', 'mpn']: # these optional BOM columns will only be included if at least one BOM item actually uses them
|
||||||
if any(fieldname in x and x.get(fieldname, None) for x in bom):
|
if any(fieldname in x and x.get(fieldname, None) for x in bom):
|
||||||
keys.append(fieldname)
|
keys.append(fieldname)
|
||||||
bom_list = []
|
bom_list = []
|
||||||
bom_list.append([k.capitalize() for k in keys]) # create header row with keys
|
# list of staic bom header names, headers not specified here are generated by capitilising the internal name
|
||||||
|
bom_headings = {
|
||||||
|
"pn": "P/N",
|
||||||
|
"mpn": "MPN"
|
||||||
|
}
|
||||||
|
bom_list.append([(bom_headings[k] if k in bom_headings else k.capitalize()) for k in keys]) # create header row with keys
|
||||||
for item in bom:
|
for item in bom:
|
||||||
item_list = [item.get(key, '') for key in keys] # fill missing values with blanks
|
item_list = [item.get(key, '') for key in keys] # fill missing values with blanks
|
||||||
item_list = [', '.join(subitem) if isinstance(subitem, List) else subitem for subitem in item_list] # convert any lists into comma separated strings
|
item_list = [', '.join(subitem) if isinstance(subitem, List) else subitem for subitem in item_list] # convert any lists into comma separated strings
|
||||||
|
|||||||
@ -117,4 +117,11 @@ def open_file_read(filename):
|
|||||||
return open(filename, 'r', encoding='UTF-8')
|
return open(filename, 'r', encoding='UTF-8')
|
||||||
|
|
||||||
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 or mpn:
|
||||||
|
return f'{manufacturer if manufacturer else "MPN"}{": " + str(mpn) if mpn else ""}'
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|||||||
@ -3,3 +3,4 @@
|
|||||||
* Part number information can be added to parts
|
* Part number information can be added to parts
|
||||||
* Only provided fields will be added to the diagram and bom
|
* Only provided fields will be added to the diagram and bom
|
||||||
* Bundles can have part information specified by wire
|
* Bundles can have part information specified by wire
|
||||||
|
* Additional parts can be added to the bom
|
||||||
|
|||||||
@ -3,11 +3,11 @@ connectors:
|
|||||||
type: Molex KK 254
|
type: Molex KK 254
|
||||||
pincount: 4
|
pincount: 4
|
||||||
subtype: female
|
subtype: female
|
||||||
manufacturer: Molex
|
manufacturer: Molex # set manufacter name
|
||||||
manufacturer_part_number: 22013047
|
mpn: 22013047 # set manufacturer part number
|
||||||
X2:
|
X2:
|
||||||
<<: *template1 # reuse template
|
<<: *template1 # reuse template
|
||||||
internal_part_number: CON4
|
pn: CON4 # set an internal part number
|
||||||
X3:
|
X3:
|
||||||
<<: *template1 # reuse template
|
<<: *template1 # reuse template
|
||||||
|
|
||||||
@ -18,16 +18,16 @@ cables:
|
|||||||
gauge: 0.25 mm2
|
gauge: 0.25 mm2
|
||||||
color_code: IEC
|
color_code: IEC
|
||||||
manufacturer: CablesCo
|
manufacturer: CablesCo
|
||||||
manufacturer_part_number: ABC123
|
mpn: ABC123
|
||||||
internal_part_number: CAB1
|
pn: CAB1
|
||||||
W2:
|
W2:
|
||||||
category: bundle
|
category: bundle
|
||||||
length: 1
|
length: 1
|
||||||
gauge: 0.25 mm2
|
gauge: 0.25 mm2
|
||||||
colors: [YE, BK, BK, RD]
|
colors: [YE, BK, BK, RD]
|
||||||
manufacturer: [WiresCo,WiresCo,WiresCo,WiresCo]
|
manufacturer: [WiresCo,WiresCo,WiresCo,WiresCo] # set a manufacter per wire
|
||||||
manufacturer_part_number: [W1-YE,W1-BK,W1-BK,W1-RD]
|
mpn: [W1-YE,W1-BK,W1-BK,W1-RD]
|
||||||
internal_part_number: [WIRE1,WIRE2,WIRE2,WIRE3]
|
pn: [WIRE1,WIRE2,WIRE2,WIRE3]
|
||||||
|
|
||||||
|
|
||||||
connections:
|
connections:
|
||||||
@ -39,3 +39,14 @@ connections:
|
|||||||
- X1: [1-4]
|
- X1: [1-4]
|
||||||
- W2: [1-4]
|
- W2: [1-4]
|
||||||
- X3: [1-4]
|
- X3: [1-4]
|
||||||
|
|
||||||
|
additional_bom_items:
|
||||||
|
- # define an additional item to add to the bill of materials
|
||||||
|
description: Label, pinout information
|
||||||
|
qty: 2
|
||||||
|
designators:
|
||||||
|
- X2
|
||||||
|
- X3
|
||||||
|
manufacturer: generic company
|
||||||
|
mpn: Label1
|
||||||
|
pn: Label-ID-1
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user