From f64b03efc752b682b1cbe8cfb114f19e3362ef76 Mon Sep 17 00:00:00 2001 From: jaseg Date: Fri, 17 Feb 2023 00:03:04 +0100 Subject: Add CLI --- gerbonara/aperture_macros/parse.py | 6 ++++++ gerbonara/aperture_macros/primitive.py | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'gerbonara/aperture_macros') diff --git a/gerbonara/aperture_macros/parse.py b/gerbonara/aperture_macros/parse.py index 1eaa317..448330f 100644 --- a/gerbonara/aperture_macros/parse.py +++ b/gerbonara/aperture_macros/parse.py @@ -142,6 +142,12 @@ class ApertureMacro: primitive.rotation -= rad_to_deg(angle) return dup + def scaled(self, scale): + dup = copy.deepcopy(self) + for primitive in dup.primitives: + primitive.scale(scale) + return dup + var = VariableExpression deg_per_rad = 180 / math.pi diff --git a/gerbonara/aperture_macros/primitive.py b/gerbonara/aperture_macros/primitive.py index 47ae87b..579c701 100644 --- a/gerbonara/aperture_macros/primitive.py +++ b/gerbonara/aperture_macros/primitive.py @@ -93,6 +93,12 @@ class Circle(Primitive): def dilate(self, offset, unit): self.diameter += UnitExpression(offset, unit) + def scale(self, scale): + self.x *= UnitExpression(scale) + self.y *= UnitExpression(scale) + self.diameter *= UnitExpression(scale) + + class VectorLine(Primitive): code = 20 exposure : Expression @@ -120,6 +126,12 @@ class VectorLine(Primitive): def dilate(self, offset, unit): self.width += UnitExpression(2*offset, unit) + def scale(self, scale): + self.start_x *= UnitExpression(scale) + self.start_y *= UnitExpression(scale) + self.end_x *= UnitExpression(scale) + self.end_y *= UnitExpression(scale) + class CenterLine(Primitive): code = 21 @@ -142,6 +154,12 @@ class CenterLine(Primitive): def dilate(self, offset, unit): self.width += UnitExpression(2*offset, unit) + + def scale(self, scale): + self.width *= UnitExpression(scale) + self.height *= UnitExpression(scale) + self.x *= UnitExpression(scale) + self.y *= UnitExpression(scale) class Polygon(Primitive): @@ -165,6 +183,11 @@ class Polygon(Primitive): def dilate(self, offset, unit): self.diameter += UnitExpression(2*offset, unit) + def scale(self, scale): + self.diameter *= UnitExpression(scale) + self.x *= UnitExpression(scale) + self.y *= UnitExpression(scale) + class Thermal(Primitive): code = 7 @@ -197,6 +220,13 @@ class Thermal(Primitive): # producing macros that may evaluate to primitives with negative values. warnings.warn('Attempted dilation of macro aperture thermal primitive. This is not supported.') + def scale(self, scale): + self.d_outer *= UnitExpression(scale) + self.d_inner *= UnitExpression(scale) + self.gap_w *= UnitExpression(scale) + self.x *= UnitExpression(scale) + self.y *= UnitExpression(scale) + class Outline(Primitive): code = 4 @@ -244,6 +274,9 @@ class Outline(Primitive): # we would need a whole polygon offset/clipping library here warnings.warn('Attempted dilation of macro aperture outline primitive. This is not supported.') + def scale(self, scale): + self.coords = [(x*UnitExpression(scale), y*UnitExpression(scale)) for x, y in self.coords] + class Comment: code = 0 @@ -254,6 +287,9 @@ class Comment: def to_gerber(self, unit=None): return f'0 {self.comment}' + def scale(self, scale): + pass + PRIMITIVE_CLASSES = { **{cls.code: cls for cls in [ Comment, -- cgit