From 2a03b90d2b8d772309409382f84f8b23947640e4 Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 22 Jun 2018 16:06:37 +0200 Subject: [PATCH] Forced render of 3D scene when changing tab in plater's notebook --- lib/Slic3r/GUI/Plater.pm | 4 ++++ xs/src/slic3r/GUI/3DScene.cpp | 5 +++++ xs/src/slic3r/GUI/3DScene.hpp | 1 + xs/src/slic3r/GUI/GLCanvas3D.cpp | 5 +++++ xs/src/slic3r/GUI/GLCanvas3D.hpp | 1 + xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 7 +++++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 1 + xs/xsp/GUI_3DScene.xsp | 6 ++++++ 8 files changed, 30 insertions(+) diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index f5ef10e9c..f4ba05bdb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -206,6 +206,8 @@ sub new { Slic3r::GUI::_3DScene::set_active($self->{canvas3D}, 0); Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 1); $self->{preview3D}->load_print(1); + # sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably) + Slic3r::GUI::_3DScene::set_as_dirty($self->{preview3D}->canvas); } else { Slic3r::GUI::_3DScene::enable_legend_texture($self->{preview3D}->canvas, 0); } @@ -218,6 +220,8 @@ sub new { Slic3r::GUI::_3DScene::set_objects_selections($self->{canvas3D}, \@$selections); Slic3r::GUI::_3DScene::reload_scene($self->{canvas3D}, 1); } + # sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably) + Slic3r::GUI::_3DScene::set_as_dirty($self->{canvas3D}); } else { $preview->OnActivate if $preview->can('OnActivate'); } diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 1879b3082..a2a310f3c 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1758,6 +1758,11 @@ void _3DScene::set_active(wxGLCanvas* canvas, bool active) s_canvas_mgr.set_active(canvas, active); } +void _3DScene::set_as_dirty(wxGLCanvas* canvas) +{ + s_canvas_mgr.set_as_dirty(canvas); +} + unsigned int _3DScene::get_volumes_count(wxGLCanvas* canvas) { return s_canvas_mgr.get_volumes_count(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index c6a166397..c317dba24 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -517,6 +517,7 @@ public: static bool init(wxGLCanvas* canvas); static void set_active(wxGLCanvas* canvas, bool active); + static void set_as_dirty(wxGLCanvas* canvas); 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 d3153bdb4..6f23af5a3 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1536,6 +1536,11 @@ void GLCanvas3D::set_active(bool active) m_active = active; } +void GLCanvas3D::set_as_dirty() +{ + m_dirty = true; +} + unsigned int GLCanvas3D::get_volumes_count() const { return (unsigned int)m_volumes.volumes.size(); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index c503d1845..18011f497 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -452,6 +452,7 @@ public: bool set_current(); void set_active(bool active); + void set_as_dirty(); unsigned int get_volumes_count() const; void reset_volumes(); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index bdca73854..81efe4408 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -219,6 +219,13 @@ void GLCanvas3DManager::set_active(wxGLCanvas* canvas, bool active) it->second->set_active(active); } +void GLCanvas3DManager::set_as_dirty(wxGLCanvas* canvas) +{ + CanvasesMap::iterator it = _get_canvas(canvas); + if (it != m_canvases.end()) + it->second->set_as_dirty(); +} + unsigned int GLCanvas3DManager::get_volumes_count(wxGLCanvas* canvas) const { CanvasesMap::const_iterator it = _get_canvas(canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp index 3092925d3..8726eb0b1 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -70,6 +70,7 @@ public: bool init(wxGLCanvas* canvas); void set_active(wxGLCanvas* canvas, bool active); + void set_as_dirty(wxGLCanvas* canvas); 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 29f35293b..d46c06120 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -197,6 +197,12 @@ set_active(canvas, active) CODE: _3DScene::set_active((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), active); +void +set_as_dirty(canvas) + SV *canvas; + CODE: + _3DScene::set_as_dirty((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + unsigned int get_volumes_count(canvas) SV *canvas;