2016-09-14 09:22:41 +00:00
|
|
|
# Configuration of mesh modifiers and their parameters.
|
|
|
|
# This panel is inserted into ObjectSettingsDialog.
|
|
|
|
|
2014-01-08 18:36:41 +00:00
|
|
|
package Slic3r::GUI::Plater::ObjectPartsPanel;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
use File::Basename qw(basename);
|
2017-05-20 20:02:04 +00:00
|
|
|
use Wx qw(:misc :sizer :treectrl :button :keycode wxTAB_TRAVERSAL wxSUNKEN_BORDER wxBITMAP_TYPE_PNG wxID_CANCEL wxMOD_CONTROL
|
2014-06-14 17:59:59 +00:00
|
|
|
wxTheApp);
|
2018-04-10 10:47:09 +00:00
|
|
|
use Wx::Event qw(EVT_BUTTON EVT_TREE_ITEM_COLLAPSING EVT_TREE_SEL_CHANGED EVT_TREE_KEY_DOWN EVT_KEY_DOWN);
|
2018-05-18 11:02:47 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
use List::Util qw(max);
|
|
|
|
#==============================================================================================================================
|
2014-01-08 18:36:41 +00:00
|
|
|
use base 'Wx::Panel';
|
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
use constant ICON_OBJECT => 0;
|
|
|
|
use constant ICON_SOLIDMESH => 1;
|
|
|
|
use constant ICON_MODIFIERMESH => 2;
|
2014-01-08 18:36:41 +00:00
|
|
|
|
|
|
|
sub new {
|
2017-09-18 08:01:37 +00:00
|
|
|
my ($class, $parent, %params) = @_;
|
2014-01-08 18:36:41 +00:00
|
|
|
my $self = $class->SUPER::new($parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
|
|
|
|
2017-02-07 17:28:53 +00:00
|
|
|
# C++ type Slic3r::ModelObject
|
2016-11-27 01:55:43 +00:00
|
|
|
my $object = $self->{model_object} = $params{model_object};
|
|
|
|
|
|
|
|
# Save state for sliders.
|
|
|
|
$self->{move_options} = {
|
|
|
|
x => 0,
|
|
|
|
y => 0,
|
|
|
|
z => 0,
|
|
|
|
};
|
|
|
|
$self->{last_coords} = {
|
|
|
|
x => 0,
|
|
|
|
y => 0,
|
|
|
|
z => 0,
|
|
|
|
};
|
2014-01-08 18:36:41 +00:00
|
|
|
|
|
|
|
# create TreeCtrl
|
2014-02-14 09:02:08 +00:00
|
|
|
my $tree = $self->{tree} = Wx::TreeCtrl->new($self, -1, wxDefaultPosition, [300, 100],
|
2014-03-22 16:41:14 +00:00
|
|
|
wxTR_NO_BUTTONS | wxSUNKEN_BORDER | wxTR_HAS_VARIABLE_ROW_HEIGHT
|
2017-05-20 20:02:04 +00:00
|
|
|
| wxTR_SINGLE);
|
2014-01-08 18:36:41 +00:00
|
|
|
{
|
|
|
|
$self->{tree_icons} = Wx::ImageList->new(16, 16, 1);
|
|
|
|
$tree->AssignImageList($self->{tree_icons});
|
2017-10-25 10:53:31 +00:00
|
|
|
$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
|
2014-01-08 18:36:41 +00:00
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
my $rootId = $tree->AddRoot("Object", ICON_OBJECT);
|
|
|
|
$tree->SetPlData($rootId, { type => 'object' });
|
2014-01-08 18:36:41 +00:00
|
|
|
}
|
2014-01-17 18:33:13 +00:00
|
|
|
|
2014-02-14 15:25:22 +00:00
|
|
|
# buttons
|
2014-01-22 20:09:32 +00:00
|
|
|
$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);
|
2016-11-27 01:57:35 +00:00
|
|
|
$self->{btn_load_lambda_modifier} = Wx::Button->new($self, -1, "Load generic…", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
2014-01-18 17:43:55 +00:00
|
|
|
$self->{btn_delete} = Wx::Button->new($self, -1, "Delete part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
2017-06-15 13:38:15 +00:00
|
|
|
$self->{btn_split} = Wx::Button->new($self, -1, "Split part", wxDefaultPosition, wxDefaultSize, wxBU_LEFT);
|
2017-08-03 15:47:18 +00:00
|
|
|
$self->{btn_move_up} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
|
|
|
|
$self->{btn_move_down} = Wx::Button->new($self, -1, "", wxDefaultPosition, [40, -1], wxBU_LEFT);
|
2017-10-25 10:53:31 +00:00
|
|
|
$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));
|
|
|
|
$self->{btn_split}->SetBitmap(Wx::Bitmap->new(Slic3r::var("shape_ungroup.png"), wxBITMAP_TYPE_PNG));
|
|
|
|
$self->{btn_move_up}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_up.png"), wxBITMAP_TYPE_PNG));
|
|
|
|
$self->{btn_move_down}->SetBitmap(Wx::Bitmap->new(Slic3r::var("bullet_arrow_down.png"), wxBITMAP_TYPE_PNG));
|
2014-01-17 18:33:13 +00:00
|
|
|
|
2014-02-14 15:25:22 +00:00
|
|
|
# buttons sizer
|
2017-05-20 20:02:04 +00:00
|
|
|
my $buttons_sizer = Wx::GridSizer->new(2, 3);
|
|
|
|
$buttons_sizer->Add($self->{btn_load_part}, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5);
|
|
|
|
$buttons_sizer->Add($self->{btn_load_modifier}, 0, wxEXPAND | wxBOTTOM | wxRIGHT, 5);
|
|
|
|
$buttons_sizer->Add($self->{btn_load_lambda_modifier}, 0, wxEXPAND | wxBOTTOM, 5);
|
|
|
|
$buttons_sizer->Add($self->{btn_delete}, 0, wxEXPAND | wxRIGHT, 5);
|
2017-06-15 13:38:15 +00:00
|
|
|
$buttons_sizer->Add($self->{btn_split}, 0, wxEXPAND | wxRIGHT, 5);
|
|
|
|
{
|
|
|
|
my $up_down_sizer = Wx::GridSizer->new(1, 2);
|
|
|
|
$up_down_sizer->Add($self->{btn_move_up}, 0, wxEXPAND | wxRIGHT, 5);
|
|
|
|
$up_down_sizer->Add($self->{btn_move_down}, 0, wxEXPAND, 5);
|
|
|
|
$buttons_sizer->Add($up_down_sizer, 0, wxEXPAND, 5);
|
|
|
|
}
|
2014-02-14 15:25:22 +00:00
|
|
|
$self->{btn_load_part}->SetFont($Slic3r::GUI::small_font);
|
|
|
|
$self->{btn_load_modifier}->SetFont($Slic3r::GUI::small_font);
|
2016-11-27 01:57:35 +00:00
|
|
|
$self->{btn_load_lambda_modifier}->SetFont($Slic3r::GUI::small_font);
|
2014-02-14 15:25:22 +00:00
|
|
|
$self->{btn_delete}->SetFont($Slic3r::GUI::small_font);
|
2017-06-15 13:38:15 +00:00
|
|
|
$self->{btn_split}->SetFont($Slic3r::GUI::small_font);
|
2017-05-20 20:02:04 +00:00
|
|
|
$self->{btn_move_up}->SetFont($Slic3r::GUI::small_font);
|
|
|
|
$self->{btn_move_down}->SetFont($Slic3r::GUI::small_font);
|
2014-02-14 15:25:22 +00:00
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
# part settings panel
|
2018-04-05 13:55:50 +00:00
|
|
|
$self->{settings_panel} = Slic3r::GUI::Plater::OverrideSettingsPanel->new($self, on_change => sub { $self->{part_settings_changed} = 1; $self->_update_canvas; });
|
2014-03-22 16:41:14 +00:00
|
|
|
my $settings_sizer = Wx::StaticBoxSizer->new($self->{staticbox} = Wx::StaticBox->new($self, -1, "Part Settings"), wxVERTICAL);
|
2014-02-14 21:24:30 +00:00
|
|
|
$settings_sizer->Add($self->{settings_panel}, 1, wxEXPAND | wxALL, 0);
|
2016-11-27 01:55:43 +00:00
|
|
|
|
2016-11-28 05:46:05 +00:00
|
|
|
my $optgroup_movers;
|
|
|
|
$optgroup_movers = $self->{optgroup_movers} = Slic3r::GUI::OptionsGroup->new(
|
2016-11-27 01:55:43 +00:00
|
|
|
parent => $self,
|
|
|
|
title => 'Move',
|
|
|
|
on_change => sub {
|
|
|
|
my ($opt_id) = @_;
|
|
|
|
# There seems to be an issue with wxWidgets 3.0.2/3.0.3, where the slider
|
|
|
|
# genates tens of events for a single value change.
|
|
|
|
# Only trigger the recalculation if the value changes
|
|
|
|
# or a live preview was activated and the mesh cut is not valid yet.
|
2016-11-28 05:46:05 +00:00
|
|
|
if ($self->{move_options}{$opt_id} != $optgroup_movers->get_value($opt_id)) {
|
|
|
|
$self->{move_options}{$opt_id} = $optgroup_movers->get_value($opt_id);
|
2016-11-27 01:55:43 +00:00
|
|
|
wxTheApp->CallAfter(sub {
|
|
|
|
$self->_update;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
label_width => 20,
|
|
|
|
);
|
2016-11-28 05:46:05 +00:00
|
|
|
$optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
2016-11-27 01:55:43 +00:00
|
|
|
opt_id => 'x',
|
|
|
|
type => 'slider',
|
|
|
|
label => 'X',
|
|
|
|
default => 0,
|
|
|
|
min => -($self->{model_object}->bounding_box->size->x)*4,
|
|
|
|
max => $self->{model_object}->bounding_box->size->x*4,
|
|
|
|
full_width => 1,
|
|
|
|
));
|
2016-11-28 05:46:05 +00:00
|
|
|
$optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
2016-11-27 01:55:43 +00:00
|
|
|
opt_id => 'y',
|
|
|
|
type => 'slider',
|
|
|
|
label => 'Y',
|
|
|
|
default => 0,
|
|
|
|
min => -($self->{model_object}->bounding_box->size->y)*4,
|
|
|
|
max => $self->{model_object}->bounding_box->size->y*4,
|
|
|
|
full_width => 1,
|
|
|
|
));
|
2016-11-28 05:46:05 +00:00
|
|
|
$optgroup_movers->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
2016-11-27 01:55:43 +00:00
|
|
|
opt_id => 'z',
|
|
|
|
type => 'slider',
|
|
|
|
label => 'Z',
|
|
|
|
default => 0,
|
|
|
|
min => -($self->{model_object}->bounding_box->size->z)*4,
|
|
|
|
max => $self->{model_object}->bounding_box->size->z*4,
|
|
|
|
full_width => 1,
|
|
|
|
));
|
2016-11-28 05:46:05 +00:00
|
|
|
|
2014-02-14 15:25:22 +00:00
|
|
|
# left pane with tree
|
|
|
|
my $left_sizer = Wx::BoxSizer->new(wxVERTICAL);
|
2017-05-20 17:44:55 +00:00
|
|
|
$left_sizer->Add($tree, 3, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
|
2014-02-14 15:25:22 +00:00
|
|
|
$left_sizer->Add($buttons_sizer, 0, wxEXPAND | wxLEFT | wxRIGHT | wxBOTTOM, 10);
|
2017-05-20 17:44:55 +00:00
|
|
|
$left_sizer->Add($settings_sizer, 5, wxEXPAND | wxALL, 0);
|
2016-11-28 05:46:05 +00:00
|
|
|
$left_sizer->Add($optgroup_movers->sizer, 0, wxEXPAND | wxBOTTOM | wxLEFT | wxRIGHT, 10);
|
2014-02-14 15:25:22 +00:00
|
|
|
|
2014-01-17 18:33:13 +00:00
|
|
|
# right pane with preview canvas
|
2014-02-11 00:08:41 +00:00
|
|
|
my $canvas;
|
|
|
|
if ($Slic3r::GUI::have_OpenGL) {
|
2015-01-09 00:30:04 +00:00
|
|
|
$canvas = $self->{canvas} = Slic3r::GUI::3DScene->new($self);
|
2018-05-22 07:02:42 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
Slic3r::GUI::_3DScene::enable_picking($canvas, 1);
|
|
|
|
# $canvas->enable_picking(1);
|
|
|
|
#==============================================================================================================================
|
2015-01-13 18:07:25 +00:00
|
|
|
$canvas->select_by('volume');
|
|
|
|
|
|
|
|
$canvas->on_select(sub {
|
|
|
|
my ($volume_idx) = @_;
|
|
|
|
# convert scene volume to model object volume
|
2017-01-31 10:38:07 +00:00
|
|
|
$self->reload_tree(($volume_idx == -1) ? undef : $canvas->volumes->[$volume_idx]->volume_idx);
|
2015-01-13 18:07:25 +00:00
|
|
|
});
|
|
|
|
|
2016-12-12 17:02:24 +00:00
|
|
|
$canvas->load_object($self->{model_object}, undef, undef, [0]);
|
2018-05-15 13:38:25 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
Slic3r::GUI::_3DScene::set_auto_bed_shape($canvas);
|
2018-05-18 11:02:47 +00:00
|
|
|
Slic3r::GUI::_3DScene::set_axes_length($canvas, 2.0 * max(@{ $canvas->volumes_bounding_box->size }));
|
2018-05-15 13:38:25 +00:00
|
|
|
# $canvas->set_auto_bed_shape;
|
|
|
|
#==============================================================================================================================
|
2016-11-27 01:57:35 +00:00
|
|
|
$canvas->SetSize([500,700]);
|
2018-04-05 10:52:29 +00:00
|
|
|
$canvas->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
|
2014-02-11 00:08:41 +00:00
|
|
|
}
|
2014-01-17 18:33:13 +00:00
|
|
|
|
|
|
|
$self->{sizer} = Wx::BoxSizer->new(wxHORIZONTAL);
|
|
|
|
$self->{sizer}->Add($left_sizer, 0, wxEXPAND | wxALL, 0);
|
2014-02-11 00:08:41 +00:00
|
|
|
$self->{sizer}->Add($canvas, 1, wxEXPAND | wxALL, 0) if $canvas;
|
2014-01-17 18:33:13 +00:00
|
|
|
|
|
|
|
$self->SetSizer($self->{sizer});
|
|
|
|
$self->{sizer}->SetSizeHints($self);
|
|
|
|
|
|
|
|
# attach events
|
2014-01-08 18:36:41 +00:00
|
|
|
EVT_TREE_ITEM_COLLAPSING($self, $tree, sub {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
$event->Veto;
|
|
|
|
});
|
2014-01-17 18:33:13 +00:00
|
|
|
EVT_TREE_SEL_CHANGED($self, $tree, sub {
|
|
|
|
my ($self, $event) = @_;
|
2015-05-04 23:11:41 +00:00
|
|
|
return if $self->{disable_tree_sel_changed_event};
|
2014-01-18 17:43:55 +00:00
|
|
|
$self->selection_changed;
|
|
|
|
});
|
2017-05-20 20:02:04 +00:00
|
|
|
EVT_TREE_KEY_DOWN($self, $tree, \&on_tree_key_down);
|
2014-01-22 20:09:32 +00:00
|
|
|
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) });
|
2016-11-27 01:57:35 +00:00
|
|
|
EVT_BUTTON($self, $self->{btn_load_lambda_modifier}, sub { $self->on_btn_lambda(1) });
|
2014-01-22 20:09:32 +00:00
|
|
|
EVT_BUTTON($self, $self->{btn_delete}, \&on_btn_delete);
|
2017-06-15 13:38:15 +00:00
|
|
|
EVT_BUTTON($self, $self->{btn_split}, \&on_btn_split);
|
2017-05-20 20:02:04 +00:00
|
|
|
EVT_BUTTON($self, $self->{btn_move_up}, \&on_btn_move_up);
|
|
|
|
EVT_BUTTON($self, $self->{btn_move_down}, \&on_btn_move_down);
|
2018-04-10 10:47:09 +00:00
|
|
|
EVT_KEY_DOWN($canvas, sub {
|
|
|
|
my ($canvas, $event) = @_;
|
|
|
|
if ($event->GetKeyCode == WXK_DELETE) {
|
|
|
|
$canvas->GetParent->on_btn_delete;
|
|
|
|
} else {
|
|
|
|
$event->Skip;
|
|
|
|
}
|
|
|
|
});
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2014-03-21 21:06:47 +00:00
|
|
|
$self->reload_tree;
|
2014-01-18 17:43:55 +00:00
|
|
|
|
|
|
|
return $self;
|
|
|
|
}
|
|
|
|
|
|
|
|
sub reload_tree {
|
2015-01-13 18:07:25 +00:00
|
|
|
my ($self, $selected_volume_idx) = @_;
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2015-01-13 18:07:25 +00:00
|
|
|
$selected_volume_idx //= -1;
|
2014-01-18 17:43:55 +00:00
|
|
|
my $object = $self->{model_object};
|
|
|
|
my $tree = $self->{tree};
|
|
|
|
my $rootId = $tree->GetRootItem;
|
|
|
|
|
2015-05-04 23:11:41 +00:00
|
|
|
# despite wxWidgets states that DeleteChildren "will not generate any events unlike Delete() method",
|
|
|
|
# the MSW implementation of DeleteChildren actually calls Delete() for each item, so
|
|
|
|
# EVT_TREE_SEL_CHANGED is being called, with bad effects (the event handler is called; this
|
|
|
|
# subroutine is never continued; an invisible EndModal is called on the dialog causing Plater
|
|
|
|
# to continue its logic and rescheduling the background process etc. GH #2774)
|
|
|
|
$self->{disable_tree_sel_changed_event} = 1;
|
2014-01-18 17:43:55 +00:00
|
|
|
$tree->DeleteChildren($rootId);
|
2015-05-04 23:11:41 +00:00
|
|
|
$self->{disable_tree_sel_changed_event} = 0;
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2015-01-13 18:07:25 +00:00
|
|
|
my $selectedId = $rootId;
|
2014-01-18 17:43:55 +00:00
|
|
|
foreach my $volume_id (0..$#{$object->volumes}) {
|
|
|
|
my $volume = $object->volumes->[$volume_id];
|
2014-01-17 18:33:13 +00:00
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
my $icon = $volume->modifier ? ICON_MODIFIERMESH : ICON_SOLIDMESH;
|
2015-01-13 18:07:25 +00:00
|
|
|
my $itemId = $tree->AppendItem($rootId, $volume->name || $volume_id, $icon);
|
|
|
|
if ($volume_id == $selected_volume_idx) {
|
|
|
|
$selectedId = $itemId;
|
|
|
|
}
|
2014-01-18 17:43:55 +00:00
|
|
|
$tree->SetPlData($itemId, {
|
|
|
|
type => 'volume',
|
|
|
|
volume_id => $volume_id,
|
|
|
|
});
|
|
|
|
}
|
2014-03-22 16:41:14 +00:00
|
|
|
$tree->ExpandAll;
|
2014-03-21 21:06:47 +00:00
|
|
|
|
2014-07-12 09:46:03 +00:00
|
|
|
Slic3r::GUI->CallAfter(sub {
|
2015-01-13 18:07:25 +00:00
|
|
|
$self->{tree}->SelectItem($selectedId);
|
2015-03-30 18:27:18 +00:00
|
|
|
|
|
|
|
# SelectItem() should trigger EVT_TREE_SEL_CHANGED as per wxWidgets docs,
|
|
|
|
# but in fact it doesn't if the given item is already selected (this happens
|
|
|
|
# on first load)
|
|
|
|
$self->selection_changed;
|
2014-07-12 09:46:03 +00:00
|
|
|
});
|
2014-01-18 17:43:55 +00:00
|
|
|
}
|
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
sub get_selection {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
my $nodeId = $self->{tree}->GetSelection;
|
|
|
|
if ($nodeId->IsOk) {
|
|
|
|
return $self->{tree}->GetPlData($nodeId);
|
|
|
|
}
|
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
sub selection_changed {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
# deselect all meshes
|
2014-02-11 00:08:41 +00:00
|
|
|
if ($self->{canvas}) {
|
2017-03-14 09:11:08 +00:00
|
|
|
$_->set_selected(0) for @{$self->{canvas}->volumes};
|
2014-02-11 00:08:41 +00:00
|
|
|
}
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2014-02-14 21:24:30 +00:00
|
|
|
# disable things as if nothing is selected
|
2017-06-15 16:11:36 +00:00
|
|
|
$self->{'btn_' . $_}->Disable for (qw(delete move_up move_down split));
|
2014-03-21 21:15:33 +00:00
|
|
|
$self->{settings_panel}->disable;
|
|
|
|
$self->{settings_panel}->set_config(undef);
|
2016-11-27 01:55:43 +00:00
|
|
|
|
|
|
|
# reset move sliders
|
2016-11-28 05:46:05 +00:00
|
|
|
$self->{optgroup_movers}->set_value("x", 0);
|
|
|
|
$self->{optgroup_movers}->set_value("y", 0);
|
|
|
|
$self->{optgroup_movers}->set_value("z", 0);
|
2016-11-27 01:55:43 +00:00
|
|
|
$self->{move_options} = {
|
|
|
|
x => 0,
|
|
|
|
y => 0,
|
|
|
|
z => 0,
|
|
|
|
};
|
|
|
|
$self->{last_coords} = {
|
|
|
|
x => 0,
|
|
|
|
y => 0,
|
|
|
|
z => 0,
|
|
|
|
};
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
if (my $itemData = $self->get_selection) {
|
2014-06-19 18:07:16 +00:00
|
|
|
my ($config, @opt_keys);
|
2014-03-22 16:41:14 +00:00
|
|
|
if ($itemData->{type} eq 'volume') {
|
|
|
|
# select volume in 3D preview
|
|
|
|
if ($self->{canvas}) {
|
2017-03-14 09:11:08 +00:00
|
|
|
$self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1);
|
2014-03-22 16:41:14 +00:00
|
|
|
}
|
|
|
|
$self->{btn_delete}->Enable;
|
2017-06-15 13:38:15 +00:00
|
|
|
$self->{btn_split}->Enable;
|
2017-05-20 20:02:04 +00:00
|
|
|
$self->{btn_move_up}->Enable if $itemData->{volume_id} > 0;
|
|
|
|
$self->{btn_move_down}->Enable if $itemData->{volume_id} + 1 < $self->{model_object}->volumes_count;
|
2014-03-22 16:41:14 +00:00
|
|
|
|
2014-07-12 09:20:57 +00:00
|
|
|
# attach volume config to settings panel
|
2014-03-22 16:41:14 +00:00
|
|
|
my $volume = $self->{model_object}->volumes->[ $itemData->{volume_id} ];
|
2016-12-06 06:57:16 +00:00
|
|
|
|
|
|
|
if ($volume->modifier) {
|
|
|
|
$self->{optgroup_movers}->enable;
|
|
|
|
} else {
|
|
|
|
$self->{optgroup_movers}->disable;
|
|
|
|
}
|
2014-07-11 18:09:01 +00:00
|
|
|
$config = $volume->config;
|
2014-03-22 16:41:14 +00:00
|
|
|
$self->{staticbox}->SetLabel('Part Settings');
|
2014-06-19 18:07:16 +00:00
|
|
|
|
|
|
|
# get default values
|
|
|
|
@opt_keys = @{Slic3r::Config::PrintRegion->new->get_keys};
|
2014-03-22 16:41:14 +00:00
|
|
|
} elsif ($itemData->{type} eq 'object') {
|
2015-01-13 18:07:25 +00:00
|
|
|
# select nothing in 3D preview
|
2014-03-22 16:41:14 +00:00
|
|
|
|
|
|
|
# attach object config to settings panel
|
2016-11-28 05:46:05 +00:00
|
|
|
$self->{optgroup_movers}->disable;
|
2014-03-22 16:41:14 +00:00
|
|
|
$self->{staticbox}->SetLabel('Object Settings');
|
2014-06-19 18:07:16 +00:00
|
|
|
@opt_keys = (map @{$_->get_keys}, Slic3r::Config::PrintObject->new, Slic3r::Config::PrintRegion->new);
|
|
|
|
$config = $self->{model_object}->config;
|
2014-02-11 00:08:41 +00:00
|
|
|
}
|
2014-06-19 18:07:16 +00:00
|
|
|
# get default values
|
2017-10-27 20:49:59 +00:00
|
|
|
my $default_config = Slic3r::Config::new_from_defaults_keys(\@opt_keys);
|
2014-06-19 18:07:16 +00:00
|
|
|
|
|
|
|
# append default extruder
|
|
|
|
push @opt_keys, 'extruder';
|
|
|
|
$default_config->set('extruder', 0);
|
|
|
|
$config->set_ifndef('extruder', 0);
|
|
|
|
$self->{settings_panel}->set_default_config($default_config);
|
|
|
|
$self->{settings_panel}->set_config($config);
|
|
|
|
$self->{settings_panel}->set_opt_keys(\@opt_keys);
|
|
|
|
$self->{settings_panel}->set_fixed_options([qw(extruder)]);
|
|
|
|
$self->{settings_panel}->enable;
|
2014-01-18 17:43:55 +00:00
|
|
|
}
|
|
|
|
|
2014-02-11 00:08:41 +00:00
|
|
|
$self->{canvas}->Render if $self->{canvas};
|
2014-01-18 17:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub on_btn_load {
|
2014-01-22 20:09:32 +00:00
|
|
|
my ($self, $is_modifier) = @_;
|
2014-01-18 17:43:55 +00:00
|
|
|
|
2014-06-14 17:59:59 +00:00
|
|
|
my @input_files = wxTheApp->open_model($self);
|
2014-01-18 17:43:55 +00:00
|
|
|
foreach my $input_file (@input_files) {
|
|
|
|
my $model = eval { Slic3r::Model->read_from_file($input_file) };
|
|
|
|
if ($@) {
|
|
|
|
Slic3r::GUI::show_error($self, $@);
|
|
|
|
next;
|
|
|
|
}
|
2014-01-17 19:16:54 +00:00
|
|
|
|
2014-01-18 17:43:55 +00:00
|
|
|
foreach my $object (@{$model->objects}) {
|
|
|
|
foreach my $volume (@{$object->volumes}) {
|
|
|
|
my $new_volume = $self->{model_object}->add_volume($volume);
|
2014-05-15 14:37:18 +00:00
|
|
|
$new_volume->set_modifier($is_modifier);
|
2014-07-12 09:20:57 +00:00
|
|
|
$new_volume->set_name(basename($input_file));
|
2014-03-23 14:25:26 +00:00
|
|
|
|
2014-04-02 18:23:26 +00:00
|
|
|
# apply the same translation we applied to the object
|
2014-12-12 21:43:04 +00:00
|
|
|
$new_volume->mesh->translate(@{$self->{model_object}->origin_translation});
|
2014-04-02 18:23:26 +00:00
|
|
|
|
2014-03-23 14:25:26 +00:00
|
|
|
# set a default extruder value, since user can't add it manually
|
2014-07-11 18:09:01 +00:00
|
|
|
$new_volume->config->set_ifndef('extruder', 0);
|
2014-03-23 15:45:55 +00:00
|
|
|
|
|
|
|
$self->{parts_changed} = 1;
|
2014-01-17 19:16:54 +00:00
|
|
|
}
|
2014-01-17 18:33:13 +00:00
|
|
|
}
|
2014-01-18 17:43:55 +00:00
|
|
|
}
|
2014-01-08 18:36:41 +00:00
|
|
|
|
2014-12-27 23:16:15 +00:00
|
|
|
$self->_parts_changed;
|
2014-01-22 20:09:32 +00:00
|
|
|
}
|
|
|
|
|
2016-11-27 01:57:35 +00:00
|
|
|
sub on_btn_lambda {
|
|
|
|
my ($self, $is_modifier) = @_;
|
|
|
|
|
|
|
|
my $dlg = Slic3r::GUI::Plater::LambdaObjectDialog->new($self);
|
2016-11-27 05:03:51 +00:00
|
|
|
if ($dlg->ShowModal() == wxID_CANCEL) {
|
|
|
|
return;
|
|
|
|
}
|
2016-11-27 01:57:35 +00:00
|
|
|
my $params = $dlg->ObjectParameter;
|
2016-11-28 04:35:19 +00:00
|
|
|
my $type = "".$params->{"type"};
|
2016-11-27 01:57:35 +00:00
|
|
|
my $name = "lambda-".$params->{"type"};
|
2016-11-28 08:46:43 +00:00
|
|
|
my $mesh;
|
2016-11-27 01:57:35 +00:00
|
|
|
|
2016-11-28 04:35:19 +00:00
|
|
|
if ($type eq "box") {
|
2016-11-28 08:46:43 +00:00
|
|
|
$mesh = Slic3r::TriangleMesh::cube($params->{"dim"}[0], $params->{"dim"}[1], $params->{"dim"}[2]);
|
2016-11-28 04:35:19 +00:00
|
|
|
} elsif ($type eq "cylinder") {
|
2016-11-28 08:46:43 +00:00
|
|
|
$mesh = Slic3r::TriangleMesh::cylinder($params->{"cyl_r"}, $params->{"cyl_h"});
|
2016-12-05 22:44:17 +00:00
|
|
|
} elsif ($type eq "sphere") {
|
2016-12-05 23:08:12 +00:00
|
|
|
$mesh = Slic3r::TriangleMesh::sphere($params->{"sph_rho"});
|
2016-12-05 23:08:36 +00:00
|
|
|
} elsif ($type eq "slab") {
|
|
|
|
$mesh = Slic3r::TriangleMesh::cube($self->{model_object}->bounding_box->size->x*1.5, $self->{model_object}->bounding_box->size->y*1.5, $params->{"slab_h"});
|
|
|
|
# box sets the base coordinate at 0,0, move to center of plate and move it up to initial_z
|
|
|
|
$mesh->translate(-$self->{model_object}->bounding_box->size->x*1.5/2.0, -$self->{model_object}->bounding_box->size->y*1.5/2.0, $params->{"slab_z"});
|
2016-11-28 04:35:19 +00:00
|
|
|
} else {
|
|
|
|
return;
|
2016-11-28 01:15:27 +00:00
|
|
|
}
|
2016-12-05 23:40:28 +00:00
|
|
|
$mesh->repair;
|
2016-11-28 01:15:27 +00:00
|
|
|
my $new_volume = $self->{model_object}->add_volume(mesh => $mesh);
|
2016-11-27 01:57:35 +00:00
|
|
|
$new_volume->set_modifier($is_modifier);
|
|
|
|
$new_volume->set_name($name);
|
|
|
|
|
|
|
|
# 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;
|
|
|
|
}
|
|
|
|
|
2017-05-20 20:02:04 +00:00
|
|
|
sub on_tree_key_down {
|
|
|
|
my ($self, $event) = @_;
|
|
|
|
my $keycode = $event->GetKeyCode;
|
|
|
|
# Wx >= 0.9911
|
2018-04-09 12:20:44 +00:00
|
|
|
if (defined(&Wx::TreeEvent::GetKeyEvent)) {
|
|
|
|
if ($event->GetKeyEvent->GetModifiers & wxMOD_CONTROL) {
|
|
|
|
if ($keycode == WXK_UP) {
|
|
|
|
$event->Skip;
|
|
|
|
$self->on_btn_move_up;
|
|
|
|
} elsif ($keycode == WXK_DOWN) {
|
|
|
|
$event->Skip;
|
|
|
|
$self->on_btn_move_down;
|
|
|
|
}
|
|
|
|
} elsif ($keycode == WXK_DELETE) {
|
|
|
|
$self->on_btn_delete;
|
2017-05-20 20:02:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_btn_move_up {
|
|
|
|
my ($self) = @_;
|
|
|
|
my $itemData = $self->get_selection;
|
|
|
|
if ($itemData && $itemData->{type} eq 'volume') {
|
|
|
|
my $volume_id = $itemData->{volume_id};
|
|
|
|
if ($self->{model_object}->move_volume_up($volume_id)) {
|
2017-06-21 12:10:22 +00:00
|
|
|
$self->{canvas}->volumes->move_volume_up($volume_id);
|
2017-05-20 20:02:04 +00:00
|
|
|
$self->{parts_changed} = 1;
|
|
|
|
$self->reload_tree($volume_id - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
sub on_btn_move_down {
|
|
|
|
my ($self) = @_;
|
|
|
|
my $itemData = $self->get_selection;
|
|
|
|
if ($itemData && $itemData->{type} eq 'volume') {
|
|
|
|
my $volume_id = $itemData->{volume_id};
|
|
|
|
if ($self->{model_object}->move_volume_down($volume_id)) {
|
2017-06-21 12:10:22 +00:00
|
|
|
$self->{canvas}->volumes->move_volume_down($volume_id);
|
2017-05-20 20:02:04 +00:00
|
|
|
$self->{parts_changed} = 1;
|
|
|
|
$self->reload_tree($volume_id + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
sub on_btn_delete {
|
|
|
|
my ($self) = @_;
|
2016-11-27 01:55:43 +00:00
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
my $itemData = $self->get_selection;
|
|
|
|
if ($itemData && $itemData->{type} eq 'volume') {
|
|
|
|
my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
|
2016-11-27 01:55:43 +00:00
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
# if user is deleting the last solid part, throw error
|
|
|
|
if (!$volume->modifier && scalar(grep !$_->modifier, @{$self->{model_object}->volumes}) == 1) {
|
|
|
|
Slic3r::GUI::show_error($self, "You can't delete the last solid part from this object.");
|
|
|
|
return;
|
|
|
|
}
|
2016-11-27 01:55:43 +00:00
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
$self->{model_object}->delete_volume($itemData->{volume_id});
|
2014-03-23 15:45:55 +00:00
|
|
|
$self->{parts_changed} = 1;
|
2014-01-22 20:09:32 +00:00
|
|
|
}
|
|
|
|
|
2014-12-27 23:16:15 +00:00
|
|
|
$self->_parts_changed;
|
|
|
|
}
|
|
|
|
|
2017-06-15 13:38:15 +00:00
|
|
|
sub on_btn_split {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
my $itemData = $self->get_selection;
|
|
|
|
if ($itemData && $itemData->{type} eq 'volume') {
|
|
|
|
my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
|
2018-05-07 14:13:58 +00:00
|
|
|
my $nozzle_dmrs = $self->GetParent->GetParent->GetParent->{config}->get('nozzle_diameter');
|
|
|
|
$self->{parts_changed} = 1 if $volume->split(scalar(@$nozzle_dmrs)) > 1;
|
2017-06-15 13:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$self->_parts_changed;
|
|
|
|
}
|
|
|
|
|
2014-12-27 23:16:15 +00:00
|
|
|
sub _parts_changed {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
2014-01-22 20:09:32 +00:00
|
|
|
$self->reload_tree;
|
2014-02-11 00:08:41 +00:00
|
|
|
if ($self->{canvas}) {
|
2018-05-18 12:08:59 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
Slic3r::GUI::_3DScene::reset_volumes($self->{canvas});
|
|
|
|
# $self->{canvas}->reset_objects;
|
|
|
|
#==============================================================================================================================
|
2014-02-11 00:08:41 +00:00
|
|
|
$self->{canvas}->load_object($self->{model_object});
|
2014-12-27 23:16:15 +00:00
|
|
|
$self->{canvas}->zoom_to_volumes;
|
2018-04-05 13:55:50 +00:00
|
|
|
$self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
|
2014-02-11 00:08:41 +00:00
|
|
|
$self->{canvas}->Render;
|
|
|
|
}
|
2014-01-08 18:36:41 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 16:41:14 +00:00
|
|
|
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
|
2017-10-27 16:52:35 +00:00
|
|
|
my $config = $self->GetParent->GetParent->GetParent->GetParent->GetParent->config->clone;
|
2014-03-22 16:41:14 +00:00
|
|
|
eval {
|
2017-10-27 16:52:35 +00:00
|
|
|
$config->apply($self->model_object->config);
|
2014-03-22 16:41:14 +00:00
|
|
|
$config->validate;
|
|
|
|
};
|
2017-10-27 16:52:35 +00:00
|
|
|
return ! Slic3r::GUI::catch_error($self);
|
2014-03-22 16:41:14 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 08:47:04 +00:00
|
|
|
#=============================================================================================================================
|
|
|
|
sub Destroy {
|
|
|
|
my ($self) = @_;
|
|
|
|
$self->{canvas}->Destroy if ($self->{canvas});
|
|
|
|
}
|
|
|
|
#=============================================================================================================================
|
|
|
|
|
2014-03-23 15:45:55 +00:00
|
|
|
sub PartsChanged {
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{parts_changed};
|
|
|
|
}
|
|
|
|
|
|
|
|
sub PartSettingsChanged {
|
|
|
|
my ($self) = @_;
|
|
|
|
return $self->{part_settings_changed};
|
|
|
|
}
|
|
|
|
|
2018-04-05 13:55:50 +00:00
|
|
|
sub _update_canvas {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
if ($self->{canvas}) {
|
2018-05-18 12:08:59 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
Slic3r::GUI::_3DScene::reset_volumes($self->{canvas});
|
|
|
|
# $self->{canvas}->reset_objects;
|
|
|
|
#==============================================================================================================================
|
2018-04-05 13:55:50 +00:00
|
|
|
$self->{canvas}->load_object($self->{model_object});
|
|
|
|
|
|
|
|
# restore selection, if any
|
|
|
|
if (my $itemData = $self->get_selection) {
|
|
|
|
if ($itemData->{type} eq 'volume') {
|
|
|
|
$self->{canvas}->volumes->[ $itemData->{volume_id} ]->set_selected(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
|
|
|
|
$self->{canvas}->Render;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-27 01:55:43 +00:00
|
|
|
sub _update {
|
|
|
|
my ($self) = @_;
|
|
|
|
my ($m_x, $m_y, $m_z) = ($self->{move_options}{x}, $self->{move_options}{y}, $self->{move_options}{z});
|
|
|
|
my ($l_x, $l_y, $l_z) = ($self->{last_coords}{x}, $self->{last_coords}{y}, $self->{last_coords}{z});
|
|
|
|
|
|
|
|
my $itemData = $self->get_selection;
|
|
|
|
if ($itemData && $itemData->{type} eq 'volume') {
|
|
|
|
my $d = Slic3r::Pointf3->new($m_x - $l_x, $m_y - $l_y, $m_z - $l_z);
|
|
|
|
my $volume = $self->{model_object}->volumes->[$itemData->{volume_id}];
|
|
|
|
$volume->mesh->translate(@{$d});
|
|
|
|
$self->{last_coords}{x} = $m_x;
|
|
|
|
$self->{last_coords}{y} = $m_y;
|
|
|
|
$self->{last_coords}{z} = $m_z;
|
|
|
|
}
|
|
|
|
|
2016-11-27 04:13:55 +00:00
|
|
|
$self->{parts_changed} = 1;
|
2016-11-27 01:55:43 +00:00
|
|
|
my @objects = ();
|
|
|
|
push @objects, $self->{model_object};
|
2018-05-18 12:08:59 +00:00
|
|
|
#==============================================================================================================================
|
|
|
|
Slic3r::GUI::_3DScene::reset_volumes($self->{canvas});
|
|
|
|
# $self->{canvas}->reset_objects;
|
|
|
|
#==============================================================================================================================
|
2016-11-27 01:55:43 +00:00
|
|
|
$self->{canvas}->load_object($_, undef, [0]) for @objects;
|
2018-04-05 13:55:50 +00:00
|
|
|
$self->{canvas}->update_volumes_colors_by_extruder($self->GetParent->GetParent->GetParent->{config});
|
2016-11-27 01:55:43 +00:00
|
|
|
$self->{canvas}->Render;
|
|
|
|
}
|
|
|
|
|
2014-01-08 18:36:41 +00:00
|
|
|
1;
|