// -*- C -*-
+// todo
+// various registration marks
+// protrustions at ends at strap width and middle
+// grooves on top face at 1/4,1/2,3/4 length and 1/2 width
+
+crewpunch_slop = 0.3;
+
+holder_min_wall = 2;
+holder_attach_near_wall = 3;
+
+holder_attach_xsz = 5;
+holder_ctie_width = 4.0 + 0.5;
+holder_ctie_thick = 3.0 + 0.5;
+holder_attach_walls = 3;
+holder_attach_roof = 2.5;
+
+jig_interval = 25;
+strap_width = 26.75 + 0.7;
+strap_thick = 3;
+edgewall_width = 3;
+
+punch_travel = 8;
+
+main_slop = 0.5;
+
+jig_max_len = 160; // print diagonally
+//jig_max_len = 30;
+
+registrationgroove_width = 0.8;
+registrationgroove_depth = 1.2;
+
+registrationprotrusion_poke = 3;
+registrationprotrusion_slope = 0.75;
+
+jig_overlap = 1;
+
+// from careful measurement
+
+crewpunch_shape =
+ [[ 6, [0.6, 6.0], [1.6, 12.3] ],
+ [ 8, [1.1, 6.2], [1.9, 12.5] ],
+ [ 10, [1.6, 6.5], [2.1, 12.8] ],
+ [ 12, [1.8, 6.6], [2.3, 12.7] ],
+ [ 14, [2.1, 6.8], [2.6, 13.0] ],
+ [ 16, [2.4, 6.9], [2.7, 13.2] ],
+ [ 18, [2.5, 7.0], [2.9, 13.3] ],
+ [ 22, [3.1, 7.1], [3.2, 13.4] ],
+ [ 26, [3.3, 7.2], [3.5, 13.6] ],
+ ];
+
+crewpunch_shaft_max_y = 3.5;
+
+crewpunch_systematic_size_error = +0.36;
+
+crewpunch_smallest_shape = crewpunch_shape[0];
+crewpunch_biggest_shape = crewpunch_shape[len(crewpunch_shape)-1];
+
+crewpunch_skew_angle = 3.5; //degrees
+crewpunch_skew_yoff_broken = 0; //mm
+crewpunch_skew_yoff = -1.1; //mm
+
+// computed
+
+attach_ysz = holder_attach_walls*2 + holder_ctie_width;
+
+holder_block_zsz = crewpunch_biggest_shape[0] - crewpunch_smallest_shape[0];
+holder_xsz = crewpunch_biggest_shape[2][0] + crewpunch_biggest_shape[2][1] +
+ holder_min_wall*2;
+
+holder_skewangle_yextra = holder_xsz/2 * sin(abs(crewpunch_skew_angle));
+
+holder_front_all = crewpunch_shaft_max_y - crewpunch_biggest_shape[1][0]
+ + attach_ysz + crewpunch_systematic_size_error + crewpunch_skew_yoff_broken
+ + holder_skewangle_yextra;
+
+crewpunch_biggest_y =
+ crewpunch_biggest_shape[1][0] + crewpunch_biggest_shape[1][1];
+holder_ysz = crewpunch_biggest_y + holder_min_wall + holder_front_all
+ + max(0, -crewpunch_skew_yoff_broken);
+
+attach_offset = 0.5 * (holder_front_all - holder_attach_near_wall);
+
+jig_main_zsz = holder_block_zsz + punch_travel;
+
+jig_ends_extra = 2;
+
+//jig_iters = (jig_max_len - jig_ends_extra) / jig_interval;
+jig_iters=2;
+echo(jig_iters);
+
+// objects
+
module CrewPunch(){
-
+ ourslop = crewpunch_slop - crewpunch_systematic_size_error;
+ hull(){
+ for(layer=crewpunch_shape){
+ translate([0,0, layer[0]]){
+ for(xind=[0,1]) //translate([xind?0:1,0,0])
+ for(yind=[0,1]) //translate([0,yind?0.5:0,0])
+ mirror([xind?1:0,0,0]) mirror([0,yind?0:1,0]){
+ translate([-0.1,-0.1,-0.1])
+ cube([0.1 + layer[2][xind] + ourslop,
+ 0.1 + layer[1][1-yind] + ourslop,
+ 0.2]);
+ }
+ }
+ }
+ }
+}
+
+module PunchHolder(cutouts=true){
+ translations=[-holder_xsz/2,
+ -holder_ysz + holder_min_wall + crewpunch_biggest_y/2,
+ 0];
+ translate(translations){
+ difference(){
+ translate([0,attach_offset,0])
+ cube([holder_xsz, holder_ysz - attach_offset, holder_block_zsz]);
+ if (cutouts)
+ translate([0,-crewpunch_skew_yoff_broken])
+ translate(-translations)
+ rotate([0,0,-crewpunch_skew_angle])
+ translate(translations)
+ translate([crewpunch_biggest_shape[2][1] + holder_min_wall,
+ crewpunch_biggest_shape[1][1] + holder_front_all,
+ -crewpunch_smallest_shape[0]])
+ CrewPunch();
+ }
+ difference(){
+ translate([holder_xsz/2 - holder_attach_xsz/2, 0, 0])
+ cube([holder_attach_xsz,
+ attach_ysz,
+ holder_block_zsz + punch_travel
+ + holder_ctie_thick + holder_attach_roof + 1]);
+ if (cutouts)
+ translate([-30,
+ holder_attach_walls,
+ holder_block_zsz + punch_travel])
+ cube([60, holder_ctie_width, holder_ctie_thick]);
+ }
+ }
+}
+
+module RegistrationGroove(l){
+ // runs along the +ve X axis for length l but at correct z pos
+ translate([0, 0, jig_main_zsz + 0.1]) {
+ rotate([90,0,90])
+ linear_extrude(height=l)
+ polygon([[-registrationgroove_width/2, 0],
+ [ +registrationgroove_width/2, 0],
+ [ 0, -registrationgroove_depth ]]);
+ }
+}
+
+module OneJig(){
+ difference(){
+ translate([-(jig_interval/2 + jig_overlap),
+ -(strap_width/2 + edgewall_width) - attach_offset,
+ -strap_thick])
+ cube([jig_interval + 2,
+ strap_width + edgewall_width*2 + attach_offset,
+ jig_main_zsz + strap_thick]);
+ minkowski(){
+ cube([main_slop*2, main_slop*2, 50], center=true);
+ PunchHolder(false);
+ }
+ translate([-100, -strap_width/2, -10])
+ cube([200, strap_width, 10]);
+ translate([-100,0,0])
+ RegistrationGroove(200);
+ for (xfrac=[-1/4,0,+1/4])
+ translate([jig_interval * xfrac, -100, 0])
+ rotate([0,0,90])
+ RegistrationGroove(200);
+ }
+}
+
+module RegistrationProtrusion(){
+ // points towards the positive x axis
+ xsz = registrationprotrusion_poke;
+ ysz = registrationprotrusion_poke;
+ diag_sz = xsz * sqrt(2);
+ zsz = diag_sz / registrationprotrusion_slope;
+ hull(){
+ translate([0, 0, 0.1]){
+ linear_extrude(height=0.1)
+ polygon([[ 0, -ysz ],
+ [ xsz, 0 ],
+ [ 0, ysz ]]);
+ translate([-0.1, 0, zsz ])
+ rotate([0,0,45])
+ cube(0.1);
+ }
+ }
}
+
+module Jig(){
+ for(end=[0,1]){
+ for(yfrac=[-1/2, 0, 1/2]){
+ translate([ end
+ ? jig_interval * (jig_iters - 0.5)
+ : -jig_interval/2,
+ yfrac * strap_width,
+ 0])
+ rotate([0,0, end ? 0 : 180])
+ translate([ jig_overlap, 0, 0 ])
+ RegistrationProtrusion();
+ }
+ }
+ for (i=[0:jig_iters-1]) {
+ translate([jig_interval * i, 0, 0])
+ OneJig();
+ }
+}
+
+module JigT(){ ////toplevel
+ translate([0,0,jig_main_zsz])
+ rotate([180,0,0])
+ Jig();
+}
+
+module PunchHolderT(){ ////toplevel
+ PunchHolder(true);
+}
+
+module Demo(){ ////toplevel
+ %PunchHolder();
+ Jig();
+}
+
+module Kit(){ ////toplevel
+ rotate([0,0,-45]){
+ JigT();
+ translate([(jig_iters-1)*jig_interval/2,
+ -strap_width,
+ 0])
+ PunchHolder();
+ }
+}
+
+//CrewPunch();
+//PunchHolder();
+//PunchHolder(false);
+//OneJig();
+//Jig();
+Demo();
+//JigT();
+//RegistrationProtrusion();
+//PunchHolderT();
+//Kit();