forked from applemuncy/boxmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_slots.py
229 lines (161 loc) · 7.36 KB
/
my_slots.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# -*- coding: utf-8 -*-
'''
Generates Inkscape SVG file containing box components needed to
laser cut a tabbed construction box taking kerf and clearance into account
Copyright (C) 2016 Apple Muncy [email protected]
Copyright (C) 2011 elliot white [email protected]
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
from ink_helper import *
import inkex
class Slot_row:
'''
an Slot_row class to hold all information of an row of slots.
'''
def row(self ):
divs=int(self.length/self.nom_tab_width) # divisions
if not divs%2: divs-=1 # make divs odd
divs=float(divs)
tabs=(divs-1)/2 # tabs for side
screw_r = self.screw_diameter / 2.
if 'Fixed' == self.equalTabs :
gapWidth=tabWidth=self.length/divs
else:
tabWidth=self.nom_tab_width
gapWidth=(self.length-tabs*self.nom_tab_width)/(divs-tabs)
if self.isTab: # kerf correction
gapWidth-=self.correction
tabWidth+=self.correction
first=self.correction/2
else:
gapWidth+=self.correction
tabWidth-=self.correction
first=-self.correction/2
firstVec=0; secondVec=self.tabVec1
dirxN=0 if self.dirV2[0] else 1 # used to select operation on x or y
diryN=0 if self.dirV2[1] else 1
half_thickness = self.thickness/2
(Vx,Vy)=(self.x+self.sox*self.thickness,self.y+self.soy*self.thickness)
s=''
if dirxN: Vy=self.y
if diryN: Vx=self.x
# generate line as tab or hole using:
# last co-ord:Vx,Vy ; tab dir:self.tabVec1 ; direction:self.dirV2 ; thickness:thickness
# divisions:divs ; gap width:gapWidth ; tab width:tabWidth
#setup for nut slots and holes
s_h_flipflop = '0' # always skip the first hole .
if self.isTab :
start_sequence = 'O'
else :
start_sequence = 'I'
Ox,Oy = None,None
for n in range(1,int(divs)):
if n == 1:
Vx=Vx+(self.dirV2[0]*gapWidth+dirxN*firstVec+first*self.dirV2[0])
Vy=Vy+(self.dirV2[1]*gapWidth+diryN*firstVec+first*self.dirV2[1])
s+='M '+str(Vx)+','+str(-1*Vy)+' '
Ox,Oy=Vx,Vy
Vx=Vx+dirxN*secondVec
Vy=Vy+diryN*secondVec
s+='L '+str(Vx)+','+str(-1*Vy)+' '
s_h_flipflop = start_sequence
elif n%2:
Vx=Vx+(self.dirV2[0]*gapWidth+dirxN*firstVec)/2
Vy=Vy+(self.dirV2[1]*gapWidth+diryN*firstVec)/2
if s_h_flipflop == 'I':
#s+='L '+str(Vx)+','+str(-1*Vy)+' '
s_h_flipflop = 'O'
elif s_h_flipflop == 'O' :
if self.do_holes :
drawCircle( screw_r, ((Vx+self.inV2[0] * half_thickness) , -1* (Vy -
self.inV2[1]*half_thickness )), self.parent )
s_h_flipflop = 'I'
else : s_h_flipflop = start_sequence
Vx=Vx+(self.dirV2[0]*gapWidth+dirxN*firstVec)/2
Vy=Vy+(self.dirV2[1]*gapWidth+diryN*firstVec)/2
#moves to right and below hole
s+='M '+str(Vx)+','+str(-1*Vy)+' '
#this should grab the beginning of the box.
Ox,Oy=Vx,Vy
Vx=Vx+dirxN*secondVec
Vy=Vy+diryN*secondVec
#draws the first vertical line
s+='L '+str(Vx)+','+str(-1*Vy)+' '
else:
Vx=Vx+(self.dirV2[0]*tabWidth+dirxN*firstVec)
Vy=Vy+(self.dirV2[1]*tabWidth+diryN*firstVec)
s+='L '+str(Vx)+','+str(-1*Vy)+' '
#Ox , Oy = Vx, Vy
if s_h_flipflop == 'I':
s_h_flipflop ='O'
elif s_h_flipflop == 'O' :
s_h_flipflop = 'I'
else : s_h_flipflop = start_sequence
Vx=Vx+dirxN*secondVec
Vy=Vy+diryN*secondVec
s+='L '+str(Vx)+','+str(-1*Vy)+' '
#close the box.
s+='L '+str(Ox)+','+str(-1*Oy)+' '
(secondVec,firstVec)=(-secondVec,-firstVec) # swap tab direction
return s
def __init__(self, panel_name, name, x , y, (sox,soy),(eox,eoy), isTab ,tab_direction, length , my_dict):
'''
grab all values to draw slots.
'''
self.debug = my_dict['debug']
#Knerf correction
self.correction = my_dict['correction']
if panel_name in(['front_panel','back_panel']):
self.nom_tab_width = my_dict['nom_length_tab_width']
elif panel_name in (['left_panel','right_panel']):
self.nom_tab_width = my_dict['nom_width_tab_width']
self.equalTabs = my_dict['equalTabs']
self.screw_diameter = my_dict['screw_diameter']
self.panel_name = panel_name
self.name = name
if not 'divider_panel' == panel_name :
self.do_holes = my_dict[ self.panel_name + '_' + self.name + '_screw_hole']
else:
self.do_holes = False
self.parent = my_dict['parent']
#x, y are absolute position coordinate
self.x = x
self.y = y
#sox,soy,eox,eoy contain correction of where edge starts and ends
self.sox, self.soy = (sox,soy)
self.eox, self.eoy = (eox,eoy)
#isTab controls the mesh pattern of of the box where panels meet.
#That is to say isTab is True of and edge then its mating edge must have
# have isTab False.
self.isTab = isTab
#tab_direction is 1 or -1 according to how this edge
#is to mate with the adjoining edge.
self.tab_direction = tab_direction
self.thickness = my_dict['thickness']
#tab_direction times thickness becomes the distance and direction
#to draw the tab side.
self.tabVec1 = self.tab_direction * self.thickness
#length in one direction of this edge
self.length = length
#self.dirV2 holds the unit 2 dimention vector of this edge
self.dirV2 = None
#inV2 holds the direction in , that is to say direction from
#the edge toward the inside of the panel
self.inV2 = None
if self.name == 'slot_row':
self.dirV2 = Vec2(1, 0)
self.inV2 = Vec2(0,-1)
else :
inkex.debug('wrong slot_row parameter {0} passed to Slot_row class'.format(i))
S = self.row()
drawS(S, self.parent)
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99