diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-20 15:27:38 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2019-05-20 15:27:38 +0200 |
commit | 9eba62ef1d6b4896de693976116f69a9692332d9 (patch) | |
tree | 98ae9fdf48818206a6db552938c53e35abf1c45d /src/ee/kicad/functions.py | |
parent | def66a1bd81283d38b468b66ff6e4e34621a5ce2 (diff) | |
download | ee-python-9eba62ef1d6b4896de693976116f69a9692332d9.tar.gz ee-python-9eba62ef1d6b4896de693976116f69a9692332d9.tar.bz2 ee-python-9eba62ef1d6b4896de693976116f69a9692332d9.tar.xz ee-python-9eba62ef1d6b4896de693976116f69a9692332d9.zip |
ee:
o Adding FactType as a smaller wrapper around the fact uri.
o Adding ee.part.Facts, used as Part.facts
o Renaming 'type' uri to 'ee-component-type'.
kicad-make-bom: Removing strategy functionality, replaced with
part-apply-function. Moving default strategy contents into
ee.kicad.functions.
Diffstat (limited to 'src/ee/kicad/functions.py')
-rw-r--r-- | src/ee/kicad/functions.py | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/ee/kicad/functions.py b/src/ee/kicad/functions.py new file mode 100644 index 0000000..39614b6 --- /dev/null +++ b/src/ee/kicad/functions.py @@ -0,0 +1,105 @@ +import re + +import ee.kicad.model +import ee.kicad.sch_fact_types as kicad_ft +from ee.kicad import sch_fact_types +from ee.part import Part +from ee.part import common_fact_types +from ee.xml import uris + + +def part_type_from_footprint(lib): + if lib == "Capacitor_SMD": + return uris.CAPACITOR + elif lib == "Resistor_SMD": + return uris.RESISTOR + elif lib == "Diode_SMD": + return uris.DIODE + elif lib == "Inductor_SMD": + return uris.INDUCTOR + elif lib == "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(part: Part) -> Part: + pt = None + + fp_lib = part.facts.get_value(kicad_ft.footprint_library) + if fp_lib is not None: + pt = part_type_from_footprint(fp_lib) + + ref = part.get_only_schematic_reference() + if ref: + ref_type, ref_num = ee.kicad.model.split_ref(ref.referenceProp) + + if ref_type: + pt = part_type_from_ref_type(ref_type) + + if pt is not None: + part.facts.add(common_fact_types.ee_component_type, pt) + + return part + + +def fix_value_strategy(part: Part) -> Part: + ref = part.get_only_schematic_reference() + + if not ref: + return part + + ref_type, ref_num = ee.kicad.model.split_ref(ref.referenceProp) + + if not ref_num: + return part + + v = part.facts.get_value(sch_fact_types.value) + if not v: + return part + + symbol_name = part.facts.get_value(sch_fact_types.symbol_name) + + if ref_type in ("D", "R", "L", "C") and v == symbol_name: + part.remove_fact(uris.make_fact_key("value")) + + if ref_type == "Q" and v == symbol_name and re.match("^Q_[NP]MOS_[DSG]{3}$", symbol_name): + part.remove_fact(uris.make_fact_key("value")) + + return part + + +def mpn_strategy(part: Part) -> Part: + for field in part.facts.all(sch_fact_types.field): + + k, v = re.split(":", field.value, 1) + if k == "mpn": + part.add_mpn(v) + + return part + + +def default(part: Part) -> Part: + functions = [ + fix_value_strategy, + mpn_strategy, + part_type_strategy, + ] + + for f in functions: + part = f(part) + + return part |