From a8311bd1bd75d93565afbb05e2bfaa80fbd317ee Mon Sep 17 00:00:00 2001 From: Enrico Turri Date: Fri, 25 May 2018 16:28:24 +0200 Subject: [PATCH] 3DScene layer_editing_allowed method moved to c++ --- lib/Slic3r/GUI/3DScene.pm | 16 ++++++++-------- lib/Slic3r/GUI/Plater.pm | 10 ++++++++-- xs/src/slic3r/GUI/3DScene.cpp | 5 +++++ xs/src/slic3r/GUI/3DScene.hpp | 1 + xs/src/slic3r/GUI/GLCanvas3D.cpp | 17 +++++++++++------ xs/src/slic3r/GUI/GLCanvas3D.hpp | 5 +++-- xs/src/slic3r/GUI/GLCanvas3DManager.cpp | 6 ++++++ xs/src/slic3r/GUI/GLCanvas3DManager.hpp | 1 + xs/xsp/GUI_3DScene.xsp | 8 ++++++++ 9 files changed, 51 insertions(+), 18 deletions(-) diff --git a/lib/Slic3r/GUI/3DScene.pm b/lib/Slic3r/GUI/3DScene.pm index b27b7d55f..b2a572c30 100644 --- a/lib/Slic3r/GUI/3DScene.pm +++ b/lib/Slic3r/GUI/3DScene.pm @@ -350,16 +350,16 @@ sub Destroy { # } # return $self->{layer_editing_enabled}; #} +# +#sub layer_editing_allowed { +# my ($self) = @_; +# # Allow layer editing if either the shaders were not initialized yet and we don't know +# # whether it will be possible to initialize them, +# # or if the initialization was done already and it failed. +# return ! (defined($self->{layer_editing_initialized}) && $self->{layer_editing_initialized} == 2); +#} #============================================================================================================================== -sub layer_editing_allowed { - my ($self) = @_; - # Allow layer editing if either the shaders were not initialized yet and we don't know - # whether it will be possible to initialize them, - # 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}) { diff --git a/lib/Slic3r/GUI/Plater.pm b/lib/Slic3r/GUI/Plater.pm index 3e78b5c95..f1ce8fe0a 100644 --- a/lib/Slic3r/GUI/Plater.pm +++ b/lib/Slic3r/GUI/Plater.pm @@ -1836,7 +1836,10 @@ sub on_config_change { #============================================================================================================================== $self->{canvas3D}->Refresh; $self->{canvas3D}->Update; - } elsif ($self->{canvas3D}->layer_editing_allowed) { +#============================================================================================================================== + } elsif (Slic3r::GUI::_3DScene::is_layers_editing_allowed($self->{canvas3D})) { +# } elsif ($self->{canvas3D}->layer_editing_allowed) { +#============================================================================================================================== # Want to allow the layer editing, but do it only if the OpenGL supports it. if ($self->{htoolbar}) { $self->{htoolbar}->EnableTool(TB_LAYER_EDITING, 1); @@ -1997,7 +2000,10 @@ sub object_list_changed { # Enable/disable buttons depending on whether there are any objects on the platter. my $have_objects = @{$self->{objects}} ? 1 : 0; - my $variable_layer_height_allowed = $self->{config}->variable_layer_height && $self->{canvas3D}->layer_editing_allowed; +#============================================================================================================================== + my $variable_layer_height_allowed = $self->{config}->variable_layer_height && Slic3r::GUI::_3DScene::is_layers_editing_allowed($self->{canvas3D}); +# my $variable_layer_height_allowed = $self->{config}->variable_layer_height && $self->{canvas3D}->layer_editing_allowed; +#============================================================================================================================== if ($self->{htoolbar}) { # On OSX or Linux $self->{htoolbar}->EnableTool($_, $have_objects) diff --git a/xs/src/slic3r/GUI/3DScene.cpp b/xs/src/slic3r/GUI/3DScene.cpp index 87071ce20..a9262337b 100644 --- a/xs/src/slic3r/GUI/3DScene.cpp +++ b/xs/src/slic3r/GUI/3DScene.cpp @@ -1939,6 +1939,11 @@ bool _3DScene::is_picking_enabled(wxGLCanvas* canvas) return s_canvas_mgr.is_picking_enabled(canvas); } +bool _3DScene::is_layers_editing_allowed(wxGLCanvas* canvas) +{ + return s_canvas_mgr.is_layers_editing_allowed(canvas); +} + bool _3DScene::is_multisample_allowed(wxGLCanvas* canvas) { return s_canvas_mgr.is_multisample_allowed(canvas); diff --git a/xs/src/slic3r/GUI/3DScene.hpp b/xs/src/slic3r/GUI/3DScene.hpp index 153744987..94ce59a3b 100644 --- a/xs/src/slic3r/GUI/3DScene.hpp +++ b/xs/src/slic3r/GUI/3DScene.hpp @@ -598,6 +598,7 @@ public: static bool is_layers_editing_enabled(wxGLCanvas* canvas); static bool is_picking_enabled(wxGLCanvas* canvas); + static bool is_layers_editing_allowed(wxGLCanvas* canvas); static bool is_multisample_allowed(wxGLCanvas* canvas); static void enable_layers_editing(wxGLCanvas* canvas, bool enable); diff --git a/xs/src/slic3r/GUI/GLCanvas3D.cpp b/xs/src/slic3r/GUI/GLCanvas3D.cpp index 823a4df0c..95ec9c342 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.cpp @@ -589,7 +589,7 @@ GLCanvas3D::LayersEditing::GLTextureData::GLTextureData(unsigned int id, int wid } GLCanvas3D::LayersEditing::LayersEditing() - : m_allowed(false) + : m_use_legacy_opengl(false) , m_enabled(false) , m_z_texture_id(0) , m_band_width(2.0f) @@ -636,12 +636,12 @@ bool GLCanvas3D::LayersEditing::init(const std::string& vertex_shader_filename, bool GLCanvas3D::LayersEditing::is_allowed() const { - return m_allowed; + return m_use_legacy_opengl && m_shader.is_initialized(); } -void GLCanvas3D::LayersEditing::set_allowed(bool allowed) +void GLCanvas3D::LayersEditing::set_use_legacy_opengl(bool use_legacy_opengl) { - m_allowed = allowed; + m_use_legacy_opengl = use_legacy_opengl; } bool GLCanvas3D::LayersEditing::is_enabled() const @@ -651,7 +651,7 @@ bool GLCanvas3D::LayersEditing::is_enabled() const void GLCanvas3D::LayersEditing::set_enabled(bool enabled) { - m_enabled = m_allowed && m_shader.is_initialized() && enabled; + m_enabled = is_allowed() && enabled; } unsigned int GLCanvas3D::LayersEditing::get_z_texture_id() const @@ -1030,7 +1030,7 @@ bool GLCanvas3D::init(bool useVBOs, bool use_legacy_opengl) if (useVBOs && !m_layers_editing.init("variable_layer_height.vs", "variable_layer_height.fs")) return false; - m_layers_editing.set_allowed(!use_legacy_opengl); + m_layers_editing.set_use_legacy_opengl(!use_legacy_opengl); return true; } @@ -1335,6 +1335,11 @@ bool GLCanvas3D::is_picking_enabled() const return m_picking_enabled; } +bool GLCanvas3D::is_layers_editing_allowed() const +{ + return m_layers_editing.is_allowed(); +} + bool GLCanvas3D::is_multisample_allowed() const { return m_multisample_allowed; diff --git a/xs/src/slic3r/GUI/GLCanvas3D.hpp b/xs/src/slic3r/GUI/GLCanvas3D.hpp index e110fee3b..2a78ded07 100644 --- a/xs/src/slic3r/GUI/GLCanvas3D.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3D.hpp @@ -211,7 +211,7 @@ public: GLTextureData(unsigned int id, int width, int height); }; - bool m_allowed; + bool m_use_legacy_opengl; bool m_enabled; Shader m_shader; unsigned int m_z_texture_id; @@ -226,7 +226,7 @@ public: bool init(const std::string& vertex_shader_filename, const std::string& fragment_shader_filename); bool is_allowed() const; - void set_allowed(bool allowed); + void set_use_legacy_opengl(bool use_legacy_opengl); bool is_enabled() const; void set_enabled(bool enabled); @@ -360,6 +360,7 @@ public: bool is_layers_editing_enabled() const; bool is_picking_enabled() const; + bool is_layers_editing_allowed() const; bool is_multisample_allowed() const; void enable_layers_editing(bool enable); diff --git a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp index 730badb87..2406f0094 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.cpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.cpp @@ -380,6 +380,12 @@ bool GLCanvas3DManager::is_picking_enabled(wxGLCanvas* canvas) const return (it != m_canvases.end()) ? it->second->is_picking_enabled() : false; } +bool GLCanvas3DManager::is_layers_editing_allowed(wxGLCanvas* canvas) const +{ + CanvasesMap::const_iterator it = _get_canvas(canvas); + return (it != m_canvases.end()) ? it->second->is_layers_editing_allowed() : false; +} + bool GLCanvas3DManager::is_multisample_allowed(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 cab1be2f5..14b857920 100644 --- a/xs/src/slic3r/GUI/GLCanvas3DManager.hpp +++ b/xs/src/slic3r/GUI/GLCanvas3DManager.hpp @@ -98,6 +98,7 @@ public: bool is_layers_editing_enabled(wxGLCanvas* canvas) const; bool is_picking_enabled(wxGLCanvas* canvas) const; + bool is_layers_editing_allowed(wxGLCanvas* canvas) const; bool is_multisample_allowed(wxGLCanvas* canvas) const; void enable_layers_editing(wxGLCanvas* canvas, bool enable); diff --git a/xs/xsp/GUI_3DScene.xsp b/xs/xsp/GUI_3DScene.xsp index 53688e8da..bbc8fc2f9 100644 --- a/xs/xsp/GUI_3DScene.xsp +++ b/xs/xsp/GUI_3DScene.xsp @@ -468,6 +468,14 @@ is_picking_enabled(canvas) OUTPUT: RETVAL +bool +is_layers_editing_allowed(canvas) + SV *canvas; + CODE: + RETVAL = _3DScene::is_layers_editing_allowed((wxGLCanvas*)wxPli_sv_2_object(aTHX_ canvas, "Wx::GLCanvas")); + OUTPUT: + RETVAL + bool is_multisample_allowed(canvas) SV *canvas;