Skip to content

Commit

Permalink
Add some more program output
Browse files Browse the repository at this point in the history
  • Loading branch information
aligator committed Apr 3, 2021
1 parent a7a245d commit 2aa1f2e
Show file tree
Hide file tree
Showing 11 changed files with 52 additions and 3 deletions.
2 changes: 2 additions & 0 deletions data/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ type GoSliceOptions struct {
// OutputFilePath specifies the path to the output gcode file.
OutputFilePath string

// Logger can be used to redirect the log output to anything you want.
// All output in GoSlice just calls this logger.
Logger *log.Logger
}

Expand Down
1 change: 1 addition & 0 deletions gcode/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ func (g *generator) Generate(layers []data.PartitionedLayer) (string, error) {
maxLayer := len(layers) - 1

for layerNr := range layers {
g.options.GoSlice.Logger.Printf("Render layer %d/%d\n", layerNr, maxLayer)
for _, renderer := range g.renderers {
z := g.options.Print.InitialLayerThickness + data.Micrometer(layerNr)*g.options.Print.LayerThickness
err := renderer.Render(g.builder, layerNr, maxLayer, layers[layerNr], z, g.options)
Expand Down
7 changes: 6 additions & 1 deletion gcode/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/aligator/goslice/data"
"github.com/aligator/goslice/gcode"
"github.com/aligator/goslice/util/test"
"log"
"testing"
)

Expand Down Expand Up @@ -38,7 +39,11 @@ func TestGCodeGenerator(t *testing.T) {

layers := make([]data.PartitionedLayer, 3)

generator := gcode.NewGenerator(&data.Options{}, gcode.WithRenderer(&fakeRenderer{t: t, c: rendererCounter}))
generator := gcode.NewGenerator(&data.Options{
GoSlice: data.GoSliceOptions{
Logger: log.Default(),
},
}, gcode.WithRenderer(&fakeRenderer{t: t, c: rendererCounter}))
generator.Init(nil)
result, err := generator.Generate(layers)

Expand Down
7 changes: 6 additions & 1 deletion goslice.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,18 +125,20 @@ func (s *GoSlice) Process() error {
startTime := time.Now()

// 1. Load model
s.Options.Logger.Printf("Load model %v\n", s.Options.InputFilePath)
models, err := s.Reader.Read(s.Options.InputFilePath)
if err != nil {
return err
}
s.Options.Logger.Printf("Model loaded.\nFace count: %v\nSize: min: %v max %v\n", models.FaceCount(), models.Min(), models.Max())

// 2. Optimize model
var optimizedModel data.OptimizedModel

optimizedModel, err = s.Optimizer.Optimize(models)
if err != nil {
return err
}
s.Options.Logger.Printf("Model optimized\n")

//err = optimizedModel.SaveDebugSTL("test.stl")
//if err != nil {
Expand All @@ -148,6 +150,7 @@ func (s *GoSlice) Process() error {
if err != nil {
return err
}
s.Options.Logger.Printf("Model sliced to %v layers\n", len(layers))

// 4. Modify the layers
// e.g. generate perimeter paths,
Expand All @@ -158,7 +161,9 @@ func (s *GoSlice) Process() error {
if err != nil {
return err
}
s.Options.Logger.Printf("Modifier %s applied\n", m.GetName())
}
s.Options.Logger.Printf("Layers modified %v\n", len(layers))

// 5. generate gcode from the layers
s.Generator.Init(optimizedModel)
Expand Down
13 changes: 13 additions & 0 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ package handler

import "github.com/aligator/goslice/data"

type Namer interface {
GetName() string
}

type Named struct {
Name string
}

func (n Named) GetName() string {
return n.Name
}

// ModelReader reads a model from a file.
type ModelReader interface {
Read(filename string) (data.Model, error)
Expand All @@ -21,6 +33,7 @@ type ModelSlicer interface {

// LayerModifier can add new attributes to the layers or even alter the layer directly.
type LayerModifier interface {
Namer
Init(m data.OptimizedModel)
Modify(layers []data.PartitionedLayer) error
}
Expand Down
4 changes: 4 additions & 0 deletions modifier/brim.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type brimModifier struct {
handler.Named
options *data.Options
}

Expand All @@ -25,6 +26,9 @@ func (m brimModifier) Init(model data.OptimizedModel) {}
// "outerBrim" just contains the outline of the brim (taking into account the line width also).
func NewBrimModifier(options *data.Options) handler.LayerModifier {
return &brimModifier{
Named: handler.Named{
Name: "Brim",
},
options: options,
}
}
Expand Down
4 changes: 4 additions & 0 deletions modifier/infill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type infillModifier struct {
handler.Named
options *data.Options
}

Expand All @@ -16,6 +17,9 @@ func (m infillModifier) Init(model data.OptimizedModel) {}
// NewInfillModifier calculates the areas which need infill and passes them as "bottom" attribute to the layer.
func NewInfillModifier(options *data.Options) handler.LayerModifier {
return &infillModifier{
Named: handler.Named{
Name: "Infill",
},
options: options,
}
}
Expand Down
4 changes: 4 additions & 0 deletions modifier/internal_infill.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type internalInfillModifier struct {
handler.Named
options *data.Options
}

Expand All @@ -16,6 +17,9 @@ func (m internalInfillModifier) Init(model data.OptimizedModel) {}
// NewInfillModifier calculates the areas which need infill and passes them as "bottom" attribute to the layer.
func NewInternalInfillModifier(options *data.Options) handler.LayerModifier {
return &internalInfillModifier{
Named: handler.Named{
Name: "InternalInfill",
},
options: options,
}
}
Expand Down
4 changes: 4 additions & 0 deletions modifier/perimeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
)

type perimeterModifier struct {
handler.Named
options *data.Options
}

Expand All @@ -16,6 +17,9 @@ type perimeterModifier struct {
// The perimeters are saved as attribute in the LayerPart.
func NewPerimeterModifier(options *data.Options) handler.LayerModifier {
return &perimeterModifier{
Named: handler.Named{
Name: "Perimeter",
},
options: options,
}
}
Expand Down
8 changes: 8 additions & 0 deletions modifier/support.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func FullSupport(layer data.PartitionedLayer) ([]data.LayerPart, error) {
}

type supportDetectorModifier struct {
handler.Named
options *data.Options
}

Expand Down Expand Up @@ -63,6 +64,9 @@ func (m supportDetectorModifier) Init(_ data.OptimizedModel) {}
// All areas that remain have a higher angle than the threshold and need to be supported."
func NewSupportDetectorModifier(options *data.Options) handler.LayerModifier {
return &supportDetectorModifier{
Named: handler.Named{
Name: "SupportDetector",
},
options: options,
}
}
Expand Down Expand Up @@ -108,6 +112,7 @@ func (m supportDetectorModifier) Modify(layers []data.PartitionedLayer) error {
}

type supportGeneratorModifier struct {
handler.Named
options *data.Options
}

Expand All @@ -119,6 +124,9 @@ func (m supportGeneratorModifier) Init(_ data.OptimizedModel) {}
// and removes them from the normal support areas.
func NewSupportGeneratorModifier(options *data.Options) handler.LayerModifier {
return &supportGeneratorModifier{
Named: handler.Named{
Name: "SupportGenerator",
},
options: options,
}
}
Expand Down
1 change: 0 additions & 1 deletion slicer/slicer.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func NewSlicer(options *data.Options) handler.ModelSlicer {

func (s slicer) Slice(m data.OptimizedModel) ([]data.PartitionedLayer, error) {
layerCount := (m.Size().Z()-s.options.Print.InitialLayerThickness)/s.options.Print.LayerThickness + 1
s.options.GoSlice.Logger.Println("layer count:", layerCount)

layers := make([]*layer, layerCount)

Expand Down

0 comments on commit 2aa1f2e

Please sign in to comment.