From 662031bc2d6a49d1c3f09bb96e5e3512d51cddb7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 13 Mar 2017 23:47:52 +0100 Subject: [PATCH] Print the brim using the support material extruder if we have a raft. #2957 --- lib/Slic3r/Print/GCode.pm | 6 +++++- t/skirt_brim.t | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/lib/Slic3r/Print/GCode.pm b/lib/Slic3r/Print/GCode.pm index b851f5242..b2187f208 100644 --- a/lib/Slic3r/Print/GCode.pm +++ b/lib/Slic3r/Print/GCode.pm @@ -462,7 +462,11 @@ sub process_layer { # extrude brim if (!$self->_brim_done) { - $gcode .= $self->_gcodegen->set_extruder($self->print->regions->[0]->config->perimeter_extruder-1); + my $extr = $self->print->regions->[0]->config->perimeter_extruder-1; + if (my $o = first { $_->config->raft_layers > 0 } @{$self->objects}) { + $extr = $o->config->support_material_extruder-1; + } + $gcode .= $self->_gcodegen->set_extruder($extr); $self->_gcodegen->set_origin(Slic3r::Pointf->new(0,0)); $self->_gcodegen->avoid_crossing_perimeters->set_use_external_mp(1); $gcode .= $self->_gcodegen->extrude($_, 'brim', $object->config->support_material_speed) diff --git a/t/skirt_brim.t b/t/skirt_brim.t index 9b2a0a126..d6181ba23 100644 --- a/t/skirt_brim.t +++ b/t/skirt_brim.t @@ -1,4 +1,4 @@ -use Test::More tests => 6; +use Test::More tests => 8; use strict; use warnings; @@ -89,6 +89,39 @@ use Slic3r::Test; ok Slic3r::Test::gcode($print), 'successful G-code generation when skirt_height = 0 and skirts > 0'; } +{ + my $config = Slic3r::Config->new_from_defaults; + $config->set('skirts', 0); + $config->set('brim_width', 5); + $config->set('perimeter_extruder', 2); + $config->set('support_material_extruder', 3); + + my $test = sub { + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my $tool = undef; + my $brim_tool = undef; + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd =~ /^T(\d+)/) { + $tool = $1; + } elsif ($cmd eq 'G1' && $info->{extruding} && $info->{dist_XY} > 0) { + if (!defined $brim_tool) { + # first extrusion is brim + $brim_tool = $tool; + } + } + }); + return $brim_tool; + }; + is $test->(), $config->perimeter_extruder-1, + 'brim is printed with the extruder used for the perimeters of first object'; + + $config->set('raft_layers', 1); + is $test->(), $config->support_material_extruder-1, + 'if raft is enabled, brim is printed with the extruder used for it'; +} + { my $config = Slic3r::Config->new_from_defaults; $config->set('layer_height', 0.4);