chiark / gitweb /
31f7f65a1bd06c5fb905d96953f5e080d201d033
[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
32 m4_define(`BoxLocals',`
33   xbox = $sealingbox_sz[0];
34   ybox = $sealingbox_sz[1];
35   zbox = $sealingbox_sz[2];
36   wall = $sealingbox_wallth;
37   floorth = $sealingbox_floorth;
38   ceilth = $sealingbox_ceilth;
39   cnrrad = $sealingbox_cnrrad;
40
41   xbox_lin = xbox - cnrrad*2;
42   ybox_lin = ybox - cnrrad*2;
43
44   innertube = 1.0 + 0.2;
45   lidoverlap = 1.5;
46   lidoverhang = 6;
47   tubesealrad = 2.0;
48 ')
49
50 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
51 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
52 m4_define(`Box_Part',`
53   translate([($1),($2)])
54     rotate([0,0,($3)])
55     mirror([($4),0,0])
56     BoxPart_Extrude_$5($6, $7)') m4_dnl
57
58 boxpart_d = 0.01;
59
60 m4_dnl BoxPart_Extrude_Linear(dist, `profile(...);');
61 m4_define(`BoxPart_Extrude_Linear',`
62   rotate([90,0,0])
63     translate([0,0, -($1)])
64     linear_extrude(height= boxpart_d + ($1)) {
65       $2
66     }
67 ')
68
69 m4_dnl BoxPart_Extrude_Arc(x0_radius, swept_angle, `profile(...);')
70 m4_dnl  arc starting at transl_x, transl_y, moving towards positive
71 m4_dnl  y at first and then bending towards negative x, until
72 m4_dnl  use negative x0_radius to inciate bending towards positive x
73 m4_dnl  swept_angle is reached
74 m4_dnl  x0_radius is the radius of the extruded part at x=0, not of the box
75 m4_define(`BoxPart_Extrude_Arc',`
76   translate([-($1),0,0])
77     intersection(){
78       translate([0,0,-500])
79         linear_extrude(height=1000)
80         scale(500)
81         mirror([($1)<0, 0,0])
82         FArcSegment_mask($2);
83       rotate_extrude(convexity=10, $fs=1, $fn=36)
84         mirror([($1)<0, 0,0])
85         translate([+($1),0,0]){
86           $3
87         }
88     }
89 ')
90
91 m4_dnl BoxDoShapeRect(`profile(profileargs)');
92 m4_define(`BoxDoShapeRect',`
93   Box_Part(0,           cnrrad,         0,0, Linear,`ybox_lin', `$1' )
94   Box_Part(0,           ybox-cnrrad,    0,0, Arc,`-cnrrad,90' , `$1' )
95   Box_Part(cnrrad,      ybox,         -90,0, Linear,`xbox_lin', `$1' )
96   Box_Part(xbox-cnrrad, ybox,         -90,0, Arc,`-cnrrad,90' , `$1' )
97   Box_Part(xbox,        ybox-cnrrad, -180,0, Linear,`ybox_lin', `$1' )
98   Box_Part(xbox,        cnrrad,      -180,0, Arc,`-cnrrad,90' , `$1' )
99   Box_Part(xbox-cnrrad, 0,           -270,0, Linear,`xbox_lin', `$1' )
100   Box_Part(cnrrad,      0,           -270,0, Arc,`-cnrrad,90' , `$1' )
101 ')
102
103 m4_dnl '
104
105 module SealingBox_WallProfile(){
106   BoxLocals
107   z = zbox - innertube - tubesealrad;
108   translate([0, -0.1]) square([wall, z]);
109   translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
110 }
111
112 module SealingBox_FloorProfile(){
113   BoxLocals
114   mirror([0,1]) square([wall, floorth]);
115 }
116
117 module SealingBox_LidProfile(){
118   BoxLocals
119   rad = tubesealrad + innertube;
120   morex = wall;
121   difference(){
122     translate([-lidoverlap - innertube,
123                zbox - lidoverhang - innertube])
124       square([lidoverlap + innertube + wall,
125               lidoverhang + innertube + ceilth]);
126     hull(){
127       translate([tubesealrad,
128                  zbox - innertube - tubesealrad])
129         for (t=[ [0,0],
130                  [morex*2, 0],
131                  [0, -zbox]
132                  ]) {
133           translate(t)
134             circle(r= tubesealrad + innertube, $fn=20);
135         }
136     }
137   }
138 }
139
140 module SealingBox_CeilProfile(){
141   BoxLocals
142   translate([0, zbox])
143     square([wall*2, ceilth]);
144 }
145
146 // BoxDoShape(Basename,BoxDoShapeSomething)
147 // generates modules BasenameBox and BasenameLid
148 m4_define(`BoxUseShape',`
149   module $1Box(){
150     BoxLocals
151     $2(SealingBox_WallProfile(););
152     hull(){ $2(SealingBox_FloorProfile();); }
153   }
154
155   module $1Lid(){
156     BoxLocals
157     $2(SealingBox_LidProfile(););
158     hull(){ $2(SealingBox_CeilProfile();); }
159   }
160 ')
161
162 BoxUseShape(`SealingBox_Rect',`BoxDoShapeRect')