FooCAD Source Codeimport static uk.co.nickthecoder.foocad.layout.v1.Layout2d.*
import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.*
import static uk.co.nickthecoder.foocad.changefilament.v1.ChangeFilament.*
import static uk.co.nickthecoder.foocad.chamferedextrude.v1.ChamferedExtrude.*
include Jigsaw.feather
/**
Ensure Retract Lift is set to 0 in slicer settings, otherwise the change of filaments will be too early.
Broken : 8
*/
class SVGJigsaw : Model {
@Custom
var svgFilename = "HappyMothersDay.svg"
@Custom( about="The number of pieces in the X direction" )
var across = 6
@Custom( about="The number of pieces in the Y direction" )
var down = 8
// NOTE, The default bobble size, cornerVariance and bobbleVariance can cause holes to get too close
// and therefore the piece is weak (or completely broken).
// So check the pieces, and either try a new random seed, or reduce the variances.
// Also, sometimes, the chamfer fails for some pieces. Beware!
@Custom( about="The random seed - changes the 'cut'." )
var seed = 1
@Custom( about="Which pieces to print (see toPiece)")
var fromPiece = 0
@Custom( about="Which pieces to print (see toPiece)")
var toPiece = across * down - 1
@Custom( about="How many pieces to print per row" )
var piecesPerRow = 6
fun makeJigsaw() : Jigsaw {
val svg = SVGDocument( svgFilename )
val outline = svg["outline"]
val pattern = svg["pattern"].translate(-outline.corner)
val carving = svg["carving"].translate(-outline.corner)
println( "Outline = ${outline.corner} : ${outline.size}" )
println( "Pattern = ${pattern.corner} : ${pattern.size}" )
println( "Carving = ${carving.corner} : ${carving.size}" )
val jigsaw = Jigsaw( outline.toOrigin(), pattern, carving, across, down ).apply {
random = Random( seed )
blunt = 0.75
chamfer = 0.4
kerf = 0.25
}
return jigsaw
}
@Piece
fun print() : Shape3d {
val jigsaw = makeJigsaw()
jigsaw.cut()
return jigsaw.build(fromPiece, toPiece, piecesPerRow)
}
/*
@Piece
fun bodge() : Shape3d {
val jigsaw = makeJigsaw()
jigsaw.cut()
return jigsaw.buildPieces(listOf<int>(8, 18), piecesPerRow)
}
*/
override fun build() : Shape3d {
val jigsaw = makeJigsaw()
return jigsaw.cut()
}
/*
override fun postProcess(pieceName : String, gcode : GCode) {
println(" Post Process" )
val jigsaw = makeJigsaw()
pauseAtHeight( gcode, jigsaw.thickness-jigsaw.patternHeight, "Change Filament" )
pauseAtHeight( gcode, jigsaw.thickness, "Change Filament" )
}
*/
}