aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--src/ee/kicad/pcb/__init__.py60
-rw-r--r--test/kicad_pcb/parser-1.kicad_pcb20
-rw-r--r--test/test_parse_pcb.py9
4 files changed, 69 insertions, 21 deletions
diff --git a/.gitignore b/.gitignore
index 328f659..ea22c76 100644
--- a/.gitignore
+++ b/.gitignore
@@ -23,3 +23,4 @@ demo/*/*.log
*.bak
_saved_*.sch
*.kicad_pcb-bak
+_autosave-*.kicad_pcb
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
diff --git a/test/kicad_pcb/parser-1.kicad_pcb b/test/kicad_pcb/parser-1.kicad_pcb
index 9aa6ab4..99f5d33 100644
--- a/test/kicad_pcb/parser-1.kicad_pcb
+++ b/test/kicad_pcb/parser-1.kicad_pcb
@@ -2,8 +2,8 @@
(general
(links 5)
- (no_connects 1)
- (area 139.649999 101.549999 152.450001 109.270001)
+ (no_connects 0)
+ (area 137.492381 96.36 152.55 110.085)
(thickness 1.6)
(drawings 5)
(tracks 14)
@@ -58,8 +58,8 @@
(mod_edge_width 0.15)
(mod_text_size 1 1)
(mod_text_width 0.15)
- (pad_size 1.524 1.524)
- (pad_drill 0.762)
+ (pad_size 0.8 0.75)
+ (pad_drill 0)
(pad_to_mask_clearance 0.2)
(aux_axis_origin 0 0)
(visible_elements FFFFFF7F)
@@ -107,16 +107,16 @@
(add_net "Net-(J1-Pad2)")
)
- (module Capacitors_SMD:C_0603 (layer F.Cu) (tedit 59958EE7) (tstamp 5A29152D)
- (at 149.86 106.68 180)
+ (module Capacitors_SMD:C_0603 (layer F.Cu) (tedit 5A2A3416) (tstamp 5A29152D)
+ (at 149.86 106.68 180.1)
(descr "Capacitor SMD 0603, reflow soldering, AVX (see smccp.pdf)")
(tags "capacitor 0603")
(path /5A2915AE)
(attr smd)
- (fp_text reference C1 (at 0 -1.5 180) (layer F.SilkS)
+ (fp_text reference C1 (at 0 -1.5 180.1) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
- (fp_text value C (at 0 1.5 180) (layer F.Fab)
+ (fp_text value C (at 0 1.5 180.1) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_line (start 1.4 0.65) (end -1.4 0.65) (layer F.CrtYd) (width 0.05))
@@ -129,10 +129,10 @@
(fp_line (start 0.8 -0.4) (end 0.8 0.4) (layer F.Fab) (width 0.1))
(fp_line (start 0.8 0.4) (end -0.8 0.4) (layer F.Fab) (width 0.1))
(fp_line (start -0.8 0.4) (end -0.8 -0.4) (layer F.Fab) (width 0.1))
- (fp_text user %R (at 0 0 180) (layer F.Fab)
+ (fp_text user %R (at 0 0 180.1) (layer F.Fab)
(effects (font (size 0.3 0.3) (thickness 0.075)))
)
- (pad 2 smd rect (at 0.75 0 180) (size 0.8 0.75) (layers F.Cu F.Paste F.Mask)
+ (pad 2 smd rect (at 0.75 0 180.1) (size 0.8 0.75) (layers F.Cu F.Paste F.Mask)
(net 3 GND))
(pad 1 smd rect (at -0.75 0 180) (size 0.8 0.75) (layers F.Cu F.Paste F.Mask)
(net 1 "Net-(C1-Pad1)"))
diff --git a/test/test_parse_pcb.py b/test/test_parse_pcb.py
index 9592b92..3199a78 100644
--- a/test/test_parse_pcb.py
+++ b/test/test_parse_pcb.py
@@ -12,4 +12,11 @@ def test_parsing():
del kicad_pcb.modules
print(str(kicad_pcb))
for m in modules:
- print(m)
+ pads = m.pads
+ del m.pads
+ print(" {}".format(m))
+ for p in pads:
+ print(" {}".format(p))
+
+ assert len(modules) == 4
+ assert len(pads) == 2