
$fn = 100;

bandLenght = 110;
bandWidthSart = 21; 
bandWidthEnd = 17; 
bandThick = 2; 
bandTipLenght = 15; 

shortBandLength = 75;
shortBandWidthStop = 16;

roundingStichLenght = 10;
roundungHoleDia = 2; 

stichResess = 2; 
stichStep = 4; 
stichHole = 2.2;
stichAngle = 38;
stichWidth = 0.5;

difference()
{   
    strapLong();
    translate([-30,-1,0])cube([bandLenght,bandWidthSart+4,bandThick+1]);
}
//translate([0, bandWidthSart +3,0]) strapShort();
//translate([0, bandWidthSart*2 + 5,0]) strapInsret();






module roundingEnds() 
{
   rounded_box(roundingStichLenght + roundungHoleDia*PI,bandWidthSart,bandWidthSart,2,0.2,0,0); 
}

module roundingEndBuckle() 
{
    rounded_box(roundingStichLenght + roundungHoleDia*PI,shortBandWidthStop,shortBandWidthStop,2,0.2,0,0); 
}

module strapInsret()
{
    rounded_box(40,12,7,4,2,1,1);
}

module strapLong()
{
    difference()
    {
        union()
        {
            rounded_box(bandLenght-bandTipLenght, bandWidthSart,bandWidthEnd,bandThick,bandThick, 0,0);
            translate([bandLenght-bandTipLenght,(bandWidthSart-bandWidthEnd)/2,0])strapEnd(15,bandWidthEnd,2);
            rotate([0,0,180])translate([0,-bandWidthSart,0])roundingEnds();
        }
    //translate([0,stichResess,0])strapLongSticth(); 
        translate([0,stichResess,0])stichesStrait(0,0,bandLenght-bandTipLenght,(bandWidthSart-bandWidthEnd)/2,stichStep,stichHole,stichWidth,stichAngle,bandThick);
        translate([0,-stichResess,0])stichesStrait(0,bandWidthSart,bandLenght-bandTipLenght,(bandWidthSart-bandWidthEnd)/2+bandWidthEnd-stichResess/2,stichStep,stichHole,stichWidth,stichAngle,bandThick);
       
        translate([50,bandWidthSart/2,0])tubes(7,2,7,4);
    }
}

module strapShort()
{
    rounded_box(shortBandLength,bandWidthSart,shortBandWidthStop,bandThick,bandThick,0,0);
    rotate([0,0,180])translate([0,-bandWidthSart,0])roundingEnds();
    translate([shortBandLength,(bandWidthSart-shortBandWidthStop)/2,0])roundingEndBuckle();
}

module tubes(qte,dia,space,height)
{
    for( a = [0:qte])
    {
        translate([a*space,0,0])cylinder(d=dia, h=height);
    }
}

module trinagle(l,w,t)
{    
  //translate([0,-w/4+1,0])
    translate([0,0,0])
    {
        hull()
        {
            translate([0,0,0])cylinder(r=0.001, h=t);
            translate([w,0,0])cylinder(r=0.001, h=t);
            translate([w/2,l,0])cylinder(r=0.001, h=t); 
        }
    }
}

module strapEnd(l,w,t)
{
    r = sqrt(pow(l,2)+pow((w/2),2)); 
    difference()
    {
        intersection()
        {
            translate([0,(2*r-w)+(w-r),0])cylinder(r=r, h=t);
            translate([0,(w-r),0])cylinder(r=r, h=t);
        }    
        translate([-l*1.5,0,0])cube([l*1.5,w,t]);
    }
}


 
module rounded_box(length,widthStart,widthStop,thicknessStart,thicknessStop, rStart, rStop){
    
    cubeSize = 0.01; 
    
    hull()
    {
        if(rStart)
        {
            translate([rStart,rStart,0])cylinder(r=rStart, h=thicknessStart);
            translate([rStart,widthStart-rStart,0])cylinder(r=rStart, h=thicknessStart);           
        }
        else 
        {
            translate([rStart,rStart,0])cube([cubeSize,cubeSize,thicknessStart]);
            translate([rStart,widthStart-rStart,0])cube([cubeSize,cubeSize,thicknessStart]);   
        }
        
        if(rStop)
        {
            translate([length-rStop,rStop+(widthStart-widthStop)/2,0])cylinder(r=rStop, h=thicknessStop);
            translate([length-rStop,(widthStop-rStop) + (widthStart-widthStop)/2 ,0])cylinder(r=rStop, h=thicknessStop);
        }
        else
        {
            translate([length-rStop,rStop+(widthStart-widthStop)/2,0])cube([cubeSize,cubeSize,thicknessStop]);
            translate([length-rStop,(widthStop-rStop) + (widthStart-widthStop)/2 ,0])cube([cubeSize,cubeSize,thicknessStop]);
        }   
    }
}


module stichesStrait(startX,startY,stopX,stopY,stichSpace,StichLenght,stichWidth,angle,height)
{
    hypAngle = asin((stopY-startY)/(stopX-startX));
    stichCount = floor((stopX-startX)/(stichSpace));
    echo(stichCount);
       for( a = [0:stichCount])
       {
            rotate([0,0,hypAngle])translate([startX+stichSpace*a,startY-(sin(angle)*StichLenght)/2,0])rotate([0,0,angle])cube([StichLenght,stichWidth,height]);
       }
}

