Root/bacon/case/case.fpd

Source at commit 24fdda0713df89cbbb9df9e6cf0b6f4c07fee8d6 created 12 years 4 days ago.
By Werner Almesberger, bacon/case/case.fpd: rearranged model of middle part
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 off = topborder+topridge
80
81    frame top_outline @
82    ll: vec @(off, off)
83    RRECT(pcb_, ll, width-2*off, length-2*off, ri_ridge)
84}
85
86frame top_ridge {
87    loop if = 1, top_ridge
88
89    set inside = topborder+topridge
90
91    ro: vec @(topborder, topborder)
92    RRECT(ridge_o_, ro, width-2*topborder, length-2*topborder, ro_ridge)
93    ri: vec ro(topridge, topridge)
94    RRECT(ridge_i_, ri, width-2*inside, length-2*inside, ri_ridge)
95}
96
97frame top_surface {
98    loop if = 1, top_surface
99
100    frame top_outline @
101}
102
103
104/* ----- Middle part ------------------------------------------------------- */
105
106
107frame mid_rrect_ridge {
108    RRECT_SETUP(edge_, @, width, length);
109        RRECT_DRAW_ARCS(edge_, ro_edge);
110
111    base: vec @(red, red)
112    RRECT_SETUP(ridge_, base, width-2*red, length-2*red);
113        RRECT_DRAW_ARCS(ridge_, r);
114
115    usb_ur: vec edge_ur(-usb_roff, 0mm)
116    usb_ul: vec usb_ur(-usb_w, 0mm)
117    usb_ll: vec usb_ul(0mm, -red)
118    usb_lr: vec usb_ur(0mm, -red)
119
120    line edge_lly edge_uly /* outside */
121    line edge_ulx usb_ul
122    line usb_ul usb_ll /* USB bay */
123    line usb_ll ridge_ulx
124    line ridge_uly ridge_lly /* inside */
125    line ridge_llx ridge_lrx
126    line ridge_lry ridge_ury
127    line ridge_urx usb_lr
128    line usb_lr usb_ur /* USB bay */
129    line usb_ur edge_urx
130    line edge_ury edge_lry /* outside */
131    line edge_lrx edge_llx
132}
133
134
135frame mid_rrect_body {
136    RRECT_SETUP(edge_, @, width, length);
137        RRECT_DRAW_ARCS(edge_, ro_edge);
138
139    usb_ur: vec edge_ur(-usb_roff, 0mm)
140    usb_ul: vec usb_ur(-usb_w, 0mm)
141    usb_ll: vec usb_ul(0mm, -usb_d)
142    usb_lr: vec usb_ur(0mm, -usb_d)
143
144    line edge_llx edge_lrx
145    line edge_ulx usb_ul
146
147    line usb_ul usb_ll /* USB bay */
148    line usb_ll usb_lr
149    line usb_lr usb_ur
150
151    line usb_ur edge_urx
152    line edge_lly edge_uly
153    line edge_lry edge_ury
154}
155
156
157frame mid_ridge {
158    loop if = 1, mid_ridge
159
160    set red = topborder
161    set r = ro_ridge
162    frame mid_rrect_ridge @
163}
164
165
166frame mid_pcb {
167    loop if = 1, mid_pcb
168
169    set red = topborder+topridge
170    set r = ri_ridge
171    frame mid_rrect_ridge @
172}
173
174
175frame post {
176    vec @(r, 0mm)
177    circ @ .
178}
179
180
181frame mid_body {
182    loop if = 1, mid_body
183
184    frame mid_rrect_body @
185
186    bc: vec @(width/2, batt_y)
187    br: vec bc(batt_d/2, 0mm)
188    circ bc br
189
190    set r = post_do/2
191    vec @(post_x, cvr_f+cvr_d+post_y)
192    frame post .
193    vec @(width-post_x, cvr_f+cvr_d+post_y)
194    frame post .
195}
196
197
198/* ----- Bottom part ------------------------------------------------------- */
199
200
201frame bot_rrect {
202    base: vec @(0mm, cvr_f)
203
204    RRECT_SETUP(edge_, base, width, length-cvr_f);
205    QUL(edge_, ro_edge);
206    QUR(edge_, ro_edge);
207
208    set side = (width-cvr_w-cvr_play)/2-red
209    cvr_ll: vec edge_ll(side, 0mm)
210    cvr_lr: vec edge_lr(-side, 0mm)
211    cvr_ul: vec cvr_ll(0mm, cvr_d+cvr_play+red)
212    cvr_ur: vec cvr_lr(0mm, cvr_d+cvr_play+red)
213
214    line edge_ll cvr_ll
215
216    line cvr_ll cvr_ul /* cover bay */
217    line cvr_ul cvr_ur
218    line cvr_ur cvr_lr
219
220    line cvr_lr edge_lr
221    line edge_ll edge_uly
222    line edge_lr edge_ury
223    line edge_ulx edge_urx
224}
225
226
227frame bot_posts {
228    loop if = 1, bot_posts
229
230    set r = post_di/2
231    vec @(post_x, cvr_f+cvr_d+post_y)
232    frame post .
233    vec @(width-post_x, cvr_f+cvr_d+post_y)
234    frame post .
235}
236
237
238frame bot_base {
239    loop if = 1, bot_base
240
241    set red = cvr_foot+cvr_play
242    frame bot_rrect @
243}
244
245
246frame bot_surface {
247    loop if = 1, bot_surface
248
249    set red = 0mm
250    frame bot_rrect @
251}
252
253
254/* ----- Main -------------------------------------------------------------- */
255
256
257package "$part-$z"
258unit mm
259
260table
261    { part, z, top_surface, top_window, top_pcb, top_ridge,
262            mid_ridge, mid_pcb, mid_body,
263            bot_posts, bot_base, bot_surface}
264    { "top_surface", 2.5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
265    { "top_window", 1.5, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0 }
266// { "top_pcb", 0.5, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0 }
267    { "top_ridge", 0.5, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 }
268    { "mid_ridge", 0.5, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 }
269    { "mid_pcb", 1.0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0 }
270    { "mid_body", 4.5, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 }
271    { "bot_posts", 1.2, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0 }
272    { "bot_base", 2.0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0 }
273    { "bot_surface", 2.7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
274
275table
276    { pcbw, pcbl, pcbgap }
277    { 20mm, 45mm, 0.2mm }
278
279table
280    /* window position relative to left edge of PCB */
281    { topridge, topborder, win_x0, win_x1, win_r }
282    { 1.0mm, 1.0mm, 1.0mm, 5.0mm, 1.6mm }
283
284table
285    /* component area position relative to lower left corner of PCB */
286    { cmp_x0, cmp_y0, cmp_x1, cmp_y1, cmp_r }
287    { 6.5mm, 1.0mm, 19.5mm, 30.0mm, 2.0mm }
288
289table
290    /* usb_roff = offset from right outer case edge */
291    { usb_w, usb_d, usb_roff }
292    { 8.5mm, 6.0mm, 4.5mm }
293
294table
295    /* post_y is from the edge of the battery bay. post_x is from the edge */
296    { batt_d, batt_y, post_do, post_di, post_y, post_x }
297    { 20.2mm, 12.1mm, 4.1mm, 4.0mm, 5.0mm, 4.5mm }
298
299table
300    { cvr_w, cvr_d, cvr_f, cvr_foot, cvr_play }
301    { 20.0mm, 15.0mm, 5.0mm, 0.8mm, 0.1 mm }
302
303set width = pcbw+2*(pcbgap+topridge+topborder)
304set length = pcbl+2*(pcbgap+topridge+topborder)
305
306set ri_ridge = 2.0mm
307set ro_ridge = ri_ridge+topridge
308
309/*
310 * ro_edge is an outer edge, so we can make the radius smaller than ro_ridge,
311 * for added strength and less fruity esthetics.
312 */
313
314set ro_edge = 1.5mm
315
316frame top_ridge @
317frame top_pcb @
318frame top_window @
319frame top_surface @
320
321frame mid_ridge @
322frame mid_pcb @
323frame mid_body @
324
325frame bot_posts @
326frame bot_base @
327frame bot_surface @
328
329measx top_outline.edge_ul -> top_outline.edge_ur 4mm
330measy top_outline.edge_ll -> top_outline.edge_ul 4mm
331measx top_pcb.pcb_ul -> top_pcb.pcb_ur 3mm
332measy top_pcb.pcb_ll -> top_pcb.pcb_ul 3mm
333
334measx top_ridge.ridge_o_ul -> top_ridge.ridge_o_ur 4mm
335measy top_ridge.ridge_o_ll -> top_ridge.ridge_o_ul 4mm
336measx top_ridge.ridge_i_ul -> top_ridge.ridge_i_ur 3mm
337measy top_ridge.ridge_i_ll -> top_ridge.ridge_i_ul 3mm
338
339measy bot_rrect.edge_ll -> bot_rrect.edge_ul 4mm
340measx bot_rrect.edge_ll -> bot_rrect.cvr_ll -3mm
341

Archive Download this file

Branches:
master



interactive