diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index a8221ce69..65f261eff 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -636,9 +636,9 @@ void GLCanvas3D::WarningTexture::activate(WarningTexture::Warning warning, bool auto ¬ification_manager = *wxGetApp().plater()->get_notification_manager(); if (state) { if(error) - notification_manager.push_plater_error_notification(text,*(wxGetApp().plater()->get_current_canvas3D())); + notification_manager.push_plater_error_notification(text); else - notification_manager.push_plater_warning_notification(text, *(wxGetApp().plater()->get_current_canvas3D())); + notification_manager.push_plater_warning_notification(text); } else { if (error) notification_manager.close_plater_error_notification(text); @@ -1699,8 +1699,7 @@ void GLCanvas3D::render() m_tooltip.render(m_mouse.position, *this); wxGetApp().plater()->get_mouse3d_controller().render_settings_dialog(*this); - - wxGetApp().plater()->get_notification_manager()->render_notifications(*this, get_overlay_window_width()); + wxGetApp().plater()->get_notification_manager()->render_notifications(get_overlay_window_width()); wxGetApp().imgui()->render(); diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 7a8b78664..c0ffb1415 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -820,7 +820,7 @@ bool GUI_App::on_init_inner() app_config->save(); if (this->plater_ != nullptr) { if (*Semver::parse(SLIC3R_VERSION) < *Semver::parse(into_u8(evt.GetString()))) { - this->plater_->get_notification_manager()->push_notification(NotificationType::NewAppAvailable, *(this->plater_->get_current_canvas3D())); + this->plater_->get_notification_manager()->push_notification(NotificationType::NewAppAvailable); } } }); diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index e59d61d0a..15c84af9e 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -849,19 +849,19 @@ NotificationManager::NotificationManager(wxEvtHandler* evt_handler) : m_evt_handler(evt_handler) { } -void NotificationManager::push_notification(const NotificationType type, GLCanvas3D& canvas, int timestamp) +void NotificationManager::push_notification(const NotificationType type, int timestamp) { auto it = std::find_if(basic_notifications.begin(), basic_notifications.end(), boost::bind(&NotificationData::type, boost::placeholders::_1) == type); assert(it != basic_notifications.end()); if (it != basic_notifications.end()) - push_notification_data( *it, canvas, timestamp); + push_notification_data(*it, timestamp); } -void NotificationManager::push_notification(const std::string& text, GLCanvas3D& canvas, int timestamp) +void NotificationManager::push_notification(const std::string& text, int timestamp) { - push_notification_data({ NotificationType::CustomNotification, NotificationLevel::RegularNotification, 10, text }, canvas, timestamp ); + push_notification_data({ NotificationType::CustomNotification, NotificationLevel::RegularNotification, 10, text }, timestamp); } -void NotificationManager::push_notification(const std::string& text, NotificationManager::NotificationLevel level, GLCanvas3D& canvas, int timestamp) +void NotificationManager::push_notification(const std::string& text, NotificationManager::NotificationLevel level, int timestamp) { int duration = 0; switch (level) { @@ -872,32 +872,32 @@ void NotificationManager::push_notification(const std::string& text, Notificatio assert(false); return; } - push_notification_data({ NotificationType::CustomNotification, level, duration, text }, canvas, timestamp); + push_notification_data({ NotificationType::CustomNotification, level, duration, text }, timestamp); } -void NotificationManager::push_slicing_error_notification(const std::string& text, GLCanvas3D& canvas) +void NotificationManager::push_slicing_error_notification(const std::string& text) { set_all_slicing_errors_gray(false); - push_notification_data({ NotificationType::SlicingError, NotificationLevel::ErrorNotification, 0, _u8L("ERROR:") + "\n" + text }, canvas, 0); + push_notification_data({ NotificationType::SlicingError, NotificationLevel::ErrorNotification, 0, _u8L("ERROR:") + "\n" + text }, 0); close_notification_of_type(NotificationType::SlicingComplete); } -void NotificationManager::push_slicing_warning_notification(const std::string& text, bool gray, GLCanvas3D& canvas, ObjectID oid, int warning_step) +void NotificationManager::push_slicing_warning_notification(const std::string& text, bool gray, ObjectID oid, int warning_step) { NotificationData data { NotificationType::SlicingWarning, NotificationLevel::WarningNotification, 0, _u8L("WARNING:") + "\n" + text }; auto notification = std::make_unique(data, m_id_provider, m_evt_handler); notification->object_id = oid; notification->warning_step = warning_step; - if (push_notification_data(std::move(notification), canvas, 0)) { + if (push_notification_data(std::move(notification), 0)) { m_pop_notifications.back()->set_gray(gray); } } -void NotificationManager::push_plater_error_notification(const std::string& text, GLCanvas3D& canvas) +void NotificationManager::push_plater_error_notification(const std::string& text) { - push_notification_data({ NotificationType::PlaterError, NotificationLevel::ErrorNotification, 0, _u8L("ERROR:") + "\n" + text }, canvas, 0); + push_notification_data({ NotificationType::PlaterError, NotificationLevel::ErrorNotification, 0, _u8L("ERROR:") + "\n" + text }, 0); } -void NotificationManager::push_plater_warning_notification(const std::string& text, GLCanvas3D& canvas) +void NotificationManager::push_plater_warning_notification(const std::string& text) { - push_notification_data({ NotificationType::PlaterWarning, NotificationLevel::WarningNotification, 0, _u8L("WARNING:") + "\n" + text }, canvas, 0); + push_notification_data({ NotificationType::PlaterWarning, NotificationLevel::WarningNotification, 0, _u8L("WARNING:") + "\n" + text }, 0); // dissaper if in preview set_in_preview(m_in_preview); } @@ -951,7 +951,7 @@ void NotificationManager::close_slicing_errors_and_warnings() } } } -void NotificationManager::push_slicing_complete_notification(GLCanvas3D& canvas, int timestamp, bool large) +void NotificationManager::push_slicing_complete_notification(int timestamp, bool large) { std::string hypertext; int time = 10; @@ -963,8 +963,7 @@ void NotificationManager::push_slicing_complete_notification(GLCanvas3D& canvas, } NotificationData data{ NotificationType::SlicingComplete, NotificationLevel::RegularNotification, time, _u8L("Slicing finished."), hypertext, [](wxEvtHandler* evnthndlr){ if (evnthndlr != nullptr) wxPostEvent(evnthndlr, ExportGcodeNotificationClickedEvent(EVT_EXPORT_GCODE_NOTIFICAION_CLICKED)); return true; } }; - push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, large), - canvas, timestamp); + push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, large), timestamp); } void NotificationManager::set_slicing_complete_print_time(const std::string &info) { @@ -1001,37 +1000,36 @@ void NotificationManager::remove_slicing_warnings_of_released_objects(const std: notification->close(); } } -void NotificationManager::push_exporting_finished_notification(GLCanvas3D& canvas, std::string path, std::string dir_path, bool on_removable) +void NotificationManager::push_exporting_finished_notification(const std::string& path, const std::string& dir_path, bool on_removable) { close_notification_of_type(NotificationType::ExportFinished); - NotificationData data{ NotificationType::ExportFinished, NotificationLevel::RegularNotification, 0, _u8L("Exporting finished.") +"\n"+ path }; - push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, on_removable, path, dir_path), - canvas, 0); + NotificationData data{ NotificationType::ExportFinished, NotificationLevel::RegularNotification, 0, _u8L("Exporting finished.") + "\n" + path }; + push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, on_removable, path, dir_path), 0); } -void NotificationManager::push_progress_bar_notification(const std::string& text, GLCanvas3D& canvas, float percentage) +void NotificationManager::push_progress_bar_notification(const std::string& text, float percentage) { NotificationData data{ NotificationType::ProgressBar, NotificationLevel::ProgressBarNotification, 0, text }; - push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, 0),canvas, 0); + push_notification_data(std::make_unique(data, m_id_provider, m_evt_handler, 0), 0); } -void NotificationManager::set_progress_bar_percentage(const std::string& text, float percentage, GLCanvas3D& canvas) +void NotificationManager::set_progress_bar_percentage(const std::string& text, float percentage) { bool found = false; for (std::unique_ptr& notification : m_pop_notifications) { if (notification->get_type() == NotificationType::ProgressBar && notification->compare_text(text)) { dynamic_cast(notification.get())->set_percentage(percentage); - canvas.request_extra_frame(); + wxGetApp().plater()->get_current_canvas3D()->request_extra_frame(); found = true; } } if (!found) { - push_progress_bar_notification(text, canvas, percentage); + push_progress_bar_notification(text, percentage); } } -bool NotificationManager::push_notification_data(const NotificationData ¬ification_data, GLCanvas3D& canvas, int timestamp) +bool NotificationManager::push_notification_data(const NotificationData& notification_data, int timestamp) { - return push_notification_data(std::make_unique(notification_data, m_id_provider, m_evt_handler), canvas, timestamp); + return push_notification_data(std::make_unique(notification_data, m_id_provider, m_evt_handler), timestamp); } -bool NotificationManager::push_notification_data(std::unique_ptr notification, GLCanvas3D& canvas, int timestamp) +bool NotificationManager::push_notification_data(std::unique_ptr notification, int timestamp) { // if timestamped notif, push only new one if (timestamp != 0) { @@ -1041,6 +1039,9 @@ bool NotificationManager::push_notification_data(std::unique_ptrget_current_canvas3D(); + if (this->activate_existing(notification.get())) { m_pop_notifications.back()->update(notification->get_data()); canvas.request_extra_frame(); @@ -1051,7 +1052,7 @@ bool NotificationManager::push_notification_data(std::unique_ptrget_current_canvas3D(); + // iterate thru notifications and render them / erease them for (auto it = m_pop_notifications.begin(); it != m_pop_notifications.end();) { if ((*it)->get_finished()) { diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index da544391d..d8ca1e0bd 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -87,16 +87,16 @@ public: NotificationManager(wxEvtHandler* evt_handler); // Push a prefabricated notification from basic_notifications (see the table at the end of this file). - void push_notification(const NotificationType type, GLCanvas3D& canvas, int timestamp = 0); + void push_notification(const NotificationType type, int timestamp = 0); // Push a NotificationType::CustomNotification with NotificationLevel::RegularNotification and 10s fade out interval. - void push_notification(const std::string& text, GLCanvas3D& canvas, int timestamp = 0); + void push_notification(const std::string& text, int timestamp = 0); // Push a NotificationType::CustomNotification with provided notification level and 10s for RegularNotification. // ErrorNotification and ImportantNotification are never faded out. - void push_notification(const std::string& text, NotificationLevel level, GLCanvas3D& canvas, int timestamp = 0); + void push_notification(const std::string& text, NotificationLevel level, int timestamp = 0); // Creates Slicing Error notification with a custom text and no fade out. - void push_slicing_error_notification(const std::string& text, GLCanvas3D& canvas); + void push_slicing_error_notification(const std::string& text); // Creates Slicing Warning notification with a custom text and no fade out. - void push_slicing_warning_notification(const std::string& text, bool gray, GLCanvas3D& canvas, ObjectID oid, int warning_step); + void push_slicing_warning_notification(const std::string& text, bool gray, ObjectID oid, int warning_step); // marks slicing errors as gray void set_all_slicing_errors_gray(bool g); // marks slicing warings as gray @@ -108,32 +108,32 @@ public: // living_oids is expected to be sorted. void remove_slicing_warnings_of_released_objects(const std::vector& living_oids); // Object partially outside of the printer working space, cannot print. No fade out. - void push_plater_error_notification(const std::string& text, GLCanvas3D& canvas); + void push_plater_error_notification(const std::string& text); // Object fully out of the printer working space and such. No fade out. - void push_plater_warning_notification(const std::string& text, GLCanvas3D& canvas); + void push_plater_warning_notification(const std::string& text); // Closes error or warning of the same text void close_plater_error_notification(const std::string& text); void close_plater_warning_notification(const std::string& text); // Creates special notification slicing complete. // If large = true (Plater side bar is closed), then printing time and export button is shown // at the notification and fade-out is disabled. Otherwise the fade out time is set to 10s. - void push_slicing_complete_notification(GLCanvas3D& canvas, int timestamp, bool large); + void push_slicing_complete_notification(int timestamp, bool large); // Add a print time estimate to an existing SlicingComplete notification. void set_slicing_complete_print_time(const std::string &info); // Called when the side bar changes its visibility, as the "slicing complete" notification supplements // the "slicing info" normally shown at the side bar. void set_slicing_complete_large(bool large); // Exporting finished, show this information with path, button to open containing folder and if ejectable - eject button - void push_exporting_finished_notification(GLCanvas3D& canvas, std::string path, std::string dir_path, bool on_removable); + void push_exporting_finished_notification(const std::string& path, const std::string& dir_path, bool on_removable); // notification with progress bar - void push_progress_bar_notification(const std::string& text, GLCanvas3D& canvas, float percentage = 0); - void set_progress_bar_percentage(const std::string& text, float percentage, GLCanvas3D& canvas); + void push_progress_bar_notification(const std::string& text, float percentage = 0); + void set_progress_bar_percentage(const std::string& text, float percentage); // Close old notification ExportFinished. void new_export_began(bool on_removable); // finds ExportFinished notification and closes it if it was to removable device void device_ejected(); // renders notifications in queue and deletes expired ones - void render_notifications(GLCanvas3D& canvas, float overlay_width); + void render_notifications(float overlay_width); // finds and closes all notifications of given type void close_notification_of_type(const NotificationType type); // Which view is active? Plater or G-code preview? Hide warnings in G-code preview. @@ -366,8 +366,8 @@ private: //pushes notification into the queue of notifications that are rendered //can be used to create custom notification - bool push_notification_data(const NotificationData& notification_data, GLCanvas3D& canvas, int timestamp); - bool push_notification_data(std::unique_ptr notification, GLCanvas3D& canvas, int timestamp); + bool push_notification_data(const NotificationData& notification_data, int timestamp); + bool push_notification_data(std::unique_ptr notification, int timestamp); //finds older notification of same type and moves it to the end of queue. returns true if found bool activate_existing(const NotificationManager::PopNotification* notification); // Put the more important notifications to the bottom of the list. diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 6709800ff..f24e4d249 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -2106,12 +2106,12 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) if (evt.data.second) { this->show_action_buttons(this->ready_to_slice); notification_manager->close_notification_of_type(NotificationType::ExportFinished); - notification_manager->push_notification(format(_L("Successfully unmounted. The device %s(%s) can now be safely removed from the computer."),evt.data.first.name, evt.data.first.path), - NotificationManager::NotificationLevel::RegularNotification, *q->get_current_canvas3D()); - } else { - notification_manager->push_notification(format(_L("Ejecting of device %s(%s) has failed."), evt.data.first.name, evt.data.first.path), - NotificationManager::NotificationLevel::ErrorNotification, *q->get_current_canvas3D()); - } + notification_manager->push_notification(format(_L("Successfully unmounted. The device %s(%s) can now be safely removed from the computer."), evt.data.first.name, evt.data.first.path), + NotificationManager::NotificationLevel::RegularNotification); + } else { + notification_manager->push_notification(format(_L("Ejecting of device %s(%s) has failed."), evt.data.first.name, evt.data.first.path), + NotificationManager::NotificationLevel::ErrorNotification); + } }); this->q->Bind(EVT_REMOVABLE_DRIVES_CHANGED, [this, q](RemovableDrivesChangedEvent &) { this->show_action_buttons(this->ready_to_slice); @@ -2938,7 +2938,7 @@ unsigned int Plater::priv::update_background_process(bool force_validation, bool } else { // The print is not valid. // Show error as notification. - notification_manager->push_slicing_error_notification(err, *q->get_current_canvas3D()); + notification_manager->push_slicing_error_notification(err); return_state |= UPDATE_BACKGROUND_PROCESS_INVALID; } } else if (! this->delayed_error_message.empty()) { @@ -3499,7 +3499,7 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) this->statusbar()->set_progress(evt.status.percent); this->statusbar()->set_status_text(_(evt.status.text) + wxString::FromUTF8("…")); - //notification_manager->set_progress_bar_percentage("Slicing progress", (float)evt.status.percent / 100.0f, *q->get_current_canvas3D()); + //notification_manager->set_progress_bar_percentage("Slicing progress", (float)evt.status.percent / 100.0f); } if (evt.status.flags & (PrintBase::SlicingStatus::RELOAD_SCENE | PrintBase::SlicingStatus::RELOAD_SLA_SUPPORT_POINTS)) { switch (this->printer_technology) { @@ -3541,8 +3541,8 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) // Now process state.warnings. for (auto const& warning : state.warnings) { if (warning.current) { - notification_manager->push_slicing_warning_notification(warning.message, false, *q->get_current_canvas3D(), object_id, warning_step); - add_warning(warning, object_id.id); + notification_manager->push_slicing_warning_notification(warning.message, false, object_id, warning_step); + add_warning(warning, object_id.id); } } } @@ -3550,7 +3550,7 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) void Plater::priv::on_slicing_completed(wxCommandEvent & evt) { - notification_manager->push_slicing_complete_notification(*q->get_current_canvas3D(), evt.GetInt(), is_sidebar_collapsed()); + notification_manager->push_slicing_complete_notification(evt.GetInt(), is_sidebar_collapsed()); switch (this->printer_technology) { case ptFFF: this->update_fff_scene(); @@ -3644,7 +3644,7 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt) else show_error(q, message); } else - notification_manager->push_slicing_error_notification(message, *q->get_current_canvas3D()); + notification_manager->push_slicing_error_notification(message); this->statusbar()->set_status_text(from_u8(message)); if (evt.invalidate_plater()) { @@ -3690,10 +3690,10 @@ void Plater::priv::on_process_completed(SlicingProcessCompletedEvent &evt) // If writing to removable drive was scheduled, show notification with eject button if (exporting_status == ExportingStatus::EXPORTING_TO_REMOVABLE && !this->process_completed_with_error) { show_action_buttons(false); - notification_manager->push_exporting_finished_notification(*q->get_current_canvas3D(), last_output_path, last_output_dir_path, true); + notification_manager->push_exporting_finished_notification(last_output_path, last_output_dir_path, true); wxGetApp().removable_drive_manager()->set_exporting_finished(true); }else if (exporting_status == ExportingStatus::EXPORTING_TO_LOCAL && !this->process_completed_with_error) - notification_manager->push_exporting_finished_notification(*q->get_current_canvas3D(), last_output_path, last_output_dir_path, false); + notification_manager->push_exporting_finished_notification(last_output_path, last_output_dir_path, false); } exporting_status = ExportingStatus::NOT_EXPORTING; } diff --git a/src/slic3r/Utils/PresetUpdater.cpp b/src/slic3r/Utils/PresetUpdater.cpp index 10de8b0ef..60dfe05c7 100644 --- a/src/slic3r/Utils/PresetUpdater.cpp +++ b/src/slic3r/Utils/PresetUpdater.cpp @@ -827,7 +827,7 @@ PresetUpdater::UpdateResult PresetUpdater::config_update(const Semver& old_slic3 } } else { p->set_waiting_updates(updates); - GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::PresetUpdateAvailable, *(GUI::wxGetApp().plater()->get_current_canvas3D())); + GUI::wxGetApp().plater()->get_notification_manager()->push_notification(GUI::NotificationType::PresetUpdateAvailable); } // MsgUpdateConfig will show after the notificaation is clicked