import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* import static uk.co.nickthecoder.foocad.arrange.v1.Arrange.* include RightAngle.foocad include Clamp.foocad include CornerClampHelper.foocad class ClampsInsert : Model { val baseThickness = 0.8 val cornerSize = 12 val cornerThickness = 4 val clearance = 1.0 meth corner( height : double ) : Shape3d { val shape = ( Square( cornerSize ).translate( -cornerThickness, -cornerThickness ) - Square( cornerSize ) ).toPolygon().roundCorners(listOf(5,4,3,2,0),1) return shape.extrude( height ) } meth corners( width : double, depth : double, height : double ) : Shape3d { val corner = corner( height ) val h = corner.mirrorX().translateX( width + clearance ).also(2) return (h.mirrorY().translateY( depth + clearance ).also(2)) .margin( -cornerThickness, -cornerThickness, 0 ) } meth cornersThree( width : double, depth : double, height : double ) : Shape3d { val corner = corner( height ) val h = corner.mirrorX().translateX( width + clearance ).also(2) return (h + corner.mirrorY().translateY( depth + clearance )) .margin( -cornerThickness, -cornerThickness, 0 ) } meth withCorners( height : double, example : Shape3d ) : Shape3d { return example.previewOnly() + corners( example.size.x, example.size.y, height ) .leftTo( example.left ).frontTo(example.front) } meth withCornersThree( height : double, example : Shape3d ) : Shape3d { return example.previewOnly() + cornersThree( example.size.x, example.size.y, height ) .leftTo( example.left ).frontTo(example.front) } meth withCornersThreeB( height : double, example : Shape3d ) : Shape3d { return example.previewOnly() + cornersThree( example.size.x, example.size.y, height ) .mirrorX() .leftTo( example.left ).frontTo(example.front) } meth withCornersThreeC( height : double, example : Shape3d ) : Shape3d { return example.previewOnly() + cornersThree( example.size.x, example.size.y, height ) .rotateZ(180) .leftTo( example.left ).frontTo(example.front) } meth withCornersThreeD( height : double, example : Shape3d ) : Shape3d { return example.previewOnly() + cornersThree( example.size.x, example.size.y, height ) .mirrorY() .leftTo( example.left ).frontTo(example.front) } meth dividerShape() : Shape2d { return Square( cornerThickness, cornerSize ) .roundCorner(3,1).roundCorner(2,1).frontTo(-cornerThickness) + Square( cornerSize, cornerThickness ).roundAllCorners(1) .centerXTo( cornerThickness/2 ).frontTo(-cornerThickness) } meth inRow( count : int, height : double, example : Shape3d ) : Shape3d { val width = example.size.x val dx = width + cornerThickness + clearance val cornersWidth = dx * (count-1) + width val divider = dividerShape() .extrude( height ) .translate( example.left + dx - cornerThickness, example.front, 0 ) val dividers = divider.repeatX( count-1, dx ) .mirrorY().backTo( example.back + cornerThickness + clearance ).also(2) val examples = example.previewOnly()//.repeatX( count, dx ) return examples + dividers + corners( cornersWidth, example.size.y, height ) .translateX( example.left ).translateY( example.front ) } meth inColumn( count : int, height : double, example : Shape3d ) : Shape3d { val depth = example.size.y val dy = depth + cornerThickness + clearance val cornersDepth = dy * (count-1) + depth val divider = dividerShape().rotate(-90).translateY(cornerThickness) .extrude( height ) .translate( example.left, example.front + dy - cornerThickness, 0 ) val dividers = divider.repeatY( count-1, dy ) .mirrorX().rightTo( example.right + cornerThickness + clearance ).also(2) val examples = example.previewOnly()//.repeatY( count, dy ) return examples + dividers + corners( example.size.x, cornersDepth, height ) .translateX( example.left ).translateY( example.front ) } override fun build() : Shape3d { val largeClamp = Clamp().apply { size = Vector2(80,100) thickness = 18 threadDiameter = 12 }.clamp() .rotateZ(180).frontTo(5).rightTo(0) .tileZ(2,clearance) val mediumClamp = Clamp().apply { size = Vector2(40,50) thickness = 18 threadDiameter = 12 }.clamp() .mirrorY() .frontTo( largeClamp.front ).leftTo( largeClamp.right + clearance + cornerThickness ) .tileZ(2,clearance) val smallClamp = Clamp().apply { }.preview() .rotateY(90).bottomTo(0).rotateZ(-90) .frontTo( largeClamp.front + 46 ).leftTo( largeClamp.left + 18 + clearance + cornerThickness ) val smallRightAngles = RightAngle().apply { size = Vector3( 80, 60, 7 ) width = 12 }.build().rotateZ(90).mirrorY() .rightTo(mediumClamp.right).frontTo( mediumClamp.back + cornerThickness+clearance ) .tileZ(4,clearance) val tinyRightAngles = RightAngle().apply { size = Vector3( 40, 30, 7 ) width = 10 }.build().rotateZ(90).mirrorY() .leftTo(smallRightAngles.left + 10 ).backTo( smallRightAngles.back - 28 ) .tileZ(4,clearance) val cch = CornerClampHelper().build()//.rotateZ(90) .leftTo( largeClamp.left ) .backTo( smallRightAngles.back ) .tileZ(2,clearance) val base = Square( mediumClamp.right - largeClamp.left, smallRightAngles.back - mediumClamp.front ) .offset( cornerThickness + clearance ) .roundAllCorners(1) .leftTo( largeClamp.left - cornerThickness ) .frontTo( largeClamp.front - cornerThickness ) .extrude( baseThickness ) .color("Green") val all = withCornersThree( 32, largeClamp ) + withCornersThreeB( 32, mediumClamp ) + inColumn( 4, 10, smallClamp ) + withCornersThreeC( 30, tinyRightAngles ) + withCornersThreeC( 30, smallRightAngles ) + inRow( 2, 32, cch ) return base + all.bottomTo( baseThickness ) } }