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