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