2012-06-28 14:44:54 +02:00
|
|
|
|
package Slic3r::GCode;
|
2015-07-01 21:47:17 +02:00
|
|
|
|
use strict;
|
|
|
|
|
|
use warnings;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-03-27 00:01:33 +01:00
|
|
|
|
use List::Util qw(min max first);
|
2014-05-12 21:49:17 +02:00
|
|
|
|
use Slic3r::ExtrusionLoop ':roles';
|
2012-06-28 14:44:54 +02:00
|
|
|
|
use Slic3r::ExtrusionPath ':roles';
|
2014-10-25 11:15:12 +02:00
|
|
|
|
use Slic3r::Geometry qw(epsilon scale unscale PI X Y B);
|
2014-11-23 20:16:51 +01:00
|
|
|
|
use Slic3r::Geometry::Clipper qw(union_ex);
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-01-03 18:27:46 +01:00
|
|
|
|
sub set_extruders {
|
2014-10-18 17:41:21 +02:00
|
|
|
|
my ($self, $extruder_ids) = @_;
|
2014-01-03 18:27:46 +01:00
|
|
|
|
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$self->writer->set_extruders($extruder_ids);
|
2014-03-27 00:01:33 +01:00
|
|
|
|
|
2014-10-18 17:41:21 +02:00
|
|
|
|
# enable wipe path generation if any extruder has wipe enabled
|
2015-07-01 20:57:16 +02:00
|
|
|
|
$self->wipe->set_enable(defined first { $self->config->get_at('wipe', $_) } @$extruder_ids);
|
2014-01-03 18:27:46 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-06-28 14:44:54 +02:00
|
|
|
|
sub change_layer {
|
2013-08-27 00:02:24 +02:00
|
|
|
|
my ($self, $layer) = @_;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2015-07-01 21:47:17 +02:00
|
|
|
|
{
|
|
|
|
|
|
my $l = $layer->isa('Slic3r::Layer::Support')
|
|
|
|
|
|
? $layer->as_layer
|
|
|
|
|
|
: $layer;
|
|
|
|
|
|
$self->set_layer($l);
|
|
|
|
|
|
}
|
|
|
|
|
|
$self->set_layer_index($self->layer_index + 1);
|
|
|
|
|
|
$self->set_first_layer($layer->id == 0);
|
2013-07-07 19:12:44 +02:00
|
|
|
|
|
2013-08-09 14:55:36 +02:00
|
|
|
|
# avoid computing islands and overhangs if they're not needed
|
2014-05-13 08:34:21 +02:00
|
|
|
|
if ($self->config->avoid_crossing_perimeters) {
|
2014-11-23 15:13:40 +01:00
|
|
|
|
$self->avoid_crossing_perimeters->init_layer_mp(
|
2014-05-13 20:06:01 +02:00
|
|
|
|
union_ex([ map @$_, @{$layer->slices} ], 1),
|
2014-11-23 15:13:40 +01:00
|
|
|
|
);
|
2012-08-23 15:42:58 +02:00
|
|
|
|
}
|
2013-01-17 14:56:31 +01:00
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
2015-07-01 21:47:17 +02:00
|
|
|
|
if ($self->layer_count > 0) {
|
2015-05-03 20:18:34 +02:00
|
|
|
|
$gcode .= $self->writer->update_progress($self->layer_index, $self->layer_count);
|
2013-01-17 14:56:31 +01:00
|
|
|
|
}
|
2013-08-09 19:46:20 +02:00
|
|
|
|
|
2014-10-21 20:16:45 +02:00
|
|
|
|
my $z = $layer->print_z + $self->config->z_offset; # in unscaled coordinates
|
2014-10-28 21:47:09 +01:00
|
|
|
|
if ($self->config->get_at('retract_layer_change', $self->writer->extruder->id) && $self->writer->will_move_z($z)) {
|
2014-10-21 20:16:45 +02:00
|
|
|
|
$gcode .= $self->retract;
|
2012-10-30 10:45:55 +01:00
|
|
|
|
}
|
2015-05-03 20:18:34 +02:00
|
|
|
|
$gcode .= $self->writer->travel_to_z($z, 'move to next layer (' . $self->layer_index . ')');
|
2014-12-24 12:02:42 +01:00
|
|
|
|
|
|
|
|
|
|
# forget last wiping path as wiping after raising Z is pointless
|
2015-07-01 20:57:16 +02:00
|
|
|
|
$self->wipe->reset_path;
|
2014-12-24 12:02:42 +01:00
|
|
|
|
|
2012-06-28 14:44:54 +02:00
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub extrude {
|
|
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
2013-07-15 16:21:09 +02:00
|
|
|
|
$_[0]->isa('Slic3r::ExtrusionLoop')
|
2012-07-20 14:39:07 +02:00
|
|
|
|
? $self->extrude_loop(@_)
|
|
|
|
|
|
: $self->extrude_path(@_);
|
2012-06-28 14:44:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub extrude_loop {
|
2014-05-18 17:02:18 +02:00
|
|
|
|
my ($self, $loop, $description, $speed) = @_;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-03-24 20:01:14 +01:00
|
|
|
|
# make a copy; don't modify the orientation of the original loop object otherwise
|
|
|
|
|
|
# next copies (if any) would not detect the correct orientation
|
|
|
|
|
|
$loop = $loop->clone;
|
|
|
|
|
|
|
2012-06-28 14:44:54 +02:00
|
|
|
|
# extrude all loops ccw
|
2013-07-16 17:13:01 +02:00
|
|
|
|
my $was_clockwise = $loop->make_counter_clockwise;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
|
|
|
|
|
# find the point of the loop that is closest to the current extruder position
|
|
|
|
|
|
# or randomize if requested
|
|
|
|
|
|
my $last_pos = $self->last_pos;
|
2014-05-22 12:28:12 +02:00
|
|
|
|
if ($self->config->spiral_vase) {
|
|
|
|
|
|
$loop->split_at($last_pos);
|
2014-05-24 22:10:28 +02:00
|
|
|
|
} elsif ($self->config->seam_position eq 'nearest' || $self->config->seam_position eq 'aligned') {
|
2014-07-25 12:04:33 +02:00
|
|
|
|
# simplify polygon in order to skip false positives in concave/convex detection
|
2015-06-01 17:55:51 +02:00
|
|
|
|
# ($loop is always ccw as $polygon->simplify only works on ccw polygons)
|
2014-05-22 19:34:49 +02:00
|
|
|
|
my $polygon = $loop->polygon;
|
2014-10-28 21:47:09 +01:00
|
|
|
|
my @simplified = @{$polygon->simplify(scale $self->config->get_at('nozzle_diameter', $self->writer->extruder->id)/2)};
|
2014-05-22 19:34:49 +02:00
|
|
|
|
|
2015-06-01 17:55:51 +02:00
|
|
|
|
# restore original winding order so that concave and convex detection always happens
|
|
|
|
|
|
# on the right/outer side of the polygon
|
|
|
|
|
|
if ($was_clockwise) {
|
|
|
|
|
|
$_->reverse for @simplified;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-07-25 12:04:33 +02:00
|
|
|
|
# concave vertices have priority
|
|
|
|
|
|
my @candidates = map @{$_->concave_points(PI*4/3)}, @simplified;
|
2014-05-22 19:34:49 +02:00
|
|
|
|
|
2014-07-25 12:04:33 +02:00
|
|
|
|
# if no concave points were found, look for convex vertices
|
|
|
|
|
|
@candidates = map @{$_->convex_points(PI*2/3)}, @simplified if !@candidates;
|
|
|
|
|
|
|
|
|
|
|
|
# retrieve the last start position for this object
|
2015-07-01 21:47:17 +02:00
|
|
|
|
if ($self->has_layer) {
|
|
|
|
|
|
if ($self->_has_seam_position($self->layer->object)) {
|
|
|
|
|
|
$last_pos = $self->_seam_position($self->layer->object);
|
2014-05-22 19:34:49 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2014-07-25 12:04:33 +02:00
|
|
|
|
|
|
|
|
|
|
my $point;
|
|
|
|
|
|
if ($self->config->seam_position eq 'nearest') {
|
|
|
|
|
|
@candidates = @$polygon if !@candidates;
|
|
|
|
|
|
$point = $last_pos->nearest_point(\@candidates);
|
2014-11-08 12:56:14 +01:00
|
|
|
|
if (!$loop->split_at_vertex($point)) {
|
|
|
|
|
|
# On 32-bit Linux, Clipper will change some point coordinates by 1 unit
|
|
|
|
|
|
# while performing simplify_polygons(), thus split_at_vertex() won't
|
|
|
|
|
|
# find them anymore.
|
|
|
|
|
|
$loop->split_at($point);
|
|
|
|
|
|
}
|
2014-07-25 12:04:33 +02:00
|
|
|
|
} elsif (@candidates) {
|
|
|
|
|
|
my @non_overhang = grep !$loop->has_overhang_point($_), @candidates;
|
|
|
|
|
|
@candidates = @non_overhang if @non_overhang;
|
|
|
|
|
|
$point = $last_pos->nearest_point(\@candidates);
|
2014-11-08 12:56:14 +01:00
|
|
|
|
if (!$loop->split_at_vertex($point)) {
|
|
|
|
|
|
$loop->split_at($point);
|
|
|
|
|
|
}
|
2014-07-25 12:04:33 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
$point = $last_pos->projection_onto_polygon($polygon);
|
|
|
|
|
|
$loop->split_at($point);
|
|
|
|
|
|
}
|
2015-07-01 21:47:17 +02:00
|
|
|
|
$self->_set_seam_position($self->layer->object, $point)
|
|
|
|
|
|
if $self->has_layer;
|
2014-05-24 22:10:28 +02:00
|
|
|
|
} elsif ($self->config->seam_position eq 'random') {
|
2014-05-22 19:34:49 +02:00
|
|
|
|
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);
|
2014-05-22 12:28:12 +02:00
|
|
|
|
}
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
|
|
|
|
|
# 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
|
2014-05-08 11:07:37 +02:00
|
|
|
|
my $clip_length = $self->enable_loop_clipping
|
2014-10-28 21:47:09 +01:00
|
|
|
|
? scale($self->config->get_at('nozzle_diameter', $self->writer->extruder->id)) * &Slic3r::LOOP_CLIPPING_LENGTH_OVER_NOZZLE_DIAMETER
|
2014-05-08 11:07:37 +02:00
|
|
|
|
: 0;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-05-08 11:07:37 +02:00
|
|
|
|
# get paths
|
|
|
|
|
|
my @paths = @{$loop->clip_end($clip_length)};
|
|
|
|
|
|
return '' if !@paths;
|
2013-06-20 20:11:46 +02:00
|
|
|
|
|
2013-06-21 14:52:35 +02:00
|
|
|
|
# apply the small perimeter speed
|
2014-05-13 08:34:21 +02:00
|
|
|
|
if ($paths[0]->is_perimeter && $loop->length <= &Slic3r::SMALL_PERIMETER_LENGTH) {
|
2014-05-18 17:02:18 +02:00
|
|
|
|
$speed //= $self->config->get_abs_value('small_perimeter_speed');
|
2013-06-21 14:52:35 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-06-28 14:44:54 +02:00
|
|
|
|
# extrude along the path
|
2014-08-03 16:31:20 +02:00
|
|
|
|
my $gcode = join '', map $self->_extrude_path($_, $description, $speed), @paths;
|
|
|
|
|
|
|
|
|
|
|
|
# reset acceleration
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= $self->writer->set_acceleration($self->config->default_acceleration);
|
2014-08-03 16:31:20 +02:00
|
|
|
|
|
2015-07-01 20:57:16 +02:00
|
|
|
|
$self->wipe->set_path($paths[0]->polyline->clone) if $self->wipe->enable; # TODO: don't limit wipe to last path
|
2012-12-05 11:31:35 +01:00
|
|
|
|
|
|
|
|
|
|
# make a little move inwards before leaving loop
|
2015-07-01 21:47:17 +02:00
|
|
|
|
if ($paths[-1]->role == EXTR_ROLE_EXTERNAL_PERIMETER && $self->has_layer && $self->config->perimeters > 1) {
|
2014-05-08 11:07:37 +02:00
|
|
|
|
my $last_path_polyline = $paths[-1]->polyline;
|
2012-12-05 11:31:35 +01:00
|
|
|
|
# detect angle between last and first segment
|
|
|
|
|
|
# the side depends on the original winding order of the polygon (left for contours, right for holes)
|
2015-01-08 15:19:56 +01:00
|
|
|
|
my @points = ($paths[0][1], $paths[-1][-2]);
|
|
|
|
|
|
@points = reverse @points if $was_clockwise;
|
|
|
|
|
|
my $angle = $paths[0]->first_point->ccw_angle(@points) / 3;
|
|
|
|
|
|
|
|
|
|
|
|
# turn left if contour, turn right if hole
|
2012-12-05 11:31:35 +01:00
|
|
|
|
$angle *= -1 if $was_clockwise;
|
|
|
|
|
|
|
|
|
|
|
|
# create the destination point along the first segment and rotate it
|
2013-03-09 17:15:45 +01:00
|
|
|
|
# we make sure we don't exceed the segment length because we don't know
|
|
|
|
|
|
# the rotation of the second segment so we might cross the object boundary
|
2014-12-25 11:06:42 +01:00
|
|
|
|
my $first_segment = Slic3r::Line->new(@{$paths[0]->polyline}[0,1]);
|
2014-10-28 21:47:09 +01:00
|
|
|
|
my $distance = min(scale($self->config->get_at('nozzle_diameter', $self->writer->extruder->id)), $first_segment->length);
|
2013-10-27 22:57:25 +01:00
|
|
|
|
my $point = $first_segment->point_at($distance);
|
2014-12-25 11:06:42 +01:00
|
|
|
|
$point->rotate($angle, $first_segment->a);
|
2012-12-05 11:31:35 +01:00
|
|
|
|
|
|
|
|
|
|
# generate the travel move
|
2014-12-29 17:40:56 +01:00
|
|
|
|
$gcode .= $self->writer->travel_to_xy($self->point_to_gcode($point), "move inwards before travel");
|
2012-12-05 11:31:35 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub extrude_path {
|
2014-05-13 08:34:21 +02:00
|
|
|
|
my ($self, $path, $description, $speed) = @_;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-08-03 16:31:20 +02:00
|
|
|
|
my $gcode = $self->_extrude_path($path, $description, $speed);
|
|
|
|
|
|
|
|
|
|
|
|
# reset acceleration
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= $self->writer->set_acceleration($self->config->default_acceleration);
|
2014-08-03 16:31:20 +02:00
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub _extrude_path {
|
|
|
|
|
|
my ($self, $path, $description, $speed) = @_;
|
|
|
|
|
|
|
2012-11-18 17:38:08 +01:00
|
|
|
|
$path->simplify(&Slic3r::SCALED_RESOLUTION);
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
|
|
|
|
|
# go to first point of extrusion path
|
2013-03-05 17:30:27 +01:00
|
|
|
|
my $gcode = "";
|
2013-08-29 01:36:42 +02:00
|
|
|
|
{
|
|
|
|
|
|
my $first_point = $path->first_point;
|
|
|
|
|
|
$gcode .= $self->travel_to($first_point, $path->role, "move to first $description point")
|
2015-07-01 21:47:17 +02:00
|
|
|
|
if !$self->last_pos_defined || !$self->last_pos->coincides_with($first_point);
|
2013-08-29 01:36:42 +02:00
|
|
|
|
}
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
|
|
|
|
|
# compensate retraction
|
2012-12-21 15:14:44 +01:00
|
|
|
|
$gcode .= $self->unretract;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2013-03-09 20:28:03 +01:00
|
|
|
|
# adjust acceleration
|
2014-08-03 16:31:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
my $acceleration;
|
2014-10-28 21:47:09 +01:00
|
|
|
|
if ($self->config->first_layer_acceleration && $self->first_layer) {
|
2014-08-03 16:31:20 +02:00
|
|
|
|
$acceleration = $self->config->first_layer_acceleration;
|
|
|
|
|
|
} elsif ($self->config->perimeter_acceleration && $path->is_perimeter) {
|
2014-05-13 08:34:21 +02:00
|
|
|
|
$acceleration = $self->config->perimeter_acceleration;
|
2014-10-15 00:23:58 +02:00
|
|
|
|
} elsif ($self->config->bridge_acceleration && $path->is_bridge) {
|
2014-05-13 08:34:21 +02:00
|
|
|
|
$acceleration = $self->config->bridge_acceleration;
|
2014-12-17 00:34:00 +01:00
|
|
|
|
} elsif ($self->config->infill_acceleration && $path->is_infill) {
|
|
|
|
|
|
$acceleration = $self->config->infill_acceleration;
|
2014-08-03 16:31:20 +02:00
|
|
|
|
} else {
|
|
|
|
|
|
$acceleration = $self->config->default_acceleration;
|
2013-08-09 14:30:43 +02:00
|
|
|
|
}
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= $self->writer->set_acceleration($acceleration);
|
2013-03-09 20:31:09 +01:00
|
|
|
|
}
|
2013-03-09 20:28:03 +01:00
|
|
|
|
|
2012-07-03 18:05:31 +02:00
|
|
|
|
# calculate extrusion length per distance unit
|
2014-10-28 21:47:09 +01:00
|
|
|
|
my $e_per_mm = $self->writer->extruder->e_per_mm3 * $path->mm3_per_mm;
|
2014-11-09 19:02:45 +01:00
|
|
|
|
$e_per_mm = 0 if !$self->writer->extrusion_axis;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2012-12-05 10:47:41 +01:00
|
|
|
|
# set speed
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed //= -1;
|
|
|
|
|
|
if ($speed == -1) {
|
2014-11-23 19:15:28 +01:00
|
|
|
|
if ($path->role == EXTR_ROLE_PERIMETER) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('perimeter_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_EXTERNAL_PERIMETER) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('external_perimeter_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_OVERHANG_PERIMETER || $path->role == EXTR_ROLE_BRIDGE) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('bridge_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_FILL) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('infill_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_SOLIDFILL) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('solid_infill_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_TOPSOLIDFILL) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('top_solid_infill_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} elsif ($path->role == EXTR_ROLE_GAPFILL) {
|
2014-11-23 19:37:59 +01:00
|
|
|
|
$speed = $self->config->get_abs_value('gap_fill_speed');
|
2014-11-23 19:15:28 +01:00
|
|
|
|
} else {
|
|
|
|
|
|
die "Invalid speed";
|
|
|
|
|
|
}
|
2014-05-13 08:34:21 +02:00
|
|
|
|
}
|
2014-10-28 21:47:09 +01:00
|
|
|
|
if ($self->first_layer) {
|
2015-05-31 22:04:32 +02:00
|
|
|
|
$speed = $self->config->get_abs_value_over('first_layer_speed', $speed);
|
2013-08-28 18:12:20 +02:00
|
|
|
|
}
|
2015-05-31 22:04:32 +02:00
|
|
|
|
if ($self->volumetric_speed != 0) {
|
|
|
|
|
|
$speed ||= $self->volumetric_speed / $path->mm3_per_mm;
|
|
|
|
|
|
}
|
2015-06-02 11:54:38 +02:00
|
|
|
|
if ($self->config->max_volumetric_speed > 0) {
|
|
|
|
|
|
# Cap speed with max_volumetric_speed anyway (even if user is not using autospeed)
|
|
|
|
|
|
$speed = min(
|
|
|
|
|
|
$speed,
|
|
|
|
|
|
$self->config->max_volumetric_speed / $path->mm3_per_mm,
|
|
|
|
|
|
);
|
|
|
|
|
|
}
|
2015-05-31 22:04:32 +02:00
|
|
|
|
my $F = $speed * 60; # convert mm/sec to mm/min
|
2015-06-02 11:49:43 +02:00
|
|
|
|
|
2012-12-05 10:47:41 +01:00
|
|
|
|
# extrude arc or line
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= ";_BRIDGE_FAN_START\n" if $path->is_bridge && $self->enable_cooling_markers;
|
2014-04-01 16:54:57 +03:00
|
|
|
|
my $path_length = unscale $path->length;
|
2013-08-28 19:50:16 +02:00
|
|
|
|
{
|
2014-10-28 21:47:09 +01:00
|
|
|
|
my $extruder_offset = $self->config->get_at('extruder_offset', $self->writer->extruder->id);
|
|
|
|
|
|
$gcode .= $path->gcode($self->writer->extruder, $e_per_mm, $F,
|
2014-10-25 10:56:21 +02:00
|
|
|
|
$self->origin->x - $extruder_offset->x,
|
|
|
|
|
|
$self->origin->y - $extruder_offset->y, #-
|
2014-11-09 19:02:45 +01:00
|
|
|
|
$self->writer->extrusion_axis,
|
2014-05-13 08:34:21 +02:00
|
|
|
|
$self->config->gcode_comments ? " ; $description" : "");
|
2014-04-01 16:54:57 +03:00
|
|
|
|
|
2014-11-23 15:13:40 +01:00
|
|
|
|
if ($self->wipe->enable) {
|
2015-07-01 20:57:16 +02:00
|
|
|
|
$self->wipe->set_path($path->polyline->clone);
|
2014-11-23 15:13:40 +01:00
|
|
|
|
$self->wipe->path->reverse;
|
2013-08-29 01:36:42 +02:00
|
|
|
|
}
|
2012-06-28 14:44:54 +02:00
|
|
|
|
}
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= ";_BRIDGE_FAN_END\n" if $path->is_bridge && $self->enable_cooling_markers;
|
2015-07-01 21:47:17 +02:00
|
|
|
|
$self->set_last_pos($path->last_point);
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2014-05-13 08:34:21 +02:00
|
|
|
|
if ($self->config->cooling) {
|
2013-08-28 18:12:20 +02:00
|
|
|
|
my $path_time = $path_length / $F * 60;
|
2015-07-01 21:47:17 +02:00
|
|
|
|
$self->set_elapsed_time($self->elapsed_time + $path_time);
|
2012-06-28 14:44:54 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2014-12-28 22:09:28 +01:00
|
|
|
|
# This method accepts $point in print coordinates.
|
2012-08-23 15:42:58 +02:00
|
|
|
|
sub travel_to {
|
2013-08-27 00:02:24 +02:00
|
|
|
|
my ($self, $point, $role, $comment) = @_;
|
2012-08-23 15:42:58 +02:00
|
|
|
|
|
2014-10-27 10:34:51 +01:00
|
|
|
|
# Define the travel move as a line between current position and the taget point.
|
|
|
|
|
|
# This is expressed in print coordinates, so it will need to be translated by
|
|
|
|
|
|
# $self->origin in order to get G-code coordinates.
|
2015-01-06 14:47:53 +01:00
|
|
|
|
my $travel = Slic3r::Polyline->new($self->last_pos, $point);
|
2013-03-05 17:30:27 +01:00
|
|
|
|
|
2015-01-06 14:47:53 +01:00
|
|
|
|
# check whether a straight travel move would need retraction
|
2015-07-02 14:29:20 +02:00
|
|
|
|
my $needs_retraction = $self->needs_retraction($travel, $role // EXTR_ROLE_NONE);
|
2015-01-06 14:47:53 +01:00
|
|
|
|
|
|
|
|
|
|
# if a retraction would be needed, try to use avoid_crossing_perimeters to plan a
|
|
|
|
|
|
# multi-hop travel path inside the configuration space
|
|
|
|
|
|
if ($needs_retraction
|
|
|
|
|
|
&& $self->config->avoid_crossing_perimeters
|
|
|
|
|
|
&& !$self->avoid_crossing_perimeters->disable_once) {
|
2015-07-01 23:00:52 +02:00
|
|
|
|
$travel = $self->avoid_crossing_perimeters->travel_to($self, $point);
|
2015-01-06 14:47:53 +01:00
|
|
|
|
|
|
|
|
|
|
# check again whether the new travel path still needs a retraction
|
2015-07-02 14:29:20 +02:00
|
|
|
|
$needs_retraction = $self->needs_retraction($travel, $role // EXTR_ROLE_NONE);
|
2012-08-23 15:42:58 +02:00
|
|
|
|
}
|
2012-08-23 21:10:04 +02:00
|
|
|
|
|
2014-10-27 10:34:51 +01:00
|
|
|
|
# Re-allow avoid_crossing_perimeters for the next travel moves
|
2015-07-01 20:14:05 +02:00
|
|
|
|
$self->avoid_crossing_perimeters->set_disable_once(0);
|
|
|
|
|
|
$self->avoid_crossing_perimeters->set_use_external_mp_once(0);
|
2015-01-06 14:47:53 +01:00
|
|
|
|
|
|
|
|
|
|
# generate G-code for the travel move
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
|
$gcode .= $self->retract if $needs_retraction;
|
|
|
|
|
|
|
|
|
|
|
|
# use G1 because we rely on paths being straight (G0 may make round paths)
|
|
|
|
|
|
$gcode .= $self->writer->travel_to_xy($self->point_to_gcode($_->b), $comment)
|
|
|
|
|
|
for @{$travel->lines};
|
2014-10-27 10:34:51 +01:00
|
|
|
|
|
2012-08-23 21:10:04 +02:00
|
|
|
|
return $gcode;
|
2012-08-23 15:42:58 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2012-09-23 02:40:25 +02:00
|
|
|
|
sub set_extruder {
|
2014-01-03 18:27:46 +01:00
|
|
|
|
my ($self, $extruder_id) = @_;
|
2012-06-28 14:44:54 +02:00
|
|
|
|
|
2015-05-31 22:14:24 +02:00
|
|
|
|
$self->placeholder_parser->set('current_extruder', $extruder_id);
|
2014-10-28 21:47:09 +01:00
|
|
|
|
return "" if !$self->writer->need_toolchange($extruder_id);
|
2012-08-22 19:20:34 +02:00
|
|
|
|
|
2012-08-22 19:47:59 +02:00
|
|
|
|
# if we are running a single-extruder setup, just set the extruder and return nothing
|
2014-10-28 21:47:09 +01:00
|
|
|
|
if (!$self->writer->multiple_extruders) {
|
|
|
|
|
|
return $self->writer->toolchange($extruder_id);
|
2012-08-22 19:47:59 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-18 17:41:21 +02:00
|
|
|
|
# prepend retraction on the current extruder
|
2014-10-21 20:16:45 +02:00
|
|
|
|
my $gcode = $self->retract(1);
|
2012-08-22 19:47:59 +02:00
|
|
|
|
|
2012-12-23 16:29:08 +01:00
|
|
|
|
# append custom toolchange G-code
|
2014-10-28 21:47:09 +01:00
|
|
|
|
if (defined $self->writer->extruder && $self->config->toolchange_gcode) {
|
2015-07-01 19:35:22 +02:00
|
|
|
|
my $pp = $self->placeholder_parser->clone;
|
|
|
|
|
|
$pp->set('previous_extruder' => $self->writer->extruder->id);
|
|
|
|
|
|
$pp->set('next_extruder' => $extruder_id);
|
|
|
|
|
|
$gcode .= sprintf "%s\n", $pp->process($self->config->toolchange_gcode);
|
2012-12-23 16:29:08 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2014-10-18 17:58:14 +02:00
|
|
|
|
# if ooze prevention is enabled, park current extruder in the nearest
|
|
|
|
|
|
# standby point and set it to the standby temperature
|
|
|
|
|
|
$gcode .= $self->ooze_prevention->pre_toolchange($self)
|
2014-11-23 15:13:40 +01:00
|
|
|
|
if $self->ooze_prevention->enable && defined $self->writer->extruder;
|
2013-09-18 18:49:19 +02:00
|
|
|
|
|
2014-10-18 17:41:21 +02:00
|
|
|
|
# append the toolchange command
|
2014-10-28 21:47:09 +01:00
|
|
|
|
$gcode .= $self->writer->toolchange($extruder_id);
|
2012-08-22 19:47:59 +02:00
|
|
|
|
|
2013-09-18 18:49:19 +02:00
|
|
|
|
# set the new extruder to the operating temperature
|
2014-10-18 17:58:14 +02:00
|
|
|
|
$gcode .= $self->ooze_prevention->post_toolchange($self)
|
2014-11-23 15:13:40 +01:00
|
|
|
|
if $self->ooze_prevention->enable;
|
|
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
package Slic3r::GCode::OozePrevention;
|
2015-07-01 21:01:42 +02:00
|
|
|
|
use strict;
|
|
|
|
|
|
use warnings;
|
2014-11-23 15:13:40 +01:00
|
|
|
|
|
|
|
|
|
|
use Slic3r::Geometry qw(scale);
|
|
|
|
|
|
|
|
|
|
|
|
sub pre_toolchange {
|
|
|
|
|
|
my ($self, $gcodegen) = @_;
|
|
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
|
|
|
|
|
|
|
# move to the nearest standby point
|
|
|
|
|
|
if (@{$self->standby_points}) {
|
2015-01-19 15:30:34 +01:00
|
|
|
|
# get current position in print coordinates
|
|
|
|
|
|
my $pos = Slic3r::Point->new_scale(@{$gcodegen->writer->get_position}[0,1]);
|
|
|
|
|
|
|
|
|
|
|
|
my $standby_point = Slic3r::Pointf->new_unscale(@{$pos->nearest_point($self->standby_points)});
|
|
|
|
|
|
# We don't call $gcodegen->travel_to() because we don't need retraction (it was already
|
|
|
|
|
|
# triggered by the caller) nor avoid_crossing_perimeters and also because the coordinates
|
|
|
|
|
|
# of the destination point must not be transformed by origin nor current extruder offset.
|
|
|
|
|
|
$gcode .= $gcodegen->writer->travel_to_xy($standby_point, 'move to standby position');
|
2014-11-23 15:13:40 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if ($gcodegen->config->standby_temperature_delta != 0) {
|
2015-07-01 21:47:17 +02:00
|
|
|
|
my $temp = $gcodegen->has_layer && $gcodegen->layer->id == 0
|
2014-11-23 15:13:40 +01:00
|
|
|
|
? $gcodegen->config->get_at('first_layer_temperature', $gcodegen->writer->extruder->id)
|
|
|
|
|
|
: $gcodegen->config->get_at('temperature', $gcodegen->writer->extruder->id);
|
|
|
|
|
|
# we assume that heating is always slower than cooling, so no need to block
|
|
|
|
|
|
$gcode .= $gcodegen->writer->set_temperature($temp + $gcodegen->config->standby_temperature_delta, 0);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
sub post_toolchange {
|
|
|
|
|
|
my ($self, $gcodegen) = @_;
|
|
|
|
|
|
|
|
|
|
|
|
my $gcode = "";
|
|
|
|
|
|
|
|
|
|
|
|
if ($gcodegen->config->standby_temperature_delta != 0) {
|
2015-07-01 21:47:17 +02:00
|
|
|
|
my $temp = $gcodegen->has_layer && $gcodegen->layer->id == 0
|
2014-11-23 15:13:40 +01:00
|
|
|
|
? $gcodegen->config->get_at('first_layer_temperature', $gcodegen->writer->extruder->id)
|
|
|
|
|
|
: $gcodegen->config->get_at('temperature', $gcodegen->writer->extruder->id);
|
|
|
|
|
|
$gcode .= $gcodegen->writer->set_temperature($temp, 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return $gcode;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2012-06-28 14:44:54 +02:00
|
|
|
|
1;
|