Merge branch 'master' into visilibity

Conflicts:
	lib/Slic3r/GCode.pm
	xs/MANIFEST
This commit is contained in:
Alessandro Ranellucci 2014-05-27 00:04:53 +02:00
commit 7215e66a6a
68 changed files with 1258 additions and 825 deletions

View file

@ -8,7 +8,8 @@ use List::Util qw(first max);
# cemetery of old config settings
our @Ignore = qw(duplicate_x duplicate_y multiply_x multiply_y support_material_tool acceleration
adjust_overhang_flow standby_temperature scale rotate duplicate duplicate_grid
rotate scale duplicate_grid);
rotate scale duplicate_grid start_perimeters_at_concave_points start_perimeters_at_non_overhang
randomize_start seal_position);
our $Options = print_config_def();
@ -140,6 +141,10 @@ sub _handle_legacy {
$value *= 100;
$value = "$value"; # force update of the PV value, workaround for bug https://rt.cpan.org/Ticket/Display.html?id=94110
}
if ($opt_key eq 'randomize_start' && $value) {
$opt_key = 'seam_position';
$value = 'random';
}
# For historical reasons, the world's full of configs having these very low values;
# to avoid unexpected behavior we need to ignore them. Banning these two hard-coded
@ -330,7 +335,7 @@ sub validate {
die "Can't make less than one perimeter when spiral vase mode is enabled\n"
if $self->perimeters < 1;
die "Spiral vase mode is not compatible with non-zero fill density\n"
die "Spiral vase mode can only print hollow objects, so you need to set Fill density to 0\n"
if $self->fill_density > 0;
die "Spiral vase mode is not compatible with top solid layers\n"
@ -338,11 +343,6 @@ sub validate {
die "Spiral vase mode is not compatible with support material\n"
if $self->support_material || $self->support_material_enforce_layers > 0;
# This should be enforce automatically only on spiral layers and
# done on the others
die "Spiral vase mode is not compatible with retraction on layer change\n"
if defined first { $_ } @{ $self->retract_layer_change };
}
# extrusion widths

View file

@ -2,4 +2,11 @@ package Slic3r::ExtrusionLoop;
use strict;
use warnings;
use parent qw(Exporter);
our @EXPORT_OK = qw(EXTRL_ROLE_DEFAULT EXTRL_ROLE_EXTERNAL_PERIMETER
EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER);
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
1;

View file

@ -4,10 +4,9 @@ use warnings;
use parent qw(Exporter);
our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_EXTERNAL_PERIMETER
EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER EXTR_ROLE_OVERHANG_PERIMETER
EXTR_ROLE_FILL EXTR_ROLE_SOLIDFILL EXTR_ROLE_TOPSOLIDFILL EXTR_ROLE_BRIDGE
EXTR_ROLE_INTERNALBRIDGE EXTR_ROLE_SKIRT EXTR_ROLE_SUPPORTMATERIAL EXTR_ROLE_GAPFILL);
our @EXPORT_OK = qw(EXTR_ROLE_PERIMETER EXTR_ROLE_EXTERNAL_PERIMETER EXTR_ROLE_OVERHANG_PERIMETER
EXTR_ROLE_FILL EXTR_ROLE_SOLIDFILL EXTR_ROLE_TOPSOLIDFILL EXTR_ROLE_GAPFILL EXTR_ROLE_BRIDGE
EXTR_ROLE_SKIRT EXTR_ROLE_SUPPORTMATERIAL EXTR_ROLE_SUPPORTMATERIAL_INTERFACE);
our %EXPORT_TAGS = (roles => \@EXPORT_OK);
1;

View file

@ -207,6 +207,7 @@ sub make_fill {
$h,
$is_bridge,
$layerm->id == 0,
undef,
$layerm->object,
);
@ -230,9 +231,7 @@ sub make_fill {
$collection->append(
map Slic3r::ExtrusionPath->new(
polyline => $_,
role => ($surface->surface_type == S_TYPE_INTERNALBRIDGE
? EXTR_ROLE_INTERNALBRIDGE
: $is_bridge
role => ($is_bridge
? EXTR_ROLE_BRIDGE
: $is_solid
? (($surface->surface_type == S_TYPE_TOP) ? EXTR_ROLE_TOPSOLIDFILL : EXTR_ROLE_SOLIDFILL)

View file

@ -2,13 +2,14 @@ package Slic3r::GCode;
use Moo;
use List::Util qw(min max first);
use Slic3r::ExtrusionLoop ':roles';
use Slic3r::ExtrusionPath ':roles';
use Slic3r::Flow ':roles';
use Slic3r::Geometry qw(epsilon scale unscale scaled_epsilon points_coincide PI X Y B);
use Slic3r::Geometry::Clipper qw(union_ex offset_ex);
use Slic3r::Surface ':types';
has 'print_config' => (is => 'ro', default => sub { Slic3r::Config::Print->new });
has 'config' => (is => 'ro', default => sub { Slic3r::Config::Full->new });
has 'placeholder_parser' => (is => 'rw', default => sub { Slic3r::GCode::PlaceholderParser->new });
has 'standby_points' => (is => 'rw');
has 'enable_loop_clipping' => (is => 'rw', default => sub {1});
@ -16,19 +17,15 @@ has 'enable_wipe' => (is => 'rw', default => sub {0}); # at least one e
has 'layer_count' => (is => 'ro', required => 1 );
has '_layer_index' => (is => 'rw', default => sub {-1}); # just a counter
has 'layer' => (is => 'rw');
has 'region' => (is => 'rw');
has '_layer_islands' => (is => 'rw');
has '_upper_layer_islands' => (is => 'rw');
has '_seam_position' => (is => 'ro', default => sub { {} }); # $object => pos
has 'shift_x' => (is => 'rw', default => sub {0} );
has 'shift_y' => (is => 'rw', default => sub {0} );
has 'z' => (is => 'rw');
has 'speed' => (is => 'rw');
has '_extrusion_axis' => (is => 'rw');
has '_retract_lift' => (is => 'rw');
has 'extruders' => (is => 'ro', default => sub {{}});
has 'multiple_extruders' => (is => 'rw', default => sub {0});
has 'extruder' => (is => 'rw');
has 'speeds' => (is => 'lazy'); # mm/min
has 'external_mp' => (is => 'rw');
has 'layer_mp' => (is => 'rw');
has 'new_object' => (is => 'rw', default => sub {0});
@ -36,23 +33,14 @@ has 'straight_once' => (is => 'rw', default => sub {1});
has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds
has 'lifted' => (is => 'rw', default => sub {0} );
has 'last_pos' => (is => 'rw', default => sub { Slic3r::Point->new(0,0) } );
has 'last_speed' => (is => 'rw', default => sub {""});
has 'last_f' => (is => 'rw', default => sub {""});
has 'last_fan_speed' => (is => 'rw', default => sub {0});
has 'wipe_path' => (is => 'rw');
sub BUILD {
my ($self) = @_;
$self->_extrusion_axis($self->print_config->get_extrusion_axis);
$self->_retract_lift($self->print_config->retract_lift->[0]);
}
sub set_extruders {
my ($self, $extruder_ids) = @_;
my ($self, $extruder_ids, $print_config) = @_;
foreach my $i (@$extruder_ids) {
$self->extruders->{$i} = my $e = Slic3r::Extruder->new($i, $self->print_config);
$self->extruders->{$i} = my $e = Slic3r::Extruder->new($i, $print_config);
$self->enable_wipe(1) if $e->wipe;
}
@ -62,30 +50,6 @@ sub set_extruders {
$self->multiple_extruders(max(@$extruder_ids) > 0);
}
sub _build_speeds {
my $self = shift;
return {
map { $_ => 60 * $self->print_config->get_value("${_}_speed") }
qw(travel perimeter small_perimeter external_perimeter infill
solid_infill top_solid_infill bridge gap_fill retract),
};
}
# assign speeds to roles
my %role_speeds = (
&EXTR_ROLE_PERIMETER => 'perimeter',
&EXTR_ROLE_EXTERNAL_PERIMETER => 'external_perimeter',
&EXTR_ROLE_OVERHANG_PERIMETER => 'bridge',
&EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER => 'perimeter',
&EXTR_ROLE_FILL => 'infill',
&EXTR_ROLE_SOLIDFILL => 'solid_infill',
&EXTR_ROLE_TOPSOLIDFILL => 'top_solid_infill',
&EXTR_ROLE_BRIDGE => 'bridge',
&EXTR_ROLE_INTERNALBRIDGE => 'bridge',
&EXTR_ROLE_SKIRT => 'perimeter',
&EXTR_ROLE_GAPFILL => 'gap_fill',
);
sub set_shift {
my ($self, @shift) = @_;
@ -110,23 +74,23 @@ sub change_layer {
# avoid computing islands and overhangs if they're not needed
$self->_layer_islands($layer->islands);
$self->_upper_layer_islands($layer->upper_layer ? $layer->upper_layer->islands : []);
if ($self->print_config->avoid_crossing_perimeters) {
if ($self->config->avoid_crossing_perimeters) {
$self->layer_mp(Slic3r::MotionPlanner->new(
union_ex([ map @$_, @{$layer->slices} ], 1),
));
}
my $gcode = "";
if ($self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/) {
if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) {
$gcode .= sprintf "M73 P%s%s\n",
int(99 * ($self->_layer_index / ($self->layer_count - 1))),
($self->print_config->gcode_comments ? ' ; update progress' : '');
($self->config->gcode_comments ? ' ; update progress' : '');
}
if ($self->print_config->first_layer_acceleration) {
if ($self->config->first_layer_acceleration) {
if ($layer->id == 0) {
$gcode .= $self->set_acceleration($self->print_config->first_layer_acceleration);
$gcode .= $self->set_acceleration($self->config->first_layer_acceleration);
} elsif ($layer->id == 1) {
$gcode .= $self->set_acceleration($self->print_config->default_acceleration);
$gcode .= $self->set_acceleration($self->config->default_acceleration);
}
}
@ -140,7 +104,7 @@ sub move_z {
my $gcode = "";
$z += $self->print_config->z_offset;
$z += $self->config->z_offset;
my $current_z = $self->z;
my $nominal_z = defined $current_z ? ($current_z - $self->lifted) : undef;
@ -157,8 +121,7 @@ sub move_z {
$current_z = $self->z; # update current z in case retract() changed it
$nominal_z = defined $current_z ? ($current_z - $self->lifted) : undef;
}
$self->speed('travel');
$gcode .= $self->G0(undef, $z, 0, $comment || ('move to next layer (' . $self->layer->id . ')'))
$gcode .= $self->G0(undef, $z, 0, $self->config->travel_speed*60, $comment || ('move to next layer (' . $self->layer->id . ')'))
if !defined $current_z || abs($z - $nominal_z) > epsilon;
} elsif ($z < $current_z) {
# we're moving above the current nominal layer height and below the current actual one.
@ -179,7 +142,7 @@ sub extrude {
}
sub extrude_loop {
my ($self, $loop, $description) = @_;
my ($self, $loop, $description, $speed) = @_;
# make a copy; don't modify the orientation of the original loop object otherwise
# next copies (if any) would not detect the correct orientation
@ -188,43 +151,39 @@ sub extrude_loop {
# extrude all loops ccw
my $was_clockwise = $loop->make_counter_clockwise;
# find candidate starting points
# start looking for concave vertices not being overhangs
my $polygon = $loop->polygon;
my @concave = ();
if ($self->print_config->start_perimeters_at_concave_points) {
@concave = $polygon->concave_points;
}
my @candidates = ();
if ($self->print_config->start_perimeters_at_non_overhang) {
@candidates = grep !$loop->has_overhang_point($_), @concave;
}
if (!@candidates) {
# if none, look for any concave vertex
@candidates = @concave;
if (!@candidates) {
# if none, look for any non-overhang vertex
if ($self->print_config->start_perimeters_at_non_overhang) {
@candidates = grep !$loop->has_overhang_point($_), @$polygon;
}
if (!@candidates) {
# if none, all points are valid candidates
@candidates = @$polygon;
}
}
}
# find the point of the loop that is closest to the current extruder position
# or randomize if requested
my $last_pos = $self->last_pos;
if ($self->print_config->randomize_start && $loop->role == EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER) {
$last_pos = Slic3r::Point->new(scale $self->print_config->print_center->[X], scale $self->print_config->bed_size->[Y]);
$last_pos->rotate(rand(2*PI), $self->print_config->print_center);
if ($self->config->spiral_vase) {
$loop->split_at($last_pos);
} elsif ($self->config->seam_position eq 'nearest' || $self->config->seam_position eq 'aligned') {
my $polygon = $loop->polygon;
my @candidates = @{$polygon->concave_points(PI*4/3)};
@candidates = @{$polygon->convex_points(PI*2/3)} if !@candidates;
@candidates = @{$polygon} if !@candidates;
my @non_overhang = grep !$loop->has_overhang_point($_), @candidates;
@candidates = @non_overhang if @non_overhang;
if ($self->config->seam_position eq 'nearest') {
$loop->split_at_vertex($last_pos->nearest_point(\@candidates));
} elsif ($self->config->seam_position eq 'aligned') {
if (defined $self->layer && defined $self->_seam_position->{$self->layer->object}) {
$last_pos = $self->_seam_position->{$self->layer->object};
}
my $point = $self->_seam_position->{$self->layer->object} = $last_pos->nearest_point(\@candidates);
$loop->split_at_vertex($point);
}
} elsif ($self->config->seam_position eq 'random') {
if ($loop->role == EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER) {
my $polygon = $loop->polygon;
my $centroid = $polygon->centroid;
$last_pos = Slic3r::Point->new($polygon->bounding_box->x_max, $centroid->y); #))
$last_pos->rotate(rand(2*PI), $centroid);
}
$loop->split_at($last_pos);
}
# split the loop at the starting point
$loop->split_at($last_pos->nearest_point(\@candidates));
# clip the path to avoid the extruder to get exactly on the first point of the loop;
# if polyline was shorter than the clipping distance we'd get a null polyline, so
# we discard it in that case
@ -237,17 +196,17 @@ sub extrude_loop {
return '' if !@paths;
# apply the small perimeter speed
my %params = ();
if ($paths[0]->is_perimeter && abs($loop->length) <= &Slic3r::SMALL_PERIMETER_LENGTH) {
$params{speed} = 'small_perimeter';
if ($paths[0]->is_perimeter && $loop->length <= &Slic3r::SMALL_PERIMETER_LENGTH) {
$speed //= $self->config->get_abs_value('small_perimeter_speed');
}
$speed //= -1;
# extrude along the path
my $gcode = join '', map $self->extrude_path($_, $description, %params), @paths;
my $gcode = join '', map $self->extrude_path($_, $description, $speed), @paths;
$self->wipe_path($paths[-1]->polyline->clone) if $self->enable_wipe; # TODO: don't limit wipe to last path
# make a little move inwards before leaving loop
if ($paths[-1]->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->region->config->perimeters > 1) {
if ($paths[-1]->role == EXTR_ROLE_EXTERNAL_PERIMETER && defined $self->layer && $self->config->perimeters > 1) {
my $last_path_polyline = $paths[-1]->polyline;
# detect angle between last and first segment
# the side depends on the original winding order of the polygon (left for contours, right for holes)
@ -271,7 +230,7 @@ sub extrude_loop {
}
sub extrude_path {
my ($self, $path, $description, %params) = @_;
my ($self, $path, $description, $speed) = @_;
$path->simplify(&Slic3r::SCALED_RESOLUTION);
@ -288,26 +247,45 @@ sub extrude_path {
# adjust acceleration
my $acceleration;
if (!$self->print_config->first_layer_acceleration || $self->layer->id != 0) {
if ($self->print_config->perimeter_acceleration && $path->is_perimeter) {
$acceleration = $self->print_config->perimeter_acceleration;
} elsif ($self->print_config->infill_acceleration && $path->is_fill) {
$acceleration = $self->print_config->infill_acceleration;
} elsif ($self->print_config->infill_acceleration && $path->is_bridge) {
$acceleration = $self->print_config->bridge_acceleration;
if (!$self->config->first_layer_acceleration || $self->layer->id != 0) {
if ($self->config->perimeter_acceleration && $path->is_perimeter) {
$acceleration = $self->config->perimeter_acceleration;
} elsif ($self->config->infill_acceleration && $path->is_fill) {
$acceleration = $self->config->infill_acceleration;
} elsif ($self->config->infill_acceleration && $path->is_bridge) {
$acceleration = $self->config->bridge_acceleration;
}
$gcode .= $self->set_acceleration($acceleration) if $acceleration;
}
# calculate extrusion length per distance unit
my $e = $self->extruder->e_per_mm3 * $path->mm3_per_mm;
$e = 0 if !$self->_extrusion_axis;
$e = 0 if !$self->config->get_extrusion_axis;
# set speed
$self->speed( $params{speed} || $role_speeds{$path->role} || die "Unknown role: " . $path->role );
my $F = $self->speeds->{$self->speed} // $self->speed;
my $F;
if ($path->role == EXTR_ROLE_PERIMETER) {
$F = $self->config->get_abs_value('perimeter_speed');
} elsif ($path->role == EXTR_ROLE_EXTERNAL_PERIMETER) {
$F = $self->config->get_abs_value('external_perimeter_speed');
} elsif ($path->role == EXTR_ROLE_OVERHANG_PERIMETER || $path->role == EXTR_ROLE_BRIDGE) {
$F = $self->config->get_abs_value('bridge_speed');
} elsif ($path->role == EXTR_ROLE_FILL) {
$F = $self->config->get_abs_value('infill_speed');
} elsif ($path->role == EXTR_ROLE_SOLIDFILL) {
$F = $self->config->get_abs_value('solid_infill_speed');
} elsif ($path->role == EXTR_ROLE_TOPSOLIDFILL) {
$F = $self->config->get_abs_value('top_solid_infill_speed');
} elsif ($path->role == EXTR_ROLE_GAPFILL) {
$F = $self->config->get_abs_value('gap_fill_speed');
} else {
$F = $speed // -1;
die "Invalid speed" if $F < 0; # $speed == -1
}
$F *= 60; # convert mm/sec to mm/min
if ($self->layer->id == 0) {
$F = $self->print_config->get_abs_value_over('first_layer_speed', $F/60) * 60;
$F = $self->config->get_abs_value_over('first_layer_speed', $F/60) * 60;
}
# extrude arc or line
@ -317,8 +295,8 @@ sub extrude_path {
$gcode .= $path->gcode($self->extruder, $e, $F,
$self->shift_x - $self->extruder->extruder_offset->x,
$self->shift_y - $self->extruder->extruder_offset->y, #,,
$self->_extrusion_axis,
$self->print_config->gcode_comments ? " ; $description" : "");
$self->config->get_extrusion_axis,
$self->config->gcode_comments ? " ; $description" : "");
if ($self->enable_wipe) {
$self->wipe_path($path->polyline->clone);
@ -328,14 +306,14 @@ sub extrude_path {
$gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge;
$self->last_pos($path->last_point);
if ($self->print_config->cooling) {
if ($self->config->cooling) {
my $path_time = $path_length / $F * 60;
$self->elapsed_time($self->elapsed_time + $path_time);
}
# reset acceleration
$gcode .= $self->set_acceleration($self->print_config->default_acceleration)
if $acceleration && $self->print_config->default_acceleration;
$gcode .= $self->set_acceleration($self->config->default_acceleration)
if $acceleration && $self->config->default_acceleration;
return $gcode;
}
@ -354,19 +332,17 @@ sub travel_to {
# skip retraction if the travel move is contained in an island in the current layer
# *and* in an island in the upper layer (so that the ooze will not be visible)
if ($travel->length < scale $self->extruder->retract_before_travel
|| ($self->print_config->only_retract_when_crossing_perimeters
|| ($self->config->only_retract_when_crossing_perimeters
&& (first { $_->contains_line($travel) } @{$self->_upper_layer_islands})
&& (first { $_->contains_line($travel) } @{$self->_layer_islands}))
|| (defined $role && $role == EXTR_ROLE_SUPPORTMATERIAL && (first { $_->contains_line($travel) } @{$self->layer->support_islands}))
) {
$self->straight_once(0);
$self->speed('travel');
$gcode .= $self->G0($point, undef, 0, $comment || "");
} elsif (!$self->print_config->avoid_crossing_perimeters || $self->straight_once) {
$gcode .= $self->G0($point, undef, 0, $self->config->travel_speed*60, $comment || "");
} elsif (!$self->config->avoid_crossing_perimeters || $self->straight_once) {
$self->straight_once(0);
$gcode .= $self->retract;
$self->speed('travel');
$gcode .= $self->G0($point, undef, 0, $comment || "");
$gcode .= $self->G0($point, undef, 0, $self->config->travel_speed*60, $comment || "");
} else {
if ($self->new_object) {
$self->new_object(0);
@ -395,7 +371,7 @@ sub _plan {
my @travel = @{$mp->shortest_path($self->last_pos, $point)->lines};
# if the path is not contained in a single island we need to retract
my $need_retract = !$self->print_config->only_retract_when_crossing_perimeters;
my $need_retract = !$self->config->only_retract_when_crossing_perimeters;
if (!$need_retract) {
$need_retract = 1;
foreach my $island (@{$self->_upper_layer_islands}) {
@ -411,9 +387,8 @@ sub _plan {
$gcode .= $self->retract if $need_retract;
# append the actual path and return
$self->speed('travel');
# use G1 because we rely on paths being straight (G0 may make round paths)
$gcode .= join '', map $self->G1($_->b, undef, 0, $comment || ""), @travel;
$gcode .= join '', map $self->G1($_->b, undef, 0, $self->config->travel_speed*60, $comment || ""), @travel;
return $gcode;
}
@ -435,60 +410,55 @@ sub retract {
if ($self->extruder->wipe && $self->wipe_path) {
my @points = @{$self->wipe_path};
$wipe_path = Slic3r::Polyline->new($self->last_pos, @{$self->wipe_path}[1..$#{$self->wipe_path}]);
$wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance($self->print_config->travel_speed));
$wipe_path->clip_end($wipe_path->length - $self->extruder->scaled_wipe_distance($self->config->travel_speed));
}
# prepare moves
my $retract = [undef, undef, -$length, $comment];
my $lift = ($self->_retract_lift == 0 || defined $params{move_z}) && !$self->lifted
my $retract = [undef, undef, -$length, $self->extruder->retract_speed_mm_min, $comment];
my $lift = ($self->config->retract_lift->[0] == 0 || defined $params{move_z}) && !$self->lifted
? undef
: [undef, $self->z + $self->_retract_lift, 0, 'lift plate during travel'];
: [undef, $self->z + $self->config->retract_lift->[0], 0, $self->config->travel_speed*60, 'lift plate during travel'];
# check that we have a positive wipe length
if ($wipe_path) {
$self->speed($self->speeds->{travel} * 0.8);
# subdivide the retraction
my $retracted = 0;
foreach my $line (@{$wipe_path->lines}) {
my $segment_length = $line->length;
# reduce retraction length a bit to avoid effective retraction speed to be greater than the configured one
# due to rounding
my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance($self->print_config->travel_speed)) * 0.95;
my $e = $retract->[2] * ($segment_length / $self->extruder->scaled_wipe_distance($self->config->travel_speed)) * 0.95;
$retracted += $e;
$gcode .= $self->G1($line->b, undef, $e, $retract->[3] . ";_WIPE");
$gcode .= $self->G1($line->b, undef, $e, $self->config->travel_speed*60*0.8, $retract->[3] . ";_WIPE");
}
if ($retracted > $retract->[2]) {
# if we retracted less than we had to, retract the remainder
# TODO: add regression test
$self->speed('retract');
$gcode .= $self->G1(undef, undef, $retract->[2] - $retracted, $comment);
$gcode .= $self->G1(undef, undef, $retract->[2] - $retracted, $self->extruder->retract_speed_mm_min, $comment);
}
} elsif ($self->print_config->use_firmware_retraction) {
} elsif ($self->config->use_firmware_retraction) {
$gcode .= "G10 ; retract\n";
} else {
$self->speed('retract');
$gcode .= $self->G1(@$retract);
}
if (!$self->lifted) {
$self->speed('travel');
if (defined $params{move_z} && $self->_retract_lift > 0) {
my $travel = [undef, $params{move_z} + $self->_retract_lift, 0, 'move to next layer (' . $self->layer->id . ') and lift'];
if (defined $params{move_z} && $self->config->retract_lift->[0] > 0) {
my $travel = [undef, $params{move_z} + $self->config->retract_lift->[0], 0, $self->config->travel_speed*60, 'move to next layer (' . $self->layer->id . ') and lift'];
$gcode .= $self->G0(@$travel);
$self->lifted($self->_retract_lift);
$self->lifted($self->config->retract_lift->[0]);
} elsif ($lift) {
$gcode .= $self->G1(@$lift);
}
}
$self->extruder->set_retracted($self->extruder->retracted + $length);
$self->extruder->set_restart_extra($restart_extra);
$self->lifted($self->_retract_lift) if $lift;
$self->lifted($self->config->retract_lift->[0]) if $lift;
# reset extrusion distance during retracts
# this makes sure we leave sufficient precision in the firmware
$gcode .= $self->reset_e;
$gcode .= "M103 ; extruder off\n" if $self->print_config->gcode_flavor eq 'makerware';
$gcode .= "M103 ; extruder off\n" if $self->config->gcode_flavor eq 'makerware';
return $gcode;
}
@ -497,26 +467,24 @@ sub unretract {
my ($self) = @_;
my $gcode = "";
$gcode .= "M101 ; extruder on\n" if $self->print_config->gcode_flavor eq 'makerware';
$gcode .= "M101 ; extruder on\n" if $self->config->gcode_flavor eq 'makerware';
if ($self->lifted) {
$self->speed('travel');
$gcode .= $self->G0(undef, $self->z - $self->lifted, 0, 'restore layer Z');
$gcode .= $self->G0(undef, $self->z - $self->lifted, 0, $self->config->travel_speed*60, 'restore layer Z');
$self->lifted(0);
}
my $to_unretract = $self->extruder->retracted + $self->extruder->restart_extra;
if ($to_unretract) {
$self->speed('retract');
if ($self->print_config->use_firmware_retraction) {
if ($self->config->use_firmware_retraction) {
$gcode .= "G11 ; unretract\n";
} elsif ($self->_extrusion_axis) {
} elsif ($self->config->get_extrusion_axis) {
# use G1 instead of G0 because G0 will blend the restart with the previous travel move
$gcode .= sprintf "G1 %s%.5f F%.3f",
$self->_extrusion_axis,
$self->config->get_extrusion_axis,
$self->extruder->extrude($to_unretract),
$self->extruder->retract_speed_mm_min;
$gcode .= " ; compensate retraction" if $self->print_config->gcode_comments;
$gcode .= " ; compensate retraction" if $self->config->gcode_comments;
$gcode .= "\n";
}
$self->extruder->set_retracted(0);
@ -528,11 +496,11 @@ sub unretract {
sub reset_e {
my ($self) = @_;
return "" if $self->print_config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/;
return "" if $self->config->gcode_flavor =~ /^(?:mach3|makerware|sailfish)$/;
$self->extruder->set_E(0) if $self->extruder;
return sprintf "G92 %s0%s\n", $self->_extrusion_axis, ($self->print_config->gcode_comments ? ' ; reset extrusion distance' : '')
if $self->_extrusion_axis && !$self->print_config->use_relative_e_distances;
return sprintf "G92 %s0%s\n", $self->config->get_extrusion_axis, ($self->config->gcode_comments ? ' ; reset extrusion distance' : '')
if $self->config->get_extrusion_axis && !$self->config->use_relative_e_distances;
}
sub set_acceleration {
@ -540,12 +508,12 @@ sub set_acceleration {
return "" if !$acceleration;
return sprintf "M204 S%s%s\n",
$acceleration, ($self->print_config->gcode_comments ? ' ; adjust acceleration' : '');
$acceleration, ($self->config->gcode_comments ? ' ; adjust acceleration' : '');
}
sub G0 {
my $self = shift;
return $self->G1(@_) if !($self->print_config->g0 || $self->print_config->gcode_flavor eq 'mach3');
return $self->G1(@_) if !($self->config->g0 || $self->config->gcode_flavor eq 'mach3');
return $self->_G0_G1("G0", @_);
}
@ -555,7 +523,7 @@ sub G1 {
}
sub _G0_G1 {
my ($self, $gcode, $point, $z, $e, $comment) = @_;
my ($self, $gcode, $point, $z, $e, $F, $comment) = @_;
if ($point) {
$gcode .= sprintf " X%.3f Y%.3f",
@ -568,25 +536,20 @@ sub _G0_G1 {
$gcode .= sprintf " Z%.3f", $z;
}
return $self->_Gx($gcode, $e, $comment);
return $self->_Gx($gcode, $e, $F, $comment);
}
sub _Gx {
my ($self, $gcode, $e, $comment) = @_;
my ($self, $gcode, $e, $F, $comment) = @_;
my $F = $self->speed eq 'retract'
? ($self->extruder->retract_speed_mm_min)
: $self->speeds->{$self->speed} // $self->speed;
$self->last_speed($self->speed);
$self->last_f($F);
$gcode .= sprintf " F%.3f", $F;
# output extrusion distance
if ($e && $self->_extrusion_axis) {
$gcode .= sprintf " %s%.5f", $self->_extrusion_axis, $self->extruder->extrude($e);
if ($e && $self->config->get_extrusion_axis) {
$gcode .= sprintf " %s%.5f", $self->config->get_extrusion_axis, $self->extruder->extrude($e);
}
$gcode .= " ; $comment" if $comment && $self->print_config->gcode_comments;
$gcode .= " ; $comment" if $comment && $self->config->gcode_comments;
return "$gcode\n";
}
@ -607,8 +570,8 @@ sub set_extruder {
$gcode .= $self->retract(toolchange => 1) if defined $self->extruder;
# append custom toolchange G-code
if (defined $self->extruder && $self->print_config->toolchange_gcode) {
$gcode .= sprintf "%s\n", $self->placeholder_parser->process($self->print_config->toolchange_gcode, {
if (defined $self->extruder && $self->config->toolchange_gcode) {
$gcode .= sprintf "%s\n", $self->placeholder_parser->process($self->config->toolchange_gcode, {
previous_extruder => $self->extruder->id,
next_extruder => $extruder_id,
});
@ -617,30 +580,38 @@ sub set_extruder {
# set the current extruder to the standby temperature
if ($self->standby_points && defined $self->extruder) {
# move to the nearest standby point
$gcode .= $self->travel_to($self->last_pos->nearest_point($self->standby_points));
{
my $last_pos = $self->last_pos->clone;
$last_pos->translate(scale +$self->shift_x, scale +$self->shift_y);
my $standby_point = $last_pos->nearest_point($self->standby_points);
$standby_point->translate(scale -$self->shift_x, scale -$self->shift_y);
$gcode .= $self->travel_to($standby_point);
}
my $temp = defined $self->layer && $self->layer->id == 0
? $self->extruder->first_layer_temperature
: $self->extruder->temperature;
# we assume that heating is always slower than cooling, so no need to block
$gcode .= $self->set_temperature($temp + $self->print_config->standby_temperature_delta, 0);
if ($self->config->standby_temperature_delta != 0) {
my $temp = defined $self->layer && $self->layer->id == 0
? $self->extruder->first_layer_temperature
: $self->extruder->temperature;
# we assume that heating is always slower than cooling, so no need to block
$gcode .= $self->set_temperature($temp + $self->config->standby_temperature_delta, 0);
}
}
# set the new extruder
$self->extruder($self->extruders->{$extruder_id});
$gcode .= sprintf "%s%d%s\n",
($self->print_config->gcode_flavor eq 'makerware'
($self->config->gcode_flavor eq 'makerware'
? 'M135 T'
: $self->print_config->gcode_flavor eq 'sailfish'
: $self->config->gcode_flavor eq 'sailfish'
? 'M108 T'
: 'T'),
$extruder_id,
($self->print_config->gcode_comments ? ' ; change extruder' : '');
($self->config->gcode_comments ? ' ; change extruder' : '');
$gcode .= $self->reset_e;
# set the new extruder to the operating temperature
if ($self->print_config->ooze_prevention) {
if ($self->config->ooze_prevention && $self->config->standby_temperature_delta != 0) {
my $temp = defined $self->layer && $self->layer->id == 0
? $self->extruder->first_layer_temperature
: $self->extruder->temperature;
@ -656,18 +627,18 @@ sub set_fan {
if ($self->last_fan_speed != $speed || $dont_save) {
$self->last_fan_speed($speed) if !$dont_save;
if ($speed == 0) {
my $code = $self->print_config->gcode_flavor eq 'teacup'
my $code = $self->config->gcode_flavor eq 'teacup'
? 'M106 S0'
: $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/
: $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/
? 'M127'
: 'M107';
return sprintf "$code%s\n", ($self->print_config->gcode_comments ? ' ; disable fan' : '');
return sprintf "$code%s\n", ($self->config->gcode_comments ? ' ; disable fan' : '');
} else {
if ($self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/) {
return sprintf "M126%s\n", ($self->print_config->gcode_comments ? ' ; enable fan' : '');
if ($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/) {
return sprintf "M126%s\n", ($self->config->gcode_comments ? ' ; enable fan' : '');
} else {
return sprintf "M106 %s%d%s\n", ($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
(255 * $speed / 100), ($self->print_config->gcode_comments ? ' ; enable fan' : '');
return sprintf "M106 %s%d%s\n", ($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'),
(255 * $speed / 100), ($self->config->gcode_comments ? ' ; enable fan' : '');
}
}
}
@ -677,17 +648,17 @@ sub set_fan {
sub set_temperature {
my ($self, $temperature, $wait, $tool) = @_;
return "" if $wait && $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/;
return "" if $wait && $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/;
my ($code, $comment) = ($wait && $self->print_config->gcode_flavor ne 'teacup')
my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup')
? ('M109', 'wait for temperature to be reached')
: ('M104', 'set temperature');
my $gcode = sprintf "$code %s%d %s; $comment\n",
($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
(defined $tool && ($self->multiple_extruders || $self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : "";
($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
(defined $tool && ($self->multiple_extruders || $self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/)) ? "T$tool " : "";
$gcode .= "M116 ; wait for temperature to be reached\n"
if $self->print_config->gcode_flavor eq 'teacup' && $wait;
if $self->config->gcode_flavor eq 'teacup' && $wait;
return $gcode;
}
@ -695,14 +666,14 @@ sub set_temperature {
sub set_bed_temperature {
my ($self, $temperature, $wait) = @_;
my ($code, $comment) = ($wait && $self->print_config->gcode_flavor ne 'teacup')
? (($self->print_config->gcode_flavor =~ /^(?:makerware|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
my ($code, $comment) = ($wait && $self->config->gcode_flavor ne 'teacup')
? (($self->config->gcode_flavor =~ /^(?:makerware|sailfish)$/ ? 'M109' : 'M190'), 'wait for bed temperature to be reached')
: ('M140', 'set bed temperature');
my $gcode = sprintf "$code %s%d ; $comment\n",
($self->print_config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
($self->config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature;
$gcode .= "M116 ; wait for bed temperature to be reached\n"
if $self->print_config->gcode_flavor eq 'teacup' && $wait;
if $self->config->gcode_flavor eq 'teacup' && $wait;
return $gcode;
}

View file

@ -46,6 +46,7 @@ sub process_layer {
my $gcode = "";
my $object = $layer->object;
$self->gcodegen->config->apply_object_config($object->config);
# check whether we're going to apply spiralvase logic
if (defined $self->spiralvase) {
@ -95,7 +96,7 @@ sub process_layer {
my $extruder_id = $extruder_ids[($i/@extruder_ids) % @extruder_ids];
$gcode .= $self->gcodegen->set_extruder($extruder_id)
if $layer->id == 0;
$gcode .= $self->gcodegen->extrude_loop($skirt_loops[$i], 'skirt');
$gcode .= $self->gcodegen->extrude_loop($skirt_loops[$i], 'skirt', $object->config->support_material_speed);
}
}
$self->skirt_done->{$layer->print_z} = 1;
@ -106,7 +107,8 @@ sub process_layer {
if (!$self->brim_done) {
$gcode .= $self->gcodegen->set_extruder($self->print->objects->[0]->config->support_material_extruder-1);
$self->gcodegen->set_shift(@{$self->shift});
$gcode .= $self->gcodegen->extrude_loop($_, 'brim') for @{$self->print->brim};
$gcode .= $self->gcodegen->extrude_loop($_, 'brim', $object->config->support_material_speed)
for @{$self->print->brim};
$self->brim_done(1);
$self->gcodegen->straight_once(1);
}
@ -122,14 +124,12 @@ sub process_layer {
if ($layer->isa('Slic3r::Layer::Support')) {
if ($layer->support_interface_fills->count > 0) {
$gcode .= $self->gcodegen->set_extruder($object->config->support_material_interface_extruder-1);
my %params = (speed => $object->config->support_material_speed*60);
$gcode .= $self->gcodegen->extrude_path($_, 'support material interface', %params)
$gcode .= $self->gcodegen->extrude_path($_, 'support material interface', $object->config->get_abs_value('support_material_interface_speed'))
for @{$layer->support_interface_fills->chained_path_from($self->gcodegen->last_pos, 0)};
}
if ($layer->support_fills->count > 0) {
$gcode .= $self->gcodegen->set_extruder($object->config->support_material_extruder-1);
my %params = (speed => $object->config->support_material_speed*60);
$gcode .= $self->gcodegen->extrude_path($_, 'support material', %params)
$gcode .= $self->gcodegen->extrude_path($_, 'support material', $object->config->get_abs_value('support_material_speed'))
for @{$layer->support_fills->chained_path_from($self->gcodegen->last_pos, 0)};
}
}
@ -145,7 +145,7 @@ sub process_layer {
foreach my $region_id (@region_ids) {
my $layerm = $layer->regions->[$region_id] or next;
my $region = $self->print->regions->[$region_id];
$self->gcodegen->region($region);
$self->gcodegen->config->apply_region_config($region->config);
# group extrusions by island
my @perimeters_by_island = map [], 0..$#{$layer->slices}; # slice idx => @perimeters

View file

@ -43,7 +43,7 @@ sub process_layer {
}
});
#use XXX; YYY [ $gcode, $layer_height, $z, $total_layer_length ];
#use XXX; XXX [ $gcode, $layer_height, $z, $total_layer_length ];
# remove layer height from initial Z
$z -= $layer_height;
@ -57,16 +57,19 @@ sub process_layer {
my $line = $info->{raw};
$line =~ s/ Z[.0-9]+/ Z$z/;
$new_gcode .= "$line\n";
} elsif ($cmd eq 'G1' && !exists $args->{Z} && $info->{dist_XY}) {
} elsif ($cmd eq 'G1' && !exists($args->{Z}) && $info->{dist_XY}) {
# horizontal move
my $line = $info->{raw};
if ($info->{extruding}) {
$z += $info->{dist_XY} * $layer_height / $total_layer_length;
$line =~ s/^G1 /sprintf 'G1 Z%.3f ', $z/e;
$new_gcode .= "$line\n";
} else {
$new_gcode .= "$line\n";
}
# skip travel moves: the move to first perimeter point will
# cause a visible seam when loops are not aligned in XY; by skipping
# it we blend the first loop move in the XY plane (although the smoothness
# of such blend depend on how long the first segment is; maybe we should
# enforce some minimum length?)
} else {
$new_gcode .= "$info->{raw}\n";
}

View file

@ -231,7 +231,9 @@ sub _build_field {
});
} else {
$field = Wx::TextCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style);
$self->_setters->{$opt_key} = sub { $field->ChangeValue($_[0]) };
# value supplied to the setter callback might be undef in case user loads a config
# that has empty string for multi-value options like 'wipe'
$self->_setters->{$opt_key} = sub { $field->ChangeValue($_[0]) if defined $_[0] };
EVT_TEXT($self->parent, $field, $on_change);
EVT_KILL_FOCUS($field, $on_kill_focus);
}

View file

@ -627,12 +627,6 @@ sub split_object {
Slic3r::GUI::warning_catcher($self)->("The selected object couldn't be split because it already contains a single part.");
return;
}
# remove the original object before spawning the object_loaded event, otherwise
# we'll pass the wrong $obj_idx to it (which won't be recognized after the
# thumbnail thread returns)
$self->remove($obj_idx);
$current_object = $obj_idx = undef;
# create a bogus Model object, we only need to instantiate the new Model::Object objects
my $new_model = Slic3r::Model->new;
@ -666,6 +660,12 @@ sub split_object {
$model_object->center_around_origin;
push @model_objects, $model_object;
}
# remove the original object before spawning the object_loaded event, otherwise
# we'll pass the wrong $obj_idx to it (which won't be recognized after the
# thumbnail thread returns)
$self->remove($obj_idx);
$current_object = $obj_idx = undef;
# load all model objects at once, otherwise the plate would be rearranged after each one
# causing original positions not to be kept
@ -692,6 +692,7 @@ sub export_gcode {
$self->{print}->apply_config($config);
$self->{print}->validate;
};
Slic3r::GUI::catch_error($self) and return;
# apply extra variables
{

View file

@ -197,7 +197,7 @@ sub on_btn_load {
foreach my $object (@{$model->objects}) {
foreach my $volume (@{$object->volumes}) {
my $new_volume = $self->{model_object}->add_volume($volume);
$new_volume->modifier($is_modifier);
$new_volume->set_modifier($is_modifier);
if (!defined $new_volume->material_id) {
# it looks like this block is never entered because all input volumes seem to have an assigned material
# TODO: check we can assume that for any input format

View file

@ -150,7 +150,7 @@ sub Closing {
my $self = shift;
# save ranges into the plater object
$self->model_object->layer_height_ranges([ $self->_get_ranges ]);
$self->model_object->set_layer_height_ranges([ $self->_get_ranges ]);
}
sub _get_ranges {

View file

@ -235,15 +235,6 @@ sub extra_variables {
return { %extra_variables };
}
sub init_print {
my $self = shift;
return Slic3r::Print->new(
config => $self->config,
extra_variables => $self->extra_variables,
);
}
sub export_config {
my $self = shift;

View file

@ -417,21 +417,17 @@ sub build {
},
{
title => 'Quality (slower slicing)',
options => [qw(extra_perimeters avoid_crossing_perimeters start_perimeters_at_concave_points start_perimeters_at_non_overhang thin_walls overhangs)],
options => [qw(extra_perimeters avoid_crossing_perimeters thin_walls overhangs)],
lines => [
Slic3r::GUI::OptionsGroup->single_option_line('extra_perimeters'),
Slic3r::GUI::OptionsGroup->single_option_line('avoid_crossing_perimeters'),
{
label => 'Start perimeters at',
options => [qw(start_perimeters_at_concave_points start_perimeters_at_non_overhang)],
},
Slic3r::GUI::OptionsGroup->single_option_line('thin_walls'),
Slic3r::GUI::OptionsGroup->single_option_line('overhangs'),
],
},
{
title => 'Advanced',
options => [qw(randomize_start external_perimeters_first)],
options => [qw(seam_position external_perimeters_first)],
},
]);
@ -454,7 +450,7 @@ sub build {
$self->add_options_page('Speed', 'time.png', optgroups => [
{
title => 'Speed for print moves',
options => [qw(perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed support_material_speed bridge_speed gap_fill_speed)],
options => [qw(perimeter_speed small_perimeter_speed external_perimeter_speed infill_speed solid_infill_speed top_solid_infill_speed support_material_speed support_material_interface_speed bridge_speed gap_fill_speed)],
},
{
title => 'Speed for non-print moves',
@ -743,7 +739,13 @@ sub _build_extruder_pages {
# extend options
foreach my $opt_key ($self->_extruder_options) {
my $values = $self->{config}->get($opt_key);
$values->[$extruder_idx] //= $default_config->get_at($opt_key, 0);
if (!defined $values) {
$values = [ $default_config->get_at($opt_key, 0) ];
} else {
# use last extruder's settings for the new one
my $last_value = $values->[-1];
$values->[$extruder_idx] //= $last_value;
}
$self->{config}->set($opt_key, $values)
or die "Unable to extend $opt_key";
}

View file

@ -2,6 +2,7 @@ package Slic3r::Layer::Region;
use Moo;
use List::Util qw(sum first);
use Slic3r::ExtrusionLoop ':roles';
use Slic3r::ExtrusionPath ':roles';
use Slic3r::Flow ':roles';
use Slic3r::Geometry qw(PI A B scale unscale chained_path points_coincide);
@ -124,7 +125,7 @@ sub make_perimeters {
)};
# look for gaps
if ($self->print->config->gap_fill_speed > 0 && $self->config->fill_density > 0) {
if ($self->region->config->gap_fill_speed > 0 && $self->config->fill_density > 0) {
# not using safety offset here would "detect" very narrow gaps
# (but still long enough to escape the area threshold) that gap fill
# won't be able to fill but we'd still remove from infill area
@ -179,8 +180,7 @@ sub make_perimeters {
# and use zigzag).
my $w = $gap_size->[2];
my @filled = map {
@{($_->isa('Slic3r::ExtrusionLoop') ? $_->split_at_first_point : $_)
->polyline
@{($_->isa('Slic3r::ExtrusionLoop') ? $_->polygon->split_at_first_point : $_->polyline)
->grow(scale $w/2)};
} @gap_fill;
@last = @{diff(\@last, \@filled)};
@ -233,7 +233,7 @@ sub make_perimeters {
# prepare grown lower layer slices for overhang detection
my $lower_slices = Slic3r::ExPolygon::Collection->new;
if ($self->layer->lower_layer && $self->layer->print->config->overhangs) {
if ($self->layer->lower_layer && $self->region->config->overhangs) {
# We consider overhang any part where the entire nozzle diameter is not supported by the
# lower layer, so we take lower slices and offset them by half the nozzle diameter used
# in the current layer
@ -257,18 +257,27 @@ sub make_perimeters {
foreach my $polynode (@$polynodes) {
my $polygon = ($polynode->{outer} // $polynode->{hole})->clone;
my $role = EXTR_ROLE_PERIMETER;
if ($is_contour ? $depth == 0 : !@{ $polynode->{children} }) {
my $role = EXTR_ROLE_PERIMETER;
my $loop_role = EXTRL_ROLE_DEFAULT;
my $root_level = $depth == 0;
my $no_children = !@{ $polynode->{children} };
my $is_external = $is_contour ? $root_level : $no_children;
my $is_internal = $is_contour ? $no_children : $root_level;
if ($is_external) {
# external perimeters are root level in case of contours
# and items with no children in case of holes
$role = EXTR_ROLE_EXTERNAL_PERIMETER;
} elsif ($depth == 1 && $is_contour) {
$role = EXTR_ROLE_CONTOUR_INTERNAL_PERIMETER;
$role = EXTR_ROLE_EXTERNAL_PERIMETER;
$loop_role = EXTRL_ROLE_EXTERNAL_PERIMETER;
} elsif ($is_contour && $is_internal) {
# internal perimeters are root level in case of holes
# and items with no children in case of contours
$loop_role = EXTRL_ROLE_CONTOUR_INTERNAL_PERIMETER;
}
# detect overhanging/bridging perimeters
my @paths = ();
if ($self->layer->print->config->overhangs && $lower_slices->count > 0) {
if ($self->region->config->overhangs && $lower_slices->count > 0) {
# get non-overhang paths by intersecting this loop with the grown lower slices
foreach my $polyline (@{ intersection_ppl([ $polygon ], $lower_slices_p) }) {
push @paths, Slic3r::ExtrusionPath->new(
@ -292,7 +301,7 @@ sub make_perimeters {
height => $self->height,
);
}
# reapply the nearest point search for starting point
# (clone because the collection gets DESTROY'ed)
# We allow polyline reversal because Clipper may have randomly
@ -309,6 +318,7 @@ sub make_perimeters {
);
}
my $loop = Slic3r::ExtrusionLoop->new_from_paths(@paths);
$loop->role($loop_role);
# return ccw contours and cw holes
# GCode.pm will convert all of them to ccw, but it needs to know
@ -427,6 +437,11 @@ sub _fill_gaps {
my $loop = Slic3r::ExtrusionLoop->new;
$loop->append(Slic3r::ExtrusionPath->new(polyline => $polylines[$i]->split_at_first_point, %path_args));
$polylines[$i] = $loop;
} elsif ($polylines[$i]->is_valid && $polylines[$i]->first_point->coincides_with($polylines[$i]->last_point)) {
# since medial_axis() now returns only Polyline objects, detect loops here
my $loop = Slic3r::ExtrusionLoop->new;
$loop->append(Slic3r::ExtrusionPath->new(polyline => $polylines[$i], %path_args));
$polylines[$i] = $loop;
} else {
$polylines[$i] = Slic3r::ExtrusionPath->new(polyline => $polylines[$i], %path_args);
}

View file

@ -15,6 +15,11 @@ sub wkt {
return sprintf "POLYGON((%s))", join ',', map "$_->[0] $_->[1]", @$self;
}
sub dump_perl {
my $self = shift;
return sprintf "[%s]", join ',', map "[$_->[0],$_->[1]]", @$self;
}
sub grow {
my $self = shift;
return $self->split_at_first_point->grow(@_);
@ -40,15 +45,52 @@ sub subdivide {
return Slic3r::Polygon->new(@new_points);
}
# for cw polygons this will return convex points!
sub concave_points {
my $self = shift;
my ($self, $angle) = @_;
$angle //= PI;
# input angle threshold is checked on the internal side of the polygon
# but angle3points measures CCW angle, so we calculate the complementary angle
my $ccw_angle = 2*PI-$angle;
my @points = @$self;
my @points_pp = @{$self->pp};
return map $points[$_],
grep Slic3r::Geometry::angle3points(@points_pp[$_, $_-1, $_+1]) < PI - epsilon,
-1 .. ($#points-1);
my @concave = ();
for my $i (-1 .. ($#points-1)) {
next if $points[$i-1]->coincides_with($points[$i]);
# angle is measured in ccw orientation
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
if ($vertex_angle <= $ccw_angle) {
push @concave, $points[$i];
}
}
return [@concave];
}
sub convex_points {
my ($self, $angle) = @_;
$angle //= PI;
# input angle threshold is checked on the internal side of the polygon
# but angle3points measures CCW angle, so we calculate the complementary angle
my $ccw_angle = 2*PI-$angle;
my @points = @$self;
my @points_pp = @{$self->pp};
my @convex = ();
for my $i (-1 .. ($#points-1)) {
next if $points[$i-1]->coincides_with($points[$i]);
# angle is measured in ccw orientation
my $vertex_angle = Slic3r::Geometry::angle3points(@points_pp[$i, $i-1, $i+1]);
if ($vertex_angle >= $ccw_angle) {
push @convex, $points[$i];
}
}
return [@convex];
}
1;

View file

@ -3,7 +3,7 @@ use strict;
use warnings;
use List::Util qw(first);
use Slic3r::Geometry qw(X Y epsilon);
use Slic3r::Geometry qw(X Y PI epsilon);
use Slic3r::Geometry::Clipper qw(JT_SQUARE);
sub new_scale {

View file

@ -580,7 +580,7 @@ EOF
my @current_layer_slices = ();
# sort slices so that the outermost ones come first
my @slices = sort { $a->contour->encloses_point($b->contour->[0]) ? 0 : 1 } @{$layer->slices};
my @slices = sort { $a->contour->contains_point($b->contour->[0]) ? 0 : 1 } @{$layer->slices};
foreach my $copy (@{$layer->object->copies}) {
foreach my $slice (@slices) {
my $expolygon = $slice->clone;
@ -625,11 +625,14 @@ EOF
sub make_skirt {
my $self = shift;
# since this method must be idempotent, we clear skirt paths *before*
# checking whether we need to generate them
$self->skirt->clear;
return unless $self->config->skirts > 0
|| ($self->config->ooze_prevention && @{$self->extruders} > 1);
$self->skirt->clear; # method must be idempotent
# First off we need to decide how tall the skirt must be.
# The skirt_height option from config is expressed in layers, but our
# object might have different layer heights, so we need to find the print_z
@ -737,9 +740,12 @@ sub make_skirt {
sub make_brim {
my $self = shift;
return unless $self->config->brim_width > 0;
$self->brim->clear; # method must be idempotent
# since this method must be idempotent, we clear brim paths *before*
# checking whether we need to generate them
$self->brim->clear;
return unless $self->config->brim_width > 0;
# brim is only printed on first layer and uses support material extruder
my $first_layer_height = $self->objects->[0]->config->get_abs_value('first_layer_height');
@ -851,11 +857,11 @@ sub write_gcode {
# set up our helper object
my $gcodegen = Slic3r::GCode->new(
print_config => $self->config,
placeholder_parser => $self->placeholder_parser,
layer_count => $self->layer_count,
);
$gcodegen->set_extruders($self->extruders);
$gcodegen->config->apply_print_config($self->config);
$gcodegen->set_extruders($self->extruders, $self->config);
print $fh "G21 ; set units to millimeters\n" if $self->config->gcode_flavor ne 'makerware';
print $fh $gcodegen->set_fan(0, 1) if $self->config->cooling && $self->config->disable_fan_first_layers;
@ -944,6 +950,7 @@ sub write_gcode {
my $finished_objects = 0;
for my $obj_idx (@obj_idx) {
my $object = $self->objects->[$obj_idx];
for my $copy (@{ $self->objects->[$obj_idx]->_shifted_copies }) {
# move to the origin position for the copy we're going to print.
# this happens before Z goes down to layer 0 again, so that
@ -951,7 +958,7 @@ sub write_gcode {
if ($finished_objects > 0) {
$gcodegen->set_shift(map unscale $copy->[$_], X,Y);
print $fh $gcodegen->retract;
print $fh $gcodegen->G0(Slic3r::Point->new(0,0), undef, 0, 'move to origin position for next object');
print $fh $gcodegen->G0($object->_copies_shift->negative, undef, 0, $gcodegen->config->travel_speed*60, 'move to origin position for next object');
}
my $buffer = Slic3r::GCode::CoolingBuffer->new(
@ -959,7 +966,6 @@ sub write_gcode {
gcodegen => $gcodegen,
);
my $object = $self->objects->[$obj_idx];
my @layers = sort { $a->print_z <=> $b->print_z } @{$object->layers}, @{$object->support_layers};
for my $layer (@layers) {
# if we are printing the bottom layer of an object, and we have already finished
@ -1037,9 +1043,11 @@ sub write_gcode {
# append full config
print $fh "\n";
foreach my $opt_key (sort @{$self->config->get_keys}) {
next if $Slic3r::Config::Options->{$opt_key}{shortcut};
printf $fh "; %s = %s\n", $opt_key, $self->config->serialize($opt_key);
foreach my $config ($self->config, $self->default_object_config, $self->default_region_config) {
foreach my $opt_key (sort @{$config->get_keys}) {
next if $Slic3r::Config::Options->{$opt_key}{shortcut};
printf $fh "; %s = %s\n", $opt_key, $config->serialize($opt_key);
}
}
# close our gcode file

View file

@ -308,11 +308,10 @@ sub slice {
}
# remove empty layers from bottom
my $first_object_layer_id = $self->config->raft_layers;
while (@{$self->layers} && !@{$self->layers->[$first_object_layer_id]->slices}) {
splice @{$self->layers}, $first_object_layer_id, 1;
for (my $i = $first_object_layer_id; $i <= $#{$self->layers}; $i++) {
$self->layers->[$i]->id($i);
while (@{$self->layers} && !@{$self->layers->[0]->slices}) {
shift @{$self->layers};
for (my $i = 0; $i <= $#{$self->layers}; $i++) {
$self->layers->[$i]->id( $self->layers->[$i]->id-1 );
}
}
@ -965,6 +964,9 @@ sub combine_infill {
sub generate_support_material {
my $self = shift;
# TODO: make this method idempotent by removing all support layers
# before checking whether we need to generate support or not
return unless ($self->config->support_material || $self->config->raft_layers > 0)
&& scalar(@{$self->layers}) >= 2;

View file

@ -132,7 +132,7 @@ sub contact_area {
# If a threshold angle was specified, use a different logic for detecting overhangs.
if (defined $threshold_rad
|| $layer_id < $self->object_config->support_material_enforce_layers
|| $self->object_config->raft_layers > 0) {
|| ($self->object_config->raft_layers > 0 && $layer_id == 0)) {
my $d = defined $threshold_rad
? scale $lower_layer->height * ((cos $threshold_rad) / (sin $threshold_rad))
: 0;
@ -608,7 +608,7 @@ sub generate_toolpaths {
my $mm3_per_mm = $interface_flow->mm3_per_mm($layer->height);
@loops = map Slic3r::ExtrusionPath->new(
polyline => $_,
role => EXTR_ROLE_SUPPORTMATERIAL,
role => EXTR_ROLE_SUPPORTMATERIAL_INTERFACE,
mm3_per_mm => $mm3_per_mm,
width => $interface_flow->width,
height => $layer->height,
@ -656,7 +656,7 @@ sub generate_toolpaths {
push @paths, map Slic3r::ExtrusionPath->new(
polyline => Slic3r::Polyline->new(@$_),
role => EXTR_ROLE_SUPPORTMATERIAL,
role => EXTR_ROLE_SUPPORTMATERIAL_INTERFACE,
mm3_per_mm => $mm3_per_mm,
width => $params->{flow}->width,
height => $layer->height,