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/rs274x.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'gerberex/rs274x.py') diff --git a/gerberex/rs274x.py b/gerberex/rs274x.py index 4eb317d..13d3421 100644 --- a/gerberex/rs274x.py +++ b/gerberex/rs274x.py @@ -5,7 +5,7 @@ import gerber.rs274x from gerber.gerber_statements import ADParamStmt, CoordStmt -from gerberex.statements import AMParamStmt, AMParamStmtEx +from gerberex.gerber_statements import AMParamStmt, AMParamStmtEx, ADParamStmtEx from gerberex.utility import rotate class GerberFile(gerber.rs274x.GerberFile): @@ -17,6 +17,8 @@ class GerberFile(gerber.rs274x.GerberFile): def swap_statement(statement): if isinstance(statement, AMParamStmt) and not isinstance(statement, AMParamStmtEx): return AMParamStmtEx.from_stmt(statement) + elif isinstance(statement, ADParamStmt) and not isinstance(statement, AMParamStmtEx): + return ADParamStmtEx.from_stmt(statement) else: return statement statements = [swap_statement(statement) for statement in gerber_file.statements] @@ -26,6 +28,18 @@ class GerberFile(gerber.rs274x.GerberFile): def __init__(self, statements, settings, primitives, apertures, filename=None): super(GerberFile, self).__init__(statements, settings, primitives, apertures, filename) + def offset(self, x_offset=0, y_offset=0): + for statement in self.statements: + if isinstance(statement, CoordStmt): + if statement.x is not None: + statement.x += x_offset + if statement.y is not None: + statement.y += y_offset + else: + statement.offset(x_offset, y_offset) + for primitive in self.primitives: + primitive.offset(x_offset, y_offset) + def rotate(self, angle, center=(0,0)): if angle % 360 == 0: return @@ -84,7 +98,7 @@ class GerberFile(gerber.rs274x.GerberFile): while name in macros: name = '%s_%d' % (macro_def[0], num) num += 1 - self.statements.insert(insert_point, macro_def[1](name)) + self.statements.insert(insert_point, macro_def[1](name, self.units)) macro_defs[idx] = (name, macro_def[1]) for idx in range(insert_point, last_aperture + len(macro_defs) + 1): statement = self.statements[idx] @@ -92,10 +106,10 @@ class GerberFile(gerber.rs274x.GerberFile): if statement.shape == 'R': statement.shape = macro_defs[RECTANGLE][0] elif statement.shape == 'O': - x = statement.modifiers[0] \ - if len(statement.modifiers) > 0 else 0 - y = statement.modifiers[1] \ - if len(statement.modifiers) > 1 else 0 + x = statement.modifiers[0][0] \ + if len(statement.modifiers[0]) > 0 else 0 + y = statement.modifiers[0][1] \ + if len(statement.modifiers[0]) > 1 else 0 statement.shape = macro_defs[LANDSCAPE_OBROUND][0] \ if x > y else macro_defs[PORTRATE_OBROUND][0] elif statement.shape == 'P': -- cgit