aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad/make_bom.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ee/kicad/make_bom.py')
-rw-r--r--src/ee/kicad/make_bom.py45
1 files changed, 19 insertions, 26 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py
index 0a8f4bb..ddaa6b9 100644
--- a/src/ee/kicad/make_bom.py
+++ b/src/ee/kicad/make_bom.py
@@ -8,7 +8,7 @@ from ee import EeException
from ee.kicad.model import Component
from ee.kicad.read_schematic import read_schematics
from ee.kicad.to_bom import to_bom, to_bom_xml
-from ee.part import PartDb, save_db
+from ee.part import PartDb, save_db, Part
from ee.xml import types, uris
__all__ = [
@@ -21,61 +21,60 @@ __all__ = [
"make_bom",
]
-StrategyCallable = Callable[[Component, types.Part], Optional[types.Part]]
+StrategyCallable = Callable[[Component, Part], Optional[Part]]
-def apply_strategies(c: Component, part: types.Part, strategies: List[StrategyCallable]):
+def apply_strategies(c: Component, part: Part, strategies: List[StrategyCallable]):
for strategy in strategies:
part = strategy(c, part)
if part is None:
return
- if not isinstance(part, types.Part):
- raise EeException("Values returned from strategy must be a types.Part, got {}".format(type(part)))
+ if not isinstance(part, Part):
+ raise EeException("Values returned from strategy must be a Part, got {}".format(type(part)))
return part
-def part_type_strategy(component: Component, part: types.Part) -> types.Part:
+def part_type_strategy(component: Component, part: Part) -> Part:
fp = component.footprint
if fp is None:
return part
lib, part_name = fp.split(":")
+ xml = part.underlying
if lib == "Capacitor_SMD":
- part.part_typeProp = uris.CAPACITOR
+ xml.part_typeProp = uris.CAPACITOR
elif lib == "Resistor_SMD":
- part.part_typeProp = uris.RESISTOR
+ xml.part_typeProp = uris.RESISTOR
elif lib == "Diode_SMD":
- part.part_typeProp = uris.DIODE
+ xml.part_typeProp = uris.DIODE
elif lib == "Inductor_SMD":
- part.part_typeProp = uris.INDUCTOR
+ xml.part_typeProp = uris.INDUCTOR
elif lib == "Crystal":
- part.part_typeProp = uris.CRYSTAL
+ xml.part_typeProp = uris.CRYSTAL
return part
-def mpn_strategy(component: Component, part: types.Part) -> types.Part:
+def mpn_strategy(component: Component, part: Part) -> Part:
mpn = component.get_field("mpn")
if mpn is not None:
- pn = types.PartNumber(value=mpn.value)
- part.referencesProp.add_part_number(pn)
+ part.add_mpn(mpn.value)
return part
def dpn_strategy_factory(dpn_mappings: Mapping[str, str]) -> StrategyCallable:
- def dpn_strategy(component: Component, part: types.Part) -> types.Part:
+ def dpn_strategy(component: Component, part: Part) -> Part:
for field_name, distributor in dpn_mappings:
s = component.get_field(field_name)
if s is None:
continue
- pn = types.SupplierPartNumber(value=s.value, supplier=distributor)
- part.referencesProp.add_part_number(pn)
+ part.add_spn(s.value)
return part
@@ -111,21 +110,15 @@ def work(sch, out: Path, strategy: MakeBomStrategy, new_mode, pretty):
parts = PartDb()
components = to_bom(sch)
for c in components:
- part = types.Part()
- part.referencesProp = types.ReferencesList()
- part.referencesProp.schematic_reference.append(types.SchematicReference(reference=c.ref))
+ xml = types.Part()
+ part = Part(xml)
+ part.add_schematic_reference(c.ref)
part = strategy.process_part(c, part)
if part is None:
continue
- if len(part.referencesProp.schematic_reference) == 0 and \
- len(part.referencesProp.part_number) == 0 and \
- len(part.referencesProp.supplier_part_number) == 0:
- # No need to dirty the xml with empty lists
- part.referencesProp = None
-
parts.add_entry(part, True)
save_db(out, parts)