import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.* /** Helps draw center lines along a plank of wood. As a bonus it also helps draw third and quarter marks too. */ class CenterGuage : Model { var maxPlankWidth = 125 // Min = 67 var pinDiameter = 13 var bodyHeight = 4.0 var pencilHoleDiameter = 2 var bodyWidth = 18 var pinHeight = 10 // Bolt head diameter, bolt shaft diameter and height of the bolt head. (Plus some slack). var boltSize = Vector3(12.0, 6.5, 5.0) override fun build() : Shape3d { val pinDist = maxPlankWidth - pinDiameter val nubHeight = bodyHeight + 5.5 val pinHole = Circle( 10 ).chamferedExtrude( nubHeight, 0, 1 ) remove ( Cylinder( 20, boltSize.y/2 ).center() + Circle( boltSize.x/2 ).sides(6).extrude( boltSize.z ).topTo( nubHeight+0.1 ) ) val pinHoles = pinHole.translateX( pinDist/2 ).mirrorX().also().withCavities() val pencilHoles = pencilHole( 2 ) + pencilHole( 3 ).mirrorX() + pencilHole(4) val end = Circle( bodyWidth/2 ).translateX( pinDist / 2 ) val body2d = (end hull end.mirrorX()) val body = body2d.chamferedExtrude( bodyHeight, 1 ) val hook = ( Circle( 7 ) - Circle( 4 ) ) .extrude(3).color("yellow").darker() .rightTo( body.right + 10 ) val result = (body and pinHoles) - pencilHoles + hook // Using a margin, so that the Ears extension will no include the hook. return result.margin( Vector3(0,0,0), Vector3(-10,0,0) ) } @Piece( slice="brimWidth=4" ) fun pin() : Shape3d { return Cylinder( pinHeight, pinDiameter / 2 ) - Cylinder( 100, 3 ).center() } fun pencilHole( denominator : int ) : Shape3d { val pinDist = maxPlankWidth - pinDiameter val pencilHole = Cylinder( 10, pencilHoleDiameter/2 ).sides(20) + Cylinder( bodyHeight, pencilHoleDiameter/2, bodyHeight ).sides(20).bottomTo(0.2) val label = if ( maxPlankWidth < 80 ) { Cube(0) } else { Square( 2, 4 ).tileX( denominator, 2 ) .centerX().backTo( bodyWidth/2 ) .extrude( 0.6) .topTo( bodyHeight + 0.01 ) } return (pencilHole + label).translateX( -pinDist/2 + pinDist / denominator ) } }