forked from halfmarble/hm-panelizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPcbRail.py
131 lines (100 loc) · 4.91 KB
/
PcbRail.py
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
# The MIT License (MIT)
# Copyright 2021,2022 HalfMarble LLC
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import tempfile
from kivy.cache import Cache
from kivy.graphics import Rectangle, Color
from AppSettings import *
from PcbFile import *
from Utilities import *
from Constants import *
class PcbRail:
def __init__(self):
self._gm1 = None
self._gtl = None
self._gts = None
self._gto = None
self._panels = 0
self._gap = 0
self._origin = (0, 0)
self._size = (0, 0)
self._vcut = False
self._jlc = False
self._tmp_folder = tempfile.TemporaryDirectory().name
try:
os.mkdir(self._tmp_folder)
except FileExistsError:
pass
def generate_pcb_files(self):
if self._tmp_folder is None:
print('ERROR: PcbRail temp folder is NULL')
return
save_rail_gm1(self._tmp_folder, self._origin, self._size, self._panels, self._gap, self._vcut)
save_rail_gtl(self._tmp_folder, self._origin, self._size)
save_rail_gts(self._tmp_folder, self._origin, self._size)
save_rail_gto(self._tmp_folder, self._origin, self._size, self._panels, self._gap, self._vcut, self._jlc)
save_rail_gbo(self._tmp_folder, self._origin, self._size)
return self._tmp_folder
def render_masks(self, panels, gap, origin, size, vcut, jlc):
if self._tmp_folder is None:
print('ERROR: PcbRail temp folder is NULL')
return
if self._gm1 is None or self._panels != panels or self._origin != origin or self._size != size or \
self._vcut != vcut or self._jlc != jlc:
bounds = render_rail_gm1(self._tmp_folder, 'rail_edge_cuts', origin, size, panels, gap, vcut)
render_rail_gtl(bounds, self._tmp_folder, 'rail_top_copper', origin, size)
render_rail_gts(bounds, self._tmp_folder, 'rail_top_mask', origin, size)
render_rail_gto(bounds, self._tmp_folder, 'rail_top_silk', origin, size, panels, gap, vcut, jlc)
self._gm1 = load_image_masked(self._tmp_folder, 'rail_edge_cuts_mask.png', Color(1, 1, 1, 1))
self._gtl = load_image_masked(self._tmp_folder, 'rail_top_copper.png', Color(1, 1, 1, 1))
self._gts = load_image_masked(self._tmp_folder, 'rail_top_mask.png', Color(1, 1, 1, 1))
self._gto = load_image_masked(self._tmp_folder, 'rail_top_silk.png', Color(1, 1, 1, 1))
# TODO: is there anything else that's more efficient that we can do here?
# without this the rail images do not refresh correctly
Cache.remove('kv.image')
Cache.remove('kv.texture')
self._panels = panels
self._gap = gap
self._origin = origin
self._size = size
self._vcut = vcut
self._jlc = jlc
def paint(self, bottom, top):
c = PCB_MASK_COLOR
Color(c.r, c.g, c.b, c.a)
Rectangle(texture=self._gm1.texture, pos=bottom.pos, size=bottom.size)
Rectangle(texture=self._gm1.texture, pos=top.pos, size=top.size)
c = PCB_TOP_MASK_COLOR
Color(c.r, c.g, c.b, c.a)
Rectangle(texture=self._gts.texture, pos=bottom.pos, size=bottom.size)
Rectangle(texture=self._gts.texture, pos=top.pos, size=top.size)
c = PCB_TOP_TRACES_COLOR
Color(c.r, c.g, c.b, c.a)
Rectangle(texture=self._gtl.texture, pos=bottom.pos, size=bottom.size)
Rectangle(texture=self._gtl.texture, pos=top.pos, size=top.size)
c = PCB_TOP_SILK_COLOR
Color(c.r, c.g, c.b, c.a)
Rectangle(texture=self._gto.texture, pos=bottom.pos, size=bottom.size)
Rectangle(texture=self._gto.texture, pos=top.pos, size=top.size)
def invalidate(self):
self._gm1 = None
self._gtl = None
self._gts = None
self._gto = None
def cleanup(self):
rmrf(self._tmp_folder)
PcbRail = PcbRail()