Fix preview after rotation in plater

This commit is contained in:
Alessandro Ranellucci 2012-11-19 17:39:16 +01:00
parent 99c942b5ea
commit 5678cd562c
3 changed files with 19 additions and 14 deletions

View file

@ -416,6 +416,9 @@ sub rotate {
my ($obj_idx, $object) = $self->selected_object;
# we need thumbnail to be computed before allowing rotation
return if !$object->thumbnail;
if (!defined $angle) {
$angle = Wx::GetNumberFromUser("", "Enter the rotation angle:", "Rotate", $object->rotate, -364, 364, $self);
return if !$angle || $angle == -1;
@ -446,7 +449,7 @@ sub arrange {
my $total_parts = sum(map $_->instances_count, @{$self->{objects}}) or return;
my @size = ();
for my $a (X,Y) {
$size[$a] = max(map $_->rotated_size->[$a], @{$self->{objects}});
$size[$a] = max(map $_->size->[$a], @{$self->{objects}});
}
eval {
@ -756,7 +759,7 @@ sub recenter {
my $obj = $_;
map {
my $instance = $_;
$instance, [ map $instance->[$_] + $obj->rotated_size->[$_], X,Y ];
$instance, [ map $instance->[$_] + $obj->size->[$_], X,Y ];
} @{$obj->instances};
} @{$self->{objects}},
]);
@ -1059,6 +1062,7 @@ has 'scale' => (is => 'rw', default => sub { 1 });
has 'rotate' => (is => 'rw', default => sub { 0 });
has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis
has 'thumbnail' => (is => 'rw');
has 'thumbnail_scaling_factor' => (is => 'rw');
# statistics
has 'facets' => (is => 'rw');
@ -1111,6 +1115,7 @@ sub make_thumbnail {
my @points = map [ @$_[X,Y] ], @{$self->model_object->mesh->vertices};
my $convex_hull = Slic3r::Polygon->new(convex_hull(\@points));
$self->thumbnail_scaling_factor($params{scaling_factor});
for (@$convex_hull) {
@$_ = map $_ * $params{scaling_factor}, @$_;
}
@ -1132,6 +1137,8 @@ sub set_rotation {
if ($self->thumbnail) {
$self->thumbnail->rotate(Slic3r::Geometry::deg2rad($angle - $self->rotate));
$self->thumbnail->align_to_origin;
my $z_size = $self->size->[Z];
$self->size([ (map $_ / $self->thumbnail_scaling_factor, @{$self->thumbnail->size}), $z_size ]);
}
$self->rotate($angle);
}
@ -1150,14 +1157,6 @@ sub set_scale {
$self->scale($scale);
}
sub rotated_size {
my $self = shift;
return Slic3r::Polygon->new([0,0], [$self->size->[X], 0], [@{$self->size}], [0, $self->size->[Y]])
->rotate(Slic3r::Geometry::deg2rad($self->rotate))
->size;
}
package Slic3r::GUI::Plater::ObjectInfoDialog;
use Wx qw(:dialog :id :misc :sizer :systemsettings);
use Wx::Event qw(EVT_BUTTON EVT_TEXT_ENTER);