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