chiark / gitweb /
bike-lipo-box: rotate again so glands are at front for viewing while printing
[reprap-play.git] / sealing-box.scad.m4
index 26697d182fcc64638de9bd1d6cbb2799699146d6..40b4f6492a6ce75a3d503fadf9dc211d859bd686 100644 (file)
@@ -1,5 +1,55 @@
 // -*- C -*-
 
+// This file can be used in two ways:
+//
+// A. Rectangular boxes
+//      1. include <sealing-box.scad>
+//      2. assign() values to (xxx these should be $ variables)
+//           $sealingbox_wallth
+//           $sealingbox_sz[0] (outer dimension)
+//           $sealingbox_sz[1] (outer dimension)
+//           $sealingbox_sz[2] (inner dimension)
+//           $sealingbox_ceilth
+//           $sealingbox_floorth
+//           $sealingbox_wallth
+//      3. use the modules
+//           SealingBox_RectBox
+//           SealingBox_RectLid
+//           (origin is notional outside corner, but at level of
+//            inside of base; box extends to positive x,y,z)
+//
+// B. Complicated shapes, but harder work
+//      1. Be a .m4 file and m4_include sealing-box.scad.m4
+//      2. Define your own BoxDoShapeSomething like BoxDoShapeRect
+//      3. Invoke BoxUseShape
+//      4. Use the Box and Lid modules generated
+//
+// Other settings
+//  $sealingbox_cnrrad
+
+$sealingbox_cnrrad = 10;
+$sealingbox_crude = false;
+
+m4_define(`BoxLocals',`
+  xbox = $sealingbox_sz[0];
+  ybox = $sealingbox_sz[1];
+  zbox = $sealingbox_sz[2];
+  wall = $sealingbox_wallth;
+  floorth = $sealingbox_floorth;
+  ceilth = $sealingbox_ceilth;
+  cnrrad = $sealingbox_cnrrad;
+
+  xbox_lin = xbox - cnrrad*2;
+  ybox_lin = ybox - cnrrad*2;
+')
+
+m4_define(`innertube', `(1.0 + 0.2)')
+m4_define(`lidoverlap', `1.5')
+m4_define(`lidoverhang', `6')
+m4_define(`tubesealrad', `2.0')
+
+m4_define(`BoxFn',`$fn= $sealingbox_crude ? ($2) : ($1)')
+
 m4_dnl Box_Part($1=transl_x,$2=transl_y, $3=rot_z,$4=mirror_xy)
 m4_dnl          $5=kind, $6=kindargs, $7=profile(profileargsargs))
 m4_define(`Box_Part',`
@@ -33,7 +83,7 @@ m4_define(`BoxPart_Extrude_Arc',`
         scale(500)
         mirror([($1)<0, 0,0])
         FArcSegment_mask($2);
-      rotate_extrude(convexity=10, $fs=1, $fn=36)
+      rotate_extrude(convexity=10, $fs=1, BoxFn(36,8))
         mirror([($1)<0, 0,0])
         translate([+($1),0,0]){
           $3
@@ -41,68 +91,77 @@ m4_define(`BoxPart_Extrude_Arc',`
     }
 ')
 
-ts_cidoff = (ts_cnrrad * (1-.7) + wallthick * .8) * [1,1];
-
-ts_xbox_lin = ts_xbox - ts_cnrrad*2;
-ts_ybox_lin = ts_ybox - ts_cnrrad*2;
-
-m4_dnl TestSealDoBoxShape(`profile(profileargs)');
-m4_define(`TestSealDoBoxShape',`
-  Box_Part(0,               ts_cnrrad,    0,0, Linear,`ts_ybox_lin', `$1' )
-  Box_Part(0, ts_ybox-ts_cnrrad,          0,0, Arc,`-ts_cnrrad,90' , `$1' )
-  Box_Part(ts_cnrrad,       ts_ybox,    -90,0, Linear,`ts_xbox_lin', `$1' )
-  Box_Part(ts_xbox-ts_cnrrad, ts_ybox,  -90,0, Arc,`-ts_cnrrad,90' , `$1' )
-  Box_Part(ts_xbox, ts_ybox-ts_cnrrad, -180,0, Linear,`ts_ybox_lin', `$1' )
-  Box_Part(ts_xbox,         ts_cnrrad, -180,0, Arc,`-ts_cnrrad,90' , `$1' )
-  Box_Part(ts_xbox-ts_cnrrad, 0,       -270,0, Linear,`ts_xbox_lin', `$1' )
-  Box_Part(ts_cnrrad,         0,       -270,0, Arc,`-ts_cnrrad,90' , `$1' )
+m4_dnl BoxDoShapeRect(`profile(profileargs)');
+m4_define(`BoxDoShapeRect',`
+  Box_Part(0,           cnrrad,         0,0, Linear,`ybox_lin', `$1' )
+  Box_Part(0,           ybox-cnrrad,    0,0, Arc,`-cnrrad,90' , `$1' )
+  Box_Part(cnrrad,      ybox,         -90,0, Linear,`xbox_lin', `$1' )
+  Box_Part(xbox-cnrrad, ybox,         -90,0, Arc,`-cnrrad,90' , `$1' )
+  Box_Part(xbox,        ybox-cnrrad, -180,0, Linear,`ybox_lin', `$1' )
+  Box_Part(xbox,        cnrrad,      -180,0, Arc,`-cnrrad,90' , `$1' )
+  Box_Part(xbox-cnrrad, 0,           -270,0, Linear,`xbox_lin', `$1' )
+  Box_Part(cnrrad,      0,           -270,0, Arc,`-cnrrad,90' , `$1' )
 ')
 
 m4_dnl '
 
-module WallProfile(){
-  z = ts_zbox - innertube - tubesealrad;
-  translate([0, -0.1]) square([wallthick, z]);
-  translate([tubesealrad, z]) circle(r=tubesealrad, $fn=20);
+module SealingBox_WallProfile(){
+  BoxLocals
+  z = zbox - innertube - tubesealrad;
+  translate([0, -0.1]) square([wall, z]);
+  translate([tubesealrad, z]) circle(r=tubesealrad, BoxFn(20,6));
 }
 
-module FloorProfile(){
-  mirror([0,1]) square([wallthick, floorth]);
+module SealingBox_FloorProfile(){
+  BoxLocals
+  mirror([0,1]) square([wall, floorth]);
 }
 
-module LidProfile(){
+function SealingBox_lidbigger() = lidoverlap + innertube;
+
+module SealingBox_LidProfile(){
+  BoxLocals
   rad = tubesealrad + innertube;
-  morex = wallthick;
+  morex = wall;
   difference(){
-    translate([-lidoverlap - innertube,
-              ts_zbox - lidoverhang - innertube])
-      square([lidoverlap + innertube + wallthick,
+    translate([-SealingBox_lidbigger(),
+              zbox - lidoverhang - innertube])
+      square([lidoverlap + innertube + wall,
              lidoverhang + innertube + ceilth]);
     hull(){
       translate([tubesealrad,
-                ts_zbox - innertube - tubesealrad])
+                zbox - innertube - tubesealrad])
        for (t=[ [0,0],
                 [morex*2, 0],
-                [0, -ts_zbox]
+                [0, -zbox]
                 ]) {
          translate(t)
-           circle(r= tubesealrad + innertube, $fn=20);
+           circle(r= tubesealrad + innertube, BoxFn(20,6));
        }
     }
   }
 }
 
-module CeilProfile(){
-  translate([0, ts_zbox])
-    square([wallthick*2, ceilth]);
+module SealingBox_CeilProfile(){
+  BoxLocals
+  translate([0, zbox])
+    square([wall*2, ceilth]);
 }
 
-module TestSealBoxBox(){
-  TestSealDoBoxShape(WallProfile(););
-  hull(){ TestSealDoBoxShape(FloorProfile();); }
-}
+// BoxDoShape(Basename,BoxDoShapeSomething)
+// generates modules BasenameBox and BasenameLid
+m4_define(`BoxUseShape',`
+  module $1Box(){
+    BoxLocals
+    $2(SealingBox_WallProfile(););
+    hull(){ $2(SealingBox_FloorProfile();); }
+  }
 
-module TestSealBoxLid(){ ////toplevel
-  TestSealDoBoxShape(LidProfile(););
-  hull(){ TestSealDoBoxShape(CeilProfile();); }
-}
+  module $1Lid(){
+    BoxLocals
+    $2(SealingBox_LidProfile(););
+    hull(){ $2(SealingBox_CeilProfile();); }
+  }
+')
+
+BoxUseShape(`SealingBox_Rect',`BoxDoShapeRect')