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.* import static uk.co.nickthecoder.foocad.arrange.v1.Arrange.* import uk.co.nickthecoder.foocad.threaded.v2.* import static uk.co.nickthecoder.foocad.threaded.v2.Thread.* class StandardThreads : Model { @Custom var threadDiameter = 10 fun thread() = Thread( threadDiameter ) @Piece fun bolt() = bolt(thread()) fun bolt(thread:Thread) : Shape3d { val bolt = thread.bolt( thread.nutHeight + 4 ) val dots = Square(1.6).center() .repeatCircular( bolt.size.x * 0.32 - 0.5, thread.diameter ) .extrude( 0.6 ) return bolt - dots.color("Red") } @Piece fun nut() = nut(thread()) fun nut(thread:Thread) = thread.nut() @Piece fun boltInNut() : Shape3d { val thread = thread() val bolt = thread.bolt( thread.nutHeight + 4 ) val nut = nut().translateZ( thread.headSize.y ) return nut + bolt } @Piece fun washer() = washer(thread()) fun washer(thread:Thread) = thread.washer() @Piece fun rod() = rod(thread()) fun rod(thread:Thread) = thread.threadedRod( thread.diameter * 1.5 ) @Piece fun completeSet() : Shape3d { var all : Shape3d = Union3d() for (diameter in 4 to 12 step 2) { val thread = Thread(diameter) all = all + arrangeX( 2, bolt(thread), nut(thread), washer(thread) ).frontTo( all.back + 2 ) } return all.centerXY() } @Piece fun washers() : Shape3d { var all : Shape3d = Union3d() for (diameter in 4 to 12 step 2) { val thread = Thread(diameter) all = all + washer(thread).frontTo( all.back + 2 ) } return all.centerXY() } @Piece fun holder() : Shape3d { var block : Shape2d = ( Circle( 6 ) hull Circle( 6 ).translateX(-12) ) hull ( Circle( 12 ).translateY( 70 ) hull Circle( 12 ).translate( -16, 70 ) ) var bolts : Shape3d = Cube(0) var text : Shape2d = Square(0) var y = 0 for (diameter in 4 to 12 step 2 ) { val thread = Thread(diameter) val cutout = Circle( thread.diameter/2 * 1.1 + 0.5 ) .translateY( y ) block -= cutout bolts += bolt( thread ) .mirrorZ() .centerZ() .translateY( y ) .topTo( 2 + thread.headSize.y ) text += Text( "$diameter" ).centerX() .rotate(90) .translate( -thread.headSize.x * 0.6 - 2, y ) y += thread.headSize.x * 1.2 + 4 } return block.extrude( 1.2 ) - text.extrude(1).topTo(2) + bolts.previewOnly() } override fun build() : Shape3d { return completeSet().rightTo(-2) + holder().centerY().leftTo(2) } }