// -*- C -*-
-// xxx
-bolt_above = 4;
-wall_thick = 4;
-bolthole_height = 4;
-bolthole_width = 10;
-base_thick = 5;
-lidinner_thick_allow = 20;
+// xxx from actual ksafe, needs slop adding
+bolt_above = 14.30;
+bolthole_height = 4.24;
+wall_thick = 4.50;
+bolthole_width = 16.62;
+main_sz = 150.56;
+cnr_rad = 13.5; // approx
+lidinner_thick_allow = 20.78;
+
+// other parameters
+web_thick = 4;
+web_height = 20; // excluding wall and base thick
+bolthole_rhs = 20;
+bolthole_lhs = 20;
+boltreinf_thick = 6;
+anchor_wall_space = 25;
+base_thick = 4;
space = 25;
anchor_thick = 4;
anchor_rad = 4;
-minbevel = space/2;
+bevel = 8;
+
+// ----- calculated -----
+
+hsz = main_sz/2;
+
+gppA = [0,0];
+gppB = gppA - [ wall_thick, 0 ];
+
+gppL = [ gppB[0], -(lidinner_thick_allow + space + base_thick) ];
+
+yw1 = -web_thick/2;
+yw2 = yw1 - bolthole_rhs;
+yw3 = yw2 - anchor_thick;
+yw4 = yw3 - anchor_wall_space;
+yw5 = yw4 - wall_thick;
+yw6 = -(hsz - cnr_rad + 0.1);
-// calculated
+yw10 = web_thick/2;
+yw11 = yw2 + anchor_wall_space;
+yw12 = yw11 + wall_thick;
+yw13 = -yw6;
-uppA = [0,0];
-uppB = uppA - [ wall_thick, 0 ];
+// anchor
-uppL = [ uppB[0], -(lidinner_thick_allow + space + base_thick) ];
anchor_b = anchor_thick + anchor_rad;
-uppM = uppL + anchor_b * [1,1];
+appM = gppL + anchor_b * [1,1];
+
+a_bevel = 2 * anchor_b * (1 + sqrt(0.5));
+
+module upp_app_Vars(t_bevel){
+ $xppE = gppL + t_bevel * [0,1];
+ $xppF = gppL + t_bevel * [1,0];
+
+ $xppJ = $xppE + wall_thick * [ 1, tan(22.5) ];
+ $xppI = $xppF + base_thick * [ tan(22.5), 1 ];
+
+ // must pass a_bevel for t_bevel for these to be valid
+ $gppP = gppA + [0,-1] * lidinner_thick_allow;
+ $gppQ = $gppP + [1,-1] * web_height;
+ $gppR = $xppJ + [ 1, tan(22.5) ] * web_height;
+ $gppS = $xppI + [ tan(22.5), 1 ] * web_height;
+ $gppT = [ $gppQ[0], $xppE[1] ];
+
+ children();
+}
-bevel = max(minbevel, 2 * anchor_b * (1 + sqrt(0.5)));
-uppE = uppL + bevel * [0,1];
-uppF = uppL + bevel * [1,0];
+module upp_app_Profile(){
+ polygon([ gppA,
+ gppB,
+ $xppE,
+ $xppF,
+ $xppF + [1,0],
+ $xppI + [1,0],
+ $xppJ ],
+ convexity=10);
+}
-uppJ = uppE + wall_thick * [ 1, tan(22.5) ];
-uppI = uppF + base_thick + [ tan(22.5), 1 ];
-uppH = upp
module UsualProfile(){
-
+ upp_app_Vars(bevel) upp_app_Profile();
+}
+
+module NearAnchorProfile(){
+ upp_app_Vars(a_bevel) upp_app_Profile();
+}
+
+module AnchorProfile(){
+ upp_app_Vars(a_bevel) {
+
+ upp_app_Profile();
+
+ difference(){
+ hull(){
+ polygon([ $xppE,
+ $xppF,
+ $xppF + [0,1],
+ $xppE + [1,0] ],
+ convexity=10);
+ translate(appM) circle(r= anchor_b);
+ }
+ translate(appM) circle(r= anchor_rad);
+ }
+ }
+}
+
+module AnchorWallProfile(){
+ UsualProfile();
+ NearAnchorProfile();
+ hull(){
+ for (bev = [bevel, a_bevel]) {
+ upp_app_Vars(bev) {
+ polygon([ $xppE,
+ $xppF,
+ $xppI,
+ $xppJ ],
+ convexity=10);
+ }
+ }
+ }
+}
+
+module WebProfile(){
+ upp_app_Vars(a_bevel){
+ if ($gppR[1] <= $gppP[1]) {
+ polygon([ $gppP,
+ $xppE,
+ $gppT,
+ $gppQ ]);
+ polygon([ $gppP,
+ $xppE,
+ $xppF,
+ $gppS,
+ $gppR ],
+ convexity=10);
+ } else {
+ polygon([ $gppP,
+ $xppE,
+ $xppF,
+ $gppS,
+ $gppP + web_height * [1,0] ],
+ convexity=10);
+ }
+ polygon([ $gppS,
+ $xppF,
+ $xppF + [1,0],
+ $gppS + [1,0] ],
+ convexity=10);
+ }
+}
+
+module SWalls(ymin, ymax, t_bevel) {
+ upp_app_Vars(t_bevel) {
+ translate([0,ymin,0])
+// rotate([90,0,0])
+mirror([0,1,0])
+ rotate([90,0,0])
+ linear_extrude(height= ymax-ymin, convexity=10)
+ children();
+ }
+}
+
+module KsafeBase(){
+ /// corners
+ for (xm=[0,1]) for (ym=[0,1]) {
+ mirror([xm,0,0]) mirror([0,ym,0])
+ translate((hsz - cnr_rad) * [1,1])
+ intersection(){
+ rotate_extrude(convexity=10)
+ translate([-cnr_rad,0])
+ UsualProfile();
+ translate([0,0,-250])
+ cube([50,50,500]);
+ }
+ }
+
+ // side walls
+ for (xm=[0,1]) {
+ mirror([xm,0,0]){
+ translate([-hsz, 0,0]){
+ SWalls(yw6 , yw4 , bevel ) UsualProfile();
+ SWalls(yw5 , yw4 , a_bevel) AnchorWallProfile();
+ SWalls(yw5 , yw12, a_bevel) NearAnchorProfile();
+ SWalls(yw3 , yw2 , a_bevel) AnchorProfile();
+ SWalls(yw11, yw12, a_bevel) AnchorWallProfile();
+ SWalls(yw11, yw13, bevel ) UsualProfile();
+ }
+ }
+ }
+}
+
+module DemoProfiles(){
+ translate([0,0,-2]) color("yellow") AnchorWallProfile();
+ color("red") AnchorProfile();
+ translate([0,0,2]) color("black") NearAnchorProfile();
+ translate([0,0,4]) color("blue") UsualProfile();
+ translate([0,0,-4]) color("pink") WebProfile();
+}
+
+//DemoProfiles();
+KsafeBase();