diff options
Diffstat (limited to 'src/ee/kicad')
-rw-r--r-- | src/ee/kicad/make_bom.py | 65 |
1 files changed, 54 insertions, 11 deletions
diff --git a/src/ee/kicad/make_bom.py b/src/ee/kicad/make_bom.py index bec42de..7c8d8f0 100644 --- a/src/ee/kicad/make_bom.py +++ b/src/ee/kicad/make_bom.py @@ -1,3 +1,4 @@ +import re import pydoc from pathlib import Path from typing import Optional, List, Callable, Mapping @@ -37,24 +38,65 @@ def apply_strategies(c: Component, part: Part, strategies: List[StrategyCallable return part -def part_type_strategy(component: Component, part: Part) -> Part: - fp = component.footprint - if fp is None: - return part - +def part_type_from_footprint(fp): lib, part_name = fp.split(":") - xml = part.underlying if lib == "Capacitor_SMD": - xml.part_typeProp = uris.CAPACITOR + return uris.CAPACITOR elif lib == "Resistor_SMD": - xml.part_typeProp = uris.RESISTOR + return uris.RESISTOR elif lib == "Diode_SMD": - xml.part_typeProp = uris.DIODE + return uris.DIODE elif lib == "Inductor_SMD": - xml.part_typeProp = uris.INDUCTOR + return uris.INDUCTOR elif lib == "Crystal": - xml.part_typeProp = uris.CRYSTAL + return uris.CRYSTAL + + +def part_type_from_ref_type(ref_type): + if ref_type == "C": + return uris.CAPACITOR + elif ref_type == "R": + return uris.RESISTOR + elif ref_type == "D": + return uris.DIODE + elif ref_type == "L": + return uris.INDUCTOR + elif ref_type == "X": + return uris.CRYSTAL + elif ref_type == "Q": + return uris.TRANSISTOR + + +def part_type_strategy(component: Component, part: Part) -> Part: + pt = None + + fp = component.footprint + if fp is not None: + pt = part_type_from_footprint(fp) + + if pt is None and component.has_ref_num: + pt = part_type_from_ref_type(component.ref_type) + + if pt is not None: + part.get_facts().append(types.Fact(uris.make_fact_key("type"), value=pt)) + + return part + + +def fix_value_strategy(component: Component, part: Part) -> Part: + if not component.has_ref_num: + return part + + rt = component.ref_type + v = component.value + + print("component.symbol.name={}".format(component.symbol.name)) + if rt in ("D", "R", "L", "C") and v == component.symbol.name: + part.remove_fact(uris.make_fact_key("value")) + + if rt == "Q" and v == component.symbol.name and re.match("^Q_[NP]MOS_[DSG]{3}$", component.symbol.name): + part.remove_fact(uris.make_fact_key("value")) return part @@ -85,6 +127,7 @@ class MakeBomStrategy(): def __init__(self): self.dpn_mappings = {} self.default_strategies = [ + fix_value_strategy, mpn_strategy, part_type_strategy, dpn_strategy_factory(self.dpn_mappings), |