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