Fixes and improvements to the view selection menu, cherry picked from @alexrj a7693c4719c0e0e0129aea7461706d2ed53a52cc

This commit is contained in:
Alessandro Ranellucci 2016-11-27 16:48:48 +01:00 committed by bubnikv
parent d628764da6
commit 9e8dae817d
3 changed files with 28 additions and 22 deletions

View File

@ -74,7 +74,7 @@ use constant SELECTED_COLOR => [0,1,0,1];
use constant HOVER_COLOR => [0.4,0.9,0,1];
# phi / theta angles to orient the camera.
use constant VIEW_DEFAULT => [45.0,45.0];
use constant VIEW_ISO => [45.0,45.0];
use constant VIEW_LEFT => [90.0,90.0];
use constant VIEW_RIGHT => [-90.0,90.0];
use constant VIEW_TOP => [0.0,0.0];
@ -82,8 +82,7 @@ use constant VIEW_BOTTOM => [0.0,180.0];
use constant VIEW_FRONT => [0.0,90.0];
use constant VIEW_REAR => [180.0,90.0];
#use constant GIMBALL_LOCK_THETA_MAX => 150;
use constant GIMBALL_LOCK_THETA_MAX => 170;
use constant GIMBAL_LOCK_THETA_MAX => 170;
# make OpenGL::Array thread-safe
{
@ -257,7 +256,7 @@ sub mouse_event {
if (TURNTABLE_MODE) {
$self->_sphi($self->_sphi + ($pos->x - $orig->x) * TRACKBALLSIZE);
$self->_stheta($self->_stheta - ($pos->y - $orig->y) * TRACKBALLSIZE); #-
$self->_stheta(GIMBALL_LOCK_THETA_MAX) if $self->_stheta > GIMBALL_LOCK_THETA_MAX;
$self->_stheta(GIMBAL_LOCK_THETA_MAX) if $self->_stheta > GIMBAL_LOCK_THETA_MAX;
$self->_stheta(0) if $self->_stheta < 0;
} else {
my $size = $self->GetClientSize;
@ -341,8 +340,8 @@ sub select_view {
if (ref($direction)) {
$dirvec = $direction;
} else {
if ($direction eq 'default') {
$dirvec = VIEW_DEFAULT;
if ($direction eq 'iso') {
$dirvec = VIEW_ISO;
} elsif ($direction eq 'left') {
$dirvec = VIEW_LEFT;
} elsif ($direction eq 'right') {
@ -357,18 +356,22 @@ sub select_view {
$dirvec = VIEW_REAR;
}
}
my $bb = $self->volumes_bounding_box;
if (! $bb->empty) {
$self->_sphi($dirvec->[0]);
$self->_stheta($dirvec->[1]);
# Avoid gimball lock.
$self->_stheta(GIMBALL_LOCK_THETA_MAX) if $self->_stheta > GIMBALL_LOCK_THETA_MAX;
$self->_stheta(0) if $self->_stheta < 0;
# View everything.
$self->zoom_to_bounding_box($bb);
$self->on_viewport_changed->() if $self->on_viewport_changed;
$self->Refresh;
}
$self->_sphi($dirvec->[0]);
$self->_stheta($dirvec->[1]);
# Avoid gimbal lock.
$self->_stheta(GIMBAL_LOCK_THETA_MAX) if $self->_stheta > GIMBAL_LOCK_THETA_MAX;
$self->_stheta(0) if $self->_stheta < 0;
# View everything.
$self->volumes_bounding_box->defined
? $self->zoom_to_volumes
: $self->zoom_to_bed;
$self->on_viewport_changed->() if $self->on_viewport_changed;
$self->_dirty(1);
$self->Refresh;
}
sub zoom_to_bounding_box {
@ -377,7 +380,7 @@ sub zoom_to_bounding_box {
# calculate the zoom factor needed to adjust viewport to
# bounding box
my $max_size = max(@{$bb->size}) * 2;
my $max_size = max(@{$bb->size}) * 1.05;
my $min_viewport_size = min($self->GetSizeWH);
$self->_zoom($min_viewport_size / $max_size);

View File

@ -292,7 +292,7 @@ sub _init_menubar {
# View menu
if (!$self->{no_plater}) {
$self->{viewMenu} = Wx::Menu->new;
$self->_append_menu_item($self->{viewMenu}, "Default", 'Default View', sub { $self->select_view('default'); });
$self->_append_menu_item($self->{viewMenu}, "Iso" , 'Iso View' , sub { $self->select_view('iso' ); });
$self->_append_menu_item($self->{viewMenu}, "Top" , 'Top View' , sub { $self->select_view('top' ); });
$self->_append_menu_item($self->{viewMenu}, "Bottom" , 'Bottom View' , sub { $self->select_view('bottom' ); });
$self->_append_menu_item($self->{viewMenu}, "Front" , 'Front View' , sub { $self->select_view('front' ); });

View File

@ -30,7 +30,8 @@
long y_min() %code{% RETVAL = THIS->min.y; %};
long y_max() %code{% RETVAL = THIS->max.y; %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%ld,%ld;%ld,%ld", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %};
bool defined() %code{% RETVAL = THIS->defined; %};
%{
BoundingBox*
@ -69,7 +70,8 @@ new_from_points(CLASS, points)
void set_y_min(double val) %code{% THIS->min.y = val; %};
void set_y_max(double val) %code{% THIS->max.y = val; %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf;%lf,%lf", THIS->min.x, THIS->min.y, THIS->max.x, THIS->max.y); RETVAL = buf; %};
bool defined() %code{% RETVAL = THIS->defined; %};
%{
BoundingBoxf*
@ -106,4 +108,5 @@ new_from_points(CLASS, points)
double z_min() %code{% RETVAL = THIS->min.z; %};
double z_max() %code{% RETVAL = THIS->max.z; %};
std::string serialize() %code{% char buf[2048]; sprintf(buf, "%lf,%lf,%lf;%lf,%lf,%lf", THIS->min.x, THIS->min.y, THIS->min.z, THIS->max.x, THIS->max.y, THIS->max.z); RETVAL = buf; %};
bool defined() %code{% RETVAL = THIS->defined; %};
};