aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:38:50 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2019-03-28 16:43:14 +0100
commitfa85d46af0b91477cf354947df628af0dc0d2800 (patch)
treeb18b775d232560f57eaeb3f43d0861b98201d4ef /src/ee/kicad
parent52401b170d8f1c9deaa153acca76e7d6060a06df (diff)
downloadee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.gz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.bz2
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.tar.xz
ee-python-fa85d46af0b91477cf354947df628af0dc0d2800.zip
ee.xsd:
o Renaming <part-uri> to <part-reference>. o Adding <supplier> on <part>, removing from <supplier-part-number>. A part can have exactly one part. create-order: o Creating anonymous part objects, with two references, one schematic reference and one part-uri reference to the selected part. o Redoing how the order is calculated with the new ObjDb structure. ee.part.Part: o Absorbing bom_file_utils into Part. Much better wrapper object around the xml goop.
Diffstat (limited to 'src/ee/kicad')
-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)