More fixes for plater positioning. #1171

This commit is contained in:
Alessandro Ranellucci 2013-06-13 20:05:32 +02:00
parent 962a51cc80
commit 145fe08203

View File

@ -814,7 +814,7 @@ sub _update_bed_size {
# to constrain print bed area inside preview # to constrain print bed area inside preview
# when the canvas is not rendered yet, its GetSize() method returns 0,0 # when the canvas is not rendered yet, its GetSize() method returns 0,0
$self->{scaling_factor} = CANVAS_SIZE->[X] / max(@{ $self->{config}->bed_size }); $self->{scaling_factor} = CANVAS_SIZE->[X] / max(@{ $self->{config}->bed_size });
$_->change_thumbnail_scaling_factor($self->{scaling_factor}) for @{ $self->{objects} }; $_->thumbnail_scaling_factor($self->{scaling_factor}) for @{ $self->{objects} };
$self->recenter; $self->recenter;
} }
@ -1080,7 +1080,7 @@ has 'rotate' => (is => 'rw', default => sub { 0 }, trigger => \&_
has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis has 'instances' => (is => 'rw', default => sub { [] }); # upward Y axis
has 'thumbnail' => (is => 'rw', trigger => \&_transform_thumbnail); has 'thumbnail' => (is => 'rw', trigger => \&_transform_thumbnail);
has 'transformed_thumbnail' => (is => 'rw'); has 'transformed_thumbnail' => (is => 'rw');
has 'thumbnail_scaling_factor' => (is => 'rw'); has 'thumbnail_scaling_factor' => (is => 'rw', trigger => \&_transform_thumbnail);
has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ] has 'layer_height_ranges' => (is => 'rw', default => sub { [] }); # [ z_min, z_max, layer_height ]
# statistics # statistics
@ -1143,7 +1143,6 @@ sub make_thumbnail {
? $mesh->horizontal_projection ? $mesh->horizontal_projection
: [ Slic3r::ExPolygon->new(convex_hull($mesh->vertices)) ], : [ Slic3r::ExPolygon->new(convex_hull($mesh->vertices)) ],
); );
$thumbnail->scale($self->thumbnail_scaling_factor);
# only simplify expolygons larger than the threshold # only simplify expolygons larger than the threshold
@{$thumbnail->expolygons} = grep @$_, @{$thumbnail->expolygons} = grep @$_,
@ -1159,12 +1158,9 @@ sub make_thumbnail {
sub _transform_thumbnail { sub _transform_thumbnail {
my $self = shift; my $self = shift;
# the order of these transformations MUST be the same everywhere, including return unless $self->thumbnail;
# in Slic3r::Print->add_model() my $t = $self->_apply_transform($self->thumbnail);
my $t = $self->thumbnail $t->scale($self->thumbnail_scaling_factor);
->clone
->rotate(deg2rad($self->rotate), $self->bounding_box->center_2D->clone->scale($self->thumbnail_scaling_factor))
->scale($self->scale);
$self->transformed_thumbnail($t); $self->transformed_thumbnail($t);
} }
@ -1172,8 +1168,16 @@ sub _transform_thumbnail {
# bounding box with applied rotation and scaling # bounding box with applied rotation and scaling
sub transformed_bounding_box { sub transformed_bounding_box {
my $self = shift; my $self = shift;
return $self->_apply_transform($self->bounding_box);
}
sub _apply_transform {
my $self = shift;
my ($entity) = @_; # can be anything that implements ->clone(), ->rotate() and ->scale()
return $self->bounding_box # the order of these transformations MUST be the same everywhere, including
# in Slic3r::Print->add_model()
return $entity
->clone ->clone
->rotate(deg2rad($self->rotate), $self->bounding_box->center_2D) ->rotate(deg2rad($self->rotate), $self->bounding_box->center_2D)
->scale($self->scale); ->scale($self->scale);
@ -1184,14 +1188,4 @@ sub transformed_size {
return $self->transformed_bounding_box->size; return $self->transformed_bounding_box->size;
} }
sub change_thumbnail_scaling_factor {
my $self = shift;
my ($new_factor) = @_;
return unless $self->thumbnail;
$self->thumbnail->scale($new_factor / $self->thumbnail_scaling_factor);
$self->thumbnail_scaling_factor($new_factor);
$self->_transform_thumbnail;
}
1; 1;