From 8ae96a8868cd36e44c0520afccc38e42f0fabc4a Mon Sep 17 00:00:00 2001
From: Alessandro Ranellucci <aar@cpan.org>
Date: Wed, 21 Nov 2012 19:00:43 +0100
Subject: [PATCH] Only apply vibration limit to gaps fill while it's not very
 mature to work with long segments

---
 lib/Slic3r/ExtrusionPath.pm | 3 ++-
 lib/Slic3r/GCode.pm         | 7 ++++++-
 lib/Slic3r/Layer/Region.pm  | 2 +-
 3 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/lib/Slic3r/ExtrusionPath.pm b/lib/Slic3r/ExtrusionPath.pm
index d392b5c40..81d79fa97 100644
--- a/lib/Slic3r/ExtrusionPath.pm
+++ b/lib/Slic3r/ExtrusionPath.pm
@@ -6,7 +6,7 @@ our @ISA = qw(Exporter);
 our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_SMALLPERIMETER EXTR_ROLE_EXTERNAL_PERIMETER 
     EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER
     EXTR_ROLE_FILL EXTR_ROLE_SOLIDFILL EXTR_ROLE_TOPSOLIDFILL EXTR_ROLE_BRIDGE EXTR_ROLE_SKIRT 
-    EXTR_ROLE_SUPPORTMATERIAL);
+    EXTR_ROLE_SUPPORTMATERIAL EXTR_ROLE_GAPFILL);
 our %EXPORT_TAGS = (roles => \@EXPORT_OK);
 
 use Slic3r::Geometry qw(PI X Y epsilon deg2rad rotate_points);
@@ -33,6 +33,7 @@ use constant EXTR_ROLE_TOPSOLIDFILL                 => 6;
 use constant EXTR_ROLE_BRIDGE                       => 7;
 use constant EXTR_ROLE_SKIRT                        => 8;
 use constant EXTR_ROLE_SUPPORTMATERIAL              => 9;
+use constant EXTR_ROLE_GAPFILL                      => 10;
 
 use constant PACK_FMT => 'ffca*';
 
diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm
index e25479e46..3daa3ca74 100644
--- a/lib/Slic3r/GCode.pm
+++ b/lib/Slic3r/GCode.pm
@@ -26,6 +26,7 @@ has 'last_path'          => (is => 'rw');
 has 'dec'                => (is => 'ro', default => sub { 3 } );
 
 # used for vibration limit:
+has 'limit_frequency'    => (is => 'rw', default => sub { 0 });
 has 'last_dir'           => (is => 'ro', default => sub { [0,0] });
 has 'segment_time'       => (is => 'ro', default => sub { [ [0,0,0], [0,0,0] ] });
 
@@ -51,6 +52,7 @@ my %role_speeds = (
     &EXTR_ROLE_BRIDGE                       => 'bridge',
     &EXTR_ROLE_SKIRT                        => 'perimeter',
     &EXTR_ROLE_SUPPORTMATERIAL              => 'perimeter',
+    &EXTR_ROLE_GAPFILL                      => 'solid_infill',
 );
 
 sub set_shift {
@@ -165,6 +167,9 @@ sub extrude_path {
         }
     }
     
+    # only apply vibration limiting to gap fill until the algorithm is more mature
+    $self->limit_frequency($path->role == EXTR_ROLE_GAPFILL);
+    
     # go to first point of extrusion path
     $self->speed('travel');
     $gcode .= $self->G0($path->points->[0], undef, 0, "move to first $description point")
@@ -327,7 +332,7 @@ sub _G0_G1 {
         $gcode .= sprintf " X%.${dec}f Y%.${dec}f", 
             ($point->x * &Slic3r::SCALING_FACTOR) + $self->shift_x - $self->extruder->extruder_offset->[X], 
             ($point->y * &Slic3r::SCALING_FACTOR) + $self->shift_y - $self->extruder->extruder_offset->[Y]; #**
-        $speed_factor = $self->_limit_frequency($point);
+        $speed_factor = $self->_limit_frequency($point) if $self->limit_frequency;
         $self->last_pos($point->clone);
     }
     if (defined $z && (!defined $self->z || $z != $self->z)) {
diff --git a/lib/Slic3r/Layer/Region.pm b/lib/Slic3r/Layer/Region.pm
index 52b98abc5..98bcc15a1 100644
--- a/lib/Slic3r/Layer/Region.pm
+++ b/lib/Slic3r/Layer/Region.pm
@@ -283,7 +283,7 @@ sub make_perimeters {
                             }
                             map Slic3r::ExtrusionPath->new(
                                 polyline        => Slic3r::Polyline->new(@$_),
-                                role            => EXTR_ROLE_SOLIDFILL,
+                                role            => EXTR_ROLE_GAPFILL,
                                 height          => $self->height,
                                 flow_spacing    => $params->{flow_spacing},
                             ), @paths;