include <stanley1992.scad>
include <MCAD-master/bearing.scad>
include <MCAD-master/materials.scad>
$fn=150; 


srewHoleClearence = 4;
M3Hole = 3.1;
M3Thread = 2.8;
srcewDepth = 10;
 
 bottomThikcness =5;
 
bearindId = 8; 
bearingOd = 22; 
beragingWidth = 7;
bearingCount = 9;
beragingTotalWidth = beragingWidth*bearingCount;



sideX = bearingOd + 19/2;
sideY = 5; 
sideZ = bearingOd + bottomThikcness+10;
sideHoleOffsetX = 5; 
sideHoleOffsetZ = -5; 
bearingResess = 1;
sideWidth = sideY + bearingResess; 

shatfLenght = bearingCount*beragingWidth+2*sideWidth+0.01;


  
bladeWall = 2;
srcrewWall = 0.5;
bladeEdgeResses = 3;
cutterX = stanley1992_Width + 2 * bladeWall;
cutterY = stanley1992_Height+bladeWall-bladeEdgeResses; 
cutterZ = stanley1992_Thickness+bladeWall; 
cutterSrewBotY = bladeEdgeResses+4;
cutterSrewBotX = 4.5;
cutterSrewTopY = cutterY - 2;
cutterSrewTopX = 10;



 //splitter(); 
 module splitter()
 {
    color(Stainless)translate([0,-cutterX/2,bearingOd/2+2])rotate([0,0,90])cutter();
    bearings();
    %translate([-sideHoleOffsetX,-beragingTotalWidth/2-bearingResess-sideY/2,-sideHoleOffsetZ])side();
     translate([-sideHoleOffsetX,beragingTotalWidth/2+bearingResess+sideY/2,-sideHoleOffsetZ])mirror([0,1,0])side();
      
 }


//bearings(); 
module bearings()
{ 
    for(a=[0:bearingCount-1])
    {
        color(Iron)translate([0,-(bearingCount*beragingWidth)/2])
        bearing(    pos=[0,beragingWidth+beragingWidth*a,0], 
                    angle=[90,0,0], 
                    model=SkateBearing, 
                    outline=false,
                    material=Steel, 
                    sideMaterial=Iron, 
                    center=false); 
    }
    color("Silver")rotate([90,0,0])cylinder(d=bearindId,h=shatfLenght,center=true); 
}

cutter(); 
module cutter()
{
    angle=10; 
    srewBottomY = 6;
    srewTopY = 15;
    topResses = (stanley1992_Width-stanley1992_Top)/2;
    alpha = atan(topResses/stanley1992_Height); 
    
    
    difference()
    {
        hull()
        {
        rotate([angle,0,0])translate([0,bladeEdgeResses,stanley1992_Thickness-bladeEdgeResses/tan(90-angle)])cube([cutterX,cutterY+bladeWall/2,cutterZ],center = false); 
        translate([0,bladeEdgeResses,0])cube([cutterX,cutterY,cutterZ],center=false); 
        }  
        rotate([angle,0,0])translate([0,bladeEdgeResses-1,stanley1992_Thickness-bladeEdgeResses/tan(90-angle)-0.1])cube([cutterX,cutterY+bladeWall/2+1,cutterZ+bladeWall],center = false);
        translate([(cutterX-stanley1992_Width)/2,0,-bladeEdgeResses/tan(90-angle)])rotate([angle,0,0])stanley1992(thickness = stanley1992_Thickness, center = false);
        translate([0,cutterY+bladeEdgeResses,0])cube([cutterX,bladeEdgeResses,cutterZ*5],center=false); 
        translate([srewBottomY*tan(alpha)+bladeWall-M3Hole/2-srcrewWall,srewBottomY,0])cylinder(d=M3Hole, h = cutterZ*5);
        translate([cutterX-srewBottomY*tan(alpha)-bladeWall+M3Hole/2+srcrewWall,srewBottomY,0])cylinder(d=M3Hole, h = cutterZ*5);
        translate([srewTopY*tan(alpha)+bladeWall-M3Hole/2-srcrewWall,srewTopY,0])cylinder(d=M3Hole, h = cutterZ*5);
        translate([cutterX-srewTopY*tan(alpha)-bladeWall+M3Hole/2+srcrewWall,srewTopY,0])cylinder(d=M3Hole, h = cutterZ*5);

    } 
    translate([(cutterX-stanley1992_Width)/2,0,-bladeEdgeResses/tan(90-angle)])rotate([angle,0,0])stanley1992(thickness = stanley1992_Thickness, center = false);
}

 


//side();
module side()
{
    difference()
    {
        union()
        {
            cube([sideX,sideY,sideZ],center = true);
                translate([sideHoleOffsetX,sideY/2+bearingResess/2,sideHoleOffsetZ])rotate([90,0,0])cylinder(d=bearindId+2, h=bearingResess, center = true); 
        }
        translate([sideX/2-srewHoleClearence,0,sideZ/2-srcewDepth/2])cylinder(d=M3Thread, h=srcewDepth, center = true);
    translate([-sideX/2+srewHoleClearence,0,sideZ/2-srcewDepth/2])cylinder(d=M3Thread, h=srcewDepth, center = true); 
    translate([sideX/2-srewHoleClearence,0,-sideZ/2+srcewDepth/2])cylinder(d=M3Thread, h=srcewDepth, center = true);
    translate([-sideX/2+srewHoleClearence,0,-sideZ/2+srcewDepth/2])cylinder(d=M3Thread, h=srcewDepth, center = true);
        
        translate([sideHoleOffsetX,bearingResess/2,sideHoleOffsetZ])rotate([90,0,0])cylinder(d=bearindId, h=sideWidth+1, center = true); 
    }
     
}
