From d3171b1eeafe5b320ed65fea0fce4fcf5abfb959 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 16 Dec 2013 00:36:53 +0100 Subject: [PATCH] More work for updating the embedded Print object when Model is changed in plater --- lib/Slic3r/GUI/Plater.pm | 12 ++++++++++-- lib/Slic3r/Print.pm | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 96980db72..7368baff3 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -526,6 +526,11 @@ sub rotate { my $new_angle = $model_instance->rotation + $angle; $_->rotation($new_angle) for @{ $model_object->instances }; $model_object->update_bounding_box; + + # update print + $self->{print}->delete_object($obj_idx); + $self->{print}->add_model_object($model_object, $obj_idx); + $object->transform_thumbnail($self->{model}, $obj_idx); } $self->selection_changed; # refresh info (size etc.) @@ -557,6 +562,11 @@ sub changescale { } $_->scaling_factor($scale) for @{ $model_object->instances }; $model_object->update_bounding_box; + + # update print + $self->{print}->delete_object($obj_idx); + $self->{print}->add_model_object($model_object, $obj_idx); + $object->transform_thumbnail($self->{model}, $obj_idx); } $self->selection_changed(1); # refresh info (size, volume etc.) @@ -725,7 +735,6 @@ sub export_gcode2 { eval { $print->config->validate; - $print->add_model_object($_) for @{ $self->{model}->objects }; $print->validate; { @@ -1058,7 +1067,6 @@ sub mouse_event { $parent->Refresh; } elsif ($event->Moving) { my $cursor = wxSTANDARD_CURSOR; - ###use XXX;YYY [[$pos->pp], map $_->pp, @$_]; if (defined first { $_->contains_point($pos) } map @{$_->instance_thumbnails}, @{ $parent->{objects} }) { $cursor = Wx::Cursor->new(wxCURSOR_HAND); } diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 83d928bc3..ea875b9fa 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -79,7 +79,7 @@ sub _build_has_support_material { # and have explicit instance positions sub add_model_object { my $self = shift; - my ($object) = @_; + my ($object, $obj_idx) = @_; # read the material mapping provided by the model object, if any my %matmap = %{ $object->material_mapping || {} }; @@ -113,7 +113,7 @@ sub add_model_object { } # initialize print object - push @{$self->objects}, Slic3r::Print::Object->new( + my $o = Slic3r::Print::Object->new( print => $self, meshes => [ map $meshes{$_}, 0..$#{$self->regions} ], copies => [ map Slic3r::Point->new_scale(@{ $_->offset }), @{ $object->instances } ], @@ -121,6 +121,11 @@ sub add_model_object { config_overrides => $object->config, layer_height_ranges => $object->layer_height_ranges, ); + if (defined $obj_idx) { + splice @{$self->objects}, $obj_idx, 0, $o; + } else { + push @{$self->objects}, $o; + } if (!defined $self->extra_variables->{input_filename}) { if (defined (my $input_file = $object->input_file)) {