Skip to content

Commit

Permalink
Some fixes and improvements to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Nov 8, 2015
1 parent 3c43fb8 commit 80620a5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
37 changes: 32 additions & 5 deletions lib/Slic3r/GUI/Controller.pm
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ 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 'Wx::ScrolledWindow';
use base qw(Wx::ScrolledWindow Class::Accessor);

__PACKAGE__->mk_accessors(qw(_selected_printer_preset));

our @ConfigOptions = qw(bed_shape serial_port serial_speed);

sub new {
my ($class, $parent) = @_;
Expand Down Expand Up @@ -105,17 +109,23 @@ sub OnActivate {
grep { $_->is_connected || @{$_->jobs} > 0 }
$self->print_panels;

# if there are no active panels, use sensible defaults
if (!%active) {
if (keys %presets <= 2) {
if (%presets) {
# if there are no active panels, use sensible defaults
if (!%active && keys %presets <= 2) {
# if only one or two presets exist, load them
$active{$_} = 1 for keys %presets;
} else {
}
if (!%active) {
# enable printers whose port is available
my %ports = map { $_ => 1 } wxTheApp->scan_serial_ports;
$active{$_} = 1
for grep exists $ports{$presets{$_}->serial_port}, keys %presets;
}
if (!%active && $self->_selected_printer_preset) {
# enable currently selected printer if it is configured
$active{$self->_selected_printer_preset} = 1
if $presets{$self->_selected_printer_preset};
}
}

# apply changes
Expand Down Expand Up @@ -163,4 +173,21 @@ sub print_panels {
map $_->GetWindow, $self->{sizer}->GetChildren;
}

sub update_presets {
my $self = shift;
my ($group, $presets, $selected, $is_dirty) = @_;

# update configs of currently loaded print panels
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);
}
}
}

$self->_selected_printer_preset($presets->[$selected]->name);
}

1;
2 changes: 1 addition & 1 deletion lib/Slic3r/GUI/Controller/PrinterPanel.pm
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ sub new {
}
{
my $filament_stats = join "\n",
map "$_ (" . sprintf("%.2f", $job->filament_stats->{$_}/100) . "m)",
map "$_ (" . sprintf("%.2f", $job->filament_stats->{$_}/1000) . "m)",
sort keys %{$job->filament_stats};
my $text = Wx::StaticText->new($self, -1, $filament_stats, wxDefaultPosition, wxDefaultSize);
$text->SetFont($Slic3r::GUI::small_font);
Expand Down
3 changes: 2 additions & 1 deletion lib/Slic3r/GUI/MainFrame.pm
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ sub _init_tabpanel {
if ($self->{plater}) {
$self->{plater}->update_presets($tab_name, @_);
$self->{plater}->on_config_change($tab->config);
$self->{controller}->update_presets($tab_name, @_);
}
});
$tab->load_presets;
Expand Down Expand Up @@ -735,7 +736,7 @@ sub check_unsaved_changes {

sub select_tab {
my ($self, $tab) = @_;
$self->{tabpanel}->ChangeSelection($tab);
$self->{tabpanel}->SetSelection($tab);
}

sub _append_menu_item {
Expand Down

0 comments on commit 80620a5

Please sign in to comment.