forked from ezrec/uv3dp
/
retract.go
77 lines (57 loc) · 1.57 KB
/
retract.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//
// Copyright (c) 2020 Jason S. McMullan <jason.mcmullan@gmail.com>
//
package main
import (
"github.com/spf13/pflag"
"github.com/nicarran/uv3dp"
)
type RetractCommand struct {
*pflag.FlagSet
RetractHeight float32
RetractSpeed float32
}
func NewRetractCommand() (cmd *RetractCommand) {
cmd = &RetractCommand{
FlagSet: pflag.NewFlagSet("retract", pflag.ContinueOnError),
}
cmd.Float32VarP(&cmd.RetractHeight, "height", "h", 0.0, "Retract height in mm")
cmd.Float32VarP(&cmd.RetractSpeed, "speed", "s", 0.0, "Retract speed in mm/min")
cmd.SetInterspersed(false)
return
}
type retractModifier struct {
uv3dp.Printable
exposure uv3dp.Exposure
}
func (mod *retractModifier) Exposure() (exposure uv3dp.Exposure) {
// Set the bottom and normal retract from the resins
exposure = mod.exposure
return
}
func (mod *retractModifier) LayerExposure(index int) (exposure uv3dp.Exposure) {
bot := mod.Printable.Bottom()
exp := mod.exposure
if index < bot.Count {
exposure = mod.Printable.LayerExposure(index)
} else {
exposure = exp
}
return
}
func (cmd *RetractCommand) Filter(input uv3dp.Printable) (mod uv3dp.Printable, err error) {
exp := input.Exposure()
if cmd.Changed("height") {
TraceVerbosef(VerbosityNotice, " Setting default retract height to %v mm", cmd.RetractHeight)
exp.RetractHeight = cmd.RetractHeight
}
if cmd.Changed("speed") {
TraceVerbosef(VerbosityNotice, " Setting default retract speed to %v mm/min", cmd.RetractSpeed)
exp.RetractSpeed = cmd.RetractSpeed
}
mod = &retractModifier{
Printable: input,
exposure: exp,
}
return
}