Fix regression causing toolchange_gcode to crash Slic3r. Includes regression test. #1545
This commit is contained in:
parent
5217bc370a
commit
387df3b900
4 changed files with 13 additions and 10 deletions
|
@ -8,6 +8,7 @@ use Slic3r::Geometry::Clipper qw(union_ex);
|
||||||
use Slic3r::Surface ':types';
|
use Slic3r::Surface ':types';
|
||||||
|
|
||||||
has 'config' => (is => 'ro', required => 1);
|
has 'config' => (is => 'ro', required => 1);
|
||||||
|
has 'extra_variables' => (is => 'rw', default => sub {{}});
|
||||||
has 'extruders' => (is => 'ro', required => 1);
|
has 'extruders' => (is => 'ro', required => 1);
|
||||||
has 'multiple_extruders' => (is => 'lazy');
|
has 'multiple_extruders' => (is => 'lazy');
|
||||||
has 'standby_points' => (is => 'rw');
|
has 'standby_points' => (is => 'rw');
|
||||||
|
@ -642,7 +643,7 @@ sub set_extruder {
|
||||||
|
|
||||||
# append custom toolchange G-code
|
# append custom toolchange G-code
|
||||||
if (defined $self->extruder && $self->config->toolchange_gcode) {
|
if (defined $self->extruder && $self->config->toolchange_gcode) {
|
||||||
$gcode .= sprintf "%s\n", $self->print->replace_variables($self->config->toolchange_gcode, {
|
$gcode .= sprintf "%s\n", $self->replace_variables($self->config->toolchange_gcode, {
|
||||||
previous_extruder => $self->extruder->id,
|
previous_extruder => $self->extruder->id,
|
||||||
next_extruder => $extruder->id,
|
next_extruder => $extruder->id,
|
||||||
});
|
});
|
||||||
|
@ -741,4 +742,9 @@ sub set_bed_temperature {
|
||||||
return $gcode;
|
return $gcode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub replace_variables {
|
||||||
|
my ($self, $string, $extra) = @_;
|
||||||
|
return $self->config->replace_options($string, { %{$self->extra_variables}, %{ $extra || {} } });
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
|
|
@ -66,7 +66,7 @@ sub process_layer {
|
||||||
|
|
||||||
# set new layer - this will change Z and force a retraction if retract_layer_change is enabled
|
# set new layer - this will change Z and force a retraction if retract_layer_change is enabled
|
||||||
$gcode .= $self->gcodegen->change_layer($layer);
|
$gcode .= $self->gcodegen->change_layer($layer);
|
||||||
$gcode .= $self->print->replace_variables($Slic3r::Config->layer_gcode, {
|
$gcode .= $self->gcodegen->replace_variables($Slic3r::Config->layer_gcode, {
|
||||||
layer_num => $self->gcodegen->layer->id,
|
layer_num => $self->gcodegen->layer->id,
|
||||||
}) . "\n" if $Slic3r::Config->layer_gcode;
|
}) . "\n" if $Slic3r::Config->layer_gcode;
|
||||||
|
|
||||||
|
|
|
@ -726,6 +726,7 @@ sub write_gcode {
|
||||||
# set up our extruder object
|
# set up our extruder object
|
||||||
my $gcodegen = Slic3r::GCode->new(
|
my $gcodegen = Slic3r::GCode->new(
|
||||||
config => $self->config,
|
config => $self->config,
|
||||||
|
extra_variables => $self->extra_variables,
|
||||||
extruders => $self->extruders, # we should only pass the *used* extruders (but maintain the Tx indices right!)
|
extruders => $self->extruders, # we should only pass the *used* extruders (but maintain the Tx indices right!)
|
||||||
layer_count => $self->layer_count,
|
layer_count => $self->layer_count,
|
||||||
);
|
);
|
||||||
|
@ -749,7 +750,7 @@ sub write_gcode {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
$print_first_layer_temperature->(0);
|
$print_first_layer_temperature->(0);
|
||||||
printf $fh "%s\n", $self->replace_variables($Slic3r::Config->start_gcode);
|
printf $fh "%s\n", $gcodegen->replace_variables($Slic3r::Config->start_gcode);
|
||||||
$print_first_layer_temperature->(1);
|
$print_first_layer_temperature->(1);
|
||||||
|
|
||||||
# set other general things
|
# set other general things
|
||||||
|
@ -902,7 +903,7 @@ sub write_gcode {
|
||||||
# write end commands to file
|
# write end commands to file
|
||||||
print $fh $gcodegen->retract if $gcodegen->extruder; # empty prints don't even set an extruder
|
print $fh $gcodegen->retract if $gcodegen->extruder; # empty prints don't even set an extruder
|
||||||
print $fh $gcodegen->set_fan(0);
|
print $fh $gcodegen->set_fan(0);
|
||||||
printf $fh "%s\n", $self->replace_variables($Slic3r::Config->end_gcode);
|
printf $fh "%s\n", $gcodegen->replace_variables($Slic3r::Config->end_gcode);
|
||||||
|
|
||||||
foreach my $extruder (@{$self->extruders}) {
|
foreach my $extruder (@{$self->extruders}) {
|
||||||
printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
|
printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
|
||||||
|
@ -949,12 +950,7 @@ sub expanded_output_filepath {
|
||||||
# path is a full path to a file so we use it as it is
|
# path is a full path to a file so we use it as it is
|
||||||
}
|
}
|
||||||
|
|
||||||
return $self->replace_variables($path, $extra_variables);
|
return $self->config->replace_options($path, { %{$self->extra_variables}, %$extra_variables });
|
||||||
}
|
|
||||||
|
|
||||||
sub replace_variables {
|
|
||||||
my ($self, $string, $extra) = @_;
|
|
||||||
return $self->config->replace_options($string, { %{$self->extra_variables}, %{ $extra || {} } });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# given the path to a file, this function returns its filename with and without extension
|
# given the path to a file, this function returns its filename with and without extension
|
||||||
|
|
|
@ -22,6 +22,7 @@ use Slic3r::Test;
|
||||||
$config->set('extruder_offset', [ [0,0], [20,0], [0,20] ]);
|
$config->set('extruder_offset', [ [0,0], [20,0], [0,20] ]);
|
||||||
$config->set('temperature', [200, 180, 170]);
|
$config->set('temperature', [200, 180, 170]);
|
||||||
$config->set('first_layer_temperature', [206, 186, 166]);
|
$config->set('first_layer_temperature', [206, 186, 166]);
|
||||||
|
$config->set('toolchange_gcode', ';toolchange'); # test that it doesn't crash when this is supplied
|
||||||
|
|
||||||
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
my $print = Slic3r::Test::init_print('20mm_cube', config => $config);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue