Merge pull request #3864 from Samir55/gsoc

Adding Zoom
This commit is contained in:
Alessandro Ranellucci 2017-04-29 19:26:56 +02:00 committed by GitHub
commit 9499122d58
4 changed files with 50 additions and 7 deletions

View File

@ -330,6 +330,19 @@ sub set_viewport_from_scene {
$self->_dirty(1); $self->_dirty(1);
} }
sub zoom{
my ($self, $direction) = @_;
if( $direction eq 'in'){
$self->_zoom($self->_zoom / (1-0.3));
}
elsif($direction eq 'out'){
$self->_zoom($self->_zoom / (1+0.3));
}
$self->on_viewport_changed->() if $self->on_viewport_changed;
$self->_dirty(1);
$self->Refresh;
}
# Set the camera to a default orientation, # Set the camera to a default orientation,
# zoom to volumes. # zoom to volumes.
sub select_view { sub select_view {

View File

@ -182,6 +182,8 @@ sub _init_menubar {
wxTheApp->append_menu_item($self->{plater_menu}, "Select Prev Object\tCtrl+Left", 'Select Previous Object in the plater', sub { wxTheApp->append_menu_item($self->{plater_menu}, "Select Prev Object\tCtrl+Left", 'Select Previous Object in the plater', sub {
$plater->select_prev; $plater->select_prev;
}, undef, 'arrow_left.png'); }, undef, 'arrow_left.png');
$self->_append_menu_item($self->{plater_menu}, "Zoom In\tCtrl+up" , 'Zoom In' , sub { $self->{plater}->zoom('in' ); });
$self->_append_menu_item($self->{plater_menu}, "Zoom Out\tCtrl+down" , 'Zoom Out' , sub { $self->{plater}->zoom('out' ); });
$self->{plater_menu}->AppendSeparator(); $self->{plater_menu}->AppendSeparator();
wxTheApp->append_menu_item($self->{plater_menu}, "Export G-code...", 'Export current plate as G-code', sub { wxTheApp->append_menu_item($self->{plater_menu}, "Export G-code...", 'Export current plate as G-code', sub {
$plater->export_gcode; $plater->export_gcode;
@ -192,7 +194,6 @@ sub _init_menubar {
wxTheApp->append_menu_item($self->{plater_menu}, "Export plate with modifiers as AMF...", 'Export current plate as AMF, including all modifier meshes', sub { wxTheApp->append_menu_item($self->{plater_menu}, "Export plate with modifiers as AMF...", 'Export current plate as AMF, including all modifier meshes', sub {
$plater->export_amf; $plater->export_amf;
}, undef, 'brick_go.png'); }, undef, 'brick_go.png');
$self->{object_menu} = $self->{plater}->object_menu; $self->{object_menu} = $self->{plater}->object_menu;
$self->on_plater_selection_changed(0); $self->on_plater_selection_changed(0);
} }
@ -626,7 +627,7 @@ sub select_tab {
# Set a camera direction, zoom to all objects. # Set a camera direction, zoom to all objects.
sub select_view { sub select_view {
my ($self, $direction) = @_; my ($self, $direction) = @_;
$self->{plater}->select_view($direction); $self->{plater}->select_view($direction);
} }

View File

@ -91,7 +91,7 @@ sub new {
my $on_instances_moved = sub { my $on_instances_moved = sub {
$self->on_model_change; $self->on_model_change;
}; };
# Initialize 3D plater # Initialize 3D plater
if ($Slic3r::GUI::have_OpenGL) { if ($Slic3r::GUI::have_OpenGL) {
$self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config}); $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config});
@ -2440,6 +2440,21 @@ sub select_view {
} }
} }
sub zoom{
my ($self, $direction) = @_;
#Apply Zoom to the current active tab
my ($currentSelection) = $self->{preview_notebook}->GetSelection;
if($currentSelection == 0){
$self->{canvas3D}->zoom($direction) if($self->{canvas3D});
}
elsif($currentSelection == 2){ #3d Preview tab
$self->{preview3D}->canvas->zoom($direction) if($self->{preview3D});
}
elsif($currentSelection == 3) { #2D toolpaths tab
$self->{toolpaths2D}->{canvas}->zoom($direction) if($self->{toolpaths2D});
}
}
package Slic3r::GUI::Plater::DropTarget; package Slic3r::GUI::Plater::DropTarget;
use Wx::DND; use Wx::DND;
use base 'Wx::FileDropTarget'; use base 'Wx::FileDropTarget';

View File

@ -187,21 +187,21 @@ sub new {
$zoom /= 10; $zoom /= 10;
$self->_zoom($self->_zoom / (1-$zoom)); $self->_zoom($self->_zoom / (1-$zoom));
$self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much $self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much
{ {
# In order to zoom around the mouse point we need to translate # In order to zoom around the mouse point we need to translate
# the camera target. This math is almost there but not perfect yet... # the camera target. This math is almost there but not perfect yet...
my $camera_bb_size = $self->_camera_bb->size; my $camera_bb_size = $self->_camera_bb->size;
my $size = Slic3r::Pointf->new($self->GetSizeWH); my $size = Slic3r::Pointf->new($self->GetSizeWH);
my $pos = Slic3r::Pointf->new($e->GetPositionXY); my $pos = Slic3r::Pointf->new($e->GetPositionXY);
# calculate the zooming center in pixel coordinates relative to the viewport center # calculate the zooming center in pixel coordinates relative to the viewport center
my $vec = Slic3r::Pointf->new($pos->x - $size->x/2, $pos->y - $size->y/2); #- my $vec = Slic3r::Pointf->new($pos->x - $size->x/2, $pos->y - $size->y/2); #-
# calculate where this point will end up after applying the new zoom # calculate where this point will end up after applying the new zoom
my $vec2 = $vec->clone; my $vec2 = $vec->clone;
$vec2->scale($old_zoom / $self->_zoom); $vec2->scale($old_zoom / $self->_zoom);
# move the camera target by the difference of the two positions # move the camera target by the difference of the two positions
$self->_camera_target->translate( $self->_camera_target->translate(
-($vec->x - $vec2->x) * $camera_bb_size->x / $size->x, -($vec->x - $vec2->x) * $camera_bb_size->x / $size->x,
@ -217,6 +217,20 @@ sub new {
return $self; return $self;
} }
sub zoom{
my($self, $direction) = @_;
if( $direction eq 'in'){
$self->_zoom($self->_zoom / (1+0.3));
}
elsif($direction eq 'out'){
$self->_zoom($self->_zoom / (1-0.3));
$self->_zoom(1) if $self->_zoom > 1; # prevent from zooming out too much
}
#apply changes
$self->_dirty(1);
$self->Refresh;
}
sub mouse_event { sub mouse_event {
my ($self, $e) = @_; my ($self, $e) = @_;