Skip to content

Commit

Permalink
Rename 'overridable' to 'shortcuts' and change semantics accordingly:…
Browse files Browse the repository at this point in the history
… options in plater update the selected preset automatically instead of overriding it
  • Loading branch information
alranel committed Apr 17, 2017
1 parent 3ca6ff3 commit 19a36cf
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 21 deletions.
21 changes: 14 additions & 7 deletions lib/Slic3r/GUI/Plater.pm
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ sub new {
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{config} = Slic3r::Config->new_from_defaults(qw(
bed_shape complete_objects extruder_clearance_radius skirts skirt_distance brim_width
serial_port serial_speed octoprint_host octoprint_apikey overridable filament_colour
serial_port serial_speed octoprint_host octoprint_apikey shortcuts filament_colour
));
$self->{model} = Slic3r::Model->new;
$self->{print} = Slic3r::Print->new;
Expand Down Expand Up @@ -367,6 +367,13 @@ sub new {
{
my $o = $self->{settings_override_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self,
on_change => sub {
my ($preset) = $self->selected_presets('print');

# Apply the overrides to the current Print preset, potentially making it dirty
$preset->load_config;
$preset->_dirty_config->apply($self->{settings_override_config});

$self->load_presets;
$self->config_changed;
});
$o->set_editable(1);
Expand Down Expand Up @@ -568,26 +575,26 @@ sub _on_select_preset {
$o_config->clear;
}

my $overridable = $config->get('overridable');
my $shortcuts = $config->get('shortcuts');

# Add/remove options (we do it this way for preserving current options)
foreach my $opt_key (@$overridable) {
foreach my $opt_key (@$shortcuts) {
# Populate option with the default value taken from configuration
# (re-set the override always, because if we here it means user
# switched to this preset or opened/closed the editor, so he expects
# the new values set in the editor to be used).
$o_config->set($opt_key, $config->get($opt_key));
}
foreach my $opt_key (@{$o_config->get_keys}) {
# Keep options listed among overridable and options added on the fly
if ((none { $_ eq $opt_key } @$overridable)
# Keep options listed among shortcuts and options added on the fly
if ((none { $_ eq $opt_key } @$shortcuts)
&& (any { $_ eq $opt_key } $o_panel->fixed_options)) {
$o_config->erase($opt_key);
}
}

$o_panel->set_default_config($config);
$o_panel->set_fixed_options(\@$overridable);
$o_panel->set_fixed_options(\@$shortcuts);
$o_panel->update_optgroup;
} elsif ($group eq 'printer') {
# reload print and filament settings to honor their compatible_printer options
Expand Down Expand Up @@ -766,7 +773,7 @@ sub config {
my $config = Slic3r::Config->new_from_defaults;

# get defaults also for the values tracked by the Plater's config
# (for example 'overridable')
# (for example 'shortcuts')
$config->apply(Slic3r::Config->new_from_defaults(@{$self->{config}->get_keys}));

my %classes = map { $_ => "Slic3r::GUI::PresetEditor::".ucfirst($_) }
Expand Down
2 changes: 2 additions & 0 deletions lib/Slic3r/GUI/Preset.pm
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ sub dirty_config {
sub load_config {
my ($self) = @_;

return if $self->_loaded;

my @keys = $self->_group_class->options;
my @extra_keys = $self->_group_class->overriding_options;

Expand Down
24 changes: 12 additions & 12 deletions lib/Slic3r/GUI/PresetEditor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -441,15 +441,15 @@ sub options {
external_perimeter_extrusion_width infill_extrusion_width solid_infill_extrusion_width
top_infill_extrusion_width support_material_extrusion_width
infill_overlap bridge_flow_ratio
xy_size_compensation resolution overridable compatible_printers
xy_size_compensation resolution shortcuts compatible_printers
print_settings_id
)
}

sub build {
my $self = shift;

my $overridable_widget = sub {
my $shortcuts_widget = sub {
my ($parent) = @_;

my $Options = $Slic3r::Config::Options;
Expand All @@ -458,15 +458,15 @@ sub build {
grep { exists $Options->{$_} && $Options->{$_}{category} } $self->options
);
my @opt_keys = sort { $options{$a} cmp $options{$b} } keys %options;
$self->{overridable_opt_keys} = [ @opt_keys ];
$self->{shortcuts_opt_keys} = [ @opt_keys ];

my $listbox = $self->{overridable_list} = Wx::CheckListBox->new($parent, -1,
my $listbox = $self->{shortcuts_list} = Wx::CheckListBox->new($parent, -1,
wxDefaultPosition, [-1, 320], [ map $options{$_}, @opt_keys ]);

EVT_CHECKLISTBOX($self, $listbox, sub {
my $value = [ map $opt_keys[$_], grep $listbox->IsChecked($_), 0..$#opt_keys ];
$self->config->set('overridable', $value);
$self->_on_value_change('overridable');
$self->config->set('shortcuts', $value);
$self->_on_value_change('shortcuts');
});

my $sizer = Wx::BoxSizer->new(wxVERTICAL);
Expand Down Expand Up @@ -715,7 +715,7 @@ sub build {
}

{
my $page = $self->add_options_page('Overrides', 'wrench.png');
my $page = $self->add_options_page('Shortcuts', 'wrench.png');
{
my $optgroup = $page->new_optgroup('Profile preferences');
{
Expand All @@ -727,10 +727,10 @@ sub build {
}
}
{
my $optgroup = $page->new_optgroup('Overridable settings (they will be displayed in the plater for quick changes)');
my $optgroup = $page->new_optgroup('Show shortcuts for the following settings');
{
my $line = Slic3r::GUI::OptionsGroup::Line->new(
widget => $overridable_widget,
widget => $shortcuts_widget,
full_width => 1,
);
$optgroup->append_line($line);
Expand All @@ -745,9 +745,9 @@ sub reload_config {
$self->_reload_compatible_printers_widget;

{
my %overridable = map { $_ => 1 } @{ $self->config->get('overridable') };
for my $i (0..$#{$self->{overridable_opt_keys}}) {
$self->{overridable_list}->Check($i, $overridable{ $self->{overridable_opt_keys}[$i] });
my %shortcuts = map { $_ => 1 } @{ $self->config->get('shortcuts') };
for my $i (0..$#{$self->{shortcuts_opt_keys}}) {
$self->{shortcuts_list}->Check($i, $shortcuts{ $self->{shortcuts_opt_keys}[$i] });
}
}

Expand Down
5 changes: 3 additions & 2 deletions xs/src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -853,8 +853,9 @@ PrintConfigDef::PrintConfigDef()
def->cli = "overhangs|detect-bridging-perimeters!";
def->default_value = new ConfigOptionBool(true);

def = this->add("overridable", coStrings);
def->label = "Overridable options";
def = this->add("shortcuts", coStrings);
def->label = "Shortcuts";
def->aliases.push_back("overridable");
{
ConfigOptionStrings* opt = new ConfigOptionStrings();
opt->values.push_back("support_material");
Expand Down

1 comment on commit 19a36cf

@gege2b
Copy link
Contributor

@gege2b gege2b commented on 19a36cf Apr 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah !
"shortcut" term makes more sense IMHO

after a few test on this branch, it work fine in the "set shortcut => update profile settings" way
but if I change a profile settings, the corresponding shortcut is not updated when I close the dialog (no matter if I save change or not).
Shortcut values seems to take precedence over profile settings, so they still act as overrides in this particular case (i.e. newly changed profile settings is ignored if a corresponding shortcut is active and with a different value)

Note : only the predefined "generate support material" checkbox is synced in both ways, making it a "true" shortcut

don't know if I'm clear sorry

Please sign in to comment.