chiark / gitweb /
dbfb220f9519b7535a4ec66f16a40ce6d588b30b
[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 //           $sealingbox_wallth
9 //           $sealingbox_sz[0] (outer dimension)
10 //           $sealingbox_sz[1] (outer dimension)
11 //           $sealingbox_sz[2] (inner dimension)
12 //           $sealingbox_ceilth
13 //           $sealingbox_floorth
14 //           $sealingbox_wallth
15 //      3. use the modules
16 //           SealingBox_RectBox
17 //           SealingBox_RectLid
18 //           (origin is notional outside corner, but at level of
19 //            inside of base; box extends to positive x,y,z)
20 //
21 // B. Complicated shapes, but harder work
22 //      1. Be a .m4 file and m4_include sealing-box.scad.m4
23 //      2. Define your own BoxDoShapeSomething like BoxDoShapeRect
24 //      3. Invoke BoxUseShape
25 //      4. Use the Box and Lid modules generated
26 //
27 // Other settings
28 //  $sealingbox_cnrrad
29
30 $sealingbox_cnrrad = 10;
31 $sealingbox_crude = false;
32 $sealingbox_inner_slop = 0.2;
33
34 m4_define(`BoxLocals',`
35   xbox = $sealingbox_sz[0];
36   ybox = $sealingbox_sz[1];
37   zbox = $sealingbox_sz[2];
38   wall = $sealingbox_wallth;
39   floorth = $sealingbox_floorth;
40   ceilth = $sealingbox_ceilth;
41   cnrrad = $sealingbox_cnrrad;
42
43   xbox_lin = xbox - cnrrad*2;
44   ybox_lin = ybox - cnrrad*2;
45 ')
46
47 m4_define(`innertube', `(1.0 + 0.2)')
48 m4_define(`lidoverlap', `1.5')
49 m4_define(`lidoverhang', `6')
50 m4_define(`tubesealrad', `2.0')
51
52 m4_define(`BoxFn',`$fn= $sealingbox_crude ? ($2) : ($1)')
53
54 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
55 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
56 m4_define(`Box_Part',`
57   translate([($1),($2)])
58     rotate([0,0,($3)])
59     mirror([($4),0,0])
60     BoxPart_Extrude_$5($6, $7)') m4_dnl
61
62 boxpart_d = 0.01;
63
64 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
65 m4_define(`BoxPart_Extrude_Linear',`
66   rotate([90,0,0])
67     translate([0,0, -($1)])
68     linear_extrude(height= boxpart_d + ($1)) {
69       $2
70     }
71 ')
72
73 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
74 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
75 m4_dnl  y at first and then bending towards negative x, until
76 m4_dnl  use negative x0_radius to inciate bending towards positive x
77 m4_dnl  swept_angle is reached
78 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
79 m4_define(`BoxPart_Extrude_Arc',`
80   translate([-($1),0,0])
81     intersection(){
82       translate([0,0,-500])
83         linear_extrude(height=1000)
84         scale(500)
85         mirror([($1)<0, 0,0])
86         FArcSegment_mask($2);
87       rotate_extrude(convexity=10, $fs=1, BoxFn(36,8))
88         mirror([($1)<0, 0,0])
89         translate([+($1),0,0]){
90           $3
91         }
92     }
93 ')
94
95 m4_dnl BoxDoShapeRect(`profile(profileargs)');
96 m4_define(`BoxDoShapeRect',`
97   Box_Part(0,           cnrrad,         0,0, Linear,`ybox_lin', `$1' )
98   Box_Part(0,           ybox-cnrrad,    0,0, Arc,`-cnrrad,90' , `$1' )
99   Box_Part(cnrrad,      ybox,         -90,0, Linear,`xbox_lin', `$1' )
100   Box_Part(xbox-cnrrad, ybox,         -90,0, Arc,`-cnrrad,90' , `$1' )
101   Box_Part(xbox,        ybox-cnrrad, -180,0, Linear,`ybox_lin', `$1' )
102   Box_Part(xbox,        cnrrad,      -180,0, Arc,`-cnrrad,90' , `$1' )
103   Box_Part(xbox-cnrrad, 0,           -270,0, Linear,`xbox_lin', `$1' )
104   Box_Part(cnrrad,      0,           -270,0, Arc,`-cnrrad,90' , `$1' )
105 ')
106
107 m4_dnl '
108
109 module SealingBox_WallProfile(){
110   BoxLocals
111   z = zbox - innertube - tubesealrad;
112   translate([0, -0.1]) square([wall, z]);
113   translate([tubesealrad, z]) circle(r=tubesealrad, BoxFn(20,6));
114 }
115
116 module SealingBox_FloorProfile(){
117   BoxLocals
118   mirror([0,1]) square([wall, floorth]);
119 }
120
121 function SealingBox_lidbigger() = lidoverlap + innertube;
122
123 module SealingBox_LidProfile(){
124   BoxLocals
125   rad = tubesealrad + innertube;
126   morex = wall;
127   inner_buttress_h = tubesealrad*1.5 + innertube + ceilth;
128
129   difference(){
130     translate([0, zbox + ceilth]) mirror([0,1]) {
131       translate([-SealingBox_lidbigger(),
132                  0])
133       square([lidoverlap + innertube + tubesealrad,
134               lidoverhang + innertube + ceilth]);
135       square([tubesealrad*2 + innertube + lidoverlap,
136               inner_buttress_h]);
137     }
138     hull(){
139       translate([tubesealrad,
140                  zbox - innertube - tubesealrad])
141         for (t=[ [0,0],
142                  [0, -zbox]
143                  ]) {
144           translate(t)
145             circle(r= tubesealrad + innertube, BoxFn(20,6));
146         }
147     }
148   }
149   translate([tubesealrad*2 + $sealingbox_inner_slop,
150              zbox + ceilth]) {
151     mirror([0,1]) {
152       square([lidoverlap + innertube,
153               inner_buttress_h]);
154     }
155   }
156 }
157
158 module SealingBox_CeilProfile(){
159   BoxLocals
160   translate([0, zbox])
161     square([wall*2, ceilth]);
162 }
163
164 // BoxDoShape(Basename,BoxDoShapeSomething)
165 // generates modules BasenameBox and BasenameLid
166 m4_define(`BoxUseShape',`
167   module $1Box(){
168     BoxLocals
169     $2(SealingBox_WallProfile(););
170     hull(){ $2(SealingBox_FloorProfile();); }
171   }
172
173   module $1Lid(){
174     BoxLocals
175     $2(SealingBox_LidProfile(););
176     hull(){ $2(SealingBox_CeilProfile();); }
177   }
178 ')
179
180 BoxUseShape(`SealingBox_Rect',`BoxDoShapeRect')