Support named type of cables (or wires in a bundle)
Add cable type to diagram and BOM entries.
This commit is contained in:
parent
c9895bd282
commit
6f91b65128
@ -124,7 +124,8 @@ 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)'
|
||||||
|
|
||||||
attributes = [f'{len(cable.colors)}x' if cable.show_wirecount else '',
|
attributes = [cable.type,
|
||||||
|
f'{len(cable.colors)}x' if cable.show_wirecount else '',
|
||||||
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '',
|
f'{cable.gauge} {cable.gauge_unit}{awg_fmt}' if cable.gauge else '',
|
||||||
'+ S' if cable.shield else '',
|
'+ S' if cable.shield else '',
|
||||||
f'{cable.length} m' if cable.length > 0 else '']
|
f'{cable.length} m' if cable.length > 0 else '']
|
||||||
@ -273,7 +274,7 @@ class Harness:
|
|||||||
# 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?
|
||||||
# Otherwise, it can be removed from the cable_group because it will allways be empty.
|
# Otherwise, it can be removed from the cable_group because it will allways be empty.
|
||||||
cable_group = lambda c: (c.category, c.gauge, c.gauge_unit, c.wirecount, c.shield)
|
cable_group = lambda c: (c.category, c.type, c.gauge, c.gauge_unit, c.wirecount, c.shield)
|
||||||
groups = Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle'])
|
groups = Counter([cable_group(v) for v in self.cables.values() if v.category != 'bundle'])
|
||||||
for group in groups:
|
for group in groups:
|
||||||
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}
|
||||||
@ -281,15 +282,16 @@ class Harness:
|
|||||||
designators = list(items.keys())
|
designators = list(items.keys())
|
||||||
designators.sort()
|
designators.sort()
|
||||||
total_length = sum(i.length for i in items.values())
|
total_length = sum(i.length for i in items.values())
|
||||||
|
cable_type = f', {shared.type}' if shared.type else ''
|
||||||
gauge_name = f' x {shared.gauge} {shared.gauge_unit}'if shared.gauge else ' wires'
|
gauge_name = f' x {shared.gauge} {shared.gauge_unit}'if shared.gauge else ' wires'
|
||||||
shield_name = ' shielded' if shared.shield else ''
|
shield_name = ' shielded' if shared.shield else ''
|
||||||
name = f'Cable, {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}
|
||||||
bom_cables.append(item)
|
bom_cables.append(item)
|
||||||
# bundles (ignores wirecount)
|
# bundles (ignores wirecount)
|
||||||
wirelist = []
|
wirelist = []
|
||||||
# list all cables again, since bundles are represented as wires internally, with the category='bundle' set
|
# list all cables again, since bundles are represented as wires internally, with the category='bundle' set
|
||||||
bundle_group = lambda b: (b.gauge, b.gauge_unit, b.length)
|
bundle_group = lambda b: (b.type, b.gauge, b.gauge_unit, b.length) # TODO: Why is b.lenght included?
|
||||||
groups = Counter([bundle_group(v) for v in self.cables.values() if v.category == 'bundle'])
|
groups = Counter([bundle_group(v) for v in self.cables.values() if v.category == 'bundle'])
|
||||||
for group in groups:
|
for group in groups:
|
||||||
items = {k: v for k, v in self.cables.items() if bundle_group(v) == group}
|
items = {k: v for k, v in self.cables.items() if bundle_group(v) == group}
|
||||||
@ -297,10 +299,10 @@ class Harness:
|
|||||||
for bundle in items.values():
|
for bundle in items.values():
|
||||||
# add each wire from each bundle to the wirelist
|
# add each wire from each bundle to the wirelist
|
||||||
for color in bundle.colors:
|
for color in bundle.colors:
|
||||||
wirelist.append({'gauge': shared.gauge, 'gauge_unit': shared.gauge_unit,
|
wirelist.append({'type': shared.type, 'gauge': shared.gauge, 'gauge_unit': shared.gauge_unit,
|
||||||
'length': shared.length, 'color': color, 'designator': bundle.name})
|
'length': shared.length, 'color': color, 'designator': bundle.name})
|
||||||
# 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['gauge'], w['gauge_unit'], w['color'])
|
wire_group = lambda w: (w['type'], w['gauge'], w['gauge_unit'], w['color'])
|
||||||
groups = Counter([wire_group(v) for v in wirelist])
|
groups = Counter([wire_group(v) for v in wirelist])
|
||||||
for group in groups:
|
for group in groups:
|
||||||
items = [v for v in wirelist if wire_group(v) == group]
|
items = [v for v in wirelist if wire_group(v) == group]
|
||||||
@ -310,9 +312,10 @@ class Harness:
|
|||||||
designators = list(dict.fromkeys(designators))
|
designators = list(dict.fromkeys(designators))
|
||||||
designators.sort()
|
designators.sort()
|
||||||
total_length = sum(i['length'] for i in items)
|
total_length = sum(i['length'] for i in items)
|
||||||
|
wire_type = f', {shared["type"]}' if shared['type'] else ''
|
||||||
gauge_name = f', {shared["gauge"]} {shared["gauge_unit"]}' if shared['gauge'] else ''
|
gauge_name = f', {shared["gauge"]} {shared["gauge_unit"]}' if shared['gauge'] else ''
|
||||||
gauge_color = f', {shared["color"]}' if shared['color'] != '' else ''
|
gauge_color = f', {shared["color"]}' if shared['color'] != '' else ''
|
||||||
name = f'Wire{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}
|
||||||
bom_cables.append(item)
|
bom_cables.append(item)
|
||||||
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
bom_cables = sorted(bom_cables, key=lambda k: k['item']) # https://stackoverflow.com/a/73050
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user