Only reload the selected object and not all the objects of the input file. #3786

This commit is contained in:
Alessandro Ranellucci 2017-03-21 17:33:49 +01:00
parent ddad7ce25f
commit 8560655372
2 changed files with 29 additions and 14 deletions

View File

@ -632,7 +632,7 @@ sub add_tin {
sub load_file {
my $self = shift;
my ($input_file) = @_;
my ($input_file, $obj_idx) = @_;
$Slic3r::GUI::Settings->{recent}{skein_directory} = dirname($input_file);
wxTheApp->save_settings;
@ -657,7 +657,19 @@ sub load_file {
$model->convert_multipart_object;
}
}
@obj_idx = $self->load_model_objects(@{$model->objects});
if (defined $obj_idx) {
return () if $obj_idx >= $model->objects_count;
@obj_idx = $self->load_model_objects($model->get_object($obj_idx));
} else {
@obj_idx = $self->load_model_objects(@{$model->objects});
}
my $i = 0;
foreach my $obj_idx (@obj_idx) {
$self->{objects}[$obj_idx]->input_file($input_file);
$self->{objects}[$obj_idx]->input_file_obj_idx($i++);
}
$self->statusbar->SetStatusText("Loaded " . basename($input_file));
}
@ -1488,13 +1500,14 @@ sub reload_from_disk {
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;
return if !$object->input_file
|| !-e $object->input_file;
my @new_obj_idx = $self->load_file($model_object->input_file);
# Only reload the selected object and not all objects from the input file.
my @new_obj_idx = $self->load_file($object->input_file, $object->input_file_obj_idx);
return if !@new_obj_idx;
my $model_object = $self->{model}->objects->[$obj_idx];
foreach my $new_obj_idx (@new_obj_idx) {
my $o = $self->{model}->objects->[$new_obj_idx];
$o->clear_instances;
@ -1509,6 +1522,8 @@ sub reload_from_disk {
$self->remove($obj_idx);
# TODO: refresh object list which contains wrong count and scale
# 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.
@ -2127,6 +2142,8 @@ use List::Util qw(first);
use Slic3r::Geometry qw(X Y Z MIN MAX deg2rad);
has 'name' => (is => 'rw', required => 1);
has 'input_file' => (is => 'rw');
has 'input_file_obj_idx' => (is => 'rw');
has 'thumbnail' => (is => 'rw'); # ExPolygon::Collection in scaled model units with no transforms
has 'transformed_thumbnail' => (is => 'rw');
has 'instance_thumbnails' => (is => 'ro', default => sub { [] }); # array of ExPolygon::Collection objects, each one representing the actual placed thumbnail of each instance in pixel units

View File

@ -92,9 +92,8 @@ Model::delete_object(size_t idx)
void
Model::clear_objects()
{
// int instead of size_t because it can be -1 when vector is empty
for (int i = this->objects.size()-1; i >= 0; --i)
this->delete_object(i);
while (!this->objects.empty())
this->delete_object(0);
}
void
@ -467,9 +466,8 @@ ModelObject::delete_volume(size_t idx)
void
ModelObject::clear_volumes()
{
// int instead of size_t because it can be -1 when vector is empty
for (int i = this->volumes.size()-1; i >= 0; --i)
this->delete_volume(i);
while (!this->volumes.empty())
this->delete_volume(0);
}
ModelInstance*
@ -508,8 +506,8 @@ ModelObject::delete_last_instance()
void
ModelObject::clear_instances()
{
for (size_t i = 0; i < this->instances.size(); ++i)
this->delete_instance(i);
while (!this->instances.empty())
this->delete_last_instance();
}
// this returns the bounding box of the *transformed* instances