diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-12-12 12:02:29 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-12-15 07:30:35 +0100 |
commit | 102614dc8fe2f5aefd0fd92c1b6e48107a9629b0 (patch) | |
tree | 341436f8afc4a29819e59b199eb629a80ffd2df0 /src/ee/kicad/pcb | |
parent | 6cd194703674268b313918b590f2bc483c641efa (diff) | |
download | ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.gz ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.bz2 ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.tar.xz ee-python-102614dc8fe2f5aefd0fd92c1b6e48107a9629b0.zip |
o Adding a kicad-make-pos tool.
Diffstat (limited to 'src/ee/kicad/pcb')
-rw-r--r-- | src/ee/kicad/pcb/__init__.py | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/src/ee/kicad/pcb/__init__.py b/src/ee/kicad/pcb/__init__.py index 10350c3..679c5ea 100644 --- a/src/ee/kicad/pcb/__init__.py +++ b/src/ee/kicad/pcb/__init__.py @@ -1,4 +1,5 @@ from .. import sexpr +from ..._utils import run_filters def auto_str(cls): def __str__(self): @@ -25,16 +26,32 @@ class Module(object): for k, v in kwargs.items(): setattr(self, k, v) + self.fp_texts = self.fp_texts or [] + + def filter_fp_text(self, kind = None): + filters = [] + + if kind: + filters.append(lambda fp_text: fp_text.kind == kind) + + return (fp_text for fp_text in self.fp_texts if run_filters(filters, fp_text)) + @auto_str class Pad(object): def __init__(self, **kwargs): for k, v in kwargs.items(): setattr(self, k, v) +@auto_str +class FpText(object): + def __init__(self, **kwargs): + for k, v in kwargs.items(): + setattr(self, k, v) + def parse(path): count = 0 p = sexpr.parse(path) - p = sexpr.logging_parser(p) + #p = sexpr.logging_parser(p) (event, token) = next(p) assert event == sexpr.EVENT_LPAREN @@ -111,10 +128,12 @@ def parse(path): def _parse_module(): pads = [] + fp_texts = [] args = {} args["footprint"] = _parse_text() args["pads"] = pads + args["fp_texts"] = fp_texts (event, token) = next(p) while event == sexpr.EVENT_TEXT: @@ -128,6 +147,8 @@ def parse(path): args[token] = _parse_at() elif token == "pad": pads.append(_parse_pad()) + elif token == "fp_text": + fp_texts.append(_parse_fp_text()) else: _consume() (event, token) = next(p) @@ -155,6 +176,21 @@ def parse(path): return Pad(**args) + def _parse_fp_text(): + args = { + "kind": _parse_text(), + "value": _parse_text(), + } + (event, token) = next(p) + while event == sexpr.EVENT_LPAREN: + (event, token) = next(p) + if token == "at": + args[token] = _parse_at() + if token == "layer": + args[token] = _parse_text() + else: + _consume() + return FpText(**args) def _parse_at(): x = _parse_text(to=float) @@ -163,6 +199,5 @@ def parse(path): return (x, y, rot or 0) kicad_pcb = _parse_kicad_pcb() -# (event, token) = next(p) -# assert event == sexpr.EVENT_END + assert next(p, None) == None return kicad_pcb |