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