From d074b98aba60c385ca298086661f764abdc298dd Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 5 Jul 2013 15:03:08 +0200 Subject: [PATCH] Optimization: don't store wipe path if wipe is not requested --- lib/Slic3r/GCode.pm | 18 +++++++++++++++--- lib/Slic3r/Print.pm | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index 5b7ca6d7..2d6e27f8 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -8,7 +8,9 @@ use Slic3r::Geometry::Clipper qw(union_ex); use Slic3r::Surface ':types'; has 'config' => (is => 'ro', required => 1); -has 'multiple_extruders' => (is => 'ro', default => sub {0} ); +has 'extruders' => (is => 'ro', default => sub {0}, required => 1); +has 'multiple_extruders' => (is => 'lazy'); +has 'enable_wipe' => (is => 'lazy'); # at least one extruder has wipe enabled has 'layer_count' => (is => 'ro', required => 1 ); has 'layer' => (is => 'rw'); has '_layer_overhangs' => (is => 'rw'); @@ -63,6 +65,16 @@ my %role_speeds = ( &EXTR_ROLE_GAPFILL => 'gap_fill', ); +sub _build_multiple_extruders { + my $self = shift; + return @{$self->extruders} > 1; +} + +sub _build_enable_wipe { + my $self = shift; + return (first { $_->wipe } @{$self->extruders}) ? 1 : 0; +} + sub set_shift { my $self = shift; my @shift = @_; @@ -205,7 +217,7 @@ sub extrude_loop { # extrude along the path my $gcode = join '', map $self->extrude_path($_, $description, %params), @paths; - $self->wipe_path($extrusion_path->polyline); + $self->wipe_path($extrusion_path->polyline) if $self->enable_wipe; # make a little move inwards before leaving loop if ($loop->role == EXTR_ROLE_EXTERNAL_PERIMETER && $self->config->perimeters > 1) { @@ -296,7 +308,7 @@ sub extrude_path { $gcode .= $self->G1($line->[B], undef, $e * $line_length, $description); } $self->wipe_path(Slic3r::Polyline->new(reverse @{$path->points})) - if $self->extruder->wipe; + if $self->enable_wipe; } if ($self->config->cooling) { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index d62e84f0..53119758 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -711,7 +711,7 @@ sub write_gcode { # set up our extruder object my $gcodegen = Slic3r::GCode->new( config => $self->config, - multiple_extruders => (@{$self->extruders} > 1), + extruders => $self->extruders, layer_count => $self->layer_count, ); print $fh "G21 ; set units to millimeters\n" if $Slic3r::Config->gcode_flavor ne 'makerware';