Root/bacon/case/case.fpd

Source at commit e0063a90c557863e7733660a44065c4c75874221 created 9 years 8 months ago.
By Werner Almesberger, ircstat/ML: update for 2014-05
1/*
2 * Draw a rounded edge in one quadrant
3 *
4 * Draw a arc from corner point vc plus rector ra to vc+rb. vc+ra is stored
5 * in va and vc+rb is stored in vb.
6 */
7
8#define Q(va, vb, vc, ra, rb) \
9    va: vec vc ra; \
10    vb: vec vc rb; \
11    vc##_center: vec va rb; \
12    arc vc##_center va vb
13
14#define QLL(pfx, r) \
15    Q(pfx##lly, pfx##llx, pfx##ll, (0mm, r), (r, 0mm))
16#define QLR(pfx, r) \
17    Q(pfx##lrx, pfx##lry, pfx##lr, (-(r), 0mm), (0mm, r))
18#define QUL(pfx, r) \
19    Q(pfx##ulx, pfx##uly, pfx##ul, (r, 0mm), (0mm, -(r)))
20#define QUR(pfx, r) \
21    Q(pfx##ury, pfx##urx, pfx##ur, (0mm, -(r)), (-(r), 0mm))
22
23/*
24 * Rectangle with rounded corners.
25 *
26 * pfx is the prefix for all the names generated by this macro. origin is the
27 * lower left corner. w and h are the width and height. r is the radius of the
28 * corners.
29 */
30
31#define RRECT_SETUP(pfx, origin, w, h) \
32    pfx##ll: vec origin(0mm, 0mm); \
33    pfx##lr: vec pfx##ll(w, 0mm); \
34    pfx##ul: vec pfx##ll(0mm, h); \
35    pfx##ur: vec pfx##ll(w, h); \
36
37#define RRECT_DRAW_ARCS(pfx, r) \
38    QLL(pfx, r); \
39    QLR(pfx, r); \
40    QUL(pfx, r); \
41    QUR(pfx, r)
42
43#define RRECT_DRAW_LINES(pfx) \
44    line pfx##llx pfx##lrx; \
45    line pfx##ulx pfx##urx; \
46    line pfx##lly pfx##uly; \
47    line pfx##lry pfx##ury
48
49#define RRECT(pfx, origin, w, h, r) \
50    RRECT_SETUP(pfx, origin, w, h); \
51    RRECT_DRAW_ARCS(pfx, r); \
52    RRECT_DRAW_LINES(pfx)
53
54
55/* ----- Top part ---------------------------------------------------------- */
56
57
58frame top_outline {
59    RRECT(edge_, @, width, length, ro_edge)
60}
61
62frame top_window {
63    loop if = 1, top_window
64
65    set off = topborder+topridge
66
67    frame top_outline @
68
69    win_orig: vec @(off+pcbgap+win_x0, off)
70    RRECT(win_, win_orig, win_x1-win_x0, length-2*off, win_r)
71
72    cmp_orig: vec @(off+pcbgap+cmp_x0, off+pcbgap+cmp_y0)
73    RRECT(cmp_, cmp_orig, cmp_x1-cmp_x0, cmp_y1-cmp_y0, cmp_r)
74}
75
76frame top_pcb {
77    loop if = 1, top_pcb
78
79    set inside = topborder+topridge
80
81    frame top_outline @
82    ro: vec @(topborder, topborder)
83    ri: vec ro(topridge, topridge)
84    RRECT(ridge_i_, ri, width-2*inside, length-2*inside, ri_ridge)
85}
86
87frame top_ridge {
88    loop if = 1, top_ridge
89
90    set inside = topborder+topridge
91
92    ro: vec @(topborder, topborder)
93    RRECT(ridge_o_, ro, width-2*topborder, length-2*topborder, ro_ridge)
94    ri: vec ro(topridge, topridge)
95    RRECT(ridge_i_, ri, width-2*inside, length-2*inside, ri_ridge)
96}
97
98frame top_surface {
99    loop if = 1, top_surface
100
101    frame top_outline @
102}
103
104
105/* ----- Middle part ------------------------------------------------------- */
106
107
108frame mid_rrect_ridge {
109    RRECT_SETUP(edge_, @, width, length);
110        RRECT_DRAW_ARCS(edge_, ro_edge);
111
112    base: vec @(red, red)
113    RRECT_SETUP(ridge_, base, width-2*red, length-2*red);
114        RRECT_DRAW_ARCS(ridge_, r);
115
116    usb_ur: vec edge_ur(-usb_roff, 0mm)
117    usb_ul: vec usb_ur(-usb_w, 0mm)
118    usb_ll: vec usb_ul(0mm, -red)
119    usb_lr: vec usb_ur(0mm, -red)
120
121    line edge_lly edge_uly /* outside */
122    line edge_ulx usb_ul
123    line usb_ul usb_ll /* USB bay */
124    line usb_ll ridge_ulx
125    line ridge_uly ridge_lly /* inside */
126    line ridge_llx ridge_lrx
127    line ridge_lry ridge_ury
128    line ridge_urx usb_lr
129    line usb_lr usb_ur /* USB bay */
130    line usb_ur edge_urx
131    line edge_ury edge_lry /* outside */
132    line edge_lrx edge_llx
133}
134
135
136frame mid_rrect_body {
137    RRECT_SETUP(edge_, @, width, length);
138        RRECT_DRAW_ARCS(edge_, ro_edge);
139
140    usb_ur: vec edge_ur(-usb_roff, 0mm)
141    usb_ul: vec usb_ur(-usb_w, 0mm)
142    usb_ll: vec usb_ul(0mm, -usb_d)
143    usb_lr: vec usb_ur(0mm, -usb_d)
144
145    line edge_llx edge_lrx
146    line edge_ulx usb_ul
147
148    line usb_ul usb_ll /* USB bay */
149    line usb_ll usb_lr
150    line usb_lr usb_ur
151
152    line usb_ur edge_urx
153    line edge_lly edge_uly
154    line edge_lry edge_ury
155}
156
157
158frame mid_ridge {
159    loop if = 1, mid_ridge
160
161    set red = topborder
162    set r = ro_ridge
163    frame mid_rrect_ridge @
164}
165
166
167frame mid_pcb {
168    loop if = 1, mid_pcb
169
170    set red = topborder+topridge
171    set r = ri_ridge
172    frame mid_rrect_ridge @
173}
174
175
176frame post {
177    vec @(r, 0mm)
178    circ @ .
179}
180
181
182frame mid_body {
183    loop if = 1, mid_body
184
185    frame mid_rrect_body @
186
187    bc: vec @(width/2, batt_y)
188    br: vec bc(batt_d/2, 0mm)
189    circ bc br
190
191    set r = post_do/2
192    vec @(post_x, cvr_f+cvr_d+post_y)
193    frame post .
194    vec @(width-post_x, cvr_f+cvr_d+post_y)
195    frame post .
196}
197
198
199/* ----- Bottom part ------------------------------------------------------- */
200
201
202frame bot_rrect {
203    base: vec @(0mm, cvr_f)
204
205    RRECT_SETUP(edge_, base, width, length-cvr_f);
206    QUL(edge_, ro_edge);
207    QUR(edge_, ro_edge);
208
209    set side = (width-cvr_w-2*cvr_play)/2-red
210    cvr_ll: vec edge_ll(side, 0mm)
211    cvr_lr: vec edge_lr(-side, 0mm)
212    cvr_ul: vec cvr_ll(0mm, cvr_d+2*cvr_play+red)
213    cvr_ur: vec cvr_lr(0mm, cvr_d+2*cvr_play+red)
214
215    line edge_ll cvr_ll /* outside */
216
217    QUL(cvr_, cvr_r+red+cvr_play) /* cover bay */
218    QUR(cvr_, cvr_r+red+cvr_play)
219
220    line cvr_ll cvr_uly
221    line cvr_ulx cvr_urx
222    line cvr_ury cvr_lr
223
224    line cvr_lr edge_lr /* outside */
225    line edge_ll edge_uly
226    line edge_lr edge_ury
227    line edge_ulx edge_urx
228}
229
230
231frame bot_posts {
232    loop if = 1, bot_posts
233
234    set r = post_di/2
235    vec @(post_x, cvr_f+cvr_d+post_y)
236    frame post .
237    vec @(width-post_x, cvr_f+cvr_d+post_y)
238    frame post .
239}
240
241
242frame bot_base {
243    loop if = 1, bot_base
244
245    set red = cvr_foot
246    frame bot_rrect @
247}
248
249
250frame bot_surface {
251    loop if = 1, bot_surface
252
253    set red = 0mm
254    frame bot_rrect @
255}
256
257
258/* ----- Main -------------------------------------------------------------- */
259
260
261package "$part-$z"
262unit mm
263
264table
265    { part, z, top_surface, top_window, top_pcb, top_ridge,
266            mid_ridge, mid_pcb, mid_body,
267            bot_posts, bot_base, bot_surface}
268    { "top_surface", 3.3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
269    { "top_window", 2.3, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }
270    { "top_pcb", 1.2, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }
271    { "top_ridge", 0.5, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
272    { "mid_ridge", 0.6, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }
273    { "mid_pcb", 1.2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }
274    { "mid_body", 4.7, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }
275    { "bot_posts", 1.2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }
276    { "bot_base", 2.0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }
277    { "bot_surface", 2.7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
278
279table
280    { pcbw, pcbl, pcbgap }
281    { 20mm, 45mm, 0.2mm }
282
283table
284    /* window position relative to left edge of PCB */
285    { topridge, topborder, win_x0, win_x1, win_r }
286    { 1.0mm, 1.0mm, 1.0mm, 5.0mm, 1.6mm }
287
288table
289    /* component area position relative to lower left corner of PCB */
290    { cmp_x0, cmp_y0, cmp_x1, cmp_y1, cmp_r }
291    { 6.5mm, 1.0mm, 19.5mm, 30.0mm, 2.0mm }
292
293table
294    /* usb_roff = offset from right outer case edge */
295    /* usb_d = 10 mm for prototypes (mini-USB); reduce to 6.0 mm for micro */
296    { usb_w, usb_d, usb_roff }
297    { 8.6mm, 10.0mm, 4.9mm }
298
299table
300    /* post_y is from the edge of the battery bay. post_x is from the edge */
301    { batt_d, batt_y, post_do, post_di, post_y, post_x }
302    { 20.2mm, 12.1mm, 4.1mm, 4.0mm, 5.0mm, 4.5mm }
303
304table
305    { cvr_w, cvr_d, cvr_f, cvr_foot, cvr_play, cvr_r }
306    { 20.0mm, 15.0mm, 5.0mm, 0.8mm, 0.1mm, 2.0mm }
307
308set width = pcbw+2*(pcbgap+topridge+topborder)
309set length = pcbl+2*(pcbgap+topridge+topborder)
310
311set ri_ridge = 2.0mm
312set ro_ridge = ri_ridge+topridge
313
314/*
315 * ro_edge is an outer edge, so we can make the radius smaller than ro_ridge,
316 * for added strength and less fruity esthetics.
317 */
318
319set ro_edge = 1.5mm
320
321frame top_ridge @
322frame top_pcb @
323frame top_window @
324frame top_surface @
325
326frame mid_ridge @
327frame mid_pcb @
328frame mid_body @
329
330frame bot_posts @
331frame bot_base @
332frame bot_surface @
333
334measx top_outline.edge_ul -> top_outline.edge_ur 4mm
335measy top_outline.edge_ll -> top_outline.edge_ul 4mm
336//measx top_pcb.pcb_ul -> top_pcb.pcb_ur 3mm
337//measy top_pcb.pcb_ll -> top_pcb.pcb_ul 3mm
338
339measx top_ridge.ridge_o_ul -> top_ridge.ridge_o_ur 4mm
340measy top_ridge.ridge_o_ll -> top_ridge.ridge_o_ul 4mm
341measx top_ridge.ridge_i_ul -> top_ridge.ridge_i_ur 3mm
342measy top_ridge.ridge_i_ll -> top_ridge.ridge_i_ul 3mm
343
344measy bot_rrect.edge_ll -> bot_rrect.edge_ul 4mm
345measx bot_rrect.edge_ll -> bot_rrect.cvr_ll -3mm
346

Archive Download this file

Branches:
master



interactive