// License: CC0
//
// To the extent possible under law, Clementine Computing LLC has waived
// all copyright and related or neighboring rights to this file.
//
// This work is published from: United States.
//

include <PopufareHousingCommon.scad>

module PopufareHousingTopPlate_hing0() {
  dh = POPUFARE_HOUSING_HEIGHT - POPUFARE_FRONT_HEIGHT;
  w = POPUFARE_HOUSING_WIDTH;
  h = POPUFARE_HOUSING_DEPTH-dh;

  bx = POPUFARE_BRACKET_CX;
  br = POPUFARE_BRACKET_D/2.0;
  de = POPUFARE_BRACKET_DE;
  des = POPUFARE_BRACKET_DE_SHORT;

  lip = _MATERIAL_THICKNESS;
  
  hinge_dw = POPUFARE_HINGE_TOP_HOLE_WIDTH;
  hinge_r = POPUFARE_HINGE_D/2;
  hinge_de = POPUFARE_HINGE_TOP_HOLE_DE;

  difference() {
    union() {
      square([w,h], center=true);
      translate([0, (h/2 + lip/2) - 0.001]) square([w, lip], center=true);
      
      // add overhang to back and sides but not front
      //
      translate([-w/2, -h/4]) square([lip, h/2], center=true);
      translate([ w/2, -h/4]) square([lip, h/2], center=true);

      translate([-w/2, h/4 + lip/2]) square([lip, h/2 + lip], center=true);
      translate([ w/2, h/4 + lip/2]) square([lip, h/2 + lip], center=true);
     
    };
    
    // shave off top front panel to accomodate angle plate
    //
    translate([0, -(h/2 - lip/2) - 0.01]) square([2*w, lip], center=true);
    
    // attach to back plate bracket
    //
    //translate([ -(w/2 - de), (h/2-bx) ]) circle(br);
    //translate([  (w/2 - de), (h/2-bx) ]) circle(br);
    
    // side plate bracket attachment
    //
    translate([ -(w/2 - bx), (h/2-des)]) circle(br);
    translate([ -(w/2 - bx),-(h/2-des)]) circle(br);
    translate([  (w/2 - bx), (h/2-des)]) circle(br);
    translate([  (w/2 - bx),-(h/2-des)]) circle(br);
    
    // hinge attachment
    //
    translate([ -hinge_dw/2, h/2 - hinge_de ]) circle(hinge_r);
    translate([  hinge_dw/2, h/2 - hinge_de ]) circle(hinge_r);

  }

}


// hinge1 measurements
// dh_inner = 10.5
// dh_outter = 22
// dh_first = 8
// dh_second = 3.75
// bot_to_under = 8.25
// dw = 27.75, 35.5

module PopufareHousingTopPlate_hing1() {
  dh = POPUFARE_HOUSING_HEIGHT - POPUFARE_FRONT_HEIGHT;
  w = POPUFARE_HOUSING_WIDTH;
  h = POPUFARE_HOUSING_DEPTH-dh;

  bx = POPUFARE_BRACKET_CX;
  br = POPUFARE_BRACKET_D/2.0;
  de = POPUFARE_BRACKET_DE;
  des = POPUFARE_BRACKET_DE_SHORT;

  lip = _MATERIAL_THICKNESS;
  
  hinge_de = POPUFARE_HINGE1_DE;
  hinge_dh = POPUFARE_HINGE1_DH;
  hinge_dw = POPUFARE_HINGE1_DW;
  hinge_r = POPUFARE_HINGE1_R;
  

  difference() {
    union() {
      square([w,h], center=true);
      translate([0, (h/2 + lip/2) - 0.001]) square([w, lip], center=true);
      
      // add overhang to back and sides but not front
      //
      translate([-w/2, -h/4]) square([lip, h/2], center=true);
      translate([ w/2, -h/4]) square([lip, h/2], center=true);

      translate([-w/2, h/4 + lip/2]) square([lip, h/2 + lip], center=true);
      translate([ w/2, h/4 + lip/2]) square([lip, h/2 + lip], center=true);
     
    };
    
    // shave off top front panel to accomodate angle plate
    //
    translate([0, -(h/2 - lip/2) - 0.01]) square([2*w, lip], center=true);
    
    // attach to back plate bracket
    //
    //translate([ -(w/2 - de), (h/2-bx) ]) circle(br);
    //translate([  (w/2 - de), (h/2-bx) ]) circle(br);
    
    // side plate bracket attachment
    //
    translate([ -(w/2 - bx), (h/2-des)]) circle(br);
    translate([ -(w/2 - bx),-(h/2-des)]) circle(br);
    translate([  (w/2 - bx), (h/2-des)]) circle(br);
    translate([  (w/2 - bx),-(h/2-des)]) circle(br);
    
    // hinge attachment
    //
    translate([ -hinge_dw/2, h/2 + lip - hinge_de ]) circle(hinge_r);
    translate([  hinge_dw/2, h/2 + lip - hinge_de ]) circle(hinge_r);
    
    translate([  -hinge_dw/2, h/2 + lip - (hinge_de + hinge_dh) ]) circle(hinge_r);
    translate([  hinge_dw/2, h/2 + lip - (hinge_de + hinge_dh) ]) circle(hinge_r);

  }

}


module PopufareHousingTopPlate() {
  PopufareHousingTopPlate_hing1();
}

//PopufareHousingTopPlate();
