From b9b20a9644ca7b87493ca5786e2a25ecab132b75 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Wed, 18 Mar 2015 03:38:52 -0300 Subject: Fix Excellon repeat command --- gerber/excellon.py | 6 ++++-- gerber/excellon_statements.py | 29 ++++++++++++++++++----------- gerber/tests/test_excellon_statements.py | 2 +- 3 files changed, 23 insertions(+), 14 deletions(-) (limited to 'gerber') diff --git a/gerber/excellon.py b/gerber/excellon.py index 900e2df..930b683 100755 --- a/gerber/excellon.py +++ b/gerber/excellon.py @@ -54,6 +54,8 @@ class ExcellonFile(CamFile): The ExcellonFile class represents a single excellon file. + http://www.excellon.com/manuals/program.htm + Parameters ---------- tools : list @@ -305,8 +307,8 @@ class ExcellonParser(object): stmt = RepeatHoleStmt.from_excellon(line, self._settings()) self.statements.append(stmt) for i in range(stmt.count): - self.pos[0] += stmt.xdelta - self.pos[1] += stmt.ydelta + self.pos[0] += stmt.xdelta if stmt.xdelta is not None else 0 + self.pos[1] += stmt.ydelta if stmt.ydelta is not None else 0 self.hits.append((self.active_tool, tuple(self.pos))) self.active_tool._hit() diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py index 83a96a0..53ea951 100644 --- a/gerber/excellon_statements.py +++ b/gerber/excellon_statements.py @@ -317,16 +317,16 @@ class RepeatHoleStmt(ExcellonStatement): @classmethod def from_excellon(cls, line, settings): - match = re.compile(r'R(?P[0-9]*)X?(?P\d*\.?\d*)?Y?' - '(?P\d*\.?\d*)?').match(line) + match = re.compile(r'R(?P[0-9]*)X?(?P[+\-]?\d*\.?\d*)?Y?' + '(?P[+\-]?\d*\.?\d*)?').match(line) stmt = match.groupdict() count = int(stmt['rcount']) xdelta = (parse_gerber_value(stmt['xdelta'], settings.format, settings.zero_suppression) - if stmt['xdelta'] is not '' else None) + if stmt['xdelta'] is not '' else None) ydelta = (parse_gerber_value(stmt['ydelta'], settings.format, settings.zero_suppression) - if stmt['ydelta'] is not '' else None) + if stmt['ydelta'] is not '' else None) return cls(count, xdelta, ydelta) def __init__(self, count, xdelta=0.0, ydelta=0.0): @@ -336,24 +336,31 @@ class RepeatHoleStmt(ExcellonStatement): def to_excellon(self, settings): stmt = 'R%d' % self.count - if self.xdelta != 0.0: + if self.xdelta is not None and self.xdelta != 0.0: stmt += 'X%s' % write_gerber_value(self.xdelta, settings.format, settings.zero_suppression) - if self.ydelta != 0.0: + if self.ydelta is not None and self.ydelta != 0.0: stmt += 'Y%s' % write_gerber_value(self.ydelta, settings.format, settings.zero_suppression) return stmt def to_inch(self): - self.xdelta = inch(self.xdelta) - self.ydelta = inch(self.ydelta) + if self.xdelta is not None: + self.xdelta = inch(self.xdelta) + if self.ydelta is not None: + self.ydelta = inch(self.ydelta) def to_metric(self): - self.xdelta = metric(self.xdelta) - self.ydelta = metric(self.ydelta) + if self.xdelta is not None: + self.xdelta = metric(self.xdelta) + if self.ydelta is not None: + self.ydelta = metric(self.ydelta) def __str__(self): - return '' % self.count + return '' % ( + self.count, + self.xdelta if self.xdelta is not None else 0, + self.ydelta if self.ydelta is not None else 0) class CommentStmt(ExcellonStatement): diff --git a/gerber/tests/test_excellon_statements.py b/gerber/tests/test_excellon_statements.py index eb30db1..2da7c15 100644 --- a/gerber/tests/test_excellon_statements.py +++ b/gerber/tests/test_excellon_statements.py @@ -216,7 +216,7 @@ def test_repeatholestmt_conversion(): def test_repeathole_str(): stmt = RepeatHoleStmt.from_excellon('R4X015Y32', FileSettings()) - assert_equal(str(stmt), '') + assert_equal(str(stmt), '') def test_commentstmt_factory(): """ Test CommentStmt factory method -- cgit