summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/aperture_macros/primitive.py
diff options
context:
space:
mode:
authorjaseg <git@jaseg.de>2022-01-01 17:47:50 +0100
committerjaseg <git@jaseg.de>2022-01-01 17:47:50 +0100
commit27a992f1c8c0a37245168e23db160412494d0e18 (patch)
treeab7bdef14e9e2715277e1cff68adf109ca3ca963 /gerbonara/gerber/aperture_macros/primitive.py
parentf46b8897818439269d3fbce32773ec1ed12ad657 (diff)
downloadgerbonara-27a992f1c8c0a37245168e23db160412494d0e18.tar.gz
gerbonara-27a992f1c8c0a37245168e23db160412494d0e18.tar.bz2
gerbonara-27a992f1c8c0a37245168e23db160412494d0e18.zip
Add dilation code
Diffstat (limited to 'gerbonara/gerber/aperture_macros/primitive.py')
-rw-r--r--gerbonara/gerber/aperture_macros/primitive.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/gerbonara/gerber/aperture_macros/primitive.py b/gerbonara/gerber/aperture_macros/primitive.py
index a587d7e..b28fdb5 100644
--- a/gerbonara/gerber/aperture_macros/primitive.py
+++ b/gerbonara/gerber/aperture_macros/primitive.py
@@ -4,6 +4,7 @@
# Copyright 2019 Hiroshi Murayama <opiopan@gmail.com>
# Copyright 2022 Jan Götte <gerbonara@jaseg.de>
+import warnings
import contextlib
import math
@@ -20,6 +21,13 @@ def point_distance(a, b):
def deg_to_rad(a):
return (a / 180) * math.pi
+def convert(value, src, dst):
+ if src == dst or src is None or dst is None or value is None:
+ return value
+ elif dst == 'mm':
+ return value * 25.4
+ else:
+ return value / 25.4
class Primitive:
def __init__(self, unit, args):
@@ -88,6 +96,9 @@ class Circle(Primitive):
x, y = x+offset[0], y+offset[1]
return [ gp.Circle(x, y, calc.r, polarity_dark=bool(calc.exposure)) ]
+ def dilate(self, offset, unit):
+ self.diameter += UnitExpression(offset, unit)
+
class VectorLine(Primitive):
code = 20
exposure : Expression
@@ -112,6 +123,9 @@ class VectorLine(Primitive):
return [ gp.Rectangle(center_x, center_y, length, calc.width, rotation=rotation,
polarity_dark=bool(calc.exposure)) ]
+ def dilate(self, offset, unit):
+ self.width += UnitExpression(2*offset, unit)
+
class CenterLine(Primitive):
code = 21
@@ -131,6 +145,9 @@ class CenterLine(Primitive):
w, h = calc.width, calc.height
return [ gp.Rectangle(x, y, w, h, rotation, polarity_dark=bool(calc.exposure)) ]
+
+ def dilate(self, offset, unit):
+ self.width += UnitExpression(2*offset, unit)
class Polygon(Primitive):
@@ -151,6 +168,9 @@ class Polygon(Primitive):
return [ gp.RegularPolygon(calc.x, calc.y, calc.diameter/2, calc.n_vertices, rotation,
polarity_dark=bool(calc.exposure)) ]
+ def dilate(self, offset, unit):
+ self.diameter += UnitExpression(2*offset, unit)
+
class Thermal(Primitive):
code = 7
@@ -178,6 +198,11 @@ class Thermal(Primitive):
gp.Rectangle(x, y, gap_w, d_outer, rotation=rotation, polarity_dark=not dark),
]
+ def dilate(self, offset, unit):
+ # I'd rather print a warning and produce graphically slightly incorrect output in these few cases here than
+ # producing macros that may evaluate to primitives with negative values.
+ warnings.warn('Attempted dilation of macro aperture thermal primitive. This is not supported.')
+
class Outline(Primitive):
code = 4
@@ -220,6 +245,10 @@ class Outline(Primitive):
return gp.ArcPoly(bound_coords, bound_radii, polarity_dark=calc.exposure)
+ def dilate(self, offset, unit):
+ # we would need a whole polygon offset/clipping library here
+ warnings.warn('Attempted dilation of macro aperture outline primitive. This is not supported.')
+
class Comment:
code = 0