summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/apertures.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/apertures.py
parentf46b8897818439269d3fbce32773ec1ed12ad657 (diff)
downloadgerbonara-27a992f1c8c0a37245168e23db160412494d0e18.tar.gz
gerbonara-27a992f1c8c0a37245168e23db160412494d0e18.tar.bz2
gerbonara-27a992f1c8c0a37245168e23db160412494d0e18.zip
Add dilation code
Diffstat (limited to 'gerbonara/gerber/apertures.py')
-rw-r--r--gerbonara/gerber/apertures.py27
1 files changed, 27 insertions, 0 deletions
diff --git a/gerbonara/gerber/apertures.py b/gerbonara/gerber/apertures.py
index 2723c8d..7c98775 100644
--- a/gerbonara/gerber/apertures.py
+++ b/gerbonara/gerber/apertures.py
@@ -50,6 +50,14 @@ class Aperture:
else:
return value / 25.4
+ def convert_from(self, value, unit):
+ if self.unit == unit or self.unit is None or unit is None or value is None:
+ return value
+ elif unit == 'mm':
+ return value / 25.4
+ else:
+ return value * 25.4
+
def params(self, unit=None):
out = []
for f in fields(self):
@@ -112,6 +120,10 @@ class CircleAperture(Aperture):
def equivalent_width(self):
return self.diameter
+ def dilated(self, offset, unit='mm'):
+ offset = self.convert_from(offset, unit)
+ return replace(self, diameter=self.diameter+2*offset, hole_dia=None, hole_rect_h=None)
+
def _rotated(self):
if math.isclose(self.rotation % (2*math.pi), 0) or self.hole_rect_h is None:
return self
@@ -150,6 +162,10 @@ class RectangleAperture(Aperture):
def equivalent_width(self):
return math.sqrt(self.w**2 + self.h**2)
+ def dilated(self, offset, unit='mm'):
+ offset = self.convert_from(offset, unit)
+ return replace(self, w=self.w+2*offset, h=self.h+2*offset, hole_dia=None, hole_rect_h=None)
+
def _rotated(self):
if math.isclose(self.rotation % math.pi, 0):
return self
@@ -192,6 +208,10 @@ class ObroundAperture(Aperture):
flash = _flash_hole
+ def dilated(self, offset, unit='mm'):
+ offset = self.convert_from(offset, unit)
+ return replace(self, w=self.w+2*offset, h=self.h+2*offset, hole_dia=None, hole_rect_h=None)
+
def _rotated(self):
if math.isclose(self.rotation % math.pi, 0):
return self
@@ -232,6 +252,10 @@ class PolygonAperture(Aperture):
def __str__(self):
return f'<{self.n_vertices}-gon aperture d={self.diameter:.3}'
+ def dilated(self, offset, unit='mm'):
+ offset = self.convert_from(offset, unit)
+ return replace(self, diameter=self.diameter+2*offset, hole_dia=None)
+
flash = _flash_hole
def _rotated(self):
@@ -266,6 +290,9 @@ class ApertureMacroInstance(Aperture):
# FIXME return graphical primitives not macro primitives here
return [ primitive.with_offset(x, y).rotated(self.rotation, cx=0, cy=0) for primitive in self._primitives ]
+ def dilated(self, offset, unit='mm'):
+ return replace(self, macro=self.macro.dilated(offset, unit))
+
def _rotated(self):
if math.isclose(self.rotation % (2*math.pi), 0):
return self