+ ImportTemplate(bladew, k,"bl");
+ hull(){
+ ImportTemplate(width(k), k,"hl");
+ translate([-100,0,0])
+ ImportTemplate(width(k), k,"hl");
+ }
+}
+
+module DoKnife(k){
+ translate([locations[k],0,0]){
+ rotate([0,90,0])
+ translate([-(handlelenbase + handlelendelta[k]),0,0])
+ Knife(k);
+ }
+}
+
+module DoKnives(){
+ for (k=[0:nknives-1])
+ DoKnife(k);
+}
+
+module ScrewHole(){
+ translate([0,-50,0])
+ rotate([-90,0,0])
+ cylinder(r=screwdia/2, h=150, $fn=40);
+ translate([0, totaldepth-front - screwbackdepth, 0])
+ rotate([90,0,0])
+ cylinder(r=screwcsinkdia/2 / (sqrt(3)/2), h=100, $fn=6);
+}
+
+module PegTemplate(apex){
+ for (mx=[0,1]) for (my=[0,1]) {
+ mirror([mx,0,0]) mirror([0,my,0])
+ polygon([[-0.1, -0.1],
+ [pegstem/2, -0.1],
+ [pegstem/2, pegstemheight/2],
+ [peghead/2, pegheight /2],
+ [-0.1, pegheight /2 + apex]]);
+ }
+}
+
+module AtSides(){
+ translate([minx,0,0]) child(0);
+ translate([maxx,0,0]) mirror([1,0,0]) child(1);
+}
+
+module BlockPegSlot(){
+ translate([recessblockwidth/2, pegrecess - 0.5*peglen, -height]){
+ rotate([-90,0,0]) linear_extrude(height=totaldepth){
+ PegTemplate(peghead/2 * 1.2);
+ }
+ }
+}
+
+module Block(){
+ sidemidx = minsideout + screwcsinkdia/2;
+
+ difference(){
+ mirror([0,0,1]) {
+ translate([minx, -front, 0])
+ cube([maxx-minx, totaldepth, height]);
+ }
+ for (x=[minx + sidemidx, maxx - sidemidx]) {
+ translate([x, 0, -screwabove])
+ ScrewHole();
+ }
+ for (yshift=[-1,1])
+ translate([0, yshift * frontbackslop, 0])
+ DoKnives();
+ AtSides() { BlockPegSlot(); BlockPegSlot(); }
+ }
+}
+
+module BlockPrint(){ ////toplevel
+ rotate([0,0,90])
+ Block();
+}
+
+module CoverTemplate(){
+ linear_extrude(height=coverthick)
+ polygon([[minx, 0],
+ [maxx, 0],
+ [maxx, coverlonglen],
+ [maxx - coverside, coverlonglen],
+ [minx, covershortlen]]);
+}
+
+module CoverSide(len){
+ translate([0, 0 ,0]) {
+ rotate([90,0,90])
+ linear_extrude(height=coverside)
+ polygon([[0, 0],
+ [0, totaldepth],
+ [covertopwing, totaldepth],
+ [covertopwingbase, coverside + coverthick],
+ [len - covertopwingbase, coverside + coverthick],
+ [len - covertopwing, totaldepth],
+ [len, totaldepth],
+ [len, 0]]);
+ cube([recessblockwidth, recessblockheight, totaldepth]);
+ }
+}
+
+module Peg(){
+ echo("peg angle slope (must be <1)",
+ (peghead-pegstem)/(pegheight-pegstemheight));
+ dx = pegsloph;
+ dy = pegslopv;
+ rotate([90,0,0]) {
+ linear_extrude(height=peglen-pegslopl) {
+ intersection(){
+ translate([-dx,-dy,0]) PegTemplate(0);
+ translate([-dx,+dy,0]) PegTemplate(0);
+ translate([+dx,+dy,0]) PegTemplate(0);
+ translate([+dx,-dy,0]) PegTemplate(0);
+ }
+ }
+ }
+}
+
+module CoverPegSlot(coverlen){
+ translate([recessblockwidth/2, 0, -1]){
+ linear_extrude(height= 1 + pegrecess + 0.5*peglen){
+ PegTemplate(0);
+ }
+ }
+}
+
+module HoleRow(){
+ imax = ceil(coverlonglen / holepitch);
+ echo("Holes Y count ", imax);
+ for (i=[0:imax]) {
+ translate([0, (i+0.5)*holepitch, -20])
+ cylinder(r=holesize/2, h=40, $fn=20);
+ }
+}
+
+module HolesScope(){
+ intersection_for (dx=[-1,+1]) {
+ intersection_for (dy=[-1,+1]) {
+ translate([dx * holeedge, dy * holeedge, -5])
+ scale([1,1,10])
+ CoverTemplate();
+ }
+ }
+}
+
+module Holes(){
+ imin = ceil((maxx-minx)/(sqrt(3)*holepitch));
+ echo("Holes X count 2 x", imin);
+ intersection(){
+ translate([holeoffx * holepitch, holeoffy * holepitch, 0]) {
+ for (i=[-imin:2]) {
+ translate([i * sqrt(3) * holepitch, 0, 0]) {
+ HoleRow();
+ translate([sqrt(3)/2 * holepitch, -0.5 * holepitch, 0])
+ HoleRow();
+ }
+ }
+ }
+ HolesScope();
+ }
+}
+
+module CoverCover(){
+ difference(){
+ CoverTemplate();
+ Holes();
+ }
+}
+
+module Cover(){
+ difference(){
+ union(){
+ CoverCover();
+ AtSides() { CoverSide(covershortlen); CoverSide(coverlonglen); }
+ }
+ AtSides() { CoverPegSlot(); CoverPegSlot(); }
+ }
+}
+
+module CoverAligned(){
+ translate([0,-front,-height])
+ rotate([-90,0,0])
+ Cover();
+}
+
+module DemoPeg(){
+ translate([recessblockwidth/2, pegrecess, -height])
+ Peg();
+}
+
+module Demo(){ ////toplevel
+ %Block();
+ DoKnives();
+ color([0,0,1]) CoverAligned();
+ color([1,0,0]) AtSides() { DemoPeg(); DemoPeg(); }
+}
+
+module CoverParts(){ ////toplevel
+ Cover();
+ translate([0, coverlonglen, pegheight/2]) {
+ Peg();
+ translate([-peghead-3, 0,0]) Peg();