2014-07-13 10:10:34 +00:00
|
|
|
package Slic3r::GUI::Plater::3D;
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
use utf8;
|
|
|
|
|
|
|
|
use List::Util qw();
|
|
|
|
use Slic3r::Geometry qw();
|
|
|
|
use Slic3r::Geometry::Clipper qw();
|
|
|
|
use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL);
|
|
|
|
use Wx::Event qw();
|
2015-01-09 00:30:04 +00:00
|
|
|
use base qw(Slic3r::GUI::3DScene Class::Accessor);
|
2015-01-09 00:18:47 +00:00
|
|
|
|
2014-07-13 10:10:34 +00:00
|
|
|
sub new {
|
|
|
|
my $class = shift;
|
|
|
|
my ($parent, $objects, $model, $config) = @_;
|
|
|
|
|
|
|
|
my $self = $class->SUPER::new($parent);
|
2014-12-13 19:41:03 +00:00
|
|
|
$self->enable_picking(1);
|
2014-12-16 00:12:37 +00:00
|
|
|
$self->enable_moving(1);
|
2014-07-13 10:10:34 +00:00
|
|
|
|
|
|
|
$self->{objects} = $objects;
|
|
|
|
$self->{model} = $model;
|
|
|
|
$self->{config} = $config;
|
|
|
|
$self->{on_select_object} = sub {};
|
2014-12-16 00:12:37 +00:00
|
|
|
$self->{on_instance_moved} = sub {};
|
2014-12-13 23:54:35 +00:00
|
|
|
|
|
|
|
$self->on_select(sub {
|
|
|
|
my ($volume_idx) = @_;
|
|
|
|
|
|
|
|
my $obj_idx = undef;
|
|
|
|
if ($volume_idx != -1) {
|
2015-01-13 16:25:56 +00:00
|
|
|
$obj_idx = $self->object_idx($volume_idx);
|
|
|
|
$self->volumes->[$_]->selected(1) for @{$self->volumes_by_object->{$obj_idx}};
|
2014-12-13 23:54:35 +00:00
|
|
|
$self->Refresh;
|
|
|
|
}
|
|
|
|
$self->{on_select_object}->($obj_idx)
|
|
|
|
if $self->{on_select_object};
|
|
|
|
});
|
|
|
|
$self->on_hover(sub {
|
|
|
|
my ($volume_idx) = @_;
|
|
|
|
|
2015-01-13 16:25:56 +00:00
|
|
|
my $obj_idx = $self->object_idx($volume_idx);
|
|
|
|
$self->volumes->[$_]->hover(1) for @{$self->volumes_by_object->{$obj_idx}};
|
2014-12-13 23:54:35 +00:00
|
|
|
});
|
2014-12-16 00:12:37 +00:00
|
|
|
$self->on_move(sub {
|
|
|
|
my ($volume_idx) = @_;
|
|
|
|
|
|
|
|
my $volume = $self->volumes->[$volume_idx];
|
2015-01-13 16:25:56 +00:00
|
|
|
my $obj_idx = $self->object_idx($volume_idx);
|
|
|
|
my $instance_idx = $self->instance_idx($volume_idx);
|
2014-12-16 00:12:37 +00:00
|
|
|
my $model_object = $self->{model}->get_object($obj_idx);
|
|
|
|
$model_object
|
2015-01-13 16:25:56 +00:00
|
|
|
->instances->[$instance_idx]
|
2014-12-16 00:12:37 +00:00
|
|
|
->offset
|
|
|
|
->translate($volume->origin->x, $volume->origin->y); #))
|
|
|
|
$model_object->invalidate_bounding_box;
|
|
|
|
|
2015-01-13 16:25:56 +00:00
|
|
|
$self->{on_instance_moved}->($obj_idx, $instance_idx)
|
2014-12-16 00:12:37 +00:00
|
|
|
if $self->{on_instance_moved};
|
|
|
|
});
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
sub set_on_instance_moved {
|
|
|
|
my ($self, $cb) = @_;
|
2014-12-16 00:12:37 +00:00
|
|
|
$self->{on_instance_moved} = $cb;
|
2014-12-13 19:41:03 +00:00
|
|
|
}
|
|
|
|
|
2014-07-13 10:10:34 +00:00
|
|
|
sub update {
|
|
|
|
my ($self) = @_;
|
|
|
|
|
|
|
|
$self->reset_objects;
|
2014-12-16 00:12:37 +00:00
|
|
|
$self->update_bed_size;
|
2014-07-13 10:10:34 +00:00
|
|
|
|
2014-12-13 19:41:03 +00:00
|
|
|
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
|
2015-01-13 16:25:56 +00:00
|
|
|
my @volume_idxs = $self->load_object($self->{model}, $obj_idx);
|
2014-12-13 19:41:03 +00:00
|
|
|
|
2014-12-13 23:54:35 +00:00
|
|
|
if ($self->{objects}[$obj_idx]->selected) {
|
2014-12-13 19:41:03 +00:00
|
|
|
$self->select_volume($_) for @volume_idxs;
|
|
|
|
}
|
2014-07-13 10:10:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-16 00:12:37 +00:00
|
|
|
sub update_bed_size {
|
|
|
|
my ($self) = @_;
|
|
|
|
$self->set_bed_shape($self->{config}->bed_shape);
|
|
|
|
}
|
|
|
|
|
2014-12-13 19:41:03 +00:00
|
|
|
1;
|