From 11c91d781e4c56c5047a692f743d5f65a938c561 Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Tue, 17 Aug 2021 15:28:08 +0200 Subject: [PATCH] FIX: extra frame request Do not freeze bargraph in Siplify dialog when no mouse move. --- src/slic3r/GUI/GLCanvas3D.cpp | 19 ++++++----------- src/slic3r/GUI/GLCanvas3D.hpp | 4 +--- src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp | 25 +++++++++-------------- src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp | 9 ++++---- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 529056e99..96cf015ea 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -2780,11 +2780,10 @@ void GLCanvas3D::on_timer(wxTimerEvent& evt) void GLCanvas3D::on_render_timer(wxTimerEvent& evt) { - // no need to do anything here - // right after this event is recieved, idle event is fired - - //m_dirty = true; - //wxWakeUpIdle(); + m_dirty = true; + // wxWakeUpIdle(); + // no need to wake up idle + // right after this event, idle event is fired } @@ -2802,21 +2801,15 @@ void GLCanvas3D::schedule_extra_frame(int miliseconds) return; } } - // Start timer - int64_t now = timestamp_now(); + int remaining_time = m_render_timer.GetInterval(); // Timer is not running - if (! m_render_timer.IsRunning()) { - m_extra_frame_requested_delayed = miliseconds; + if (!m_render_timer.IsRunning()) { m_render_timer.StartOnce(miliseconds); - m_render_timer_start = now; // Timer is running - restart only if new period is shorter than remaning period } else { - const int64_t remaining_time = (m_render_timer_start + m_extra_frame_requested_delayed) - now; if (miliseconds + 20 < remaining_time) { m_render_timer.Stop(); - m_extra_frame_requested_delayed = miliseconds; m_render_timer.StartOnce(miliseconds); - m_render_timer_start = now; } } } diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index d9cd55e35..ba8430c07 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -463,15 +463,13 @@ private: std::string m_sidebar_field; // when true renders an extra frame by not resetting m_dirty to false // see request_extra_frame() - bool m_extra_frame_requested; - int m_extra_frame_requested_delayed { std::numeric_limits::max() }; + bool m_extra_frame_requested; bool m_event_handlers_bound{ false }; GLVolumeCollection m_volumes; GCodeViewer m_gcode_viewer; RenderTimer m_render_timer; - int64_t m_render_timer_start; Selection m_selection; const DynamicPrintConfig* m_config; diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp index 23ab4ef13..06a999cad 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.cpp @@ -184,7 +184,7 @@ void GLGizmoSimplify::on_render_input_window(float x, float y, float bottom_limi } ImGui::SameLine(m_gui_cfg->bottom_left_width); if (m_imgui->button(_L("Preview"))) { - m_state = State::simplifying; + m_state = State::preview; // simplify but not aply on mesh process(); } @@ -263,23 +263,18 @@ void GLGizmoSimplify::process() if (m_state == State::canceling) { throw SimplifyCanceledException(); } - }; + }; std::function statusfn = [&](int percent) { m_progress = percent; m_parent.schedule_extra_frame(0); }; indexed_triangle_set collapsed; - if (m_last_error.has_value()) { - // is chance to continue with last reduction - const indexed_triangle_set &its = m_volume->mesh().its; - uint32_t last_triangle_count = static_cast(its.indices.size()); - if ((!m_configuration.use_count || triangle_count <= last_triangle_count) && - (!m_configuration.use_error || m_configuration.max_error <= *m_last_error)) { - collapsed = its; // small copy - } else { - collapsed = *m_original_its; // copy - } + if (m_last_error.has_value() && m_last_count.has_value() && + (!m_configuration.use_count || triangle_count <= *m_last_count) && + (!m_configuration.use_error || m_configuration.max_error <= *m_last_error)) { + // continue from last reduction - speed up + collapsed = m_volume->mesh().its; // small copy } else { collapsed = *m_original_its; // copy } @@ -288,14 +283,14 @@ void GLGizmoSimplify::process() its_quadric_edge_collapse(collapsed, triangle_count, &max_error, throw_on_cancel, statusfn); set_its(collapsed); m_is_valid_result = true; + m_last_count = triangle_count; // need to store last requirement, collapsed count could be count-1 m_last_error = max_error; } catch (SimplifyCanceledException &) { // set state out of main thread + m_last_error = {}; m_state = State::settings; } - // need to render last status fn - // without sleep it freezes until mouse move - std::this_thread::sleep_for(std::chrono::milliseconds(50)); + // need to render last status fn to change bar graph to buttons m_parent.schedule_extra_frame(0); }); } diff --git a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp index 57174b7c1..5a84cabad 100644 --- a/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp +++ b/src/slic3r/GUI/Gizmos/GLGizmoSimplify.hpp @@ -36,17 +36,18 @@ private: size_t m_obj_index; std::optional m_original_its; + std::optional m_last_error; // for use previous reduction + std::optional m_last_count; volatile bool m_need_reload; // after simplify, glReload must be on main thread std::thread m_worker; enum class State { settings, - simplifying, // start processing - canceling, // canceled - successfull, // successful simplified - close_on_end + preview, // simplify to show preview + close_on_end, // simplify with close on end + canceling // after button click, before canceled }; volatile State m_state;