From 7c8b71012c1c4352b1c394a3fa3d435c24f5f34a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 21 Dec 2015 15:02:39 +0100 Subject: [PATCH] Force the 'nearest' strategy for starting skirt loops --- lib/Slic3r/ExtrusionLoop.pm | 2 +- lib/Slic3r/Print.pm | 7 +++++-- xs/src/libslic3r/ExtrusionEntity.hpp | 1 + xs/src/libslic3r/GCode.cpp | 9 ++++++--- xs/xsp/ExtrusionLoop.xsp | 1 + 5 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/Slic3r/ExtrusionLoop.pm b/lib/Slic3r/ExtrusionLoop.pm index 9b2d77300..f0a857785 100644 --- a/lib/Slic3r/ExtrusionLoop.pm +++ b/lib/Slic3r/ExtrusionLoop.pm @@ -5,7 +5,7 @@ use warnings; use parent qw(Exporter); our @EXPORT_OK = qw(EXTRL_ROLE_DEFAULT - EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER); + EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER EXTRL_ROLE_SKIRT); our %EXPORT_TAGS = (roles => \@EXPORT_OK); diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 95ae87377..053fcdef9 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -5,6 +5,7 @@ use warnings; use File::Basename qw(basename fileparse); use File::Spec; use List::Util qw(min max first sum); +use Slic3r::ExtrusionLoop ':roles'; use Slic3r::ExtrusionPath ':roles'; use Slic3r::Flow ':roles'; use Slic3r::Geometry qw(X Y Z X1 Y1 X2 Y2 MIN MAX PI scale unscale convex_hull); @@ -273,7 +274,7 @@ sub make_skirt { for (my $i = $skirts; $i > 0; $i--) { $distance += scale $spacing; my $loop = offset([$convex_hull], $distance, 1, JT_ROUND, scale(0.1))->[0]; - $self->skirt->append(Slic3r::ExtrusionLoop->new_from_paths( + my $eloop = Slic3r::ExtrusionLoop->new_from_paths( Slic3r::ExtrusionPath->new( polyline => Slic3r::Polygon->new(@$loop)->split_at_first_point, role => EXTR_ROLE_SKIRT, @@ -281,7 +282,9 @@ sub make_skirt { width => $flow->width, height => $first_layer_height, # this will be overridden at G-code export time ), - )); + ); + $eloop->role(EXTRL_ROLE_SKIRT); + $self->skirt->append($eloop); if ($self->config->min_skirt_length > 0) { $extruded_length[$extruder_idx] ||= 0; diff --git a/xs/src/libslic3r/ExtrusionEntity.hpp b/xs/src/libslic3r/ExtrusionEntity.hpp index 719c80c15..98fbdc92f 100644 --- a/xs/src/libslic3r/ExtrusionEntity.hpp +++ b/xs/src/libslic3r/ExtrusionEntity.hpp @@ -31,6 +31,7 @@ enum ExtrusionRole { enum ExtrusionLoopRole { elrDefault, elrContourInternalPerimeter, + elrSkirt, }; class ExtrusionEntity diff --git a/xs/src/libslic3r/GCode.cpp b/xs/src/libslic3r/GCode.cpp index 003ad6105..69056652e 100644 --- a/xs/src/libslic3r/GCode.cpp +++ b/xs/src/libslic3r/GCode.cpp @@ -316,12 +316,15 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) // extrude all loops ccw bool was_clockwise = loop.make_counter_clockwise(); + SeamPosition seam_position = this->config.seam_position; + if (loop.role == elrSkirt) seam_position = spNearest; + // find the point of the loop that is closest to the current extruder position // or randomize if requested Point last_pos = this->last_pos(); if (this->config.spiral_vase) { loop.split_at(last_pos); - } else if (this->config.seam_position == spNearest || this->config.seam_position == spAligned) { + } else if (seam_position == spNearest || seam_position == spAligned) { const Polygon polygon = loop.polygon(); // simplify polygon in order to skip false positives in concave/convex detection @@ -356,7 +359,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) } Point point; - if (this->config.seam_position == spNearest) { + if (seam_position == spNearest) { if (candidates.empty()) candidates = polygon.points; last_pos.nearest_point(candidates, &point); @@ -382,7 +385,7 @@ GCode::extrude(ExtrusionLoop loop, std::string description, double speed) } if (this->layer != NULL) this->_seam_position[this->layer->object()] = point; - } else if (this->config.seam_position == spRandom) { + } else if (seam_position == spRandom) { if (loop.role == elrContourInternalPerimeter) { Polygon polygon = loop.polygon(); Point centroid = polygon.centroid(); diff --git a/xs/xsp/ExtrusionLoop.xsp b/xs/xsp/ExtrusionLoop.xsp index 39398cbaf..ef4879322 100644 --- a/xs/xsp/ExtrusionLoop.xsp +++ b/xs/xsp/ExtrusionLoop.xsp @@ -66,6 +66,7 @@ _constant() ALIAS: EXTRL_ROLE_DEFAULT = elrDefault EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER = elrContourInternalPerimeter + EXTRL_ROLE_SKIRT = elrSkirt PROTOTYPE: CODE: RETVAL = ix;