diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 1ac490b2d..ef9ea3dfb 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -211,7 +211,6 @@ sub new { # Initialize 3D toolpaths preview 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::enable_legend_texture($self->{preview3D}->canvas, 1); 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->{preview_notebook}->AddPage($self->{preview3D}, L('Preview')); @@ -227,19 +226,12 @@ sub new { EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{preview_notebook}, sub { my $preview = $self->{preview_notebook}->GetCurrentPage; if (($preview != $self->{preview3D}) && ($preview != $self->{canvas3D})) { - Slic3r::GUI::_3DScene::set_active($self->{preview3D}->canvas, 0); - Slic3r::GUI::_3DScene::set_active($self->{canvas3D}, 0); - Slic3r::GUI::_3DScene::reset_current_canvas(); $preview->OnActivate if $preview->can('OnActivate'); } elsif ($preview == $self->{preview3D}) { - Slic3r::GUI::_3DScene::set_active($self->{preview3D}->canvas, 1); - Slic3r::GUI::_3DScene::set_active($self->{canvas3D}, 0); $self->{preview3D}->load_print; # 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); } elsif ($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/lib/Slic3r/GUI/Plater/3DPreview.pm b/lib/Slic3r/GUI/Plater/3DPreview.pm index c7dab869f..9ed2374ec 100644 --- a/lib/Slic3r/GUI/Plater/3DPreview.pm +++ b/lib/Slic3r/GUI/Plater/3DPreview.pm @@ -279,7 +279,6 @@ sub reload_print { my ($self, $force) = @_; Slic3r::GUI::_3DScene::reset_volumes($self->canvas); - Slic3r::GUI::_3DScene::reset_current_canvas(); $self->_loaded(0); if (! $self->IsShown && ! $force) { diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 6738446b0..a52946afb 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1851,21 +1851,6 @@ bool _3DScene::init(wxGLCanvas* canvas) return s_canvas_mgr.init(canvas); } -bool _3DScene::set_current(wxGLCanvas* canvas, bool force) -{ - return s_canvas_mgr.set_current(canvas, force); -} - -void _3DScene::reset_current_canvas() -{ - s_canvas_mgr.set_current(nullptr, false); -} - -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); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index d1e6dbc61..f7fc75db5 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -509,10 +509,6 @@ public: static bool init(wxGLCanvas* canvas); - static bool set_current(wxGLCanvas* canvas, bool force); - static void reset_current_canvas(); - - static void set_active(wxGLCanvas* canvas, bool active); static void set_as_dirty(wxGLCanvas* canvas); static unsigned int get_volumes_count(wxGLCanvas* canvas); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index b522193ff..0767b197f 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -1449,15 +1449,14 @@ GLGizmoBase* GLCanvas3D::Gizmos::_get_current() const return (it != m_gizmos.end()) ? it->second : nullptr; } -GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) +GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas) : m_canvas(canvas) - , m_context(context) + , m_context(nullptr) , m_timer(nullptr) , m_config(nullptr) , 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) @@ -1475,7 +1474,10 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context) , m_reload_delayed(false) { if (m_canvas != nullptr) + { + m_context = new wxGLContext(m_canvas); m_timer = new wxTimer(m_canvas); + } } GLCanvas3D::~GLCanvas3D() @@ -1488,6 +1490,12 @@ GLCanvas3D::~GLCanvas3D() m_timer = nullptr; } + if (m_context != nullptr) + { + delete m_context; + m_context = nullptr; + } + _deregister_callbacks(); } @@ -1496,6 +1504,9 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) if (m_initialized) return true; + if ((m_canvas == nullptr) || (m_context == nullptr)) + return false; + ::glClearColor(1.0f, 1.0f, 1.0f, 1.0f); ::glClearDepth(1.0f); @@ -1561,19 +1572,14 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) return true; } -bool GLCanvas3D::set_current(bool force) +bool GLCanvas3D::set_current() { - if ((force || m_active) && (m_canvas != nullptr) && (m_context != nullptr)) + if ((m_canvas != nullptr) && (m_context != nullptr)) return m_canvas->SetCurrent(*m_context); return false; } -void GLCanvas3D::set_active(bool active) -{ - m_active = active; -} - void GLCanvas3D::set_as_dirty() { m_dirty = true; @@ -1590,7 +1596,7 @@ void GLCanvas3D::reset_volumes() if (!m_volumes.empty()) { // ensures this canvas is current - if ((m_canvas == nullptr) || !_3DScene::set_current(m_canvas, true)) + if (!set_current()) return; m_volumes.release_geometry(); @@ -1696,6 +1702,8 @@ void GLCanvas3D::set_bed_shape(const Pointfs& shape) // Set the origin and size for painting of the coordinate system axes. m_axes.origin = Pointf3(0.0, 0.0, (coordf_t)GROUND_Z); set_axes_length(0.3f * (float)m_bed.get_bounding_box().max_size()); + + m_dirty = true; } void GLCanvas3D::set_auto_bed_shape() @@ -1927,7 +1935,7 @@ void GLCanvas3D::render() return; // ensures this canvas is current and initialized - if (!_3DScene::set_current(m_canvas, false) || !_3DScene::init(m_canvas)) + if (!set_current() || !_3DScene::init(m_canvas)) return; if (m_force_zoom_to_bed_enabled) @@ -2010,7 +2018,7 @@ void GLCanvas3D::reload_scene(bool force) reset_volumes(); // ensures this canvas is current - if (!_3DScene::set_current(m_canvas, true)) + if (!set_current()) return; set_bed_shape(dynamic_cast(m_config->option("bed_shape"))->values); @@ -2086,7 +2094,7 @@ void GLCanvas3D::reload_scene(bool force) void GLCanvas3D::load_print_toolpaths() { // ensures this canvas is current - if (!_3DScene::set_current(m_canvas, true)) + if (!set_current()) return; if (m_print == nullptr) @@ -2454,7 +2462,7 @@ void GLCanvas3D::load_gcode_preview(const GCodePreviewData& preview_data, const if ((m_canvas != nullptr) && (m_print != nullptr)) { // ensures that this canvas is current - if (!_3DScene::set_current(m_canvas, true)) + if (!set_current()) return; if (m_volumes.empty()) @@ -2783,11 +2791,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) #endif } else if (evt.LeftDClick() && (m_hover_volume_id != -1)) - { - m_active = false; m_on_double_click_callback.call(); - m_active = true; - } else if (evt.LeftDown() || evt.RightDown()) { // If user pressed left or right button we first check whether this happened @@ -2883,11 +2887,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { // if right clicking on volume, propagate event through callback if (m_volumes.volumes[volume_idx]->hover) - { - m_active = false; m_on_right_click_callback.call(pos.x, pos.y); - m_active = true; - } } } } @@ -3165,7 +3165,7 @@ Point GLCanvas3D::get_local_mouse_position() const bool GLCanvas3D::_is_shown_on_screen() const { - return (m_canvas != nullptr) ? m_active && m_canvas->IsShownOnScreen() : false; + return (m_canvas != nullptr) ? m_canvas->IsShownOnScreen() : false; } void GLCanvas3D::_force_zoom_to_bed() @@ -3180,7 +3180,7 @@ void GLCanvas3D::_resize(unsigned int w, unsigned int h) return; // ensures that this canvas is current - _3DScene::set_current(m_canvas, false); + set_current(); ::glViewport(0, 0, w, h); ::glMatrixMode(GL_PROJECTION); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index 546d72f96..34a329e9c 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -412,9 +412,6 @@ 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; @@ -457,14 +454,13 @@ private: PerlCallback m_on_update_geometry_info_callback; public: - GLCanvas3D(wxGLCanvas* canvas, wxGLContext* context); + GLCanvas3D(wxGLCanvas* canvas); ~GLCanvas3D(); bool init(bool useVBOs, bool use_legacy_opengl); - bool set_current(bool force); + bool set_current(); - void set_active(bool active); void set_as_dirty(); unsigned int get_volumes_count() const; diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 116307678..8520754d9 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -114,20 +114,13 @@ std::string GLCanvas3DManager::GLInfo::to_string(bool format_as_html, bool exten } GLCanvas3DManager::GLCanvas3DManager() - : m_context(nullptr) - , m_current(nullptr) + : m_current(nullptr) , m_gl_initialized(false) , m_use_legacy_opengl(false) , m_use_VBOs(false) { } -GLCanvas3DManager::~GLCanvas3DManager() -{ - if (m_context != nullptr) - delete m_context; -} - bool GLCanvas3DManager::add(wxGLCanvas* canvas) { if (canvas == nullptr) @@ -136,14 +129,7 @@ bool GLCanvas3DManager::add(wxGLCanvas* canvas) if (_get_canvas(canvas) != m_canvases.end()) return false; - if (m_context == nullptr) - { - m_context = new wxGLContext(canvas); - if (m_context == nullptr) - return false; - } - - GLCanvas3D* canvas3D = new GLCanvas3D(canvas, m_context); + GLCanvas3D* canvas3D = new GLCanvas3D(canvas); if (canvas3D == nullptr) return false; @@ -213,41 +199,6 @@ bool GLCanvas3DManager::init(wxGLCanvas* canvas) return false; } -bool GLCanvas3DManager::set_current(wxGLCanvas* canvas, bool force) -{ - // given canvas is already current, return - if (m_current == canvas) - return true; - - if (canvas == nullptr) - { - m_current = nullptr; - return true; - } - - // set given canvas as current - CanvasesMap::iterator it = _get_canvas(canvas); - if (it != m_canvases.end()) - { - bool res = it->second->set_current(force); - if (res) - { - m_current = canvas; - return true; - } - } - - m_current = nullptr; - return false; -} - -void GLCanvas3DManager::set_active(wxGLCanvas* canvas, bool active) -{ - CanvasesMap::iterator it = _get_canvas(canvas); - if (it != m_canvases.end()) - it->second->set_active(active); -} - void GLCanvas3DManager::set_as_dirty(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 838abaed1..c813fd477 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -43,7 +43,6 @@ class GLCanvas3DManager typedef std::map CanvasesMap; - wxGLContext* m_context; CanvasesMap m_canvases; wxGLCanvas* m_current; GLInfo m_gl_info; @@ -53,7 +52,6 @@ class GLCanvas3DManager public: GLCanvas3DManager(); - ~GLCanvas3DManager(); bool add(wxGLCanvas* canvas); bool remove(wxGLCanvas* canvas); @@ -70,8 +68,6 @@ public: bool init(wxGLCanvas* canvas); - bool set_current(wxGLCanvas* canvas, bool force); - void set_active(wxGLCanvas* canvas, bool active); void set_as_dirty(wxGLCanvas* canvas); unsigned int get_volumes_count(wxGLCanvas* canvas) const; diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 9939f5240..65dfc8e8e 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -194,18 +194,6 @@ remove_all_canvases() CODE: _3DScene::remove_all_canvases(); -void -reset_current_canvas() - CODE: - _3DScene::reset_current_canvas(); - -void -set_active(canvas, active) - SV *canvas; - bool active; - CODE: - _3DScene::set_active((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas"), active); - void set_as_dirty(canvas) SV *canvas;