From 82e2dd4e629b16407e88b27e2071cb810a718e4f Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 11 Jun 2014 19:58:11 +0200 Subject: [PATCH] Bugfix: wrong number of raft layers in some situations due to a numerical error --- lib/Slic3r/Print/Object.pm | 5 ++- lib/Slic3r/Print/SupportMaterial.pm | 3 +- t/support.t | 48 ++++++++++++++++++----------- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 55703d72c..f372ecda1 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -106,6 +106,7 @@ sub slice { # make layers taking custom heights into account my $print_z = my $slice_z = my $height = my $id = 0; my $first_object_layer_height = -1; + my $first_object_layer_distance = -1; # add raft layers if ($self->config->raft_layers > 0) { @@ -123,7 +124,8 @@ sub slice { # force first layer print_z according to the contact distance # (the loop below will raise print_z by such height) - $first_object_layer_height = $distance; + $first_object_layer_height = $nozzle_diameter; + $first_object_layer_distance = $distance; } # loop until we have at least one layer and the max slice_z reaches the object height @@ -147,6 +149,7 @@ sub slice { if ($first_object_layer_height != -1 && !@{$self->layers}) { $height = $first_object_layer_height; + $print_z += ($first_object_layer_distance - $height); } $print_z += $height; diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 12f632816..410a763f9 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -338,7 +338,6 @@ sub support_layers_z { # layer_height > nozzle_diameter * 0.75 my $nozzle_diameter = $self->print_config->get_at('nozzle_diameter', $self->object_config->support_material_extruder-1); my $support_material_height = max($max_object_layer_height, $nozzle_diameter * 0.75); - my @z = sort { $a <=> $b } @$contact_z, @$top_z, (map $_ + $nozzle_diameter, @$top_z); # enforce first layer height @@ -352,7 +351,7 @@ sub support_layers_z { # $z[1] is last raft layer (contact layer for the first layer object) my $height = ($z[1] - $z[0]) / ($self->object_config->raft_layers - 1); splice @z, 1, 0, - map { int($_*100)/100 } + map { sprintf "%.2f", $_ } map { $z[0] + $height * $_ } 0..($self->object_config->raft_layers - 1); } diff --git a/t/support.t b/t/support.t index 8939848bb..4a780ddde 100644 --- a/t/support.t +++ b/t/support.t @@ -1,4 +1,4 @@ -use Test::More tests => 16; +use Test::More tests => 18; use strict; use warnings; @@ -130,31 +130,43 @@ use Slic3r::Test; 'first object layer is completely supported by raft'; } -foreach my $raft_layers (2, 70) { +{ my $config = Slic3r::Config->new_from_defaults; $config->set('skirts', 0); - $config->set('raft_layers', $raft_layers); $config->set('layer_height', 0.35); $config->set('first_layer_height', 0.3); $config->set('nozzle_diameter', [0.5]); $config->set('support_material_extruder', 2); $config->set('support_material_interface_extruder', 2); - my $print = Slic3r::Test::init_print('20mm_cube', config => $config); - my %raft_z = (); # z => 1 - my $tool = undef; - Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { - my ($self, $cmd, $args, $info) = @_; - - if ($cmd =~ /^T(\d+)/) { - $tool = $1; - } elsif ($info->{extruding} && $info->{dist_XY} > 0) { - if ($tool == $config->support_material_extruder-1) { - $raft_z{$self->Z} = 1; - } - } - }); - is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated'; + my $test = sub { + my ($raft_layers) = @_; + $config->set('raft_layers', $raft_layers); + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + my %raft_z = (); # z => 1 + my $tool = undef; + Slic3r::GCode::Reader->new->parse(Slic3r::Test::gcode($print), sub { + my ($self, $cmd, $args, $info) = @_; + + if ($cmd =~ /^T(\d+)/) { + $tool = $1; + } elsif ($info->{extruding} && $info->{dist_XY} > 0) { + if ($tool == $config->support_material_extruder-1) { + $raft_z{$self->Z} = 1; + } + } + }); + + is scalar(keys %raft_z), $config->raft_layers, 'correct number of raft layers is generated'; + }; + + $test->(2); + $test->(70); + + $config->set('layer_height', 0.4); + $config->set('first_layer_height', 0.35); + $test->(3); + $test->(70); } __END__