From f71ac8cd6583edac6aba9aa703e400837d3bb80b Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sat, 22 Mar 2014 17:41:14 +0100 Subject: [PATCH] Merge the Object Settings tab into the Parts tab --- lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm | 77 +++++++++++++----- lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm | 53 +----------- .../GUI/Plater/OverrideSettingsPanel.pm | 18 ++-- var/brick.png | Bin 0 -> 452 bytes 4 files changed, 71 insertions(+), 77 deletions(-) create mode 100755 var/brick.png diff --git a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm index 2ba7e41ab..46500146a 100644 --- a/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm +++ b/lib/Slic3r/GUI/Plater/ObjectPartsPanel.pm @@ -8,8 +8,9 @@ use Wx qw(:misc :sizer :treectrl :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMA use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED); use base 'Wx::Panel'; -use constant ICON_SOLIDMESH => 0; -use constant ICON_MODIFIERMESH => 1; +use constant ICON_OBJECT => 0; +use constant ICON_SOLIDMESH => 1; +use constant ICON_MODIFIERMESH => 2; sub new { my $class = shift; @@ -20,15 +21,17 @@ sub new { # create TreeCtrl my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [300, 100], - wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT | wxTR_HIDE_ROOT - | wxTR_MULTIPLE | wxTR_NO_BUTTONS | wxTR_NO_LINES); + wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT + | wxTR_SINGLE | wxTR_NO_BUTTONS); { $self->{tree_icons} = Wx::ImageList->new(16, 16, 1); $tree->AssignImageList($self->{tree_icons}); + $self->{tree_icons}->Add(Wx::Bitmap->new("$Slic3r::var/brick.png", wxBITMAP_TYPE_PNG)); # ICON_OBJECT $self->{tree_icons}->Add(Wx::Bitmap->new("$Slic3r::var/package.png", wxBITMAP_TYPE_PNG)); # ICON_SOLIDMESH $self->{tree_icons}->Add(Wx::Bitmap->new("$Slic3r::var/plugin.png", wxBITMAP_TYPE_PNG)); # ICON_MODIFIERMESH - $tree->AddRoot(""); + my $rootId = $tree->AddRoot("Object", ICON_OBJECT); + $tree->SetPlData($rootId, { type => 'object' }); } # buttons @@ -51,11 +54,8 @@ sub new { $self->{btn_delete}->SetFont($Slic3r::GUI::small_font); # part settings panel - $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new( - $self, - opt_keys => Slic3r::Config::PrintRegion->new->get_keys, - ); - my $settings_sizer = Wx::StaticBoxSizer->new(Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL); + $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self); + my $settings_sizer = Wx::StaticBoxSizer->new($self->{staticbox} = Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL); $settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0); # left pane with tree @@ -120,6 +120,7 @@ sub reload_tree { volume_id => $volume_id, }); } + $tree->ExpandAll; $self->selection_changed; } @@ -147,18 +148,36 @@ sub selection_changed { $self->{settings_panel}->disable; $self->{settings_panel}->set_config(undef); - my $itemData = $self->get_selection; - if ($itemData && $itemData->{type} eq 'volume') { - if ($self->{canvas}) { - $self->{canvas}->volumes->[ $itemData->{volume_id} ]{selected} = 1; + if (my $itemData = $self->get_selection) { + if ($itemData->{type} eq 'volume') { + # select volume in 3D preview + if ($self->{canvas}) { + $self->{canvas}->volumes->[ $itemData->{volume_id} ]{selected} = 1; + } + $self->{btn_delete}->Enable; + + # attach volume material config to settings panel + my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ]; + my $material = $self->{model_object}->model->materials->{ $volume->material_id // '_' }; + $material //= $volume->assign_unique_material; + $self->{staticbox}->SetLabel('Part Settings'); + $self->{settings_panel}->enable; + $self->{settings_panel}->set_opt_keys(Slic3r::Config::PrintRegion->new->get_keys); + $self->{settings_panel}->set_config($material->config); + } elsif ($itemData->{type} eq 'object') { + # select all object volumes in 3D preview + if ($self->{canvas}) { + $_->{selected} = 1 for @{$self->{canvas}->volumes}; + } + + # attach object config to settings panel + $self->{staticbox}->SetLabel('Object Settings'); + $self->{settings_panel}->enable; + $self->{settings_panel}->set_opt_keys( + [ map @{$_->get_keys}, Slic3r::Config::PrintObject->new, Slic3r::Config::PrintRegion->new ] + ); + $self->{settings_panel}->set_config($self->{model_object}->config); } - $self->{btn_delete}->Enable; - - my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ]; - my $material = $self->{model_object}->model->materials->{ $volume->material_id // '_' }; - $material //= $volume->assign_unique_material; - $self->{settings_panel}->enable; - $self->{settings_panel}->set_config($material->config); } $self->{canvas}->Render if $self->{canvas}; @@ -219,4 +238,20 @@ sub on_btn_delete { } } +sub CanClose { + my $self = shift; + + return 1; # skip validation for now + + # validate options before allowing user to dismiss the dialog + # the validate method only works on full configs so we have + # to merge our settings with the default ones + my $config = Slic3r::Config->merge($self->GetParent->GetParent->GetParent->GetParent->GetParent->config, $self->model_object->config); + eval { + $config->validate; + }; + return 0 if Slic3r::GUI::catch_error($self); + return 1; +} + 1; diff --git a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm index 8f39b2b1a..661dfb92e 100644 --- a/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm +++ b/lib/Slic3r/GUI/Plater/ObjectSettingsDialog.pm @@ -14,14 +14,13 @@ sub new { $self->{$_} = $params{$_} for keys %params; $self->{tabpanel} = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL); - $self->{tabpanel}->AddPage($self->{settings} = Slic3r::GUI::Plater::ObjectDialog::SettingsTab->new($self->{tabpanel}), "Settings"); - $self->{tabpanel}->AddPage($self->{layers} = Slic3r::GUI::Plater::ObjectDialog::LayersTab->new($self->{tabpanel}), "Layers"); $self->{tabpanel}->AddPage($self->{parts} = Slic3r::GUI::Plater::ObjectPartsPanel->new($self->{tabpanel}, model_object => $params{model_object}), "Parts"); + $self->{tabpanel}->AddPage($self->{layers} = Slic3r::GUI::Plater::ObjectDialog::LayersTab->new($self->{tabpanel}), "Layers"); my $buttons = $self->CreateStdDialogButtonSizer(wxOK); EVT_BUTTON($self, wxID_OK, sub { # validate user input - return if !$self->{settings}->CanClose; + return if !$self->{parts}->CanClose; return if !$self->{layers}->CanClose; # notify tabs @@ -49,54 +48,6 @@ sub model_object { return $self->GetParent->GetParent->{model_object}; } -package Slic3r::GUI::Plater::ObjectDialog::SettingsTab; -use Wx qw(:dialog :id :misc :sizer :systemsettings :button :icon); -use Wx::Grid; -use Wx::Event qw(EVT_BUTTON); -use base 'Slic3r::GUI::Plater::ObjectDialog::BaseTab'; - -sub new { - my $class = shift; - my ($parent, %params) = @_; - my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize); - - $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL); - - # descriptive text - { - my $label = Wx::StaticText->new($self, -1, "You can use this section to override some settings just for this object.", - wxDefaultPosition, [-1, 25]); - $label->SetFont(Wx::SystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); - $self->{sizer}->Add($label, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10); - } - - $self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new( - $self, - config => $self->model_object->config, - opt_keys => [ map @{$_->get_keys}, Slic3r::Config::PrintObject->new, Slic3r::Config::PrintRegion->new ], - ); - $self->{sizer}->Add($self->{settings_panel}, 1, wxEXPAND | wxLEFT | wxRIGHT, 10); - - $self->SetSizer($self->{sizer}); - $self->{sizer}->SetSizeHints($self); - - return $self; -} - -sub CanClose { - my $self = shift; - - # validate options before allowing user to dismiss the dialog - # the validate method only works on full configs so we have - # to merge our settings with the default ones - my $config = Slic3r::Config->merge($self->GetParent->GetParent->GetParent->GetParent->GetParent->config, $self->model_object->config); - eval { - $config->validate; - }; - return 0 if Slic3r::GUI::catch_error($self); - return 1; -} - package Slic3r::GUI::Plater::ObjectDialog::LayersTab; use Wx qw(:dialog :id :misc :sizer :systemsettings); use Wx::Grid; diff --git a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm index 8518b8320..3e392d944 100644 --- a/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm +++ b/lib/Slic3r/GUI/Plater/OverrideSettingsPanel.pm @@ -17,16 +17,12 @@ sub new { my ($parent, %params) = @_; my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); $self->{config} = $params{config}; # may be passed as undef - my @opt_keys = @{$params{opt_keys}}; $self->{sizer} = Wx::BoxSizer->new(wxVERTICAL); # option selector { - # get all options with object scope and sort them by category+label - my %settings = map { $_ => sprintf('%s > %s', $Slic3r::Config::Options->{$_}{category}, $Slic3r::Config::Options->{$_}{full_label} // $Slic3r::Config::Options->{$_}{label}) } @opt_keys; - $self->{options} = [ sort { $settings{$a} cmp $settings{$b} } keys %settings ]; - my $choice = $self->{choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], [ map $settings{$_}, @{$self->{options}} ]); + my $choice = $self->{choice} = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], []); # create the button my $btn = $self->{btn_add} = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG)); @@ -50,11 +46,23 @@ sub new { $self->SetSizer($self->{sizer}); $self->SetScrollbars(0, 1, 0, 1); + $self->set_opt_keys($params{opt_keys}) if $params{opt_keys}; $self->update_optgroup; return $self; } +sub set_opt_keys { + my ($self, $opt_keys) = @_; + + # sort options by category+label + my %settings = map { $_ => sprintf('%s > %s', $Slic3r::Config::Options->{$_}{category}, $Slic3r::Config::Options->{$_}{full_label} // $Slic3r::Config::Options->{$_}{label}) } @$opt_keys; + $self->{options} = [ sort { $settings{$a} cmp $settings{$b} } keys %settings ]; + + $self->{choice}->Clear; + $self->{choice}->Append($_) for map $settings{$_}, @{$self->{options}}; +} + sub set_config { my ($self, $config) = @_; $self->{config} = $config; diff --git a/var/brick.png b/var/brick.png new file mode 100755 index 0000000000000000000000000000000000000000..7851cf34c946e5667221e3478668503eb1cd733f GIT binary patch literal 452 zcmV;#0XzPQP)Pdwe5?6tW?r-ok|b$oDQj8FV%kZPq;(MWOV8?8;<)(iP}>hNMU> z7fbz%jjlr7h8uuoQ~J6}n}@Y@PdTk=)PxO{%7zmL?dchpZX*~n;I{!C>*(8cU;q(~ zAS%Po_@naEU!xidrBXD?;hN|x^%W|Ij)0y*r5vi|?W&Fub(NqJ@z0o=O