-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaseBuilderLib_Lock.scad
201 lines (176 loc) · 8.22 KB
/
CaseBuilderLib_Lock.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
//###############################################################################
//# CaseBuilderLib - Lock #
//###############################################################################
//# Copyright 2020 Dirk Heisswolf #
//# This file is part of the CaseBuilderLib project. #
//# #
//# This project 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 project 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 project. If not, see <http://www.gnu.org/licenses/>. #
//# #
//###############################################################################
//# Description: #
//# A selection of lock options: #
//# 1. Elastic string #
//# 2. Pull Latch #
//# #
//###############################################################################
//# Version History: #
//# June 29, 2020 #
//# - Initial release #
//# #
//###############################################################################
include <CaseBuilderLib_Common.scad>
//Local parameters
//================
//Lock option 1: Elastic string
stringD = 3; //Diameter of the elasic string
knotD = 5; //Diameter of the knot
knotOff = 2; //Knot offset
//Positive lower lock parts
module lowerLockPos(pSet) {
//Short cuts
idimX = pSet[idxIdimX]; //Inner X dimension
idimY = pSet[idxIdimY]; //Inner Y dimension
idimZ = pSet[idxIdimZ]; //Inner Z dimension
wallW = pSet[idxWallW]; //Wall thickness
gapW = pSet[idxGapW]; //Gap between moving parts
lockO = pSet[idxLockO]; //Lock option
}
//Negative lower lock parts
module lowerLockNeg(pSet) {
//Short cuts
idimX = pSet[idxIdimX]; //Inner X dimension
idimY = pSet[idxIdimY]; //Inner Y dimension
idimZ = pSet[idxIdimZ]; //Inner Z dimension
wallW = pSet[idxWallW]; //Wall thickness
gapW = pSet[idxGapW]; //Gap between moving parts
lockO = pSet[idxLockO]; //Lock option
//Elastic string option
if (lockO==1) {
translate([-idimX/2,-idimY/2+knotD/2+knotOff,-idimZ/2]) rotate([90,0,0]) torus4n(d1=knotD,d2=knotD,angle=90,$fn=12);
translate([-idimX/2+knotD/2,-idimY/2+knotD/2+knotOff,-idimZ/2]) rotate([180,0,0]) cylinder4n(h=wallW+1,d=knotD,$fn=12);
translate([-idimX/2,-idimY/2+knotD/2+knotOff,-idimZ/2+knotD/2]) rotate([0,270,0]) cylinder4n(h=wallW+1,d=stringD,$fn=12);
translate([idimX/2,-idimY/2+knotD/2+knotOff,-idimZ/2]) rotate([90,0,180]) torus4n(d1=knotD,d2=knotD,angle=90,$fn=12);
translate([idimX/2-knotD/2,-idimY/2+knotD/2+knotOff,-idimZ/2]) rotate([180,0,0]) cylinder4n(h=wallW+1,d=knotD,$fn=12);
translate([idimX/2,-idimY/2+knotD/2+knotOff,-idimZ/2+knotD/2]) rotate([0,90,0]) cylinder4n(h=wallW+1,d=stringD,$fn=12);
}
//Pull latch option
if (lockO==2) {
intersection() {
hull() {
translate([-15-gapW,-10-idimY/2,-8]) cube([30+2*gapW,10,4]);
translate([-25-gapW,-10-idimY/2,-4+idimZ/2]) cube([50+2*gapW,10,4]);
}
union() {
hull() {
translate([-idimX/2,-2-idimY/2,-4]) rotate([0,90,0]) cylinder4n(h=idimX,d=3);
translate([-idimX/2,-2-idimY/2,-6]) rotate([0,90,0]) cylinder4n(h=idimX,d=3);
}
translate([-idimX/2,-2-wallW-idimY/2,-7.5]) cube([idimX,wallW,5]);
hull() {
translate([-idimX/2,-2-wallW-idimY/2,-2.5]) cube([idimX,wallW,4]);
translate([-idimX/2,-1-wallW-idimY/2,]) cube([idimX,wallW,2]);
}
}
}
}
//Push latch option
if (lockO==3) {
}
}
//Positive upper lock parts
module upperLockPos(pSet) {
//Short cuts
idimX = pSet[idxIdimX]; //Inner X dimension
idimY = pSet[idxIdimY]; //Inner Y dimension
idimZ = pSet[idxIdimZ]; //Inner Z dimension
wallW = pSet[idxWallW]; //Wall thickness
gapW = pSet[idxGapW]; //Gap between moving parts
lockO = pSet[idxLockO]; //Lock option
//Pull latch option
if (lockO==2) {
intersection() {
hull() {
translate([-15,-10-idimY/2,-8]) cube([30,10,4]);
translate([-25,-10-idimY/2,-4+idimZ/2]) cube([50,10,4]);
}
union() {
translate([-idimX/2,-2-idimY/2,-4]) rotate([0,90,0]) cylinder4n(h=idimX,d=3);
translate([-idimX/2,-2.75-idimY/2,-5.5]) rotate([0,90,0]) cylinder4n(h=idimX,d=1.5);
translate([-idimX/2,-3.5-idimY/2,-5.5]) cube([idimX,1.5,idimZ/2]);
hull() {
translate([-idimX/2,-3.5-idimY/2,-6+idimZ/2]) cube([idimX,1.5,2]);
translate([-idimX/2,-wallW-idimY/2,-2+idimZ/2]) cube([idimX,wallW,2]);
}
}
}
}
}
//Negative upper lock parts
module upperLockNeg(pSet) {
//Short cuts
idimX = pSet[idxIdimX]; //Inner X dimension
idimY = pSet[idxIdimY]; //Inner Y dimension
idimZ = pSet[idxIdimZ]; //Inner Z dimension
wallW = pSet[idxWallW]; //Wall thickness
gapW = pSet[idxGapW]; //Gap between moving parts
lockO = pSet[idxLockO]; //Lock option
//Pull latch option
if (lockO==2) {
intersection() {
hull() {
translate([-15-gapW,-10-idimY/2,-8]) cube([30+2*gapW,10,4]);
translate([-25-gapW,-10-idimY/2,-4+idimZ/2]) cube([50+2*gapW,10,4]);
}
translate([-idimX/2,2*gapW-2-wallW-idimY/2,-1]) cube([idimX,wallW,-4+idimZ/2]);
}
}
}
//Attach lower lock
module attachLowerLock(pSet) {
lowerLockPos(pSet);
difference() {
children();
lowerLockNeg(pSet);
}
}
//Attach upper lock
module attachUpperLock(pSet) {
upperLockPos(pSet);
difference() {
children();
upperLockNeg(pSet);
}
}
//Space, taken up by the lock
module lockSpace(pSet) {
lowerLockPos(pSet);
lowerLockNeg(pSet);
upperLockPos(pSet);
upperLockNeg(pSet);
}
//Preview
if ($preview) {
//Preview parameter set
prevPSet = pSet(lockO=2);
idimX = prevPSet[idxIdimX]; //Inner X dimension
idimY = prevPSet[idxIdimY]; //Inner Y dimension
idimZ = prevPSet[idxIdimZ]; //Inner Z dimension
wallW = prevPSet[idxWallW]; //Wall thickness
gapW = prevPSet[idxGapW]; //Gap between moving parts
color("red") lowerLockNeg(prevPSet);
color("green") upperLockPos(prevPSet);
color("red") upperLockNeg(prevPSet);
color("gray",0.25) translate([0,0,idimZ/4]) cube([idimX,idimY,idimZ/2],center=true);
color("gray",0.45) translate([0,0,-idimZ/4]) cube([idimX,idimY,idimZ/2],center=true);
}