Exit Full View
Up

/Tools/GuideHoleBlock.foocad

GuideHoleBlock
FooCAD Source Code
class GuideHoleBlock : Model {
   
    // metric, metric0.5
    var piece = "metric"
 
    var delta = 0.0

    var middle : Shape2d = Circle( 1 )

    val sizes = listOf<double>( 1.0, 2.0, 3.0 ,4.0 ,5.0 ,6.0 ,8.0, 10.0 )

    var radius = 18.0
    var innerR = 14.0
    var clearance = 3

    @Custom
    var height = 10.0

    @Custom
    var chamfer = 1

    fun build2() : Shape3d {

        val holes = listOf<Shape3d>()

        var travel = 0.0
        var textOnBase = false

        for (s in sizes) {
            val size = s as double + delta
            val angle = 360 * travel / ((innerR - size/2) * 2 * Math.PI)
            val circle = Circle.hole( size as double/2 )
            val withChamfer = circle.scale( (size + chamfer) / size )
            val hole = ExtrusionBuilder().apply {
                forward(-0.01)
                crossSection( withChamfer )
                forward( chamfer )
                crossSection( circle )
                forward( height - chamfer*2 )
                crossSection( circle )
                forward( chamfer + 0.02 )
                crossSection( withChamfer )
            }.build()
                .translateX( innerR-size/2 )
                .rotateZ( angle )

            holes.add(hole)

            travel += size + clearance

        }
        

        return ExtrusionBuilder().apply {
            crossSection( Circle( radius - chamfer ) )
            forward(chamfer)
            crossSection( Circle( radius ) )
            forward( height - chamfer*2 )
            crossSection( Circle( radius ) )
            forward(chamfer)
            crossSection( Circle( radius - chamfer ) )
        }.build() - Union3d( holes ) -
            middle.extrude(2).translateZ(height-1) -
            middle.extrude(2).rotateY(180).translateZ(1)
    }

    override fun build() : Shape3d {
        if ( piece == "metric0.5" ) {
            middle = Text( "½", BOLD, 10 ).hAlign(CENTER).center().translateY(2)
            delta = 0.5
            clearance += 2
            
            sizes.remove(10.0)
        }

        return build2()
    }

}