Merge branch 'dk_notifications' into master

This commit is contained in:
David Kocik 2020-12-16 17:44:31 +01:00
commit 642223dadc
3 changed files with 49 additions and 29 deletions

View file

@ -20,11 +20,11 @@ static constexpr float GAP_WIDTH = 10.0f;
static constexpr float SPACE_RIGHT_PANEL = 10.0f; static constexpr float SPACE_RIGHT_PANEL = 10.0f;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
static constexpr float FADING_OUT_DURATION = 2.0f; 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; static constexpr int FADING_OUT_TIMEOUT = 100;
// If timeout is changed to higher than 1 second, substract_time call should be revorked // 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_MILISECONDS = 1000;
static constexpr int MAX_TIMEOUT_SECONDS = 1; //static constexpr int MAX_TIMEOUT_SECONDS = 1;
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
namespace Slic3r { namespace Slic3r {
@ -139,6 +139,7 @@ NotificationManager::PopNotification::PopNotification(const NotificationData &n,
, m_hypertext (n.hypertext) , m_hypertext (n.hypertext)
, m_text2 (n.text2) , m_text2 (n.text2)
, m_evt_handler (evt_handler) , m_evt_handler (evt_handler)
, m_notification_start (GLCanvas3D::timestamp_now())
{ {
//init(); //init();
} }
@ -760,29 +761,29 @@ void NotificationManager::PopNotification::update_state()
return; return;
} }
int64_t now = GLCanvas3D::timestamp_now();
if (m_hovered) { if (m_hovered) {
// reset fading // reset fading
m_fading_out = false; m_fading_out = false;
m_current_fade_opacity = 1.0f; m_current_fade_opacity = 1.0f;
m_remaining_time = m_data.duration; m_remaining_time = m_data.duration;
// m_notification_start = GLCanvas3D::timestamp_now(); m_notification_start = now;
// BOOST_LOG_TRIVIAL(error) << "hover";
} }
int64_t now = GLCanvas3D::timestamp_now();
if (m_counting_down) { 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) if (m_fading_out && m_current_fade_opacity <= 0.0f)
m_finished = true; 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_out = true;
m_fading_start = now; m_fading_start = now;
m_last_render_fading = now; m_last_render_fading = now;
} else if (!m_fading_out) { } else if (!m_fading_out) {
m_next_render = std::min<int64_t>(/*m_data.duration * 1000 - up_time*/m_remaining_time * 1000, MAX_TIMEOUT_MILISECONDS); m_next_render = m_data.duration * 1000 - up_time;//std::min<int64_t>(/*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);
} }
} }
@ -790,14 +791,12 @@ void NotificationManager::PopNotification::update_state()
if (m_finished) { if (m_finished) {
m_state = EState::Finished; m_state = EState::Finished;
m_next_render = 0; m_next_render = 0;
//BOOST_LOG_TRIVIAL(error) << "EState::Finished";
return; return;
} }
if (m_close_pending) { if (m_close_pending) {
m_finished = true; m_finished = true;
m_state = EState::ClosePending; m_state = EState::ClosePending;
m_next_render = 0; m_next_render = 0;
//BOOST_LOG_TRIVIAL(error) << "EState::ClosePending";
return; return;
} }
if (m_fading_out) { if (m_fading_out) {
@ -813,10 +812,8 @@ void NotificationManager::PopNotification::update_state()
m_next_render = 0; m_next_render = 0;
} else } else
m_next_render = next_render; 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 #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<NotificationManager::PopNotification> notification, int timestamp) bool NotificationManager::push_notification_data(std::unique_ptr<NotificationManager::PopNotification> notification, int timestamp)
{ {
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
m_requires_update = true; m_requires_update = true;
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
// if timestamped notif, push only new one // if timestamped notif, push only new one
if (timestamp != 0) { if (timestamp != 0) {
if (m_used_timestamps.find(timestamp) == m_used_timestamps.end()) { if (m_used_timestamps.find(timestamp) == m_used_timestamps.end()) {
@ -1242,6 +1240,7 @@ bool NotificationManager::push_notification_data(std::unique_ptr<NotificationMan
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::render_notifications(float overlay_width) void NotificationManager::render_notifications(float overlay_width)
{ {
sort_notifications(); sort_notifications();
GLCanvas3D& canvas = *wxGetApp().plater()->get_current_canvas3D(); GLCanvas3D& canvas = *wxGetApp().plater()->get_current_canvas3D();
@ -1376,6 +1375,14 @@ void NotificationManager::set_in_preview(bool preview)
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void NotificationManager::update_notifications() void NotificationManager::update_notifications()
{ {
// no update if not top window
wxWindow* p = dynamic_cast<wxWindow*>(wxGetApp().plater());
while (p->GetParent() != nullptr)
p = p->GetParent();
wxTopLevelWindow* top_level_wnd = dynamic_cast<wxTopLevelWindow*>(p);
if (!top_level_wnd->IsActive())
return;
static size_t last_size = m_pop_notifications.size(); static size_t last_size = m_pop_notifications.size();
for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) {
@ -1388,7 +1395,7 @@ void NotificationManager::update_notifications()
++it; ++it;
} }
} }
/*
m_requires_update = false; m_requires_update = false;
for (const std::unique_ptr<PopNotification>& notification : m_pop_notifications) { for (const std::unique_ptr<PopNotification>& notification : m_pop_notifications) {
if (notification->requires_update()) { if (notification->requires_update()) {
@ -1396,7 +1403,7 @@ void NotificationManager::update_notifications()
break; break;
} }
} }
*/
// update hovering state // update hovering state
m_hovered = false; m_hovered = false;
for (const std::unique_ptr<PopNotification>& notification : m_pop_notifications) { for (const std::unique_ptr<PopNotification>& notification : m_pop_notifications) {
@ -1406,7 +1413,7 @@ void NotificationManager::update_notifications()
} }
} }
/*
// Reuire render if some notification was just deleted. // Reuire render if some notification was just deleted.
size_t curr_size = m_pop_notifications.size(); size_t curr_size = m_pop_notifications.size();
m_requires_render = m_hovered || (last_size != curr_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 // Make sure there will be update after last notification erased
if (m_requires_render) if (m_requires_render)
m_requires_update = true; m_requires_update = true;
*/
//request frames //request frames
int64_t next_render = std::numeric_limits<int64_t>::max(); int64_t next_render = std::numeric_limits<int64_t>::max();
const int64_t max = std::numeric_limits<int64_t>::max(); const int64_t max = std::numeric_limits<int64_t>::max();
@ -1437,6 +1444,7 @@ void NotificationManager::update_notifications()
else if (next_render < max) else if (next_render < max)
wxGetApp().plater()->get_current_canvas3D()->request_extra_frame_delayed(int(next_render)); wxGetApp().plater()->get_current_canvas3D()->request_extra_frame_delayed(int(next_render));
/*
// actualizate timers // actualizate timers
wxWindow* p = dynamic_cast<wxWindow*>(wxGetApp().plater()); wxWindow* p = dynamic_cast<wxWindow*>(wxGetApp().plater());
while (p->GetParent() != nullptr) while (p->GetParent() != nullptr)
@ -1460,6 +1468,7 @@ void NotificationManager::update_notifications()
} }
} }
} }
*/
} }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT

View file

@ -148,13 +148,13 @@ public:
void set_in_preview(bool preview); void set_in_preview(bool preview);
// Move to left to avoid colision with variable layer height gizmo. // Move to left to avoid colision with variable layer height gizmo.
void set_move_from_overlay(bool move) { m_move_from_overlay = move; } void set_move_from_overlay(bool move) { m_move_from_overlay = move; }
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
void update_notifications();
bool requires_update() const { return m_requires_update; } bool requires_update() const { return m_requires_update; }
bool requires_render() const { return m_requires_render; } bool requires_render() const { return m_requires_render; }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
private: private:
// duration 0 means not disapearing // duration 0 means not disapearing
struct NotificationData { struct NotificationData {
@ -189,6 +189,7 @@ private:
class PopNotification class PopNotification
{ {
public: public:
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
enum class EState enum class EState
{ {
@ -209,6 +210,7 @@ private:
Hovered Hovered
}; };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
PopNotification(const NotificationData &n, NotificationIDProvider &id_provider, wxEvtHandler* evt_handler); PopNotification(const NotificationData &n, NotificationIDProvider &id_provider, wxEvtHandler* evt_handler);
virtual ~PopNotification() { if (m_id) m_id_provider.release_id(m_id); } virtual ~PopNotification() { if (m_id) m_id_provider.release_id(m_id); }
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
@ -238,13 +240,15 @@ private:
bool compare_text(const std::string& text); bool compare_text(const std::string& text);
void hide(bool h) { m_hidden = h; } void hide(bool h) { m_hidden = h; }
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// sets m_next_render with time of next mandatory rendering
void update_state(); 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_render() const { return m_state == EState::FadingOutRender || m_state == EState::ClosePending || m_state == EState::Finished; }
bool requires_update() const { return m_state != EState::Hidden; } bool requires_update() const { return m_state != EState::Hidden; }
*/
EState get_state() const { return m_state; } EState get_state() const { return m_state; }
int64_t next_render() const { return m_next_render; }
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
protected: protected:
// Call after every size change // Call after every size change
void init(); void init();
@ -279,9 +283,11 @@ private:
// For reusing ImGUI windows. // For reusing ImGUI windows.
NotificationIDProvider &m_id_provider; NotificationIDProvider &m_id_provider;
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
EState m_state { EState::Unknown }; EState m_state { EState::Unknown };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
int m_id { 0 }; int m_id { 0 };
bool m_initialized { false }; bool m_initialized { false };
// Main text // Main text
@ -302,7 +308,7 @@ private:
// time of last done render when fading // time of last done render when fading
int64_t m_last_render_fading { 0LL }; int64_t m_last_render_fading { 0LL };
// first appereance of notification or last hover; // first appereance of notification or last hover;
// int64_t m_notification_start; int64_t m_notification_start;
// time to next must-do render // time to next must-do render
int64_t m_next_render { std::numeric_limits<int64_t>::max() }; int64_t m_next_render { std::numeric_limits<int64_t>::max() };
#else #else
@ -432,8 +438,12 @@ private:
void sort_notifications(); void sort_notifications();
// If there is some error notification active, then the "Export G-code" notification after the slicing is finished is suppressed. // 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(); bool has_slicing_error_notification();
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
// Target for wxWidgets events sent by clicking on the hyperlink available at some notifications. // 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; wxEvtHandler* m_evt_handler;
// Cache of IDs to identify and reuse ImGUI windows. // Cache of IDs to identify and reuse ImGUI windows.
NotificationIDProvider m_id_provider; NotificationIDProvider m_id_provider;
@ -448,11 +458,12 @@ private:
bool m_in_preview { false }; bool m_in_preview { false };
// True if the layer editing is enabled in Plater, so that the notifications are shifted left of it. // True if the layer editing is enabled in Plater, so that the notifications are shifted left of it.
bool m_move_from_overlay { false }; bool m_move_from_overlay { false };
/*
#if ENABLE_NEW_NOTIFICATIONS_FADE_OUT #if ENABLE_NEW_NOTIFICATIONS_FADE_OUT
bool m_requires_update{ false }; bool m_requires_update{ false };
bool m_requires_render{ false }; bool m_requires_render{ false };
#endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT #endif // ENABLE_NEW_NOTIFICATIONS_FADE_OUT
*/
//prepared (basic) notifications //prepared (basic) notifications
const std::vector<NotificationData> basic_notifications = { const std::vector<NotificationData> basic_notifications = {
// {NotificationType::SlicingNotPossible, NotificationLevel::RegularNotification, 10, _u8L("Slicing is not possible.")}, // {NotificationType::SlicingNotPossible, NotificationLevel::RegularNotification, 10, _u8L("Slicing is not possible.")},

View file

@ -741,7 +741,7 @@ void PresetUpdater::slic3r_update_notify()
PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, bool no_notification) const PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3r_version, bool no_notification) const
{ {
if (! p->enabled_config_update) { return R_NOOP; } if (! p->enabled_config_update) { return R_NOOP; }
auto updates = p->get_config_updates(old_slic3r_version); auto updates = p->get_config_updates(old_slic3r_version);
if (updates.incompats.size() > 0) { if (updates.incompats.size() > 0) {
BOOST_LOG_TRIVIAL(info) << format("%1% bundles incompatible. Asking for action...", updates.incompats.size()); BOOST_LOG_TRIVIAL(info) << format("%1% bundles incompatible. Asking for action...", updates.incompats.size());