summaryrefslogtreecommitdiff
path: root/gerber/excellon.py
diff options
context:
space:
mode:
authorHamilton Kibbe <ham@hamiltonkib.be>2014-10-06 18:28:32 -0400
committerHamilton Kibbe <ham@hamiltonkib.be>2014-10-06 18:28:32 -0400
commit22a6f87e94c1192b277a1353aefc7c0316f41f90 (patch)
treed44170d9bae5cb116427dbb16fef326383985dcc /gerber/excellon.py
parent08253b40f6f677c4edaeb7108177846d8f0d8703 (diff)
downloadgerbonara-22a6f87e94c1192b277a1353aefc7c0316f41f90.tar.gz
gerbonara-22a6f87e94c1192b277a1353aefc7c0316f41f90.tar.bz2
gerbonara-22a6f87e94c1192b277a1353aefc7c0316f41f90.zip
add excellon file write
Diffstat (limited to 'gerber/excellon.py')
-rwxr-xr-xgerber/excellon.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/gerber/excellon.py b/gerber/excellon.py
index 45a8e4b..072bc31 100755
--- a/gerber/excellon.py
+++ b/gerber/excellon.py
@@ -74,6 +74,11 @@ class ExcellonFile(CncFile):
ctx.drill(pos[0], pos[1], tool.diameter)
ctx.dump(filename)
+ def write(self, filename):
+ with open(filename, 'w') as f:
+ for statement in self.statements:
+ f.write(statement.to_excellon() + '\n')
+
class ExcellonParser(object):
""" Excellon File Parser
@@ -155,9 +160,9 @@ class ExcellonParser(object):
elif line[0] == 'T' and self.state != 'HEADER':
stmt = ToolSelectionStmt.from_excellon(line)
- self.active_tool self.tools[stmt.tool]
+ self.active_tool = self.tools[stmt.tool]
#self.active_tool = self.tools[int(line.strip().split('T')[1])]
- self.statements.append(statement)
+ self.statements.append(stmt)
elif line[0] in ['X', 'Y']:
stmt = CoordinateStmt.from_excellon(line, fmt, zs)
@@ -197,18 +202,8 @@ class ExcellonParser(object):
return FileSettings(units=self.units, format=self.format,
zero_suppression=self.zero_suppression,
notation=self.notation)
-
-
-def pairwise(iterator):
- """ Iterate over list taking two elements at a time.
-
- e.g. [1, 2, 3, 4, 5, 6] ==> [(1, 2), (3, 4), (5, 6)]
- """
- itr = iter(iterator)
- while True:
- yield tuple([itr.next() for i in range(2)])
if __name__ == '__main__':
- p = parser()
- p.parse('examples/ncdrill.txt')
+ p = ExcellonParser()
+ parsed = p.parse('examples/ncdrill.txt')