From d6d796fdd48b3f0561a66853cb51c6ea2b3d3310 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Mon, 16 Jun 2014 22:45:13 +0200 Subject: [PATCH] Finished implementing bed shape configuration within wizard --- lib/Slic3r/GUI/MainFrame.pm | 4 ++-- lib/Slic3r/GUI/OptionsGroup.pm | 22 ++++++++++++++++++---- lib/Slic3r/GUI/Tab.pm | 1 + 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index cb11e2f1f..49c154068 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -551,13 +551,13 @@ sub config_wizard { my $self = shift; return unless $self->check_unsaved_changes; - if (my $config = Slic3r::GUI::ConfigWizard->new($self)->run) {use XXX; YYY $config->bed_shape; + if (my $config = Slic3r::GUI::ConfigWizard->new($self)->run) { if ($self->{mode} eq 'expert') { for my $tab (values %{$self->{options_tabs}}) { $tab->select_default_preset; } } - $self->load_config($config);use XXX; YYY $self->config->bed_shape; + $self->load_config($config); if ($self->{mode} eq 'expert') { for my $tab (values %{$self->{options_tabs}}) { $tab->save_preset('My Settings'); diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index 2c9089a28..9d2c8f5c8 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -80,6 +80,13 @@ sub BUILD { $self->sizer->Add($grid_sizer, 0, wxEXPAND | wxALL, &Wx::wxMAC ? 0 : 5); foreach my $line (@{$self->lines}) { + # build default callbacks in case we don't call _build_line() below + foreach my $opt_key (@{$line->{options}}) { + my $opt = first { $_->{opt_key} eq $opt_key } @{$self->options}; + $self->_setters->{$opt_key} //= sub {}; + $self->_triggers->{$opt_key} = $opt->{on_change} || sub { return 1 }; + } + if ($line->{sizer}) { $self->sizer->Add($line->{sizer}, 0, wxEXPAND | wxALL, &Wx::wxMAC ? 0 : 15); } elsif ($line->{widget} && $line->{full_width}) { @@ -143,7 +150,7 @@ sub _build_line { my @field_labels = (); foreach my $opt_key (@{$line->{options}}) { my $opt = first { $_->{opt_key} eq $opt_key } @{$self->options}; - push @fields, $self->_build_field($opt); + push @fields, $self->_build_field($opt) unless $line->{widget}; push @field_labels, $opt->{label}; } if (@fields > 1 || $line->{widget} || $line->{sidetext}) { @@ -175,7 +182,6 @@ sub _build_field { my ($opt) = @_; my $opt_key = $opt->{opt_key}; - $self->_triggers->{$opt_key} = $opt->{on_change} || sub { return 1 }; my $on_kill_focus = sub { my ($s, $event) = @_; @@ -369,6 +375,7 @@ has '+ignore_on_change_return' => (is => 'ro', default => sub { 0 }); sub _trigger_options { my $self = shift; + $self->SUPER::_trigger_options; @{$self->options} = map { my $opt = $_; if (ref $opt ne 'HASH') { @@ -414,10 +421,17 @@ sub set_value { if ($key eq $opt_key) { $self->config->set($key, $value); $self->SUPER::set_value($full_key, $self->_get_config($key, $index)); - $changed = 1; + return 1; } } - return $changed; + + # if we're here, we know this option but we found no setter, so we just propagate it + if ($self->config->has($opt_key)) { + $self->config->set($opt_key, $value); + $self->SUPER::set_value($opt_key, $value); + return 1; + } + return 0; } sub on_kill_focus { diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index a4e02b15d..56e052ff7 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -709,6 +709,7 @@ sub build { { label => 'Bed shape', widget => $bed_shape_widget, + options => ['bed_shape'], }, Slic3r::GUI::OptionsGroup->single_option_line('print_center'), Slic3r::GUI::OptionsGroup->single_option_line('z_offset'),