From d3b19efb484941f9726b1ae805c8d39e767bbe15 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Wed, 20 May 2015 16:20:02 -0300 Subject: Add support for PCBmodE generated files. PCBmodE uses a standard but probably undefined behaviour issue on Gerber where it defines circle apertures with a single modifier but leaves a trilling 'X' after it. 'X' is modifiers separator but when there is only one modifier the behaviour is undefined. For parsing we are just ignoring blank modifiers. Test updated to catch this case. --- gerber/gerber_statements.py | 2 +- gerber/tests/test_gerber_statements.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'gerber') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index a198bb9..fd1e629 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -293,7 +293,7 @@ class ADParamStmt(ParamStmt): self.d = d self.shape = shape if modifiers: - self.modifiers = [tuple([float(x) for x in m.split("X")]) for m in modifiers.split(",") if len(m)] + self.modifiers = [tuple([float(x) for x in m.split("X") if len(x)]) for m in modifiers.split(",") if len(m)] else: self.modifiers = [tuple()] diff --git a/gerber/tests/test_gerber_statements.py b/gerber/tests/test_gerber_statements.py index f3249b1..b5c20b1 100644 --- a/gerber/tests/test_gerber_statements.py +++ b/gerber/tests/test_gerber_statements.py @@ -635,6 +635,24 @@ def test_ADParamStmt_factory(): assert_equal(ad.d, 1) assert_equal(ad.shape, 'R') + stmt = {'param': 'AD', 'd': 1, 'shape': 'C', "modifiers": "1.42"} + ad = ADParamStmt.from_dict(stmt) + assert_equal(ad.d, 1) + assert_equal(ad.shape, 'C') + assert_equal(ad.modifiers, [(1.42,)]) + + stmt = {'param': 'AD', 'd': 1, 'shape': 'C', "modifiers": "1.42X"} + ad = ADParamStmt.from_dict(stmt) + assert_equal(ad.d, 1) + assert_equal(ad.shape, 'C') + assert_equal(ad.modifiers, [(1.42,)]) + + stmt = {'param': 'AD', 'd': 1, 'shape': 'R', "modifiers": "1.42X1.24"} + ad = ADParamStmt.from_dict(stmt) + assert_equal(ad.d, 1) + assert_equal(ad.shape, 'R') + assert_equal(ad.modifiers, [(1.42, 1.24)]) + def test_ADParamStmt_conversion(): stmt = {'param': 'AD', 'd': 0, 'shape': 'C', 'modifiers': '25.4X25.4,25.4X25.4'} ad = ADParamStmt.from_dict(stmt) -- cgit