From bdbc86167c15545ed91312e28a644f6ae4faa683 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 25 May 2018 09:03:55 +0200 Subject: [PATCH] 3DScene volume selection methods moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 43 +++++++++++++------------ lib/Slic3r/GUI/Plater.pm | 5 ++- lib/Slic3r/GUI/Plater/3D.pm | 5 ++- xs/src/slic3r/GUI/3DScene.cpp | 10 ++++++ xs/src/slic3r/GUI/3DScene.hpp | 2 ++ xs/src/slic3r/GUI/GLCanvas3D.cpp | 22 +++++++++++++ xs/src/slic3r/GUI/GLCanvas3D.hpp | 2 ++ xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 14 ++++++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 2 ++ xs/xsp/GUI_3DScene.xsp | 13 ++++++++ 10 files changed, 96 insertions(+), 22 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index d8ee842bd..e48d2cf5c 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -508,16 +508,21 @@ sub mouse_event { # during the scene manipulation. #============================================================================================================================== if (Slic3r::GUI::_3DScene::is_picking_enabled($self) && ($volume_idx != -1 || ! $self->layer_editing_enabled)) { + Slic3r::GUI::_3DScene::deselect_volumes($self); + Slic3r::GUI::_3DScene::select_volume($self, $volume_idx); # if ($self->enable_picking && ($volume_idx != -1 || ! $self->layer_editing_enabled)) { +# $self->deselect_volumes; +# $self->select_volume($volume_idx); #============================================================================================================================== - $self->deselect_volumes; - $self->select_volume($volume_idx); if ($volume_idx != -1) { my $group_id = $self->volumes->[$volume_idx]->select_group_id; my @volumes; if ($group_id != -1) { - $self->select_volume($_) +#============================================================================================================================== + Slic3r::GUI::_3DScene::select_volume($self, $_) +# $self->select_volume($_) +#============================================================================================================================== for grep $self->volumes->[$_]->select_group_id == $group_id, 0..$#{$self->volumes}; } @@ -1048,23 +1053,21 @@ sub get_zoom_to_bounding_box_factor { # # $self->bed_polygon(offset_ex([$expolygon->contour], $bed_bb->radius * 1.7, JT_ROUND, scale(0.5))->[0]->contour->clone); #} -#============================================================================================================================== - -sub deselect_volumes { - my ($self) = @_; - $_->set_selected(0) for @{$self->volumes}; -} - -sub select_volume { - my ($self, $volume_idx) = @_; - - return if ($volume_idx >= scalar(@{$self->volumes})); - - $self->volumes->[$volume_idx]->set_selected(1) - if $volume_idx != -1; -} - -#============================================================================================================================== +# +#sub deselect_volumes { +# my ($self) = @_; +# $_->set_selected(0) for @{$self->volumes}; +#} +# +#sub select_volume { +# my ($self, $volume_idx) = @_; +# +# return if ($volume_idx >= scalar(@{$self->volumes})); +# +# $self->volumes->[$volume_idx]->set_selected(1) +# if $volume_idx != -1; +#} +# #sub SetCuttingPlane { # my ($self, $z, $expolygons) = @_; # diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index e7de0eb9b..e5e6a73d4 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1854,7 +1854,10 @@ sub list_item_deselected { if ($self->{list}->GetFirstSelected == -1) { $self->select_object(undef); $self->{canvas}->Refresh; - $self->{canvas3D}->deselect_volumes if $self->{canvas3D}; +#============================================================================================================================== + Slic3r::GUI::_3DScene::deselect_volumes($self->{canvas3D}) if $self->{canvas3D}; +# $self->{canvas3D}->deselect_volumes if $self->{canvas3D}; +#============================================================================================================================== $self->{canvas3D}->Render if $self->{canvas3D}; } undef $self->{_lecursor}; diff --git a/lib/Slic3r/GUI/Plater/3D.pm b/lib/Slic3r/GUI/Plater/3D.pm index 641c800cb..5d905c896 100644 --- a/lib/Slic3r/GUI/Plater/3D.pm +++ b/lib/Slic3r/GUI/Plater/3D.pm @@ -195,7 +195,10 @@ sub update_volumes_selection { foreach my $obj_idx (0..$#{$self->{model}->objects}) { if ($self->{objects}[$obj_idx]->selected) { my $volume_idxs = $self->{objects_volumes_idxs}->[$obj_idx]; - $self->select_volume($_) for @{$volume_idxs}; +#============================================================================================================================== + Slic3r::GUI::_3DScene::select_volume($self, $_) for @{$volume_idxs}; +# $self->select_volume($_) for @{$volume_idxs}; +#============================================================================================================================== } } } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 0f4b020da..affca1083 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1792,6 +1792,16 @@ void _3DScene::reset_volumes(wxGLCanvas* canvas) s_canvas_mgr.reset_volumes(canvas); } +void _3DScene::deselect_volumes(wxGLCanvas* canvas) +{ + s_canvas_mgr.deselect_volumes(canvas); +} + +void _3DScene::select_volume(wxGLCanvas* canvas, unsigned int id) +{ + s_canvas_mgr.select_volume(canvas, id); +} + DynamicPrintConfig* _3DScene::get_config(wxGLCanvas* canvas) { return s_canvas_mgr.get_config(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index edbb42bc2..e09c226c7 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -556,6 +556,8 @@ public: static GLVolumeCollection* get_volumes(wxGLCanvas* canvas); static void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes); static void reset_volumes(wxGLCanvas* canvas); + static void deselect_volumes(wxGLCanvas* canvas); + static void select_volume(wxGLCanvas* canvas, unsigned int id); static DynamicPrintConfig* get_config(wxGLCanvas* canvas); static void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 942a7e6ef..3e93b8a1b 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -992,6 +992,28 @@ void GLCanvas3D::reset_volumes() } } +void GLCanvas3D::deselect_volumes() +{ + if (m_volumes != nullptr) + { + for (GLVolume* vol : m_volumes->volumes) + { + if (vol != nullptr) + vol->selected = false; + } + } +} + +void GLCanvas3D::select_volume(unsigned int id) +{ + if ((m_volumes != nullptr) && (id < (unsigned int)m_volumes->volumes.size())) + { + GLVolume* vol = m_volumes->volumes[id]; + if (vol != nullptr) + vol->selected = true; + } +} + DynamicPrintConfig* GLCanvas3D::get_config() { return m_config; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index a15e632fc..2a0a19772 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -285,6 +285,8 @@ public: GLVolumeCollection* get_volumes(); void set_volumes(GLVolumeCollection* volumes); void reset_volumes(); + void deselect_volumes(); + void select_volume(unsigned int id); DynamicPrintConfig* get_config(); void set_config(DynamicPrintConfig* config); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index c28bfb675..6dd7744c5 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -200,6 +200,20 @@ void GLCanvas3DManager::reset_volumes(wxGLCanvas* canvas) it->second->reset_volumes(); } +void GLCanvas3DManager::deselect_volumes(wxGLCanvas* canvas) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->deselect_volumes(); +} + +void GLCanvas3DManager::select_volume(wxGLCanvas* canvas, unsigned int id) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->select_volume(id); +} + DynamicPrintConfig* GLCanvas3DManager::get_config(wxGLCanvas* canvas) { CanvasesMap::const_iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 19baaf94f..98baa3070 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -64,6 +64,8 @@ public: GLVolumeCollection* get_volumes(wxGLCanvas* canvas); void set_volumes(wxGLCanvas* canvas, GLVolumeCollection* volumes); void reset_volumes(wxGLCanvas* canvas); + void deselect_volumes(wxGLCanvas* canvas); + void select_volume(wxGLCanvas* canvas, unsigned int id); DynamicPrintConfig* get_config(wxGLCanvas* canvas); void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index f87cbda44..c2314e3f0 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -251,6 +251,19 @@ reset_volumes(canvas) CODE: _3DScene::reset_volumes((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); +void +deselect_volumes(canvas) + SV *canvas; + CODE: + _3DScene::deselect_volumes((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + +void +select_volume(canvas, id) + SV *canvas; + unsigned int id; + CODE: + _3DScene::select_volume((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), id); + DynamicPrintConfig* get_config(canvas) SV *canvas;