-
Notifications
You must be signed in to change notification settings - Fork 1
/
make_6box.py
204 lines (164 loc) · 8.33 KB
/
make_6box.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
import Boxmaker
from reportlab.lib.colors import black
from reportlab.lib.colors import red
from reportlab.lib.colors import blue
from reportlab.lib.colors import green
from reportlab.graphics import shapes
from reportlab.lib.units import mm
PLATE_LENGTH = 1220
PLATE_WIDTH = 480
MATERIAL_THICKNESS = 5
BOX_LENGTH = 245
BOX_WIDTH = 140
BOX_INNER_HEIGHT = 5 * MATERIAL_THICKNESS - 0.1*mm
CUT_WIDTH = 0.001
SCREEN_X = 8
SCREEN_Y = 15
SCREEN_WIDTH = 194
SCREEN_HEIGHT = 111
SCREEN_TO_SCREW1X = 36
SCREEN_TO_SCREW2X = 162
SCREEN_TO_SCREW1Y = 22
SCREEN_TO_SCREW2Y = 87.5
RADIUS = 1.5
SCREEN_TO_METALX1 = 14
SCREEN_TO_METALX2 = 184
SCREEN_TO_METALY1 = 6
SCREEN_TO_METALY2 = 108
marginxTop = 20
marginxBottom = 62
marginx = 70
marginy = 10
##### preparation (box and field)
box = Boxmaker.Box(BOX_LENGTH, BOX_INNER_HEIGHT + MATERIAL_THICKNESS, BOX_WIDTH, MATERIAL_THICKNESS, CUT_WIDTH, 2.5*MATERIAL_THICKNESS)
box._compute_dimensions()
box._initialize_document("6box_wood.pdf", PLATE_LENGTH, PLATE_WIDTH, 0.001)
# ################## render the bottom part
boxBottom = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
boxBottom.add(box._draw_width_by_depth_side(0, 0))
# the field
boxBottom.add(box.drawField(BOX_LENGTH - MATERIAL_THICKNESS, 0, BOX_WIDTH/2, 5))
boxBottom.add(box.drawField(MATERIAL_THICKNESS, 0, BOX_WIDTH/2, 5, -1))
def draw_side(x, y, attach_height, hole_dist_x, fieldnum, fliph = 1, colorout = green, colorin = green):
f = box.drawField(x, y, BOX_WIDTH/2, fieldnum, fliph, colorout)
attach_width = 12
insert_length = fliph * 10
insert_width = 15
margin_hole = 5
l1 = box._draw_line(x, y, x, y + MATERIAL_THICKNESS, colorout)
l2 = box._draw_line(x, y + MATERIAL_THICKNESS, x - insert_length, y + MATERIAL_THICKNESS, colorout)
l3 = box._draw_line(x - insert_length, y + MATERIAL_THICKNESS, x - insert_length, y + MATERIAL_THICKNESS + insert_width, colorout)
l4 = box._draw_line(x, y + MATERIAL_THICKNESS + insert_width, x - insert_length, y + MATERIAL_THICKNESS + insert_width, colorout)
l5 = box._draw_line(x, y + MATERIAL_THICKNESS + insert_width, x, y + attach_height - attach_width/2, colorout)
b = box._draw_polyline([
x, y + attach_height - attach_width/2,
x - (hole_dist_x + margin_hole) * fliph, y + attach_height - attach_width/2 ,
x - (hole_dist_x + margin_hole) * fliph, y + attach_height + attach_width/2 ,
x, y + attach_height + attach_width/2], colorout)
l6 = box._draw_line(x, y + attach_height + attach_width/2, x, BOX_WIDTH + y - MATERIAL_THICKNESS - insert_width , colorout)
l7 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, colorout)
l8 = box._draw_line(x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS - insert_width, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS , colorout)
l9 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS, x - insert_length, y + BOX_WIDTH - MATERIAL_THICKNESS, colorout)
l10 = box._draw_line(x, y + BOX_WIDTH - MATERIAL_THICKNESS, x, y + BOX_WIDTH, colorout)
if fliph == 1:
p = box._draw_circle(x - hole_dist_x * fliph, y + attach_height, RADIUS, colorin)
else:
p = box._draw_circle(x - hole_dist_x * fliph, y + attach_height, RADIUS, colorin)
# p = box._draw_circle(x - (SCREEN_X + SCREEN_TO_SCREW1X - MATERIAL_THICKNESS)*fliph, y + attach_height, RADIUS, colorin)
return shapes.Group(f, l1, l2, l3, l4, l5, l6, l7, l8, l9, l10, p, b)
# for i in [4, 3, 2, 1]:
# boxBottom.add(draw_side(BOX_LENGTH - MATERIAL_THICKNESS, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, BOX_LENGTH - SCREEN_X - SCREEN_TO_SCREW2X - MATERIAL_THICKNESS, i))
# boxBottom.add(draw_side(MATERIAL_THICKNESS, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, SCREEN_TO_SCREW1X - MATERIAL_THICKNESS + SCREEN_X, i, -1))
# screws
boxBottom.add(shapes.Group(
box._draw_circle(SCREEN_X + SCREEN_TO_SCREW1X, SCREEN_Y + SCREEN_TO_SCREW1Y, RADIUS, red),
box._draw_circle(SCREEN_X + SCREEN_TO_SCREW1X, SCREEN_Y + SCREEN_TO_SCREW2Y, RADIUS, red),
box._draw_circle(SCREEN_X + SCREEN_TO_SCREW2X, SCREEN_Y + SCREEN_TO_SCREW1Y, RADIUS, red),
box._draw_circle(SCREEN_X + SCREEN_TO_SCREW2X, SCREEN_Y + SCREEN_TO_SCREW2Y, RADIUS, red)
))
boxBottom.drawOn(box._doc, 58*mm, 10*mm)
################# render the top part
boxTop = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
boxTop.add(box._draw_width_by_depth_side(0, 0))
# the field
boxTop.add(box.drawField(BOX_LENGTH - MATERIAL_THICKNESS, 0, BOX_WIDTH/2, 0))
boxTop.add(box.drawField(MATERIAL_THICKNESS, 0, BOX_WIDTH/2, 0, -1))
# # the screen
# boxTop.add(box._draw_rectangle(SCREEN_X, SCREEN_Y, SCREEN_WIDTH, SCREEN_HEIGHT, green))
# # screws
# boxTop.add(shapes.Group(
# box._draw_circle(SCREEN_X + SCREEN_TO_SCREW1X, SCREEN_Y + SCREEN_TO_SCREW1Y, RADIUS, green),
# box._draw_circle(SCREEN_X + SCREEN_TO_SCREW1X, SCREEN_Y + SCREEN_TO_SCREW2Y, RADIUS, green),
# box._draw_circle(SCREEN_X + SCREEN_TO_SCREW2X, SCREEN_Y + SCREEN_TO_SCREW1Y, RADIUS, green),
# box._draw_circle(SCREEN_X + SCREEN_TO_SCREW2X, SCREEN_Y + SCREEN_TO_SCREW2Y, RADIUS, green)
# ))
# hole for the led
boxTop.add(box._draw_circle(SCREEN_X + SCREEN_WIDTH + 25, SCREEN_Y + 55, 0.3, red))
# the metal part
boxTop.add(box._draw_rectangle(SCREEN_X + SCREEN_TO_METALX1, SCREEN_Y + SCREEN_TO_METALY1, SCREEN_TO_METALX2 - SCREEN_TO_METALX1, SCREEN_TO_METALY2 - SCREEN_TO_METALY1, red))
boxTop.drawOn(box._doc, 20*mm, (BOX_WIDTH + 18) * mm)
################# render the sides parts
boxSides = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
boxSides.add(box._draw_width_by_height_side(0, 0))
boxSides.add(box._draw_line(MATERIAL_THICKNESS, MATERIAL_THICKNESS, MATERIAL_THICKNESS, BOX_INNER_HEIGHT))
boxSides.add(box._draw_line(BOX_LENGTH - MATERIAL_THICKNESS, MATERIAL_THICKNESS, BOX_LENGTH - MATERIAL_THICKNESS, BOX_INNER_HEIGHT))
g = shapes.Group()
g.add(box._draw_width_by_height_side(0, 0))
g.add(box._draw_line(MATERIAL_THICKNESS, MATERIAL_THICKNESS, MATERIAL_THICKNESS, BOX_INNER_HEIGHT))
g.add(box._draw_line(BOX_LENGTH - MATERIAL_THICKNESS, MATERIAL_THICKNESS, BOX_LENGTH - MATERIAL_THICKNESS, BOX_INNER_HEIGHT))
g.translate(box._notch_length['w']*mm, BOX_INNER_HEIGHT*mm)
boxSides.add(g)
c = box._draw_circle(MATERIAL_THICKNESS + 50.5*mm, MATERIAL_THICKNESS + BOX_INNER_HEIGHT, 4, red)
boxSides.add(c)
boxSides.drawOn(box._doc, 20*mm , (2*BOX_WIDTH + 18 - MATERIAL_THICKNESS) * mm)
################# the sides
d = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
g1 = shapes.Group()
g1.add(draw_side(0, 0, BOX_WIDTH - (SCREEN_Y + SCREEN_TO_SCREW1Y), BOX_LENGTH - SCREEN_X - SCREEN_TO_SCREW2X - MATERIAL_THICKNESS, 1, 1, blue, red))
g1.rotate(9)
g1.translate(-17*mm, 67*mm)
d.add(g1)
g2 = shapes.Group()
g2.add(draw_side(51, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, SCREEN_TO_SCREW1X - MATERIAL_THICKNESS + SCREEN_X, 1, 1, red, red))
g2.rotate(90)
g2.translate(180*mm, 200*mm)
d.add(g2)
d.drawOn(box._doc, (BOX_LENGTH + 155)*mm , 5* mm)
d = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
g1 = shapes.Group()
g1.add(draw_side(0, 0, BOX_WIDTH - (SCREEN_Y + SCREEN_TO_SCREW1Y), BOX_LENGTH - SCREEN_X - SCREEN_TO_SCREW2X - MATERIAL_THICKNESS, 2, -1, blue, red))
g1.rotate(20)
g1.translate(32*mm, 38*mm)
d.add(g1)
g2 = shapes.Group()
g2.add(draw_side(55, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, SCREEN_TO_SCREW1X - MATERIAL_THICKNESS + SCREEN_X, 2, 1, blue, red))
g2.rotate(20)
g2.translate(10*mm, -6*mm)
d.add(g2)
d.drawOn(box._doc, (BOX_LENGTH + 75)*mm , (BOX_WIDTH + 30)* mm)
d = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
g = shapes.Group()
s = draw_side(0, 0, BOX_WIDTH - (SCREEN_Y + SCREEN_TO_SCREW1Y), BOX_LENGTH - SCREEN_X - SCREEN_TO_SCREW2X - MATERIAL_THICKNESS, 3, -1, blue, red)
s.rotate(90)
g.add(s)
s = draw_side(55, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, SCREEN_TO_SCREW1X - MATERIAL_THICKNESS + SCREEN_X, 3, 1, blue, red)
s.rotate(90)
s.translate(-40*mm, -50*mm)
g.add(s)
d.add(g)
d.drawOn(box._doc, (BOX_WIDTH + 5)*mm , (3*BOX_WIDTH - 23)* mm)
d = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
g = shapes.Group()
s = draw_side(0, 0, BOX_WIDTH - (SCREEN_Y + SCREEN_TO_SCREW1Y), BOX_LENGTH - SCREEN_X - SCREEN_TO_SCREW2X - MATERIAL_THICKNESS, 4, -1, blue, red)
s.rotate(90)
g.add(s)
s = draw_side(55, 0, SCREEN_Y + SCREEN_TO_SCREW1Y, SCREEN_TO_SCREW1X - MATERIAL_THICKNESS + SCREEN_X, 4, 1, blue, red)
s.rotate(90)
s.translate(-40*mm, -50*mm)
g.add(s)
d.add(g)
d.drawOn(box._doc, (BOX_WIDTH + 200)*mm , (3*BOX_WIDTH - 18)* mm)
bounds = shapes.Drawing(PLATE_LENGTH, PLATE_WIDTH)
bounds.add(box._draw_rectangle(1, 1, 400, 478))
bounds.drawOn(box._doc, 0, 0)
box._doc.save()