Anonymous object supports. Initial implementation provides for a box of arbitrary size.
This commit is contained in:
parent
e93cc13698
commit
33f489bba9
110
lib/Slic3r/GUI/Plater/LambdaObjectDialog.pm
Normal file
110
lib/Slic3r/GUI/Plater/LambdaObjectDialog.pm
Normal file
@ -0,0 +1,110 @@
|
||||
# Generate an anonymous or "lambda" 3D object. This gets used with the Add Generic option in Settings.
|
||||
#
|
||||
|
||||
package Slic3r::GUI::Plater::LambdaObjectDialog;
|
||||
use strict;
|
||||
use warnings;
|
||||
use utf8;
|
||||
|
||||
use Slic3r::Geometry qw(PI X);
|
||||
use Wx qw(wxTheApp :dialog :id :misc :sizer wxTAB_TRAVERSAL wxCB_READONLY wxTE_PROCESS_TAB);
|
||||
use Wx::Event qw(EVT_CLOSE EVT_BUTTON EVT_COMBOBOX EVT_TEXT);
|
||||
use Scalar::Util qw(looks_like_number);
|
||||
use base 'Wx::Dialog';
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent, %params) = @_;
|
||||
my $self = $class->SUPER::new($parent, -1, "Lambda Object", wxDefaultPosition, [500,500], wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER);
|
||||
# Note whether the window was already closed, so a pending update is not executed.
|
||||
$self->{already_closed} = 0;
|
||||
$self->{object_parameters} = {
|
||||
type => "box",
|
||||
dim => [1, 1, 1],
|
||||
};
|
||||
|
||||
$self->{sizer} = Wx::BoxSizer->new(wxVERTICAL);
|
||||
my $button_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
my $buttons = $self->CreateStdDialogButtonSizer(wxOK);
|
||||
EVT_BUTTON($self, wxID_OK, sub {
|
||||
# validate user input
|
||||
return if !$self->CanClose;
|
||||
|
||||
$self->EndModal(wxID_OK);
|
||||
$self->Destroy;
|
||||
});
|
||||
$button_sizer->Add($buttons, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
||||
|
||||
my @options = ("box");
|
||||
$self->{type} = Wx::ComboBox->new($self, 1, "box", wxDefaultPosition, wxDefaultSize, \@options, wxCB_READONLY);
|
||||
|
||||
my $sbox = Wx::StaticBox->new($self, -1, '', wxDefaultPosition, wxDefaultSize, 0, 'sbox');
|
||||
my $cube_dim_sizer = Wx::StaticBoxSizer->new($sbox, wxVERTICAL);
|
||||
{
|
||||
my $opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
{
|
||||
my $lbl = Wx::StaticText->new($self, 2, "X", wxDefaultPosition, Wx::Size->new(10,-1));
|
||||
$self->{dim_x} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
||||
$opt_sizer->Add($self->{dim_x});
|
||||
|
||||
}
|
||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
||||
$opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
{
|
||||
my $lbl = Wx::StaticText->new($self, -1, "Y", wxDefaultPosition, Wx::Size->new(10,-1));
|
||||
$self->{dim_y} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
||||
$opt_sizer->Add($self->{dim_y});
|
||||
}
|
||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
||||
$opt_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
{
|
||||
my $lbl = Wx::StaticText->new($self, -1, "Z", wxDefaultPosition, Wx::Size->new(10,-1));
|
||||
$self->{dim_z} = Wx::TextCtrl->new($self, 2, "1", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_TAB);
|
||||
$opt_sizer->Add($lbl, 1, wxRIGHT , 8);
|
||||
$opt_sizer->Add($self->{dim_z});
|
||||
}
|
||||
$cube_dim_sizer->Add($opt_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
|
||||
EVT_TEXT($self, 2, sub {
|
||||
if (!looks_like_number($self->{dim_x}->GetValue)) {
|
||||
return 0;
|
||||
}
|
||||
if (!looks_like_number($self->{dim_y}->GetValue)) {
|
||||
return 0;
|
||||
}
|
||||
if (!looks_like_number($self->{dim_z}->GetValue)) {
|
||||
return 0;
|
||||
}
|
||||
if ($self->{dim_x}->GetValue() > 0) {
|
||||
$self->{object_parameters}->{dim}[0] = $self->{dim_x}->GetValue;
|
||||
}
|
||||
if ($self->{dim_y}->GetValue() > 0) {
|
||||
$self->{object_parameters}->{dim}[1] = $self->{dim_y}->GetValue;
|
||||
}
|
||||
if ($self->{dim_z}->GetValue() > 0) {
|
||||
$self->{object_parameters}->{dim}[2] = $self->{dim_z}->GetValue;
|
||||
}
|
||||
});
|
||||
}
|
||||
EVT_COMBOBOX($self, 1, sub{
|
||||
$self->{object_parameters}->{type} = $self->{type}->GetValue();
|
||||
});
|
||||
$self->{sizer}->Add($self->{type}, 0, wxEXPAND, 3);
|
||||
$self->{sizer}->Add($cube_dim_sizer, 0, wxEXPAND, 10);
|
||||
$self->{sizer}->Add($button_sizer);
|
||||
$self->SetSizer($self->{sizer});
|
||||
$self->{sizer}->Fit($self);
|
||||
$self->{sizer}->SetSizeHints($self);
|
||||
|
||||
|
||||
return $self;
|
||||
}
|
||||
sub CanClose {
|
||||
return 1;
|
||||
}
|
||||
sub ObjectParameter {
|
||||
my ($self) = @_;
|
||||
return $self->{object_parameters};
|
||||
}
|
||||
1;
|
@ -54,10 +54,12 @@ sub new {
|
||||
# buttons
|
||||
$self->{btn_load_part} = Wx::Button->new($self, -1, "Load part…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
$self->{btn_load_modifier} = Wx::Button->new($self, -1, "Load modifier…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
$self->{btn_load_lambda_modifier} = Wx::Button->new($self, -1, "Load generic…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
$self->{btn_delete} = Wx::Button->new($self, -1, "Delete part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
||||
if ($Slic3r::GUI::have_button_icons) {
|
||||
$self->{btn_load_part}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_modifier}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_load_lambda_modifier}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_add.png"), wxBITMAP_TYPE_PNG));
|
||||
$self->{btn_delete}->SetBitmap(Wx::Bitmap->new($Slic3r::var->("brick_delete.png"), wxBITMAP_TYPE_PNG));
|
||||
}
|
||||
|
||||
@ -65,9 +67,11 @@ sub new {
|
||||
my $buttons_sizer = Wx::BoxSizer->new(wxHORIZONTAL);
|
||||
$buttons_sizer->Add($self->{btn_load_part}, 0);
|
||||
$buttons_sizer->Add($self->{btn_load_modifier}, 0);
|
||||
$buttons_sizer->Add($self->{btn_load_lambda_modifier}, 0);
|
||||
$buttons_sizer->Add($self->{btn_delete}, 0);
|
||||
$self->{btn_load_part}->SetFont($Slic3r::GUI::small_font);
|
||||
$self->{btn_load_modifier}->SetFont($Slic3r::GUI::small_font);
|
||||
$self->{btn_load_lambda_modifier}->SetFont($Slic3r::GUI::small_font);
|
||||
$self->{btn_delete}->SetFont($Slic3r::GUI::small_font);
|
||||
|
||||
# part settings panel
|
||||
@ -145,7 +149,7 @@ sub new {
|
||||
|
||||
$canvas->load_object($self->{model_object}, undef, undef, [0]);
|
||||
$canvas->set_auto_bed_shape;
|
||||
$canvas->SetSize([500,500]);
|
||||
$canvas->SetSize([500,700]);
|
||||
$canvas->zoom_to_volumes;
|
||||
}
|
||||
|
||||
@ -168,6 +172,7 @@ sub new {
|
||||
});
|
||||
EVT_BUTTON($self, $self->{btn_load_part}, sub { $self->on_btn_load(0) });
|
||||
EVT_BUTTON($self, $self->{btn_load_modifier}, sub { $self->on_btn_load(1) });
|
||||
EVT_BUTTON($self, $self->{btn_load_lambda_modifier}, sub { $self->on_btn_lambda(1) });
|
||||
EVT_BUTTON($self, $self->{btn_delete}, \&on_btn_delete);
|
||||
|
||||
$self->reload_tree;
|
||||
@ -328,6 +333,28 @@ sub on_btn_load {
|
||||
$self->_parts_changed;
|
||||
}
|
||||
|
||||
sub on_btn_lambda {
|
||||
my ($self, $is_modifier) = @_;
|
||||
|
||||
my $dlg = Slic3r::GUI::Plater::LambdaObjectDialog->new($self);
|
||||
$dlg->ShowModal();
|
||||
my $params = $dlg->ObjectParameter;
|
||||
my $name = "lambda-".$params->{"type"};
|
||||
|
||||
my $new_volume = $self->{model_object}->add_volume(mesh => Slic3r::Test::mesh($params->{"type"}, dim=>$params->{"dim"}), material_id=>"generic");
|
||||
$new_volume->set_modifier($is_modifier);
|
||||
$new_volume->set_name($name);
|
||||
|
||||
# apply the same translation we applied to the object
|
||||
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation});
|
||||
|
||||
# set a default extruder value, since user can't add it manually
|
||||
$new_volume->config->set_ifndef('extruder', 0);
|
||||
|
||||
$self->{parts_changed} = 1;
|
||||
$self->_parts_changed;
|
||||
}
|
||||
|
||||
sub on_btn_delete {
|
||||
my ($self) = @_;
|
||||
|
||||
|
@ -27,6 +27,14 @@ sub mesh {
|
||||
$facets = [
|
||||
[0,1,2], [0,2,3], [4,5,6], [4,6,7], [0,4,7], [0,7,1], [1,7,6], [1,6,2], [2,6,5], [2,5,3], [4,0,3], [4,3,5],
|
||||
],
|
||||
} elsif ($name eq 'box') {
|
||||
my ($x, $y, $z) = @{ $params{"dim"} };
|
||||
$vertices = [
|
||||
[$x,$y,0], [$x,0,0], [0,0,0], [0,$y,0], [$x,$y,$z], [0,$y,$z], [0,0,$z], [$x,0,$z],
|
||||
];
|
||||
$facets = [
|
||||
[0,1,2], [0,2,3], [4,5,6], [4,6,7], [0,4,7], [0,7,1], [1,7,6], [1,6,2], [2,6,5], [2,5,3], [4,0,3], [4,3,5],
|
||||
],
|
||||
} elsif ($name eq 'cube_with_hole') {
|
||||
$vertices = [
|
||||
[0,0,0],[0,0,10],[0,20,0],[0,20,10],[20,0,0],[20,0,10],[5,5,0],[15,5,0],[5,15,0],[20,20,0],[15,15,0],[20,20,10],[5,5,10],[5,15,10],[15,5,10],[15,15,10]
|
||||
|
Loading…
Reference in New Issue
Block a user