From e84f131720e5952ba0dc20de8729bfd1d7aa0fe7 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 31 Jan 2016 14:17:35 +0800 Subject: Add support for more excellon formats. Dont consider line width when determinging region bounding box --- gerber/excellon.py | 2 ++ gerber/excellon_statements.py | 14 ++++++++++++-- gerber/primitives.py | 2 +- 3 files changed, 15 insertions(+), 3 deletions(-) (limited to 'gerber') diff --git a/gerber/excellon.py b/gerber/excellon.py index 4317e41..4456329 100755 --- a/gerber/excellon.py +++ b/gerber/excellon.py @@ -461,6 +461,8 @@ class ExcellonParser(object): stmt = UnitStmt.from_excellon(line) self.units = stmt.units self.zeros = stmt.zeros + if stmt.format: + self.format = stmt.format self.statements.append(stmt) elif line[:3] == 'M71' or line [:3] == 'M72': diff --git a/gerber/excellon_statements.py b/gerber/excellon_statements.py index e10308a..d2ba233 100644 --- a/gerber/excellon_statements.py +++ b/gerber/excellon_statements.py @@ -601,14 +601,24 @@ class UnitStmt(ExcellonStatement): def from_excellon(cls, line, **kwargs): units = 'inch' if 'INCH' in line else 'metric' zeros = 'leading' if 'LZ' in line else 'trailing' - return cls(units, zeros, **kwargs) + if '0000.00' in line: + format = (4, 2) + elif '000.000' in line: + format = (3, 3) + elif '00.0000' in line: + format = (2, 4) + else: + format = None + return cls(units, zeros, format, **kwargs) - def __init__(self, units='inch', zeros='leading', **kwargs): + def __init__(self, units='inch', zeros='leading', format=None, **kwargs): super(UnitStmt, self).__init__(**kwargs) self.units = units.lower() self.zeros = zeros + self.format = format def to_excellon(self, settings=None): + # TODO This won't export the invalid format statement if it exists stmt = '%s,%s' % ('INCH' if self.units == 'inch' else 'METRIC', 'LZ' if self.zeros == 'leading' else 'TZ') diff --git a/gerber/primitives.py b/gerber/primitives.py index b0e17e9..81c5837 100644 --- a/gerber/primitives.py +++ b/gerber/primitives.py @@ -827,7 +827,7 @@ class Region(Primitive): @property def bounding_box(self): - xlims, ylims = zip(*[p.bounding_box for p in self.primitives]) + xlims, ylims = zip(*[p.bounding_box_no_aperture for p in self.primitives]) minx, maxx = zip(*xlims) miny, maxy = zip(*ylims) min_x = min(minx) -- cgit