// by zeus - zeus@ctdo.de - CC-BY-NC-4.00
// -> https://www.thingiverse.com/zeus
// -> https://www.printables.com/social/366928-zeus/about
// -> https://github.com/zeus86
// -> https://blog.tastatursport.de/
// 2023-03-14
// Wallmount for Cables in the style of a pipeclamp
//##################
// 
//
//##################
//
// VARS
mt=4;               // general material thickness
slack=0.5;          // added slack to inner dimensions to allow easier fitment
width=20+slack;     // outer width + slack
height=37.5+slack;    // outer height + slack
depth=40+slack;     // outer depth + slack
tab_l=(width-2*mt);            // width of the cutout for the cabletie
tab_h=2;            // height of the cutout for the cabletie
cut_d=(depth-2*mt); // diameter of cutout for the cables
$fn=100;            // general resolution
q=0.01;             // used to avoid graphical glitches
holedia=4.5;        // diameter of the hole for the screw
rounding_eyeball=3; // not very scientific, add arbitrary amount to refine rounding.
//
//##################
//
// MODEL

module base(){
    difference(){
            // base body
            translate([0,0,height/2])cube([width,depth,height],center=true);
            // primary cutout
            translate([0,0,height]){
                hull(){                
                    translate([0,0,-mt*2])rotate([0,90,0])cylinder(d=cut_d,h=width+q,center=true);
                    translate([0,0,-height+cut_d/2+mt])rotate([0,90,0])cylinder(d=cut_d,h=width+q,center=true);
                }
            }
            // cable-tie slit
            translate([0,0,height-(mt*1.5)])cube([tab_l,depth+q,tab_h],center=true);
            // screwhole
            translate([0,0,mt-q]){
                cylinder(d=holedia,h=mt*2,center=true);
                translate([0,0,0])cylinder(d1=0,d2=holedia*3.14,h=mt*2,center=true);
            }
            //cylinder(d1=holedia,d2=holedia*2,h=height,center=true);

    }
};

module rounding(){
    rotate([0,90,0]){
        cylinder(d=depth+mt+rounding_eyeball,h=width+q,center=true,$fn=500);
    }
}

intersection(){
    translate([0,0,-height/2])base();
    rounding();
}