FIX:create new project should delete notification

in last project
jira:none

Change-Id: I936e9a737f8b5e43905936d8796aeedd70248268
This commit is contained in:
zhou.xu 2024-11-22 11:55:07 +08:00 committed by Lane.Wei
parent c1179de25a
commit e3330c6fba
3 changed files with 92 additions and 18 deletions

View File

@ -178,6 +178,18 @@ void NotificationManager::PopNotification::on_change_color_mode(bool is_dark)
m_is_dark = 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() void NotificationManager::PopNotification::use_bbl_theme()
{ {
ensure_ui_inited(); ensure_ui_inited();
@ -408,6 +420,12 @@ void NotificationManager::PopNotification::bbl_render_block_notification(GLCanva
ImGui::PopStyleColor(3); 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() bool NotificationManager::PopNotification::push_background_color()
{ {
if (m_is_gray) { if (m_is_gray) {
@ -970,6 +988,12 @@ bool NotificationManager::PopNotification::compare_text(const std::string& text)
return false; 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) 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<PopNotification> &notification = *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<PopNotification> &notification = *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<ObjectID>& living_oids) void NotificationManager::remove_slicing_warnings_of_released_objects(const std::vector<ObjectID>& living_oids)
{ {
for (std::unique_ptr<PopNotification> &notification : m_pop_notifications) for (std::unique_ptr<PopNotification> &notification : m_pop_notifications)
@ -2202,7 +2257,12 @@ bool NotificationManager::push_notification_data(std::unique_ptr<NotificationMan
return false; return false;
} }
} }
if(!notification->is_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; bool retval = false;
if (this->activate_existing(notification.get())) { if (this->activate_existing(notification.get())) {
if (m_initialized) { // ignore update action - it cant be initialized if canvas and imgui context is not ready 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); ;// 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(); m_last_render = GLCanvas3D::timestamp_now();
} }
@ -2758,5 +2822,13 @@ void NotificationManager::set_scale(float scale)
} }
}//namespace GUI void NotificationManager::PlaterWarningNotification::close()
}//namespace Slic3r {
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

View File

@ -43,7 +43,7 @@ enum class InfoItemType;
enum class NotificationType enum class NotificationType
{ {
CustomNotification, CustomNotification = 0,
// SlicingNotPossible, // SlicingNotPossible,
// Notification on end of export to a removable media, with hyperling to eject the external media. // Notification on end of export to a removable media, with hyperling to eject the external media.
// Obsolete by ExportFinished // Obsolete by ExportFinished
@ -145,7 +145,10 @@ enum class NotificationType
BBLPreviewOnlyMode, BBLPreviewOnlyMode,
BBLPrinterConfigUpdateAvailable, BBLPrinterConfigUpdateAvailable,
BBLUserPresetExceedLimit, BBLUserPresetExceedLimit,
BBLBedFilamentIncompatible BBLSliceLimitError,
BBLBedFilamentIncompatible,
NotificationTypeCount
}; };
class NotificationManager class NotificationManager
@ -279,6 +282,8 @@ public:
void render_notifications(GLCanvas3D &canvas, float overlay_width, float bottom_margin, float right_margin); void render_notifications(GLCanvas3D &canvas, float overlay_width, float bottom_margin, float right_margin);
// finds and closes all notifications of given type // finds and closes all notifications of given type
void close_notification_of_type(const NotificationType 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 // Hides warnings in G-code preview. Should be called from plater only when 3d view/ preview is changed
void set_in_preview(bool preview); void set_in_preview(bool preview);
// Calls set_in_preview to apply appearing or disappearing of some notificatons; // 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 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); 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 // 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 // data from newer notification of same type
void update(const NotificationData& n); void update(const NotificationData& n);
void append(const std::string& append_str); void append(const std::string& append_str);
@ -413,7 +418,7 @@ private:
const bool is_gray() const { return m_is_gray; } const bool is_gray() const { return m_is_gray; }
void set_gray(bool g) { m_is_gray = g; } void set_gray(bool g) { m_is_gray = g; }
virtual bool compare_text(const std::string& text) const; 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. // 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); virtual bool update_state(bool paused, const int64_t delta);
int64_t next_render() const { return is_finished() ? 0 : m_next_render; } 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; } void set_Multiline(bool Multi) { m_multiline = Multi; }
virtual void on_change_color_mode(bool is_dark); virtual void on_change_color_mode(bool is_dark);
void set_scale(float scale) { m_scale = scale; } void set_scale(float scale) { m_scale = scale; }
typedef std::function<void(PopNotification*)> DeleteCallback;
void set_delete_callback(DeleteCallback);
bool is_valid_delete_callback();
protected: protected:
// Call after every size change // Call after every size change
virtual void init(); virtual void init();
@ -529,6 +536,7 @@ private:
std::string error_start = "<Error>"; std::string error_start = "<Error>";
std::string error_end = "</Error>"; std::string error_end = "</Error>";
DeleteCallback m_on_delete_callback;
// inner variables to position notification window, texts and buttons correctly // inner variables to position notification window, texts and buttons correctly
// all space without text // all space without text
@ -561,7 +569,7 @@ private:
float m_scale = 1.0f; float m_scale = 1.0f;
}; };
void close_and_delete_self(PopNotification*);
class ObjectIDNotification : public PopNotification class ObjectIDNotification : public PopNotification
{ {
@ -577,7 +585,7 @@ private:
{ {
public: public:
PlaterWarningNotification(const NotificationData& n, NotificationIDProvider& id_provider, wxEvtHandler* evt_handler) : PopNotification(n, id_provider, evt_handler) {} 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 real_close() { m_state = EState::ClosePending; wxGetApp().plater()->get_current_canvas3D()->schedule_extra_frame(0); }
void show() { m_state = EState::Unknown; } void show() { m_state = EState::Unknown; }
}; };
@ -813,6 +821,7 @@ private:
// 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;
std::deque<std::unique_ptr<PopNotification>> m_pop_notifications; std::deque<std::unique_ptr<PopNotification>> m_pop_notifications;
PopNotification* m_to_delete_after_finish_render{nullptr};
// delayed waiting notifications, first is remaining time // delayed waiting notifications, first is remaining time
std::vector<DelayedNotification> m_waiting_notifications; std::vector<DelayedNotification> m_waiting_notifications;
//timestamps used for slicing finished - notification could be gone so it needs to be stored here //timestamps used for slicing finished - notification could be gone so it needs to be stored here

View File

@ -8943,14 +8943,7 @@ int Plater::new_project(bool skip_confirm, bool silent, const wxString &project_
m_only_gcode = false; m_only_gcode = false;
m_exported_file = false; m_exported_file = false;
m_loading_project = false; m_loading_project = false;
get_notification_manager()->bbl_close_plateinfo_notification(); get_notification_manager()->clear_all();
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);
if (!silent) if (!silent)
wxGetApp().mainframe->select_tab(MainFrame::tp3DEditor); wxGetApp().mainframe->select_tab(MainFrame::tp3DEditor);