import static uk.co.nickthecoder.foocad.changefilament.v1.ChangeFilament.* import static uk.co.nickthecoder.foocad.layout.v1.Layout2d.* import static uk.co.nickthecoder.foocad.layout.v1.Layout3d.* include PlantPot.foocad class StripedPlantPot : AbstractModel(), PostProcessor { @Custom var potSize = Vector2(95,90) @Custom var potType = "6" @Custom var potLip = 4.0 @Custom var potThickness = 1.2 @Custom var baseThickness = 2.4 @Custom( lines = 10 ) var colors = """0.7 DarkBlue 2 White 10 Orange 2 White 19 FireBrick 2 White 13 DarkBlue 2 White 19 FireBrick 2 White 10 Orange 2 White 14 DarkBlue 15 White """ @Custom( lines = 3 ) var text = "" var preview = false fun pot() : Shape3d { val pot = PlantPot().apply { type = potType potDiameter = potSize.x potHeight = potSize.y thickness = potThickness lip = potLip showInner = false } pot.baseThickness = baseThickness pot.text = text return pot.build() } var sliceCount = 0 var pot : Shape3d = null var z = 0 var pauses = listOf() fun layer(thickness : double, color: String) : Shape3d { if (sliceCount == 0) { pot = pot() } sliceCount ++ val slice = Cube( pot.size.x*2, pot.size.y*2, thickness ).bottomTo( z ).centerXY() z += thickness pauses.add(z) return (pot.translateX(1).rotateZ(sliceCount*3)/slice).color( color ) } override fun build() = create( false ) @Piece( picture = true ) fun preview() = create( true ) fun create( preview : bool ) : Shape3d { this.preview = preview val slices = listOf() for (line in colors.split("\n")) { val space = line.indexOf(" ") //println( "Line : $line space=$space" ) if ( space > 0 ) { val h = line.substring(0, space).toDouble() val color = line.substring(space).trim() val layer = layer( h, color ) slices.add(layer) } } //println( "Pauses : $pauses" ) return if (preview) { Union3d( slices ) } else { pot } } override fun postProcess(gcode: GCode) { if ( !preview ) { val top = pot.size.z for ( p in pauses ) { if (p < top ) pauseAtHeight( gcode, p, "Change Filament" ) } } } }