From 7415f9a5848853fb7a2b5b91bbe438d85728e33a Mon Sep 17 00:00:00 2001 From: jaseg Date: Thu, 11 Nov 2021 12:10:56 +0100 Subject: Aperture macro parser works --- gerbonara/gerber/apertures.py | 85 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 gerbonara/gerber/apertures.py (limited to 'gerbonara/gerber/apertures.py') diff --git a/gerbonara/gerber/apertures.py b/gerbonara/gerber/apertures.py new file mode 100644 index 0000000..aa2764e --- /dev/null +++ b/gerbonara/gerber/apertures.py @@ -0,0 +1,85 @@ + +from dataclasses import dataclass + +from primitives import Primitive + +def _flash_hole(self, x, y): + if self.hole_rect_h is not None: + return self.primitives(x, y), Rectangle((x, y), (self.hole_dia, self.hole_rect_h), polarity_dark=False) + else: + return self.primitives(x, y), Circle((x, y), self.hole_dia, polarity_dark=False) + +class Aperture: + @property + def hole_shape(self): + if self.hole_rect_h is not None: + return 'rect' + else: + return 'circle' + + @property + def hole_size(self): + return (self.hole_dia, self.hole_rect_h) + + def flash(self, x, y): + return self.primitives(x, y) + + +@dataclass +class ApertureCircle(Aperture): + diameter : float + hole_dia : float = 0 + hole_rect_h : float = None + + def primitives(self, x, y): + return Circle((x, y), self.diameter, polarity_dark=True), + + flash = _flash_hole + + +@dataclass +class ApertureRectangle(Aperture): + w : float + h : float + hole_dia : float = 0 + hole_rect_h : float = None + + def primitives(self, x, y): + return Rectangle((x, y), (self.w, self.h), polarity_dark=True), + + flash = _flash_hole + + +@dataclass +class ApertureObround(Aperture): + w : float + h : float + hole_dia : float = 0 + hole_rect_h : float = None + + def primitives(self, x, y): + return Obround((x, y), self.w, self.h, polarity_dark=True) + + flash = _flash_hole + + +@dataclass +class AperturePolygon(Aperture): + diameter : float + n_vertices : int + hole_dia : float = 0 + hole_rect_h : float = None + + def primitives(self, x, y): + return Polygon((x, y), diameter, n_vertices, rotation, polarity_dark=True), + + flash = _flash_hole + +class MacroAperture(Aperture): + parameters : [float] + self.macro : ApertureMacro + + def primitives(self, x, y): + return self.macro.execute(x, y, self.parameters) + + -- cgit