Attempt to workaround bug in wxWidgets IsShownOnScreen() method

This commit is contained in:
Enrico Turri 2018-06-12 09:18:25 +02:00
parent 5f02669d2d
commit af3d07bb05
8 changed files with 34 additions and 19 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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