2013-05-13 18:15:45 +00:00
|
|
|
|
package Slic3r::GCode::SpiralVase;
|
|
|
|
|
use Moo;
|
|
|
|
|
|
2013-07-29 15:28:30 +00:00
|
|
|
|
has 'config' => (is => 'ro', required => 1);
|
2014-02-13 00:00:17 +00:00
|
|
|
|
has 'enable' => (is => 'rw', default => sub { 0 });
|
2014-02-13 15:06:52 +00:00
|
|
|
|
has 'reader' => (is => 'ro', default => sub { Slic3r::GCode::Reader->new });
|
2013-07-29 15:28:30 +00:00
|
|
|
|
|
2013-05-13 18:15:45 +00:00
|
|
|
|
use Slic3r::Geometry qw(unscale);
|
|
|
|
|
|
|
|
|
|
sub process_layer {
|
|
|
|
|
my $self = shift;
|
2014-02-13 15:06:52 +00:00
|
|
|
|
my ($gcode) = @_;
|
|
|
|
|
|
|
|
|
|
# This post-processor relies on several assumptions:
|
|
|
|
|
# - all layers are processed through it, including those that are not supposed
|
|
|
|
|
# to be transformed, in order to update the reader with the XY positions
|
|
|
|
|
# - each call to this method includes a full layer, with a single Z move
|
|
|
|
|
# at the beginning
|
|
|
|
|
# - each layer is composed by suitable geometry (i.e. a single complete loop)
|
|
|
|
|
# - loops were not clipped before calling this method
|
2013-05-13 18:15:45 +00:00
|
|
|
|
|
2014-02-13 00:00:17 +00:00
|
|
|
|
# if we're not going to modify G-code, just feed it to the reader
|
|
|
|
|
# in order to update positions
|
|
|
|
|
if (!$self->enable) {
|
2014-02-13 15:06:52 +00:00
|
|
|
|
$self->reader->parse($gcode, sub {});
|
2014-02-13 00:00:17 +00:00
|
|
|
|
return $gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# get total XY length for this layer by summing all extrusion moves
|
2013-05-13 18:15:45 +00:00
|
|
|
|
my $total_layer_length = 0;
|
2014-02-13 15:06:52 +00:00
|
|
|
|
my $layer_height = 0;
|
2014-02-13 00:00:17 +00:00
|
|
|
|
my $z = undef;
|
2014-02-13 15:06:52 +00:00
|
|
|
|
$self->reader->clone->parse($gcode, sub {
|
2013-05-13 18:15:45 +00:00
|
|
|
|
my ($reader, $cmd, $args, $info) = @_;
|
2014-02-13 00:00:17 +00:00
|
|
|
|
|
|
|
|
|
if ($cmd eq 'G1') {
|
2014-02-13 15:06:52 +00:00
|
|
|
|
if ($info->{extruding}) {
|
|
|
|
|
$total_layer_length += $info->{dist_XY};
|
|
|
|
|
} elsif (exists $args->{Z}) {
|
|
|
|
|
$layer_height += $info->{dist_Z};
|
|
|
|
|
$z //= $args->{Z};
|
|
|
|
|
}
|
2014-02-13 00:00:17 +00:00
|
|
|
|
}
|
2013-05-13 18:15:45 +00:00
|
|
|
|
});
|
|
|
|
|
|
2014-02-13 15:06:52 +00:00
|
|
|
|
#use XXX; YYY [ $gcode, $layer_height, $z, $total_layer_length ];
|
2014-02-13 00:00:17 +00:00
|
|
|
|
# remove layer height from initial Z
|
|
|
|
|
$z -= $layer_height;
|
|
|
|
|
|
2014-02-13 15:06:52 +00:00
|
|
|
|
my $new_gcode = "";
|
|
|
|
|
$self->reader->parse($gcode, sub {
|
2013-05-13 18:15:45 +00:00
|
|
|
|
my ($reader, $cmd, $args, $info) = @_;
|
|
|
|
|
|
|
|
|
|
if ($cmd eq 'G1' && exists $args->{Z}) {
|
2014-02-13 00:00:17 +00:00
|
|
|
|
# if this is the initial Z move of the layer, replace it with a
|
|
|
|
|
# (redundant) move to the last Z of previous layer
|
2013-05-13 18:15:45 +00:00
|
|
|
|
my $line = $info->{raw};
|
2014-02-13 15:06:52 +00:00
|
|
|
|
$line =~ s/ Z[.0-9]+/ Z$z/;
|
2013-05-13 18:15:45 +00:00
|
|
|
|
$new_gcode .= "$line\n";
|
2013-07-28 11:39:15 +00:00
|
|
|
|
} elsif ($cmd eq 'G1' && !exists $args->{Z} && $info->{dist_XY}) {
|
2014-02-13 00:00:17 +00:00
|
|
|
|
# horizontal move
|
2013-05-13 18:15:45 +00:00
|
|
|
|
my $line = $info->{raw};
|
2013-07-28 11:39:15 +00:00
|
|
|
|
if ($info->{extruding}) {
|
|
|
|
|
$z += $info->{dist_XY} * $layer_height / $total_layer_length;
|
|
|
|
|
$line =~ s/^G1 /sprintf 'G1 Z%.3f ', $z/e;
|
|
|
|
|
$new_gcode .= "$line\n";
|
|
|
|
|
} else {
|
|
|
|
|
$new_gcode .= "$line\n";
|
|
|
|
|
}
|
2013-05-13 18:15:45 +00:00
|
|
|
|
} else {
|
|
|
|
|
$new_gcode .= "$info->{raw}\n";
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return $new_gcode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|