From 710568b9896eb0ffa2ec1de791a78c807a2972c4 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Tue, 1 Jul 2014 18:22:19 +0200 Subject: [PATCH] Initialize controls status when loading cut window --- lib/Slic3r/GUI/Plater/ObjectCutDialog.pm | 51 ++++++++++++++---------- 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm index b62776b0b..08eb427d1 100644 --- a/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectCutDialog.pm @@ -25,33 +25,14 @@ sub new { }; my $optgroup; - $optgroup = Slic3r::GUI::OptionsGroup->new( + $optgroup = $self->{optgroup} = Slic3r::GUI::OptionsGroup->new( parent => $self, title => 'Cut', on_change => sub { my ($opt_id) = @_; $self->{cut_options}{$opt_id} = $optgroup->get_value($opt_id); - - # update canvas - if ($self->{canvas}) { - $self->{canvas}->SetCuttingPlane($self->{cut_options}{z}); - $self->{canvas}->Render; - } - - # update controls - my $z = $self->{cut_options}{z}; - $optgroup->get_field('keep_upper')->toggle(my $have_upper = abs($z - $optgroup->get_option('z')->max) > 0.1); - $optgroup->get_field('keep_lower')->toggle(my $have_lower = $z > 0.1); - $optgroup->get_field('rotate_lower')->toggle($z > 0 && $self->{cut_options}{keep_lower}); - - # update cut button - if (($self->{cut_options}{keep_upper} && $have_upper) - || ($self->{cut_options}{keep_lower} && $have_lower)) { - $self->{btn_cut}->Enable; - } else { - $self->{btn_cut}->Disable; - } + $self->_update; }, label_width => 120, ); @@ -125,9 +106,37 @@ sub new { EVT_BUTTON($self, $self->{btn_cut}, sub { $self->perform_cut }); + $self->_update; + return $self; } +sub _update { + my ($self) = @_; + + my $optgroup = $self->{optgroup}; + + # update canvas + if ($self->{canvas}) { + $self->{canvas}->SetCuttingPlane($self->{cut_options}{z}); + $self->{canvas}->Render; + } + + # update controls + my $z = $self->{cut_options}{z}; + $optgroup->get_field('keep_upper')->toggle(my $have_upper = abs($z - $optgroup->get_option('z')->max) > 0.1); + $optgroup->get_field('keep_lower')->toggle(my $have_lower = $z > 0.1); + $optgroup->get_field('rotate_lower')->toggle($z > 0 && $self->{cut_options}{keep_lower}); + + # update cut button + if (($self->{cut_options}{keep_upper} && $have_upper) + || ($self->{cut_options}{keep_lower} && $have_lower)) { + $self->{btn_cut}->Enable; + } else { + $self->{btn_cut}->Disable; + } +} + sub perform_cut { my ($self) = @_;