Preset shortcuts in the plater tab

This commit is contained in:
Alessandro Ranellucci 2012-06-19 17:23:10 +02:00
parent 0003c093e3
commit b910840f76
4 changed files with 94 additions and 40 deletions

View File

@ -16,6 +16,11 @@ use base 'Wx::App';
my $growler;
our $datadir;
our $small_font = Wx::SystemSettings::GetFont(&Wx::wxSYS_DEFAULT_GUI_FONT);
$small_font->SetPointSize(11);
our $medium_font = Wx::SystemSettings::GetFont(&Wx::wxSYS_DEFAULT_GUI_FONT);
$medium_font->SetPointSize(12);
sub OnInit {
my $self = shift;

View File

@ -193,9 +193,29 @@ sub new {
$vertical_sizer->Add($list_sizer, 0, wxEXPAND | &Wx::wxBOTTOM, 10);
$vertical_sizer->Add($buttons, 0, wxEXPAND);
my $sizer = Wx::BoxSizer->new(wxHORIZONTAL);
$sizer->Add($self->{canvas}, 0, wxALL, 10);
$sizer->Add($vertical_sizer, 1, wxEXPAND | wxALL, 10);
my $hsizer = Wx::BoxSizer->new(wxHORIZONTAL);
$hsizer->Add($self->{canvas}, 0, wxALL, 10);
$hsizer->Add($vertical_sizer, 1, wxEXPAND | wxALL, 10);
my $presets = Wx::BoxSizer->new(wxHORIZONTAL);
my %group_labels = (
print => 'Print settings',
filament => 'Filament',
printer => 'Printer',
);
$self->{preset_choosers} = {};
for my $group (qw(print filament printer)) {
my $text = Wx::StaticText->new($self, -1, "$group_labels{$group}:", [-1, -1], [-1, -1], wxALIGN_RIGHT);
$text->SetFont($Slic3r::GUI::medium_font);
$self->{preset_choosers}{$group} = Wx::Choice->new($self, -1, [-1, -1], [-1, -1], []);
$presets->Add($text, 1, wxALIGN_RIGHT | wxRIGHT, 4);
$presets->Add($self->{preset_choosers}{$group}, 2, wxRIGHT, 15);
}
my $sizer = Wx::BoxSizer->new(wxVERTICAL);
$sizer->Add($hsizer, 0, wxEXPAND | wxBOTTOM, 10);
$sizer->Add($presets, 0, wxEXPAND | wxLEFT | wxRIGHT, 20);
$sizer->SetSizeHints($self);
$self->SetSizer($sizer);
}

View File

@ -21,13 +21,17 @@ sub new {
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
$self->{options_tabs} = {};
my $tabpanel = Wx::Notebook->new($self, -1, Wx::wxDefaultPosition, Wx::wxDefaultSize, &Wx::wxNB_TOP);
$tabpanel->AddPage(Slic3r::GUI::Plater->new($tabpanel), "Plater");
$tabpanel->AddPage($self->{options_tabs}{print} = Slic3r::GUI::Tab::Print->new($tabpanel), "Print settings");
$tabpanel->AddPage($self->{options_tabs}{filament} = Slic3r::GUI::Tab::Filament->new($tabpanel), "Filament settings");
$tabpanel->AddPage($self->{options_tabs}{printer} = Slic3r::GUI::Tab::Printer->new($tabpanel), "Printer settings");
$tabpanel->AddPage($self->{plater} = Slic3r::GUI::Plater->new($tabpanel), "Plater");
$self->{options_tabs} = {
print => Slic3r::GUI::Tab::Print->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{print}),
filament => Slic3r::GUI::Tab::Filament->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{filament}),
printer => Slic3r::GUI::Tab::Printer->new ($tabpanel, sync_presets_with => $self->{plater}{preset_choosers}{printer}),
};
$tabpanel->AddPage($self->{options_tabs}{print}, "Print settings");
$tabpanel->AddPage($self->{options_tabs}{filament}, "Filament settings");
$tabpanel->AddPage($self->{options_tabs}{printer}, "Printer settings");
my $buttons_sizer;
{
$buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL);

View File

@ -9,14 +9,17 @@ use Wx qw(:sizer :progressdialog);
use Wx::Event qw(EVT_TREE_SEL_CHANGED EVT_CHOICE EVT_BUTTON);
use base 'Wx::Panel';
my $small_font = Wx::SystemSettings::GetFont(&Wx::wxSYS_DEFAULT_GUI_FONT);
$small_font->SetPointSize(11);
sub new {
my $class = shift;
my ($parent) = @_;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, [-1,-1], [-1,-1], &Wx::wxBK_LEFT);
$self->{sync_presets_with} = $params{sync_presets_with};
EVT_CHOICE($parent, $self->{sync_presets_with}, sub {
$self->{presets_choice}->SetSelection($self->{sync_presets_with}->GetSelection);
$self->on_select_preset;
});
# horizontal sizer
$self->{sizer} = Wx::BoxSizer->new(&Wx::wxHORIZONTAL);
$self->{sizer}->SetSizeHints($self);
@ -35,7 +38,7 @@ sub new {
# choice menu
$self->{presets_choice} = Wx::Choice->new($box, -1, [-1, -1], [-1, -1], []);
$self->{presets_choice}->SetFont($small_font);
$self->{presets_choice}->SetFont($Slic3r::GUI::small_font);
# buttons
$self->{btn_save_preset} = Wx::BitmapButton->new($box, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", &Wx::wxBITMAP_TYPE_PNG));
@ -71,26 +74,8 @@ sub new {
});
EVT_CHOICE($parent, $self->{presets_choice}, sub {
if (defined $self->{dirty}) {
# TODO: prompt user?
$self->set_dirty(0);
}
my $i = $self->{presets_choice}->GetSelection;
if ($i == 0) {
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
$self->{btn_delete_preset}->Disable;
} else {
my $file = $self->{presets}[$i-1];
if (!-e $file) {
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($file).");
return;
}
Slic3r::Config->load($file, $self->{presets_group});
$self->{btn_delete_preset}->Enable;
}
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
$self->set_dirty(0);
$self->on_select_preset;
$self->sync_presets;
});
EVT_BUTTON($self, $self->{btn_save_preset}, sub {
@ -109,17 +94,44 @@ sub new {
$self->set_dirty(0);
$self->load_presets;
$self->{presets_choice}->SetSelection(1 + first { basename($self->{presets}[$_]) eq $dlg->get_name . ".ini" } 0 .. $#{$self->{presets}});
$self->sync_presets;
});
return $self;
}
sub on_select_preset {
my $self = shift;
if (defined $self->{dirty}) {
# TODO: prompt user?
$self->set_dirty(0);
}
my $i = $self->{presets_choice}->GetSelection;
if ($i == 0) {
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
$self->{btn_delete_preset}->Disable;
} else {
my $file = $self->{presets}[$i-1];
if (!-e $file) {
Slic3r::GUI::show_error($self, "The selected preset does not exist anymore ($file).");
return;
}
Slic3r::Config->load($file, $self->{presets_group});
$self->{btn_delete_preset}->Enable;
}
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
$self->set_dirty(0);
}
sub add_options_page {
my $self = shift;
my $title = shift;
my $icon = (ref $_[1]) ? undef : shift;
my $page = Slic3r::GUI::Tab::Page->new($self, @_, on_change => sub {
$self->set_dirty(1);
$self->sync_presets;
});
my $bitmap = $icon
@ -156,6 +168,7 @@ sub set_dirty {
$text =~ s/ \(modified\)$//;
$self->{presets_choice}->SetString($i, $text);
}
$self->sync_presets;
}
sub load_presets {
@ -176,6 +189,7 @@ sub load_presets {
$preset =~ s/\.ini$//i;
$self->{presets_choice}->Append($preset);
}
$self->sync_presets;
}
sub external_config_loaded {
@ -194,6 +208,17 @@ sub external_config_loaded {
$self->set_dirty(0);
$self->{btn_save_preset}->Enable;
$self->{btn_delete_preset}->Disable;
$self->sync_presets;
}
sub sync_presets {
my $self = shift;
return unless $self->{sync_presets_with};
$self->{sync_presets_with}->Clear;
foreach my $item ($self->{presets_choice}->GetStrings) {
$self->{sync_presets_with}->Append($item);
}
$self->{sync_presets_with}->SetSelection($self->{presets_choice}->GetSelection);
}
package Slic3r::GUI::Tab::Print;
@ -203,8 +228,8 @@ use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, %params);
$self->add_options_page('Layers and perimeters', 'layers.png', optgroups => [
{
@ -309,8 +334,8 @@ use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, %params);
$self->add_options_page('Filament', 'spool.png', optgroups => [
{
@ -351,8 +376,8 @@ use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1);
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, %params);
$self->add_options_page('General', 'printer_empty.png', optgroups => [
{