From 4a815bf25ddd1d378ec6ad5af008e5bbcd362b51 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Wed, 30 Dec 2015 14:05:00 +0800 Subject: First time any macro renders --- gerber/gerber_statements.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index fd1e629..14a431b 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -26,6 +26,7 @@ from .utils import (parse_gerber_value, write_gerber_value, decimal_string, from .am_statements import * from .am_read import read_macro from .am_eval import eval_macro +from .primitives import AMGroup class Statement(object): @@ -388,6 +389,8 @@ class AMParamStmt(ParamStmt): self.primitives.append(AMThermalPrimitive.from_gerber(primitive)) else: self.primitives.append(AMUnsupportPrimitive.from_gerber(primitive)) + + return AMGroup(self.primitives, units=self.units) def to_inch(self): if self.units == 'metric': -- cgit From 29c0d82bf53907030d11df9eb09471b716a0be2e Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 27 Feb 2016 15:24:36 +0800 Subject: RS274X backend for rendering. Incompelte still --- gerber/gerber_statements.py | 65 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 63 insertions(+), 2 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 14a431b..bb190f4 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -226,6 +226,11 @@ class LPParamStmt(ParamStmt): param = stmt_dict['param'] lp = 'clear' if stmt_dict.get('lp') == 'C' else 'dark' return cls(param, lp) + + @classmethod + def from_region(cls, region): + #todo what is the first param? + return cls(None, region.level_polarity) def __init__(self, param, lp): """ Initialize LPParamStmt class @@ -258,7 +263,21 @@ class LPParamStmt(ParamStmt): class ADParamStmt(ParamStmt): """ AD - Gerber Aperture Definition Statement """ - + + @classmethod + def rect(cls, dcode, width, height): + '''Create a rectangular aperture definition statement''' + return cls('AD', dcode, 'R', ([width, height],)) + + @classmethod + def circle(cls, dcode, diameter): + '''Create a circular aperture definition statement''' + return cls('AD', dcode, 'C', ([diameter],)) + + @classmethod + def macro(cls, dcode, name): + return cls('AD', dcode, name, '') + @classmethod def from_dict(cls, stmt_dict): param = stmt_dict.get('param') @@ -293,7 +312,9 @@ class ADParamStmt(ParamStmt): ParamStmt.__init__(self, param) self.d = d self.shape = shape - if modifiers: + if isinstance(modifiers, tuple): + self.modifiers = modifiers + elif modifiers: self.modifiers = [tuple([float(x) for x in m.split("X") if len(x)]) for m in modifiers.split(",") if len(m)] else: self.modifiers = [tuple()] @@ -817,6 +838,14 @@ class CoordStmt(Statement): """ Coordinate Data Block """ + OP_DRAW = 'D01' + OP_MOVE = 'D02' + OP_FLASH = 'D03' + + FUNC_LINEAR = 'G01' + FUNC_ARC_CW = 'G02' + FUNC_ARC_CCW = 'G03' + @classmethod def from_dict(cls, stmt_dict, settings): function = stmt_dict['function'] @@ -835,6 +864,22 @@ class CoordStmt(Statement): if j is not None: j = parse_gerber_value(stmt_dict.get('j'), settings.format, settings.zero_suppression) return cls(function, x, y, i, j, op, settings) + + @classmethod + def move(cls, func, point): + return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None) + + @classmethod + def line(cls, func, point): + return cls(func, point[0], point[1], None, None, CoordStmt.OP_DRAW, None) + + @classmethod + def arc(cls, func, point, center): + return cls(func, point[0], point[1], center[0], center[1], CoordStmt.OP_DRAW, None) + + @classmethod + def flash(cls, point): + return cls(None, point[0], point[1], None, None, CoordStmt.OP_FLASH, None) def __init__(self, function, x, y, i, j, op, settings): """ Initialize CoordStmt class @@ -1003,6 +1048,14 @@ class EofStmt(Statement): class QuadrantModeStmt(Statement): + + @classmethod + def single(cls): + return cls('single-quadrant') + + @classmethod + def multi(cls): + return cls('multi-quadrant') @classmethod def from_gerber(cls, line): @@ -1031,6 +1084,14 @@ class RegionModeStmt(Statement): if 'G36' not in line and 'G37' not in line: raise ValueError('%s is not a valid region mode statement' % line) return (cls('on') if line[:3] == 'G36' else cls('off')) + + @classmethod + def on(cls): + return cls('on') + + @classmethod + def off(cls): + return cls('off') def __init__(self, mode): super(RegionModeStmt, self).__init__('RegionMode') -- cgit From 223a010831f0d9dae4bd6d2e626a603a78eb0b1d Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 27 Feb 2016 18:18:04 +0800 Subject: Fix critical issue with rotatin points (when the angle is zero the y would be flipped). Render AM with outline to gerber --- gerber/gerber_statements.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index bb190f4..dcdd90d 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -168,6 +168,10 @@ class FSParamStmt(ParamStmt): class MOParamStmt(ParamStmt): """ MO - Gerber Mode (measurement units) Statement. """ + + @classmethod + def from_units(cls, units): + return cls(None, 'inch') @classmethod def from_dict(cls, stmt_dict): -- cgit From 20a9af279ac2217a39b73903ff94b916a3025be2 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Tue, 1 Mar 2016 00:06:14 +0800 Subject: More rendering of AMGroup to statements --- gerber/gerber_statements.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index dcdd90d..aa25d0a 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -93,6 +93,11 @@ class ParamStmt(Statement): class FSParamStmt(ParamStmt): """ FS - Gerber Format Specification Statement """ + + @classmethod + def from_settings(cls, settings): + + return cls('FS', settings.zero_suppression, settings.notation, settings.format) @classmethod def from_dict(cls, stmt_dict): @@ -278,6 +283,11 @@ class ADParamStmt(ParamStmt): '''Create a circular aperture definition statement''' return cls('AD', dcode, 'C', ([diameter],)) + @classmethod + def obround(cls, dcode, width, height): + '''Create an obrou d aperture definition statement''' + return cls('AD', dcode, 'O', ([width, height],)) + @classmethod def macro(cls, dcode, name): return cls('AD', dcode, name, '') -- cgit From 74c638c7181e7a8ca4d0f791545bbf5db8b86c2a Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Thu, 19 May 2016 23:19:28 +0800 Subject: Fix issue where did not always switch into the G01 mode after G03 when the point was unchanged --- gerber/gerber_statements.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index aa25d0a..119df9d 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -887,6 +887,10 @@ class CoordStmt(Statement): def line(cls, func, point): return cls(func, point[0], point[1], None, None, CoordStmt.OP_DRAW, None) + @classmethod + def mode(cls, func): + return cls(func, None, None, None, None, None, None) + @classmethod def arc(cls, func, point, center): return cls(func, point[0], point[1], center[0], center[1], CoordStmt.OP_DRAW, None) -- cgit From c9c1313d598d5afa8cb387a2cfcd4a4281086e01 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 28 May 2016 12:36:31 +0800 Subject: Fix units statement. Keep track of original macro statement in the AMGroup --- gerber/gerber_statements.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 119df9d..b171a7f 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -176,7 +176,7 @@ class MOParamStmt(ParamStmt): @classmethod def from_units(cls, units): - return cls(None, 'inch') + return cls(None, units) @classmethod def from_dict(cls, stmt_dict): @@ -425,7 +425,7 @@ class AMParamStmt(ParamStmt): else: self.primitives.append(AMUnsupportPrimitive.from_gerber(primitive)) - return AMGroup(self.primitives, units=self.units) + return AMGroup(self.primitives, stmt=self, units=self.units) def to_inch(self): if self.units == 'metric': -- cgit From 49dadd46ee62a863b75087e9ed8f0590183bd525 Mon Sep 17 00:00:00 2001 From: Paulo Henrique Silva Date: Mon, 23 Nov 2015 16:02:16 -0200 Subject: Fix AMParamStmt to_gerber to write changes back. AMParamStmt was not calling to_gerber on each of its primitives on his own to_gerber method. That way primitives that changes after reading, such as when you call to_inch/to_metric was failing because it was writing only the original macro back. --- gerber/gerber_statements.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index b171a7f..725febf 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -440,7 +440,7 @@ class AMParamStmt(ParamStmt): primitive.to_metric() def to_gerber(self, settings=None): - return '%AM{0}*{1}*%'.format(self.name, self.macro) + return '%AM{0}*{1}%'.format(self.name, "".join([primitive.to_gerber() for primitive in self.primitives])) def __str__(self): return '' % (self.name, self.macro) -- cgit From ccb6eb7a766bd6edf314978f3ec4fc0dcd61652d Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sat, 25 Jun 2016 16:46:44 +0800 Subject: Add support for polygon apertures --- gerber/gerber_statements.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 725febf..234952e 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -285,9 +285,14 @@ class ADParamStmt(ParamStmt): @classmethod def obround(cls, dcode, width, height): - '''Create an obrou d aperture definition statement''' + '''Create an obround aperture definition statement''' return cls('AD', dcode, 'O', ([width, height],)) + @classmethod + def polygon(cls, dcode, diameter, num_vertices, rotation, hole_diameter): + '''Create a polygon aperture definition statement''' + return cls('AD', dcode, 'P', ([diameter, num_vertices, rotation, hole_diameter],)) + @classmethod def macro(cls, dcode, name): return cls('AD', dcode, name, '') -- cgit From b140f5e4767912110f69cbda8417a8e076345b70 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Tue, 28 Jun 2016 23:15:20 +0800 Subject: Don't flash G03-only commands --- gerber/gerber_statements.py | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 234952e..881e5bc 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -1022,6 +1022,16 @@ class CoordStmt(Statement): coord_str += 'Op: %s' % op return '' % coord_str + + @property + def only_function(self): + """ + Returns if the statement only set the function. + """ + + # TODO I would like to refactor this so that the function is handled separately and then + # TODO this isn't required + return self.function != None and self.op == None and self.x == None and self.y == None and self.i == None and self.j == None class ApertureStmt(Statement): -- cgit From 9b0d3b1122ffc3b7c2211b0cdc2cb6de6be9b242 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 10 Jul 2016 15:07:17 +0800 Subject: Fix issue with chaning region mode via flash. Add options for controlling output from rendered gerber --- gerber/gerber_statements.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 881e5bc..52e7ac3 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -886,7 +886,10 @@ class CoordStmt(Statement): @classmethod def move(cls, func, point): - return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None) + if point: + return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None) + # No point specified, so just write the function. This is normally for ending a region (D02*) + return cls(func, None, None, None, None, CoordStmt.OP_MOVE, None) @classmethod def line(cls, func, point): @@ -902,7 +905,10 @@ class CoordStmt(Statement): @classmethod def flash(cls, point): - return cls(None, point[0], point[1], None, None, CoordStmt.OP_FLASH, None) + if point: + return cls(None, point[0], point[1], None, None, CoordStmt.OP_FLASH, None) + else: + return cls(None, None, None, None, None, CoordStmt.OP_FLASH, None) def __init__(self, function, x, y, i, j, op, settings): """ Initialize CoordStmt class -- cgit From 7cd6acf12670f3773113f67ed2acb35cb21c32a0 Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 24 Jul 2016 17:08:47 +0800 Subject: Add many render tests based on the Umaco gerger specification. Fix multiple rendering bugs, especially related to holes in flashed apertures --- gerber/gerber_statements.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 52e7ac3..3212c1c 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -279,9 +279,9 @@ class ADParamStmt(ParamStmt): return cls('AD', dcode, 'R', ([width, height],)) @classmethod - def circle(cls, dcode, diameter): + def circle(cls, dcode, diameter, hole_diameter): '''Create a circular aperture definition statement''' - return cls('AD', dcode, 'C', ([diameter],)) + return cls('AD', dcode, 'C', ([diameter, hole_diameter],)) @classmethod def obround(cls, dcode, width, height): -- cgit From 965d3ce23b92f8aff1063debd6d3364de15791fe Mon Sep 17 00:00:00 2001 From: Garret Fick Date: Sun, 24 Jul 2016 22:08:31 +0800 Subject: Add more tests for rendering to PNG. Start adding tests for rendering to Gerber format. Changed definition of no hole to use None instead of 0 so we can differentiate when writing to Gerber format. Makde polygon use hole diameter instead of hole radius to match other primitives --- gerber/gerber_statements.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 3212c1c..fba2a3c 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -281,7 +281,10 @@ class ADParamStmt(ParamStmt): @classmethod def circle(cls, dcode, diameter, hole_diameter): '''Create a circular aperture definition statement''' - return cls('AD', dcode, 'C', ([diameter, hole_diameter],)) + + if hole_diameter != None: + return cls('AD', dcode, 'C', ([diameter, hole_diameter],)) + return cls('AD', dcode, 'C', ([diameter],)) @classmethod def obround(cls, dcode, width, height): -- cgit From 8cd842a41a55ab3d8f558a2e3e198beba7da58a1 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Manually mere rendering changes --- gerber/gerber_statements.py | 47 +++++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 17 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index fba2a3c..08dbd82 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -44,6 +44,7 @@ class Statement(object): type : string String identifying the statement type. """ + def __init__(self, stype, units='inch'): self.type = stype self.units = units @@ -85,6 +86,7 @@ class ParamStmt(Statement): param : string Parameter type code """ + def __init__(self, param): Statement.__init__(self, "PARAM") self.param = param @@ -163,8 +165,6 @@ class FSParamStmt(ParamStmt): return '%FS{0}{1}X{2}Y{3}*%'.format(zero_suppression, notation, fmt, fmt) - - def __str__(self): return ('' % (self.format[0], self.format[1], self.zero_suppression, self.notation)) @@ -343,13 +343,15 @@ class ADParamStmt(ParamStmt): def to_inch(self): if self.units == 'metric': - self.units = 'inch' - self.modifiers = [tuple([inch(x) for x in modifier]) for modifier in self.modifiers] + self.units = 'inch' + self.modifiers = [tuple([inch(x) for x in modifier]) + for modifier in self.modifiers] def to_metric(self): if self.units == 'inch': - self.units = 'metric' - self.modifiers = [tuple([metric(x) for x in modifier]) for modifier in self.modifiers] + self.units = 'metric' + self.modifiers = [tuple([metric(x) for x in modifier]) + for modifier in self.modifiers] def to_gerber(self, settings=None): if any(self.modifiers): @@ -426,10 +428,11 @@ class AMParamStmt(ParamStmt): self.primitives.append(AMOutlinePrimitive.from_gerber(primitive)) elif primitive[0] == '5': self.primitives.append(AMPolygonPrimitive.from_gerber(primitive)) - elif primitive[0] =='6': + elif primitive[0] == '6': self.primitives.append(AMMoirePrimitive.from_gerber(primitive)) elif primitive[0] == '7': - self.primitives.append(AMThermalPrimitive.from_gerber(primitive)) + self.primitives.append( + AMThermalPrimitive.from_gerber(primitive)) else: self.primitives.append(AMUnsupportPrimitive.from_gerber(primitive)) @@ -878,13 +881,17 @@ class CoordStmt(Statement): op = stmt_dict.get('op') if x is not None: - x = parse_gerber_value(stmt_dict.get('x'), settings.format, settings.zero_suppression) + x = parse_gerber_value(stmt_dict.get('x'), settings.format, + settings.zero_suppression) if y is not None: - y = parse_gerber_value(stmt_dict.get('y'), settings.format, settings.zero_suppression) + y = parse_gerber_value(stmt_dict.get('y'), settings.format, + settings.zero_suppression) if i is not None: - i = parse_gerber_value(stmt_dict.get('i'), settings.format, settings.zero_suppression) + i = parse_gerber_value(stmt_dict.get('i'), settings.format, + settings.zero_suppression) if j is not None: - j = parse_gerber_value(stmt_dict.get('j'), settings.format, settings.zero_suppression) + j = parse_gerber_value(stmt_dict.get('j'), settings.format, + settings.zero_suppression) return cls(function, x, y, i, j, op, settings) @classmethod @@ -958,13 +965,17 @@ class CoordStmt(Statement): if self.function: ret += self.function if self.x is not None: - ret += 'X{0}'.format(write_gerber_value(self.x, settings.format, settings.zero_suppression)) + ret += 'X{0}'.format(write_gerber_value(self.x, settings.format, + settings.zero_suppression)) if self.y is not None: - ret += 'Y{0}'.format(write_gerber_value(self.y, settings.format, settings.zero_suppression)) + ret += 'Y{0}'.format(write_gerber_value(self.y, settings.format, + settings.zero_suppression)) if self.i is not None: - ret += 'I{0}'.format(write_gerber_value(self.i, settings.format, settings.zero_suppression)) + ret += 'I{0}'.format(write_gerber_value(self.i, settings.format, + settings.zero_suppression)) if self.j is not None: - ret += 'J{0}'.format(write_gerber_value(self.j, settings.format, settings.zero_suppression)) + ret += 'J{0}'.format(write_gerber_value(self.j, settings.format, + settings.zero_suppression)) if self.op: ret += self.op return ret + '*' @@ -1046,6 +1057,7 @@ class CoordStmt(Statement): class ApertureStmt(Statement): """ Aperture Statement """ + def __init__(self, d, deprecated=None): Statement.__init__(self, "APERTURE") self.d = int(d) @@ -1079,6 +1091,7 @@ class CommentStmt(Statement): class EofStmt(Statement): """ EOF Statement """ + def __init__(self): Statement.__init__(self, "EOF") @@ -1149,6 +1162,7 @@ class RegionModeStmt(Statement): class UnknownStmt(Statement): """ Unknown Statement """ + def __init__(self, line): Statement.__init__(self, "UNKNOWN") self.line = line @@ -1158,4 +1172,3 @@ class UnknownStmt(Statement): def __str__(self): return '' % self.line - -- cgit From 5af19af190c1fb0f0c5be029d46d63e657dde4d9 Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Thu, 21 Jan 2016 03:57:44 -0500 Subject: Commit partial merge so I can work on the plane --- gerber/gerber_statements.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 08dbd82..33fb4ec 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -337,7 +337,8 @@ class ADParamStmt(ParamStmt): if isinstance(modifiers, tuple): self.modifiers = modifiers elif modifiers: - self.modifiers = [tuple([float(x) for x in m.split("X") if len(x)]) for m in modifiers.split(",") if len(m)] + self.modifiers = [tuple([float(x) for x in m.split("X") if len(x)]) + for m in modifiers.split(",") if len(m)] else: self.modifiers = [tuple()] -- cgit From 724c2b3bced319ed0b50c4302fed9b0e1aa9ce9c Mon Sep 17 00:00:00 2001 From: Hamilton Kibbe Date: Sat, 5 Nov 2016 20:56:47 -0400 Subject: Finish Merge, most tests passing --- gerber/gerber_statements.py | 52 ++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) (limited to 'gerber/gerber_statements.py') diff --git a/gerber/gerber_statements.py b/gerber/gerber_statements.py index 33fb4ec..9fc6fca 100644 --- a/gerber/gerber_statements.py +++ b/gerber/gerber_statements.py @@ -95,10 +95,10 @@ class ParamStmt(Statement): class FSParamStmt(ParamStmt): """ FS - Gerber Format Specification Statement """ - + @classmethod def from_settings(cls, settings): - + return cls('FS', settings.zero_suppression, settings.notation, settings.format) @classmethod @@ -173,7 +173,7 @@ class FSParamStmt(ParamStmt): class MOParamStmt(ParamStmt): """ MO - Gerber Mode (measurement units) Statement. """ - + @classmethod def from_units(cls, units): return cls(None, units) @@ -235,7 +235,7 @@ class LPParamStmt(ParamStmt): param = stmt_dict['param'] lp = 'clear' if stmt_dict.get('lp') == 'C' else 'dark' return cls(param, lp) - + @classmethod def from_region(cls, region): #todo what is the first param? @@ -272,34 +272,34 @@ class LPParamStmt(ParamStmt): class ADParamStmt(ParamStmt): """ AD - Gerber Aperture Definition Statement """ - + @classmethod def rect(cls, dcode, width, height): '''Create a rectangular aperture definition statement''' return cls('AD', dcode, 'R', ([width, height],)) - + @classmethod def circle(cls, dcode, diameter, hole_diameter): '''Create a circular aperture definition statement''' - + if hole_diameter != None: return cls('AD', dcode, 'C', ([diameter, hole_diameter],)) return cls('AD', dcode, 'C', ([diameter],)) - + @classmethod def obround(cls, dcode, width, height): '''Create an obround aperture definition statement''' return cls('AD', dcode, 'O', ([width, height],)) - + @classmethod def polygon(cls, dcode, diameter, num_vertices, rotation, hole_diameter): '''Create a polygon aperture definition statement''' return cls('AD', dcode, 'P', ([diameter, num_vertices, rotation, hole_diameter],)) - + @classmethod def macro(cls, dcode, name): return cls('AD', dcode, name, '') - + @classmethod def from_dict(cls, stmt_dict): param = stmt_dict.get('param') @@ -436,7 +436,7 @@ class AMParamStmt(ParamStmt): AMThermalPrimitive.from_gerber(primitive)) else: self.primitives.append(AMUnsupportPrimitive.from_gerber(primitive)) - + return AMGroup(self.primitives, stmt=self, units=self.units) def to_inch(self): @@ -452,7 +452,7 @@ class AMParamStmt(ParamStmt): primitive.to_metric() def to_gerber(self, settings=None): - return '%AM{0}*{1}%'.format(self.name, "".join([primitive.to_gerber() for primitive in self.primitives])) + return '%AM{0}*{1}*%'.format(self.name, self.macro) def __str__(self): return '' % (self.name, self.macro) @@ -864,10 +864,10 @@ class CoordStmt(Statement): """ Coordinate Data Block """ - OP_DRAW = 'D01' + OP_DRAW = 'D01' OP_MOVE = 'D02' OP_FLASH = 'D03' - + FUNC_LINEAR = 'G01' FUNC_ARC_CW = 'G02' FUNC_ARC_CCW = 'G03' @@ -894,26 +894,26 @@ class CoordStmt(Statement): j = parse_gerber_value(stmt_dict.get('j'), settings.format, settings.zero_suppression) return cls(function, x, y, i, j, op, settings) - + @classmethod def move(cls, func, point): if point: return cls(func, point[0], point[1], None, None, CoordStmt.OP_MOVE, None) # No point specified, so just write the function. This is normally for ending a region (D02*) return cls(func, None, None, None, None, CoordStmt.OP_MOVE, None) - + @classmethod def line(cls, func, point): return cls(func, point[0], point[1], None, None, CoordStmt.OP_DRAW, None) - + @classmethod def mode(cls, func): return cls(func, None, None, None, None, None, None) - + @classmethod def arc(cls, func, point, center): return cls(func, point[0], point[1], center[0], center[1], CoordStmt.OP_DRAW, None) - + @classmethod def flash(cls, point): if point: @@ -1043,13 +1043,13 @@ class CoordStmt(Statement): coord_str += 'Op: %s' % op return '' % coord_str - + @property def only_function(self): """ Returns if the statement only set the function. """ - + # TODO I would like to refactor this so that the function is handled separately and then # TODO this isn't required return self.function != None and self.op == None and self.x == None and self.y == None and self.i == None and self.j == None @@ -1104,11 +1104,11 @@ class EofStmt(Statement): class QuadrantModeStmt(Statement): - + @classmethod def single(cls): return cls('single-quadrant') - + @classmethod def multi(cls): return cls('multi-quadrant') @@ -1140,11 +1140,11 @@ class RegionModeStmt(Statement): if 'G36' not in line and 'G37' not in line: raise ValueError('%s is not a valid region mode statement' % line) return (cls('on') if line[:3] == 'G36' else cls('off')) - + @classmethod def on(cls): return cls('on') - + @classmethod def off(cls): return cls('off') -- cgit