From 994222c3171181dd1b695ac4d5582d05e85854de Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Mon, 28 May 2018 14:10:02 +0200 Subject: [PATCH] 3DScene _first_selected_object_id_for_variable_layer_height_editing method moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 31 +++++++++++++------------ xs/src/slic3r/GUI/3DScene.cpp | 5 ++++ xs/src/slic3r/GUI/3DScene.hpp | 1 + xs/src/slic3r/GUI/GLCanvas3D.cpp | 30 ++++++++++++++++++++---- xs/src/slic3r/GUI/GLCanvas3D.hpp | 12 ++++++---- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 6 +++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 1 + xs/xsp/GUI_3DScene.xsp | 10 ++++++++ 8 files changed, 71 insertions(+), 25 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index c5626d4bd..765fde9ab 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -360,21 +360,21 @@ sub Destroy { # # or if the initialization was done already and it failed. # return ! (defined($self->{layer_editing_initialized}) && $self->{layer_editing_initialized} == 2); #} +# +#sub _first_selected_object_id_for_variable_layer_height_editing { +# my ($self) = @_; +# for my $i (0..$#{$self->volumes}) { +# if ($self->volumes->[$i]->selected) { +# my $object_id = int($self->volumes->[$i]->select_group_id / 1000000); +# # Objects with object_id >= 1000 have a specific meaning, for example the wipe tower proxy. +# return ($object_id >= $self->{print}->object_count) ? -1 : $object_id +# if $object_id < 10000; +# } +# } +# return -1; +#} #============================================================================================================================== -sub _first_selected_object_id_for_variable_layer_height_editing { - my ($self) = @_; - for my $i (0..$#{$self->volumes}) { - if ($self->volumes->[$i]->selected) { - my $object_id = int($self->volumes->[$i]->select_group_id / 1000000); - # Objects with object_id >= 1000 have a specific meaning, for example the wipe tower proxy. - return ($object_id >= $self->{print}->object_count) ? -1 : $object_id - if $object_id < 10000; - } - } - return -1; -} - # Returns an array with (left, top, right, bottom) of the variable layer thickness bar on the screen. sub _variable_layer_thickness_bar_rect_screen { my ($self) = @_; @@ -498,7 +498,7 @@ sub mouse_event { my $pos = Slic3r::Pointf->new($e->GetPositionXY); #============================================================================================================================== - my $object_idx_selected = (Slic3r::GUI::_3DScene::is_layers_editing_enabled($self) && $self->{print}) ? $self->_first_selected_object_id_for_variable_layer_height_editing : -1; + my $object_idx_selected = (Slic3r::GUI::_3DScene::is_layers_editing_enabled($self) && $self->{print}) ? Slic3r::GUI::_3DScene::get_layers_editing_first_selected_object_id($self, $self->{print}->object_count) : -1; Slic3r::GUI::_3DScene::set_layers_editing_last_object_id($self, $object_idx_selected); # my $object_idx_selected = $self->{layer_height_edit_last_object_id} = ($self->layer_editing_enabled && $self->{print}) ? $self->_first_selected_object_id_for_variable_layer_height_editing : -1; #============================================================================================================================== @@ -732,9 +732,10 @@ sub mouse_wheel_event { } #============================================================================================================================== if (Slic3r::GUI::_3DScene::is_layers_editing_enabled($self) && $self->{print}) { + my $object_idx_selected = Slic3r::GUI::_3DScene::get_layers_editing_first_selected_object_id($self, $self->{print}->object_count); # if ($self->layer_editing_enabled && $self->{print}) { +# my $object_idx_selected = $self->_first_selected_object_id_for_variable_layer_height_editing; #============================================================================================================================== - my $object_idx_selected = $self->_first_selected_object_id_for_variable_layer_height_editing; if ($object_idx_selected != -1) { # A volume is selected. Test, whether hovering over a layer thickness bar. if ($self->_variable_layer_thickness_bar_rect_mouse_inside($e)) { diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 46b7a5eca..41aa1b77d 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -2075,6 +2075,11 @@ float _3DScene::get_layers_editing_cursor_z_relative(wxGLCanvas* canvas) return s_canvas_mgr.get_layers_editing_cursor_z_relative(canvas); } +int _3DScene::get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count) +{ + return s_canvas_mgr.get_layers_editing_first_selected_object_id(canvas, objects_count); +} + void _3DScene::zoom_to_bed(wxGLCanvas* canvas) { s_canvas_mgr.zoom_to_bed(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 73835df2f..38dbfc804 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -637,6 +637,7 @@ public: static GLShader* get_layers_editing_shader(wxGLCanvas* canvas); static float get_layers_editing_cursor_z_relative(wxGLCanvas* canvas); + static int get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count); static void zoom_to_bed(wxGLCanvas* canvas); static void zoom_to_volumes(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index ef82e7f25..3b218b88f 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -744,7 +744,7 @@ GLShader* GLCanvas3D::LayersEditing::get_shader() return m_shader.get_shader(); } -float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) const +float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) { const Point& mouse_pos = canvas.get_local_mouse_position(); const Rect& bar_rect = _get_bar_rect_screen(canvas); @@ -760,6 +760,21 @@ float GLCanvas3D::LayersEditing::get_cursor_z_relative(const GLCanvas3D& canvas) -1000.0f; } +int GLCanvas3D::LayersEditing::get_first_selected_object_id(const GLVolumeCollection& volumes, unsigned int objects_count) +{ + for (const GLVolume* vol : volumes.volumes) + { + if ((vol != nullptr) && vol->selected) + { + int object_id = vol->select_group_id / 1000000; + // Objects with object_id >= 1000 have a specific meaning, for example the wipe tower proxy. + if (object_id < 10000) + return (object_id >= (int)objects_count) ? -1 : object_id; + } + } + return -1; +} + bool GLCanvas3D::LayersEditing::_is_initialized() const { return m_shader.is_initialized(); @@ -942,7 +957,7 @@ void GLCanvas3D::LayersEditing::_render_profile(const PrintObject& print_object, } } -Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) const +Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) { const Size& cnv_size = canvas.get_canvas_size(); float w = (float)cnv_size.get_width(); @@ -951,7 +966,7 @@ Rect GLCanvas3D::LayersEditing::_get_bar_rect_screen(const GLCanvas3D& canvas) c return Rect(w - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, 0.0f, w, h - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT); } -Rect GLCanvas3D::LayersEditing::_get_reset_rect_screen(const GLCanvas3D& canvas) const +Rect GLCanvas3D::LayersEditing::_get_reset_rect_screen(const GLCanvas3D& canvas) { const Size& cnv_size = canvas.get_canvas_size(); float w = (float)cnv_size.get_width(); @@ -960,7 +975,7 @@ Rect GLCanvas3D::LayersEditing::_get_reset_rect_screen(const GLCanvas3D& canvas) return Rect(w - VARIABLE_LAYER_THICKNESS_BAR_WIDTH, h - VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT, w, h); } -Rect GLCanvas3D::LayersEditing::_get_bar_rect_viewport(const GLCanvas3D& canvas) const +Rect GLCanvas3D::LayersEditing::_get_bar_rect_viewport(const GLCanvas3D& canvas) { const Size& cnv_size = canvas.get_canvas_size(); float half_w = 0.5f * (float)cnv_size.get_width(); @@ -972,7 +987,7 @@ Rect GLCanvas3D::LayersEditing::_get_bar_rect_viewport(const GLCanvas3D& canvas) return Rect((half_w - VARIABLE_LAYER_THICKNESS_BAR_WIDTH) * inv_zoom, half_h * inv_zoom, half_w * inv_zoom, (-half_h + VARIABLE_LAYER_THICKNESS_RESET_BUTTON_HEIGHT) * inv_zoom); } -Rect GLCanvas3D::LayersEditing::_get_reset_rect_viewport(const GLCanvas3D& canvas) const +Rect GLCanvas3D::LayersEditing::_get_reset_rect_viewport(const GLCanvas3D& canvas) { const Size& cnv_size = canvas.get_canvas_size(); float half_w = 0.5f * (float)cnv_size.get_width(); @@ -1654,6 +1669,11 @@ float GLCanvas3D::get_layers_editing_cursor_z_relative(const GLCanvas3D& canvas) return m_layers_editing.get_cursor_z_relative(canvas); } +int GLCanvas3D::get_layers_editing_first_selected_object_id(unsigned int objects_count) const +{ + return (m_volumes != nullptr) ? m_layers_editing.get_first_selected_object_id(*m_volumes, objects_count) : -1; +} + void GLCanvas3D::render_bed() const { m_bed.render(); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 3a83321f5..9b01be081 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -256,7 +256,8 @@ public: GLShader* get_shader(); - float get_cursor_z_relative(const GLCanvas3D& canvas) const; + static float get_cursor_z_relative(const GLCanvas3D& canvas); + static int get_first_selected_object_id(const GLVolumeCollection& volumes, unsigned int objects_count); private: bool _is_initialized() const; @@ -265,10 +266,10 @@ public: void _render_reset_texture(const GLCanvas3D& canvas, const Rect& reset_rect) const; void _render_active_object_annotations(const GLCanvas3D& canvas, const GLVolume& volume, const PrintObject& print_object, const Rect& bar_rect) const; void _render_profile(const PrintObject& print_object, const Rect& bar_rect) const; - Rect _get_bar_rect_screen(const GLCanvas3D& canvas) const; - Rect _get_reset_rect_screen(const GLCanvas3D& canvas) const; - Rect _get_bar_rect_viewport(const GLCanvas3D& canvas) const; - Rect _get_reset_rect_viewport(const GLCanvas3D& canvas) const; + static Rect _get_bar_rect_screen(const GLCanvas3D& canvas); + static Rect _get_reset_rect_screen(const GLCanvas3D& canvas); + static Rect _get_bar_rect_viewport(const GLCanvas3D& canvas); + static Rect _get_reset_rect_viewport(const GLCanvas3D& canvas); }; class Mouse @@ -416,6 +417,7 @@ public: GLShader* get_layers_editing_shader(); float get_layers_editing_cursor_z_relative(const GLCanvas3D& canvas) const; + int get_layers_editing_first_selected_object_id(unsigned int objects_count) const; void zoom_to_bed(); void zoom_to_volumes(); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index b2a7f5bad..91963a9ad 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -556,6 +556,12 @@ float GLCanvas3DManager::get_layers_editing_cursor_z_relative(wxGLCanvas* canvas return (it != m_canvases.end()) ? it->second->get_layers_editing_cursor_z_relative(*it->second) : 0.0f; } +int GLCanvas3DManager::get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->get_layers_editing_first_selected_object_id(objects_count) : 0.; +} + void GLCanvas3DManager::zoom_to_bed(wxGLCanvas* canvas) { CanvasesMap::iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 4a804e921..5166da2e9 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -137,6 +137,7 @@ public: GLShader* get_layers_editing_shader(wxGLCanvas* canvas); float get_layers_editing_cursor_z_relative(wxGLCanvas* canvas) const; + int get_layers_editing_first_selected_object_id(wxGLCanvas* canvas, unsigned int objects_count) const; void zoom_to_bed(wxGLCanvas* canvas); void zoom_to_volumes(wxGLCanvas* canvas); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index cca3583fb..6cc9e0d6a 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -670,6 +670,16 @@ get_layers_editing_cursor_z_relative(canvas) OUTPUT: RETVAL +int +get_layers_editing_first_selected_object_id(canvas, objects_count) + SV *canvas; + unsigned int objects_count; + CODE: + RETVAL = _3DScene::get_layers_editing_first_selected_object_id((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), objects_count); + OUTPUT: + RETVAL + + void zoom_to_bed(canvas) SV *canvas;