showAssembled=0;

$fn=12;

flagHeight=15;
flagWidth=25;
flagDepth=10;
baseThickness=4;
chainHolderDiameter=4;

gutterHeight=5;
gutterWidth=4;

// slice it for printing
if (showAssembled) {
  wholeModel();
} else {
  translate([0,0,baseThickness]) rotate([180,0,180])
  difference(){
    wholeModel();
    translate([-50,-50,baseThickness]) cube(100);
  }
  
  translate([-20,0,-baseThickness]) difference(){
    wholeModel();
    translate([-50,-50,-100+baseThickness]) cube(100);
  }
}

module wholeModel(){
  difference() {
    union() {
      translate([0,-gutterWidth/2,gutterHeight/2-(gutterHeight-1)]){
        cube([flagDepth,flagWidth-gutterWidth,gutterHeight-2], center=true);
      }

      translate([0,-gutterWidth,(flagHeight-gutterHeight)/2]){
        cube([flagDepth,flagWidth,flagHeight-gutterHeight], center=true);
      }

      translate([0,-(flagWidth+20)/2,baseThickness/2]){
        difference(){
          cube([flagDepth,20,baseThickness], center=true);
          translate([0,0,0])
            cylinder(h=baseThickness+1,r=2.5,center=true);
        }
      }
    }
    // screw holes
    translate([0,flagWidth*.12,flagHeight*.65]) rotate([0,0,0]) cylinder(h=flagHeight/4,d=4.5, center=true);
    translate([0,flagWidth*.12,flagHeight/4]) rotate([0,0,0]) cylinder(h=flagHeight+1,d=1.5, center=true);
    translate([0,-flagWidth*.45,flagHeight*.65]) rotate([0,0,0]) cylinder(h=flagHeight/4,d=4.5, center=true);
    translate([0,-flagWidth*.45,flagHeight/4]) rotate([0,0,0]) cylinder(h=flagHeight+1,d=1.5, center=true);

    translate([0,2,baseThickness]){
      chainHolder();
      translate([0,chainHolderDiameter+.5,0]) chainHolder();
    }
  }
}

module chainHolder() {
  translate([-flagDepth/3,-flagWidth/2+2,0]) rotate([0,90,0]) cylinder(h=flagDepth/2+1,d=chainHolderDiameter, center=true);
  translate([flagDepth/3,-flagWidth/2+2,0]) rotate([0,90,0]) cylinder(h=flagDepth/2+1,d=chainHolderDiameter, center=true);
  translate([0,-flagWidth/2+2,0]) rotate([0,90,0]) cylinder(h=flagDepth,d=1, center=true);
}