Better fix for non-global options not being replaced in filename placeholders. Includes refactoring and a new PlaceholderParser class. Also includes regression tests. #1831

This commit is contained in:
Alessandro Ranellucci 2014-03-17 00:39:07 +01:00
parent bc054e613c
commit 34f1511e0c
10 changed files with 146 additions and 128 deletions

View file

@ -9,7 +9,7 @@ use Slic3r::Geometry::Clipper qw(union_ex);
use Slic3r::Surface ':types';
has 'print_config' => (is => 'ro', default => sub { Slic3r::Config::Print->new });
has 'extra_variables' => (is => 'rw', default => sub {{}});
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});
has 'enable_wipe' => (is => 'rw', default => sub {0}); # at least one extruder has wipe enabled
@ -649,7 +649,7 @@ sub set_extruder {
# append custom toolchange G-code
if (defined $self->extruder && $self->print_config->toolchange_gcode) {
$gcode .= sprintf "%s\n", $self->replace_variables($self->print_config->toolchange_gcode, {
$gcode .= sprintf "%s\n", $self->placeholder_parser->process($self->print_config->toolchange_gcode, {
previous_extruder => $self->extruder->id,
next_extruder => $extruder_id,
});
@ -748,9 +748,4 @@ sub set_bed_temperature {
return $gcode;
}
sub replace_variables {
my ($self, $string, $extra) = @_;
return $self->print_config->replace_options($string, { %{$self->extra_variables}, %{ $extra || {} } });
}
1;