Updated Controller after the presets C++ port.

This commit is contained in:
bubnikv 2017-11-02 21:51:06 +01:00
parent dd9e1aff70
commit b11d9708ed
5 changed files with 26 additions and 48 deletions

View File

@ -10,6 +10,7 @@ use utf8;
use Wx qw(wxTheApp :frame :id :misc :sizer :bitmap :button :icon :dialog); use Wx qw(wxTheApp :frame :id :misc :sizer :bitmap :button :icon :dialog);
use Wx::Event qw(EVT_CLOSE EVT_LEFT_DOWN EVT_MENU); use Wx::Event qw(EVT_CLOSE EVT_LEFT_DOWN EVT_MENU);
use base qw(Wx::ScrolledWindow Class::Accessor); use base qw(Wx::ScrolledWindow Class::Accessor);
use List::Util qw(first);
__PACKAGE__->mk_accessors(qw(_selected_printer_preset)); __PACKAGE__->mk_accessors(qw(_selected_printer_preset));
@ -38,21 +39,19 @@ sub new {
if $btn->can('SetToolTipString'); if $btn->can('SetToolTipString');
EVT_LEFT_DOWN($btn, sub { EVT_LEFT_DOWN($btn, sub {
my $menu = Wx::Menu->new; my $menu = Wx::Menu->new;
my $presets = wxTheApp->{preset_bundle}->printer->presets_hash; my @panels = $self->print_panels;
# remove printers that already exist # remove printers that already exist
my @panels = $self->print_panels; # update configs of currently loaded print panels
delete $presets->{$_} for map $_->printer_name, @panels; foreach my $preset (@{wxTheApp->{preset_bundle}->printer}) {
my $preset_name = $preset->name;
foreach my $preset_name (sort keys %{$presets}) { next if ! $preset->config->serial_port ||
my $config = Slic3r::Config->load($presets->{$preset_name}); defined first { defined $_ && $_->printer_name eq $preset_name } @panels;
next if !$config->serial_port; my $myconfig = $preset->config->clone_only(\@ConfigOptions);
my $id = &Wx::NewId(); my $id = &Wx::NewId();
$menu->Append($id, $preset_name); $menu->Append($id, $preset_name);
EVT_MENU($menu, $id, sub { EVT_MENU($menu, $id, sub {
$self->add_printer($preset_name, $config); $self->add_printer($preset_name, $myconfig);
}); });
} }
$self->PopupMenu($menu, $btn->GetPosition); $self->PopupMenu($menu, $btn->GetPosition);
@ -98,12 +97,8 @@ sub OnActivate {
my ($self) = @_; my ($self) = @_;
# get all available presets # get all available presets
my %presets = (); my %presets = map { $_->name => $_->config->clone_only(\@ConfigOptions) }
{ grep { $_->config->serial_port } @{wxTheApp->{preset_bundle}->printer};
my $all = wxTheApp->{preset_bundle}->printer->presets_hash;
my %configs = map { my $name = $_; $name => Slic3r::Config->load($all->{$name}) } keys %{$all};
%presets = map { $_ => $configs{$_} } grep $configs{$_}->serial_port, keys %{$all};
}
# decide which ones we want to keep # decide which ones we want to keep
my %active = (); my %active = ();
@ -177,25 +172,19 @@ sub print_panels {
map $_->GetWindow, $self->{sizer}->GetChildren; map $_->GetWindow, $self->{sizer}->GetChildren;
} }
# Called by # Called by Slic3r::GUI::Tab::Printer::_on_presets_changed
# Slic3r::GUI::Tab::Print::_on_presets_changed # when the presets are loaded or the user selects another preset.
# Slic3r::GUI::Tab::Filament::_on_presets_changed
# Slic3r::GUI::Tab::Printer::_on_presets_changed
# when the presets are loaded or the user select another preset.
sub update_presets { sub update_presets {
my ($self, $group, $presets, $default_suppressed, $selected, $is_dirty) = @_; my ($self, $presets) = @_;
# update configs of currently loaded print panels # update configs of currently loaded print panels
my @presets = @$presets;
foreach my $panel ($self->print_panels) { foreach my $panel ($self->print_panels) {
foreach my $preset (@$presets) { my $preset = $presets->find_preset($panel->printer_name, 0);
if ($panel->printer_name eq $preset->name) { $panel->config($preset->config->clone_only(\@ConfigOptions))
my $config = $preset->config(\@ConfigOptions); if defined $preset;
$panel->config->apply($config);
}
}
} }
$self->_selected_printer_preset($presets->[$selected]->name); $self->_selected_printer_preset($presets->get_selected_preset->name);
} }
1; 1;

View File

@ -128,8 +128,8 @@ sub _init_tabpanel {
# Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs. # Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs.
$self->{plater}->update_presets($tab_name, @_); $self->{plater}->update_presets($tab_name, @_);
$self->{plater}->on_config_change($tab->{presets}->get_current_preset->config); $self->{plater}->on_config_change($tab->{presets}->get_current_preset->config);
if ($self->{controller}) { if ($self->{controller} && $tab_name eq 'printer') {
$self->{controller}->update_presets($tab_name, @_); $self->{controller}->update_presets(@_);
} }
} }
}); });

View File

@ -1535,7 +1535,7 @@ sub export_amf {
sub _get_export_file { sub _get_export_file {
my ($self, $format) = @_; my ($self, $format) = @_;
my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml'; my $suffix = $format eq 'STL' ? '.stl' : '.amf.xml';
my $output_file = $self->{print}->output_filepath($main::opt{output}); my $output_file = $self->{print}->output_filepath($main::opt{output} // '');
$output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/; $output_file =~ s/\.[gG][cC][oO][dD][eE]$/$suffix/;
my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file), my $dlg = Wx::FileDialog->new($self, "Save $format file as:", dirname($output_file),
basename($output_file), &Slic3r::GUI::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT); basename($output_file), &Slic3r::GUI::MODEL_WILDCARD, wxFD_SAVE | wxFD_OVERWRITE_PROMPT);

View File

@ -11,6 +11,8 @@
static DynamicPrintConfig* new_from_defaults(); static DynamicPrintConfig* new_from_defaults();
static DynamicPrintConfig* new_from_defaults_keys(std::vector<std::string> keys); static DynamicPrintConfig* new_from_defaults_keys(std::vector<std::string> keys);
DynamicPrintConfig* clone() %code{% RETVAL = new DynamicPrintConfig(*THIS); %}; DynamicPrintConfig* clone() %code{% RETVAL = new DynamicPrintConfig(*THIS); %};
DynamicPrintConfig* clone_only(std::vector<std::string> keys)
%code{% RETVAL = new DynamicPrintConfig(); RETVAL->apply_only(*THIS, keys, true); %};
bool has(t_config_option_key opt_key); bool has(t_config_option_key opt_key);
SV* as_hash() SV* as_hash()
%code{% RETVAL = ConfigBase__as_hash(THIS); %}; %code{% RETVAL = ConfigBase__as_hash(THIS); %};

View File

@ -87,19 +87,6 @@ PresetCollection::arrayref()
OUTPUT: OUTPUT:
RETVAL RETVAL
SV*
PresetCollection::presets_hash()
CODE:
HV* hv = newHV();
for (size_t i = 1; i < THIS->size(); ++ i) {
const Slic3r::Preset &preset = THIS->preset(i);
if (! preset.is_default && ! preset.is_external)
(void)hv_store(hv, preset.name.c_str(), - int(preset.name.size()), newSVpvn_utf8(preset.file.c_str(), preset.file.size(), true), 0);
}
RETVAL = (SV*)newRV_noinc((SV*)hv);
OUTPUT:
RETVAL
%} %}
}; };