Memory optimization in PreviewCanvas: don't keep additional meshes in memory when not needed
This commit is contained in:
parent
64c9e3af4b
commit
4c7d9dfef5
3 changed files with 23 additions and 16 deletions
|
@ -8,7 +8,9 @@ use Slic3r::Geometry qw();
|
|||
use Slic3r::Geometry::Clipper qw();
|
||||
use Wx qw(:misc :pen :brush :sizer :font :cursor wxTAB_TRAVERSAL);
|
||||
use Wx::Event qw();
|
||||
use base 'Slic3r::GUI::PreviewCanvas';
|
||||
use base qw(Slic3r::GUI::PreviewCanvas Class::Accessor);
|
||||
|
||||
__PACKAGE__->mk_accessors(qw(_volumes _volumes_inv));
|
||||
|
||||
sub new {
|
||||
my $class = shift;
|
||||
|
@ -29,8 +31,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->_volumes_inv->{$volume_idx};
|
||||
$self->volumes->[$_]->selected(1) for @{$self->_volumes->{$obj_idx}};
|
||||
$self->Refresh;
|
||||
}
|
||||
$self->{on_select_object}->($obj_idx)
|
||||
|
@ -39,14 +41,14 @@ 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->_volumes_inv->{$volume_idx};
|
||||
$self->volumes->[$_]->hover(1) for @{$self->_volumes->{$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->_volumes_inv->{$volume_idx};
|
||||
my $model_object = $self->{model}->get_object($obj_idx);
|
||||
$model_object
|
||||
->instances->[$volume->instance_idx]
|
||||
|
@ -84,8 +86,8 @@ 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->_volumes({}); # obj_idx => [ volume_idx, volume_idx ]
|
||||
$self->_volumes_inv({}); # volume_idx => obj_idx
|
||||
$self->reset_objects;
|
||||
|
||||
$self->update_bed_size;
|
||||
|
@ -95,8 +97,8 @@ sub update {
|
|||
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;
|
||||
$self->_volumes->{$obj_idx} = [ @volume_idxs ];
|
||||
$self->_volumes_inv->{$_} = $obj_idx for @volume_idxs;
|
||||
|
||||
if ($self->{objects}[$obj_idx]->selected) {
|
||||
$self->select_volume($_) for @volume_idxs;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue