summaryrefslogtreecommitdiff
path: root/gerbonara/cad/breakout.py
blob: 16d59ff3422c1246aba8b9544fcdd3441df733a5 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from dataclasses import dataclass

from ..utils import MM
from .primitives import *


@dataclass
class PadRing(Positioned):
    w: int
    h: int
    pitch: float = 2.54
    clearance: float = 0.2
    rows: int = 2
    trace_width: float = 0.4
    drill_dia: float = 0.9
    stagger: bool = False

    def ports(self):
        x, y, rotation = self.abs_pos

        x += self.pitch/2
        y += self.pitch/2

        x += self.pitch * self.rows
        y += self.pitch * self.rows

        pad_dia = self.pitch - 2*self.clearance - self.trace_width
        offset = pad_dia/2 - self.trace_width/2

        for i in range(1, self.w):
            yield (x+self.pitch/2 + i*self.pitch, y+offset)
            yield (x+self.pitch/2 + i*self.pitch, y+(self.h+1)*self.pitch-offset)

        for i in range(0, self.w):
            yield (x + (i+1)*self.pitch, y+offset)
            yield (x + (i+1)*self.pitch, y+(self.h+1)*self.pitch-offset)

        for i in range(1, self.h):
            yield (x+offset, y+self.pitch/2 + i*self.pitch)
            yield (x+(self.w+1)*self.pitch-offset, y+self.pitch/2 + i*self.pitch)

        for i in range(0, self.h):
            yield (x+offset, y + (i+1)*self.pitch)
            yield (x+(self.w+1)*self.pitch-offset, y + (i+1)*self.pitch)


    def generate(self, bbox, border_text, unit=MM):
        x, y, rotation = self.abs_pos

        x += self.pitch/2
        y += self.pitch/2

        x += self.pitch * self.rows
        y += self.pitch * self.rows

        pad_dia = self.pitch - 2*self.clearance - self.trace_width

        for i in range(self.w + 2 + 2*(self.rows-1)):
            for j in range(self.rows):
                yield THTPad.circle(x + (i - (self.rows - 1))*self.pitch, y - j*self.pitch, self.drill_dia, pad_dia, paste=False)
                yield THTPad.circle(x + (i - (self.rows - 1))*self.pitch, y + (self.h + 1 + j)*self.pitch, self.drill_dia, pad_dia, paste=False)

            if self.rows >= 2 and 1 <= i < self.w:
                yield Trace(self.trace_width, start=(x+i*self.pitch, y-self.pitch), end=(x+(i + 0.5)*self.pitch, y+pad_dia/2 - self.trace_width/2))
                yield Trace(self.trace_width, start=(x+i*self.pitch, y+(self.h+2)*self.pitch), end=(x+(i + 0.5)*self.pitch, y+(self.h+1)*self.pitch -pad_dia/2 + self.trace_width/2), orientation=('cw',))

        for i in range(1, self.h+1):
            for j in range(self.rows):
                yield THTPad.circle(x - j*self.pitch, y + i*self.pitch, self.drill_dia, pad_dia, paste=False)
                yield THTPad.circle(x + (self.w + 1 + j)*self.pitch, y + i*self.pitch, self.drill_dia, pad_dia, paste=False)

        for i in range(1, self.h):
            yield (x+offset, y+self.pitch/2 + i*self.pitch)
            yield (x+(self.w+1)*self.pitch-offset, y+self.pitch/2 + i*self.pitch)


    def generate(self, bbox, border_text, unit=MM):
        x, y, rotation = self.abs_pos

        x += self.pitch/2
        y += self.pitch/2

        x += self.pitch * self.rows
        y += self.pitch * self.rows

        pad_dia = self.pitch - 2*self.clearance - self.trace_width

        for i in range(self.w + 2 + 2*(self.rows-1)):
            for j in range(self.rows):
                yield THTPad.circle(x + (i - (self.rows - 1))*self.pitch, y - j*self.pitch, self.drill_dia, pad_dia, paste=False)
                yield THTPad.circle(x + (i - (self.rows - 1))*self.pitch, y + (self.h + 1 + j)*self.pitch, self.drill_dia, pad_dia, paste=False)

            if self.rows >= 2 and 1 <= i < self.w:
                yield Trace(self.trace_width, start=(x+i*self.pitch, y-self.pitch), end=(x+(i + 0.5)*self.pitch, y+pad_dia/2 - self.trace_width/2))
                yield Trace(self.trace_width, start=(x+i*self.pitch, y+(self.h+2)*self.pitch), end=(x+(i + 0.5)*self.pitch, y+(self.h+1)*self.pitch -pad_dia/2 + self.trace_width/2), orientation=('cw',))

        for i in range(1, self.h+1):
            for j in range(self.rows):
                yield THTPad.circle(x - j*self.pitch, y + i*self.pitch, self.drill_dia, pad_dia, paste=False)
                yield THTPad.circle(x + (self.w + 1 + j)*self.pitch, y + i*self.pitch, self.drill_dia, pad_dia, paste=False)

            if self.rows >= 2 and i < self.h:
                yield Trace(self.trace_width,
                            start=(
                                x-self.pitch,
                                y+i*self.pitch),
                            end=(
                                x+pad_dia/2 - self.trace_width/2,
                                y+(i + 0.5)*self.pitch),
                            orientation=('cw',))
                yield Trace(self.trace_width,
                            start=(
                                x+(self.w+2)*self.pitch,
                                y+i*self.pitch),
                            end=(
                                x+(self.w+1)*self.pitch -pad_dia/2 + self.trace_width/2,
                                y+(i + 0.5)*self.pitch))


def _breakout_demo():
    b = Board(100, 80)
    
    ring = PadRing(5, 5, 8, 12)
    for obj in ring.generate(None, None):
        b.add(obj)

    for x, y in ring.ports():
        b.add(Trace(0.1, start=(23, 27), end=(x, y)))

    with open('/tmp/test.svg', 'w') as f:
        f.write(str(b.pretty_svg()))
    b.layer_stack().save_to_directory('/tmp/testdir')


if __name__ == '__main__':
    _breakout_demo()