Refactored configuration handling.

Slic3r::Config is now an object. Multiple partial config objects are used throughout the codebase as local repositories, then merged and serialized when necessary.
This commit is contained in:
Alessandro Ranellucci 2012-07-27 21:13:03 +02:00
parent f0579e59bd
commit 7e34244b05
23 changed files with 918 additions and 833 deletions

View file

@ -372,7 +372,7 @@ sub apply {
$self->SUPER::apply;
# set print_center to centre of bed_size
my $bed_size = Slic3r::Config->get_raw('bed_size');
my $bed_size = $Slic3r::Config->bed_size;
Slic3r::Config->set('print_center', [$bed_size->[0]/2, $bed_size->[1]/2]);
}
@ -395,7 +395,7 @@ sub apply {
$self->SUPER::apply;
# set first_layer_height + layer_height based on nozzle_diameter
my $nozzle = Slic3r::Config->get_raw('nozzle_diameter');
my $nozzle = $Slic3r::Config->nozzle_diameter;
Slic3r::Config->set('first_layer_height', $nozzle->[0]);
Slic3r::Config->set('layer_height', $nozzle->[0] - 0.1);
}
@ -435,7 +435,7 @@ sub apply {
$self->SUPER::apply;
# set first_layer_temperature to temperature + 5
my $temperature = Slic3r::Config->get_raw('temperature');
my $temperature = $Slic3r::Config->temperature;
Slic3r::Config->set('first_layer_temperature', [$temperature->[0] + 5]);
}
@ -459,7 +459,7 @@ sub apply {
$self->SUPER::apply;
# set first_layer_bed_temperature to temperature + 5
my $temperature = Slic3r::Config->get_raw('bed_temperature');
my $temperature = $Slic3r::Config->bed_temperature;
Slic3r::Config->set('first_layer_bed_temperature', $temperature + 5);
}

View file

@ -1,6 +1,7 @@
package Slic3r::GUI::OptionsGroup;
use Moo;
use List::Util qw(first);
use Wx qw(:combobox :font :misc :sizer :systemsettings :textctrl);
use Wx::Event qw(EVT_CHECKBOX EVT_COMBOBOX EVT_SPINCTRL EVT_TEXT);
@ -28,6 +29,7 @@ Slic3r::GUI::OptionsGroup - pre-filled Wx::StaticBoxSizer wrapper containing one
labels => [],
values => [],
default => 0.4, # mandatory
readonly => 0,
on_change => sub { print "new value is $_[0]\n" },
},
],
@ -86,6 +88,7 @@ sub BUILD {
$field = $opt->{type} eq 'i'
? Wx::SpinCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style, $opt->{min} || 0, $opt->{max} || 100, $opt->{default})
: Wx::TextCtrl->new($self->parent, -1, $opt->{default}, wxDefaultPosition, $size, $style);
$field->Disable if $opt->{readonly};
$self->_setters->{$opt_key} = sub { $field->SetValue($_[0]) };
my $on_change = sub { $self->_on_change($opt_key, $field->GetValue) };
@ -145,6 +148,13 @@ sub BUILD {
$self->sizer->Add($grid_sizer, 0, wxEXPAND);
}
sub _option {
my $self = shift;
my ($opt_key) = @_;
return first { $_->{opt_key} eq $opt_key } @{$self->options};
}
sub _on_change {
my $self = shift;
my ($opt_key, $value) = @_;
@ -189,6 +199,7 @@ Slic3r::GUI::ConfigOptionsGroup - pre-filled Wx::StaticBoxSizer wrapper containi
my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
parent => $self->parent,
title => 'Layers',
config => $config,
options => ['layer_height'],
on_change => sub { print "new value for $_[0] is $_[1]\n" },
no_labels => 0,
@ -198,7 +209,7 @@ Slic3r::GUI::ConfigOptionsGroup - pre-filled Wx::StaticBoxSizer wrapper containi
=cut
use List::Util qw(first);
has 'config' => (is => 'ro', required => 1);
sub _trigger_options {
my $self = shift;
@ -212,7 +223,7 @@ sub _trigger_options {
$opt = {
opt_key => $full_key,
config => 1,
(map { $_ => $config_opt->{$_} } qw(type label tooltip sidetext width height full_width min max labels values multiline)),
(map { $_ => $config_opt->{$_} } qw(type label tooltip sidetext width height full_width min max labels values multiline readonly)),
default => $self->_get_config($opt_key, $index),
on_change => sub { $self->_set_config($opt_key, $index, $_[0]) },
};
@ -225,7 +236,10 @@ sub set_value {
my $self = shift;
my ($opt_key, $value) = @_;
if (first { $_->{opt_key} eq $opt_key && !$_->{config} } @{$self->options}) {
my $opt = $self->_option($opt_key) or return 0;
# if user is setting a non-config option, forward the call to the parent
if (!$opt->{config}) {
return $self->SUPER::set_value($opt_key, $value);
}
@ -234,7 +248,8 @@ sub set_value {
my ($key, $index) = $self->_split_key($full_key);
if ($key eq $opt_key) {
$self->SUPER::set_value($full_key, $self->_get_config($key, $index, $value));
$self->config->set($key, $value);
$self->SUPER::set_value($full_key, $self->_get_config($key, $index));
$changed = 1;
}
}
@ -252,11 +267,14 @@ sub _split_key {
sub _get_config {
my $self = shift;
my ($opt_key, $index, $value) = @_;
my ($opt_key, $index) = @_;
my ($get_m, $set_m) = $self->_config_methods($opt_key, $index);
$value ||= Slic3r::Config->$get_m($opt_key);
$value = $value->[$index] if defined $index;
my ($get_m, $serialized) = $self->_config_methods($opt_key, $index);
my $value = $self->config->$get_m($opt_key);
if (defined $index) {
$value->[$index] //= $value->[0]; #/
$value = $value->[$index];
}
return $value;
}
@ -264,10 +282,10 @@ sub _set_config {
my $self = shift;
my ($opt_key, $index, $value) = @_;
my ($get_m, $set_m) = $self->_config_methods($opt_key, $index);
my ($get_m, $serialized) = $self->_config_methods($opt_key, $index);
defined $index
? Slic3r::Config->$get_m($opt_key)->[$index] = $value
: Slic3r::Config->$set_m($opt_key, $value);
? $self->config->$get_m($opt_key)->[$index] = $value
: $self->config->set($opt_key, $value, $serialized);
}
sub _config_methods {
@ -275,9 +293,9 @@ sub _config_methods {
my ($opt_key, $index) = @_;
# if it's an array type but no index was specified, use the serialized version
return $Slic3r::Config::Options->{$opt_key}{type} =~ /\@$/ && !defined $index
? qw(serialize deserialize)
: qw(get_raw set);
return ($Slic3r::Config::Options->{$opt_key}{type} =~ /\@$/ && !defined $index)
? qw(serialize 1)
: qw(get 0);
}
1;

View file

@ -26,10 +26,17 @@ my $MESSAGE_DIALOG_EVENT : shared = Wx::NewEventType;
my $EXPORT_COMPLETED_EVENT : shared = Wx::NewEventType;
my $EXPORT_FAILED_EVENT : shared = Wx::NewEventType;
use constant CANVAS_TEXT => join('-', +(localtime)[3,4]) eq '13-8'
? 'What do you want to print today? ™' # Sept. 13, 2006. The first part ever printed by a RepRap to make another RepRap.
: 'Drag your objects here';
sub new {
my $class = shift;
my ($parent) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
$self->{config} = Slic3r::Config->new_from_defaults(qw(
bed_size print_center complete_objects extruder_clearance_radius skirts skirt_distance
));
$self->{canvas} = Wx::Panel->new($self, -1, wxDefaultPosition, [300, 300], wxTAB_TRAVERSAL);
$self->{canvas}->SetBackgroundColour(Wx::wxWHITE);
@ -173,7 +180,7 @@ sub new {
$self->on_export_failed;
});
$self->update_bed_size;
$self->_update_bed_size;
$self->{print} = Slic3r::Print->new;
$self->{thumbnails} = []; # polygons, each one aligned to 0,0
$self->{scale} = [];
@ -229,6 +236,11 @@ sub new {
return $self;
}
sub skeinpanel {
my $self = shift;
return $self->GetParent->GetParent;
}
sub load {
my $self = shift;
@ -428,7 +440,7 @@ sub split_object {
my $current_object = $self->{print}->objects->[$obj_idx];
my $current_copies_num = @{$self->{print}->copies->[$obj_idx]};
my $mesh = $current_object->mesh->clone;
$mesh->scale($Slic3r::scaling_factor);
$mesh->scale(&Slic3r::SCALING_FACTOR);
my @new_meshes = $mesh->split_mesh;
if (@new_meshes == 1) {
@ -517,10 +529,9 @@ sub export_gcode2 {
} if $Slic3r::have_threads;
eval {
# validate configuration
Slic3r::Config->validate;
my $print = $self->{print};
$print->config($self->skeinpanel->config);
$print->config->validate;
$print->validate;
{
@ -607,7 +618,7 @@ sub export_stl {
push @{$mesh->facets}, map [ $_->[0], map $vertices_offset + $_, @$_[-3..-1] ], @{$cloned_mesh->facets};
}
}
$mesh->scale($Slic3r::scaling_factor);
$mesh->scale(&Slic3r::SCALING_FACTOR);
$mesh->align_to_origin;
Slic3r::Format::STL->write_file($output_file, $mesh, 1);
@ -657,14 +668,21 @@ sub recenter {
];
}
sub update_bed_size {
sub on_config_change {
my $self = shift;
my ($opt_key, $value) = @_;
$self->{config}->set($opt_key, $value) if exists $self->{config}{$opt_key};
$self->_update_bed_size;
}
sub _update_bed_size {
my $self = shift;
# supposing the preview canvas is square, calculate the scaling factor
# to constrain print bed area inside preview
my $bed_size = $self->{config}->bed_size;
my $canvas_side = $self->{canvas}->GetSize->GetWidth;
my $bed_largest_side = $Slic3r::bed_size->[X] > $Slic3r::bed_size->[Y]
? $Slic3r::bed_size->[X] : $Slic3r::bed_size->[Y];
my $bed_largest_side = $bed_size->[X] > $bed_size->[Y] ? $bed_size->[X] : $bed_size->[Y];
my $old_scaling_factor = $self->{scaling_factor};
$self->{scaling_factor} = $canvas_side / $bed_largest_side;
if (defined $old_scaling_factor && $self->{scaling_factor} != $old_scaling_factor) {
@ -672,6 +690,7 @@ sub update_bed_size {
}
}
# this is called on the canvas
sub repaint {
my ($self, $event) = @_;
my $parent = $self->GetParent;
@ -681,9 +700,6 @@ sub repaint {
my $size = $self->GetSize;
my @size = ($size->GetWidth, $size->GetHeight);
# calculate scaling factor for preview
$parent->update_bed_size;
# draw grid
$dc->SetPen($parent->{grid_pen});
my $step = 10 * $parent->{scaling_factor};
@ -701,8 +717,8 @@ sub repaint {
$dc->DrawLine(0, $size[Y]/2, $size[X], $size[Y]/2);
$dc->SetTextForeground(Wx::Colour->new(0,0,0));
$dc->SetFont(Wx::Font->new(10, wxDEFAULT, wxNORMAL, wxNORMAL));
$dc->DrawLabel("X = " . $Slic3r::print_center->[X], Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
$dc->DrawRotatedText("Y = " . $Slic3r::print_center->[Y], 0, $size[Y]/2+15, 90);
$dc->DrawLabel("X = " . $parent->{config}->print_center->[X], Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
$dc->DrawRotatedText("Y = " . $parent->{config}->print_center->[Y], 0, $size[Y]/2+15, 90);
}
# draw frame
@ -714,7 +730,7 @@ sub repaint {
if (!@{$print->objects}) {
$dc->SetTextForeground(Wx::Colour->new(150,50,50));
$dc->SetFont(Wx::Font->new(14, wxDEFAULT, wxNORMAL, wxNORMAL));
$dc->DrawLabel("Drag your objects here", Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
$dc->DrawLabel(CANVAS_TEXT, Wx::Rect->new(0, 0, $self->GetSize->GetWidth, $self->GetSize->GetHeight), wxALIGN_CENTER_HORIZONTAL | wxALIGN_CENTER_VERTICAL);
}
# draw thumbnails
@ -738,8 +754,8 @@ sub repaint {
$dc->DrawPolygon($parent->_y($parent->{object_previews}->[-1][2]), 0, 0);
# if sequential printing is enabled and we have more than one object
if ($Slic3r::complete_objects && (map @$_, @{$print->copies}) > 1) {
my $clearance = +($parent->{object_previews}->[-1][2]->offset($Slic3r::extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND))[0];
if ($parent->{config}->complete_objects && (map @$_, @{$print->copies}) > 1) {
my $clearance = +($parent->{object_previews}->[-1][2]->offset($parent->{config}->extruder_clearance_radius / 2 * $parent->{scaling_factor}, 1, JT_ROUND))[0];
$dc->SetPen($parent->{clearance_pen});
$dc->SetBrush($parent->{transparent_brush});
$dc->DrawPolygon($parent->_y($clearance), 0, 0);
@ -748,9 +764,9 @@ sub repaint {
}
# draw skirt
if (@{$parent->{object_previews}} && $Slic3r::skirts) {
if (@{$parent->{object_previews}} && $parent->{config}->skirts) {
my $convex_hull = Slic3r::Polygon->new(convex_hull([ map @{$_->[2]}, @{$parent->{object_previews}} ]));
$convex_hull = +($convex_hull->offset($Slic3r::skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND))[0];
$convex_hull = +($convex_hull->offset($parent->{config}->skirt_distance * $parent->{scaling_factor}, 1, JT_ROUND))[0];
$dc->SetPen($parent->{skirt_pen});
$dc->SetBrush($parent->{transparent_brush});
$dc->DrawPolygon($parent->_y($convex_hull), 0, 0) if $convex_hull;
@ -853,7 +869,7 @@ sub selected_object_idx {
sub statusbar {
my $self = shift;
return $self->GetParent->GetParent->GetParent->{statusbar};
return $self->skeinpanel->GetParent->{statusbar};
}
sub to_pixel {

View file

@ -27,6 +27,10 @@ sub new {
filament => Slic3r::GUI::Tab::Filament->new ($self->{tabpanel}, sync_presets_with => $self->{plater}{preset_choosers}{filament}),
printer => Slic3r::GUI::Tab::Printer->new ($self->{tabpanel}, sync_presets_with => $self->{plater}{preset_choosers}{printer}),
};
# propagate config change events to the plater
$_->{on_value_change} = sub { $self->{plater}->on_config_change(@_) } for values %{$self->{options_tabs}};
$self->{tabpanel}->AddPage($self->{options_tabs}{print}, $self->{options_tabs}{print}->title);
$self->{tabpanel}->AddPage($self->{options_tabs}{filament}, $self->{options_tabs}{filament}->title);
$self->{tabpanel}->AddPage($self->{options_tabs}{printer}, $self->{options_tabs}{printer}->title);
@ -53,11 +57,12 @@ sub do_slice {
my $process_dialog;
eval {
# validate configuration
Slic3r::Config->validate;
my $config = $self->config;
$config->validate;
# confirm slicing of more than one copies
my $copies = $Slic3r::duplicate_grid->[X] * $Slic3r::duplicate_grid->[Y];
$copies = $Slic3r::duplicate if $Slic3r::duplicate > 1;
my $copies = $Slic3r::Config->duplicate_grid->[X] * $Slic3r::Config->duplicate_grid->[Y];
$copies = $Slic3r::Config->duplicate if $Slic3r::Config->duplicate > 1;
if ($copies > 1) {
my $confirmation = Wx::MessageDialog->new($self, "Are you sure you want to slice $copies copies?",
'Multiple Copies', wxICON_QUESTION | wxOK | wxCANCEL);
@ -93,7 +98,7 @@ sub do_slice {
my $input_file_basename = basename($input_file);
$last_skein_dir = dirname($input_file);
my $print = Slic3r::Print->new;
my $print = Slic3r::Print->new(config => $config);
$print->add_object_from_file($input_file);
$print->validate;
@ -160,12 +165,12 @@ sub do_slice {
sub save_config {
my $self = shift;
my $process_dialog;
my $config = $self->config;
eval {
# validate configuration
Slic3r::Config->validate;
$config->validate;
};
Slic3r::GUI::catch_error($self, sub { $process_dialog->Destroy if $process_dialog }) and return;
Slic3r::GUI::catch_error($self) and return;
my $dir = $last_config ? dirname($last_config) : $last_config_dir || $last_skein_dir || "";
my $filename = $last_config ? basename($last_config) : "config.ini";
@ -175,12 +180,12 @@ sub save_config {
my $file = $dlg->GetPath;
$last_config_dir = dirname($file);
$last_config = $file;
Slic3r::Config->save($file);
$config->save($file);
}
$dlg->Destroy;
}
sub load_config {
sub load_config_file {
my $self = shift;
my ($file) = @_;
@ -198,15 +203,40 @@ sub load_config {
$_->load_external_config($file) for values %{$self->{options_tabs}};
}
sub load_config {
my $self = shift;
my ($config) = @_;
foreach my $tab (values %{$self->{options_tabs}}) {
$tab->set_value($_, $config->$_) for keys %$config;
}
}
sub config_wizard {
my $self = shift;
return unless $self->check_unsaved_changes;
if (my %settings = Slic3r::GUI::ConfigWizard->new($self)->run) {
$self->set_value($_, $settings{$_}) for keys %settings;
if (my $config = Slic3r::GUI::ConfigWizard->new($self)->run) {
# TODO: select the default preset in all tabs
$self->load_config($config);
}
}
=head2 config
This method collects all config values from the tabs and merges them into a single config object.
=cut
sub config {
my $self = shift;
return Slic3r::Config->merge(
Slic3r::Config->new_from_defaults,
(map $_->config, values %{$self->{options_tabs}}),
);
}
sub set_value {
my $self = shift;
my ($opt_key, $value) = @_;

View file

@ -13,6 +13,7 @@ sub new {
my $class = shift;
my ($parent, %params) = @_;
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
$self->{options} = []; # array of option names handled by this tab
$self->{sync_presets_with} = $params{sync_presets_with};
EVT_CHOICE($parent, $self->{sync_presets_with}, sub {
@ -100,8 +101,8 @@ sub new {
);
return unless $dlg->ShowModal == wxID_OK;
my $file = sprintf "$Slic3r::GUI::datadir/$self->{presets_group}/%s.ini", $dlg->get_name;
Slic3r::Config->save($file, $self->{presets_group});
my $file = sprintf "$Slic3r::GUI::datadir/%s/%s.ini", $self->name, $dlg->get_name;
$self->{config}->save($file);
$self->set_dirty(0);
$self->load_presets;
$self->{presets_choice}->SetSelection(first { basename($self->{presets}[$_]{file}) eq $dlg->get_name . ".ini" } 1 .. $#{$self->{presets}});
@ -125,7 +126,13 @@ sub new {
$self->sync_presets;
});
$self->{config} = Slic3r::Config->new;
$self->build;
if ($self->hidden_options) {
$self->{config}->apply(Slic3r::Config->new_from_defaults($self->hidden_options));
push @{$self->{options}}, $self->hidden_options;
}
$self->load_presets;
return $self;
}
@ -135,8 +142,15 @@ sub current_preset {
return $self->{presets}[ $self->{presets_choice}->GetSelection ];
}
sub on_value_change {}
# propagate event to the parent
sub on_value_change {
my $self = shift;
$self->{on_value_change}->(@_) if $self->{on_value_change};
}
sub on_preset_loaded {}
sub hidden_options {}
sub config { $_[0]->{config}->clone }
sub on_select_preset {
my $self = shift;
@ -155,7 +169,7 @@ sub on_select_preset {
my $preset = $self->current_preset;
if ($preset->{default}) {
# default settings: disable the delete button
Slic3r::Config->load_hash($Slic3r::Defaults, $self->{presets_group}, 1);
$self->{config}->apply(Slic3r::Config->new_from_defaults(@{$self->{options}}));
$self->{btn_delete_preset}->Disable;
} else {
if (!-e $preset->{file}) {
@ -164,7 +178,7 @@ sub on_select_preset {
}
eval {
local $SIG{__WARN__} = Slic3r::GUI::warning_catcher($self);
Slic3r::Config->load($preset->{file}, $self->{presets_group});
$self->{config}->apply(Slic3r::Config->load($preset->{file}));
};
Slic3r::GUI::catch_error($self);
$preset->{external}
@ -174,8 +188,8 @@ sub on_select_preset {
$self->on_preset_loaded;
$self->reload_values;
$self->set_dirty(0);
$Slic3r::Settings->{presets}{$self->{presets_group}} = $preset->{file} ? basename($preset->{file}) : '';
Slic3r::Config->save_settings("$Slic3r::GUI::datadir/slic3r.ini");
$Slic3r::GUI::Settings->{presets}{$self->name} = $preset->{file} ? basename($preset->{file}) : '';
Slic3r::GUI->save_settings("$Slic3r::GUI::datadir/slic3r.ini");
}
sub add_options_page {
@ -188,6 +202,19 @@ sub add_options_page {
$self->{iconcount}++;
}
{
# get all config options being added to the current page; remove indexes; associate defaults
my @options = map { $_ =~ s/#.+//; $_ } grep !ref($_), map @{$_->{options}}, @{$params{optgroups}};
my %defaults_to_set = map { $_ => 1 } @options;
# apply default values for the options we don't have already
delete $defaults_to_set{$_} for @{$self->{options}};
$self->{config}->apply(Slic3r::Config->new_from_defaults(keys %defaults_to_set)) if %defaults_to_set;
# append such options to our list
push @{$self->{options}}, @options;
}
my $page = Slic3r::GUI::Tab::Page->new($self, $title, $self->{iconcount}, %params, on_change => sub {
$self->on_value_change(@_);
$self->set_dirty(1);
@ -214,8 +241,7 @@ sub set_value {
sub reload_values {
my $self = shift;
my $current = Slic3r::Config->current;
$self->set_value($_, $current->{$_}) for keys %$current;
$self->set_value($_, $self->{config}->get($_)) for keys %{$self->{config}};
}
sub update_tree {
@ -262,20 +288,18 @@ sub is_dirty {
sub load_presets {
my $self = shift;
my ($group) = @_;
$self->{presets_group} ||= $group;
$self->{presets} = [{
default => 1,
name => '- default -',
}];
opendir my $dh, "$Slic3r::GUI::datadir/$self->{presets_group}" or die "Failed to read directory $Slic3r::GUI::datadir/$self->{presets_group} (errno: $!)\n";
opendir my $dh, "$Slic3r::GUI::datadir/" . $self->name or die "Failed to read directory $Slic3r::GUI::datadir/" . $self->name . " (errno: $!)\n";
foreach my $file (sort grep /\.ini$/i, readdir $dh) {
my $name = basename($file);
$name =~ s/\.ini$//;
push @{$self->{presets}}, {
file => "$Slic3r::GUI::datadir/$self->{presets_group}/$file",
file => "$Slic3r::GUI::datadir/" . $self->name . "/$file",
name => $name,
};
}
@ -285,7 +309,7 @@ sub load_presets {
$self->{presets_choice}->Append($_->{name}) for @{$self->{presets}};
{
# load last used preset
my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::Settings->{presets}{$self->{presets_group}} || '') } 1 .. $#{$self->{presets}};
my $i = first { basename($self->{presets}[$_]{file}) eq ($Slic3r::GUI::Settings->{presets}{$self->name} || '') } 1 .. $#{$self->{presets}};
$self->{presets_choice}->SetSelection($i || 0);
$self->on_select_preset;
}
@ -326,6 +350,7 @@ sub sync_presets {
package Slic3r::GUI::Tab::Print;
use base 'Slic3r::GUI::Tab';
sub name { 'print' }
sub title { 'Print Settings' }
sub build {
@ -422,16 +447,17 @@ sub build {
},
{
title => 'Other',
options => [qw(duplicate_distance), ($Slic3r::have_threads ? qw(threads) : ())],
options => [($Slic3r::have_threads ? qw(threads) : ())],
},
]);
$self->load_presets('print');
}
sub hidden_options { !$Slic3r::have_threads ? qw(threads) : () }
package Slic3r::GUI::Tab::Filament;
use base 'Slic3r::GUI::Tab';
sub name { 'filament' }
sub title { 'Filament Settings' }
sub build {
@ -463,13 +489,12 @@ sub build {
options => [qw(fan_below_layer_time slowdown_below_layer_time min_print_speed)],
},
]);
$self->load_presets('filament');
}
package Slic3r::GUI::Tab::Printer;
use base 'Slic3r::GUI::Tab';
sub name { 'printer' }
sub title { 'Printer Settings' }
sub build {
@ -521,22 +546,28 @@ sub build {
]);
$self->{extruder_pages} = [];
$self->build_extruder_pages;
$self->load_presets('printer');
$self->_build_extruder_pages;
}
sub extruder_options { qw(nozzle_diameter) }
sub _extruder_options { qw(nozzle_diameter) }
sub build_extruder_pages {
sub config {
my $self = shift;
my $config = $self->SUPER::config(@_);
# remove all unused values
foreach my $opt_key ($self->_extruder_options) {
splice @{ $config->{$opt_key} }, $self->{extruders_count};
}
return $config;
}
sub _build_extruder_pages {
my $self = shift;
foreach my $extruder_idx (0 .. $self->{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 => [
{
@ -571,28 +602,22 @@ sub on_value_change {
$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, $self->{extruders_count} if $self->{extruders_count} <= $#$values;
}
# add extra pages
$self->build_extruder_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
# this gets executed after preset is loaded and before GUI fields are updated
sub on_preset_loaded {
my $self = shift;
# update the extruders count field
{
# update the GUI field according to the number of nozzle diameters supplied
$self->set_value('extruders_count', scalar @{ Slic3r::Config->get_raw('nozzle_diameter') });
$self->set_value('extruders_count', scalar @{ $self->{config}->nozzle_diameter });
# update extruder page list
$self->on_value_change('extruders_count');
@ -617,7 +642,11 @@ sub new {
$self->SetSizer($self->{vsizer});
if ($params{optgroups}) {
$self->append_optgroup(%$_, on_change => $params{on_change}) for @{$params{optgroups}};
$self->append_optgroup(
%$_,
config => $parent->{config},
on_change => $params{on_change},
) for @{$params{optgroups}};
}
return $self;
@ -627,7 +656,12 @@ sub append_optgroup {
my $self = shift;
my %params = @_;
my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(parent => $self, label_width => 200, %params);
my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
parent => $self,
config => $self->GetParent->{config},
label_width => 200,
%params,
);
$self->{vsizer}->Add($optgroup->sizer, 0, wxEXPAND | wxALL, 5);
push @{$self->{optgroups}}, $optgroup;
}