From c517b0d8f17ced2b93c63f47aa4cc12eed268801 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci <aar@cpan.org> Date: Thu, 22 Dec 2016 12:13:28 +0100 Subject: [PATCH] Bugfix: object disappeared from 2D plater when reloaded from disk. #3634 --- lib/Slic3r/GUI/Plater.pm | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index b54a50ca7..4c63fdad2 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1489,6 +1489,40 @@ sub export_stl { $self->statusbar->SetStatusText("STL file exported to $output_file"); } +sub reload_from_disk { + my ($self) = @_; + + my ($obj_idx, $object) = $self->selected_object; + return if !defined $obj_idx; + + my $model_object = $self->{model}->objects->[$obj_idx]; + return if !$model_object->input_file + || !-e $model_object->input_file; + + my @new_obj_idx = $self->load_file($model_object->input_file); + return if !@new_obj_idx; + + foreach my $new_obj_idx (@new_obj_idx) { + my $o = $self->{model}->objects->[$new_obj_idx]; + $o->clear_instances; + $o->add_instance($_) for @{$model_object->instances}; + + if ($o->volumes_count == $model_object->volumes_count) { + for my $i (0..($o->volumes_count-1)) { + $o->get_volume($i)->config->apply($model_object->get_volume($i)->config); + } + } + } + + $self->remove($obj_idx); + + # Trigger thumbnail generation again, because the remove() method altered + # object indexes before background thumbnail generation called its completion + # event, so the on_thumbnail_made callback is called with the wrong $obj_idx. + # When porting to C++ we'll probably have cleaner ways to do this. + $self->make_thumbnail($_-1) for @new_obj_idx; +} + sub export_object_stl { my $self = shift;