chiark / gitweb /
poster-tube-lid: WallMountBase prep
[reprap-play.git] / poster-tube-lid.scad
1 // -*- C -*-
2
3 // Print, for each end:
4 //
5 //   CoverPrint
6 //   StrapMount
7 //   CatchAssembly
8
9 include <funcs.scad>
10 include <utils.scad>
11
12 coarse = false;
13 enable_head_cups = false;
14
15 main_dia = 71.2 + 0.50 - 2.26;
16 top_thick_middle = 4;
17 top_thick_by_oring = 3.0;
18 top_middle_dr = 11;
19
20 main_cnr = 6.0;
21
22 min_wall = 3;
23
24 rivet_posn = 6.0 + 0.30;
25 rivet_thick = 1.67;
26 rivet_width = 4.15 + 1.0;
27 rivet_tall = 5.51 + 1.49;
28
29 over_rivet_wall = 1.0;
30 side_rivet_gap = 1.5;
31 inside_rivet_gap = 1.5;
32
33 bayo_interf = 0.30;
34 bayo_behind = 8.5;
35 bayo_interf_width = 2.0;
36 bayo_interf_slope = 0.5;
37
38 oring_thick = 5.0;
39 oring_bore = 62.0;
40
41 oring_upper_embed_angle = 80;
42 oring_compress = 0.1; // proportion
43 oring_compress_more = 0.2;
44
45 oring_rm_beside = 8;
46 oring_rm_scale = 2.0;
47 oring_rm_angle = 20;
48
49 side_taper = 1.0;
50
51 bayo_gap = 6.0;
52
53 bayo_entry = 1.167;
54 bayo_inramp = 0.9;
55
56 bayo_slice_size = coarse ? 5 : 1;
57
58 brace_hole_width = 1.0;
59 brace_above_below = 1.2;
60 brace_end_shorter = 0.3;
61
62 jig_thick = 1.4;
63 jig_hole_dia = 3.0;
64 jig_rim = 5;
65 jig_mark = 5;
66
67 strap_loop_thick = 6;
68 strap_loop_inside = 10;
69 strap_loop_strlen = 10;
70 strap_loop_elevation = 45;
71
72 sm_inner_circum = 218 - 1.90 - 1.00 - 0.50;
73 sm_main_thick = 2.0;
74 sm_main_width = 20;
75
76 sm_bolt_dia = 3.5 + 0.1;
77 sm_bolt_shaft = 21.0;
78 sm_bolt_head_dia = 6.94 + 1.0;
79 sm_bolt_head_thick = 2.14;
80 sm_bolt_nut_width = 5.89 + 0.25;
81 sm_bolt_nut_thick = 3.68;
82 sm_bolt_tighten_allow = 2.0;
83
84 sm_bolt_y_clear = 0.75;
85 sm_bolt_y_over = 0.5;
86
87 sm_closure_cnr = 3.0;
88
89 wm_thick = 5;
90 wm_screw_dia = 4.5; // XXX
91 wm_screwdriver_dia = 6.0; // XXX
92 wm_screw_around = 4.0; // XXX
93 wm_screw_slot = 3.5;
94 wm_screw_head = 7.5; // XXX
95
96 wmb_screw_dia = 5;
97 wmb_screw_head_dia = 10; // XXX
98 wmb_screw_around_x = 4; // XXX
99 wmb_screw_around_z = 6; // XXX
100 wmb_screw_depth_min = 10;
101 web_screw_len = 18; // XXX
102 wmb_nut_across = 8; // XXX
103 wmb_nut_around_min = 2; // XXX
104 wmb_nut_behind_min = 5;
105 wmb_nut_th = 4; // XXX
106 wmb_ring_gap = 1.0;
107
108 catch_stalk_h = 4.5;
109 catch_stalk_len = 50;
110 catch_tip_th = 4;
111 catch_head_th = 3;
112
113 catch_pin_slop = 0.25; // each side, and above
114 catch_pin_slop_x_extra = 0.0; // only on one side
115 catch_stalk_above_gap = 1.5;
116 catch_stalk_eff_bend_rad = catch_stalk_len * 0.75;
117
118 catch_strap_width = 12;
119 catch_stalk_base_width = 15;
120
121 catch_knob_dia = 6;
122 catch_knob_above_gap = 5;
123 catch_knob_height = 3.0;
124
125 catch_stalk_below_gap = 1.0;
126 catch_stalk_beside_gap = 2.0;
127
128 // calculated
129
130 TAU = PI*2;
131
132 bayo_entry_x = bayo_entry;
133 bayo_entry_z = bayo_entry;
134 bayo_inramp_x = bayo_inramp;
135 bayo_inramp_z = bayo_inramp;
136
137 oring_mid_dia = oring_bore + oring_thick;
138 oring_outer_dia = oring_mid_dia + oring_thick;
139
140 oring_oblate = (1 - oring_compress);
141
142 oring_y_rad = oring_thick/2 * oring_oblate;
143 oring_x_rad = oring_thick/2 / oring_oblate;
144
145 by_oring_z = oring_y_rad * (1 + cos(oring_upper_embed_angle));
146
147 side_height = rivet_posn + bayo_behind + rivet_thick/2;
148 side_thick = rivet_tall + over_rivet_wall;
149
150 top_z = top_thick_by_oring + oring_y_rad + by_oring_z;
151
152 middle_bot_z = top_z - top_thick_middle;
153
154 bayo_top_z = bayo_behind + bayo_gap;
155
156 bayo_nom_rad = main_dia/2 + side_thick;
157 bayo_real_rad = main_dia/2 + rivet_tall;
158
159 rivet_entry_width = rivet_width + side_rivet_gap;
160
161 jig_mark_rad = jig_mark + main_dia/2 + jig_thick;
162
163 handling_dia = oring_bore + oring_thick*2 + min_wall*2;
164 handling_angle = 45;
165
166 sm_inner_rad = (sm_inner_circum + sm_bolt_tighten_allow/2) / TAU;
167 sm_outer_rad = sm_inner_rad + sm_main_thick;
168
169 wm_main_width = sm_main_width;
170 wm_y_min = sqrt( pow(sm_inner_rad, 2) -
171                  pow(sm_inner_rad - (wm_thick - sm_main_thick), 2) );
172 wm_y_screw = wm_y_min + wm_screw_around + wm_screw_dia/2;
173 wm_y_max = wm_y_screw + wm_screw_dia/2 + wm_screw_around;
174 wm_y_slotc_screw = wm_y_screw + wm_screw_slot/2;
175 wm_y_slot1_screw = wm_y_screw + wm_screw_slot;
176 wm_y_slot1_max = wm_y_max + wm_screw_slot;
177 wm_z_slot0_screw = wm_main_width + wm_screwdriver_dia/2;
178 wm_z_slotc_screw = wm_z_slot0_screw + wm_screw_slot/2;
179 wm_z_slot1_screw = wm_z_slot0_screw + wm_screw_slot;
180 wm_z_max = wm_z_slot1_screw + wm_screw_around;
181
182 wmb_mount_cut_rad = sm_outer_rad + wmb_ring_gap;
183 wmb_nut_rad = wmb_nut_across / cos(30) * 0.5;
184 wmb_x_screw_plus_around_r = max(
185                                 wmb_screw_around_x + wmb_screw_dia/2,
186                                 wmb_nut_around_min + wmb_nut_across/2
187                                 );
188 wmb_x_screw = -sm_outer_rad + wmb_x_screw_plus_around_r;
189 wmb_x_outer = -sm_outer_rad + wmb_x_screw_plus_around_r * 2;
190 function wmb_screw_thing_y_min(dia) = sqrt(
191                        pow(wmb_mount_cut_rad, 2) -
192                        pow(wmb_x_screw + dia/2, 2)
193                        );
194 wmb_y_screw_end = wmb_screw_thing_y_min(wmb_screw_dia);
195 wmb_y_nut_min = wmb_screw_thing_y_min(wmb_nut_across + wmb_nut_around_min*2);
196 wmb_y_mount_max = max(
197                       wmb_y_nut_min + wmb_nut_th + wmb_nut_behind_min,
198                       wmb_y_screw_end + wmb_screw_depth_min
199                       );
200 wmb_z_screw = max(
201                   wmb_screw_around_z + wmb_screw_dia/2,
202                   wmb_nut_around_min + wmb_nut_rad
203                   );
204 wmb_z_max = wmb_z_screw * 2;
205
206 smc_pos = [ 0, sm_inner_rad, 0 ];
207
208 smc_bolt_nut_dia = sm_bolt_nut_width / cos(30);
209 smc_bolt_nut_eff_thick = sm_bolt_nut_thick + sm_bolt_tighten_allow;
210
211 smc_bolt_y = sm_bolt_dia/2 + sm_bolt_y_clear;
212 smc_max_y = smc_bolt_y + sm_bolt_y_over
213   + max(sm_bolt_head_dia/2, smc_bolt_nut_dia/2);
214 smc_cnr_c_x = sm_bolt_shaft/2 - sm_closure_cnr
215   + sm_bolt_head_thick/2 + smc_bolt_nut_eff_thick/2;
216
217 catch_cr = catch_knob_dia/2 + catch_stalk_beside_gap;
218 catch_strap_thick = sm_main_thick;
219
220 echo("R ", sm_inner_rad, bayo_real_rad, bayo_nom_rad);
221
222 $fs= coarse ? 2.5 : 0.5;
223 $fa= coarse ? 5 : 1;
224
225 include <poster-tube-lid-parametric.scad>
226
227 // bayonet definition
228
229 bayo_a = [ bayo_entry_x, 0 ];
230 bayo_p = [ 0, bayo_entry_z ];
231 bayo_n = [ 0, bayo_behind-bayo_inramp_z ];
232 bayo_m = [ bayo_inramp_x, bayo_behind ];
233 bayo_l = bayo_m + bayo_interf * [ 1/bayo_interf_slope,  1 ];
234 bayo_k = bayo_l + [ bayo_interf_width, 0 ];
235 bayo_j = bayo_k + bayo_interf * [ 1/bayo_interf_slope, -1 ];
236 bayo_i = bayo_j + [ rivet_width + inside_rivet_gap, 0 ];
237 bayo_h = [ bayo_i[0], bayo_behind + bayo_gap + bayo_interf ];
238 bayo_g = [ bayo_m[0] - rivet_width, bayo_h[1] ];
239
240 bayo_e = [-bayo_p[0], bayo_p[1]] - [rivet_entry_width,0];
241 bayo_d = [-bayo_a[0], bayo_a[1]] - [rivet_entry_width,0];
242 bayo_c = bayo_d + [0,-5];
243 bayo_b = bayo_a + [0,-5];
244
245 bayo_f = [ bayo_e[0], bayo_g[1] + (bayo_e[0] - bayo_g[0]) ];
246
247 bayo_polygon = [ bayo_a,
248                  bayo_b,
249                  bayo_c,
250                  bayo_d,
251                  bayo_e,
252                  bayo_f,
253                  bayo_g,
254                  bayo_h,
255                  bayo_i,
256                  bayo_j,
257                  bayo_k,
258                  bayo_l,
259                  bayo_m,
260                  bayo_n,
261                  bayo_p ];
262
263 echo(bayo_polygon);
264
265 // CATCH
266
267 cppxC = 0.41 * sm_inner_rad * TAU;
268
269 // catch pin
270
271 cpp_adj = (bayo_n[0] - bayo_f[0]) * (1 - sm_inner_rad / bayo_nom_rad);
272 // radius scaling due to nom and actual radius difference in
273 // bayo entry construction
274
275 cppa = bayo_f + [1,-1] * catch_pin_slop + [1,0] * cpp_adj;
276 cppb = bayo_g + [1,-1] * catch_pin_slop + [1,0] * cpp_adj;
277 cppd = [ bayo_n[0]
278          - catch_pin_slop - catch_pin_slop_x_extra,
279          -catch_stalk_above_gap ];
280 cppi = [ cppa[0], cppd[1] ];
281 cppc = [ cppd[0], cppb[1] ];
282 cpph = cppd + [0,-1] * catch_stalk_h;
283 cppe = cppd + [0,-1] * (catch_knob_above_gap + catch_knob_dia/2);
284 cppf = [ cppa[0], cppe[1] ];
285 cppg = [ cppa[0], cpph[1] ];
286 cppB = 0.5 * (cppf + cppe);
287
288 echo("RR", sm_inner_rad / bayo_nom_rad);
289
290 // catch assembly depression below pin
291
292 cppy6 = cppB[1] - (catch_knob_dia/2
293                    + (cppc[1] - cppd[1])
294                    + catch_stalk_below_gap);
295 cpp7 = [ cppB[0], cppy6 + catch_cr ];
296 cpp11 = cpp7 + [1,0] * catch_cr;
297 cppy9 = cppy6 + catch_strap_width * 1/3;
298 cpp9 = [ cpp7[0] + catch_cr * 2, cppy9 ];
299 cpp8 = cpp9 + [0,-1] * catch_cr;
300 cpp10 = cpp8 + [-1,0] * catch_cr;
301 cppC = [ cppxC, cpp9[1] ];
302 cppD = cppC + [0,-1] * catch_strap_width;
303
304 // catch assembly stalk and so on
305
306 catch_cr3 = catch_cr + catch_stalk_h;
307
308 cppF = [ cppg[0] - catch_stalk_eff_bend_rad, cppd[1] ];
309 cpp4 = [ cppg[0] - catch_stalk_len, cpph[1] ] + [1,-1] * catch_cr;
310 cpp5 = [ cpp4[0], cppC[1] + catch_cr ];
311 cpp2 = cpp5 + [-1,0] * (catch_cr * 2 + catch_stalk_base_width);
312 cpp2r = cpp2 + [1,0] * catch_cr;
313 cpp2d = cpp2 + [0,-1] * catch_cr;
314 cpp3 = [ cpp2[0] + catch_cr + catch_cr3, cppd[1] - catch_cr3 ];
315 cppA = [ -cppxC, cpp9[1] ];
316 cppE = [ cppA[0], cppD[1] ];
317
318 catch_assembly_dy = -cppy9 + catch_strap_width;
319
320
321 module MainProfile(){
322   main_cnr_pos = [ side_thick, top_z ] - [1,1]*main_cnr;
323   difference(){
324     union(){
325       translate(main_cnr_pos){
326         intersection(){
327           difference(){
328             circle(r = main_cnr);
329             circle(r = main_cnr * 0.5);
330           }
331           square([10,10]);
332         }
333       }
334       polygon([[ -top_middle_dr,        middle_bot_z      ],
335                [ -top_middle_dr,        top_z             ],
336                [ main_cnr_pos[0],       top_z             ],
337                [ side_thick,            main_cnr_pos[1]   ],
338                [ side_thick,            -side_height      ],
339                [ side_taper,            -side_height      ],
340                [ 0,                     -rivet_posn       ],
341                [ 0,                     by_oring_z        ],
342                [ -oring_x_rad,          by_oring_z        ],
343                ],
344               convexity=10);
345     }
346     translate([ oring_mid_dia/2 - main_dia/2, 0 ])
347       hull(){
348       translate([ 0, oring_y_rad ])
349         scale([ 1/oring_oblate * (oring_compress_more+1) , oring_oblate ])
350         circle(oring_thick/2);
351       translate([ 0, oring_y_rad*2 - oring_thick/2 ])
352         circle(oring_thick/2);
353     }
354   }
355 }
356
357 module StrapLoopProfile(){
358   circle(r = strap_loop_thick/2);
359 }
360
361 module StrapLoop(){ ////toplevel
362   bigrad = strap_loop_inside/2 + strap_loop_thick/2;
363   extralen = strap_loop_thick * 5;
364
365   intersection(){
366     rotate([strap_loop_elevation, 0,0]){
367       for (x= [ -1, +1 ] * bigrad) {
368         translate([x, -extralen, 0])
369           rotate([-90,0,0])
370           linear_extrude(height= extralen + strap_loop_strlen + 0.1,
371                          convexity=10)
372           StrapLoopProfile();
373       }
374       translate([0, strap_loop_strlen, 0]){
375         intersection(){
376           rotate_extrude(convexity=10)
377             translate([bigrad, 0,0])
378             StrapLoopProfile();
379           translate([0,50,0])
380             cube([100,100,100], center=true);
381         }
382       }
383     }
384     translate([0, 50, 0])
385       cube(100, center=true);
386   }
387 }
388
389 module RotateProjectSlice(offset, slice_size, nom_rad, real_rad){
390   // nom_rad > real_rad
391   rotate([0,0, atan2(offset, nom_rad) ]){
392     intersection(){
393       translate([-offset, -10, 0])
394         rotate([90,0,0])
395         linear_extrude(height= nom_rad*2, convexity=50)
396         children(0);
397       translate([0,0, -25])
398         cylinder(h=50, r= real_rad);
399       translate([0,0, -25])
400         linear_extrude(height= 50, convexity=50)
401         polygon([ [ 0,0 ],
402                   [ -slice_size, -real_rad*2 ],
403                   [ +slice_size, -real_rad*2 ] ]);
404     }
405   }
406 }
407
408 module RotateProject(x_min, x_max, slice_size, nom_rad, real_rad){
409   offs = [ for (i=[ x_min :
410                     slice_size :
411                     x_max + slice_size ]) i ];
412   echo (offs);
413   for (off=offs)
414     RotateProjectSlice(off, slice_size, nom_rad, real_rad)
415     children(0);
416 }
417
418 module BayonetCutout(){
419   RotateProject(bayo_c[0], bayo_i[0], bayo_slice_size,
420                 bayo_nom_rad, 
421                 bayo_real_rad)
422     translate([-0.5 * (bayo_a[0] + bayo_d[0]), 0])
423     polygon(bayo_polygon, convexity=10);
424 }
425
426 module ProfilesDemo(){ ////toplevel
427   translate([-10,0]) MainProfile();
428   translate([+10, -side_height]) polygon(bayo_polygon, convexity=10);
429 }
430
431 module LimitForHandling(){ ////toplevel
432   hull() for (r=[0,180])
433     rotate([0,0,r]) {
434       for (rs=[-1,+1]) {
435         for (xd=[0,1]) {
436           rotate([0,0, rs * handling_angle/2]) {
437             translate([rs * xd * main_dia/2 * tan(handling_angle/2),
438                        main_dia/2 + side_thick - main_cnr,
439                        top_z - main_cnr]) {
440               mirror([0,0,1])
441                 cylinder(r= main_cnr, h=50);
442               sphere(main_cnr);
443             }
444           }
445         }
446       } 
447     }
448   hull() rotate_extrude(convexity=10){
449     translate([ handling_dia/2 - main_cnr, top_z - main_cnr ]) {
450       circle(r = main_cnr);
451       mirror([0,1]) square([ main_cnr, 50 ]);
452     }
453   }
454   //cylinder(r= handling_dia/2, h=20);
455 }
456
457 module Cover(){ ////toplevel
458   render() difference(){
459     intersection(){
460       union(){
461         rotate_extrude(convexity=10)
462           translate([main_dia/2, 0])
463           MainProfile();
464         translate([0,0, middle_bot_z])
465           cylinder(h= top_thick_middle, r = main_dia/2 - top_middle_dr + 1);
466       }
467       LimitForHandling();
468     }
469     for (r=[0,180]){
470       rotate([0,0, r])
471         translate([0,0, -side_height])
472         BayonetCutout();
473       rotate([0,0, r + asin((-oring_rm_beside) / (main_dia/2))])
474         translate([0,
475                    oring_mid_dia/2 + oring_thick/4 * oring_rm_scale,
476                    oring_y_rad * 1.5])
477         rotate([-oring_rm_angle, 0, 0])
478         mirror([0,0,1])
479         cylinder(r = oring_thick/4 * oring_rm_scale, h=20);
480     }
481     for (r=[0 : 60 : 179]) {
482       rotate([0,0, r]) {
483         height = top_thick_middle - brace_above_below*2;
484         translate([0,0, middle_bot_z + brace_above_below + height/2 ])
485         cube(center=true, [ oring_bore - brace_end_shorter,
486                             brace_hole_width, height ]);
487       }
488     }
489   }
490   if (enable_head_cups)
491     for (r=[0,180])
492       rotate([0,0,r])
493         translate([-implheadcup_large_dia * .5 - implheadcup_thick/2,
494                    -implheadcup_large_dia * .0,
495                    middle_bot_z + 0.1])
496         ImplHeadCup();
497
498 //  translate(strap_loop_thick * [-0.5, 0, +1])
499 //    translate([handling_dia/2, 0, -side_height])
500 //    rotate([0,180,0]) rotate([0,0,90])
501 //    StrapLoop();
502 }
503
504 module SavingHole(){
505   translate([0,0, -10])
506     cylinder(r= main_dia/2 - jig_rim, h=20);
507 }
508
509 module Jig(){ ////toplevel
510   difference(){
511     union(){
512       translate([0,0, -side_height]){
513         cylinder(r= main_dia/2 + jig_thick, h= side_height + jig_thick);
514       }
515       translate([-jig_mark_rad, 0, jig_thick - jig_mark])
516         cube([jig_mark_rad*2, jig_mark, jig_mark]);
517     }
518     translate([0,0, -side_height-1])
519       cylinder(r= main_dia/2, h= side_height + 1);
520     SavingHole();
521     translate([0,0, -rivet_posn])
522       rotate([90, 0,0])
523       translate([0,0, -100])
524       cylinder(r= jig_hole_dia/2, h = 200);
525   }
526 }
527
528 module CoverPrint(){ ////toplevel
529   rotate([0,180,0]) Cover();
530 }
531
532 module CoverTest2(){ ////toplevel
533   difference(){
534     Cover();
535     SavingHole();
536   }
537 }
538
539 module CoverTest1(){ ////toplevel
540   difference(){
541     CoverTest2();
542     difference(){
543       for (r= [ 40, 147 ]){
544         rotate([0,0, r]){
545           translate([0,0, -10]) {
546             cube([ main_dia*3, main_dia * .53, 18], center=true);
547           }
548         }
549       }
550 //      translate([ 50, 0, 0 ])
551 //      cube([ 100,
552 //             strap_loop_inside + strap_loop_thick*2 + 1,
553 //             100 ],
554 //           center=true);
555     }
556   }
557 }
558
559 module ImplHeadCupTest(){ ////toplevel
560   for (r=[0,180])
561     rotate([0,0,r])
562       translate([-17,0,0])
563       ImplHeadCup();
564 }
565
566 module SomeStrap(width, cut_width=0){
567   // children(0) is to add, (1) subtract
568   difference(){
569     union(){
570       cylinder(r=sm_outer_rad, h=width);
571       StrapMountProtrusion(smc_cnr_c_x + sm_closure_cnr,
572                            smc_max_y,
573                            sm_closure_cnr,
574                            width);
575       children(0);
576     }
577     translate([0,0,-1])
578       cylinder(r=sm_inner_rad, h=max(width+2, cut_width));
579     translate(smc_pos)
580       StrapMountBolt(10, width);
581     translate(smc_pos)
582       cube([ sm_bolt_tighten_allow, 40,100 ], center=true);
583     children(1);
584   }
585 }
586
587 module StrapMountBolt(l_delta, strap_width){ ///toplevel
588   // positioned relative to smc_pos
589   translate([(smc_bolt_nut_eff_thick - sm_bolt_head_thick)/2,
590              smc_bolt_y,
591              strap_width/2]){
592     translate([ -sm_bolt_shaft/2-1, 0,0 ]){
593       rotate([0,90,0]) cylinder(r= sm_bolt_dia/2, h= sm_bolt_shaft+2);
594     }
595     translate([ -sm_bolt_shaft/2, 0,0 ])
596       rotate([0,-90,0])
597       cylinder($fn=6, r=smc_bolt_nut_dia/2,
598                h=smc_bolt_nut_eff_thick + l_delta);
599     translate([ sm_bolt_shaft/2, 0,0 ])
600       rotate([0,90,0])
601       cylinder(r=sm_bolt_head_dia/2, h=sm_bolt_head_thick + l_delta);
602   }
603 }
604
605 module StrapMountProtrusion(half_x, max_y, cnr, width){
606   translate(smc_pos){
607     linear_extrude(height=width, convexity=10){
608       hull(){
609         for (m = [0,1]) mirror([m,0,0]) {
610           translate([-(half_x - cnr), max_y - cnr])
611             circle(r=cnr);
612           translate([-half_x, -sm_inner_rad])
613             square([1,1]);
614         }
615       }
616     }
617   }
618 }
619
620 module StrapMount(){ ////toplevel
621   SomeStrap(sm_main_width){
622     rotate([0,0,180]){
623       StrapMountProtrusion(strap_loop_inside/2 + strap_loop_thick,
624                            strap_loop_thick,
625                            sm_closure_cnr,
626                            sm_main_width);
627       translate(smc_pos +
628                 [0,0, sm_main_width] +
629                 strap_loop_thick * [ 0, 0.5, -1.0 ])
630         StrapLoop();
631     }
632     union(){ };
633   }
634 }
635
636 module WallScrewHoleSlot(){ ////toplevel
637   ds = [-1,+1] * wm_screw_slot/2;
638   linextr_x_yz(-(wm_thick + 1), 1) {
639     hull(){
640       for (d = ds)
641         translate([d, 0])
642           circle(r = wm_screw_dia/2);
643     }
644   }
645   hull(){
646     for (d = ds){
647       translate([0, d, 0]){
648         linextr_x_yz(0, 1)
649           circle(r = wm_screw_head/2);
650         linextr_x_yz(-(wm_screw_head - wm_screw_dia)/2, 0)
651           circle(r = wm_screw_dia/2);
652       }
653     }
654   }
655 }
656
657 module WallMountMounts(){
658   linextr(0, wm_z_max){
659     translate([ -sm_outer_rad, 0 ])
660       rectfromto([ 0, -wm_y_max ],
661                  [ wm_thick, wm_y_slot1_max ]);
662   }
663 }
664 module WallMountScrewHoles(){
665   translate([ -sm_outer_rad + wm_thick, 0, wm_z_slotc_screw]) {
666     translate([ 0, wm_y_slotc_screw, 0 ])
667       WallScrewHoleSlot();
668     translate([ 0, -wm_y_slotc_screw, 0 ])
669       rotate([90,0,0])
670       WallScrewHoleSlot();
671   }
672 }
673
674 module WallMount(){ ////toplevel
675   SomeStrap(sm_main_width, wm_z_max + 2){
676     WallMountMounts();
677     WallMountScrewHoles();
678   }
679 }
680
681 module WallMountBaseMounts(){
682   linextr(0, wmb_z_max) {
683     difference(){
684       rectfromto([ -sm_outer_rad,            -wmb_y_mount_max ],
685                  [ wmb_x_outer, +wmb_y_mount_max ]);
686       circle(r = wmb_mount_cut_rad);
687     }
688   }
689 }
690
691 // screws, nuts, slots for nuts to go down into
692 module WallMountBaseScrewsEtc(){ ////toplevel
693   for (my=[0,1]) {
694     mirror([0, my, 0]) {
695       translate([wmb_x_screw, 0, wmb_z_screw]) {
696         linextr_y_xz(wmb_y_screw_end,
697                      wmb_y_screw_end + 100) // XXX change 100
698           circle(r = wmb_screw_dia/2);
699         linextr_y_xz(wmb_y_screw_end + web_screw_len,
700                      wmb_y_screw_end + 100) // XXX change 100
701           circle(r = wmb_screw_head_dia/2);
702         linextr_y_xz(wmb_y_nut_min,
703                      wmb_y_nut_min + wmb_nut_th){
704           hull(){
705             rotate(30)
706               circle(r = wmb_nut_rad, $fn = 6);
707             translate([0, 100]) // XXX change 100
708               square(wmb_nut_across, center=true);
709           }
710         }
711       }
712     }
713   }
714 }
715
716 module WallMountForBase(){ ////toplevel
717   SomeStrap(sm_main_width, wm_z_max + 2){
718     union(){
719       WallMountMounts();
720       WallMountBaseMounts();
721     }
722     union(){
723       WallMountScrewHoles();
724       WallMountBaseScrewsEtc();
725     }
726   }
727 }
728
729 module WallMountForBaseDemo(){ ////toplevel
730   WallMountForBase();
731   %WallMountBaseScrewsEtc();
732 }
733
734 module CatchAssemblyCoreProfile(){
735   difference(){
736     union(){
737       hull(){
738         translate(cpp3) circle(r= catch_cr3);
739         polygon([ cpp3,
740                   cpp2r,
741                   cpp5,
742                   cpph,
743                   cppd
744                   ]);
745       }
746       polygon([cppD,
747                cppC,
748                cpp9,
749                cpp10,
750                cpp11,
751                cpp4,
752                cpp2r,
753                cpp2d,
754                cppA,
755                cppE
756                ]);
757       translate(cpp8) circle(r= catch_cr);
758     }
759     hull(){
760       translate(cpp4) circle(r= catch_cr);
761       translate(cpp5) circle(r= catch_cr);
762       translate(cpp7) circle(r= catch_cr);
763       polygon([cpp4,
764                cppg,
765                cpph,
766                cpp10,
767                cpp11,
768                ]);
769     }
770     translate(cpp2) circle(r= catch_cr);
771   }
772   // if cpp11 is above cpp10, the subtracted hull above
773   // can go down too far.  Ensure we do not cut off below cppy6.
774   polygon([ cppE,
775             cppD,
776             cpp9,
777             [ cpp9[0],            cppy6 ],
778             [ cpp7[0] - catch_cr, cppy6 ],
779             cpp2d
780             ]);
781 }
782
783 module CatchTipProfile(dy){
784   ddy = [0,dy];
785   intersection(){
786     translate(cppF){
787       difference(){
788 //      circle(r = dist2d(cppF, cppd));
789         //circle(r = dist2d(cppF, cppa));
790       }
791     }
792     polygon([ cppa,
793               cppi + ddy,
794               cppd + ddy,
795               cppc,
796               cppb ]);
797   }
798 }
799
800 module CatchHeadProfile(){
801   polygon([ cppd,
802             cppd,
803             cppi,
804             cppf,
805             cppe,
806             cpph ]);
807 }
808
809
810 module CatchCore(){ /////toplevel
811   linear_extrude(height=catch_strap_thick, convexity=10)
812     CatchAssemblyCoreProfile();
813
814   hull(){
815     linear_extrude(height=catch_head_th, convexity=10)
816       CatchTipProfile(0);
817     linear_extrude(height=catch_tip_th, convexity=10)
818       CatchTipProfile(catch_tip_th - catch_head_th);
819   }
820
821   linear_extrude(height=catch_head_th, convexity=10)
822     CatchHeadProfile();
823
824   translate(concat(cppB,[0])) hull(){
825     translate([0,0, catch_knob_height + catch_head_th - catch_knob_dia/2])
826       sphere(r = catch_knob_dia/2);
827     cylinder(r = catch_knob_dia/2, h = 0.1);
828   }
829 }
830
831 module CatchPreDistort(){ /////toplevel
832   scale(100 / sm_inner_rad)
833     rotate([90,0,0])
834     CatchCore();
835 }
836
837 module CatchAssembly(){ /////toplevel
838   rotate([0,0, -(cppe[0] + cppB[0] + catch_pin_slop) / sm_inner_rad * 360/TAU])
839     translate([0,0, catch_assembly_dy])
840     scale(sm_inner_rad / 100)
841     import(str("poster-tube-lid,CatchPostDistort-fa",
842                (coarse ? 20 : 3),
843                ".stl"),
844            convexity=20);
845
846   SomeStrap(catch_strap_width){
847     union(){ }
848     union(){
849       translate([-200, -200, -200])
850         cube([400, 200, 400]);
851     }
852   }
853 }
854
855 module CatchDemo(){ /////toplevel
856   color("blue") translate([0,0,
857                            -catch_assembly_dy
858              ])
859     CatchAssembly();
860   translate([0,0,+side_height
861              ])
862     Cover();
863 }
864
865 module CatchDemoS(){ /////toplevel
866   color("blue") translate([0,0,
867              -catch_assembly_dy
868              ])
869     CatchAssembly();
870   intersection(){
871     translate([0,0,+side_height
872                ])
873       Cover();
874     mirror([0,1,0]) translate([-250,33,0]) cube([500,500,500]);
875   }
876   color("black")
877     translate([0,-33,0])
878     cube([6.15, 2,2], center=true);
879 }
880
881 module CatchPinProfileDemo(){ /////toplevel
882   translate([0, 0 * -bayo_behind,0]) {
883     echo("G ",
884          bayo_n[0] - bayo_e[0]);
885     color("blue") translate([0,0,
886                              +1,
887                ]) {
888       CatchAssemblyCoreProfile();
889       CatchHeadProfile();
890     }
891     translate([0,0,10])
892       color("red")
893       CatchTipProfile(0);
894
895     polygon(bayo_polygon, convexity=10);
896
897     // adhoc show a position
898     color("purple")
899     translate(concat(
900                      cppa,
901                      10
902                      )) difference(){ circle(2.5); circle(2.0); }
903
904  }
905 }
906
907 //ProfilesDemo();
908 //BayonetCutout();
909 //MainProfile();
910 //Cover();
911 //Jig();
912 //CoverTest();