From e3c59e39cf9bc64ce9d76c324b82956a65515f16 Mon Sep 17 00:00:00 2001 From: opiopan Date: Sun, 7 Apr 2019 22:22:33 +0900 Subject: expand test and fix many issues --- gerberex/excellon.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'gerberex/excellon.py') diff --git a/gerberex/excellon.py b/gerberex/excellon.py index 90d6742..b72b95b 100644 --- a/gerberex/excellon.py +++ b/gerberex/excellon.py @@ -6,6 +6,7 @@ from gerber.excellon import (ExcellonParser, detect_excellon_format, ExcellonFile) from gerber.excellon_statements import UnitStmt from gerber.cam import FileSettings +from gerber.utils import inch, metric from gerberex.utility import rotate def loads(data, filename=None, settings=None, tools=None, format=None): @@ -33,6 +34,19 @@ class ExcellonFileEx(ExcellonFile): return for hit in self.hits: hit.position = rotate(hit.position[0], hit.position[1], angle, center) + + def to_inch(self): + if self.units == 'metric': + super(ExcellonFileEx, self).to_inch() + for hit in self.hits: + hit.position = (inch(hit.position[0]), inch(hit.position[1])) + + def to_metric(self): + if self.units == 'inch': + super(ExcellonFileEx, self).to_metric() + for hit in self.hits: + hit.position = (metric(hit.position[0]), metric(hit.position[1])) + class UnitStmtEx(UnitStmt): @classmethod @@ -43,7 +57,8 @@ class UnitStmtEx(UnitStmt): super(UnitStmtEx, self).__init__(units, zeros, format, **kwargs) def to_excellon(self, settings=None): + format = settings.format if settings else self.format 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]) + '0' * format[0], '0' * format[1]) return stmt -- cgit