From a7693c4719c0e0e0129aea7461706d2ed53a52cc Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 27 Nov 2016 16:48:48 +0100 Subject: [PATCH] Fixes and improvements to the view selection menu --- lib/Slic3r/GUI/3DScene.pm | 24 +++++++++++++++--------- lib/Slic3r/GUI/MainFrame.pm | 2 +- xs/xsp/BoundingBox.xsp | 3 +++ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 61d45f1f4..c9bbd7962 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -55,7 +55,7 @@ use constant HAS_VBO => 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]; @@ -63,7 +63,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 => 170; +use constant GIMBAL_LOCK_THETA_MAX => 170; # make OpenGL::Array thread-safe { @@ -254,7 +254,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; @@ -336,8 +336,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') { @@ -354,12 +354,18 @@ sub select_view { } $self->_sphi($dirvec->[0]); $self->_stheta($dirvec->[1]); - # Avoid gimball lock. - $self->_stheta(GIMBALL_LOCK_THETA_MAX) if $self->_stheta > GIMBALL_LOCK_THETA_MAX; + + # 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->zoom_to_volumes; + $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; } @@ -368,7 +374,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); diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index a518a3ab2..9acf8f1d4 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -290,7 +290,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' ); }); diff --git a/xs/xsp/BoundingBox.xsp b/xs/xsp/BoundingBox.xsp index ed648a795..53af895bf 100644 --- a/xs/xsp/BoundingBox.xsp +++ b/xs/xsp/BoundingBox.xsp @@ -26,6 +26,7 @@ long x_max() %code{% RETVAL = THIS->max.x; %}; long y_min() %code{% RETVAL = THIS->min.y; %}; long y_max() %code{% RETVAL = THIS->max.y; %}; + bool defined() %code{% RETVAL = THIS->defined; %}; %{ @@ -63,6 +64,7 @@ new_from_points(CLASS, points) void set_x_max(double val) %code{% THIS->max.x = val; %}; void set_y_min(double val) %code{% THIS->min.y = val; %}; void set_y_max(double val) %code{% THIS->max.y = val; %}; + bool defined() %code{% RETVAL = THIS->defined; %}; %{ @@ -97,4 +99,5 @@ new_from_points(CLASS, points) double y_max() %code{% RETVAL = THIS->max.y; %}; double z_min() %code{% RETVAL = THIS->min.z; %}; double z_max() %code{% RETVAL = THIS->max.z; %}; + bool defined() %code{% RETVAL = THIS->defined; %}; };