2014-07-13 10:10:34 +00:00
|
|
|
|
package Slic3r::GUI::Plater::3D;
|
|
|
|
|
use strict;
|
|
|
|
|
use warnings;
|
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
|
|
use List::Util qw();
|
2017-07-21 14:29:40 +00:00
|
|
|
|
use Wx qw(:misc :pen :brush :sizer :font :cursor :keycode wxTAB_TRAVERSAL);
|
|
|
|
|
use Wx::Event qw(EVT_KEY_DOWN EVT_CHAR);
|
2015-01-09 00:30:04 +00:00
|
|
|
|
use base qw(Slic3r::GUI::3DScene Class::Accessor);
|
2015-01-09 00:18:47 +00:00
|
|
|
|
|
2018-03-09 09:40:42 +00:00
|
|
|
|
use Wx::Locale gettext => 'L';
|
|
|
|
|
|
2017-07-21 14:29:40 +00:00
|
|
|
|
__PACKAGE__->mk_accessors(qw(
|
2017-11-30 16:45:03 +00:00
|
|
|
|
on_arrange on_rotate_object_left on_rotate_object_right on_scale_object_uniformly
|
2018-03-21 14:21:03 +00:00
|
|
|
|
on_remove_object on_increase_objects on_decrease_objects on_enable_action_buttons));
|
2017-07-21 14:29:40 +00:00
|
|
|
|
|
2014-07-13 10:10:34 +00:00
|
|
|
|
sub new {
|
|
|
|
|
my $class = shift;
|
2016-12-12 17:02:24 +00:00
|
|
|
|
my ($parent, $objects, $model, $print, $config) = @_;
|
2014-07-13 10:10:34 +00:00
|
|
|
|
|
|
|
|
|
my $self = $class->SUPER::new($parent);
|
2018-05-22 07:02:42 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::enable_picking($self, 1);
|
2018-05-31 11:51:50 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::enable_moving($self, 1);
|
2018-05-22 07:02:42 +00:00
|
|
|
|
# $self->enable_picking(1);
|
2018-05-31 11:51:50 +00:00
|
|
|
|
# $self->enable_moving(1);
|
2018-05-22 07:02:42 +00:00
|
|
|
|
#==============================================================================================================================
|
2015-01-13 17:41:23 +00:00
|
|
|
|
$self->select_by('object');
|
|
|
|
|
$self->drag_by('instance');
|
2014-07-13 10:10:34 +00:00
|
|
|
|
|
|
|
|
|
$self->{objects} = $objects;
|
|
|
|
|
$self->{model} = $model;
|
2016-12-12 17:02:24 +00:00
|
|
|
|
$self->{print} = $print;
|
2014-07-13 10:10:34 +00:00
|
|
|
|
$self->{config} = $config;
|
2018-05-23 09:14:49 +00:00
|
|
|
|
#==============================================================================================================================
|
2018-05-28 13:23:01 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::set_print($self, $print);
|
2018-05-23 09:14:49 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::set_config($self, $config);
|
|
|
|
|
#==============================================================================================================================
|
2014-07-13 10:10:34 +00:00
|
|
|
|
$self->{on_select_object} = sub {};
|
2015-01-13 17:41:23 +00:00
|
|
|
|
$self->{on_instances_moved} = sub {};
|
2017-05-19 19:48:32 +00:00
|
|
|
|
$self->{on_wipe_tower_moved} = sub {};
|
2018-05-02 11:55:04 +00:00
|
|
|
|
|
2018-05-11 14:03:07 +00:00
|
|
|
|
$self->{objects_volumes_idxs} = [];
|
2018-05-02 11:55:04 +00:00
|
|
|
|
|
2018-06-04 13:42:34 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::register_on_select_callback($self, sub {
|
2014-12-13 23:54:35 +00:00
|
|
|
|
my ($volume_idx) = @_;
|
2017-05-17 14:53:40 +00:00
|
|
|
|
$self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
|
|
|
|
|
if ($self->{on_select_object});
|
2018-06-04 13:42:34 +00:00
|
|
|
|
});
|
|
|
|
|
# $self->on_select(sub {
|
|
|
|
|
# my ($volume_idx) = @_;
|
|
|
|
|
# $self->{on_select_object}->(($volume_idx == -1) ? undef : $self->volumes->[$volume_idx]->object_idx)
|
|
|
|
|
# if ($self->{on_select_object});
|
|
|
|
|
# });
|
2018-05-31 11:51:50 +00:00
|
|
|
|
#==============================================================================================================================
|
2018-05-31 14:04:59 +00:00
|
|
|
|
|
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::register_on_move_callback($self, sub {
|
|
|
|
|
# $self->on_move(sub {
|
|
|
|
|
#==============================================================================================================================
|
2015-01-13 17:41:23 +00:00
|
|
|
|
my @volume_idxs = @_;
|
2016-03-19 21:30:01 +00:00
|
|
|
|
my %done = (); # prevent moving instances twice
|
2017-05-19 19:48:32 +00:00
|
|
|
|
my $object_moved;
|
|
|
|
|
my $wipe_tower_moved;
|
2015-01-13 17:41:23 +00:00
|
|
|
|
foreach my $volume_idx (@volume_idxs) {
|
|
|
|
|
my $volume = $self->volumes->[$volume_idx];
|
2016-12-12 17:02:24 +00:00
|
|
|
|
my $obj_idx = $volume->object_idx;
|
|
|
|
|
my $instance_idx = $volume->instance_idx;
|
2016-03-19 21:30:01 +00:00
|
|
|
|
next if $done{"${obj_idx}_${instance_idx}"};
|
|
|
|
|
$done{"${obj_idx}_${instance_idx}"} = 1;
|
2017-05-17 14:53:40 +00:00
|
|
|
|
if ($obj_idx < 1000) {
|
|
|
|
|
# Move a regular object.
|
|
|
|
|
my $model_object = $self->{model}->get_object($obj_idx);
|
|
|
|
|
$model_object
|
|
|
|
|
->instances->[$instance_idx]
|
|
|
|
|
->offset
|
|
|
|
|
->translate($volume->origin->x, $volume->origin->y); #))
|
|
|
|
|
$model_object->invalidate_bounding_box;
|
2017-05-19 19:48:32 +00:00
|
|
|
|
$object_moved = 1;
|
2017-05-17 14:53:40 +00:00
|
|
|
|
} elsif ($obj_idx == 1000) {
|
|
|
|
|
# Move a wipe tower proxy.
|
2017-05-19 19:48:32 +00:00
|
|
|
|
$wipe_tower_moved = $volume->origin;
|
2017-05-17 14:53:40 +00:00
|
|
|
|
}
|
2015-01-13 17:41:23 +00:00
|
|
|
|
}
|
2014-12-16 00:12:37 +00:00
|
|
|
|
|
2015-01-13 17:41:23 +00:00
|
|
|
|
$self->{on_instances_moved}->()
|
2017-05-19 19:48:32 +00:00
|
|
|
|
if $object_moved && $self->{on_instances_moved};
|
|
|
|
|
$self->{on_wipe_tower_moved}->($wipe_tower_moved)
|
|
|
|
|
if $wipe_tower_moved && $self->{on_wipe_tower_moved};
|
2014-12-16 00:12:37 +00:00
|
|
|
|
});
|
2017-07-21 14:29:40 +00:00
|
|
|
|
|
|
|
|
|
EVT_KEY_DOWN($self, sub {
|
|
|
|
|
my ($s, $event) = @_;
|
|
|
|
|
if ($event->HasModifiers) {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
} else {
|
|
|
|
|
my $key = $event->GetKeyCode;
|
|
|
|
|
if ($key == WXK_DELETE) {
|
|
|
|
|
$self->on_remove_object->() if $self->on_remove_object;
|
|
|
|
|
} else {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
EVT_CHAR($self, sub {
|
|
|
|
|
my ($s, $event) = @_;
|
|
|
|
|
if ($event->HasModifiers) {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
} else {
|
|
|
|
|
my $key = $event->GetKeyCode;
|
2017-11-30 16:45:03 +00:00
|
|
|
|
if ($key == ord('a')) {
|
|
|
|
|
$self->on_arrange->() if $self->on_arrange;
|
|
|
|
|
} elsif ($key == ord('l')) {
|
2017-07-21 14:29:40 +00:00
|
|
|
|
$self->on_rotate_object_left->() if $self->on_rotate_object_left;
|
|
|
|
|
} elsif ($key == ord('r')) {
|
|
|
|
|
$self->on_rotate_object_right->() if $self->on_rotate_object_right;
|
|
|
|
|
} elsif ($key == ord('s')) {
|
|
|
|
|
$self->on_scale_object_uniformly->() if $self->on_scale_object_uniformly;
|
|
|
|
|
} elsif ($key == ord('+')) {
|
|
|
|
|
$self->on_increase_objects->() if $self->on_increase_objects;
|
|
|
|
|
} elsif ($key == ord('-')) {
|
|
|
|
|
$self->on_decrease_objects->() if $self->on_decrease_objects;
|
|
|
|
|
} else {
|
|
|
|
|
$event->Skip;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2014-07-13 10:10:34 +00:00
|
|
|
|
|
|
|
|
|
return $self;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-13 19:41:03 +00:00
|
|
|
|
sub set_on_select_object {
|
|
|
|
|
my ($self, $cb) = @_;
|
2014-12-13 23:54:35 +00:00
|
|
|
|
$self->{on_select_object} = $cb;
|
2014-12-13 19:41:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-31 11:51:50 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
#sub set_on_double_click {
|
|
|
|
|
# my ($self, $cb) = @_;
|
|
|
|
|
# $self->on_double_click($cb);
|
|
|
|
|
#}
|
|
|
|
|
#
|
|
|
|
|
#sub set_on_right_click {
|
|
|
|
|
# my ($self, $cb) = @_;
|
|
|
|
|
# $self->on_right_click($cb);
|
|
|
|
|
#}
|
|
|
|
|
#==============================================================================================================================
|
2014-12-13 19:41:03 +00:00
|
|
|
|
|
2017-11-30 16:45:03 +00:00
|
|
|
|
sub set_on_arrange {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_arrange($cb);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-21 14:29:40 +00:00
|
|
|
|
sub set_on_rotate_object_left {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_rotate_object_left($cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_on_rotate_object_right {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_rotate_object_right($cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_on_scale_object_uniformly {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_scale_object_uniformly($cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_on_increase_objects {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_increase_objects($cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_on_decrease_objects {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_decrease_objects($cb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sub set_on_remove_object {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_remove_object($cb);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-13 17:41:23 +00:00
|
|
|
|
sub set_on_instances_moved {
|
2014-12-13 19:41:03 +00:00
|
|
|
|
my ($self, $cb) = @_;
|
2015-01-13 17:41:23 +00:00
|
|
|
|
$self->{on_instances_moved} = $cb;
|
2014-12-13 19:41:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-19 19:48:32 +00:00
|
|
|
|
sub set_on_wipe_tower_moved {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->{on_wipe_tower_moved} = $cb;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-31 14:04:59 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
#sub set_on_model_update {
|
|
|
|
|
# my ($self, $cb) = @_;
|
|
|
|
|
# $self->on_model_update($cb);
|
|
|
|
|
#}
|
|
|
|
|
#==============================================================================================================================
|
2017-02-09 13:56:13 +00:00
|
|
|
|
|
2018-03-21 14:21:03 +00:00
|
|
|
|
sub set_on_enable_action_buttons {
|
|
|
|
|
my ($self, $cb) = @_;
|
|
|
|
|
$self->on_enable_action_buttons($cb);
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-02 11:55:04 +00:00
|
|
|
|
sub update_volumes_selection {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
|
|
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
|
|
|
|
|
if ($self->{objects}[$obj_idx]->selected) {
|
2018-05-11 14:03:07 +00:00
|
|
|
|
my $volume_idxs = $self->{objects_volumes_idxs}->[$obj_idx];
|
2018-05-25 07:03:55 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::select_volume($self, $_) for @{$volume_idxs};
|
|
|
|
|
# $self->select_volume($_) for @{$volume_idxs};
|
|
|
|
|
#==============================================================================================================================
|
2018-05-02 11:55:04 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 14:53:40 +00:00
|
|
|
|
sub reload_scene {
|
2017-05-31 15:05:11 +00:00
|
|
|
|
my ($self, $force) = @_;
|
2017-05-17 14:53:40 +00:00
|
|
|
|
|
2018-05-18 12:08:59 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::reset_volumes($self);
|
|
|
|
|
# $self->reset_objects;
|
|
|
|
|
#==============================================================================================================================
|
2014-12-16 00:12:37 +00:00
|
|
|
|
$self->update_bed_size;
|
2017-05-31 15:05:11 +00:00
|
|
|
|
|
|
|
|
|
if (! $self->IsShown && ! $force) {
|
|
|
|
|
$self->{reload_delayed} = 1;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$self->{reload_delayed} = 0;
|
|
|
|
|
|
2018-05-11 14:03:07 +00:00
|
|
|
|
$self->{objects_volumes_idxs} = [];
|
2014-12-13 19:41:03 +00:00
|
|
|
|
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
|
2016-12-12 17:02:24 +00:00
|
|
|
|
my @volume_idxs = $self->load_object($self->{model}, $self->{print}, $obj_idx);
|
2018-05-02 11:55:04 +00:00
|
|
|
|
push(@{$self->{objects_volumes_idxs}}, \@volume_idxs);
|
2014-07-13 10:10:34 +00:00
|
|
|
|
}
|
2018-05-02 11:55:04 +00:00
|
|
|
|
|
|
|
|
|
$self->update_volumes_selection;
|
|
|
|
|
|
2017-05-17 14:53:40 +00:00
|
|
|
|
if (defined $self->{config}->nozzle_diameter) {
|
|
|
|
|
# Should the wipe tower be visualized?
|
|
|
|
|
my $extruders_count = scalar @{ $self->{config}->nozzle_diameter };
|
|
|
|
|
# Height of a print.
|
|
|
|
|
my $height = $self->{model}->bounding_box->z_max;
|
|
|
|
|
# Show at least a slab.
|
|
|
|
|
$height = 10 if $height < 10;
|
|
|
|
|
if ($extruders_count > 1 && $self->{config}->single_extruder_multi_material && $self->{config}->wipe_tower &&
|
|
|
|
|
! $self->{config}->complete_objects) {
|
|
|
|
|
$self->volumes->load_wipe_tower_preview(1000,
|
2018-03-22 12:37:01 +00:00
|
|
|
|
$self->{config}->wipe_tower_x, $self->{config}->wipe_tower_y, $self->{config}->wipe_tower_width,
|
|
|
|
|
#$self->{config}->wipe_tower_per_color_wipe# 15 * ($extruders_count - 1), # this is just a hack when the config parameter became obsolete
|
|
|
|
|
15 * ($extruders_count - 1),
|
2018-06-04 11:52:57 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
$self->{model}->bounding_box->z_max, $self->{config}->wipe_tower_rotation_angle, Slic3r::GUI::_3DScene::use_VBOs());
|
|
|
|
|
# $self->{model}->bounding_box->z_max, $self->{config}->wipe_tower_rotation_angle, $self->UseVBOs);
|
|
|
|
|
#==============================================================================================================================
|
2017-05-17 14:53:40 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-05-29 13:07:06 +00:00
|
|
|
|
|
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::update_volumes_colors_by_extruder($self);
|
|
|
|
|
# $self->update_volumes_colors_by_extruder($self->{config});
|
|
|
|
|
#==============================================================================================================================
|
2018-04-05 10:52:29 +00:00
|
|
|
|
|
2018-03-09 09:40:42 +00:00
|
|
|
|
# checks for geometry outside the print volume to render it accordingly
|
|
|
|
|
if (scalar @{$self->volumes} > 0)
|
|
|
|
|
{
|
2018-04-24 07:00:33 +00:00
|
|
|
|
my $contained = $self->volumes->check_outside_state($self->{config});
|
|
|
|
|
if (!$contained) {
|
2018-05-21 12:40:09 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::enable_warning_texture($self, 1);
|
|
|
|
|
# $self->set_warning_enabled(1);
|
|
|
|
|
#==============================================================================================================================
|
2018-03-09 09:40:42 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::generate_warning_texture(L("Detected object outside print volume"));
|
2018-03-21 14:21:03 +00:00
|
|
|
|
$self->on_enable_action_buttons->(0) if ($self->on_enable_action_buttons);
|
2018-03-09 09:40:42 +00:00
|
|
|
|
} else {
|
2018-05-21 12:40:09 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::enable_warning_texture($self, 0);
|
|
|
|
|
# $self->set_warning_enabled(0);
|
|
|
|
|
#==============================================================================================================================
|
2018-04-24 07:00:33 +00:00
|
|
|
|
$self->volumes->reset_outside_state();
|
2018-03-09 09:40:42 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::reset_warning_texture();
|
2018-05-21 10:34:31 +00:00
|
|
|
|
$self->on_enable_action_buttons->(scalar @{$self->{model}->objects} > 0) if ($self->on_enable_action_buttons);
|
2018-03-09 09:40:42 +00:00
|
|
|
|
}
|
2018-04-10 12:12:16 +00:00
|
|
|
|
} else {
|
2018-05-21 12:40:09 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::enable_warning_texture($self, 0);
|
|
|
|
|
# $self->set_warning_enabled(0);
|
|
|
|
|
#==============================================================================================================================
|
2018-04-10 12:12:16 +00:00
|
|
|
|
Slic3r::GUI::_3DScene::reset_warning_texture();
|
2018-03-09 09:40:42 +00:00
|
|
|
|
}
|
2014-07-13 10:10:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
2014-12-16 00:12:37 +00:00
|
|
|
|
sub update_bed_size {
|
|
|
|
|
my ($self) = @_;
|
2018-05-15 13:38:25 +00:00
|
|
|
|
#==============================================================================================================================
|
|
|
|
|
Slic3r::GUI::_3DScene::set_bed_shape($self, $self->{config}->bed_shape);
|
|
|
|
|
# $self->set_bed_shape($self->{config}->bed_shape);
|
|
|
|
|
#==============================================================================================================================
|
2014-12-16 00:12:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-05-31 15:05:11 +00:00
|
|
|
|
# Called by the Platter wxNotebook when this page is activated.
|
|
|
|
|
sub OnActivate {
|
|
|
|
|
my ($self) = @_;
|
|
|
|
|
$self->reload_scene(1) if ($self->{reload_delayed});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
1;
|