Some initial work for adapting plater to the new centering workflow
This commit is contained in:
parent
250608aa52
commit
4993b12799
2 changed files with 30 additions and 15 deletions
|
@ -864,6 +864,8 @@ sub clean_instance_thumbnails {
|
||||||
sub recenter {
|
sub recenter {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
|
|
||||||
|
$self->{model}->center_instances_around_point($self->{config}->print_center);
|
||||||
|
return;
|
||||||
return unless @{$self->{objects}};
|
return unless @{$self->{objects}};
|
||||||
|
|
||||||
# get model bounding box in pixels
|
# get model bounding box in pixels
|
||||||
|
@ -976,7 +978,6 @@ sub repaint {
|
||||||
my $thumbnail = $object->transformed_thumbnail->clone; # in scaled coordinates
|
my $thumbnail = $object->transformed_thumbnail->clone; # in scaled coordinates
|
||||||
$thumbnail->scale(&Slic3r::SCALING_FACTOR * $parent->{scaling_factor}); # in unscaled pixels
|
$thumbnail->scale(&Slic3r::SCALING_FACTOR * $parent->{scaling_factor}); # in unscaled pixels
|
||||||
$thumbnail->translate(map $_ * $parent->{scaling_factor}, @{$instance->offset});
|
$thumbnail->translate(map $_ * $parent->{scaling_factor}, @{$instance->offset});
|
||||||
$thumbnail->translate(@{$parent->{shift}});
|
|
||||||
|
|
||||||
$object->instance_thumbnails->[$instance_idx] = $thumbnail;
|
$object->instance_thumbnails->[$instance_idx] = $thumbnail;
|
||||||
|
|
||||||
|
@ -989,7 +990,7 @@ sub repaint {
|
||||||
}
|
}
|
||||||
foreach my $expolygon (@$thumbnail) {
|
foreach my $expolygon (@$thumbnail) {
|
||||||
my $points = $expolygon->contour->pp;
|
my $points = $expolygon->contour->pp;
|
||||||
$dc->DrawPolygon($parent->_y($points), 0, 0);
|
$dc->DrawPolygon($parent->points_to_pixel($points), 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0) {
|
if (0) {
|
||||||
|
@ -1021,7 +1022,7 @@ sub repaint {
|
||||||
my ($convex_hull) = @{offset([convex_hull(\@points)], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)};
|
my ($convex_hull) = @{offset([convex_hull(\@points)], $parent->{config}->skirt_distance * $parent->{scaling_factor}, 100, JT_ROUND)};
|
||||||
$dc->SetPen($parent->{skirt_pen});
|
$dc->SetPen($parent->{skirt_pen});
|
||||||
$dc->SetBrush($parent->{transparent_brush});
|
$dc->SetBrush($parent->{transparent_brush});
|
||||||
$dc->DrawPolygon($parent->_y($convex_hull), 0, 0);
|
$dc->DrawPolygon($parent->points_to_pixel($convex_hull), 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1033,7 +1034,8 @@ sub mouse_event {
|
||||||
my $parent = $self->GetParent;
|
my $parent = $self->GetParent;
|
||||||
|
|
||||||
my $point = $event->GetPosition;
|
my $point = $event->GetPosition;
|
||||||
my $pos = Slic3r::Point->new(@{$parent->_y([[$point->x, $point->y]])->[0]}); # in pixels
|
my $pos = $parent->point_to_model_units([ $point->x, $point->y ]); #]] in pixels
|
||||||
|
$pos = Slic3r::Point->new_scale(@$pos);
|
||||||
if ($event->ButtonDown(&Wx::wxMOUSE_BTN_LEFT)) {
|
if ($event->ButtonDown(&Wx::wxMOUSE_BTN_LEFT)) {
|
||||||
$parent->select_object(undef);
|
$parent->select_object(undef);
|
||||||
for my $obj_idx (0 .. $#{$parent->{objects}}) {
|
for my $obj_idx (0 .. $#{$parent->{objects}}) {
|
||||||
|
@ -1243,21 +1245,32 @@ sub statusbar {
|
||||||
return $self->skeinpanel->GetParent->{statusbar};
|
return $self->skeinpanel->GetParent->{statusbar};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub to_pixel {
|
# convert a model coordinate into a pixel coordinate, assuming preview has square shape
|
||||||
my $self = shift;
|
sub point_to_pixel {
|
||||||
return $_[0] * $self->{scaling_factor} * &Slic3r::SCALING_FACTOR;
|
my ($self, $point) = @_;
|
||||||
|
|
||||||
|
my $canvas_height = $self->{canvas}->GetSize->GetHeight;
|
||||||
|
|
||||||
|
return [
|
||||||
|
$point->[X] * $self->{scaling_factor} + (0),
|
||||||
|
$canvas_height - ($point->[Y] * $self->{scaling_factor} + (0)),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub to_units {
|
sub points_to_pixel {
|
||||||
my $self = shift;
|
my ($self, $points) = @_;
|
||||||
return $_[0] / $self->{scaling_factor} / &Slic3r::SCALING_FACTOR;
|
return [ map $self->point_to_pixel($_), @$points ];
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _y {
|
sub point_to_model_units {
|
||||||
my $self = shift;
|
my ($self, $point) = @_;
|
||||||
my ($points) = @_;
|
|
||||||
my $height = $self->{canvas}->GetSize->GetHeight;
|
my $canvas_height = $self->{canvas}->GetSize->GetHeight;
|
||||||
return [ map [ $_->[X], $height - $_->[Y] ], @$points ];
|
|
||||||
|
return [
|
||||||
|
$point->[X] / $self->{scaling_factor},
|
||||||
|
$canvas_height - ($point->[X] / $self->{scaling_factor}),
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
package Slic3r::GUI::Plater::DropTarget;
|
package Slic3r::GUI::Plater::DropTarget;
|
||||||
|
|
|
@ -227,6 +227,8 @@ sub center_instances_around_point {
|
||||||
my ($self, $point) = @_;
|
my ($self, $point) = @_;
|
||||||
|
|
||||||
my $bb = $self->bounding_box;
|
my $bb = $self->bounding_box;
|
||||||
|
return if !defined $bb;
|
||||||
|
|
||||||
my $size = $bb->size;
|
my $size = $bb->size;
|
||||||
my @shift = (
|
my @shift = (
|
||||||
-$bb->x_min + $point->[X] - $size->[X]/2,
|
-$bb->x_min + $point->[X] - $size->[X]/2,
|
||||||
|
|
Loading…
Reference in a new issue