Exit Full View
Up

/Bike/BikeRackClip.foocad

BikeRackClip
FooCAD Source Code
import uk.co.nickthecoder.foocad.smartextrusion.v1.*
import static uk.co.nickthecoder.foocad.smartextrusion.v1.SmartExtrusion.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
import uk.co.nickthecoder.foocad.screws.v3.*
import uk.co.nickthecoder.foocad.extras.v1.*
import static uk.co.nickthecoder.foocad.extras.v1.Extras.*

class BikeRackClip : Model {

    var size = Vector3( 100, 20, 0.9 )

    var prongSize = Vector2( 30, 10 )

    var blockSize = Vector2( 30, 10 )

    var gap = 60

    var countersink = Countersink()

    var radius = 3

    var runnerSize = Vector3( 16, 12, 2 )
    var runnerBlockSize = Vector3( 0, 14, 4 )

    @Piece
    meth runner() : Shape3d {

        val profile = Square( runnerSize.z + runnerBlockSize.z, runnerSize.y + runnerBlockSize.y ) -
            Square( runnerBlockSize.z, runnerSize.y  )
                .roundCorner(2,runnerBlockSize.z)
                .toPolygon()

        val main = profile
            .extrude( runnerSize.x )
            .rotateY(90)
            .bottomTo(0)
            .centerXY()

        val envelope = Square( runnerSize.x, runnerSize.y + runnerBlockSize.y )
            .roundAllCorners( 4 )
            .extrude( runnerSize.z + runnerBlockSize.z + 2 )
            .centerXY().bottomTo(-1)

        val holes = countersink.mirrorZ()
            .spreadX(3,main.size.x, 0.25)
            .centerX()
            //.centerYTo(main.back - runnerBlockSize.y/2)
            .frontTo( main.front + runnerSize.y )

        return main.intersection( envelope ) //- holes
    }

    @Piece
    meth clip() : Shape3d {
        val base = Square( size.x, size.y )
            .centerY()
            .roundCorner( 3, radius )
            .roundCorner( 0, radius )
            .extrude( size.z )

        val prongProfile = Triangle( prongSize.x, prongSize.y, -1 ) -
            Square( 7, 4 )
                .frontTo( 1 )
                .leftTo( 2 )
        val prong = prongProfile
            .extrude( size.y )
            .rotateX(90)
            .bottomTo( size.z )
            .centerY()
            .rightTo( base.right )

        val block = Square( blockSize.x, size.y )
            .centerY()
            .roundAllCorners( radius )
            .extrude( blockSize.y )

        val holes = countersink.mirrorZ()
            .centerXTo( blockSize.x / 4 )
            .centerXTo( blockSize.x * 3 / 4 ).also()

        return base + prong //+ block - holes
    }

    @Piece
    meth lever() : Shape3d {
            
        val leverProfile = Square( 8, 100 ).centerX() +
            Square( 20, 30 )
                .centerX()
                .roundAllCorners(5) +
            Square( 14, 4 )
                .centerX()
                .roundAllCorners(1)
                .translateY( 50 ).translateY(-12).also().translateY(24).also()
    
        val lever = leverProfile
            .smartExtrude( 3 )
            .bottom( Chamfer(1) )
            .top( Fillet( 1 ) )

        // Not used any more
        val spine = Square( 3, lever.size.y - 24 )
            .roundAllCorners(1)
            .smartExtrude( 6 )
            .top( Fillet(1) )
            .centerX()
            .backTo(lever.back-3)

        val tip = Square( 5, size.y/2 + 1 ).centerX().frontTo(lever.back-2)
            .extrude( 3 )

        return (lever + tip).color("Green")
    }
    
    meth pivotProfile() = Square( 40, 10 )
            .roundAllCorners(2)
            .center()

    @Piece
    meth pivot() : Shape3d {

        val main = pivotProfile()
            .smartExtrude(14)

        val crossProfile = Square( 10, 20 ).center() +
            Square( 16, 5).center()
        val cross = crossProfile
            .extrude( 8 )
            .topTo( main.top + 0.1 )

        val holes = countersink
            .topTo(main.top+2)
            .centerXTo( main.left + 6 )
            .mirrorX().also()

        return main - cross - holes
    }

    @Piece
    meth pivotLid() : Shape3d {
        val main = pivotProfile().extrude(2)
        val holes = countersink
            .topTo(main.top)
            .centerXTo( main.left + 6 )
            .mirrorX().also()

        return (main - holes).color("Orange").darker()
    }

    @Piece( printable = false )
    override meth build() : Shape3d {
        val clip = clip().centerX()
        val lever = lever().mirrorZ()
            .backTo(-2)
            .translate( 25.5, 0, 6 )
            .rotateX(2.5)

        val pivot = pivot()
        val lid = pivotLid().bottomTo(pivot.top)

        val pivotAndLid = (pivot + lid)
            .mirrorZ()
            .centerXTo( lever.middle.x )
            .centerYTo(-59)
            .topTo(clip.top)

        val runner = runner()
            .leftTo(60)
            .frontTo( clip.back + 10 ).mirrorY().also()

        return clip + lever + pivotAndLid + runner
    }
}