diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp index 2952c5e818..9cda6d75b3 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.cpp @@ -157,9 +157,8 @@ void GLGizmoBase::update(const UpdateData& data) bool GLGizmoBase::update_items_state() { - std::lock_guard g(m_dirty_access); bool res = m_dirty; - m_dirty = false; + m_dirty = false; return res; }; @@ -218,8 +217,7 @@ std::string GLGizmoBase::format(float value, unsigned int decimals) const return Slic3r::string_printf("%.*f", decimals, value); } -void GLGizmoBase::set_dirty() { - std::lock_guard g(m_dirty_access); +void GLGizmoBase::set_dirty() { m_dirty = true; } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp index af1cc6bab2..8b033ce732 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoBase.hpp @@ -1,7 +1,6 @@ #ifndef slic3r_GLGizmoBase_hpp_ #define slic3r_GLGizmoBase_hpp_ -#include #include "libslic3r/Point.hpp" #include "slic3r/GUI/I18N.hpp" @@ -154,6 +153,8 @@ public: bool is_dragging() const { return m_dragging; } void update(const UpdateData& data); + + // returns True when Gizmo changed its state bool update_items_state(); void render() { m_tooltip.clear(); on_render(); } @@ -190,10 +191,11 @@ protected: std::string format(float value, unsigned int decimals) const; + // Mark gizmo as dirty to Re-Render when idle() void set_dirty(); - private: - std::mutex m_dirty_access; + // Flag for dirty visible state of Gizmo + // When True then need new rendering bool m_dirty; }; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index eae79b8edf..6d3031dce1 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -253,7 +253,7 @@ void GLGizmoSimplify::process() plater->clear_before_change_mesh(m_obj_index); m_progress = 0; if (m_worker.joinable()) m_worker.join(); - m_worker = std::thread([&]() { + m_worker = std::thread([this]() { // store original triangles uint32_t triangle_count = (m_configuration.use_count) ? m_configuration.wanted_count : 0; float max_error = (m_configuration.use_error) ? @@ -264,10 +264,16 @@ void GLGizmoSimplify::process() throw SimplifyCanceledException(); } }; - std::function statusfn = [&](int percent) { + + std::function statusfn = [this](int 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; @@ -290,9 +296,8 @@ void GLGizmoSimplify::process() // set state out of main thread m_state = State::settings; } - // need to render last status fn to change bar graph to buttons - set_dirty(); - m_parent.schedule_extra_frame(0); + // need to render last status fn to change bar graph to buttons + request_rerender(); }); } @@ -335,6 +340,9 @@ void GLGizmoSimplify::on_set_state() // invalidate selected model 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; } +void GLGizmoSimplify::request_rerender() { + wxGetApp().plater()->CallAfter([this]() { + set_dirty(); + m_parent.schedule_extra_frame(0); + }); +} + } // namespace Slic3r::GUI diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 4539fef018..88e60a9fc2 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -35,6 +35,7 @@ private: void process(); void set_its(indexed_triangle_set &its); void create_gui_cfg(); + void request_rerender(); bool m_is_valid_result; // differ what to do in apply volatile int m_progress; // percent of done work