From b5b735c9888c6b779d43ceb73e5246a5c2ebeea7 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 22 Mar 2014 17:01:48 +0100 Subject: [PATCH] ComboBox for fill density values --- lib/Slic3r/Config.pm | 2 -- lib/Slic3r/GUI/OptionsGroup.pm | 18 +++++++++++++----- xs/src/PrintConfig.hpp | 28 ++++++++++++++++++++++++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 22088ff3c..5fba7b392 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -262,8 +262,6 @@ sub validate { if !first { $_ eq $self->solid_fill_pattern } @{$Options->{solid_fill_pattern}{values}}; # --fill-density - die "Invalid value for --fill-density\n" - if $self->fill_density < 0 || $self->fill_density > 100; die "The selected fill pattern is not supposed to work at 100% density\n" if $self->fill_density == 100 && !first { $_ eq $self->fill_pattern } @{$Options->{solid_fill_pattern}{values}}; diff --git a/lib/Slic3r/GUI/OptionsGroup.pm b/lib/Slic3r/GUI/OptionsGroup.pm index c1cbe2d1f..0b35dde61 100644 --- a/lib/Slic3r/GUI/OptionsGroup.pm +++ b/lib/Slic3r/GUI/OptionsGroup.pm @@ -171,19 +171,27 @@ sub _build_field { # default width on Windows is too large my $size = Wx::Size->new($opt->{width} || 60, $opt->{height} || -1); - $field = $opt->{type} eq 'i' - ? Wx::SpinCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 2147483647, $opt->{default}) - : Wx::TextCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style); - $field->Disable if $opt->{readonly}; - my $on_change = sub { $self->_on_change($opt_key, $field->GetValue) }; if ($opt->{type} eq 'i') { + $field = Wx::SpinCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 2147483647, $opt->{default}); $self->_setters->{$opt_key} = sub { $field->SetValue($_[0]) }; EVT_SPINCTRL ($self->parent, $field, $on_change); + } elsif ($opt->{values}) { + $field = Wx::ComboBox->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $opt->{labels} || $opt->{values}); + $self->_setters->{$opt_key} = sub { + $field->SetValue($_[0]); + }; + EVT_COMBOBOX($self->parent, $field, sub { + $field->SetValue($opt->{values}[ $field->GetSelection ]); # set the text field to the selected value + $self->_on_change($opt_key, $on_change); + }); + EVT_TEXT($self->parent, $field, $on_change); } else { + $field = Wx::TextCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style); $self->_setters->{$opt_key} = sub { $field->ChangeValue($_[0]) }; EVT_TEXT ($self->parent, $field, $on_change); } + $field->Disable if $opt->{readonly}; $tooltip .= " (default: " . $opt->{default} . ")" if ($opt->{default}); } elsif ($opt->{type} eq 'bool') { $field = Wx::CheckBox->new($self->parent, -1, ""); diff --git a/xs/src/PrintConfig.hpp b/xs/src/PrintConfig.hpp index b9fce0e6d..096c7c7da 100644 --- a/xs/src/PrintConfig.hpp +++ b/xs/src/PrintConfig.hpp @@ -247,6 +247,34 @@ class PrintConfigDef Options["fill_density"].tooltip = "Density of internal infill, expressed in the range 0% - 100%."; Options["fill_density"].sidetext = "%"; Options["fill_density"].cli = "fill-density=s"; + Options["fill_density"].min = 0; + Options["fill_density"].max = 100; + Options["fill_density"].enum_values.push_back("5"); + Options["fill_density"].enum_values.push_back("10"); + Options["fill_density"].enum_values.push_back("15"); + Options["fill_density"].enum_values.push_back("20"); + Options["fill_density"].enum_values.push_back("25"); + Options["fill_density"].enum_values.push_back("30"); + Options["fill_density"].enum_values.push_back("40"); + Options["fill_density"].enum_values.push_back("50"); + Options["fill_density"].enum_values.push_back("60"); + Options["fill_density"].enum_values.push_back("70"); + Options["fill_density"].enum_values.push_back("80"); + Options["fill_density"].enum_values.push_back("90"); + Options["fill_density"].enum_values.push_back("100"); + Options["fill_density"].enum_labels.push_back("5%"); + Options["fill_density"].enum_labels.push_back("10%"); + Options["fill_density"].enum_labels.push_back("15%"); + Options["fill_density"].enum_labels.push_back("20%"); + Options["fill_density"].enum_labels.push_back("25%"); + Options["fill_density"].enum_labels.push_back("30%"); + Options["fill_density"].enum_labels.push_back("40%"); + Options["fill_density"].enum_labels.push_back("50%"); + Options["fill_density"].enum_labels.push_back("60%"); + Options["fill_density"].enum_labels.push_back("70%"); + Options["fill_density"].enum_labels.push_back("80%"); + Options["fill_density"].enum_labels.push_back("90%"); + Options["fill_density"].enum_labels.push_back("100%"); Options["fill_pattern"].type = coEnum; Options["fill_pattern"].label = "Fill pattern";