Browse Source

Added one more failing test to address bad option priority hierarchy

Alessandro Ranellucci 11 years ago
parent
commit
10bf334a58
3 changed files with 36 additions and 5 deletions
  1. 1 2
      lib/Slic3r/GUI/Plater.pm
  2. 17 2
      lib/Slic3r/Print.pm
  3. 18 1
      t/print.t

+ 1 - 2
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);
     }
 }
 

+ 17 - 2
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;
     

+ 18 - 1
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__