diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 85d9426fb..18545db3e 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -202,6 +202,7 @@ sub new { if ($Slic3r::GUI::have_OpenGL) { $self->{preview3D} = Slic3r::GUI::Plater::3DPreview->new($self->{preview_notebook}, $self->{print}, $self->{gcode_preview_data}, $self->{config}); #============================================================================================================================== + Slic3r::GUI::_3DScene::set_active($self->{preview3D}->canvas, 0); Slic3r::GUI::_3DScene::register_on_viewport_changed_callback($self->{preview3D}->canvas, sub { Slic3r::GUI::_3DScene::set_viewport_from_scene($self->{canvas3D}, $self->{preview3D}->canvas); }); # $self->{preview3D}->canvas->on_viewport_changed(sub { # $self->{canvas3D}->set_viewport_from_scene($self->{preview3D}->canvas); @@ -222,6 +223,8 @@ sub new { if ($preview == $self->{preview3D}) { #============================================================================================================================== + Slic3r::GUI::_3DScene::set_active($self->{preview3D}->canvas, 1); + Slic3r::GUI::_3DScene::set_active($self->{canvas3D}, 0); Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 1); # $self->{preview3D}->canvas->set_legend_enabled(1); #============================================================================================================================== @@ -235,6 +238,8 @@ sub new { #============================================================================================================================== if ($preview == $self->{canvas3D}) { + Slic3r::GUI::_3DScene::set_active($self->{canvas3D}, 1); + Slic3r::GUI::_3DScene::set_active($self->{preview3D}->canvas, 0); if (Slic3r::GUI::_3DScene::is_reload_delayed($self->{canvas3D})) { my $selections = $self->collect_selections; Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections); diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index dc40118b5..046974ba9 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1797,9 +1797,9 @@ bool _3DScene::init(wxGLCanvas* canvas) return s_canvas_mgr.init(canvas); } -bool _3DScene::is_shown_on_screen(wxGLCanvas* canvas) +void _3DScene::set_active(wxGLCanvas* canvas, bool active) { - return s_canvas_mgr.is_shown_on_screen(canvas); + s_canvas_mgr.set_active(canvas, active); } unsigned int _3DScene::get_volumes_count(wxGLCanvas* canvas) diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 9685be64d..2d043953d 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -556,7 +556,7 @@ public: static bool init(wxGLCanvas* canvas); - static bool is_shown_on_screen(wxGLCanvas* canvas); + static void set_active(wxGLCanvas* canvas, bool active); static unsigned int get_volumes_count(wxGLCanvas* canvas); static void reset_volumes(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 51e03a949..b032ce353 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1189,6 +1189,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) , m_print(nullptr) , m_model(nullptr) , m_dirty(true) + , m_active(true) , m_initialized(false) , m_use_VBOs(false) , m_force_zoom_to_bed_enabled(false) @@ -1302,9 +1303,9 @@ bool GLCanvas3D::set_current() return false; } -bool GLCanvas3D::is_shown_on_screen() const +void GLCanvas3D::set_active(bool active) { - return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; + m_active = active; } unsigned int GLCanvas3D::get_volumes_count() const @@ -1605,7 +1606,7 @@ void GLCanvas3D::render() if (m_canvas == nullptr) return; - if (!is_shown_on_screen()) + if (!_is_shown_on_screen()) return; // ensures that the proper context is selected and that this canvas is initialized @@ -2722,6 +2723,11 @@ Point GLCanvas3D::get_local_mouse_position() const return Point(mouse_pos.x, mouse_pos.y); } +bool GLCanvas3D::_is_shown_on_screen() const +{ + return (m_canvas != nullptr) ? m_active && m_canvas->IsShownOnScreen() : false; +} + void GLCanvas3D::_force_zoom_to_bed() { zoom_to_bed(); @@ -2927,7 +2933,7 @@ void GLCanvas3D::_mark_volumes_for_layer_height() const void GLCanvas3D::_refresh_if_shown_on_screen() { - if (is_shown_on_screen()) + if (_is_shown_on_screen()) { const Size& cnv_size = get_canvas_size(); _resize((unsigned int)cnv_size.get_width(), (unsigned int)cnv_size.get_height()); @@ -2942,7 +2948,7 @@ void GLCanvas3D::_camera_tranform() const ::glLoadIdentity(); ::glRotatef(-m_camera.get_theta(), 1.0f, 0.0f, 0.0f); // pitch - ::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw + ::glRotatef(m_camera.phi, 0.0f, 0.0f, 1.0f); // yaw Pointf3 neg_target = m_camera.target.negative(); ::glTranslatef((GLfloat)neg_target.x, (GLfloat)neg_target.y, (GLfloat)neg_target.z); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 30f4cb37f..d694db4e2 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -358,6 +358,9 @@ private: Model* m_model; bool m_dirty; + // the active member has been introduced to overcome a bug in wxWidgets method IsShownOnScreen() which always return true + // when a window is inside a wxNotebook + bool m_active; bool m_initialized; bool m_use_VBOs; bool m_force_zoom_to_bed_enabled; @@ -404,7 +407,7 @@ public: bool set_current(); - bool is_shown_on_screen() const; + void set_active(bool active); unsigned int get_volumes_count() const; void reset_volumes(); @@ -517,6 +520,7 @@ public: Point get_local_mouse_position() const; private: + bool _is_shown_on_screen() const; void _force_zoom_to_bed(); void _resize(unsigned int w, unsigned int h); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 298c78143..b021e65a8 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -238,10 +238,11 @@ bool GLCanvas3DManager::init(wxGLCanvas* canvas) return false; } -bool GLCanvas3DManager::is_shown_on_screen(wxGLCanvas* canvas) const +void GLCanvas3DManager::set_active(wxGLCanvas* canvas, bool active) { - CanvasesMap::const_iterator it = _get_canvas(canvas); - return (it != m_canvases.end()) ? it->second->is_shown_on_screen() : false; + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->set_active(active); } unsigned int GLCanvas3DManager::get_volumes_count(wxGLCanvas* canvas) const diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index f5187d3d3..741c8e29b 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -69,7 +69,7 @@ public: bool init(wxGLCanvas* canvas); - bool is_shown_on_screen(wxGLCanvas* canvas) const; + void set_active(wxGLCanvas* canvas, bool active); unsigned int get_volumes_count(wxGLCanvas* canvas) const; void reset_volumes(wxGLCanvas* canvas); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 91200eb2d..c7f3670fc 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -190,13 +190,12 @@ remove_all_canvases() CODE: _3DScene::remove_all_canvases(); -bool -is_shown_on_screen(canvas) - SV *canvas; +void +set_active(canvas, active) + SV *canvas; + bool active; CODE: - RETVAL = _3DScene::is_shown_on_screen((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); - OUTPUT: - RETVAL + _3DScene::set_active((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), active); unsigned int get_volumes_count(canvas)