Fixed regression and ambiguity about multiple-value placeholders like [first_layer_temperature_1]. Includes several unit tests covering regression. #1899

This commit is contained in:
Alessandro Ranellucci 2014-04-29 17:06:31 +02:00
parent 913ab54a2b
commit a4b6075600
3 changed files with 55 additions and 7 deletions

View file

@ -43,7 +43,8 @@ sub apply_config {
foreach my $opt_key (@opt_keys) {
my $value = $config->$opt_key;
next unless ref($value) eq 'ARRAY';
$m->{"${opt_key}_${_}"} = $value->[$_] for 0..$#$value;
$m->{"${opt_key}_" . ($_+1)} = $value->[$_] for 0..$#$value;
$m->{$opt_key} = $value->[0];
if ($Slic3r::Config::Options->{$opt_key}{type} eq 'point') {
$m->{"${opt_key}_X"} = $value->[0];
$m->{"${opt_key}_Y"} = $value->[1];
@ -70,7 +71,10 @@ sub process {
}
{
my $regex = join '|', keys %{$self->_multiple};
$string =~ s/\[($regex)\]/$self->_multiple->{$1}/eg;
$string =~ s/\[($regex)\]/$self->_multiple->{$1}/egx;
# unhandled indices are populated using the first value, except _0 which is ignored for safety
$string =~ s/\[($regex)_[1-9]\d*\]/$self->_multiple->{$1}/egx;
}
return $string;

View file

@ -484,16 +484,21 @@ sub config {
} else {
# TODO: handle dirty presets.
# perhaps plater shouldn't expose dirty presets at all in multi-extruder environments.
my $i = -1;
foreach my $preset_idx ($self->{plater}->filament_presets) {
$i++;
my $preset = $self->{options_tabs}{filament}->get_preset($preset_idx);
my $config = $self->{options_tabs}{filament}->get_preset_config($preset);
if (!$filament_config) {
$filament_config = $config;
$filament_config = $config->clone;
next;
}
foreach my $opt_key (@{$config->get_keys}) {
next unless ref $filament_config->get($opt_key) eq 'ARRAY';
push @{ $filament_config->get($opt_key) }, $config->get($opt_key)->[0];
my $value = $filament_config->get($opt_key);
next unless ref $value eq 'ARRAY';
$value->[$i] = $config->get($opt_key)->[0];
use XXX; YYY $value if $opt_key eq 'first_layer_temperature';
$filament_config->set($opt_key, $value);
}
}
}