Split out class AdditionalBomItem from AdditionalComponent
https://github.com/wireviz/WireViz/pull/251#discussion_r1359055105 No output changed for any examples/tutorial/tests input.
This commit is contained in:
parent
51f730f28c
commit
6f6235ad25
@ -196,6 +196,9 @@ class Component:
|
|||||||
partnos = tuple(partnos)
|
partnos = tuple(partnos)
|
||||||
self.partnumbers = PartNumberInfo(*partnos)
|
self.partnumbers = PartNumberInfo(*partnos)
|
||||||
|
|
||||||
|
self.qty = self.parse_number_and_unit(self.qty, None)
|
||||||
|
self.amount = self.parse_number_and_unit(self.amount, None)
|
||||||
|
|
||||||
def parse_number_and_unit(
|
def parse_number_and_unit(
|
||||||
self,
|
self,
|
||||||
inp: Optional[Union[NumberAndUnit, float, int, str]],
|
inp: Optional[Union[NumberAndUnit, float, int, str]],
|
||||||
@ -260,21 +263,40 @@ class Component:
|
|||||||
def has_pn_info(self) -> bool:
|
def has_pn_info(self) -> bool:
|
||||||
return any([self.pn, self.manufacturer, self.mpn, self.supplier, self.spn])
|
return any([self.pn, self.manufacturer, self.mpn, self.supplier, self.spn])
|
||||||
|
|
||||||
|
@property
|
||||||
|
def description(self) -> str:
|
||||||
|
return f"{self.type}{', ' + self.subtype if self.subtype else ''}"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class AdditionalComponent(Component):
|
class AdditionalBomItem(Component):
|
||||||
qty_multiplier: Union[QtyMultiplierConnector, QtyMultiplierCable, int] = 1
|
designators: Optional[str] = None
|
||||||
_qty_multiplier_computed: Union[int, float] = 1
|
|
||||||
designators: Optional[str] = None # used for components definedi in the
|
@property
|
||||||
# additional_bom_items section within another component
|
def additional_components(self):
|
||||||
bgcolor: SingleColor = None # ^ same here
|
# An additional item may not have further nested additional comonents.
|
||||||
note: str = None
|
# This property is currently needed for objects in the same list as
|
||||||
|
# TopLevelGraphicalComponent objects in a Harness method.
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class GraphicalComponent(Component): # abstract class
|
||||||
|
bgcolor: Optional[SingleColor] = None
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
super().__post_init__()
|
super().__post_init__()
|
||||||
self.bgcolor = SingleColor(self.bgcolor)
|
self.bgcolor = SingleColor(self.bgcolor)
|
||||||
self.qty = self.parse_number_and_unit(self.qty, None)
|
|
||||||
self.amount = self.parse_number_and_unit(self.amount, None)
|
|
||||||
|
@dataclass
|
||||||
|
class AdditionalComponent(GraphicalComponent):
|
||||||
|
qty_multiplier: Union[QtyMultiplierConnector, QtyMultiplierCable, int] = 1
|
||||||
|
_qty_multiplier_computed: Union[int, float] = 1
|
||||||
|
note: str = None
|
||||||
|
|
||||||
|
def __post_init__(self):
|
||||||
|
super().__post_init__()
|
||||||
|
|
||||||
if isinstance(self.qty_multiplier, float) or isinstance(
|
if isinstance(self.qty_multiplier, float) or isinstance(
|
||||||
self.qty_multiplier, int
|
self.qty_multiplier, int
|
||||||
@ -289,24 +311,10 @@ class AdditionalComponent(Component):
|
|||||||
else:
|
else:
|
||||||
raise Exception(f"Unknown qty multiplier: {self.qty_multiplier}")
|
raise Exception(f"Unknown qty multiplier: {self.qty_multiplier}")
|
||||||
|
|
||||||
@property
|
|
||||||
def additional_components(self):
|
|
||||||
# an additional component may not have further nested additional comonents
|
|
||||||
return []
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def bom_qty(self):
|
def bom_qty(self):
|
||||||
return self.qty.number * self._qty_multiplier_computed
|
return self.qty.number * self._qty_multiplier_computed
|
||||||
|
|
||||||
@property
|
|
||||||
def description(self) -> str:
|
|
||||||
return f"{self.type}{', ' + self.subtype if self.subtype else ''}"
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
|
||||||
class GraphicalComponent(Component): # abstract class, for future use
|
|
||||||
bgcolor: Optional[SingleColor] = None
|
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class TopLevelGraphicalComponent(GraphicalComponent): # abstract class
|
class TopLevelGraphicalComponent(GraphicalComponent): # abstract class
|
||||||
@ -368,11 +376,15 @@ class Connector(TopLevelGraphicalComponent):
|
|||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
super().__post_init__()
|
super().__post_init__()
|
||||||
|
|
||||||
self.bgcolor = SingleColor(self.bgcolor)
|
|
||||||
self.bgcolor_title = SingleColor(self.bgcolor_title)
|
self.bgcolor_title = SingleColor(self.bgcolor_title)
|
||||||
self.color = MultiColor(self.color)
|
self.color = MultiColor(self.color)
|
||||||
|
|
||||||
# connectors do not support custom qty or amount
|
# connectors do not support custom qty or amount
|
||||||
|
if self.qty != NumberAndUnit(1, None):
|
||||||
|
raise Exception("Connector qty != 1 not supported")
|
||||||
|
if self.amount is not None:
|
||||||
|
raise Exception("Connector amount not supported")
|
||||||
|
# TODO: Delete next two assignments if tests above is sufficient. Please verify!
|
||||||
self.qty = NumberAndUnit(1, None)
|
self.qty = NumberAndUnit(1, None)
|
||||||
self.amount = None
|
self.amount = None
|
||||||
|
|
||||||
@ -653,7 +665,6 @@ class Cable(TopLevelGraphicalComponent):
|
|||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
super().__post_init__()
|
super().__post_init__()
|
||||||
|
|
||||||
self.bgcolor = SingleColor(self.bgcolor)
|
|
||||||
self.bgcolor_title = SingleColor(self.bgcolor_title)
|
self.bgcolor_title = SingleColor(self.bgcolor_title)
|
||||||
self.color = MultiColor(self.color)
|
self.color = MultiColor(self.color)
|
||||||
|
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import wireviz.wv_colors
|
|||||||
from wireviz.wv_bom import BomCategory, BomEntry, bom_list, print_bom_table
|
from wireviz.wv_bom import BomCategory, BomEntry, bom_list, print_bom_table
|
||||||
from wireviz.wv_dataclasses import (
|
from wireviz.wv_dataclasses import (
|
||||||
AUTOGENERATED_PREFIX,
|
AUTOGENERATED_PREFIX,
|
||||||
AdditionalComponent,
|
AdditionalBomItem,
|
||||||
Arrow,
|
Arrow,
|
||||||
ArrowWeight,
|
ArrowWeight,
|
||||||
Cable,
|
Cable,
|
||||||
@ -48,7 +48,7 @@ class Harness:
|
|||||||
metadata: Metadata
|
metadata: Metadata
|
||||||
options: Options
|
options: Options
|
||||||
tweak: Tweak
|
tweak: Tweak
|
||||||
additional_bom_items: List[AdditionalComponent] = field(default_factory=list)
|
additional_bom_items: List[AdditionalBomItem] = field(default_factory=list)
|
||||||
|
|
||||||
def __post_init__(self):
|
def __post_init__(self):
|
||||||
self.connectors = {}
|
self.connectors = {}
|
||||||
@ -66,7 +66,7 @@ class Harness:
|
|||||||
self.cables[designator] = cbl
|
self.cables[designator] = cbl
|
||||||
|
|
||||||
def add_additional_bom_item(self, item: dict) -> None:
|
def add_additional_bom_item(self, item: dict) -> None:
|
||||||
new_item = AdditionalComponent(**item)
|
new_item = AdditionalBomItem(**item)
|
||||||
self.additional_bom_items.append(new_item)
|
self.additional_bom_items.append(new_item)
|
||||||
|
|
||||||
def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_str) -> None:
|
def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_str) -> None:
|
||||||
@ -200,7 +200,7 @@ class Harness:
|
|||||||
qty=comp.bom_qty,
|
qty=comp.bom_qty,
|
||||||
category=BomCategory.ADDITIONAL_INSIDE,
|
category=BomCategory.ADDITIONAL_INSIDE,
|
||||||
)
|
)
|
||||||
elif isinstance(item, AdditionalComponent):
|
elif isinstance(item, AdditionalBomItem):
|
||||||
cat = BomCategory.ADDITIONAL_OUTSIDE
|
cat = BomCategory.ADDITIONAL_OUTSIDE
|
||||||
_add(
|
_add(
|
||||||
hash=item.bom_hash,
|
hash=item.bom_hash,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user