Permalink
Browse files

Some incomplete work for per-region config

  • Loading branch information...
1 parent 2e7b29f commit 691db31da0a0445518f12cb2db043c9f9328f0e4 @alexrj committed Feb 14, 2014
View
@@ -1,6 +1,8 @@
package Slic3r::Format::STL;
use Moo;
+use File::Basename qw(basename);
+
sub read_file {
my $self = shift;
my ($file) = @_;
@@ -10,8 +12,11 @@ sub read_file {
$mesh->repair;
my $model = Slic3r::Model->new;
+
+ my $material_id = basename($file);
+ $model->set_material($material_id);
my $object = $model->add_object;
- my $volume = $object->add_volume(mesh => $mesh);
+ my $volume = $object->add_volume(mesh => $mesh, material_id => $material_id);
return $model;
}
View
@@ -10,6 +10,7 @@ use Slic3r::GUI::Plater;
use Slic3r::GUI::Plater::ObjectPartsPanel;
use Slic3r::GUI::Plater::ObjectPreviewDialog;
use Slic3r::GUI::Plater::ObjectSettingsDialog;
+use Slic3r::GUI::Plater::OverrideSettingsPanel;
use Slic3r::GUI::Preferences;
use Slic3r::GUI::OptionsGroup;
use Slic3r::GUI::SkeinPanel;
@@ -53,10 +53,19 @@ sub new {
$self->{btn_load_modifier}->SetFont($Slic3r::GUI::small_font);
$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);
+ $settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0);
+
# left pane with tree
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
$left_sizer->Add($tree, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
$left_sizer->Add($buttons_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
+ $left_sizer->Add($settings_sizer, 1, wxEXPAND | wxALL, 0);
# right pane with preview canvas
my $canvas;
@@ -134,15 +143,22 @@ sub selection_changed {
$_->{selected} = 0 for @{$self->{canvas}->volumes};
}
- # disable buttons
+ # disable things as if nothing is selected
$self->{btn_delete}->Disable;
+ $self->{settings_panel}->Disable;
my $itemData = $self->get_selection;
if ($itemData && $itemData->{type} eq 'volume') {
if ($self->{canvas}) {
$self->{canvas}->volumes->[ $itemData->{volume_id} ]{selected} = 1;
}
$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};
@@ -72,77 +72,19 @@ sub new {
$self->{sizer}->Add($label, 0, wxEXPAND | wxTOP | wxLEFT | wxRIGHT, 10);
}
- # 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}) }
- grep { ($Slic3r::Config::Options->{$_}{scope} // '') eq 'object' }
- keys %$Slic3r::Config::Options;
- $self->{options} = [ sort { $settings{$a} cmp $settings{$b} } keys %settings ];
- my $choice = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], [ map $settings{$_}, @{$self->{options}} ]);
-
- # create the button
- my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG));
- EVT_BUTTON($self, $btn, sub {
- my $idx = $choice->GetSelection;
- return if $idx == -1; # lack of selected item, can happen on Windows
- my $opt_key = $self->{options}[$idx];
- $self->model_object->config->apply(Slic3r::Config->new_from_defaults($opt_key));
- $self->update_optgroup;
- });
-
- my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
- $h_sizer->Add($choice, 1, wxEXPAND | wxALL, 0);
- $h_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 10);
- $self->{sizer}->Add($h_sizer, 0, wxEXPAND | wxALL, 10);
- }
-
- $self->{options_sizer} = Wx::BoxSizer->new(wxVERTICAL);
- $self->{sizer}->Add($self->{options_sizer}, 0, wxEXPAND | wxALL, 10);
-
- $self->update_optgroup;
+ $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 update_optgroup {
- my $self = shift;
-
- $self->{options_sizer}->Clear(1);
-
- my $config = $self->model_object->config;
- my %categories = ();
- foreach my $opt_key (@{$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(
- parent => $self,
- title => $category,
- config => $config,
- options => [ sort @{$categories{$category}} ],
- full_labels => 1,
- extra_column => sub {
- my ($line) = @_;
- my ($opt_key) = @{$line->{options}}; # we assume that we have one option per line
- my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
- EVT_BUTTON($self, $btn, sub {
- $self->model_object->config->erase($opt_key);
- Slic3r::GUI->CallAfter(sub { $self->update_optgroup });
- });
- return $btn;
- },
- );
- $self->{options_sizer}->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM, 10);
- }
- $self->Layout;
-}
-
sub CanClose {
my $self = shift;
@@ -0,0 +1,98 @@
+package Slic3r::GUI::Plater::OverrideSettingsPanel;
+use strict;
+use warnings;
+use utf8;
+
+use File::Basename qw(basename);
+use Wx qw(:misc :sizer :button wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG);
+use Wx::Event qw(EVT_BUTTON);
+use base 'Wx::ScrolledWindow';
+
+use constant ICON_MATERIAL => 0;
+use constant ICON_SOLIDMESH => 1;
+use constant ICON_MODIFIERMESH => 2;
+
+sub new {
+ my $class = shift;
+ 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 = Wx::Choice->new($self, -1, wxDefaultPosition, [150, -1], [ map $settings{$_}, @{$self->{options}} ]);
+
+ # create the button
+ my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/add.png", wxBITMAP_TYPE_PNG));
+ EVT_BUTTON($self, $btn, sub {
+ my $idx = $choice->GetSelection;
+ return if $idx == -1; # lack of selected item, can happen on Windows
+ my $opt_key = $self->{options}[$idx];
+ $self->{config}->apply(Slic3r::Config->new_from_defaults($opt_key));
+ $self->update_optgroup;
+ });
+
+ my $h_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
+ $h_sizer->Add($choice, 1, wxEXPAND | wxALL, 0);
+ $h_sizer->Add($btn, 0, wxEXPAND | wxLEFT, 10);
+ $self->{sizer}->Add($h_sizer, 0, wxEXPAND | wxBOTTOM, 10);
+ }
+
+ $self->{options_sizer} = Wx::BoxSizer->new(wxVERTICAL);
+ $self->{sizer}->Add($self->{options_sizer}, 0, wxEXPAND | wxALL, 0);
+
+ $self->SetSizer($self->{sizer});
+ $self->SetScrollbars(0, 1, 0, 1);
+
+ $self->update_optgroup;
+
+ return $self;
+}
+
+sub set_config {
+ my ($self, $config) = @_;
+ $self->{config} = $config;
+}
+
+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(
+ parent => $self,
+ title => $category,
+ config => $self->{config},
+ options => [ sort @{$categories{$category}} ],
+ full_labels => 1,
+ extra_column => sub {
+ my ($line) = @_;
+ my ($opt_key) = @{$line->{options}}; # we assume that we have one option per line
+ my $btn = Wx::BitmapButton->new($self, -1, Wx::Bitmap->new("$Slic3r::var/delete.png", wxBITMAP_TYPE_PNG));
+ EVT_BUTTON($self, $btn, sub {
+ $self->{config}->erase($opt_key);
+ Slic3r::GUI->CallAfter(sub { $self->update_optgroup });
+ });
+ return $btn;
+ },
+ );
+ $self->{options_sizer}->Add($optgroup->sizer, 0, wxEXPAND | wxBOTTOM, 10);
+ }
+ $self->Layout;
+}
+
+1;
View
@@ -531,6 +531,15 @@ has 'material_id' => (is => 'rw');
has 'mesh' => (is => 'rw', required => 1);
has 'modifier' => (is => 'rw', defualt => sub { 0 });
+sub assign_unique_material {
+ my ($self) = @_;
+
+ my $model = $self->object->model;
+ my $material_id = 1 + scalar keys %{$model->materials};
+ $self->material_id($material_id);
+ return $model->set_material($material_id);
+}
+
package Slic3r::Model::Instance;
use Moo;
View
@@ -378,7 +378,6 @@ class ConfigOptionDef
std::string tooltip;
std::string sidetext;
std::string cli;
- std::string scope;
t_config_option_key ratio_over;
bool multiline;
bool full_width;
Oops, something went wrong.

0 comments on commit 691db31

Please sign in to comment.