From 334086d605ea453f6969fa5367fb8f3e36d6d934 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Wed, 12 Nov 2014 23:28:42 +0100 Subject: [PATCH] Bugfix: skirt and brim were not recalculated when objects where just moved in plater --- lib/Slic3r/GUI/Plater.pm | 20 +++++++++++--------- lib/Slic3r/GUI/Plater/2D.pm | 2 +- lib/Slic3r/Print/Object.pm | 6 +++--- xs/src/libslic3r/Print.cpp | 9 --------- xs/src/libslic3r/Print.hpp | 3 ++- xs/src/libslic3r/PrintObject.cpp | 21 ++++++++++++++++++--- xs/xsp/Print.xsp | 3 ++- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index a6944d318..12391fffb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -89,7 +89,17 @@ sub new { $menu->Destroy; }); $self->{canvas}->on_instance_moved(sub { + my ($obj_idx, $instance_idx) = @_; + $self->update; + + $self->pause_background_process; + my $invalidated = $self->{print}->objects->[$obj_idx]->reload_model_instances(); + if ($invalidated) { + $self->schedule_background_process; + } else { + $self->resume_background_process; + } }); # Initialize 3D preview canvas @@ -736,6 +746,7 @@ sub arrange { my $bb = Slic3r::Geometry::BoundingBoxf->new_from_points($self->{config}->bed_shape); eval { $self->{model}->arrange_objects($self->GetFrame->config->min_object_distance, $bb); + $_->reload_model_instances for @{$self->{print}->objects}; }; # ignore arrange failures on purpose: user has visual feedback and we don't need to warn him # when parts don't fit in print bed @@ -1128,15 +1139,6 @@ sub update { $self->{model}->center_instances_around_point($self->bed_centerf); } - # sync model and print object instances - for my $obj_idx (0..$#{$self->{objects}}) { - my $model_object = $self->{model}->objects->[$obj_idx]; - my $print_object = $self->{print}->objects->[$obj_idx]; - - $print_object->delete_all_copies; - $print_object->add_copy(@{$_->offset}) for @{$model_object->instances}; - } - $self->{canvas}->Refresh; $self->{canvas3D}->update if $self->{canvas3D}; } diff --git a/lib/Slic3r/GUI/Plater/2D.pm b/lib/Slic3r/GUI/Plater/2D.pm index 1e6acc63b..5f85aa746 100644 --- a/lib/Slic3r/GUI/Plater/2D.pm +++ b/lib/Slic3r/GUI/Plater/2D.pm @@ -209,7 +209,7 @@ sub mouse_event { } $self->Refresh; } elsif ($event->ButtonUp(&Wx::wxMOUSE_BTN_LEFT)) { - $self->{on_instance_moved}->(); + $self->{on_instance_moved}->(@{ $self->{drag_object} }); $self->Refresh; $self->{drag_start_pos} = undef; $self->{drag_object} = undef; diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 584ed11b6..24c07472e 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -37,19 +37,19 @@ sub add_copy { my ($self, $x, $y) = @_; my @copies = @{$self->copies}; push @copies, Slic3r::Point->new_scale($x, $y); - $self->set_copies(\@copies); + return $self->set_copies(\@copies); } sub delete_last_copy { my ($self) = @_; my @copies = $self->copies; pop @copies; - $self->set_copies(\@copies); + return $self->set_copies(\@copies); } sub delete_all_copies { my ($self) = @_; - $self->set_copies([]); + return $self->set_copies([]); } # this is the *total* layer count (including support layers) diff --git a/xs/src/libslic3r/Print.cpp b/xs/src/libslic3r/Print.cpp index 528c45e20..0dc161622 100644 --- a/xs/src/libslic3r/Print.cpp +++ b/xs/src/libslic3r/Print.cpp @@ -351,15 +351,6 @@ Print::add_model_object(ModelObject* model_object, int idx) ? this->set_new_object(idx, model_object, bb) : this->add_object(model_object, bb); } - - { - Points copies; - for (ModelInstancePtrs::const_iterator i = model_object->instances.begin(); i != model_object->instances.end(); ++i) { - copies.push_back(Point::new_scale((*i)->offset.x, (*i)->offset.y)); - } - o->set_copies(copies); - } - o->layer_height_ranges = model_object->layer_height_ranges; for (ModelVolumePtrs::const_iterator v_i = model_object->volumes.begin(); v_i != model_object->volumes.end(); ++v_i) { size_t volume_id = v_i - model_object->volumes.begin(); diff --git a/xs/src/libslic3r/Print.hpp b/xs/src/libslic3r/Print.hpp index 664b85e23..3e9702117 100644 --- a/xs/src/libslic3r/Print.hpp +++ b/xs/src/libslic3r/Print.hpp @@ -103,7 +103,8 @@ class PrintObject ModelObject* model_object(); Points copies() const; - void set_copies(const Points &points); + bool set_copies(const Points &points); + bool reload_model_instances(); // adds region_id, too, if necessary void add_region_volume(int region_id, int volume_id); diff --git a/xs/src/libslic3r/PrintObject.cpp b/xs/src/libslic3r/PrintObject.cpp index 5f1fd19ee..868da0fd7 100644 --- a/xs/src/libslic3r/PrintObject.cpp +++ b/xs/src/libslic3r/PrintObject.cpp @@ -26,6 +26,9 @@ PrintObject::PrintObject(Print* print, ModelObject* model_object, const Bounding Pointf3 size = modobj_bbox.size(); this->size = Point3(scale_(size.x), scale_(size.y), scale_(size.z)); } + + this->reload_model_instances(); + this->layer_height_ranges = model_object->layer_height_ranges; } PrintObject::~PrintObject() @@ -50,7 +53,7 @@ PrintObject::copies() const return this->_copies; } -void +bool PrintObject::set_copies(const Points &points) { this->_copies = points; @@ -69,8 +72,20 @@ PrintObject::set_copies(const Points &points) this->_shifted_copies.push_back(copy); } - this->_print->invalidate_step(psSkirt); - this->_print->invalidate_step(psBrim); + bool invalidated = false; + if (this->_print->invalidate_step(psSkirt)) invalidated = true; + if (this->_print->invalidate_step(psBrim)) invalidated = true; + return invalidated; +} + +bool +PrintObject::reload_model_instances() +{ + Points copies; + for (ModelInstancePtrs::const_iterator i = this->_model_object->instances.begin(); i != this->_model_object->instances.end(); ++i) { + copies.push_back(Point::new_scale((*i)->offset.x, (*i)->offset.y)); + } + return this->set_copies(copies); } void diff --git a/xs/xsp/Print.xsp b/xs/xsp/Print.xsp index 2999e785c..d18d689de 100644 --- a/xs/xsp/Print.xsp +++ b/xs/xsp/Print.xsp @@ -74,7 +74,8 @@ _constant() void set_shifted_copies(Points value) %code%{ THIS->_shifted_copies = value; %}; - void set_copies(Points copies); + bool set_copies(Points copies); + bool reload_model_instances(); void set_layer_height_ranges(t_layer_height_ranges layer_height_ranges) %code%{ THIS->layer_height_ranges = layer_height_ranges; %};