From 99747f8f256064f06329fea9a96a15705e042e64 Mon Sep 17 00:00:00 2001 From: David Kocik Date: Wed, 16 Dec 2020 17:42:50 +0100 Subject: Changed requested time of rendering for timed notification to full duration. Commented unused code. --- src/slic3r/GUI/NotificationManager.cpp | 47 ++++++++++++++++++++-------------- src/slic3r/GUI/NotificationManager.hpp | 29 ++++++++++++++------- src/slic3r/Utils/PresetUpdater.cpp | 2 +- 3 files changed, 49 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index fa5aab66c..c2c7727ed 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -20,11 +20,11 @@ static constexpr float GAP_WIDTH = 10.0f; static constexpr float SPACE_RIGHT_PANEL = 10.0f; #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT static constexpr float FADING_OUT_DURATION = 2.0f; -// Time in Miliseconds after next render is requested +// Time in Miliseconds after next render when fading out is requested static constexpr int FADING_OUT_TIMEOUT = 100; // If timeout is changed to higher than 1 second, substract_time call should be revorked -static constexpr int MAX_TIMEOUT_MILISECONDS = 1000; -static constexpr int MAX_TIMEOUT_SECONDS = 1; +//static constexpr int MAX_TIMEOUT_MILISECONDS = 1000; +//static constexpr int MAX_TIMEOUT_SECONDS = 1; #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT namespace Slic3r { @@ -139,6 +139,7 @@ NotificationManager::PopNotification::PopNotification(const NotificationData &n, , m_hypertext (n.hypertext) , m_text2 (n.text2) , m_evt_handler (evt_handler) + , m_notification_start (GLCanvas3D::timestamp_now()) { //init(); } @@ -760,29 +761,29 @@ void NotificationManager::PopNotification::update_state() return; } + int64_t now = GLCanvas3D::timestamp_now(); + if (m_hovered) { // reset fading m_fading_out = false; m_current_fade_opacity = 1.0f; m_remaining_time = m_data.duration; -// m_notification_start = GLCanvas3D::timestamp_now(); -// BOOST_LOG_TRIVIAL(error) << "hover"; + m_notification_start = now; } - int64_t now = GLCanvas3D::timestamp_now(); + if (m_counting_down) { - //int64_t up_time = GLCanvas3D::timestamp_now() - m_notification_start; + int64_t up_time = now - m_notification_start; if (m_fading_out && m_current_fade_opacity <= 0.0f) m_finished = true; - else if (!m_fading_out && m_remaining_time <=0/*up_time >= m_data.duration * 1000*/) { + else if (!m_fading_out && /*m_remaining_time <=0*/up_time >= m_data.duration * 1000) { m_fading_out = true; m_fading_start = now; m_last_render_fading = now; } else if (!m_fading_out) { - m_next_render = std::min(/*m_data.duration * 1000 - up_time*/m_remaining_time * 1000, MAX_TIMEOUT_MILISECONDS); - //BOOST_LOG_TRIVIAL(error) << (boost::format("up time %1% next render %2%") % up_time % m_next_render); + m_next_render = m_data.duration * 1000 - up_time;//std::min(/*m_data.duration * 1000 - up_time*/m_remaining_time * 1000, MAX_TIMEOUT_MILISECONDS); } } @@ -790,14 +791,12 @@ void NotificationManager::PopNotification::update_state() if (m_finished) { m_state = EState::Finished; m_next_render = 0; - //BOOST_LOG_TRIVIAL(error) << "EState::Finished"; return; } if (m_close_pending) { m_finished = true; m_state = EState::ClosePending; m_next_render = 0; - //BOOST_LOG_TRIVIAL(error) << "EState::ClosePending"; return; } if (m_fading_out) { @@ -813,10 +812,8 @@ void NotificationManager::PopNotification::update_state() m_next_render = 0; } else m_next_render = next_render; - //BOOST_LOG_TRIVIAL(error) << (boost::format("fade render %1%") % m_next_render); } } - //BOOST_LOG_TRIVIAL(error) << (boost::format("remaining time %1% fading %2% next render %3%") % m_remaining_time % m_fading_out % m_next_render); } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT @@ -1214,10 +1211,11 @@ bool NotificationManager::push_notification_data(const NotificationData& notific } bool NotificationManager::push_notification_data(std::unique_ptr notification, int timestamp) { +/* #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT m_requires_update = true; #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT - +*/ // if timestamped notif, push only new one if (timestamp != 0) { if (m_used_timestamps.find(timestamp) == m_used_timestamps.end()) { @@ -1242,6 +1240,7 @@ bool NotificationManager::push_notification_data(std::unique_ptrget_current_canvas3D(); @@ -1376,6 +1375,14 @@ void NotificationManager::set_in_preview(bool preview) #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT void NotificationManager::update_notifications() { + // no update if not top window + wxWindow* p = dynamic_cast(wxGetApp().plater()); + while (p->GetParent() != nullptr) + p = p->GetParent(); + wxTopLevelWindow* top_level_wnd = dynamic_cast(p); + if (!top_level_wnd->IsActive()) + return; + static size_t last_size = m_pop_notifications.size(); for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { @@ -1388,7 +1395,7 @@ void NotificationManager::update_notifications() ++it; } } - + /* m_requires_update = false; for (const std::unique_ptr& notification : m_pop_notifications) { if (notification->requires_update()) { @@ -1396,7 +1403,7 @@ void NotificationManager::update_notifications() break; } } - + */ // update hovering state m_hovered = false; for (const std::unique_ptr& notification : m_pop_notifications) { @@ -1406,7 +1413,7 @@ void NotificationManager::update_notifications() } } - + /* // Reuire render if some notification was just deleted. size_t curr_size = m_pop_notifications.size(); m_requires_render = m_hovered || (last_size != curr_size); @@ -1424,7 +1431,7 @@ void NotificationManager::update_notifications() // Make sure there will be update after last notification erased if (m_requires_render) m_requires_update = true; - + */ //request frames int64_t next_render = std::numeric_limits::max(); const int64_t max = std::numeric_limits::max(); @@ -1437,6 +1444,7 @@ void NotificationManager::update_notifications() else if (next_render < max) wxGetApp().plater()->get_current_canvas3D()->request_extra_frame_delayed(int(next_render)); + /* // actualizate timers wxWindow* p = dynamic_cast(wxGetApp().plater()); while (p->GetParent() != nullptr) @@ -1460,6 +1468,7 @@ void NotificationManager::update_notifications() } } } + */ } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 580c838c5..9252190ef 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -148,13 +148,13 @@ public: void set_in_preview(bool preview); // Move to left to avoid colision with variable layer height gizmo. void set_move_from_overlay(bool move) { m_move_from_overlay = move; } - +/* #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT - void update_notifications(); + bool requires_update() const { return m_requires_update; } bool requires_render() const { return m_requires_render; } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT - +*/ private: // duration 0 means not disapearing struct NotificationData { @@ -189,6 +189,7 @@ private: class PopNotification { public: + #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT enum class EState { @@ -209,6 +210,7 @@ private: Hovered }; #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT + PopNotification(const NotificationData &n, NotificationIDProvider &id_provider, wxEvtHandler* evt_handler); virtual ~PopNotification() { if (m_id) m_id_provider.release_id(m_id); } #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT @@ -238,13 +240,15 @@ private: bool compare_text(const std::string& text); void hide(bool h) { m_hidden = h; } #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT + // sets m_next_render with time of next mandatory rendering void update_state(); + int64_t next_render() const { return m_next_render; } + /* bool requires_render() const { return m_state == EState::FadingOutRender || m_state == EState::ClosePending || m_state == EState::Finished; } bool requires_update() const { return m_state != EState::Hidden; } + */ EState get_state() const { return m_state; } - int64_t next_render() const { return m_next_render; } #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT - protected: // Call after every size change void init(); @@ -279,9 +283,11 @@ private: // For reusing ImGUI windows. NotificationIDProvider &m_id_provider; + #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT EState m_state { EState::Unknown }; #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT + int m_id { 0 }; bool m_initialized { false }; // Main text @@ -302,7 +308,7 @@ private: // time of last done render when fading int64_t m_last_render_fading { 0LL }; // first appereance of notification or last hover; -// int64_t m_notification_start; + int64_t m_notification_start; // time to next must-do render int64_t m_next_render { std::numeric_limits::max() }; #else @@ -432,8 +438,12 @@ private: void sort_notifications(); // If there is some error notification active, then the "Export G-code" notification after the slicing is finished is suppressed. bool has_slicing_error_notification(); - - // Target for wxWidgets events sent by clicking on the hyperlink available at some notifications. +#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT + // perform update_state on each notification and ask for more frames if needed + void update_notifications(); +#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT + + // Target for wxWidgets events sent by clicking on the hyperlink available at some notifications. wxEvtHandler* m_evt_handler; // Cache of IDs to identify and reuse ImGUI windows. NotificationIDProvider m_id_provider; @@ -448,11 +458,12 @@ private: bool m_in_preview { false }; // True if the layer editing is enabled in Plater, so that the notifications are shifted left of it. bool m_move_from_overlay { false }; +/* #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT bool m_requires_update{ false }; bool m_requires_render{ false }; #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT - +*/ //prepared (basic) notifications const std::vector basic_notifications = { // {NotificationType::SlicingNotPossible, NotificationLevel::RegularNotification, 10, _u8L("Slicing is not possible.")}, diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 94de459bc..fa0f7b38e 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -741,7 +741,7 @@ void PresetUpdater::slic3r_update_notify() PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, bool no_notification) const { if (! p->enabled_config_update) { return R_NOOP; } - + auto updates = p->get_config_updates(old_slic3r_version); if (updates.incompats.size() > 0) { BOOST_LOG_TRIVIAL(info) << format("%1% bundles incompatible. Asking for action...", updates.incompats.size()); -- cgit v1.2.3