Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/supermerill/SuperSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorbubnikv <bubnikv@gmail.com>2017-11-02 23:51:06 +0300
committerbubnikv <bubnikv@gmail.com>2017-11-02 23:51:06 +0300
commitb11d9708edd7ad4041c2a91b865430047628a6f8 (patch)
tree580ca4d283758294dc316fa810e86fe54b5d11a1 /lib
parentdd9e1aff7023dab9e33f4710bd808387f103e998 (diff)
Updated Controller after the presets C++ port.
Diffstat (limited to 'lib')
-rw-r--r--lib/Slic3r/GUI/Controller.pm53
-rw-r--r--lib/Slic3r/GUI/MainFrame.pm4
-rw-r--r--lib/Slic3r/GUI/Plater.pm2
3 files changed, 24 insertions, 35 deletions
diff --git a/lib/Slic3r/GUI/Controller.pm b/lib/Slic3r/GUI/Controller.pm
index 6f2636d20..6aa7b34cb 100644
--- a/lib/Slic3r/GUI/Controller.pm
+++ b/lib/Slic3r/GUI/Controller.pm
@@ -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;
diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm
index c7f3f1cf9..836c3e9d0 100644
--- a/lib/Slic3r/GUI/MainFrame.pm
+++ b/lib/Slic3r/GUI/MainFrame.pm
@@ -128,8 +128,8 @@ sub _init_tabpanel {
# Update preset combo boxes (Print settings, Filament, Printer) from their respective tabs.
$self->{plater}->update_presets($tab_name, @_);
$self->{plater}->on_config_change($tab->{presets}->get_current_preset->config);
- if ($self->{controller}) {
- $self->{controller}->update_presets($tab_name, @_);
+ if ($self->{controller} && $tab_name eq 'printer') {
+ $self->{controller}->update_presets(@_);
}
}
});
diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm
index 06adbe525..6b853e410 100644
--- a/lib/Slic3r/GUI/Plater.pm
+++ b/lib/Slic3r/GUI/Plater.pm
@@ -1535,7 +1535,7 @@ sub export_amf {
sub _get_export_file {
my ($self, $format) = @_;
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/;
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);