mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-03 12:04:05 -06:00
Allow configuration of G-code origin for rectangular bed shape
This commit is contained in:
parent
7aaf27c0c7
commit
06d700989f
1 changed files with 23 additions and 28 deletions
|
@ -76,12 +76,10 @@ sub new {
|
||||||
));
|
));
|
||||||
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
$optgroup->append_single_option_line(Slic3r::GUI::OptionsGroup::Option->new(
|
||||||
opt_id => 'rect_origin',
|
opt_id => 'rect_origin',
|
||||||
type => 'select',
|
type => 'point',
|
||||||
label => 'Origin',
|
label => 'Origin',
|
||||||
tooltip => 'Position of the 0,0 point.',
|
tooltip => 'Distance of the 0,0 G-code coordinate from the front left corner of the rectangle.',
|
||||||
labels => ['Front left corner','Center'],
|
default => [0,0],
|
||||||
values => ['corner','center'],
|
|
||||||
default => 'corner',
|
|
||||||
));
|
));
|
||||||
$optgroup->on_change->($_) for qw(rect_size rect_origin); # set defaults
|
$optgroup->on_change->($_) for qw(rect_size rect_origin); # set defaults
|
||||||
}
|
}
|
||||||
|
@ -147,24 +145,20 @@ sub _set_shape {
|
||||||
my $lines = $polygon->lines;
|
my $lines = $polygon->lines;
|
||||||
if ($lines->[0]->parallel_to_line($lines->[2]) && $lines->[1]->parallel_to_line($lines->[3])) {
|
if ($lines->[0]->parallel_to_line($lines->[2]) && $lines->[1]->parallel_to_line($lines->[3])) {
|
||||||
# okay, it's a rectangle
|
# okay, it's a rectangle
|
||||||
# let's check whether origin is at a known point
|
|
||||||
my $x_min = min(map $_->[X], @$points);
|
# find origin
|
||||||
my $x_max = max(map $_->[X], @$points);
|
# the || 0 hack prevents "-0" which might confuse the user
|
||||||
my $y_min = min(map $_->[Y], @$points);
|
my $x_min = min(map $_->[X], @$points) || 0;
|
||||||
my $y_max = max(map $_->[Y], @$points);
|
my $x_max = max(map $_->[X], @$points) || 0;
|
||||||
my $origin;
|
my $y_min = min(map $_->[Y], @$points) || 0;
|
||||||
if ($x_min == 0 && $y_min == 0) {
|
my $y_max = max(map $_->[Y], @$points) || 0;
|
||||||
$origin = 'corner';
|
my $origin = [-$x_min, -$y_min];
|
||||||
} elsif (($x_min + $x_max)/2 == 0 && ($y_min + $y_max)/2 == 0) {
|
|
||||||
$origin = 'center';
|
$self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR);
|
||||||
}
|
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
||||||
if (defined $origin) {
|
$optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]);
|
||||||
$self->{shape_options_book}->SetSelection(SHAPE_RECTANGULAR);
|
$optgroup->set_value('rect_origin', $origin);
|
||||||
my $optgroup = $self->{optgroups}[SHAPE_RECTANGULAR];
|
return;
|
||||||
$optgroup->set_value('rect_size', [ $x_max-$x_min, $y_max-$y_min ]);
|
|
||||||
$optgroup->set_value('rect_origin', $origin);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -195,11 +189,12 @@ sub _update_shape {
|
||||||
my ($x, $y) = @{$self->{_rect_size}};
|
my ($x, $y) = @{$self->{_rect_size}};
|
||||||
my ($x0, $y0) = (0,0);
|
my ($x0, $y0) = (0,0);
|
||||||
my ($x1, $y1) = ($x,$y);
|
my ($x1, $y1) = ($x,$y);
|
||||||
if ($self->{_rect_origin} eq 'center') {
|
{
|
||||||
$x0 -= $x/2;
|
my ($dx, $dy) = @{$self->{_rect_origin}};
|
||||||
$x1 -= $x/2;
|
$x0 -= $dx;
|
||||||
$y0 -= $y/2;
|
$x1 -= $dx;
|
||||||
$y1 -= $y/2;
|
$y0 -= $dy;
|
||||||
|
$y1 -= $dy;
|
||||||
}
|
}
|
||||||
$self->{bed_shape} = [
|
$self->{bed_shape} = [
|
||||||
[$x0,$y0],
|
[$x0,$y0],
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue