Add support for cables to have extra components
This commit is contained in:
parent
9a1bc20ace
commit
1a8942abaa
@ -142,6 +142,7 @@ class Cable:
|
|||||||
show_name: bool = True
|
show_name: bool = True
|
||||||
show_wirecount: bool = True
|
show_wirecount: bool = True
|
||||||
ignore_in_bom: bool = False
|
ignore_in_bom: bool = False
|
||||||
|
additional_components: List[Any] = None
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
|
|
||||||
|
|||||||
@ -102,25 +102,22 @@ class Harness:
|
|||||||
[html_caption(connector.image)]]
|
[html_caption(connector.image)]]
|
||||||
if connector.additional_components is not None:
|
if connector.additional_components is not None:
|
||||||
rows.append(["Additional components"])
|
rows.append(["Additional components"])
|
||||||
for extra in connector.additional_components:
|
for extra in connector.additional_components:
|
||||||
if 'qty' in extra:
|
if 'qty' in extra:
|
||||||
if isinstance(extra['qty'], int) or isinstance(extra['qty'], float):
|
if isinstance(extra['qty'], int) or isinstance(extra['qty'], float):
|
||||||
qty = extra['qty']
|
qty = extra['qty']
|
||||||
else: # check for special quantities
|
else: # check for special quantities
|
||||||
if extra['qty'] == 'pincount':
|
if extra['qty'] == 'pincount':
|
||||||
qty = connector.pincount
|
qty = connector.pincount
|
||||||
elif extra['qty'] == 'connectioncount':
|
elif extra['qty'] == 'connectioncount':
|
||||||
qty = sum(1 for value in connector.visible_pins.values() if value is True)
|
qty = sum(1 for value in connector.visible_pins.values() if value is True)
|
||||||
else:
|
else:
|
||||||
raise ValueError('invalid aty parameter')
|
raise ValueError('invalid aty parameter')
|
||||||
else:
|
else:
|
||||||
qty = 1
|
qty = 1
|
||||||
rows.append([extra["type"], qty])
|
rows.append([extra["type"], qty])
|
||||||
rows.append([extra["manufacturer"],
|
rows.append([f'P/N: {extra["pn"]}' if extra["pn"] else None,
|
||||||
f'MPN: {extra["manufacturer_part_number"]}' if "manufacturer_part_number" in extra else None,
|
html_line_breaks(manufacturer_info_field(extra.get("manufacturer", None), extra.get("mpn", None)))])
|
||||||
f'IPN: {extra["internal_part_number"]}' if "internal_part_number" in extra else None],)
|
|
||||||
rows.append([f'P/N: {extra["pn"]}' if extra["pn"] else None,
|
|
||||||
html_line_breaks(manufacturer_info_field(extra.get("manufacturer", None), extra.get("mpn", None)))])
|
|
||||||
rows.append([html_line_breaks(connector.notes)])
|
rows.append([html_line_breaks(connector.notes)])
|
||||||
html.extend(nested_html_table(rows))
|
html.extend(nested_html_table(rows))
|
||||||
|
|
||||||
@ -193,8 +190,31 @@ class Harness:
|
|||||||
cable.color, html_colorbar(cable.color)],
|
cable.color, html_colorbar(cable.color)],
|
||||||
'<!-- wire table -->',
|
'<!-- wire table -->',
|
||||||
[html_image(cable.image)],
|
[html_image(cable.image)],
|
||||||
[html_caption(cable.image)],
|
[html_caption(cable.image)]]
|
||||||
[html_line_breaks(cable.notes)]]
|
|
||||||
|
if cable.additional_components is not None:
|
||||||
|
rows.append(["Additional components"])
|
||||||
|
for extra in cable.additional_components:
|
||||||
|
if 'qty' in extra:
|
||||||
|
if isinstance(extra['qty'], int) or isinstance(extra['qty'], float):
|
||||||
|
qty = extra['qty']
|
||||||
|
else: # check for special quantities
|
||||||
|
if extra['qty'] == 'wirecount':
|
||||||
|
qty = cable.wirecount
|
||||||
|
elif extra['qty'] == 'terminations':
|
||||||
|
qty = len(cable.connections)
|
||||||
|
elif extra['qty'] == 'length':
|
||||||
|
qty = cable.length
|
||||||
|
elif extra['qty'] == 'total_length':
|
||||||
|
qty = cable.length * cable.wirecount
|
||||||
|
else:
|
||||||
|
raise ValueError('invalid aty parameter {}'.format(extra["qty"]))
|
||||||
|
else:
|
||||||
|
qty = 1
|
||||||
|
rows.append([extra["type"], qty])
|
||||||
|
rows.append([f'P/N: {extra["pn"]}' if extra["pn"] else None,
|
||||||
|
html_line_breaks(manufacturer_info_field(extra.get("manufacturer", None), extra.get("mpn", None)))])
|
||||||
|
rows.append([html_line_breaks(cable.notes)])
|
||||||
html.extend(nested_html_table(rows))
|
html.extend(nested_html_table(rows))
|
||||||
|
|
||||||
wirehtml = []
|
wirehtml = []
|
||||||
@ -355,6 +375,7 @@ class Harness:
|
|||||||
bom_connectors = []
|
bom_connectors = []
|
||||||
bom_connectors_extra = []
|
bom_connectors_extra = []
|
||||||
bom_cables = []
|
bom_cables = []
|
||||||
|
bom_cables_extra = []
|
||||||
bom_extra = []
|
bom_extra = []
|
||||||
# connectors
|
# connectors
|
||||||
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.mpn, c.pn)
|
connector_group = lambda c: (c.type, c.subtype, c.pincount, c.manufacturer, c.mpn, c.pn)
|
||||||
@ -463,6 +484,52 @@ class Harness:
|
|||||||
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)
|
||||||
|
|
||||||
|
cables_extra = []
|
||||||
|
for cable in self.cables.values():
|
||||||
|
if cable.additional_components:
|
||||||
|
for part in cable.additional_components:
|
||||||
|
if 'qty' in part:
|
||||||
|
if isinstance(part['qty'], int) or isinstance(part['qty'], float):
|
||||||
|
qty = part['qty']
|
||||||
|
else: # check for special quantities
|
||||||
|
if part['qty'] == 'wirecount':
|
||||||
|
qty = cable.wirecount
|
||||||
|
elif part['qty'] == 'terminations':
|
||||||
|
qty = len(cable.connections)
|
||||||
|
elif part['qty'] == 'length':
|
||||||
|
qty = cable.length
|
||||||
|
elif part['qty'] == 'total_length':
|
||||||
|
qty = cable.length * cable.wirecount
|
||||||
|
else:
|
||||||
|
raise ValueError('invalid aty parameter')
|
||||||
|
else:
|
||||||
|
qty = 1
|
||||||
|
cables_extra.append(
|
||||||
|
{
|
||||||
|
'type': part.get('type', None),
|
||||||
|
'qty': qty,
|
||||||
|
'unit': part.get('unit', None),
|
||||||
|
'manufacturer': part.get('manufacturer', None),
|
||||||
|
'mpn': part.get('mpn', None),
|
||||||
|
'pn': part.get('pn', None),
|
||||||
|
'designator': connector.name
|
||||||
|
}
|
||||||
|
)
|
||||||
|
cables_extra_group = lambda ce: (ce['type'], ce['qty'], ce['unit'], ce['manufacturer'], ce['mpn'], ce['pn'])
|
||||||
|
for group in Counter([connector_extra_group(v) for v in cables_extra]):
|
||||||
|
items = [v for v in cables_extra if connector_extra_group(v) == group]
|
||||||
|
shared = items[0]
|
||||||
|
designators = [i['designator'] for i in items]
|
||||||
|
designators = list(dict.fromkeys(designators)) # remove duplicates
|
||||||
|
designators.sort()
|
||||||
|
total_qty = sum(i['qty'] for i in items)
|
||||||
|
|
||||||
|
item = {'item': shared['type'], 'qty': round(total_qty, 3), 'unit': shared['unit'], 'designators': designators,
|
||||||
|
'manufacturer': shared['manufacturer'], 'mpn': shared['mpn'], 'pn': shared['pn']}
|
||||||
|
bom_cables_extra.append(item)
|
||||||
|
bom_cables_extra = sorted(bom_cables_extra, key=lambda k: k['item']) # sort list of dicts by their values (https://stackoverflow.com/a/73050)
|
||||||
|
bom.extend(bom_cables_extra)
|
||||||
|
|
||||||
for item in self.additional_bom_items:
|
for item in self.additional_bom_items:
|
||||||
name = item['description'] if item.get('description', None) else ''
|
name = item['description'] if item.get('description', None) else ''
|
||||||
if isinstance(item.get('designators', None), List):
|
if isinstance(item.get('designators', None), List):
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user