import static uk.co.nickthecoder.foocad.along.v2.Along.* import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* /** A simple junction box with three inlets. */ class JunctionBox : Model { var size = Vector2( 60, 45 ) var depth = 13 var cableSize = Vector2( 8, 5 ) var thickness = 0.8 fun profile() = Square( size ).center().roundAllCorners(5) fun rounded( size : Vector2 ) = Square( size ).center() .roundAllCorners( Math.min( size.x, size.y ) / 2 ) @Piece fun base() : Shape3d { val profile = profile() val base = ExtrusionBuilder().apply { crossSection( profile ) forward( depth ) crossSection() crossSection( - thickness ) forward ( -depth + thickness ) crossSection() }.build() val hole = rounded(cableSize).extrude( thickness * 3 ) .alongX2().center() .bottomTo( thickness + 5 ) val slab = ( Cube( 7,18, 6 ).centerXY() - Cylinder(30,1.5).center().translateY(5).mirrorY().also() ).translate(10,0,thickness) val holes = holes( slab remove hole ) val post = Cylinder(depth-thickness,3) - Cylinder(depth*3,1.5).center() return base and holes and post } fun holes ( hole : Shape3d ) : Shape3d { return hole.mirrorX().translateX(size.x/2).translateY(10).mirrorY().also().withCavities() and hole.translateX(-size.x/2) } @Piece fun cover() : Shape3d { val profile = profile() val cover = profile.extrude(thickness) + ( profile.offset(-thickness-0.3) - profile.offset( -thickness*2 - 0.3 ) ).extrude(8) val gap = rounded( cableSize + Vector2(3, 3) ).extrude( 20 ) .alongX2().center() .bottomTo( thickness + 2 ) val gaps = holes( gap ) val hole = Cylinder(10,1.5).center() return cover - hole - gaps } @Piece fun bar() = Cube(7,18,2).centerXY() - Cylinder(30,1.5).centerXY().translateY(5).bottomTo(0.2).mirrorY().also() override fun build() : Shape3d { return base() + bar().translateX(size.x/2+4).tileX(3,1) + cover().rightTo(-size.x/2-1) } }