From 4961b74c3e4391c3882599f4246cf798ac562b35 Mon Sep 17 00:00:00 2001 From: Samir55 Date: Thu, 6 Apr 2017 23:09:06 +0200 Subject: [PATCH 1/4] Adding Zoom --- lib/Slic3r/GUI/3DScene.pm | 14 ++++++++++++++ lib/Slic3r/GUI/MainFrame.pm | 8 +++++++- lib/Slic3r/GUI/Plater.pm | 5 +++++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 09801fe6d..7f65f9c30 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -330,6 +330,20 @@ sub set_viewport_from_scene { $self->_dirty(1); } +sub zoom{ + my ($self, $direction) = @_; + print ($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, # zoom to volumes. sub select_view { diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 1b07d37ef..275675dae 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -193,7 +193,8 @@ sub _init_menubar { $self->_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; }, undef, 'brick_go.png'); - + $self->_append_menu_item($self->{plater_menu}, "Zoom In\tCtrl+up" , 'Zoom In' , sub { $self->zoom('in' ); }); + $self->_append_menu_item($self->{plater_menu}, "Zoom Out\tCtrl+down" , 'Zoom Out' , sub { $self->zoom('out' ); }); $self->{object_menu} = $self->{plater}->object_menu; $self->on_plater_selection_changed(0); } @@ -631,6 +632,11 @@ sub select_view { $self->{plater}->select_view($direction); } +sub zoom{ + my($self, $direction) = @_; + $self->{plater}->zoom($direction); +} + sub _append_menu_item { my ($self, $menu, $string, $description, $cb, $id, $icon, $kind) = @_; diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 364f9c191..62468e814 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -2432,6 +2432,11 @@ sub select_view { } } +sub zoom{ + my ($self, $direction) = @_; + $self->{canvas3D}->zoom($direction); +} + package Slic3r::GUI::Plater::DropTarget; use Wx::DND; use base 'Wx::FileDropTarget'; From 75291772ce01cce7382ba15a2e5618f71d259ce9 Mon Sep 17 00:00:00 2001 From: Samir55 Date: Wed, 19 Apr 2017 15:33:42 +0200 Subject: [PATCH 2/4] Improving Zoom by keyboardShortcut --- lib/Slic3r/GUI/3DScene.pm | 1 - lib/Slic3r/GUI/MainFrame.pm | 11 +++-------- lib/Slic3r/GUI/Plater.pm | 18 ++++++++++++++++-- lib/Slic3r/GUI/Plater/2DToolpaths.pm | 22 ++++++++++++++++++---- slic3r.pl | 2 +- 5 files changed, 38 insertions(+), 16 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index 7f65f9c30..057342879 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -332,7 +332,6 @@ sub set_viewport_from_scene { sub zoom{ my ($self, $direction) = @_; - print ($direction); if( $direction eq 'in'){ $self->_zoom($self->_zoom / (1-0.3)); } diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 275675dae..7b3d998af 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -183,6 +183,8 @@ sub _init_menubar { $self->_append_menu_item($self->{plater_menu}, "Select Prev Object\tCtrl+Left", 'Select Previous Object in the plater', sub { $plater->select_prev; }, 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->_append_menu_item($self->{plater_menu}, "Export G-code...", 'Export current plate as G-code', sub { $plater->export_gcode; @@ -193,8 +195,6 @@ sub _init_menubar { $self->_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; }, undef, 'brick_go.png'); - $self->_append_menu_item($self->{plater_menu}, "Zoom In\tCtrl+up" , 'Zoom In' , sub { $self->zoom('in' ); }); - $self->_append_menu_item($self->{plater_menu}, "Zoom Out\tCtrl+down" , 'Zoom Out' , sub { $self->zoom('out' ); }); $self->{object_menu} = $self->{plater}->object_menu; $self->on_plater_selection_changed(0); } @@ -628,13 +628,8 @@ sub select_tab { # Set a camera direction, zoom to all objects. sub select_view { my ($self, $direction) = @_; - - $self->{plater}->select_view($direction); -} -sub zoom{ - my($self, $direction) = @_; - $self->{plater}->zoom($direction); + $self->{plater}->select_view($direction); } sub _append_menu_item { diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 62468e814..89341498f 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -91,7 +91,7 @@ sub new { my $on_instances_moved = sub { $self->on_model_change; }; - + # Initialize 3D plater if ($Slic3r::GUI::have_OpenGL) { $self->{canvas3D} = Slic3r::GUI::Plater::3D->new($self->{preview_notebook}, $self->{objects}, $self->{model}, $self->{config}); @@ -2434,7 +2434,21 @@ sub select_view { sub zoom{ my ($self, $direction) = @_; - $self->{canvas3D}->zoom($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 == 1) { #2D platter should zomobe applied here or not ? +# } + 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}); + } + else {#Do Nothing + } } package Slic3r::GUI::Plater::DropTarget; diff --git a/lib/Slic3r/GUI/Plater/2DToolpaths.pm b/lib/Slic3r/GUI/Plater/2DToolpaths.pm index d39c53179..c7b3765c0 100644 --- a/lib/Slic3r/GUI/Plater/2DToolpaths.pm +++ b/lib/Slic3r/GUI/Plater/2DToolpaths.pm @@ -187,21 +187,21 @@ sub new { $zoom /= 10; $self->_zoom($self->_zoom / (1-$zoom)); $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 # the camera target. This math is almost there but not perfect yet... my $camera_bb_size = $self->_camera_bb->size; my $size = Slic3r::Pointf->new($self->GetSizeWH); my $pos = Slic3r::Pointf->new($e->GetPositionXY); - + # 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); #- - + # calculate where this point will end up after applying the new zoom my $vec2 = $vec->clone; $vec2->scale($old_zoom / $self->_zoom); - + # move the camera target by the difference of the two positions $self->_camera_target->translate( -($vec->x - $vec2->x) * $camera_bb_size->x / $size->x, @@ -217,6 +217,20 @@ sub new { 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 { my ($self, $e) = @_; diff --git a/slic3r.pl b/slic3r.pl index 75bf3b961..5f08ba8b0 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -6,7 +6,7 @@ use warnings; BEGIN { use FindBin; use lib "$FindBin::Bin/lib"; - use local::lib '--no-create', "$FindBin::Bin/local-lib"; + use local::lib "$FindBin::Bin/local-lib"; } use File::Basename qw(basename); From 489059f82749ceaf9fd7e00eef4f4da69591ba9a Mon Sep 17 00:00:00 2001 From: Samir55 Date: Wed, 19 Apr 2017 18:40:32 +0200 Subject: [PATCH 3/4] Improving Zoom by Keyboard Shortcut removing unnecessary lines --- lib/Slic3r/GUI/Plater.pm | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 89341498f..c7ceb2899 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -2439,16 +2439,12 @@ sub zoom{ if($currentSelection == 0){ $self->{canvas3D}->zoom($direction) if($self->{canvas3D}); } -# elsif($currentSelection == 1) { #2D platter should zomobe applied here or not ? -# } 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}); } - else {#Do Nothing - } } package Slic3r::GUI::Plater::DropTarget; From 85836ab3804f8156c9d305fb32ae4983675c8414 Mon Sep 17 00:00:00 2001 From: Samir55 Date: Thu, 27 Apr 2017 17:45:04 +0200 Subject: [PATCH 4/4] fix slic3r.pl file --- slic3r.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slic3r.pl b/slic3r.pl index 5f08ba8b0..75bf3b961 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -6,7 +6,7 @@ use warnings; BEGIN { use FindBin; use lib "$FindBin::Bin/lib"; - use local::lib "$FindBin::Bin/local-lib"; + use local::lib '--no-create', "$FindBin::Bin/local-lib"; } use File::Basename qw(basename);