Assign extruders and flows to materials

This commit is contained in:
Alessandro Ranellucci 2012-09-23 02:40:25 +02:00
parent e2ab340edb
commit e696764af8
10 changed files with 161 additions and 120 deletions

View file

@ -5,13 +5,14 @@ use List::Util qw(first);
use Slic3r::ExtrusionPath ':roles';
use Slic3r::Geometry qw(scale unscale scaled_epsilon points_coincide PI X Y);
has 'multiple_extruders' => (is => 'ro', default => sub {0} );
has 'layer' => (is => 'rw');
has 'shift_x' => (is => 'rw', default => sub {0} );
has 'shift_y' => (is => 'rw', default => sub {0} );
has 'z' => (is => 'rw', default => sub {0} );
has 'speed' => (is => 'rw');
has 'extruder_idx' => (is => 'rw');
has 'extruder' => (is => 'rw');
has 'extrusion_distance' => (is => 'rw', default => sub {0} );
has 'elapsed_time' => (is => 'rw', default => sub {0} ); # seconds
has 'total_extrusion_length' => (is => 'rw', default => sub {0} );
@ -49,11 +50,6 @@ my %role_speeds = (
&EXTR_ROLE_SUPPORTMATERIAL => 'perimeter',
);
sub extruder {
my $self = shift;
return $Slic3r::extruders->[$self->extruder_idx];
}
sub change_layer {
my $self = shift;
my ($layer) = @_;
@ -374,26 +370,26 @@ sub _Gx {
return "$gcode\n";
}
sub set_tool {
sub set_extruder {
my $self = shift;
my ($tool) = @_;
my ($extruder) = @_;
# return nothing if this tool was already selected
return "" if (defined $self->extruder_idx) && ($self->extruder_idx == $tool);
# return nothing if this extruder was already selected
return "" if (defined $self->extruder) && ($self->extruder->id == $extruder);
# if we are running a single-extruder setup, just set the extruder and return nothing
if (@{$Slic3r::extruders} == 1) {
$self->extruder_idx($tool);
if (!$self->multiple_extruders) {
$self->extruder($extruder);
return "";
}
# trigger retraction on the current tool (if any)
# trigger retraction on the current extruder (if any)
my $gcode = "";
$gcode .= $self->retract(toolchange => 1) if defined $self->extruder_idx;
$gcode .= $self->retract(toolchange => 1) if defined $self->extruder;
# set the new tool
$self->extruder_idx($tool);
$gcode .= sprintf "T%d%s\n", $tool, ($Slic3r::Config->gcode_comments ? ' ; change tool' : '');
# set the new extruder
$self->extruder($extruder);
$gcode .= sprintf "T%d%s\n", $extruder, ($Slic3r::Config->gcode_comments ? ' ; change extruder' : '');
$gcode .= $self->reset_e;
return $gcode;
@ -426,7 +422,7 @@ sub set_temperature {
: ('M104', 'set temperature');
my $gcode = sprintf "$code %s%d %s; $comment\n",
($Slic3r::Config->gcode_flavor eq 'mach3' ? 'P' : 'S'), $temperature,
(defined $tool && $tool != $self->extruder_idx) ? "T$tool " : "";
(defined $tool && $tool != $self->extruder->id) ? "T$tool " : "";
$gcode .= "M116 ; wait for temperature to be reached\n"
if $Slic3r::Config->gcode_flavor eq 'teacup' && $wait;