Updated Controller after the presets C++ port.
This commit is contained in:
parent
dd9e1aff70
commit
b11d9708ed
@ -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));
|
||||
|
||||
@ -39,20 +40,18 @@ sub new {
|
||||
|
||||
EVT_LEFT_DOWN($btn, sub {
|
||||
my $menu = Wx::Menu->new;
|
||||
my $presets = wxTheApp->{preset_bundle}->printer->presets_hash;
|
||||
|
||||
# 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;
|
||||
|
||||
# remove printers that already exist
|
||||
# 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;
|
||||
|
@ -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(@_);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -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);
|
||||
|
@ -11,6 +11,8 @@
|
||||
static DynamicPrintConfig* new_from_defaults();
|
||||
static DynamicPrintConfig* new_from_defaults_keys(std::vector<std::string> keys);
|
||||
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);
|
||||
SV* as_hash()
|
||||
%code{% RETVAL = ConfigBase__as_hash(THIS); %};
|
||||
|
@ -87,19 +87,6 @@ PresetCollection::arrayref()
|
||||
OUTPUT:
|
||||
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
|
||||
|
||||
%}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user