aboutsummaryrefslogtreecommitdiff
path: root/src/ee/kicad
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2019-05-14 21:29:04 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2019-05-14 21:29:04 +0200
commitb9da2d88e21e5edda04e928352b45d203147be26 (patch)
tree2b62b862abe546d87e016a45e2df74d3ea7ba7a4 /src/ee/kicad
parentee62dd01720c8481599a717d067014164af7e096 (diff)
downloadee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.gz
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.bz2
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.tar.xz
ee-python-b9da2d88e21e5edda04e928352b45d203147be26.zip
ee.xsd:
o Removing distributor info, wasn't useful. o Removing part type, using a fact instead. part-search-list: o Putting in some smart rules about values for parts. Might be too smart for its own good. o Removing duplication checking, that is up to the searcher to decide.
Diffstat (limited to 'src/ee/kicad')
-rw-r--r--src/ee/kicad/make_bom.py65
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),