1
package Slic3r::GCode::Reader;
4
has 'X' => (is => 'rw', default => sub {0});
5
has 'Y' => (is => 'rw', default => sub {0});
6
has 'Z' => (is => 'rw', default => sub {0});
7
has 'E' => (is => 'rw', default => sub {0});
8
has 'F' => (is => 'rw', default => sub {0});
11
my @AXES = qw(X Y Z E);
15
return (ref $self)->new(
16
map { $_ => $self->$_ } (@AXES, 'F'),
22
my ($gcode, $cb) = @_;
24
foreach my $raw_line (split /\R+/, $gcode) {
25
print "$raw_line\n" if $Verbose || $ENV{SLIC3R_TESTS_GCODE};
27
$line =~ s/\s*;(.*)//; # strip comment
28
my %info = (comment => $1, raw => $raw_line);
31
my ($command, @args) = split /\s+/, $line;
33
my %args = map { /([A-Z])(.*)/; ($1 => $2) } @args;
36
if ($command =~ /^G[01]$/) {
37
foreach my $axis (@AXES) {
38
if (exists $args{$axis}) {
39
$info{"dist_$axis"} = $args{$axis} - $self->$axis;
40
$info{"new_$axis"} = $args{$axis};
42
$info{"dist_$axis"} = 0;
43
$info{"new_$axis"} = $self->$axis;
46
$info{dist_XY} = Slic3r::Geometry::unscale(Slic3r::Line->new_scale([0,0], [@info{qw(dist_X dist_Y)}])->length);
47
if (exists $args{E}) {
48
if ($info{dist_E} > 0) {
50
} elsif ($info{dist_E} < 0) {
59
$cb->($self, $command, \%args, \%info);
62
if ($command =~ /^(?:G[01]|G92)$/) {
63
for my $axis (@AXES, 'F') {
64
$self->$axis($args{$axis}) if exists $args{$axis};
68
# TODO: update temperatures