call render in main thread by function callAfter(hint by @Vojtech)

This commit is contained in:
Filip Sykala 2021-08-20 14:29:52 +02:00
parent 8fab4885c7
commit 6d895872b0
4 changed files with 30 additions and 14 deletions

View file

@ -157,9 +157,8 @@ void GLGizmoBase::update(const UpdateData& data)
bool GLGizmoBase::update_items_state() bool GLGizmoBase::update_items_state()
{ {
std::lock_guard<std::mutex> g(m_dirty_access);
bool res = m_dirty; bool res = m_dirty;
m_dirty = false; m_dirty = false;
return res; return res;
}; };
@ -218,8 +217,7 @@ std::string GLGizmoBase::format(float value, unsigned int decimals) const
return Slic3r::string_printf("%.*f", decimals, value); return Slic3r::string_printf("%.*f", decimals, value);
} }
void GLGizmoBase::set_dirty() { void GLGizmoBase::set_dirty() {
std::lock_guard<std::mutex> g(m_dirty_access);
m_dirty = true; m_dirty = true;
} }

View file

@ -1,7 +1,6 @@
#ifndef slic3r_GLGizmoBase_hpp_ #ifndef slic3r_GLGizmoBase_hpp_
#define slic3r_GLGizmoBase_hpp_ #define slic3r_GLGizmoBase_hpp_
#include <mutex>
#include "libslic3r/Point.hpp" #include "libslic3r/Point.hpp"
#include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/I18N.hpp"
@ -154,6 +153,8 @@ public:
bool is_dragging() const { return m_dragging; } bool is_dragging() const { return m_dragging; }
void update(const UpdateData& data); void update(const UpdateData& data);
// returns True when Gizmo changed its state
bool update_items_state(); bool update_items_state();
void render() { m_tooltip.clear(); on_render(); } void render() { m_tooltip.clear(); on_render(); }
@ -190,10 +191,11 @@ protected:
std::string format(float value, unsigned int decimals) const; std::string format(float value, unsigned int decimals) const;
// Mark gizmo as dirty to Re-Render when idle()
void set_dirty(); void set_dirty();
private: private:
std::mutex m_dirty_access; // Flag for dirty visible state of Gizmo
// When True then need new rendering
bool m_dirty; bool m_dirty;
}; };

View file

@ -253,7 +253,7 @@ void GLGizmoSimplify::process()
plater->clear_before_change_mesh(m_obj_index); plater->clear_before_change_mesh(m_obj_index);
m_progress = 0; m_progress = 0;
if (m_worker.joinable()) m_worker.join(); if (m_worker.joinable()) m_worker.join();
m_worker = std::thread([&]() { m_worker = std::thread([this]() {
// store original triangles // store original triangles
uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0; uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0;
float max_error = (m_configuration.use_error) ? float max_error = (m_configuration.use_error) ?
@ -264,10 +264,16 @@ void GLGizmoSimplify::process()
throw SimplifyCanceledException(); throw SimplifyCanceledException();
} }
}; };
std::function<void(int)> statusfn = [&](int percent) {
std::function<void(int)> statusfn = [this](int percent) {
m_progress = percent; m_progress = percent;
set_dirty();
m_parent.schedule_extra_frame(0); // check max 4fps
static int64_t last = 0;
int64_t now = m_parent.timestamp_now();
if ((now - last) < 250) return;
request_rerender();
}; };
indexed_triangle_set collapsed; indexed_triangle_set collapsed;
@ -290,9 +296,8 @@ void GLGizmoSimplify::process()
// set state out of main thread // set state out of main thread
m_state = State::settings; m_state = State::settings;
} }
// need to render last status fn to change bar graph to buttons // need to render last status fn to change bar graph to buttons
set_dirty(); request_rerender();
m_parent.schedule_extra_frame(0);
}); });
} }
@ -335,6 +340,9 @@ void GLGizmoSimplify::on_set_state()
// invalidate selected model // invalidate selected model
m_volume = nullptr; m_volume = nullptr;
} else if (GLGizmoBase::m_state == GLGizmoBase::On) {
// when open by hyperlink it needs to show up
request_rerender();
} }
} }
@ -360,4 +368,11 @@ void GLGizmoSimplify::create_gui_cfg() {
m_gui_cfg = cfg; m_gui_cfg = cfg;
} }
void GLGizmoSimplify::request_rerender() {
wxGetApp().plater()->CallAfter([this]() {
set_dirty();
m_parent.schedule_extra_frame(0);
});
}
} // namespace Slic3r::GUI } // namespace Slic3r::GUI

View file

@ -35,6 +35,7 @@ private:
void process(); void process();
void set_its(indexed_triangle_set &its); void set_its(indexed_triangle_set &its);
void create_gui_cfg(); void create_gui_cfg();
void request_rerender();
bool m_is_valid_result; // differ what to do in apply bool m_is_valid_result; // differ what to do in apply
volatile int m_progress; // percent of done work volatile int m_progress; // percent of done work