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