2016-09-14 09:22:41 +00:00
|
|
|
# Included in ObjectSettingsDialog -> ObjectPartsPanel.
|
|
|
|
# Maintains, displays, adds and removes overrides of slicing parameters for an object and its modifier mesh.
|
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
package Slic3r::GUI::Plater::OverrideSettingsPanel;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
2014-03-23 14:18:08 +00:00
|
|
|
use List::Util qw(first);
|
2014-06-14 17:59:59 +00:00
|
|
|
use Wx qw(:misc :sizer :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG
|
|
|
|
wxTheApp);
|
2014-03-23 12:46:05 +00:00
|
|
|
use Wx::Event qw(EVT_BUTTON EVT_LEFT_DOWN EVT_MENU);
|
2014-02-14 21:24:30 +00:00
|
|
|
use base 'Wx::ScrolledWindow';
|
|
|
|
|
|
|
|
use constant ICON_MATERIAL => 0;
|
|
|
|
use constant ICON_SOLIDMESH => 1;
|
|
|
|
use constant ICON_MODIFIERMESH => 2;
|
|
|
|
|
2017-08-04 14:28:01 +00:00
|
|
|
my %icons = (
|
|
|
|
'Advanced' => 'wand.png',
|
|
|
|
'Extruders' => 'funnel.png',
|
|
|
|
'Extrusion Width' => 'funnel.png',
|
|
|
|
'Infill' => 'infill.png',
|
|
|
|
'Layers and Perimeters' => 'layers.png',
|
|
|
|
'Skirt and brim' => 'box.png',
|
|
|
|
'Speed' => 'time.png',
|
|
|
|
'Speed > Acceleration' => 'time.png',
|
|
|
|
'Support material' => 'building.png',
|
|
|
|
);
|
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
|
|
|
my ($parent, %params) = @_;
|
|
|
|
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
2017-02-07 17:28:53 +00:00
|
|
|
# C++ class Slic3r::DynamicPrintConfig, initially empty.
|
2014-06-19 18:07:16 +00:00
|
|
|
$self->{default_config} = Slic3r::Config->new;
|
|
|
|
$self->{config} = Slic3r::Config->new;
|
2017-02-07 17:28:53 +00:00
|
|
|
# On change callback.
|
2014-03-23 15:45:55 +00:00
|
|
|
$self->{on_change} = $params{on_change};
|
2014-06-19 18:07:16 +00:00
|
|
|
$self->{fixed_options} = {};
|
2014-02-14 21:24:30 +00:00
|
|
|
|
|
|
|
$self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
|
|
|
|
2014-03-23 14:18:08 +00:00
|
|
|
$self->{options_sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
|
|
|
$self->{sizer}->Add($self->{options_sizer}, 0, wxEXPAND | wxALL, 0);
|
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
# option selector
|
|
|
|
{
|
|
|
|
# create the button
|
2016-04-09 17:10:57 +00:00
|
|
|
my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("add.png"), wxBITMAP_TYPE_PNG),
|
2014-03-23 14:18:08 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE);
|
2014-03-23 12:46:05 +00:00
|
|
|
EVT_LEFT_DOWN($btn, sub {
|
|
|
|
my $menu = Wx::Menu->new;
|
2017-08-04 14:28:01 +00:00
|
|
|
# create category submenus
|
|
|
|
my %categories = (); # category => submenu
|
2014-03-23 12:46:05 +00:00
|
|
|
foreach my $opt_key (@{$self->{options}}) {
|
2017-08-04 14:28:01 +00:00
|
|
|
if (my $cat = $Slic3r::Config::Options->{$opt_key}{category}) {
|
|
|
|
$categories{$cat} //= Wx::Menu->new;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
# append submenus to main menu
|
|
|
|
my @categories = ('Layers and Perimeters', 'Infill', 'Support material', 'Speed', 'Extruders', 'Extrusion Width', 'Advanced');
|
|
|
|
#foreach my $cat (sort keys %categories) {
|
|
|
|
foreach my $cat (@categories) {
|
|
|
|
wxTheApp->append_submenu($menu, $cat, "", $categories{$cat}, undef, $icons{$cat});
|
|
|
|
}
|
|
|
|
# append options to submenus
|
|
|
|
foreach my $opt_key (@{$self->{options}}) {
|
|
|
|
my $cat = $Slic3r::Config::Options->{$opt_key}{category} or next;
|
|
|
|
my $cb = sub {
|
2014-07-01 14:40:56 +00:00
|
|
|
$self->{config}->set($opt_key, $self->{default_config}->get($opt_key));
|
2014-03-23 12:46:05 +00:00
|
|
|
$self->update_optgroup;
|
2017-08-04 14:28:01 +00:00
|
|
|
$self->{on_change}->($opt_key) if $self->{on_change};
|
|
|
|
};
|
|
|
|
wxTheApp->append_menu_item($categories{$cat}, $self->{option_labels}{$opt_key},
|
|
|
|
$Slic3r::Config::Options->{$opt_key}{tooltip}, $cb);
|
2014-03-23 12:46:05 +00:00
|
|
|
}
|
|
|
|
$self->PopupMenu($menu, $btn->GetPosition);
|
|
|
|
$menu->Destroy;
|
2014-02-14 21:24:30 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
2014-03-23 14:18:08 +00:00
|
|
|
$h_sizer->Add($btn, 0, wxALL, 0);
|
2014-02-14 21:24:30 +00:00
|
|
|
$self->{sizer}->Add($h_sizer, 0, wxEXPAND | wxBOTTOM, 10);
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->SetSizer($self->{sizer});
|
|
|
|
$self->SetScrollbars(0, 1, 0, 1);
|
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
$self->set_opt_keys($params{opt_keys}) if $params{opt_keys};
|
2014-02-14 21:24:30 +00:00
|
|
|
$self->update_optgroup;
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
2014-06-19 18:07:16 +00:00
|
|
|
sub set_default_config {
|
|
|
|
my ($self, $config) = @_;
|
|
|
|
$self->{default_config} = $config;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_config {
|
|
|
|
my ($self, $config) = @_;
|
|
|
|
$self->{config} = $config;
|
|
|
|
$self->update_optgroup;
|
|
|
|
}
|
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
sub set_opt_keys {
|
|
|
|
my ($self, $opt_keys) = @_;
|
|
|
|
# sort options by category+label
|
2017-08-04 14:28:01 +00:00
|
|
|
$self->{option_labels} = { map { $_ => $Slic3r::Config::Options->{$_}{full_label} // $Slic3r::Config::Options->{$_}{label} } @$opt_keys };
|
2014-03-23 12:46:05 +00:00
|
|
|
$self->{options} = [ sort { $self->{option_labels}{$a} cmp $self->{option_labels}{$b} } @$opt_keys ];
|
2014-03-22 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
2014-06-19 18:07:16 +00:00
|
|
|
sub set_fixed_options {
|
|
|
|
my ($self, $opt_keys) = @_;
|
|
|
|
$self->{fixed_options} = { map {$_ => 1} @$opt_keys };
|
2014-02-14 23:36:52 +00:00
|
|
|
$self->update_optgroup;
|
2014-02-14 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub update_optgroup {
|
|
|
|
my $self = shift;
|
|
|
|
|
|
|
|
$self->{options_sizer}->Clear(1);
|
|
|
|
return if !defined $self->{config};
|
|
|
|
|
|
|
|
my %categories = ();
|
|
|
|
foreach my $opt_key (@{$self->{config}->get_keys}) {
|
|
|
|
my $category = $Slic3r::Config::Options->{$opt_key}{category};
|
|
|
|
$categories{$category} ||= [];
|
|
|
|
push @{$categories{$category}}, $opt_key;
|
|
|
|
}
|
|
|
|
foreach my $category (sort keys %categories) {
|
|
|
|
my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
|
2014-07-01 14:40:56 +00:00
|
|
|
parent => $self,
|
|
|
|
title => $category,
|
|
|
|
config => $self->{config},
|
|
|
|
full_labels => 1,
|
|
|
|
label_font => $Slic3r::GUI::small_font,
|
|
|
|
sidetext_font => $Slic3r::GUI::small_font,
|
|
|
|
label_width => 120,
|
|
|
|
on_change => sub { $self->{on_change}->() if $self->{on_change} },
|
|
|
|
extra_column => sub {
|
2014-02-14 21:24:30 +00:00
|
|
|
my ($line) = @_;
|
2014-07-01 14:40:56 +00:00
|
|
|
|
|
|
|
my $opt_key = $line->get_options->[0]->opt_id; # we assume that we have one option per line
|
2014-03-23 14:18:08 +00:00
|
|
|
|
2014-06-19 18:07:16 +00:00
|
|
|
# disallow deleting fixed options
|
|
|
|
return undef if $self->{fixed_options}{$opt_key};
|
2014-03-23 14:18:08 +00:00
|
|
|
|
2016-04-09 17:10:57 +00:00
|
|
|
my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new($Slic3r::var->("delete.png"), wxBITMAP_TYPE_PNG),
|
2014-03-23 14:18:08 +00:00
|
|
|
wxDefaultPosition, wxDefaultSize, Wx::wxBORDER_NONE);
|
2014-02-14 21:24:30 +00:00
|
|
|
EVT_BUTTON($self, $btn, sub {
|
|
|
|
$self->{config}->erase($opt_key);
|
2014-03-23 15:45:55 +00:00
|
|
|
$self->{on_change}->() if $self->{on_change};
|
2014-06-14 17:59:59 +00:00
|
|
|
wxTheApp->CallAfter(sub { $self->update_optgroup });
|
2014-02-14 21:24:30 +00:00
|
|
|
});
|
|
|
|
return $btn;
|
|
|
|
},
|
|
|
|
);
|
2014-07-01 14:40:56 +00:00
|
|
|
foreach my $opt_key (sort @{$categories{$category}}) {
|
|
|
|
$optgroup->append_single_option_line($opt_key);
|
|
|
|
}
|
2014-03-23 14:18:08 +00:00
|
|
|
$self->{options_sizer}->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM, 0);
|
2014-02-14 21:24:30 +00:00
|
|
|
}
|
2015-12-05 22:14:13 +00:00
|
|
|
$self->GetParent->Layout; # we need this for showing scrollbars
|
2014-02-14 21:24:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-21 21:15:33 +00:00
|
|
|
# work around a wxMAC bug causing controls not being disabled when calling Disable() on a Window
|
|
|
|
sub enable {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->{btn_add}->Enable;
|
|
|
|
$self->Enable;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub disable {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->{btn_add}->Disable;
|
|
|
|
$self->Disable;
|
|
|
|
}
|
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
1;
|