mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-07 03:19:05 +08:00
Bugfix: the Bed Shape dialog didn't retain rectangle origin correctly. #2427
This commit is contained in:
parent
5639132dae
commit
ffff597bfe
@ -82,7 +82,6 @@ sub new {
|
|||||||
tooltip => 'Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.',
|
tooltip => 'Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.',
|
||||||
default => [0,0],
|
default => [0,0],
|
||||||
));
|
));
|
||||||
$optgroup->on_change->($_) for qw(rect_size rect_origin); # set defaults
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
my $optgroup = $self->_init_shape_options_page('Circular');
|
my $optgroup = $self->_init_shape_options_page('Circular');
|
||||||
@ -94,7 +93,6 @@ sub new {
|
|||||||
sidetext => 'mm',
|
sidetext => 'mm',
|
||||||
default => 200,
|
default => 200,
|
||||||
));
|
));
|
||||||
$optgroup->on_change->($_) for qw(diameter); # set defaults
|
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
my $optgroup = $self->_init_shape_options_page('Custom');
|
my $optgroup = $self->_init_shape_options_page('Custom');
|
||||||
@ -162,6 +160,7 @@ sub _set_shape {
|
|||||||
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
||||||
$optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]);
|
$optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]);
|
||||||
$optgroup->set_value('rect_origin', $origin);
|
$optgroup->set_value('rect_origin', $origin);
|
||||||
|
$self->_update_shape;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,16 +171,18 @@ sub _set_shape {
|
|||||||
my $center = $polygon->bounding_box->center;
|
my $center = $polygon->bounding_box->center;
|
||||||
my @vertex_distances = map $center->distance_to($_), @$polygon;
|
my @vertex_distances = map $center->distance_to($_), @$polygon;
|
||||||
my $avg_dist = sum(@vertex_distances)/@vertex_distances;
|
my $avg_dist = sum(@vertex_distances)/@vertex_distances;
|
||||||
if (!defined first { abs($_ - $avg_dist) > scaled_epsilon } @vertex_distances) {
|
if (!defined first { abs($_ - $avg_dist) > 10*scaled_epsilon } @vertex_distances) {
|
||||||
# all vertices are equidistant to center
|
# all vertices are equidistant to center
|
||||||
$self->{shape_options_book}->SetSelection(SHAPE_CIRCULAR);
|
$self->{shape_options_book}->SetSelection(SHAPE_CIRCULAR);
|
||||||
my $optgroup = $self->{optgroups}[SHAPE_CIRCULAR];
|
my $optgroup = $self->{optgroups}[SHAPE_CIRCULAR];
|
||||||
$optgroup->set_value('diameter', sprintf("%.0f", unscale($avg_dist*2)));
|
$optgroup->set_value('diameter', sprintf("%.0f", unscale($avg_dist*2)));
|
||||||
|
$self->_update_shape;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->{shape_options_book}->SetSelection(SHAPE_CUSTOM);
|
$self->{shape_options_book}->SetSelection(SHAPE_CUSTOM);
|
||||||
|
$self->_update_shape;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _update_shape {
|
sub _update_shape {
|
||||||
@ -189,13 +190,14 @@ sub _update_shape {
|
|||||||
|
|
||||||
my $page_idx = $self->{shape_options_book}->GetSelection;
|
my $page_idx = $self->{shape_options_book}->GetSelection;
|
||||||
if ($page_idx == SHAPE_RECTANGULAR) {
|
if ($page_idx == SHAPE_RECTANGULAR) {
|
||||||
return if grep !defined($self->{"_$_"}), qw(rect_size rect_origin); # not loaded yet
|
my $rect_size = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_size');
|
||||||
my ($x, $y) = @{$self->{_rect_size}};
|
my $rect_origin = $self->{optgroups}[SHAPE_RECTANGULAR]->get_value('rect_origin');
|
||||||
|
my ($x, $y) = @$rect_size;
|
||||||
return if !$x || !$y; # empty strings
|
return if !$x || !$y; # empty strings
|
||||||
my ($x0, $y0) = (0,0);
|
my ($x0, $y0) = (0,0);
|
||||||
my ($x1, $y1) = ($x,$y);
|
my ($x1, $y1) = ($x,$y);
|
||||||
{
|
{
|
||||||
my ($dx, $dy) = @{$self->{_rect_origin}};
|
my ($dx, $dy) = @$rect_origin;
|
||||||
return if $dx eq '' || $dy eq ''; # empty strings
|
return if $dx eq '' || $dy eq ''; # empty strings
|
||||||
$x0 -= $dx;
|
$x0 -= $dx;
|
||||||
$x1 -= $dx;
|
$x1 -= $dx;
|
||||||
@ -209,9 +211,9 @@ sub _update_shape {
|
|||||||
[$x0,$y1],
|
[$x0,$y1],
|
||||||
];
|
];
|
||||||
} elsif ($page_idx == SHAPE_CIRCULAR) {
|
} elsif ($page_idx == SHAPE_CIRCULAR) {
|
||||||
return if grep !defined($self->{"_$_"}), qw(diameter); # not loaded yet
|
my $diameter = $self->{optgroups}[SHAPE_CIRCULAR]->get_value('diameter');
|
||||||
return if !$self->{_diameter};
|
return if !$diameter;
|
||||||
my $r = $self->{_diameter}/2;
|
my $r = $diameter/2;
|
||||||
my $twopi = 2*PI;
|
my $twopi = 2*PI;
|
||||||
my $edges = 60;
|
my $edges = 60;
|
||||||
my $polygon = Slic3r::Polygon->new_scale(
|
my $polygon = Slic3r::Polygon->new_scale(
|
||||||
@ -366,7 +368,7 @@ sub _init_shape_options_page {
|
|||||||
label_width => 100,
|
label_width => 100,
|
||||||
on_change => sub {
|
on_change => sub {
|
||||||
my ($opt_id) = @_;
|
my ($opt_id) = @_;
|
||||||
$self->{"_$opt_id"} = $optgroup->get_value($opt_id);
|
#$self->{"_$opt_id"} = $optgroup->get_value($opt_id);
|
||||||
$self->_update_shape;
|
$self->_update_shape;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user