Prepare harness.populate_bom()
This commit is contained in:
parent
1cba27fba0
commit
cb07d51b2f
@ -253,7 +253,7 @@ class Component:
|
||||
class AdditionalComponent(Component):
|
||||
qty: float = 1
|
||||
unit: Optional[str] = None
|
||||
qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = None
|
||||
qty_multiplier: Union[ConnectorMultiplier, CableMultiplier, None] = 1
|
||||
designators: Optional[str] = None # used for components definedi in the
|
||||
# additional_bom_items section within another component
|
||||
bgcolor: SingleColor = None # ^ same here
|
||||
@ -262,6 +262,10 @@ class AdditionalComponent(Component):
|
||||
super().fill_partnumbers()
|
||||
self.bgcolor = SingleColor(self.bgcolor)
|
||||
|
||||
@property
|
||||
def qty_final(self):
|
||||
return 999
|
||||
|
||||
@property
|
||||
def description(self) -> str:
|
||||
substrs = [self.type, self.subtype if self.subtype else ""]
|
||||
@ -424,6 +428,7 @@ class Connector(TopLevelGraphicalComponent):
|
||||
self.ports_right = True
|
||||
|
||||
def get_qty_multiplier(self, qty_multiplier: Optional[ConnectorMultiplier]) -> int:
|
||||
# TODO!!! how and when to compute final qty for additional components???
|
||||
if not qty_multiplier:
|
||||
return 1
|
||||
elif qty_multiplier == "pincount":
|
||||
|
||||
@ -55,17 +55,17 @@ class Harness:
|
||||
def add_connector(self, designator: str, *args, **kwargs) -> None:
|
||||
conn = Connector(designator=designator, *args, **kwargs)
|
||||
self.connectors[designator] = conn
|
||||
self._add_to_internal_bom(conn)
|
||||
# self._add_to_internal_bom(conn)
|
||||
|
||||
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)
|
||||
# self._add_to_internal_bom(cbl)
|
||||
|
||||
def add_additional_bom_item(self, item: dict) -> None:
|
||||
new_item = AdditionalComponent(**item)
|
||||
self.additional_bom_items.append(new_item)
|
||||
self._add_to_internal_bom(new_item)
|
||||
# self._add_to_internal_bom(new_item)
|
||||
|
||||
def add_mate_pin(self, from_name, from_pin, to_name, to_pin, arrow_str) -> None:
|
||||
from_con = self.connectors[from_name]
|
||||
@ -115,7 +115,7 @@ class Harness:
|
||||
_add(
|
||||
comp.bom_hash,
|
||||
designator=item.designator,
|
||||
qty=comp.qty,
|
||||
qty=comp.qty_final,
|
||||
category="connector/additional",
|
||||
)
|
||||
elif isinstance(item, Cable):
|
||||
@ -123,29 +123,47 @@ class Harness:
|
||||
if item.category == "bundle":
|
||||
_cat = "wire"
|
||||
for wire in item.wire_objects:
|
||||
_add(None, qty=item.length+.001, designator=item.designator, category="wire DUMMY")
|
||||
_add(
|
||||
None,
|
||||
qty=item.length + 0.001,
|
||||
designator=item.designator,
|
||||
category="wire DUMMY",
|
||||
)
|
||||
else:
|
||||
_cat = "cable"
|
||||
_add(item.bom_hash, qty=item.length, designator=item.designator, category="cable")
|
||||
_add(
|
||||
item.bom_hash,
|
||||
qty=item.length,
|
||||
designator=item.designator,
|
||||
category="cable",
|
||||
)
|
||||
for comp in item.additional_components:
|
||||
if comp.ignore_in_bom:
|
||||
continue
|
||||
_add(
|
||||
comp.bom_hash,
|
||||
designator=item.designator,
|
||||
qty=comp.qty,
|
||||
qty=comp.qty_final,
|
||||
category=f"{_cat}/additional",
|
||||
)
|
||||
elif isinstance(item, AdditionalComponent): # additional component
|
||||
_add(
|
||||
item.bom_hash,
|
||||
designator=item.designators,
|
||||
qty=item.qty,
|
||||
qty=item.qty_final,
|
||||
category="additional",
|
||||
)
|
||||
else:
|
||||
raise Exception(f"Unknown type of item:\n{item}")
|
||||
|
||||
def populate_bom(self):
|
||||
pass
|
||||
# raise Exception(
|
||||
# "Implement BOM population after all connections have been made, "
|
||||
# " so that additional component qty's can be computed correctly "
|
||||
# "(factoring in number of connected pins/wires/...)"
|
||||
# )
|
||||
|
||||
def connect(
|
||||
self,
|
||||
from_name: str,
|
||||
|
||||
@ -370,6 +370,8 @@ def parse(
|
||||
for line in yaml_data["additional_bom_items"]:
|
||||
harness.add_additional_bom_item(line)
|
||||
|
||||
harness.populate_bom()
|
||||
|
||||
if output_formats:
|
||||
harness.output(filename=output_file, fmt=output_formats, view=False)
|
||||
|
||||
|
||||
@ -5,6 +5,8 @@ from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
from typing import List, Optional, Union
|
||||
|
||||
from wireviz.wv_helper import html_line_breaks
|
||||
|
||||
BOM_HASH_FIELDS = "description unit partnumbers"
|
||||
BomHash = namedtuple("BomHash", BOM_HASH_FIELDS)
|
||||
BomHashList = namedtuple("BomHashList", BOM_HASH_FIELDS)
|
||||
|
||||
@ -19,7 +19,7 @@ from wireviz.DataClasses import (
|
||||
WireClass,
|
||||
)
|
||||
from wireviz.wv_bom import partnumbers_to_list
|
||||
from wireviz.wv_helper import remove_links
|
||||
from wireviz.wv_helper import html_line_breaks, remove_links
|
||||
from wireviz.wv_table_util import * # TODO: explicitly import each needed tag later
|
||||
|
||||
|
||||
@ -454,10 +454,6 @@ def html_size_attr_dict(image):
|
||||
return attr_dict
|
||||
|
||||
|
||||
def html_line_breaks(inp):
|
||||
return remove_links(inp).replace("\n", "<br />") if isinstance(inp, str) else inp
|
||||
|
||||
|
||||
def set_dot_basics(dot, options):
|
||||
dot.body.append(f"// Graph generated by {APP_NAME} {__version__}")
|
||||
dot.body.append(f"// {APP_URL}")
|
||||
|
||||
@ -100,6 +100,10 @@ def tuplelist2tsv(inp, header=None):
|
||||
return output
|
||||
|
||||
|
||||
def html_line_breaks(inp):
|
||||
return remove_links(inp).replace("\n", "<br />") if isinstance(inp, str) else inp
|
||||
|
||||
|
||||
def remove_links(inp):
|
||||
return (
|
||||
re.sub(r"<[aA] [^>]*>([^<]*)</[aA]>", r"\1", inp)
|
||||
|
||||
@ -6,9 +6,9 @@ from typing import Dict, List, Union
|
||||
|
||||
from wireviz import APP_NAME, APP_URL, __version__, wv_colors
|
||||
from wireviz.DataClasses import Metadata, Options
|
||||
from wireviz.wv_gv_html import html_line_breaks
|
||||
from wireviz.wv_helper import (
|
||||
flatten2d,
|
||||
html_line_breaks,
|
||||
open_file_read,
|
||||
open_file_write,
|
||||
smart_file_resolve,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user