import static uk.co.nickthecoder.foocad.changefilament.v1.ChangeFilament.* import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* class TapAndDieInsert : Model, PostProcessor { var size = Vector2(240,147) var thickness = 0.8 var width = 1.2 var maxHeight = 14 fun raisedEdge( shape : Shape2d, height : double ) : Shape3d { val baseH = maxHeight - height return shape.extrude(baseH) + (shape.offset( width ) - shape) .extrude(baseH+8) .color( "orange" ) } fun edge( shape : Shape2d, height: double ) : Shape3d { return shape.extrude(thickness) + (shape.offset( width ) - shape) .extrude(height) .color( "orange" ) } fun rib( diameter: double, pieceThickness: double, width: double) : Shape3d { val shape = Square( width, maxHeight - pieceThickness/2 ).centerX().backTo(0) - Circle( diameter/2 ).sides(18) return shape.extrude( this.width ).rotateX(90).rotateZ(90) .bottomTo(0).centerXY().color("orange") } fun verticalRibs( shape : Shape2d, width : double, pieceThickness: double ) : Shape3d { val spacing = 10 val s = Square( this.width, shape.size.y ) println( "Across = ${shape.size.x / spacing}" ) val all = s.repeatX( width / spacing, spacing ).center() return (all / shape).extrude( maxHeight - pieceThickness ) } @Piece fun die() : Shape3d { val shape = Circle.hole( 26/2 ) val ring = raisedEdge(shape, 8.7) return ring - Cylinder( 100, 18).center().rotateX(90).bottomTo(8) } fun tap2d(diameter :double, length :double) : Shape2d { return Square( length, diameter ).roundAllCorners(2).center() } @Piece fun dieTool() : Shape3d { val pieceThickness = 12.5 val shape = Square( 208, 11 ).center().roundAllCorners( 3 ) + Square( 79, 14 ).center().roundAllCorners(3) + Circle( 37/2 ) + Square( 9, 26 ).roundCorner(3,2).roundCorner(2,2).centerX() val foo = 90 val ribs = rib( 8.6, pieceThickness, 11 ) .repeatX( 3, 20+width ).leftTo( -foo -width ) .mirrorX().also() val ribs2 = verticalRibs( shape, 40, pieceThickness ) val fingerHoles = Cube( 20, 100, 100 ).centerY().leftTo( -foo ) .bottomTo( 5 ) .mirrorX().also() val metal = (Cylinder( 205, 8.5/2 ).center().rotateY(90) + Cylinder( 12.5, 35.7/2 ).center() ).previewOnly().bottomTo( ribs2.top ) return edge(shape, 10) - fingerHoles + ribs + ribs2 + metal } @Piece fun tapTool() : Shape3d { val pieceThickness = 12.9 val shape = Square(203, 9.5 ).center().roundAllCorners( 3 ) + Square( 73, 14 ).center().roundAllCorners( 1 ) + Square( 48, 24 ).center().roundAllCorners( 2 ) val foo = 90 val ribs = rib( 7.5, pieceThickness, 9 ) .repeatX( 3, 20+width ).leftTo( -foo - width ) .mirrorX().also() val ribs2 = verticalRibs( shape, 50, 10 ) val fingerHoles = Cube( 20, 100, 100 ).centerY().leftTo( -foo ) .bottomTo( 5 ) .mirrorX().also() val metal = ( Cylinder(197, 7.8/2 ).center().rotateY(90) + Cylinder( 71, 12.4/2 ).center().rotateY(90) + Cube( 46, 23.2, 10 ).center() ).previewOnly().bottomTo( ribs2.top - 2.4 ) return edge(shape, 11) - fingerHoles + ribs + ribs2 + metal } @Piece fun dies() : Shape3d { val dieDX = 33 val die : Shape3d = die() val dies = die.repeatX( 7, 33 ).centerX().backTo( size.y - 5 ) val sizes = listOf("3", "4", "5", "6", "8", "10", "12") val dieTextList = listOf() for (i in 0..6) { val str = sizes[i] dieTextList.add( Text( str ).rightTo(0).translateX( dieDX * i ) ) } val dieText2d = Union2d( dieTextList ) .leftTo( dies.left - 1 ) .backTo( dies.front + 5 ) val dieText = dieText2d .extrude( thickness + 0.8 ).color("white") val textBackground = Square( size.x, 42 ).roundAllCorners(8) .centerX().frontTo( dieText2d.front -1 ) .extrude( thickness ) return dies + textBackground + dieText } fun tap( length: double, shankD: double, cutD: double, str : String, leftAligned : bool ) : Shape3d { val max = Math.max( shankD, cutD ) val width = 2 + max val shape = Square( length, width ).center().roundAllCorners(2) val shankRibs = rib( shankD, max, width ) .repeatX( 3, 7 ).leftTo(shape.left + 4) val cutRibs = rib( cutD, max, width ) .repeatX( 3, 7 ).rightTo(shape.right-4) var text : Shape3d = Text( str, 9 ).extrude(thickness + 0.8).centerY() .color("White") text = if (leftAligned) { text.leftTo(2+shape.right) } else { text.rightTo(shape.left - 2) } val outline = edge( shape, maxHeight) var fingerGap : Shape3d = Cylinder( 100, length * 0.25 ).center() .rotateX(90) .bottomTo( outline.top - max*0.3 - 3) fingerGap = if (leftAligned) { fingerGap.centerXTo(outline.left+38) } else { fingerGap.centerXTo(outline.right-34) } val result = (outline - fingerGap + text + shankRibs + cutRibs).leftTo(0) .margin( 0, Math.min(0,(outline.size.y - text.size.y) / 2), 0 ) return if (leftAligned) { result } else { result.rightTo(0) } } @Piece fun tapSet1() : Shape3d { val a = tap( 83, 8.3, 12.2, "12", true) val b = tap( 77, 6.9, 10.0, "10", true).backTo(a.front - 1) val c = tap( 72, 5.9, 8.0, "8", true).backTo(b.front - 1 ) val taps = (a + b + c).toOrigin() val base = Square( taps.size.x + 2, taps.size.y ).roundAllCorners(3).extrude( thickness ) return taps + base } @Piece fun tapSet2() : Shape3d { val a = tap( 70, 6.6, 6.0, "6", false) val b = tap( 68, 5.6, 4.8, "5", false).backTo(a.front - 3 ) val c = tap( 66, 4.5, 3.8, "4", false).backTo(b.front - 3 ) val d = tap( 64, 3.3, 2.8, "3", false).backTo(c.front - 3 ) val taps = (a + b + c + d).toOrigin() val base = Square( tapSet1().size.x, taps.size.y ).roundAllCorners(3).extrude( thickness ) .rightTo( taps.right ) return taps + base } //@Piece fun taps() : Shape3d = layoutY(2, tapSet1(), tapSet2().toOrigin()) override fun build() : Shape3d { val baseOutline = Square( size ).center().roundAllCorners( 10 ) //val base = (baseOutline - baseOutline.offset(-10)).extrude( 1.0 ) val dies : Shape3d = dies() val tapTool : Shape3d = tapTool().frontTo( 0 ) val dieTool : Shape3d = dieTool().frontTo( tapTool.back ) val taps1 = tapSet1().leftTo(dies.left ).backTo( dies.front ) val taps2 = tapSet2().rightTo(dies.right ).backTo( dies.front ) return dies + dieTool + tapTool + taps1 + taps2 } override fun postProcess(piece : String, gcode: GCode) { if ( piece == "dies" || piece == "taps" || piece.startsWith("tapSet") ) { pauseAtHeight( gcode, thickness+ 0.2, "Change Filament" ) } } override fun postProcess(gcode: GCode) { } }