/*
Creator : Kerem Yollu 
date : 30.06.2021
Description : library for din rail and accessories. 
*/
	

include <box.scad>
include <swisspb.scad>

$fn = 100; 
va = 0.02;      // Visual addition for difference
vap = va/2;     // Half of visual addition 
van = -(va/2);  // Negative half of visual addition


din_rail_mount(); 

module din_rail_mount()
{
    lenght = 40; 
    heigth = 10; 
    thikness = 10.9; 

    difference()
    {
        cube(size=([lenght,heigth,thikness]),center=true); 
        din_rail_75(lenght = 20, hole_offset = 0 , extra_thickness= 0.3, extra_bending_d = 0.5 ,extra_wing_lenght =0.2, center = true);

        translate([-lenght/2,0,0])
            rotate([0,90,0])
                cylinder(d=2.4, h=7);

        translate([0,(heigth-pbswiss_mounting_size)/2,0])
        {
            cube(size=([pbswiss_mounting_size+0.3,pbswiss_mounting_size+0.2,pbswiss_mounting_size+0.3]),center=true);
            
            rotate([0,90,0])
                cylinder(d=3.2, h=lenght/2+1);

            translate([-pbswiss_mounting_size/2 -5,0,0]) 
                rotate([0,90,0])
                    cylinder(d=3.2, h=10);

            translate([pbswiss_mounting_size/2+3,0,0]) 
                rotate([0,90,0])
                    cylinder(d=6, h=lenght/2+1);
        }
    } 
}



/* DIN RAIL 35 x 7.5 mm
    lenght : Total lenght of the rail
        > Positive Values

    hole_offset : First Mounting hole offset to border  
        > 0 will remove holes 
        > ccepted values between 1 and 9
        > Otherwise error will ocure
    
    extra_thickness : To allow the addition of Thickness
        > Positive values

    extra_bending_d : Will change the bending radious 
        > Positive values 

    extra_wing_lenght : Add length to each wing
        > Positive values

    center : Centers the rail
        > true or false
*/
//din_rail_75();
module din_rail_75(lenght = 100, hole_offset = 5 , extra_thickness=0, extra_bending_d=0, extra_wing_lenght = 0, center = true)
{
    thickness = 1 + extra_thickness; 
    base_inside_width = 25-extra_thickness;
    base_outise_width = base_inside_width + 2*thickness; 
    total_width = 35; 
    total_height = 7.5 + 0.4; 

    
    hole_lenght = 15; 
    hole_spacing = 10; 
    hole_dia = 6.2;
    hole_ray = hole_dia/2;  
    hole_count = lenght/(hole_lenght+hole_spacing);

    inner_rounding_dia = 3 + extra_bending_d; 
    inner_rounding_ray = inner_rounding_dia/2; 

    outer_rounding_dia = inner_rounding_dia + 2 * thickness;
    outer_rounding_ray = outer_rounding_dia/2;

    base_inside_width_with_rounding = base_outise_width - outer_rounding_dia; 
    base_wall_height = total_height - outer_rounding_dia;
    wing_rounding_height =total_height-thickness;
    wing_width_to_rounding = (total_width - base_outise_width)/2 - inner_rounding_ray + extra_wing_lenght;
    
    center_x = wing_width_to_rounding+inner_rounding_ray-((total_width+extra_wing_lenght*2)/2);
    center_y = -total_height/2;
    center_z = 0;
    
    offset_x = wing_width_to_rounding+inner_rounding_ray;
    offset_y = 0;
    offset_z = lenght/2;


    assert(hole_offset >= 0);
    assert(hole_offset < 10);

    if(center == true)
    {
        translate([center_x,center_y,center_z])
        {
            difference()
            {
                // Din Rail
                union()
                {
                    // Rail Base 
                    translate([base_inside_width_with_rounding/2+outer_rounding_ray,thickness/2,0])
                        cube(size=([base_inside_width_with_rounding,thickness,lenght]),center=true); 

                    // Base rounding to wall near origin
                    translate([thickness,thickness,0])
                        rotate([0,0,180])
                            bend(inner_rounding_ray,thickness,lenght,90,center = true);
                    
                    // Base rounding to wall with base width offset
                    translate([base_outise_width-thickness,thickness,0])
                        rotate([0,0,270])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    // Base Wall near origin
                    translate([thickness/2,base_wall_height/2+outer_rounding_ray,0])
                        cube(size=([thickness,base_wall_height,lenght]),center=true); 
                    
                    // Base Wall with base width offset
                    translate([thickness/2+base_inside_width + thickness,base_wall_height/2+outer_rounding_ray,0])
                        cube(size=([thickness,base_wall_height,lenght]),center=true);

                    // Wall rounding to wing near origin
                    translate([0,wing_rounding_height,0])
                        rotate([0,0,0])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    // Wall rounding to wing near origin
                    translate([base_outise_width,wing_rounding_height,0])
                        rotate([0,0,90])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    translate([-wing_width_to_rounding/2-inner_rounding_ray,total_height-thickness/2,0])
                        cube(size=([wing_width_to_rounding,thickness,lenght]),center=true);

                    translate([base_outise_width+wing_width_to_rounding/2+inner_rounding_ray,total_height-thickness/2,0])
                        cube(size=([wing_width_to_rounding,thickness,lenght]),center=true);
                }

                if(hole_offset > 0)
                {
                    translate([0, 0, hole_offset])
                    {
                        for (i = [0:hole_count])
                        {
                            translate([base_outise_width/2,0, i*(hole_lenght+hole_spacing) - lenght/2])
                            hull()
                            {
                                translate([0,thickness/2,hole_ray])
                                    rotate([90,0,0])
                                        cylinder(d=hole_dia, h=thickness+va, center = true);

                                translate([0,thickness/2,hole_lenght-hole_ray])
                                    rotate([90,0,0])
                                            cylinder(d=hole_dia, h=thickness+va, center = true);
                            }
                        }
                    }
                }
            }
        }
    }

    if(center == false)
    {
        translate([offset_x,offset_y,offset_z])
        {
            difference()
            {
                // Din Rail
                union()
                {
                    // Rail Base 
                    translate([base_inside_width_with_rounding/2+outer_rounding_ray,thickness/2,0])
                        cube(size=([base_inside_width_with_rounding,thickness,lenght]),center=true); 

                    // Base rounding to wall near origin
                    translate([thickness,thickness,0])
                        rotate([0,0,180])
                            bend(inner_rounding_ray,thickness,lenght,90,center = true);
                    
                    // Base rounding to wall with base width offset
                    translate([base_outise_width-thickness,thickness,0])
                        rotate([0,0,270])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    // Base Wall near origin
                    translate([thickness/2,base_wall_height/2+outer_rounding_ray,0])
                        cube(size=([thickness,base_wall_height,lenght]),center=true); 
                    
                    // Base Wall with base width offset
                    translate([thickness/2+base_inside_width + thickness,base_wall_height/2+outer_rounding_ray,0])
                        cube(size=([thickness,base_wall_height,lenght]),center=true);

                    // Wall rounding to wing near origin
                    translate([0,wing_rounding_height,0])
                        rotate([0,0,0])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    // Wall rounding to wing near origin
                    translate([base_outise_width,wing_rounding_height,0])
                        rotate([0,0,90])
                            bend(inner_rounding_ray,thickness,lenght,90);

                    translate([-wing_width_to_rounding/2-inner_rounding_ray,total_height-thickness/2,0])
                        cube(size=([wing_width_to_rounding,thickness,lenght]),center=true);

                    translate([base_outise_width+wing_width_to_rounding/2+inner_rounding_ray,total_height-thickness/2,0])
                        cube(size=([wing_width_to_rounding,thickness,lenght]),center=true);
                }

                if(hole_offset > 0)
                {
                    translate([0, 0, hole_offset])
                    {
                        for (i = [0:hole_count])
                        {
                            translate([base_outise_width/2,0, i*(hole_lenght+hole_spacing) - lenght/2])
                            hull()
                            {
                                translate([0,thickness/2,hole_ray])
                                    rotate([90,0,0])
                                        cylinder(d=hole_dia, h=thickness+va, center = true);

                                translate([0,thickness/2,hole_lenght-hole_ray])
                                    rotate([90,0,0])
                                            cylinder(d=hole_dia, h=thickness+va, center = true);
                            }
                        }
                    }
                }
            }
        }
    }
}





//din_mount_wago_style(thickness = 6); 

module din_mount_wago_style(thickness = 6)
{
    small_dia = 1.2; 
    small_ray = small_dia/2;  

    base_lenght = 24; 
    base_width = 9;
    base_heigth = 8;
    base_resses_start = 4;
    base_resses_ramp_lenght = 5;
    base_resses_height = 4;
    base_resses_lenght = 10;

    anchor_triangle_offset_y = 0.5;
    anchor_triangle_offset_x = 10; 
    anchor_triangle_lenght = 6;
    anchor_triangle_angle = 1; 
    anchor_triangle_width = 4; 
    anchor_triangle_top_start = anchor_triangle_lenght -2.5; 

    ancor_back_offset_y = 1; 
    ancor_back_lenght = 3;
    ancor_back_opening = 1.6;
    ancor_back_clip_ressess = 0.4; 
    ancor_back_thickness = 2.6;
    ancor_back_incline_spport_len = 4;
    ancor_back_incline_spport_to_base_y = 5;
    ancor_back_incline_spport_to_base_x = 4; 


    spring_1_start = 2.5; 
    locking_point_offset_y = 1.5; 
    locking_point_incl_y = 6;
    locking_point_incl_x = 3; 
    locking_point_lenght = 8;
    locking_point_inside_lenght = 5;
    locking_point_width = 5;
    locking_point_offset_x = 2;
    flex_zone_start_height = 3;
    unmount_opening = 4; 
    unmount_height = 3;

    //base + anchor tirangle and achor openeing. 
    union()
    {
        hull()
        {
            // triangle base poin near reference
            translate([small_ray,small_ray-anchor_triangle_offset_y,0])
                cylinder(d=small_dia, h=thickness);

            // triangle base point x offset
            translate([small_ray+anchor_triangle_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // triangle base point x offset
            translate([small_ray+anchor_triangle_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness);

            // Triangle top
            translate([small_ray+anchor_triangle_top_start,anchor_triangle_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // triangle base poin near reference
            translate([small_ray,small_ray-anchor_triangle_offset_y,0])
                cylinder(d=small_dia, h=thickness);
            
            // Triangle top
            translate([small_ray+anchor_triangle_top_start,anchor_triangle_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }
        
        hull()
        {
            // Triangle top
            translate([small_ray+anchor_triangle_top_start,anchor_triangle_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);

            //solid base starting 
            translate([small_ray+anchor_triangle_top_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }


        hull()
        {
            // Triangle top
            translate([small_ray+anchor_triangle_top_start,anchor_triangle_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);
            
            //base resess starting
            translate([small_ray+anchor_triangle_top_start+base_resses_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            //solid base starting 
            translate([small_ray+anchor_triangle_top_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
            
            //base resess starting
            translate([small_ray+anchor_triangle_top_start+base_resses_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            //base resess starting
            translate([small_ray+anchor_triangle_top_start+base_resses_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
            
            //base resess ramp downgoing
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,base_resses_height-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }


        hull()
        {
            //base resess ramp downgoing
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,base_resses_height-small_ray,0])
                cylinder(d=small_dia, h=thickness);

            //base resess ramp downgoing to base bottom
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness); 
        }

        hull()
        {
            //base resess ramp downgoing
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,base_resses_height-small_ray,0])
                cylinder(d=small_dia, h=thickness);

            //base resess lenght
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght ,base_resses_height-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            //base resess lenght
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght ,base_resses_height-small_ray,0])
                cylinder(d=small_dia, h=thickness);

             //base resess lenght + resse ramp going to b ase again   
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght+ base_resses_ramp_lenght,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
             // triangle base point x offset
            translate([small_ray+anchor_triangle_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness);

             //base bottom starting
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness); 
        }


        hull()
        {
             //base bottom starting
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness); 

            // base lenght after anchor triangle. 
            translate([small_ray+anchor_triangle_lenght+base_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness);

        }

        hull()
        {
            // base lenght after anchor triangle. 
            translate([small_ray+anchor_triangle_lenght+base_lenght,small_ray,0])
                cylinder(d=small_dia, h=thickness);
            
            // back anchor hihg point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,small_ray+ancor_back_offset_y,0])
                cylinder(d=small_dia, h=thickness);
        
        }

        hull()
        {
            // back anchor hihg point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,small_ray+ancor_back_offset_y,0])
                cylinder(d=small_dia, h=thickness);

            //base resess lenght + resse ramp going to b ase again   
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght+ base_resses_ramp_lenght,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {   
            // back anchor opening high point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,small_ray+ancor_back_offset_y,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor opening low point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,-small_ray+ancor_back_offset_y-ancor_back_opening,0])
                cylinder(d=small_dia, h=thickness);
        
        }

        hull()
        {
            // back anchor opening low point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,-small_ray+ancor_back_offset_y-ancor_back_opening,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor opening return point
            translate([small_ray+anchor_triangle_lenght+base_lenght,-small_ray-ancor_back_opening,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // back anchor opening return point
            translate([small_ray+anchor_triangle_lenght+base_lenght,-small_ray-ancor_back_opening,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor clip ressesed
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess,small_ray-ancor_back_opening-ancor_back_thickness ,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // back anchor clip ressesed
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess,small_ray-ancor_back_opening-ancor_back_thickness ,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor clip ressesed flat surface
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness ,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // back anchor clip ressesed flat surface
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness ,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor clip inclined clearance
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght ,0])
                cylinder(d=small_dia, h=thickness);
        }


        hull()
        {
            // back anchor clip inclined clearance
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght ,0])
                cylinder(d=small_dia, h=thickness);
        
            // back anchor clip inclined support point to the oppening wall 
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // back anchor clip inclined clearance
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght ,0])
                cylinder(d=small_dia, h=thickness);
            
            // back anchor clip inclined clearance
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght + ancor_back_incline_spport_to_base_x ,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght + ancor_back_incline_spport_to_base_y,0])
                cylinder(d=small_dia, h=thickness);
            
        }

        hull()
        {   
            //base resess lenght + resse ramp going to b ase again   
            *translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght+ base_resses_ramp_lenght,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);



            // back anchor clip inclined clearance support back to base
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght + ancor_back_incline_spport_to_base_x - ancor_back_incline_spport_to_base_x /2 ,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght + ancor_back_incline_spport_to_base_y + ancor_back_incline_spport_to_base_x /2,0])
                cylinder(d=small_dia, h=thickness);
            

            // back anchor clip inclined clearance
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght + ancor_back_incline_spport_to_base_x ,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght + ancor_back_incline_spport_to_base_y,0])
                cylinder(d=small_dia, h=thickness);

        }

        hull()
        {
            //base resess lenght + resse ramp going to b ase again   
            translate([small_ray+anchor_triangle_top_start+base_resses_start+base_resses_ramp_lenght + base_resses_lenght+ base_resses_ramp_lenght,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor clip inclined clearance support back to base
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght + ancor_back_incline_spport_to_base_x - ancor_back_incline_spport_to_base_x /2 ,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght + ancor_back_incline_spport_to_base_y + ancor_back_incline_spport_to_base_x /2,0])
                cylinder(d=small_dia, h=thickness);

        }

        hull()
        {
            
            // back anchor opening high point  
            translate([small_ray+anchor_triangle_lenght+base_lenght+ancor_back_lenght,small_ray+ancor_back_offset_y,0])
                cylinder(d=small_dia, h=thickness);

            // back anchor clip inclined clearance support back to base
            translate([small_ray+anchor_triangle_lenght+base_lenght + ancor_back_clip_ressess+ancor_back_lenght+ancor_back_lenght + ancor_back_incline_spport_to_base_x - ancor_back_incline_spport_to_base_x /2 ,small_ray-ancor_back_opening-ancor_back_thickness + ancor_back_lenght + ancor_back_incline_spport_to_base_y + ancor_back_incline_spport_to_base_x /2,0])
                cylinder(d=small_dia, h=thickness);

        }
        

        hull()
        {
            
            //solid base starting 
            translate([small_ray+anchor_triangle_top_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);

            //starof of spring 1 
            translate([small_ray+anchor_triangle_top_start- spring_1_start,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);

        }

        
    
        hull()
            {
            // locking point start
            translate([-small_ray,-small_ray-anchor_triangle_offset_y-locking_point_offset_y,0])
                cylinder(d=small_dia, h=thickness);

            // locking point start
            translate([-small_ray-locking_point_incl_x,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
                cylinder(d=small_dia, h=thickness);

            // Locking point -x-y
            translate([-small_ray-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
                cylinder(d=small_dia, h=thickness);

            // Locking point -x y
            translate([-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray,0])
                cylinder(d=small_dia*2, h=thickness);

            // Locking point x y inside
            translate([-small_ray-locking_point_offset_x,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            // Locking point -x-y
            translate([-small_ray-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
                cylinder(d=small_dia, h=thickness);

            // unmoun -x -y
            translate([-small_ray-locking_point_incl_x-locking_point_lenght-unmount_opening,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {

            // unmoun -x -y
            translate([-small_ray-locking_point_incl_x-locking_point_lenght-unmount_opening,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
                cylinder(d=small_dia, h=thickness);

            // unmoun -x y
            translate([-small_ray-locking_point_incl_x-locking_point_lenght-unmount_opening,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+unmount_height,0])
                cylinder(d=small_dia, h=thickness);
        }

        
        // unmount wall
        translate([-small_ray-locking_point_incl_x-locking_point_lenght-unmount_opening,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y,0])
            cube(size=([unmount_opening,unmount_height,0.8])); 


        hull()
        {
            // Locking point -x y
            translate([-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray,0])
                cylinder(d=small_dia*2, h=thickness);
        
            // Locking flex zone 1 start
            translate([-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray+flex_zone_start_height,0])
                cylinder(d=small_dia, h=thickness);
            
        }

        hull()
        {
            // Locking point x y inside
            translate([-small_ray-locking_point_offset_x,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray,0])
                cylinder(d=small_dia, h=thickness);
            
            // Locking flex zone 2 start
            translate([-small_ray-locking_point_offset_x,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray+flex_zone_start_height-1,0])
                cylinder(d=small_dia, h=thickness);
        }



        hull()
        {
        
            // Locking flex zone 1 start
            translate([-locking_point_incl_x-locking_point_lenght,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray+flex_zone_start_height,0])
                cylinder(d=small_dia, h=thickness);
            
            // Locking flex zone 1 back to base
            translate([-10,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }

        hull()
        {
            
            // Locking flex zone 2 start
            translate([-small_ray-locking_point_offset_x,-small_ray-anchor_triangle_offset_y-locking_point_offset_y-locking_point_incl_y+locking_point_width-small_ray+flex_zone_start_height-1,0])
                cylinder(d=small_dia, h=thickness);

            // Locking flex zone 2 back to base
            translate([-small_ray-locking_point_offset_x+1.8,base_heigth-small_ray,0])
                cylinder(d=small_dia, h=thickness);
        }
        
        translate([-10-small_ray,base_heigth-small_dia,0])
        cube(size=([50,8,thickness])); 
    }
}




module bend(inner_bend_r = 1,thikness = 1, lenght = 10, angle = 90, center = true)
{
    inner_rad = inner_bend_r; 
    inner_dia = inner_bend_r * 2; 

    outer_rad = inner_rad + thikness; 
    outer_dia = outer_rad * 2;
    
    if(center == true)
    {
        translate([-inner_rad,-inner_rad,-lenght/2])
            rotate_extrude(angle=angle)
                polygon( points= [[inner_rad,0],[outer_rad,0], [outer_rad,lenght], [inner_rad,lenght], [inner_rad,lenght]]);  
    }
    if(center == false)
    {
        rotate_extrude(angle=angle)
            polygon( points= [[inner_rad,0],[outer_rad,0], [outer_rad,lenght], [inner_rad,lenght], [inner_rad,lenght]]);
    }
}