include <BOSL2/std.scad>

h = 240;
bot_h = 110;
d = 70;
t = 2;
conn_h = 10;

conn_slop = 0.25;

hex_size = 15;
hex_t = 1.5;

$fn = 360;

module column_hex(w, h, hex_size, t) {
  fwd(50) for(i=[0:1:h/(hex_size+t)]) {
    up(i*(hex_size+t)) left(i%2 * (hex_size+t)/2) union() {
      for (j=[-w:hex_size+t:w]) {
        right(j) rotate([270,90,0]) cylinder(d=hex_size, $fn=6, h=100);
      }
    }
  }
}

union() {
    difference() {
        cyl(d=d, h=h);
        difference() {
            cyl(d=d-t*2, h=h+0.1);
            down(h/2 - bot_h)  difference() {
                cyl(d=d, h=t);
                xrot(90) up(hex_size/4) column_hex(d,d/2,hex_size/2, hex_t);
            }
        }
        left(d/2+0.1) down(h/2+0.1) back(t/2) cube([d+1, d+1, h+1]);
    }

    difference() {
        cuboid([d,t,h]);
        down(h - bot_h) cuboid([d+1,t+1,h]);
        down(h/2 - bot_h) column_hex(d,h-bot_h-1,hex_size,hex_t);
    }
}

left(d*2) union() {
    difference() {
        cyl(d=d, h=h);
        cyl(d=d-t*2, h=h+0.1);
        left(d/2+0.1) down(h/2+0.1) back(t/2) cube([d+1, d+1, h+1]);
    }

    difference() {
        cuboid([d,t,h]);
        //down(h - bot_h) cuboid([d+1,t+1,h]);
        down(h/2) column_hex(d,h-1,hex_size,hex_t);
    }
    
    down(h/2) difference() {
        union() {
            cyl(d=d-t*2 - conn_slop, h=conn_h*2);
            up(conn_h/2) cyl(d=d-t*2, h=conn_h);
            up(conn_h/2) cuboid([d,t,conn_h]);
        }
        difference() {
            cyl(d=d-t*4, h=conn_h*2 + 1);
            fwd(t) cuboid([d,t,conn_h]*2);
        }
        left(d/2+0.1) down(h+0.1) fwd(t/2 + conn_slop) cube([d+1, d+1, h*2+1]);
    }
    down(h/2) up(conn_h/2) fwd(t/2) cuboid([d,t*2,conn_h]);

}