Improve BOM generation (TODO: wires from a bundle)
This commit is contained in:
parent
b60db7902b
commit
5c18001188
@ -14,7 +14,7 @@ from wireviz.wv_colors import (
|
||||
SingleColor,
|
||||
get_color_by_colorcode_index,
|
||||
)
|
||||
from wireviz.wv_helper import aspect_ratio, awg_equiv, mm2_equiv
|
||||
from wireviz.wv_helper import aspect_ratio, awg_equiv, mm2_equiv, remove_links
|
||||
|
||||
# Each type alias have their legal values described in comments
|
||||
# - validation might be implemented in the future
|
||||
@ -213,9 +213,10 @@ class Component:
|
||||
bom_id: Optional[str] = None # to be filled after harness is built
|
||||
|
||||
def fill_partnumbers(self):
|
||||
self.partnumbers = PartNumberInfo(
|
||||
self.pn, self.manufacturer, self.mpn, self.supplier, self.spn
|
||||
)
|
||||
partnos = [self.pn, self.manufacturer, self.mpn, self.supplier, self.spn]
|
||||
partnos = [remove_links(entry) for entry in partnos]
|
||||
partnos = tuple(partnos)
|
||||
self.partnumbers = PartNumberInfo(*partnos)
|
||||
|
||||
@property
|
||||
def bom_hash(self) -> BomHash:
|
||||
@ -263,8 +264,8 @@ class AdditionalComponent(Component):
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
s = self.type.rstrip() + f", {self.subtype.rstrip()}" if self.subtype else ""
|
||||
return s
|
||||
substrs = [self.type, self.subtype if self.subtype else ""]
|
||||
return ", ".join(substrs)
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -313,7 +314,7 @@ class Connector(TopLevelGraphicalComponent):
|
||||
"Connector",
|
||||
self.type,
|
||||
self.subtype,
|
||||
self.pincount if self.show_pincount else None,
|
||||
f"{self.pincount} pins" if self.show_pincount else None,
|
||||
str(self.color) if self.color else None,
|
||||
]
|
||||
return ", ".join([str(s) for s in substrs if s is not None and s != ""])
|
||||
|
||||
@ -14,6 +14,7 @@ from wireviz.DataClasses import (
|
||||
Arrow,
|
||||
ArrowWeight,
|
||||
Cable,
|
||||
Component,
|
||||
Connector,
|
||||
MateComponent,
|
||||
MatePin,
|
||||
@ -55,15 +56,11 @@ class Harness:
|
||||
conn = Connector(designator=designator, *args, **kwargs)
|
||||
self.connectors[designator] = conn
|
||||
self._add_to_internal_bom(conn)
|
||||
for addcom in conn.additional_components:
|
||||
self._add_to_internal_bom(addcom)
|
||||
|
||||
def add_cable(self, designator: str, *args, **kwargs) -> None:
|
||||
cbl = Cable(designator=designator, *args, **kwargs)
|
||||
self.cables[designator] = cbl
|
||||
self._add_to_internal_bom(cbl)
|
||||
for addcom in cbl.additional_components:
|
||||
self._add_to_internal_bom(addcom)
|
||||
|
||||
def add_additional_bom_item(self, item: dict) -> None:
|
||||
new_item = AdditionalComponent(**item)
|
||||
@ -85,7 +82,7 @@ class Harness:
|
||||
arrow = Arrow(direction=parse_arrow_str(arrow_str), weight=ArrowWeight.SINGLE)
|
||||
self.mates.append(MateComponent(from_name, to_name, arrow))
|
||||
|
||||
def _add_to_internal_bom(self, item):
|
||||
def _add_to_internal_bom(self, item: Component):
|
||||
if item.ignore_in_bom:
|
||||
return
|
||||
|
||||
@ -99,11 +96,15 @@ class Harness:
|
||||
bom_entry["designators"] = set()
|
||||
# update fields
|
||||
bom_entry["qty"] += qty
|
||||
if designator and not designator.startswith(AUTOGENERATED_PREFIX):
|
||||
if isinstance(designator, str):
|
||||
bom_entry["designators"].add(designator)
|
||||
else: # list
|
||||
bom_entry["designators"].update(designator)
|
||||
if designator is None:
|
||||
designator_list = []
|
||||
elif isinstance(designator, list):
|
||||
designator_list = designator
|
||||
else:
|
||||
designator_list = [designator]
|
||||
for des in designator_list:
|
||||
if des and not des.startswith(AUTOGENERATED_PREFIX):
|
||||
bom_entry["designators"].add(des)
|
||||
bom_entry["category"] = category
|
||||
|
||||
if isinstance(item, Connector):
|
||||
@ -119,13 +120,13 @@ class Harness:
|
||||
)
|
||||
elif isinstance(item, Cable):
|
||||
_bom_hash = item.bom_hash
|
||||
if isinstance(_bom_hash, list):
|
||||
_cat = "bundle"
|
||||
for subhash in _bom_hash:
|
||||
_add(subhash, designator=item.designator, category=_cat)
|
||||
if item.category == "bundle":
|
||||
_cat = "wire"
|
||||
for wire in item.wire_objects:
|
||||
_add(None, qty=item.length+.001, designator=item.designator, category="wire DUMMY")
|
||||
else:
|
||||
_cat = "cable"
|
||||
_add(item.bom_hash, designator=item.designator, category=_cat)
|
||||
_add(item.bom_hash, qty=item.length, designator=item.designator, category="cable")
|
||||
for comp in item.additional_components:
|
||||
if comp.ignore_in_bom:
|
||||
continue
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user