diff options
author | Paulo Henrique Silva <ph.silva@gmail.com> | 2015-03-18 03:38:52 -0300 |
---|---|---|
committer | Paulo Henrique Silva <ph.silva@gmail.com> | 2015-04-07 18:17:25 -0300 |
commit | b9b20a9644ca7b87493ca5786e2a25ecab132b75 (patch) | |
tree | bce7f467a120e86834872295305ba144ffd5ae8f | |
parent | 820d8aa9034fda56071f3ac2367b80eb0d1cb93a (diff) | |
download | gerbonara-b9b20a9644ca7b87493ca5786e2a25ecab132b75.tar.gz gerbonara-b9b20a9644ca7b87493ca5786e2a25ecab132b75.tar.bz2 gerbonara-b9b20a9644ca7b87493ca5786e2a25ecab132b75.zip |
Fix Excellon repeat command
-rwxr-xr-x | gerber/excellon.py | 6 | ||||
-rw-r--r-- | gerber/excellon_statements.py | 29 | ||||
-rw-r--r-- | gerber/tests/test_excellon_statements.py | 2 |
3 files changed, 23 insertions, 14 deletions
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<rcount>[0-9]*)X?(?P<xdelta>\d*\.?\d*)?Y?' - '(?P<ydelta>\d*\.?\d*)?').match(line) + match = re.compile(r'R(?P<rcount>[0-9]*)X?(?P<xdelta>[+\-]?\d*\.?\d*)?Y?' + '(?P<ydelta>[+\-]?\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 '<Repeat Hole: %d times>' % self.count + return '<Repeat Hole: %d times, offset X: %g Y: %g>' % ( + 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), '<Repeat Hole: 4 times>') + assert_equal(str(stmt), '<Repeat Hole: 4 times, offset X: 1.5 Y: 32>') def test_commentstmt_factory(): """ Test CommentStmt factory method |