From e3330c6fba7db7932e485a1d0543ce23ce43cdfe Mon Sep 17 00:00:00 2001 From: "zhou.xu" Date: Fri, 22 Nov 2024 11:55:07 +0800 Subject: [PATCH] FIX:create new project should delete notification in last project jira:none Change-Id: I936e9a737f8b5e43905936d8796aeedd70248268 --- src/slic3r/GUI/NotificationManager.cpp | 78 +++++++++++++++++++++++++- src/slic3r/GUI/NotificationManager.hpp | 23 +++++--- src/slic3r/GUI/Plater.cpp | 9 +-- 3 files changed, 92 insertions(+), 18 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index f2264385f..458c6c3be 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -178,6 +178,18 @@ void NotificationManager::PopNotification::on_change_color_mode(bool is_dark) m_is_dark = is_dark; } +void NotificationManager::PopNotification::set_delete_callback(DeleteCallback callback) +{ + m_on_delete_callback =callback; +} + +bool NotificationManager::PopNotification::is_valid_delete_callback() +{ + if(m_on_delete_callback) + return true; + return false; +} + void NotificationManager::PopNotification::use_bbl_theme() { ensure_ui_inited(); @@ -408,6 +420,12 @@ void NotificationManager::PopNotification::bbl_render_block_notification(GLCanva ImGui::PopStyleColor(3); } +void NotificationManager::PopNotification::close() +{ + m_state = EState::ClosePending; + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); +} + bool NotificationManager::PopNotification::push_background_color() { if (m_is_gray) { @@ -970,6 +988,12 @@ bool NotificationManager::PopNotification::compare_text(const std::string& text) return false; } +void NotificationManager::PopNotification::hide(bool h) +{ + if (is_finished()) return; + m_state = h ? EState::Hidden : EState::Unknown; +} + bool NotificationManager::PopNotification::update_state(bool paused, const int64_t delta) { @@ -1792,6 +1816,37 @@ void NotificationManager::close_notification_of_type(const NotificationType type } } } + +void NotificationManager::close_and_delete_self(PopNotification * self) +{ + for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { + std::unique_ptr ¬ification = *it; + if (notification.get() == self) { + m_pop_notifications.erase(it); + break; + }else + ++it; + } +} + +void NotificationManager::remove_notification_of_type(const NotificationType type) { + for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { + std::unique_ptr ¬ification = *it; + if (notification->get_type() == type) { + it = m_pop_notifications.erase(it); + break; + } else + ++it; + } +} + +void NotificationManager::clear_all() +{ + for (size_t i = 0; i < size_t(NotificationType::NotificationTypeCount); i++) { + remove_notification_of_type((NotificationType)i); + } +} + void NotificationManager::remove_slicing_warnings_of_released_objects(const std::vector& living_oids) { for (std::unique_ptr ¬ification : m_pop_notifications) @@ -2202,7 +2257,12 @@ bool NotificationManager::push_notification_data(std::unique_ptris_valid_delete_callback()){ + auto delete_self = [this](NotificationManager::PopNotification* it) { + m_to_delete_after_finish_render = it; + }; + notification->set_delete_callback(delete_self); + } bool retval = false; if (this->activate_existing(notification.get())) { if (m_initialized) { // ignore update action - it cant be initialized if canvas and imgui context is not ready @@ -2276,6 +2336,10 @@ void NotificationManager::render_notifications(GLCanvas3D &canvas, float overlay ;// assert(i <= 1); } } + if (m_to_delete_after_finish_render) { + close_and_delete_self(m_to_delete_after_finish_render); + m_to_delete_after_finish_render = nullptr; + } m_last_render = GLCanvas3D::timestamp_now(); } @@ -2758,5 +2822,13 @@ void NotificationManager::set_scale(float scale) } -}//namespace GUI -}//namespace Slic3r +void NotificationManager::PlaterWarningNotification::close() +{ + if (is_finished()) + return; + m_state = EState::Hidden; + wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); + if(m_on_delete_callback) + m_on_delete_callback(this); +} +}}//namespace Slic3r diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index beee3a4af..83abd2982 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -43,7 +43,7 @@ enum class InfoItemType; enum class NotificationType { - CustomNotification, + CustomNotification = 0, // SlicingNotPossible, // Notification on end of export to a removable media, with hyperling to eject the external media. // Obsolete by ExportFinished @@ -145,7 +145,10 @@ enum class NotificationType BBLPreviewOnlyMode, BBLPrinterConfigUpdateAvailable, BBLUserPresetExceedLimit, - BBLBedFilamentIncompatible + BBLSliceLimitError, + BBLBedFilamentIncompatible, + NotificationTypeCount + }; class NotificationManager @@ -279,6 +282,8 @@ public: void render_notifications(GLCanvas3D &canvas, float overlay_width, float bottom_margin, float right_margin); // finds and closes all notifications of given type void close_notification_of_type(const NotificationType type); + void remove_notification_of_type(const NotificationType type); + void clear_all(); // Hides warnings in G-code preview. Should be called from plater only when 3d view/ preview is changed void set_in_preview(bool preview); // Calls set_in_preview to apply appearing or disappearing of some notificatons; @@ -395,7 +400,7 @@ private: virtual void render(GLCanvas3D& canvas, float initial_y, bool move_from_overlay, float overlay_width, float right_margin); virtual void bbl_render_block_notification(GLCanvas3D &canvas, float initial_y, bool move_from_overlay, float overlay_width, float right_margin); // close will dissapear notification on next render - virtual void close() { m_state = EState::ClosePending; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0);} + virtual void close(); // data from newer notification of same type void update(const NotificationData& n); void append(const std::string& append_str); @@ -413,7 +418,7 @@ private: const bool is_gray() const { return m_is_gray; } void set_gray(bool g) { m_is_gray = g; } virtual bool compare_text(const std::string& text) const; - void hide(bool h) { if (is_finished()) return; m_state = h ? EState::Hidden : EState::Unknown; } + void hide(bool h); // sets m_next_render with time of next mandatory rendering. Delta is time since last render. virtual bool update_state(bool paused, const int64_t delta); int64_t next_render() const { return is_finished() ? 0 : m_next_render; } @@ -425,7 +430,9 @@ private: void set_Multiline(bool Multi) { m_multiline = Multi; } virtual void on_change_color_mode(bool is_dark); void set_scale(float scale) { m_scale = scale; } - + typedef std::function DeleteCallback; + void set_delete_callback(DeleteCallback); + bool is_valid_delete_callback(); protected: // Call after every size change virtual void init(); @@ -529,6 +536,7 @@ private: std::string error_start = ""; std::string error_end = ""; + DeleteCallback m_on_delete_callback; // inner variables to position notification window, texts and buttons correctly // all space without text @@ -561,7 +569,7 @@ private: float m_scale = 1.0f; }; - + void close_and_delete_self(PopNotification*); class ObjectIDNotification : public PopNotification { @@ -577,7 +585,7 @@ private: { public: PlaterWarningNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler) : PopNotification(n, id_provider, evt_handler) {} - void close() override { if(is_finished()) return; m_state = EState::Hidden; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); } + void close() override; void real_close() { m_state = EState::ClosePending; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); } void show() { m_state = EState::Unknown; } }; @@ -813,6 +821,7 @@ private: // Cache of IDs to identify and reuse ImGUI windows. NotificationIDProvider m_id_provider; std::deque> m_pop_notifications; + PopNotification* m_to_delete_after_finish_render{nullptr}; // delayed waiting notifications, first is remaining time std::vector m_waiting_notifications; //timestamps used for slicing finished - notification could be gone so it needs to be stored here diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 5c5acb96b..a4ef100dd 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -8943,14 +8943,7 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString &project_ m_only_gcode = false; m_exported_file = false; m_loading_project = false; - get_notification_manager()->bbl_close_plateinfo_notification(); - get_notification_manager()->bbl_close_preview_only_notification(); - get_notification_manager()->bbl_close_3mf_warn_notification(); - get_notification_manager()->close_notification_of_type(NotificationType::PlaterError); - get_notification_manager()->close_notification_of_type(NotificationType::PlaterWarning); - get_notification_manager()->close_notification_of_type(NotificationType::SlicingError); - get_notification_manager()->close_notification_of_type(NotificationType::SlicingSeriousWarning); - get_notification_manager()->close_notification_of_type(NotificationType::SlicingWarning); + get_notification_manager()->clear_all(); if (!silent) wxGetApp().mainframe->select_tab(MainFrame::tp3DEditor);