summaryrefslogtreecommitdiff
path: root/gerbonara/gerber/apertures.py
blob: aa2764e3d183939e5c127b14028b56f11759cd03 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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)