Support decimal scaling factors and rotation angles. #1617

This commit is contained in:
Alessandro Ranellucci 2016-12-17 00:26:57 +01:00 committed by bubnikv
parent fefba5ff1d
commit 6649888d1c

View File

@ -7,7 +7,7 @@ use utf8;
use File::Basename qw(basename dirname); use File::Basename qw(basename dirname);
use List::Util qw(sum first max); use List::Util qw(sum first max);
use Slic3r::Geometry qw(X Y Z MIN MAX scale unscale deg2rad); use Slic3r::Geometry qw(X Y Z MIN MAX scale unscale deg2rad rad2deg);
use LWP::UserAgent; use LWP::UserAgent;
use threads::shared qw(shared_clone); use threads::shared qw(shared_clone);
use Wx qw(:button :cursor :dialog :filedialog :keycode :icon :font :id :listctrl :misc use Wx qw(:button :cursor :dialog :filedialog :keycode :icon :font :id :listctrl :misc
@ -892,15 +892,17 @@ sub rotate {
if (!defined $angle) { if (!defined $angle) {
my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z'; my $axis_name = $axis == X ? 'X' : $axis == Y ? 'Y' : 'Z';
$angle = Wx::GetNumberFromUser("", "Enter the rotation angle:", "Rotate around $axis_name axis", $model_instance->rotation, -364, 364, $self); my $default = $axis == Z ? rad2deg($model_instance->rotation) : 0;
return if !$angle || $angle == -1; # Wx::GetNumberFromUser() does not support decimal numbers
$angle = 0 - $angle; # rotate clockwise (be consistent with button icon) $angle = Wx::GetTextFromUser("Enter the rotation angle:", "Rotate around $axis_name axis",
$default, $self);
return if !$angle || $angle !~ /^-?\d*(?:\.\d*)?$/ || $angle == -1;
} }
$self->stop_background_process; $self->stop_background_process;
if ($axis == Z) { if ($axis == Z) {
my $new_angle = $model_instance->rotation + deg2rad($angle); my $new_angle = deg2rad($angle);
$_->set_rotation($new_angle) for @{ $model_object->instances }; $_->set_rotation($new_angle) for @{ $model_object->instances };
$object->transform_thumbnail($self->{model}, $obj_idx); $object->transform_thumbnail($self->{model}, $obj_idx);
} else { } else {
@ -977,15 +979,20 @@ sub changescale {
my $scale; my $scale;
if ($tosize) { if ($tosize) {
my $cursize = $object_size->[$axis]; my $cursize = $object_size->[$axis];
my $newsize = Wx::GetNumberFromUser("", "Enter the new size for the selected object:", "Scale along $axis_name", # Wx::GetNumberFromUser() does not support decimal numbers
$cursize, 0, $bed_size->[$axis], $self); my $newsize = Wx::GetTextFromUser(
return if !$newsize || $newsize < 0; sprintf("Enter the new size for the selected object (print bed: %smm):", $bed_size->[$axis]),
"Scale along $axis_name",
$cursize, $self);
return if !$newsize || $newsize !~ /^\d*(?:\.\d*)?$/ || $newsize < 0;
$scale = $newsize / $cursize * 100; $scale = $newsize / $cursize * 100;
} else { } else {
$scale = Wx::GetNumberFromUser("", "Enter the scale % for the selected object:", "Scale along $axis_name", # Wx::GetNumberFromUser() does not support decimal numbers
100, 0, 100000, $self); $scale = Wx::GetTextFromUser("Enter the scale % for the selected object:",
"Scale along $axis_name", 100, $self);
$scale =~ s/%$//;
return if !$scale || $scale !~ /^\d*(?:\.\d*)?$/ || $scale < 0;
} }
return if !$scale || $scale < 0;
# apply Z rotation before scaling # apply Z rotation before scaling
if ($model_instance->rotation != 0) { if ($model_instance->rotation != 0) {
@ -1002,16 +1009,18 @@ sub changescale {
my $scale; my $scale;
if ($tosize) { if ($tosize) {
my $cursize = max(@$object_size); my $cursize = max(@$object_size);
my $newsize = Wx::GetNumberFromUser("", "Enter the new max size for the selected object:", "Scale", # Wx::GetNumberFromUser() does not support decimal numbers
$cursize, 0, max(@$bed_size), $self); my $newsize = Wx::GetTextFromUser("Enter the new max size for the selected object:",
return if !$newsize || $newsize < 0; "Scale", $cursize, $self);
return if !$newsize || $newsize !~ /^\d*(?:\.\d*)?$/ || $newsize < 0;
$scale = $newsize / $cursize * 100; $scale = $newsize / $cursize * 100;
} else { } else {
# max scale factor should be above 2540 to allow importing files exported in inches # max scale factor should be above 2540 to allow importing files exported in inches
$scale = Wx::GetNumberFromUser("", "Enter the scale % for the selected object:", 'Scale', # Wx::GetNumberFromUser() does not support decimal numbers
$model_instance->scaling_factor*100, 0, 100000, $self); $scale = Wx::GetTextFromUser("Enter the scale % for the selected object:", 'Scale',
$model_instance->scaling_factor*100, $self);
return if !$scale || $scale !~ /^\d*(?:\.\d*)?$/ || $scale < 0;
} }
return if !$scale || $scale < 0;
$self->{list}->SetItem($obj_idx, 2, "$scale%"); $self->{list}->SetItem($obj_idx, 2, "$scale%");
$scale /= 100; # turn percent into factor $scale /= 100; # turn percent into factor