// Two-way stackable 3.5" HDD rack
// GPLv3, (c) Vitaliy Filippov, 2018

w = 100;  // HDD width
h = 29;   // HDD height + spacing
hl = 147; // HDD length
l = 25;   // Mount width
fh = 13;  // Fixer height (must be < h/2)
t1 = 5;   // Wall thickness
th = 5;   // Bracket notch thickness
wo = 6;   // Width offset (must be > 5)
sw = 5;   // Stack notch thickness

module mount2() {
    difference() {
        union() {
            translate([-t1-wo,-5,-5]) cube(size=[t1,l,5+h]);
            translate([-t1-wo,-5,-5]) cube(size=[t1*2+w+wo*2,l,5]);
            translate([w+wo,-5,-5]) cube(size=[t1,l,5+h]);
            translate([-t1-wo-sw,l-15,-5]) cube(size=[w+wo*2+sw*2+t1*2,5,5]);
            translate([w,0,0]) cube(size=[wo,5,5]);
            difference() {
                translate([-t1-wo-sw,-5,h-5]) cube(size=[sw,l-5,15]);
                translate([-t1-wo-sw,l-15,h]) cube(size=[sw,l-5,5]);
            }
            difference() {
                translate([w+wo+t1,-5,h-5]) cube(size=[sw,l-5,15]);
                translate([w+wo+t1,l-15,h]) cube(size=[sw,l-5,5]);
            }
            translate([w+wo,-5,h-10]) cube(size=[5+2*sw+2*t1,5,10]);
            translate([w+wo+2*t1+2*sw,-5,h-10]) cube(size=[5,10,10]);
        }
        translate([-t1-wo-1, l-th-10-0.2, h/2-th-0.2]) cube(size=[t1+2,th+0.4,th*2+0.4]);
        translate([w+wo-1, l-th-10-0.2, h/2-th-0.2]) cube(size=[t1+2,th+0.4,th*2+0.4]);
        translate([-wo-t1-sw-1,-5-1,h-10]) cube(size=[wo+t1+sw+2,5+1,10]);
    }
}

module bracket() {
    translate([-wo, l-th-10, h/2-th]) cube(size=[5, hl-2*(l-th-10), th*2]);
    translate([-wo-t1-1, 10, h/2-th]) cube(size=[5+t1+1, th, th*2]);
    translate([-wo-t1-1, hl-2*(l-th-10)+th, h/2-th]) cube(size=[5+t1+1, th, th*2]);
}

module fixer() {
    difference() {
        union() {
            translate([w, -5, 0]) cube(size=[wo, l-10, fh]);
            translate([w-30, -5, 0]) cube(size=[wo+30, 5, fh]);
        }
        translate([w-1, 0, -1]) cube(size=[wo+2, 5+0.2, 6+0.2]);
    }
}

module cover() {
    translate([-t1-wo,-5,-5]) cube(size=[t1*2+w+wo*2,l,5]);
    translate([-t1-wo-sw,l-15,-5]) cube(size=[w+wo*2+sw*2+t1*2,5,5]);
}

module assembly(c) {
    color([0.8,0.6,1]) cube(size=[w,hl,27]);
    color(c) mount2();
    color(c) translate([0,hl,0]) rotate([0, 0, 180]) mirror() mount2();
    color([0.5,1,0.5]) {
        bracket();
        translate([w,hl,0]) rotate([0, 0, 180]) bracket();
    }
    color([0.5,1,1]) {
        fixer();
        translate([0,hl,0]) rotate([0, 0, 180]) mirror() fixer();
    }
}

module covered_assembly(c) {
    assembly(c);
    translate([0, 0, h+5]) {
        cover();
        translate([w,hl,0]) rotate([0, 0, 180]) cover();
    }
}

translate([0, 0, 0]) assembly();
translate([0, 0, h+5]) covered_assembly([0.5,0.5,1]);
translate([-w-2*wo-2*t1-2*sw, 0, 0]) assembly([0.5,0.5,1]);
translate([-w-2*wo-2*t1-2*sw, 0, h+5]) covered_assembly();

//mount2();
//fixer();
//bracket();
//cover();
//mirror() mount2();
//mirror() fixer();
