Fixed wipe (includes regression test). #1421

This commit is contained in:
Alessandro Ranellucci 2013-09-06 19:14:06 +02:00
parent e02ae0d18a
commit 4dd12b57a1
3 changed files with 26 additions and 9 deletions

View File

@ -244,7 +244,7 @@ sub extrude_loop {
# extrude along the path
my $gcode = join '', map $self->extrude_path($_, $description, %params), @paths;
$self->wipe_path($extrusion_path->polyline) if $self->enable_wipe;
$self->wipe_path($extrusion_path->polyline->clone) if $self->enable_wipe;
# make a little move inwards before leaving loop
if ($loop->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->layer->object->config->perimeters > 1) {
@ -351,7 +351,7 @@ sub extrude_path {
$local_F = 0;
}
if ($self->enable_wipe) {
$self->wipe_path($path->polyline);
$self->wipe_path($path->polyline->clone);
$self->wipe_path->reverse;
}
}
@ -468,6 +468,7 @@ sub retract {
# wipe
my $wipe_path;
if ($self->extruder->wipe && $self->wipe_path) {
my @points = @{$self->wipe_path};
$wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}])
->clip_start($self->extruder->scaled_wipe_distance);
}

View File

@ -112,23 +112,24 @@ sub clip_start {
my $self = shift;
my ($distance) = @_;
my @points = @$self;
my $points = [ $self->[0] ];
for (my $i = 1; $distance > 0 && $i <= $#$self; $i++) {
my $point = $self->[$i];
my $segment_length = $point->distance_to($self->[$i-1]);
for (my $i = 1; $distance > 0 && $i <= $#points; $i++) {
my $point = $points[$i];
my $segment_length = $point->distance_to($points[$i-1]);
if ($segment_length <= $distance) {
$distance -= $segment_length;
push @$points, $point;
next;
}
my $new_point = Slic3r::Geometry::point_along_segment($self->[$i-1], $point, $distance);
push @$points, Slic3r::Point->new($new_point);
my $new_point = Slic3r::Geometry::point_along_segment($points[$i-1], $point, $distance);
push @$points, Slic3r::Point->new(@$new_point);
$distance = 0;
}
return __PACKAGE__->new($points);
return __PACKAGE__->new(@$points);
}
# this method returns a collection of points picked on the polygon contour

View File

@ -1,4 +1,4 @@
use Test::More tests => 1;
use Test::More tests => 2;
use strict;
use warnings;
@ -9,6 +9,7 @@ BEGIN {
use Slic3r;
use Slic3r::Geometry qw(scale);
use Slic3r::Test;
{
my $gcodegen = Slic3r::GCode->new(
@ -20,4 +21,18 @@ use Slic3r::Geometry qw(scale);
is_deeply $gcodegen->last_pos->arrayref, [scale -10, scale -10], 'last_pos is shifted correctly';
}
{
my $config = Slic3r::Config->new_from_defaults;
$config->set('wipe', [1]);
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
my $have_wipe = 0;
Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub {
my ($self, $cmd, $args, $info) = @_;
$have_wipe = 1 if $info->{retracting} && $info->{dist_XY} > 0;
});
ok $have_wipe, "wipe";
}
__END__