From fec41d6dfd02e6210822209bdb42f23347160f3a Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 23 Mar 2014 16:45:55 +0100 Subject: [PATCH] Update plater and print upon changing object parts and their settings --- lib/Slic3r/GUI/Plater.pm | 14 +++++++++++++- lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm | 15 ++++++++++++++- lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm | 10 ++++++++++ lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm | 4 ++++ lib/Slic3r/Layer.pm | 7 +------ lib/Slic3r/Print.pm | 4 ---- lib/Slic3r/Print/Object.pm | 2 +- 7 files changed, 43 insertions(+), 13 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index d38629edf..fc4db7462 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1165,6 +1165,7 @@ sub object_settings_dialog { if (!defined $obj_idx) { ($obj_idx, undef) = $self->selected_object; } + my $model_object = $self->{model}->objects->[$obj_idx]; # validate config before opening the settings dialog because # that dialog can't be closed if validation fails, but user @@ -1173,9 +1174,20 @@ sub object_settings_dialog { my $dlg = Slic3r::GUI::Plater::ObjectSettingsDialog->new($self, object => $self->{objects}[$obj_idx], - model_object => $self->{model}->objects->[$obj_idx], + model_object => $model_object, ); $dlg->ShowModal; + + # update thumbnail since parts may have changed + if ($dlg->PartsChanged) { + $self->make_thumbnail($obj_idx); + } + + # update print + if ($dlg->PartsChanged || $dlg->PartSettingsChanged) { + $self->{print}->delete_object($obj_idx); + $self->{print}->add_model_object($model_object, $obj_idx); + } } sub object_list_changed { diff --git a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm index 810607923..31b7dc03d 100644 --- a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm +++ b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm @@ -54,7 +54,7 @@ sub new { $self->{btn_delete}->SetFont($Slic3r::GUI::small_font); # part settings panel - $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self); + $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self, on_change => sub { $self->{part_settings_changed} = 1; }); my $settings_sizer = Wx::StaticBoxSizer->new($self->{staticbox} = Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL); $settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0); @@ -210,6 +210,8 @@ sub on_btn_load { # set a default extruder value, since user can't add it manually my $material = $self->{model_object}->model->materials->{$new_volume->material_id}; $material->config->set_ifndef('extruder', 1); + + $self->{parts_changed} = 1; } } } @@ -235,6 +237,7 @@ sub on_btn_delete { } $self->{model_object}->delete_volume($itemData->{volume_id}); + $self->{parts_changed} = 1; } $self->reload_tree; @@ -260,4 +263,14 @@ sub CanClose { return 1; } +sub PartsChanged { + my ($self) = @_; + return $self->{parts_changed}; +} + +sub PartSettingsChanged { + my ($self) = @_; + return $self->{part_settings_changed}; +} + 1; diff --git a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm index 661dfb92e..b40d081e5 100644 --- a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm @@ -40,6 +40,16 @@ sub new { return $self; } +sub PartsChanged { + my ($self) = @_; + return $self->{parts}->PartsChanged; +} + +sub PartSettingsChanged { + my ($self) = @_; + return $self->{parts}->PartSettingsChanged; +} + package Slic3r::GUI::Plater::ObjectDialog::BaseTab; use base 'Wx::Panel'; diff --git a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm index 802340882..2f9ee4402 100644 --- a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm +++ b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm @@ -17,6 +17,7 @@ sub new { my ($parent, %params) = @_; my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); $self->{config} = $params{config}; # may be passed as undef + $self->{on_change} = $params{on_change}; $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL); @@ -36,6 +37,7 @@ sub new { EVT_MENU($menu, $id, sub { $self->{config}->apply(Slic3r::Config->new_from_defaults($opt_key)); $self->update_optgroup; + $self->{on_change}->() if $self->{on_change}; }); } $self->PopupMenu($menu, $btn->GetPosition); @@ -94,6 +96,7 @@ sub update_optgroup { label_font => $Slic3r::GUI::small_font, sidetest_font => $Slic3r::GUI::small_font, label_width => 120, + on_change => sub { $self->{on_change}->() if $self->{on_change} }, extra_column => sub { my ($line) = @_; my ($opt_key) = @{$line->{options}}; # we assume that we have one option per line @@ -105,6 +108,7 @@ sub update_optgroup { wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE); EVT_BUTTON($self, $btn, sub { $self->{config}->erase($opt_key); + $self->{on_change}->() if $self->{on_change}; Slic3r::GUI->CallAfter(sub { $self->update_optgroup }); }); return $btn; diff --git a/lib/Slic3r/Layer.pm b/lib/Slic3r/Layer.pm index 193a9cf34..f65c1d133 100644 --- a/lib/Slic3r/Layer.pm +++ b/lib/Slic3r/Layer.pm @@ -5,7 +5,7 @@ use List::Util qw(first); use Slic3r::Geometry qw(scale); use Slic3r::Geometry::Clipper qw(union_ex); -has 'id' => (is => 'rw', required => 1, trigger => 1); # sequential number of layer, 0-based +has 'id' => (is => 'rw', required => 1); # sequential number of layer, 0-based has 'object' => (is => 'ro', weak_ref => 1, required => 1, handles => [qw(print config)]); has 'upper_layer' => (is => 'rw', weak_ref => 1); has 'regions' => (is => 'ro', default => sub { [] }); @@ -19,11 +19,6 @@ has 'height' => (is => 'ro', required => 1); # layer height in unscal # also known as 'islands' (all regions and surface types are merged here) has 'slices' => (is => 'rw', default => sub { Slic3r::ExPolygon::Collection->new }); -sub _trigger_id { - my $self = shift; - $_->_trigger_layer for @{$self->regions || []}; -} - # the purpose of this method is to be overridden for ::Support layers sub islands { my $self = shift; diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index 7643d4721..fea392206 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -1091,10 +1091,6 @@ sub auto_assign_extruders { my $config = $material->config; my $extruder_id = $i + 1; $config->set_ifndef('extruder', $extruder_id); - #$config->set_ifndef('perimeter_extruder', $extruder_id); - #$config->set_ifndef('infill_extruder', $extruder_id); - #$config->set_ifndef('support_material_extruder', $extruder_id); - #$config->set_ifndef('support_material_interface_extruder', $extruder_id); } } } diff --git a/lib/Slic3r/Print/Object.pm b/lib/Slic3r/Print/Object.pm index 99f987e84..b50ee98c3 100644 --- a/lib/Slic3r/Print/Object.pm +++ b/lib/Slic3r/Print/Object.pm @@ -331,7 +331,7 @@ sub _slice_region { my ($self, $region_id, $z, $modifier) = @_; return [] if !defined $self->region_volumes->[$region_id]; - + # compose mesh my $mesh; foreach my $volume_id (@{$self->region_volumes->[$region_id]}) {