Refactored OptionsGroup class for cleaner OOP model and cleaner event model
This commit is contained in:
parent
85c59d78ac
commit
04b67f0cb0
12 changed files with 1609 additions and 1175 deletions
|
@ -23,73 +23,66 @@ sub new {
|
|||
keep_lower => 1,
|
||||
rotate_lower => 1,
|
||||
};
|
||||
my $cut_button_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
{
|
||||
$self->{btn_cut} = Wx::Button->new($self, -1, "Perform cut", wxDefaultPosition, wxDefaultSize);
|
||||
$cut_button_sizer->Add($self->{btn_cut}, 0, wxALIGN_RIGHT | wxALL, 10);
|
||||
}
|
||||
my $optgroup = Slic3r::GUI::OptionsGroup->new(
|
||||
parent => $self,
|
||||
title => 'Cut',
|
||||
options => [
|
||||
{
|
||||
opt_key => 'z',
|
||||
type => 'slider',
|
||||
label => 'Z',
|
||||
default => $self->{cut_options}{z},
|
||||
min => 0,
|
||||
max => $self->{model_object}->bounding_box->size->z,
|
||||
},
|
||||
{
|
||||
opt_key => 'keep_upper',
|
||||
type => 'bool',
|
||||
label => 'Upper part',
|
||||
default => $self->{cut_options}{keep_upper},
|
||||
},
|
||||
{
|
||||
opt_key => 'keep_lower',
|
||||
type => 'bool',
|
||||
label => 'Lower part',
|
||||
default => $self->{cut_options}{keep_lower},
|
||||
},
|
||||
{
|
||||
opt_key => 'rotate_lower',
|
||||
type => 'bool',
|
||||
label => '',
|
||||
tooltip => 'If enabled, the lower part will be rotated by 180° so that the flat cut surface lies on the print bed.',
|
||||
default => $self->{cut_options}{rotate_lower},
|
||||
},
|
||||
],
|
||||
lines => [
|
||||
{
|
||||
label => 'Z',
|
||||
options => [qw(z)],
|
||||
},
|
||||
{
|
||||
label => 'Keep',
|
||||
options => [qw(keep_upper keep_lower)],
|
||||
},
|
||||
{
|
||||
label => 'Rotate lower part',
|
||||
options => [qw(rotate_lower)],
|
||||
},
|
||||
{
|
||||
sizer => $cut_button_sizer,
|
||||
},
|
||||
],
|
||||
on_change => sub {
|
||||
my ($opt_key, $value) = @_;
|
||||
|
||||
my $optgroup;
|
||||
$optgroup = Slic3r::GUI::OptionsGroup->new(
|
||||
parent => $self,
|
||||
title => 'Cut',
|
||||
on_change => sub {
|
||||
my ($opt_id) = @_;
|
||||
|
||||
$self->{cut_options}{$opt_key} = $value;
|
||||
if ($opt_key eq 'z') {
|
||||
my $value = $optgroup->get_value($opt_id);
|
||||
$self->{cut_options}{$opt_id} = $value;
|
||||
if ($opt_id eq 'z') {
|
||||
if ($self->{canvas}) {
|
||||
$self->{canvas}->SetCuttingPlane($value);
|
||||
$self->{canvas}->Render;
|
||||
}
|
||||
}
|
||||
},
|
||||
label_width => 120,
|
||||
label_width => 120,
|
||||
);
|
||||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||
opt_id => 'z',
|
||||
type => 'slider',
|
||||
label => 'Z',
|
||||
default => $self->{cut_options}{z},
|
||||
min => 0,
|
||||
max => $self->{model_object}->bounding_box->size->z,
|
||||
));
|
||||
{
|
||||
my $line = Slic3r::GUI::OptionsGroup::Line->new(
|
||||
label => 'Keep',
|
||||
);
|
||||
$line->append_option(Slic3r::GUI::OptionsGroup::Option->new(
|
||||
opt_id => 'keep_upper',
|
||||
type => 'bool',
|
||||
label => 'Upper part',
|
||||
default => $self->{cut_options}{keep_upper},
|
||||
));
|
||||
$line->append_option(Slic3r::GUI::OptionsGroup::Option->new(
|
||||
opt_id => 'keep_lower',
|
||||
type => 'bool',
|
||||
label => 'Lower part',
|
||||
default => $self->{cut_options}{keep_lower},
|
||||
));
|
||||
$optgroup->append_line($line);
|
||||
}
|
||||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||
opt_id => 'rotate_lower',
|
||||
label => 'Rotate lower part upwards',
|
||||
type => 'bool',
|
||||
tooltip => 'If enabled, the lower part will be rotated by 180° so that the flat cut surface lies on the print bed.',
|
||||
default => $self->{cut_options}{rotate_lower},
|
||||
));
|
||||
{
|
||||
my $cut_button_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
$self->{btn_cut} = Wx::Button->new($self, -1, "Perform cut", wxDefaultPosition, wxDefaultSize);
|
||||
$cut_button_sizer->Add($self->{btn_cut}, 0, wxALIGN_RIGHT | wxALL, 10);
|
||||
$optgroup->append_line(Slic3r::GUI::OptionsGroup::Line->new(
|
||||
sizer => $cut_button_sizer,
|
||||
));
|
||||
}
|
||||
|
||||
# left pane with tree
|
||||
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
||||
|
|
|
@ -38,7 +38,7 @@ sub new {
|
|||
my $id = &Wx::NewId();
|
||||
$menu->Append($id, $self->{option_labels}{$opt_key});
|
||||
EVT_MENU($menu, $id, sub {
|
||||
$self->{config}->apply($self->{default_config}->get($opt_key));
|
||||
$self->{config}->set($opt_key, $self->{default_config}->get($opt_key));
|
||||
$self->update_optgroup;
|
||||
$self->{on_change}->() if $self->{on_change};
|
||||
});
|
||||
|
@ -102,18 +102,18 @@ sub update_optgroup {
|
|||
}
|
||||
foreach my $category (sort keys %categories) {
|
||||
my $optgroup = Slic3r::GUI::ConfigOptionsGroup->new(
|
||||
parent => $self,
|
||||
title => $category,
|
||||
config => $self->{config},
|
||||
options => [ sort @{$categories{$category}} ],
|
||||
full_labels => 1,
|
||||
label_font => $Slic3r::GUI::small_font,
|
||||
sidetest_font => $Slic3r::GUI::small_font,
|
||||
label_width => 120,
|
||||
on_change => sub { $self->{on_change}->() if $self->{on_change} },
|
||||
extra_column => sub {
|
||||
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 {
|
||||
my ($line) = @_;
|
||||
my ($opt_key) = @{$line->{options}}; # we assume that we have one option per line
|
||||
|
||||
my $opt_key = $line->get_options->[0]->opt_id; # we assume that we have one option per line
|
||||
|
||||
# disallow deleting fixed options
|
||||
return undef if $self->{fixed_options}{$opt_key};
|
||||
|
@ -128,6 +128,9 @@ sub update_optgroup {
|
|||
return $btn;
|
||||
},
|
||||
);
|
||||
foreach my $opt_key (sort @{$categories{$category}}) {
|
||||
$optgroup->append_single_option_line($opt_key);
|
||||
}
|
||||
$self->{options_sizer}->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM, 0);
|
||||
}
|
||||
$self->Layout;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue