summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/aperture_macros
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-30 15:58:20 +0100
committerjaseg <git@jaseg.de>2022-01-30 15:58:20 +0100
commitfd9e0d00792256aed5c30d13abf894df31a357c4 (patch)
tree4ba1fad9473e881bf21cec36ceca3d9958c10ba1 /gerbonara/gerber/aperture_macros
parentc8bf837a4b5dcc6242b7dac383f09e9390deca35 (diff)
downloadgerbonara-fd9e0d00792256aed5c30d13abf894df31a357c4.tar.gz
gerbonara-fd9e0d00792256aed5c30d13abf894df31a357c4.tar.bz2
gerbonara-fd9e0d00792256aed5c30d13abf894df31a357c4.zip
Fix aperture macro outline primitive rendering
Diffstat (limited to 'gerbonara/gerber/aperture_macros')
-rw-r--r--gerbonara/gerber/aperture_macros/expression.py6
-rw-r--r--gerbonara/gerber/aperture_macros/parse.py5
-rw-r--r--gerbonara/gerber/aperture_macros/primitive.py14
3 files changed, 19 insertions, 6 deletions
diff --git a/gerbonara/gerber/aperture_macros/expression.py b/gerbonara/gerber/aperture_macros/expression.py
index f25fdd2..0cf055a 100644
--- a/gerbonara/gerber/aperture_macros/expression.py
+++ b/gerbonara/gerber/aperture_macros/expression.py
@@ -21,6 +21,9 @@ class Expression:
def __str__(self):
return f'<{self.to_gerber()}>'
+ def __repr__(self):
+ return f'<E {self.to_gerber()}>'
+
def converted(self, unit):
return self
@@ -76,6 +79,9 @@ class UnitExpression(Expression):
def __str__(self):
return f'<{self._expr.to_gerber()} {self.unit}>'
+ def __repr__(self):
+ return f'<UE {self._expr.to_gerber()} {self.unit}>'
+
def converted(self, unit):
if self.unit is None or unit is None or self.unit == unit:
return self._expr
diff --git a/gerbonara/gerber/aperture_macros/parse.py b/gerbonara/gerber/aperture_macros/parse.py
index 3a6f6e1..0fa936f 100644
--- a/gerbonara/gerber/aperture_macros/parse.py
+++ b/gerbonara/gerber/aperture_macros/parse.py
@@ -91,7 +91,10 @@ class ApertureMacro:
self._name = name
def __str__(self):
- return f'<Aperture macro, variables {str(self.variables)}, primitives {self.primitives}>'
+ return f'<Aperture macro {self.name}, variables {str(self.variables)}, primitives {self.primitives}>'
+
+ def __repr__(self):
+ return str(self)
def __eq__(self, other):
return hasattr(other, 'to_gerber') and self.to_gerber() == other.to_gerber()
diff --git a/gerbonara/gerber/aperture_macros/primitive.py b/gerbonara/gerber/aperture_macros/primitive.py
index 18aaf51..8732520 100644
--- a/gerbonara/gerber/aperture_macros/primitive.py
+++ b/gerbonara/gerber/aperture_macros/primitive.py
@@ -48,6 +48,9 @@ class Primitive:
attrs = ','.join(str(getattr(self, name)).strip('<>') for name in type(self).__annotations__)
return f'<{type(self).__name__} {attrs}>'
+ def __repr__(self):
+ return str(self)
+
class Calculator:
def __init__(self, instance, variable_binding={}, unit=None):
self.instance = instance
@@ -222,18 +225,19 @@ class Outline(Primitive):
self.coords = [(UnitExpression(x, unit), UnitExpression(y, unit)) for x, y in zip(args[0::2], args[1::2])]
+ def __str__(self):
+ return f'<Outline {len(self.coords)} points>'
+
def to_gerber(self, unit=None):
coords = ','.join(coord.to_gerber(unit) for xy in self.coords for coord in xy)
return f'{self.code},{self.exposure.to_gerber()},{len(self.coords)-1},{coords},{self.rotation.to_gerber()}'
def to_graphic_primitives(self, offset, rotation, variable_binding={}, unit=None, polarity_dark=True):
with self.Calculator(self, variable_binding, unit) as calc:
- bound_coords = [ (calc(x)+offset[0], calc(y)+offset[1]) for x, y in self.coords ]
- bound_radii = [None] * len(bound_coords)
-
rotation += deg_to_rad(calc.rotation)
- bound_coords = [ gp.rotate_point(*p, rotation, 0, 0) for p in bound_coords ]
-
+ bound_coords = [ gp.rotate_point(calc(x), calc(y), rotation, 0, 0) for x, y in self.coords ]
+ bound_coords = [ (x+offset[0], y+offset[1]) for x, y in bound_coords ]
+ bound_radii = [None] * len(bound_coords)
return [gp.ArcPoly(bound_coords, bound_radii, polarity_dark=(bool(calc.exposure) == polarity_dark))]
def dilate(self, offset, unit):