From 10bf334a587a59482f814935aae9056fef34a073 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 26 Mar 2014 19:42:01 +0100 Subject: [PATCH] Added one more failing test to address bad option priority hierarchy --- lib/Slic3r/GUI/Plater.pm | 3 +-- lib/Slic3r/Print.pm | 19 +++++++++++++++++-- t/print.t | 19 ++++++++++++++++++- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index bc13ed44b3..2fbb438fda 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1196,8 +1196,7 @@ sub object_settings_dialog { # update print if ($dlg->PartsChanged || $dlg->PartSettingsChanged) { - $self->{print}->delete_object($obj_idx); - $self->{print}->add_model_object($model_object, $obj_idx); + $self->{print}->reload_object($obj_idx); } } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index f63dca4631..b2a3be6250 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -80,9 +80,9 @@ sub apply_config { next if !defined $volume->material_id; my $material = $object->model_object->model->materials->{$volume->material_id}; $new->apply_dynamic($material->config); + push @new_region_configs, $new; } } - push @new_region_configs, $new; } # then find the first pair of identical configs @@ -101,7 +101,7 @@ sub apply_config { if ($have_identical_configs) { # okay, the current subdivision of regions does not make sense anymore. # we need to remove all objects and re-add them - my @model_objects = map $_->model_object, @{$self->object}; + my @model_objects = map $_->model_object, @{$self->objects}; $self->delete_all_objects; $self->add_model_object($_) for @model_objects; } elsif (@$region_diff > 0) { @@ -141,6 +141,7 @@ sub add_model_object { # override the defaults with per-object config and then with per-material config $config->apply_dynamic($object->config); + if (defined $volume->material_id) { my $material_config = $object->model->materials->{ $volume->material_id }->config; $config->apply_dynamic($material_config); @@ -214,6 +215,20 @@ sub delete_all_objects { $self->_state->invalidate(STEP_BRIM); } +sub reload_object { + my ($self, $obj_idx) = @_; + + # TODO: this method should check whether the per-object config and per-material configs + # have changed in such a way that regions need to be rearranged or we can just apply + # the diff and invalidate something. Same logic as apply_config() + # For now we just re-add all objects since we haven't implemented this incremental logic yet. + # This should also check whether object volumes (parts) have changed. + + my @model_objects = map $_->model_object, @{$self->objects}; + $self->delete_all_objects; + $self->add_model_object($_) for @model_objects; +} + sub validate { my $self = shift; diff --git a/t/print.t b/t/print.t index b4ff201454..746ce5d3c2 100644 --- a/t/print.t +++ b/t/print.t @@ -1,4 +1,4 @@ -use Test::More tests => 2; +use Test::More tests => 3; use strict; use warnings; @@ -30,4 +30,21 @@ use Slic3r::Test; ok abs(unscale($center->[Y]) - $config->print_center->[Y]) < epsilon, 'print is centered around print_center (Y)'; } +{ + # this represents the aggregate config from presets + my $config = Slic3r::Config->new_from_defaults; + + # user adds one object to the plater + my $print = Slic3r::Test::init_print('20mm_cube', config => $config); + + # user sets a per-object option + $print->objects->[0]->config->set('fill_density', 100); + $print->reload_object(0); + + # user exports G-code, thus the default config is reapplied + $print->apply_config($config); + + is $print->objects->[0]->config->fill_density, 100, 'apply_config() does not override per-object settings'; +} + __END__