include <dimlines.scad>
include <dimensions.scad>

frontbackheight = bottomtohole + plankthick + holediameter + ( ( nestwidth + ( 2 * plankthick ) ) / 2);
frontbackwidth = nestwidth + ( 2 * plankthick );

module frontback(){
	color("red")
	difference(){
		difference(){
			cube([frontbackheight, frontbackwidth, plankthick]);
			translate([bottomtohole + plankthick + holediameter, 0, -2]){
				rotate([0, 0, -45]) {
				cube([nestwidth + ( 2 * plankthick ), nestwidth + ( 2 * plankthick ),  plankthick + 4]);
				}
			}
		}
		translate([bottomtohole + plankthick + holediameter, frontbackwidth, -2]){
			rotate([0, 0, -45]) {
			cube([nestwidth + ( 2 * plankthick ), nestwidth + ( 2 * plankthick ),  plankthick + 4]);
			}
		}
	}
	
}

module front(){
	difference(){
		frontback();
		translate([bottomtohole + (holediameter / 2), ( frontbackwidth  / 2), -2]){
			cylinder(h = plankthick + 4, d = holediameter, center = false);
		}
	}
	echo("#### Front: height = ", frontbackheight, " width = ", frontbackwidth);
}


module keyhole(){
	translate([0, 0, -2]){
		cylinder(h = plankthick + 4, d = keyholediameter, center = false);
		translate([0, - keyholeslotwidth/2, 0]){
			cube([keyholeslotlength, keyholeslotwidth, plankthick + 4]);
		}
		translate([keyholeslotlength, 0, 0]){
			cylinder(h = plankthick + 4, d = keyholeslotwidth, center = false);
		}
	}
}

module back(){
	difference(){
		frontback();
		translate([bottomtohole + plankthick + holediameter, ( ( nestwidth + ( 2 * plankthick ) ) / 2), 0]){
			keyhole();
		}
	}
	echo("#### Back: height = ", frontbackheight, " width = ", frontbackwidth);
}

module frontdim(){
	front();
	color("black"){
		translate([bottomtohole + (holediameter / 2), frontbackwidth/2, 0])
			circle_center(radius=holediameter/2, size=DIM_HOLE_CENTER,
					line_width=DIM_LINE_WIDTH);

		translate([bottomtohole, frontbackwidth + 10, 0])
			dimensions(length=holediameter);

		translate([0, -10 , 0])
			dimensions(length=bottomtohole + (holediameter / 2));
		translate([0, -20 , 0])
			dimensions(length=frontbackheight - (frontbackwidth/2));
		translate([0, -30 , 0])
			dimensions(length=frontbackheight);

		translate([-10, 0, 0])
			rotate([0,0,90])
			dimensions(length=frontbackwidth);

		translate([0, frontbackwidth + 15, 0])
			drawtext("Front");
	}
}

module backdim(){
	back();
	color("black"){
		translate([bottomtohole + plankthick + holediameter - (keyholediameter/2), frontbackwidth/2, 0])
			circle_center(radius=keyholediameter/2, size=DIM_HOLE_CENTER,
					line_width=DIM_LINE_WIDTH);

		translate([bottomtohole + plankthick + holediameter - (keyholediameter/2) + keyholeslotlength, frontbackwidth/2, 0])
			circle_center(radius=keyholediameter/2, size=DIM_HOLE_CENTER,
					line_width=DIM_LINE_WIDTH);


		translate([0, frontbackwidth + 10, 0])
			dimensions(length=bottomtohole + plankthick + holediameter - (keyholediameter/2));
		translate([bottomtohole + plankthick + holediameter - (keyholediameter/2), frontbackwidth + 10, 0])
			dimensions(length=keyholeslotlength, loc=DIM_RIGHT);

		translate([frontbackheight + 10, (frontbackwidth/2) - (keyholeslotwidth/2), 0])
			rotate([0,0,90])
			dimensions(length=keyholeslotwidth, loc=DIM_OUTSIDE);
		translate([frontbackheight + 20, (frontbackwidth/2) - (keyholediameter/2), 0])
			rotate([0,0,90])
			dimensions(length=keyholediameter, loc=DIM_OUTSIDE);

		translate([0, -10 , 0])
			dimensions(length=frontbackheight - (frontbackwidth/2));
		translate([0, -20 , 0])
			dimensions(length=frontbackheight);

		translate([-10, 0, 0])
			rotate([0,0,90])
			dimensions(length=frontbackwidth);

		translate([0, frontbackwidth + 15, 0])
			drawtext("Back");
	}
}
