mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-24 23:23:59 -06:00
Refactoring: make Slic3r::GUI::3DScene::Base model-independent
This commit is contained in:
parent
28d7b0dba6
commit
9c8f8f8ded
3 changed files with 130 additions and 88 deletions
|
@ -10,8 +10,6 @@ use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL);
|
|||
use Wx::Event qw();
|
||||
use base qw(Slic3r::GUI::3DScene Class::Accessor);
|
||||
|
||||
__PACKAGE__->mk_accessors(qw(_volumes _volumes_inv));
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
my ($parent, $objects, $model, $config) = @_;
|
||||
|
@ -31,8 +29,8 @@ sub new {
|
|||
|
||||
my $obj_idx = undef;
|
||||
if ($volume_idx != -1) {
|
||||
$obj_idx = $self->_volumes_inv->{$volume_idx};
|
||||
$self->volumes->[$_]->selected(1) for @{$self->_volumes->{$obj_idx}};
|
||||
$obj_idx = $self->object_idx($volume_idx);
|
||||
$self->volumes->[$_]->selected(1) for @{$self->volumes_by_object->{$obj_idx}};
|
||||
$self->Refresh;
|
||||
}
|
||||
$self->{on_select_object}->($obj_idx)
|
||||
|
@ -41,22 +39,23 @@ sub new {
|
|||
$self->on_hover(sub {
|
||||
my ($volume_idx) = @_;
|
||||
|
||||
my $obj_idx = $self->_volumes_inv->{$volume_idx};
|
||||
$self->volumes->[$_]->hover(1) for @{$self->_volumes->{$obj_idx}};
|
||||
my $obj_idx = $self->object_idx($volume_idx);
|
||||
$self->volumes->[$_]->hover(1) for @{$self->volumes_by_object->{$obj_idx}};
|
||||
});
|
||||
$self->on_move(sub {
|
||||
my ($volume_idx) = @_;
|
||||
|
||||
my $volume = $self->volumes->[$volume_idx];
|
||||
my $obj_idx = $self->_volumes_inv->{$volume_idx};
|
||||
my $obj_idx = $self->object_idx($volume_idx);
|
||||
my $instance_idx = $self->instance_idx($volume_idx);
|
||||
my $model_object = $self->{model}->get_object($obj_idx);
|
||||
$model_object
|
||||
->instances->[$volume->instance_idx]
|
||||
->instances->[$instance_idx]
|
||||
->offset
|
||||
->translate($volume->origin->x, $volume->origin->y); #))
|
||||
$model_object->invalidate_bounding_box;
|
||||
|
||||
$self->{on_instance_moved}->($obj_idx, $volume->instance_idx)
|
||||
$self->{on_instance_moved}->($obj_idx, $instance_idx)
|
||||
if $self->{on_instance_moved};
|
||||
});
|
||||
|
||||
|
@ -86,19 +85,11 @@ sub set_on_instance_moved {
|
|||
sub update {
|
||||
my ($self) = @_;
|
||||
|
||||
$self->_volumes({}); # obj_idx => [ volume_idx, volume_idx ]
|
||||
$self->_volumes_inv({}); # volume_idx => obj_idx
|
||||
$self->reset_objects;
|
||||
|
||||
$self->update_bed_size;
|
||||
|
||||
foreach my $obj_idx (0..$#{$self->{model}->objects}) {
|
||||
my $model_object = $self->{model}->get_object($obj_idx);
|
||||
my @volume_idxs = $self->load_object($model_object, 1);
|
||||
|
||||
# store mapping between canvas volumes and model objects
|
||||
$self->_volumes->{$obj_idx} = [ @volume_idxs ];
|
||||
$self->_volumes_inv->{$_} = $obj_idx for @volume_idxs;
|
||||
my @volume_idxs = $self->load_object($self->{model}, $obj_idx);
|
||||
|
||||
if ($self->{objects}[$obj_idx]->selected) {
|
||||
$self->select_volume($_) for @volume_idxs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue