Some multi-extruder options in GUI

This commit is contained in:
Alessandro Ranellucci 2012-07-18 20:36:34 +02:00
parent 9137a6b41e
commit 30a2213fd9
5 changed files with 172 additions and 72 deletions

View file

@ -78,6 +78,7 @@ our $bed_temperature = 0;
our $first_layer_bed_temperature = $bed_temperature;
# extruders
our $extruders_count = 1;
our $extruders = [];
our $nozzle_diameter = [0.5];

View file

@ -96,6 +96,13 @@ our $Options = {
cli => 'g0!',
type => 'bool',
},
'extruders_count' => {
label => 'Extruders',
tooltip => 'Number of extruders of the printer.',
gui_only=> 1,
type => 'i',
min => 1,
},
'gcode_comments' => {
label => 'Verbose G-code',
tooltip => 'Enable this to get a commented G-code file, with each line explained by a descriptive text. If you print from SD card, the additional weight of the file could make your firmware slow down.',
@ -905,6 +912,7 @@ sub validate {
qw(nozzle_diameter filament_diameter extrusion_multiplier temperature first_layer_temperature)
);
}
$Slic3r::extruders_count = $#$Slic3r::extruders + 1;
# calculate flow
$Slic3r::flow = $Slic3r::extruders->[0]->make_flow(width => $Slic3r::extrusion_width);

View file

@ -25,20 +25,28 @@ sub new {
my $sidetext_font = Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
my $onChange = $p{on_change} || sub {};
my $make_cb = sub {
my $cb = shift;
return sub {
$cb->(@_) if !$parent->{disabled};
};
};
foreach my $opt_key (@{$p{options}}) {
foreach my $original_opt_key (@{$p{options}}) {
my $index;
my $opt_key = $original_opt_key; # leave original one untouched
$opt_key =~ s/#(\d+)$// and $index = $1;
my $opt = $Slic3r::Config::Options->{$opt_key};
my $label;
if (!$p{no_labels}) {print $opt_key, "\n" if !defined $opt->{label};
if (!$p{no_labels}) {
$label = Wx::StaticText->new($parent, -1, "$opt->{label}:", wxDefaultPosition, [$p{label_width} || 180, -1]);
$label->Wrap($p{label_width} || 180) ; # needed to avoid Linux/GTK bug
$grid_sizer->Add($label);
}
my $field;
$fields{$opt_key} = undef;
if ($opt->{type} =~ /^(i|f|s|s@)$/) {
my $style = 0;
$style = wxTE_MULTILINE if $opt->{multiline};
@ -51,13 +59,15 @@ sub new {
my $get = sub {
my $val = Slic3r::Config->$get_m($opt_key);
$val = $val->[$index] if defined $index;
if (defined $index) {
$val = $val->[$index]; #/
}
return $val;
};
$field = $opt->{type} eq 'i'
? Wx::SpinCtrl->new($parent, -1, $get->(), wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 100, $get->())
: Wx::TextCtrl->new($parent, -1, $get->(), wxDefaultPosition, $size, $style);
$reload_callbacks{$opt_key} = sub { $field->SetValue($get->()) };
$reload_callbacks{$opt_key} = $make_cb->(sub { $field->SetValue($get->()) });
my $set = sub {
my $val = $field->GetValue;
@ -74,8 +84,8 @@ sub new {
} elsif ($opt->{type} eq 'bool') {
$field = Wx::CheckBox->new($parent, -1, "");
$field->SetValue(Slic3r::Config->get_raw($opt_key));
EVT_CHECKBOX($parent, $field, sub { Slic3r::Config->set($opt_key, $field->GetValue); $onChange->($opt_key) });
$reload_callbacks{$opt_key} = sub { $field->SetValue(Slic3r::Config->get_raw($opt_key)) };
EVT_CHECKBOX($parent, $field, $make_cb->(sub { Slic3r::Config->set($opt_key, $field->GetValue); $onChange->($opt_key) }));
$reload_callbacks{$opt_key} = $make_cb->(sub { $field->SetValue(Slic3r::Config->get_raw($opt_key)) });
} elsif ($opt->{type} eq 'point') {
$field = Wx::BoxSizer->new(wxHORIZONTAL);
my $field_size = Wx::Size->new(40, -1);
@ -96,24 +106,24 @@ sub new {
$val->[$i] = $value;
Slic3r::Config->set($opt_key, $val);
};
EVT_TEXT($parent, $x_field, sub { $set_value->(0, $x_field->GetValue); $onChange->($opt_key) });
EVT_TEXT($parent, $y_field, sub { $set_value->(1, $y_field->GetValue); $onChange->($opt_key) });
$reload_callbacks{$opt_key} = sub {
EVT_TEXT($parent, $x_field, $make_cb->(sub { $set_value->(0, $x_field->GetValue); $onChange->($opt_key) }));
EVT_TEXT($parent, $y_field, $make_cb->(sub { $set_value->(1, $y_field->GetValue); $onChange->($opt_key) }));
$reload_callbacks{$opt_key} = $make_cb->(sub {
my $value = Slic3r::Config->get_raw($opt_key);
$x_field->SetValue($value->[0]);
$y_field->SetValue($value->[1]);
};
});
$fields{$opt_key} = [$x_field, $y_field];
} elsif ($opt->{type} eq 'select') {
$field = Wx::ComboBox->new($parent, -1, "", wxDefaultPosition, wxDefaultSize, $opt->{labels} || $opt->{values}, wxCB_READONLY);
EVT_COMBOBOX($parent, $field, sub {
EVT_COMBOBOX($parent, $field, $make_cb->(sub {
Slic3r::Config->set($opt_key, $opt->{values}[$field->GetSelection]);
$onChange->($opt_key);
});
$reload_callbacks{$opt_key} = sub {
}));
$reload_callbacks{$opt_key} = $make_cb->(sub {
my $value = Slic3r::Config->get_raw($opt_key);
$field->SetSelection(grep $opt->{values}[$_] eq $value, 0..$#{$opt->{values}});
};
});
$reload_callbacks{$opt_key}->();
} else {
die "Unsupported option type: " . $opt->{type};

View file

@ -195,7 +195,7 @@ sub load_config {
}
$last_config_dir = dirname($file);
$last_config = $file;
$_->external_config_loaded($file) for values %{$self->{options_tabs}};
$_->load_external_config($file) for values %{$self->{options_tabs}};
}
sub config_wizard {

View file

@ -11,11 +11,9 @@ use base 'Wx::Panel';
sub new {
my $class = shift;
my ($parent, $title, %params) = @_;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT);
$self->{title} = $title;
$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);
@ -43,7 +41,7 @@ sub new {
# buttons
$self->{btn_save_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/disk.png", wxBITMAP_TYPE_PNG));
$self->{btn_delete_preset} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
$self->{btn_save_preset}->SetToolTipString("Save current " . lc($title));
$self->{btn_save_preset}->SetToolTipString("Save current " . lc($self->title));
$self->{btn_delete_preset}->SetToolTipString("Delete this preset");
$self->{btn_delete_preset}->Disable;
@ -66,12 +64,13 @@ sub new {
$self->{treectrl}->AssignImageList($self->{icons});
$self->{iconcount} = -1;
$self->{treectrl}->AddRoot("root");
$self->{pages} = {};
$self->{pages} = [];
$self->{treectrl}->SetIndent(0);
EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
$_->Hide for values %{$self->{pages}};
my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
or return;
$_->Hide for @{$self->{pages}};
$self->{sizer}->Remove(1);
my $page = $self->{pages}->{ $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) };
$page->Show;
$self->{sizer}->Add($page, 1, wxEXPAND | wxLEFT, 5);
$self->{sizer}->Layout;
@ -89,7 +88,7 @@ sub new {
$default_name =~ s/\.ini$//i;
my $dlg = Slic3r::GUI::SavePresetWindow->new($self,
title => lc($title),
title => lc($self->title),
default => $default_name,
values => [ map { my $name = $_->{name}; $name =~ s/\.ini$//i; $name } @{$self->{presets}} ],
);
@ -119,6 +118,8 @@ sub new {
$self->sync_presets;
});
$self->build;
return $self;
}
@ -127,6 +128,9 @@ sub current_preset {
return $self->{presets}[ $self->{presets_choice}->GetSelection ];
}
sub on_value_change {}
sub on_preset_loaded {}
sub on_select_preset {
my $self = shift;
@ -154,6 +158,7 @@ sub on_select_preset {
? $self->{btn_delete_preset}->Disable
: $self->{btn_delete_preset}->Enable;
}
$self->on_preset_loaded;
$_->() for @Slic3r::GUI::OptionsGroup::reload_callbacks{@{$Slic3r::Config::Groups{$self->{presets_group}}}};
$self->set_dirty(0);
$Slic3r::Settings->{presets}{$self->{presets_group}} = $preset->{file} ? basename($preset->{file}) : '';
@ -162,25 +167,36 @@ sub on_select_preset {
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 ($title, $icon, %params) = @_;
my $bitmap = $icon
? Wx::Bitmap->new("$Slic3r::var/$icon", wxBITMAP_TYPE_PNG)
: undef;
if ($bitmap) {
if ($icon) {
my $bitmap = Wx::Bitmap->new("$Slic3r::var/$icon", wxBITMAP_TYPE_PNG);
$self->{icons}->Add($bitmap);
$self->{iconcount}++;
}
my $page = Slic3r::GUI::Tab::Page->new($self, $title, $self->{iconcount}, %params, on_change => sub {
$self->on_value_change(@_);
$self->set_dirty(1);
$self->sync_presets;
});
$page->Hide;
my $itemId = $self->{treectrl}->AppendItem($self->{treectrl}->GetRootItem, $title, $self->{iconcount});
$self->{pages}{$title} = $page;
if (keys %{$self->{pages}} == 1) {
$self->{treectrl}->SelectItem($itemId);
push @{$self->{pages}}, $page;
$self->update_tree;
return $page;
}
sub update_tree {
my $self = shift;
my ($select) = @_;
$select //= 0; #/
my $rootItem = $self->{treectrl}->GetRootItem;
$self->{treectrl}->DeleteChildren($rootItem);
foreach my $page (@{$self->{pages}}) {
my $itemId = $self->{treectrl}->AppendItem($rootItem, $page->{title}, $page->{iconID});
$self->{treectrl}->SelectItem($itemId) if $self->{treectrl}->GetChildrenCount($rootItem) == $select + 1;
}
}
@ -211,11 +227,6 @@ sub is_dirty {
return (defined $self->{dirty});
}
sub title {
my $self = shift;
return $self->{title};
}
sub load_presets {
my $self = shift;
my ($group) = @_;
@ -248,7 +259,7 @@ sub load_presets {
$self->sync_presets;
}
sub external_config_loaded {
sub load_external_config {
my $self = shift;
my ($file) = @_;
@ -282,10 +293,10 @@ sub sync_presets {
package Slic3r::GUI::Tab::Print;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Print Settings', %params);
sub title { 'Print Settings' }
sub build {
my $self = shift;
$self->add_options_page('Layers and perimeters', 'layers.png', optgroups => [
{
@ -383,17 +394,15 @@ sub new {
]);
$self->load_presets('print');
return $self;
}
package Slic3r::GUI::Tab::Filament;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Filament Settings', %params);
sub title { 'Filament Settings' }
sub build {
my $self = shift;
$self->add_options_page('Filament', 'spool.png', optgroups => [
{
@ -423,17 +432,15 @@ sub new {
]);
$self->load_presets('filament');
return $self;
}
package Slic3r::GUI::Tab::Printer;
use base 'Slic3r::GUI::Tab';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, 'Printer Settings', %params);
sub title { 'Printer Settings' }
sub build {
my $self = shift;
$self->add_options_page('General', 'printer_empty.png', optgroups => [
{
@ -444,16 +451,9 @@ sub new {
title => 'Firmware',
options => [qw(gcode_flavor use_relative_e_distances)],
},
]);
$self->add_options_page('Extruder 1', 'funnel.png', optgroups => [
{
title => 'Size',
options => ['nozzle_diameter#0'],
},
{
title => 'Retraction',
options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
title => 'Capabilities',
options => [qw(extruders_count)],
},
]);
@ -475,9 +475,86 @@ sub new {
},
]);
$self->load_presets('printer');
$self->{extruder_pages} = [];
$self->build_extruder_pages;
return $self;
$self->load_presets('printer');
}
sub extruder_options { qw(nozzle_diameter) }
sub build_extruder_pages {
my $self = shift;
foreach my $extruder_idx (0 .. $Slic3r::extruders_count-1) {
# set default values
for my $opt_key ($self->extruder_options) {
Slic3r::Config->get_raw($opt_key)->[$extruder_idx] //= Slic3r::Config->get_raw($opt_key)->[0]; #/
}
# build page if it doesn't exist
$self->{extruder_pages}[$extruder_idx] ||= $self->add_options_page("Extruder " . ($extruder_idx + 1), 'funnel.png', optgroups => [
{
title => 'Size',
options => ['nozzle_diameter#' . $extruder_idx],
},
{
title => 'Retraction',
options => [qw(retract_length retract_lift retract_speed retract_restart_extra retract_before_travel)],
},
]);
$self->{extruder_pages}[$extruder_idx]{disabled} = 0;
}
# rebuild page list
@{$self->{pages}} = (
(grep $_->{title} !~ /^Extruder \d+/, @{$self->{pages}}),
@{$self->{extruder_pages}}[ 0 .. $Slic3r::extruders_count-1 ],
);
}
sub on_value_change {
my $self = shift;
my ($opt_key) = @_;
$self->SUPER::on_value_change(@_);
if ($opt_key eq 'extruders_count') {
# remove unused pages from list
my @unused_pages = @{ $self->{extruder_pages} }[$Slic3r::extruders_count .. $#{$self->{extruder_pages}}];
for my $page (@unused_pages) {
@{$self->{pages}} = grep $_ ne $page, @{$self->{pages}};
$page->{disabled} = 1;
}
# delete values for unused extruders
for my $opt_key ($self->extruder_options) {
my $values = Slic3r::Config->get_raw($opt_key);
splice @$values, $Slic3r::extruders_count if $Slic3r::extruders_count <= $#$values;
}
# add extra pages
$self->build_extruder_pages;
# update page list and select first page (General)
$self->update_tree(0);
}
}
# this gets executed after preset is loaded in repository and before GUI fields are updated
sub on_preset_loaded {
my $self = shift;
# update the extruders count field
{printf "nozzle count = %d\n", scalar @{ Slic3r::Config->get_raw('nozzle_diameter') };
# set value in repository according to the number of nozzle diameters supplied
Slic3r::Config->set('extruders_count', scalar @{ Slic3r::Config->get_raw('nozzle_diameter') });
# update the GUI field
$Slic3r::GUI::OptionsGroup::reload_callbacks{extruders_count}->();
# update extruder page list
$self->on_value_change('extruders_count');
}
}
package Slic3r::GUI::Tab::Page;
@ -486,8 +563,11 @@ use base 'Wx::ScrolledWindow';
sub new {
my $class = shift;
my ($parent, %params) = @_;
my ($parent, $title, $iconID, %params) = @_;
my $self = $class->SUPER::new($parent, -1);
$self->{opt_keys} = [];
$self->{title} = $title;
$self->{iconID} = $iconID;
$self->SetScrollbars(1, 1, 1, 1);
@ -503,8 +583,9 @@ sub new {
sub append_optgroup {
my $self = shift;
my %params = @_;
my $optgroup = Slic3r::GUI::OptionsGroup->new($self, label_width => 200, @_);
my $optgroup = Slic3r::GUI::OptionsGroup->new($self, label_width => 200, %params);
$self->{vsizer}->Add($optgroup, 0, wxEXPAND | wxALL, 5);
}