3DScene layer_editing_allowed method moved to c++

This commit is contained in:
Enrico Turri 2018-05-25 16:28:24 +02:00
parent c51ce63b9b
commit a8311bd1bd
9 changed files with 51 additions and 18 deletions

View File

@ -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}) {

View File

@ -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)

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;