Extended the Slic3r::GUI::Tab::XXX::_update mechanism to deliver
a set of updated config keys.
This commit is contained in:
parent
e386a2bf72
commit
64c752ff9d
2 changed files with 49 additions and 24 deletions
|
@ -70,12 +70,18 @@ sub load_config {
|
|||
my $self = shift;
|
||||
my ($config) = @_;
|
||||
|
||||
my %keys_modified = ();
|
||||
foreach my $opt_key (@{$self->{config}->get_keys}) {
|
||||
next unless $config->has($opt_key);
|
||||
$self->{config}->set($opt_key, $config->get($opt_key));
|
||||
if ($config->has($opt_key)) {
|
||||
if ($self->{config}->serialize($opt_key) ne $config->serialize($opt_key)) {
|
||||
$self->{config}->set($opt_key, $config->get($opt_key));
|
||||
$keys_modified{$opt_key} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
# Initialize UI components with the config values.
|
||||
$_->reload_config for @{$self->{optgroups}};
|
||||
$self->_update;
|
||||
$self->_update(\%keys_modified);
|
||||
}
|
||||
|
||||
sub load_presets {}
|
||||
|
@ -93,10 +99,9 @@ sub on_presets_changed {}
|
|||
|
||||
# propagate event to the parent
|
||||
sub _on_value_change {
|
||||
my $self = shift;
|
||||
|
||||
$self->{on_value_change}->(@_) if $self->{on_value_change};
|
||||
$self->_update;
|
||||
my ($self, $key, $value) = @_;
|
||||
$self->{on_value_change}->($key, $value) if $self->{on_value_change};
|
||||
$self->_update({ $key => 1 });
|
||||
}
|
||||
|
||||
sub get_field {
|
||||
|
@ -179,7 +184,8 @@ sub build {
|
|||
}
|
||||
|
||||
sub _update {
|
||||
my ($self) = @_;
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
|
||||
my $config = $self->{config};
|
||||
|
||||
|
|
|
@ -207,16 +207,17 @@ sub on_presets_changed {
|
|||
$self->{on_presets_changed} = $cb;
|
||||
}
|
||||
|
||||
# This method is supposed to be called whenever new values are loaded
|
||||
# or changed by user (so also when a preset is loaded).
|
||||
# propagate event to the parent
|
||||
# This method is called whenever an option field is changed by the user.
|
||||
# Propagate event to the parent through the 'on_value_changed' callback
|
||||
# and call _update.
|
||||
sub _on_value_change {
|
||||
my $self = shift;
|
||||
|
||||
$self->{on_value_change}->(@_) if $self->{on_value_change};
|
||||
$self->_update;
|
||||
my ($self, $key, $value) = @_;
|
||||
$self->{on_value_change}->($key, $value) if $self->{on_value_change};
|
||||
$self->_update({ $key => 1 });
|
||||
}
|
||||
|
||||
# Override this to capture changes of configuration caused either by loading or switching a preset,
|
||||
# or by a user changing an option field.
|
||||
sub _update {}
|
||||
|
||||
sub _on_presets_changed {
|
||||
|
@ -298,15 +299,20 @@ sub on_select_preset {
|
|||
my $preset_config = $self->get_preset_config($preset);
|
||||
eval {
|
||||
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
|
||||
my %keys_modified = ();
|
||||
foreach my $opt_key (@{$self->{config}->get_keys}) {
|
||||
$self->{config}->set($opt_key, $preset_config->get($opt_key))
|
||||
if $preset_config->has($opt_key);
|
||||
if ($preset_config->has($opt_key)) {
|
||||
if ($self->{config}->serialize($opt_key) ne $preset_config->serialize($opt_key)) {
|
||||
$self->{config}->set($opt_key, $preset_config->get($opt_key));
|
||||
$keys_modified{$opt_key} = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
($preset->default || $preset->external)
|
||||
? $self->{btn_delete_preset}->Disable
|
||||
: $self->{btn_delete_preset}->Enable;
|
||||
|
||||
$self->_update;
|
||||
$self->_update(\%keys_modified);
|
||||
$self->on_preset_loaded;
|
||||
$self->reload_config;
|
||||
$Slic3r::GUI::Settings->{presets}{$self->name} = $preset->file ? basename($preset->file) : '';
|
||||
|
@ -463,12 +469,15 @@ sub load_config {
|
|||
my $self = shift;
|
||||
my ($config) = @_;
|
||||
|
||||
my %keys_modified = ();
|
||||
foreach my $opt_key (@{$self->{config}->diff($config)}) {
|
||||
$self->{config}->set($opt_key, $config->get($opt_key));
|
||||
$keys_modified{$opt_key} = 1;
|
||||
$self->update_dirty;
|
||||
}
|
||||
# Initialize UI components with the config values.
|
||||
$self->reload_config;
|
||||
$self->_update;
|
||||
$self->_update(\%keys_modified);
|
||||
}
|
||||
|
||||
sub get_preset_config {
|
||||
|
@ -797,9 +806,12 @@ sub build {
|
|||
}
|
||||
}
|
||||
|
||||
# Slic3r::GUI::Tab::Print::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
my ($self) = @_;
|
||||
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
$keys_modified //= {};
|
||||
|
||||
my $config = $self->{config};
|
||||
|
||||
if ($config->spiral_vase && !($config->perimeters == 1 && $config->top_solid_layers == 0 && $config->fill_density == 0)) {
|
||||
|
@ -825,6 +837,10 @@ sub _update {
|
|||
}
|
||||
}
|
||||
|
||||
if ($keys_modified->{'layer_height'}) {
|
||||
# If the user had set the variable layer height, reset it and let the user know.
|
||||
}
|
||||
|
||||
if ($config->support_material) {
|
||||
# Ask only once.
|
||||
if (! $self->{support_material_overhangs_queried}) {
|
||||
|
@ -1050,8 +1066,10 @@ sub build {
|
|||
}
|
||||
}
|
||||
|
||||
# Slic3r::GUI::Tab::Filament::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
my ($self) = @_;
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
|
||||
$self->_update_description;
|
||||
|
||||
|
@ -1382,7 +1400,6 @@ sub _extruders_count_changed {
|
|||
$self->{extruders_count} = $extruders_count;
|
||||
$self->_build_extruder_pages;
|
||||
$self->_on_value_change('extruders_count', $extruders_count);
|
||||
$self->_update;
|
||||
}
|
||||
|
||||
sub _extruder_options { qw(nozzle_diameter extruder_offset retract_length retract_lift retract_lift_above retract_lift_below retract_speed retract_restart_extra retract_before_travel wipe
|
||||
|
@ -1464,8 +1481,10 @@ sub _build_extruder_pages {
|
|||
$self->update_tree;
|
||||
}
|
||||
|
||||
# Slic3r::GUI::Tab::Printer::_update is called after a configuration preset is loaded or switched, or when a single option is modifed by the user.
|
||||
sub _update {
|
||||
my ($self) = @_;
|
||||
# $keys_modified is a reference to hash with modified keys set to 1, unmodified keys missing.
|
||||
my ($self, $keys_modified) = @_;
|
||||
|
||||
my $config = $self->{config};
|
||||
|
||||
|
|
Loading…
Reference in a new issue