/* [Teil] */
Teil = 1; // [1:Überblick, 2:Basisblock, 3:Klemmblock_fest, 4:Klemmblock_Rippen, 5:Klemmblock_Variabel]
Klemmblock_Position = 150; // [150:1:280]
Klemmblock_Hoehe = 70; // [50:1:90]

/* [Hidden] */
$fn = 45;
Delta = 0.005;
Block = [300,120,23];
Rippe = [3,120,2]; // x,y,z
Rippen = [44, 6];
Raster = 80;
Nutenstein = [8, 16]; // 8mm wegen der Hammer-Muttern.
Schraube = [6.5, 20, 3]; // Schaft, Kopf, Tiefe
Schulter=5;
Langloch = [40,260];
Steigung=5;

module Basisblock() {
	difference() {
		// Block mit Rippen
		union() {
			cube([Block.x, Block.y, Block.z]);
			color("Red") translate([0,0,Block.z]) {
				for (i=[1:1:Rippen[0]]) translate([Block.x-(2*i-1)*Rippe.x, 0, 0]) cube(Rippe);
				// Rippe
				translate([10,0,0]) cube([5,Block.y,Rippe.z]);
			}
		}
		
		
		// Bohrungen und Langlöcher
		for (i=[(Block.y-Raster)/2, (Block.y+Raster)/2]) translate([0,i,-Delta]) union() {
			union() {
				// M6 Gewinde
				color("Blue") translate([10+5,0,0]) cylinder(d=5, h=Block.z+Rippe.z+1); 
				// Am Ende je ein einzelnes Loch für Verankerung
				color("Orange") translate([285,0,0]) {
					cylinder(d=Schraube[0], h=Block.z+5);
					translate([0,0,Block.z-Schraube[2]]) cylinder(d=Schraube[1], h=Schraube[2]+1+Rippe.z);
				}
				color("Orange") {
					// Innen für M6 Schraube
					hull() { for (i=Langloch) translate([i,0,0]) cylinder(d=Schraube[0], h=Block.z+5); }
					// 8mm unten Schulter vom Nutenstein
					hull() { for (i=[Langloch[0]-Nutenstein[1]/2, Langloch[1]+Nutenstein[1]/2]) translate([i,0,0]) cylinder(d=Nutenstein[0], h=7); }
					// 16mm unten Nutenstein Breite
					hull() { for (i=[Langloch[0]-Nutenstein[1]/2, Langloch[1]+Nutenstein[1]/2]) translate([i,0,0]) cylinder(d=Nutenstein[1], h=5); }
					// Oben für Schraubenkopf
					translate([0,0,Block.z-Schraube[2]]) hull() { for (i=Langloch) translate([i,0,0]) cylinder(d=Schraube[1], h=Schraube[2]+1+Rippe.z); }
				}
			}
		}
	}
}

module Klemmblock_Variabel_Rippen() {
	Breite_unten = Rippe.x*2*Rippen[1];
	difference() {
		union() {
			hull() {
				translate([0,0,Block.z-1]) cube([Breite_unten, Block.y, 1]);
				translate([Steigung,0,0]) cube([Breite_unten-2*Steigung, Block.y, Delta]);
			}
			color("Red") translate([0,0,Block.z]) for (i=[1:1:Rippen[1]]) translate([Breite_unten-(2*i-1)*Rippe.x, 0, 0]) cube(Rippe);
		}
		color("Blue") for (i=[(Block.y-Raster)/2, (Block.y+Raster)/2]) translate([0,i,-Delta]) union() {
			translate([Breite_unten/2,0,0]) union() {
				cylinder(d=Schraube[0], h=Block.z+Rippe.z+1); 
				cylinder(d=Schraube[1], h=5); 
			}
		}
	}
}

module Klemmblock_Variabel() {
	Breite_unten = 30;
	difference() {
		union() {
			hull() {
				translate([0,0,Block.z]) cube([Breite_unten-Steigung, Block.y, Delta]);
				cube([Breite_unten, Block.y, 1]);
			}
		}
		color("Blue") for (i=[(Block.y-Raster)/2, (Block.y+Raster)/2]) translate([0,i,-Delta]) union() {
			translate([25/2,0,0]) union() {
				cylinder(d=Schraube[0], h=Block.z+Rippe.z+1); 
				cylinder(d=Schraube[1], h=5); 
			}
		}
    translate([0,Block.y/2,-Delta]) cylinder(d=2*Schulter, h=Block.z+Rippe.z+Delta, $fn=4);
	}
}

module Klemmblock_Fest() {
	difference() {
		cube([35, Block.y, Block.z+Rippe.z]);
		color("Red") translate([10,-Delta,Block.z]) cube([5,Block.y+2*Delta,Rippe.z+Delta]);
		color("Blue") for (i=[(Block.y-Raster)/2, (Block.y+Raster)/2]) translate([0,i,-Delta]) union() {
			translate([10+5,0,0]) union() {
				cylinder(d=Schraube[0], h=Block.z+Rippe.z+1); 
				cylinder(d=Schraube[1], h=5); 
			}
		}
    color("Orange") translate([35-Schulter+Delta,-Delta,-Delta]) cube([Schulter,Block.y+2*Delta,3+Delta]);
    translate([35,Block.y/2,0]) cylinder(d=2*Schulter, h=Block.z+Rippe.z+Delta, $fn=4);
	}
}

// Datei öffnen und Customizer anzeigen, dann Teil auswählen, F6 und STL Export:

if (Teil == 1) {
  Basisblock();
  translate([Klemmblock_Position,0,55]) rotate([0,180,0]) Klemmblock_Variabel_Rippen();
  translate([90,120,Klemmblock_Hoehe]) rotate([180,0,0]) Klemmblock_Variabel();
  translate([0,120,55]) rotate([180,0,0]) Klemmblock_Fest();
}
if (Teil == 2) Basisblock();
if (Teil == 3) Klemmblock_Fest();
if (Teil == 4) Klemmblock_Variabel_Rippen();
if (Teil == 5) Klemmblock_Variabel();

