diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-07 12:41:42 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-07 12:41:42 +0200 |
commit | aa9b9d0560b6515a05c2b2c94a75a50fde25e353 (patch) | |
tree | 2afb2f09e85310e71e78c77a3224ae7555c2411d /src | |
parent | 2a48664afc5f634157d9c383f605d0d2541ca1d9 (diff) | |
download | ee-python-aa9b9d0560b6515a05c2b2c94a75a50fde25e353.tar.gz ee-python-aa9b9d0560b6515a05c2b2c94a75a50fde25e353.tar.bz2 ee-python-aa9b9d0560b6515a05c2b2c94a75a50fde25e353.tar.xz ee-python-aa9b9d0560b6515a05c2b2c94a75a50fde25e353.zip |
kicad: Better export:
* Allow unannotated parts in the export.
* Export value and footprint too.
Diffstat (limited to 'src')
-rw-r--r-- | src/ee/kicad/make_bom.py | 25 | ||||
-rw-r--r-- | src/ee/kicad/to_bom.py | 17 | ||||
-rw-r--r-- | src/ee/part/__init__.py | 10 |
3 files changed, 48 insertions, 4 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py index db4f80e..bec42de 100644 --- a/src/ee/kicad/make_bom.py +++ b/src/ee/kicad/make_bom.py @@ -98,6 +98,11 @@ class MakeBomStrategy(): def work(sch, out: Path, strategy: MakeBomStrategy, new_mode, pretty): + def strip(s): + s = (s or "").strip() + + return None if len(s) == 0 else s + if not new_mode: bom = to_bom_xml(sch) xml = ElementTree.tostring(bom, encoding="unicode") @@ -108,11 +113,27 @@ def work(sch, out: Path, strategy: MakeBomStrategy, new_mode, pretty): print(xml) else: parts = PartDb() - components = to_bom(sch) + components = to_bom(sch, require_ref=False) for c in components: xml = types.Part() part = Part(xml) - part.add_schematic_reference(c.ref) + + if c.has_ref_num: + part.add_schematic_reference(c.ref) + + value = strip(c.value) + if value: + part.facts.add(uris.make_fact_key("value"), value) + + footprint = strip(c.footprint) + if footprint: + part.facts.add(uris.make_fact_key("footprint"), footprint) + + i = footprint.find(":") + if i >= 0: + lib, footprint = footprint.split(":") + part.facts.add(uris.make_fact_key("kicad-schematic-library"), lib) + part.facts.add(uris.make_fact_key("kicad-schematic-footprint"), footprint) part = strategy.process_part(c, part) diff --git a/src/ee/kicad/to_bom.py b/src/ee/kicad/to_bom.py index 8ca3c19..354d9ba 100644 --- a/src/ee/kicad/to_bom.py +++ b/src/ee/kicad/to_bom.py @@ -35,8 +35,21 @@ def comp(c: Component) -> Element: return comp -def to_bom(schematic: Union[Schematic, Schematics]) -> Iterable[Component]: - return [c for c in sorted(schematic.components) if c.has_ref_num and c.ref_type != "#PWR" and c.ref_type != "#FLG"] +def to_bom(schematic: Union[Schematic, Schematics], require_ref=True) -> Iterable[Component]: + bad_ref_types = ("#PWR", "#FLG") + + cs = [] + + for c in sorted(schematic.components): + if require_ref and not c.has_ref_num: + continue + + if c.ref_type in bad_ref_types: + continue + + cs.append(c) + + return cs def to_bom_xml(schematic: Schematic) -> Element: diff --git a/src/ee/part/__init__.py b/src/ee/part/__init__.py index fbf0838..4354771 100644 --- a/src/ee/part/__init__.py +++ b/src/ee/part/__init__.py @@ -22,6 +22,8 @@ class Part(object): xml.linksProp = xml.linksProp if xml.linksProp is not None else types.LinkList() xml.factsProp = xml.factsProp if xml.factsProp is not None else types.FactList() + self.facts = Facts(self) + def clean_xml(self): x = self.xml if len(x.referencesProp.part_referenceProp) == 0 and \ @@ -154,6 +156,14 @@ class Part(object): return next((f for f in self.get_facts() if f.keyProp == key), None) +class Facts(object): + def __init__(self, part): + self.part = part + + def add(self, key: str, value: str, label=None): + self.part.get_facts().append(types.Fact(key=key, label=label, value=value)) + + class Entry(object): def __init__(self, new: bool, part: types.Part): self.new = new |