forked from nophead/NopSCADlib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iec.scad
267 lines (229 loc) · 9.17 KB
/
iec.scad
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
//
// NopSCADlib Copyright Chris Palmer 2018
// nop.head@gmail.com
// hydraraptor.blogspot.com
//
// This file is part of NopSCADlib.
//
// NopSCADlib 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.
//
// NopSCADlib 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 NopSCADlib.
// If not, see <https://www.gnu.org/licenses/>.
//
//
//! IEC mains inlets and outlet.
//
include <../core.scad>
use <screw.scad>
use <nut.scad>
use <washer.scad>
use <spade.scad>
use <insert.scad>
function iec_part(type) = type[1]; //! Description
function iec_screw(type) = type[2]; //! Screw type
function iec_pitch(type) = type[3]; //! Screw hole pitch
function iec_body_w(type) = type[4]; //! Body width
function iec_body_w2(type) = type[5]; //! Body width at the narrow part
function iec_body_h(type) = type[6]; //! Body height
function iec_body_r(type) = type[7]; //! Body corner radius
function iec_bezel_w(type) = type[8]; //! Bezel width
function iec_bezel_h(type) = type[9]; //! Bezel height
function iec_bezel_r(type) = type[10]; //! Bezel corner radius
function iec_bezel_t(type) = type[11]; //! Bezel thickness
function iec_flange_w(type) = type[12]; //! Flange width not including the lugs
function iec_flange_h(type) = type[13]; //! Flange height
function iec_flange_r(type) = type[14]; //! Flange corner radius
function iec_flange_t(type) = type[15]; //! Flange thickness
function iec_width(type) = type[16]; //! Widest part including the lugs
function iec_depth(type) = type[17]; //! Depth of the body below the flange
function iec_spades(type) = type[18]; //! Spade type
function iec_male(type) = type[19]; //! True for an outlet
insert_screw_length = 10;
function iec_insert_screw_length() = insert_screw_length; //! Screw length used for inserts
module iec(type) { //! Draw specified IEC connector
vitamin(str("iec(", type[0], "): ", iec_part(type)));
pin_w = 2;
pin_d = 4;
pin_h1 = 12;
pin_h2 = 15;
pin_chamfer = 1;
module pin(h)
color("silver")
hull() {
translate_z(h / 2)
cube([pin_w - pin_chamfer, pin_d - pin_chamfer, h], center = true);
translate_z((h - pin_chamfer) / 2)
cube([pin_w, pin_d, h - pin_chamfer], center = true);
}
socket_w = 24.5;
socket_w2 = 14;
socket_h = 16.34;
socket_h2 = socket_h - (socket_w - socket_w2);
socket_d = 17;
socket_r = 3;
socket_r2 = 0.5;
socket_offset = iec_bezel_h(type) / 2 - socket_h / 2 - (iec_bezel_w(type) - socket_w) / 2;
module socket_shape()
hull()
for(side = [-1, 1]) {
translate([side * (socket_w / 2 - socket_r), -socket_h / 2 + socket_r])
circle(socket_r);
translate([side * (socket_w / 2 - socket_r2), socket_h2 / 2 - socket_r2])
circle(socket_r2);
translate([side * (socket_w2 / 2 - socket_r2), socket_h / 2 - socket_r2])
circle(socket_r2);
}
module oriffice_shape()
translate([0, socket_offset])
if(iec_male(type))
difference() {
offset(2)
socket_shape();
difference() {
offset(-1) socket_shape();
translate([0, 2])
square([2.4, 5], center = true);
for(side = [-1, 1])
translate([side * 7, -2])
square([2.4, 5], center = true);
}
}
else
socket_shape();
module body_shape() {
hull() {
bw = iec_body_w(type);
bh = iec_body_h(type);
br = iec_body_r(type);
bw2 = iec_body_w2(type);
bh2 = bh - (bw - bw2);
br2 = 1;
for(side = [-1, 1]) {
translate([side * (bw / 2 - br), -bh / 2 + br])
circle4n(br);
translate([side * (bw / 2 - br2), bh2 / 2 - br2])
circle4n(br2);
translate([side * (bw2 / 2 - br2), bh / 2 - br2])
circle4n(br2);
}
}
}
color(grey20) {
// Flange
flange_t = iec_flange_t(type);
linear_extrude(height = flange_t)
difference() {
hull() {
rounded_square([iec_flange_w(type), iec_flange_h(type)], iec_flange_r(type));
iec_screw_positions(type)
circle(d = iec_width(type) - iec_pitch(type));
}
oriffice_shape();
iec_screw_positions(type)
circle(socket_r);
}
head_r = screw_head_radius(iec_screw(type));
screw_r = screw_clearance_radius(iec_screw(type));
iec_screw_positions(type)
rotate_extrude()
difference() {
translate([screw_r, 0])
square([socket_r - screw_r, flange_t]);
translate([0, flange_t - head_r])
rotate(45)
square(10);
}
// Bezel
translate_z(iec_flange_t(type))
linear_extrude(height = iec_bezel_t(type))
difference() {
rounded_square([iec_bezel_w(type), iec_bezel_h(type)], iec_bezel_r(type));
oriffice_shape();
}
// Body
h = socket_d - iec_flange_t(type) - iec_bezel_t(type);
translate_z(-h)
linear_extrude(height = h)
difference() {
body_shape();
oriffice_shape();
}
// Back
translate_z(-iec_depth(type))
linear_extrude(height = iec_depth(type) - h)
body_shape();
}
if(!iec_male(type))
translate([0, socket_offset, iec_flange_t(type) + iec_bezel_t(type) - socket_d]) {
translate([0, 2])
pin(pin_h2);
for(side = [-1, 1])
translate([side * 7, -2])
pin(pin_h1);
}
for(spade = iec_spades(type))
translate([spade[2], spade[3], -iec_depth(type)])
rotate([180, 0, spade[4]])
spade(spade[0], spade[1]);
}
function iec_spade_depth(type) = iec_depth(type) + max([for(spade = iec_spades(type)) spade[1]]);
module iec_screw_positions(type) //! Position children at the screw holes
for(side = [-1, 1])
translate([side * iec_pitch(type) / 2, 0])
children();
module iec_holes(type, h = 100, poly = false, horizontal = false, insert = false) { //! Drill the required panel holes
clearance = 0.2;
screw = iec_screw(type);
insert_type = screw_insert(screw);
insert_overlap = max(0, insert_screw_length + clearance - iec_flange_t(type) - insert_hole_length(insert_type));
iec_screw_positions(type)
if(insert)
if(h)
insert_hole(insert_type, insert_overlap, horizontal = horizontal);
else
poly_circle(insert_hole_radius(insert_type));
else
if(horizontal)
teardrop_plus(r = screw_clearance_radius(screw), h = h);
else
if(poly)
poly_cylinder(r = screw_clearance_radius(screw), h = h, center = true);
else
drill(screw_clearance_radius(screw), h);
extrude_if(h)
hull()
for(x = [-1, 1], y = [-1, 1], sag = horizontal && y > 1 ? layer_height : 0)
translate([x * (iec_body_w(type) / 2 - iec_body_r(type)), y * (iec_body_h(type) / 2 - iec_body_r(type) + sag )])
if(horizontal)
teardrop(0, iec_body_r(type) + clearance / 2 + layer_height / 4);
else
drill(iec_body_r(type) + clearance / 2, 0);
}
module iec_inserts(type) { //! Place the inserts
insert = screw_insert(iec_screw(type));
iec_screw_positions(type)
insert(insert);
}
module iec_assembly(type, thickness) { //! Assembly with fasteners given panel thickness
screw = iec_screw(type);
washer = screw_washer(screw);
nut = screw_nut(screw);
insert = screw_insert(screw);
screw_length = thickness ? screw_longer_than(iec_flange_t(type) + thickness + washer_thickness(washer) + nut_thickness(nut, true))
: insert_screw_length;
iec(type);
iec_screw_positions(type) {
translate_z(iec_flange_t(type))
screw(screw, screw_length);
if(thickness)
translate_z(-thickness)
vflip()
nut_and_washer(nut, true);
}
}