chiark / gitweb /
sealing-box: Rename some internal things (nfc)
[reprap-play.git] / sealing-box.scad.m4
1 // -*- C -*-
2
3 // This file can be used in two ways:
4 //
5 // A. Rectangular boxes
6 //      1. include <sealing-box.scad>
7 //      2. assign() values to (xxx these should be $ variables)
8 //           ts_xbox (outer dimensions)
9 //           ts_ybox (outer dimension)
10 //           ts_zbox (??? xxx)
11 //           ts_cnrrad (outer radius of corners, leave at default normall)
12 //                 xxx default should be in this file
13 //      3. use the modules
14 //           SealingBox_RectBox
15 //           SealingBox_RectLid
16 //
17 // B. Complicated shapes, but harder work
18 //      1. Be a .m4 file and m4_include sealing-box.scad.m4
19 //      2. Maybe define your own BoxDoShapeRect xxx tbd
20
21 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
22 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
23 m4_define(`Box_Part',`
24   translate([($1),($2)])
25     rotate([0,0,($3)])
26     mirror([($4),0,0])
27     BoxPart_Extrude_$5($6, $7)') m4_dnl
28
29 boxpart_d = 0.01;
30
31 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
32 m4_define(`BoxPart_Extrude_Linear',`
33   rotate([90,0,0])
34     translate([0,0, -($1)])
35     linear_extrude(height= boxpart_d + ($1)) {
36       $2
37     }
38 ')
39
40 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
41 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
42 m4_dnl  y at first and then bending towards negative x, until
43 m4_dnl  use negative x0_radius to inciate bending towards positive x
44 m4_dnl  swept_angle is reached
45 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
46 m4_define(`BoxPart_Extrude_Arc',`
47   translate([-($1),0,0])
48     intersection(){
49       translate([0,0,-500])
50         linear_extrude(height=1000)
51         scale(500)
52         mirror([($1)<0, 0,0])
53         FArcSegment_mask($2);
54       rotate_extrude(convexity=10, $fs=1, $fn=36)
55         mirror([($1)<0, 0,0])
56         translate([+($1),0,0]){
57           $3
58         }
59     }
60 ')
61
62 ts_cidoff = (ts_cnrrad * (1-.7) + wallthick * .8) * [1,1];
63
64 ts_xbox_lin = ts_xbox - ts_cnrrad*2;
65 ts_ybox_lin = ts_ybox - ts_cnrrad*2;
66
67 m4_dnl BoxDoShapeRect(`profile(profileargs)');
68 m4_define(`BoxDoShapeRect',`
69   Box_Part(0,               ts_cnrrad,    0,0, Linear,`ts_ybox_lin', `$1' )
70   Box_Part(0, ts_ybox-ts_cnrrad,          0,0, Arc,`-ts_cnrrad,90' , `$1' )
71   Box_Part(ts_cnrrad,       ts_ybox,    -90,0, Linear,`ts_xbox_lin', `$1' )
72   Box_Part(ts_xbox-ts_cnrrad, ts_ybox,  -90,0, Arc,`-ts_cnrrad,90' , `$1' )
73   Box_Part(ts_xbox, ts_ybox-ts_cnrrad, -180,0, Linear,`ts_ybox_lin', `$1' )
74   Box_Part(ts_xbox,         ts_cnrrad, -180,0, Arc,`-ts_cnrrad,90' , `$1' )
75   Box_Part(ts_xbox-ts_cnrrad, 0,       -270,0, Linear,`ts_xbox_lin', `$1' )
76   Box_Part(ts_cnrrad,         0,       -270,0, Arc,`-ts_cnrrad,90' , `$1' )
77 ')
78
79 m4_dnl '
80
81 module SealingBox_WallProfile(){
82   z = ts_zbox - innertube - tubesealrad;
83   translate([0, -0.1]) square([wallthick, z]);
84   translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
85 }
86
87 module SealingBox_FloorProfile(){
88   mirror([0,1]) square([wallthick, floorth]);
89 }
90
91 module SealingBox_LidProfile(){
92   rad = tubesealrad + innertube;
93   morex = wallthick;
94   difference(){
95     translate([-lidoverlap - innertube,
96                ts_zbox - lidoverhang - innertube])
97       square([lidoverlap + innertube + wallthick,
98               lidoverhang + innertube + ceilth]);
99     hull(){
100       translate([tubesealrad,
101                  ts_zbox - innertube - tubesealrad])
102         for (t=[ [0,0],
103                  [morex*2, 0],
104                  [0, -ts_zbox]
105                  ]) {
106           translate(t)
107             circle(r= tubesealrad + innertube, $fn=20);
108         }
109     }
110   }
111 }
112
113 module SealingBox_CeilProfile(){
114   translate([0, ts_zbox])
115     square([wallthick*2, ceilth]);
116 }
117
118 module TestSealBoxBox(){
119   BoxDoShapeRect(SealingBox_WallProfile(););
120   hull(){ BoxDoShapeRect(SealingBox_FloorProfile();); }
121 }
122
123 module TestSealBoxLid(){ ////toplevel
124   BoxDoShapeRect(SealingBox_LidProfile(););
125   hull(){ BoxDoShapeRect(SealingBox_CeilProfile();); }
126 }