summaryrefslogtreecommitdiff
path: root/gerberex/excellon.py
diff options
context:
space:
mode:
authoropiopan <opiopan@gmail.com>2019-03-21 22:00:32 +0900
committeropiopan <opiopan@gmail.com>2019-03-21 22:00:32 +0900
commit9febca7da6a730b3b3ca3a54129a9f88e5c44d14 (patch)
tree3f260096ab0c40eca527195630ab004208b4ee78 /gerberex/excellon.py
downloadgerbonara-9febca7da6a730b3b3ca3a54129a9f88e5c44d14.tar.gz
gerbonara-9febca7da6a730b3b3ca3a54129a9f88e5c44d14.tar.bz2
gerbonara-9febca7da6a730b3b3ca3a54129a9f88e5c44d14.zip
initial commit
Diffstat (limited to 'gerberex/excellon.py')
-rw-r--r--gerberex/excellon.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/gerberex/excellon.py b/gerberex/excellon.py
new file mode 100644
index 0000000..78e6e5f
--- /dev/null
+++ b/gerberex/excellon.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
+
+from gerber.excellon import (ExcellonParser, detect_excellon_format, ExcellonFile)
+from gerber.excellon_statements import UnitStmt
+from gerber.cam import FileSettings
+
+def loads(data, filename=None, settings=None, tools=None, format=None):
+ if not settings:
+ settings = FileSettings(**detect_excellon_format(data))
+ if format:
+ settings.format = format
+ file = ExcellonParser(settings, tools).parse_raw(data, filename)
+ return ExcellonFileEx.from_file(file)
+
+class ExcellonFileEx(ExcellonFile):
+ @classmethod
+ def from_file(cls, file):
+ statements = [
+ UnitStmtEx.from_statement(s) if isinstance(s, UnitStmt) else s \
+ for s in file.statements
+ ]
+ return cls(statements, file.tools, file.hits, file.settings, file.filename)
+
+ def __init__(self, statements, tools, hits, settings, filename=None):
+ super(ExcellonFileEx, self).__init__(statements, tools, hits, settings, filename)
+
+class UnitStmtEx(UnitStmt):
+ @classmethod
+ def from_statement(cls, stmt):
+ return cls(units=stmt.units, zeros=stmt.zeros, format=stmt.format, id=stmt.id)
+
+ def __init__(self, units='inch', zeros='leading', format=None, **kwargs):
+ super(UnitStmtEx, self).__init__(units, zeros, format, **kwargs)
+
+ def to_excellon(self, settings=None):
+ stmt = '%s,%s,%s.%s' % ('INCH' if self.units == 'inch' else 'METRIC',
+ 'LZ' if self.zeros == 'leading' else 'TZ',
+ '0' * self.format[0], '0' * self.format[1])
+ return stmt