diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2017-12-08 20:52:02 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2017-12-08 20:52:02 +0100 |
commit | 6cd194703674268b313918b590f2bc483c641efa (patch) | |
tree | 1b504f96497280e50f8e5bb6530d46ce570a2047 /src/ee/kicad | |
parent | efe5d835eaa26d8696c3352c4e1ed42da16fe27b (diff) | |
download | ee-python-6cd194703674268b313918b590f2bc483c641efa.tar.gz ee-python-6cd194703674268b313918b590f2bc483c641efa.tar.bz2 ee-python-6cd194703674268b313918b590f2bc483c641efa.tar.xz ee-python-6cd194703674268b313918b590f2bc483c641efa.zip |
o Parsing pads and stuff.
Diffstat (limited to 'src/ee/kicad')
-rw-r--r-- | src/ee/kicad/pcb/__init__.py | 60 |
1 files changed, 50 insertions, 10 deletions
diff --git a/src/ee/kicad/pcb/__init__.py b/src/ee/kicad/pcb/__init__.py index bfd352f..10350c3 100644 --- a/src/ee/kicad/pcb/__init__.py +++ b/src/ee/kicad/pcb/__init__.py @@ -25,6 +25,12 @@ class Module(object): for k, v in kwargs.items(): setattr(self, k, v) +@auto_str +class Pad(object): + def __init__(self, **kwargs): + for k, v in kwargs.items(): + setattr(self, k, v) + def parse(path): count = 0 p = sexpr.parse(path) @@ -71,7 +77,7 @@ def parse(path): return KicadPcb(**args) - def _parse_text(optional = False, rparen = False): + def _parse_text(optional = False, rparen = False, to = None): (event, token) = next(p) if not optional: assert event == sexpr.EVENT_TEXT @@ -83,7 +89,8 @@ def parse(path): if rparen: (event, token) = next(p) assert event == sexpr.EVENT_RPAREN - return text + + return to(text) if to else text def _parse_general(): args = {} @@ -92,9 +99,9 @@ def parse(path): while event == sexpr.EVENT_LPAREN: (event, token) = next(p) if token == "no_connects": - args[token] =_parse_text(rparen = True) + args[token] =_parse_text(to=int, rparen = True) elif token == "area": - args[token] = (_parse_text(), _parse_text(), _parse_text(), _parse_text(rparen = True)) + args[token] = (_parse_text(to=float), _parse_text(to=float), _parse_text(to=float), _parse_text(to=float, rparen = True)) elif token == "thickness": args[token] = _parse_text(rparen = True) else: @@ -103,25 +110,58 @@ def parse(path): return General(**args) def _parse_module(): - args = {} + pads = [] + args = {} args["footprint"] = _parse_text() + args["pads"] = pads (event, token) = next(p) + while event == sexpr.EVENT_TEXT: + (event, token) = next(p) + while event == sexpr.EVENT_LPAREN: (event, token) = next(p) if token == "layer": - args[token] = _parse_text(rparen = True) + args[token] = _parse_text(rparen = True) elif token == "at": - x = _parse_text() - y = _parse_text() - rot = _parse_text(optional = True, rparen = True) - args[token] = (x, y, rot or 0) + args[token] = _parse_at() + elif token == "pad": + pads.append(_parse_pad()) else: _consume() (event, token) = next(p) return Module(**args) + def _parse_pad(): + texts = [] + + args = {} + args["footprint"] = _parse_text() + + (event, token) = next(p) + while event == sexpr.EVENT_TEXT: + texts.append(token) + (event, token) = next(p) + + while event == sexpr.EVENT_LPAREN: + (event, token) = next(p) + if token == "at": + args[token] = _parse_at() + if token == "size": + args[token] = (_parse_text(to=float), _parse_text(to=float)) + else: + _consume() + + return Pad(**args) + + + def _parse_at(): + x = _parse_text(to=float) + y = _parse_text(to=float) + rot = _parse_text(to=float, optional = True, rparen = True) + return (x, y, rot or 0) + kicad_pcb = _parse_kicad_pcb() # (event, token) = next(p) # assert event == sexpr.EVENT_END |