aboutsummaryrefslogtreecommitdiff
path: root/src/ee/part
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/part')
-rw-r--r--src/ee/part/bom.py41
1 files changed, 23 insertions, 18 deletions
diff --git a/src/ee/part/bom.py b/src/ee/part/bom.py
index 0bf284a..fe0bb12 100644
--- a/src/ee/part/bom.py
+++ b/src/ee/part/bom.py
@@ -25,19 +25,30 @@ class BomLine(object):
def __init__(self, uri, part: Part):
self.uri = uri
self.part = part
- self.refs = []
+ self.refs: List[str] = []
- def add_ref(self, ref):
+ def add_ref(self, ref: str):
self.refs.append(ref)
def __lt__(self, other):
return self.uri < other.uri
-class BomItem(object):
- def __init__(self, references, part: Part):
- self.references = references
- self.part = part
+class Bom(object):
+ def __init__(self):
+ self._lines: MutableMapping[str, BomLine] = {}
+
+ def add_part(self, part_uri, supplier_part, reference):
+ if part_uri not in self._lines:
+ self._lines[part_uri] = line = BomLine(part_uri, supplier_part)
+ else:
+ line = self._lines[part_uri]
+
+ line.add_ref(reference)
+
+ @property
+ def lines(self) -> List[BomLine]:
+ return sorted(self._lines.values())
def load_bom(bom_path: Path, part_files: List[Path]) -> (ObjDb[Part](), ObjDb[Part]()):
@@ -67,12 +78,10 @@ def check_bom(bom: ObjDb[Part](), parts: ObjDb[Part]()):
pass
-def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb[Part], group_by_ref=True) -> \
- Optional[List[BomLine]]:
- lines: MutableMapping[str, BomLine] = {}
-
+def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb[Part]) -> Optional[Bom]:
uri_idx = supplier_parts.index("uri")
+ bom = Bom()
for part in bom_parts.values:
pr = part.get_only_part_reference()
@@ -85,15 +94,11 @@ def generate_bom(allow_incomplete, bom_parts: ObjDb[Part], supplier_parts: ObjDb
part_uri = pr.part_uriProp
- if part_uri not in lines:
- supplier_part = uri_idx.get_single(part_uri)
- lines[part_uri] = line = BomLine(part_uri, supplier_part)
- else:
- line = lines[part_uri]
-
- line.add_ref(part.get_exactly_one_schematic_reference().referenceProp)
+ supplier_part = uri_idx.get_single(part_uri)
+ reference = part.get_exactly_one_schematic_reference().referenceProp
+ bom.add_part(part_uri, supplier_part, reference)
- return sorted(lines.values())
+ return bom
def split_ref(ref):