Exit Full View
Up

/Util/TwistLatchSimple.foocad

TwistLatchSimple
FooCAD Source Code
import static uk.co.nickthecoder.foocad.screws.v3.Screws.*
import static uk.co.nickthecoder.foocad.along.v2.Along.*
import uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*

class TwistLatchSimple : Model {

    @Custom
    var latchSize = Vector3(40, 10, 10)

    @Custom
    var diameter = 20

    @Custom
    var holeDiameter = 4

    @Custom
    var countersink = Countersink( 4, 12 )

    @Custom
    var washerThickness = 2.0

    @Custom
    var padThickness = 2.0

    @Custom
    var cornerRadius = 2.0

    @Custom
    var keyholeHanger = KeyholeHanger()

    @Piece
    fun washer() : Shape3d {
        return (Circle( diameter / 2 - 1 ) - Circle( holeDiameter/2 + 1 ))
            .extrude( washerThickness )
            .color( "DarkGrey" )
    }

    @Piece
    fun pad() : Shape3d {
        return Square( latchSize.x - diameter / 2 - 2, latchSize.y ).center()
            .roundAllCorners( cornerRadius )
            .smartExtrude( padThickness )
            .filletTop( padThickness )
            .color( "DarkGrey" )
    }

    @Piece
    fun latch() : Shape3d {
        val latch = Square( latchSize.x, latchSize.y )
            .roundAllCorners( cornerRadius )
            .smartExtrude( latchSize.z )
            .filletTop( cornerRadius )
            .centerY()

        val round = Circle( diameter / 2 )
            .smartExtrude( latchSize.z )
            .filletTop( cornerRadius )

        println( "countersink = $countersink" )
        val hole = countersink.depth( latchSize.z)
            .topTo(latchSize.z)

        return latch + round - hole
    }

    @Piece
    fun keyholeTest() : Shape3d {
        val block = Cube( 10, 30, 40 ).centerXY()
        val keyhole = keyholeHanger
            .alongY2().mirrorZ()
            .frontTo( block.front )
            .translateZ( block.middle.z )

        return block - keyhole
    }

    override fun build() : Shape3d {
        val washer = washer()
        val latch = latch().bottomTo( washer.top ).color("green")
        val pad = pad().rightTo( latch.right ).mirrorZ().bottomTo(0)

        return washer + latch + pad
    }
}