From 0da5585582dda577adc584c1e625ebedaf6597e6 Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Thu, 3 Nov 2022 16:21:33 +0800 Subject: [PATCH] FIX: [STUDIO-1193] jump to object in slice object warnings Change-Id: Ic6445d81a31e3ecaa069c5fd49b177dc454dc1b9 --- src/libslic3r/PrintObjectSlice.cpp | 5 ++--- src/slic3r/GUI/NotificationManager.cpp | 13 +++++++++++-- src/slic3r/GUI/NotificationManager.hpp | 2 +- src/slic3r/GUI/Plater.cpp | 11 ++++++++--- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/libslic3r/PrintObjectSlice.cpp b/src/libslic3r/PrintObjectSlice.cpp index 529ffa801..8d3887abd 100644 --- a/src/libslic3r/PrintObjectSlice.cpp +++ b/src/libslic3r/PrintObjectSlice.cpp @@ -583,7 +583,7 @@ void PrintObject::slice() //BBS: send warning message to slicing callback if (!warning.empty()) { BOOST_LOG_TRIVIAL(info) << warning; - this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning+L(" Object:")+this->m_model_object->name, PrintStateBase::SlicingReplaceInitEmptyLayers); + this->active_step_add_warning(PrintStateBase::WarningLevel::CRITICAL, warning, PrintStateBase::SlicingReplaceInitEmptyLayers); } // Update bounding boxes, back up raw slices of complex models. tbb::parallel_for( @@ -937,8 +937,7 @@ void PrintObject::slice_volumes() //this->active_step_add_warning( // PrintStateBase::WarningLevel::CRITICAL, // L("An object has enabled XY Size compensation which will not be used because it is also multi-material painted.\nXY Size " - // "compensation cannot be combined with multi-material painting.") + - // "\n" + (L("Object")) + ": " + this->model_object()->name); + // "compensation cannot be combined with multi-material painting.")); BOOST_LOG_TRIVIAL(info) << "xy compensation will not work for object " << this->model_object()->name << " for multi filament."; } diff --git a/src/slic3r/GUI/NotificationManager.cpp b/src/slic3r/GUI/NotificationManager.cpp index 9ed406452..0b51436a6 100644 --- a/src/slic3r/GUI/NotificationManager.cpp +++ b/src/slic3r/GUI/NotificationManager.cpp @@ -1598,9 +1598,18 @@ void NotificationManager::push_slicing_error_notification(const std::string& tex push_notification_data({ NotificationType::SlicingError, NotificationLevel::ErrorNotificationLevel, 0, _u8L("Error:") + "\n" + text }, 0); set_slicing_progress_hidden(); } -void NotificationManager::push_slicing_warning_notification(const std::string& text, bool gray, ObjectID oid, int warning_step, int warning_msg_id) +void NotificationManager::push_slicing_warning_notification(const std::string& text, bool gray, ModelObject const * obj, ObjectID oid, int warning_step, int warning_msg_id) { - NotificationData data { NotificationType::SlicingWarning, NotificationLevel::WarningNotificationLevel, 0, _u8L("Warning:") + "\n" + text }; + auto callback = obj ? [id = obj->id()](wxEvtHandler *) { + auto & objects = wxGetApp().model().objects; + auto iter = std::find_if(objects.begin(), objects.end(), [id](auto o) { return o->id() == id; }); + if (iter != objects.end()) + wxGetApp().obj_list()->select_items({{*iter, nullptr}}); + return false; + } : std::function(); + auto link = callback ? _u8L("Jump to") : ""; + if (obj) link += std::string(" [") + obj->name + "]"; + NotificationData data { NotificationType::SlicingWarning, NotificationLevel::WarningNotificationLevel, 0, _u8L("Warning:") + "\n" + text, link, callback }; data.sub_msg_id = warning_msg_id; data.ori_text = text; diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index 41dd810b2..e5e89ef5b 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -190,7 +190,7 @@ public: // Creates Slicing Error notification with a custom text and no fade out. 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, ObjectID oid, int warning_step, int warning_msg_id); + void push_slicing_warning_notification(const std::string &text, bool gray, ModelObject const *obj, ObjectID oid, int warning_step, int warning_msg_id); // marks slicing errors as gray void set_all_slicing_errors_gray(bool g); // marks slicing warings as gray diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 0a4951563..7cb0f6e2e 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -5330,6 +5330,7 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) ObjectID object_id = evt.status.warning_object_id; int warning_step = evt.status.warning_step; PrintStateBase::StateWithWarnings state; + ModelObject const * model_object = nullptr; //BBS: add partplate related logic, use the print in background process if (evt.status.flags & PrintBase::SlicingStatus::UPDATE_PRINT_STEP_WARNINGS) { @@ -5338,17 +5339,21 @@ void Plater::priv::on_slicing_update(SlicingStatusEvent &evt) this->background_process.m_sla_print->step_state_with_warnings(static_cast(warning_step)); } else if (this->printer_technology == ptFFF) { const PrintObject *print_object = this->background_process.m_fff_print->get_object(object_id); - if (print_object) + if (print_object) { state = print_object->step_state_with_warnings(static_cast(warning_step)); + model_object = print_object->model_object(); + } } else { const SLAPrintObject *print_object = this->background_process.m_sla_print->get_object(object_id); - if (print_object) + if (print_object) { state = print_object->step_state_with_warnings(static_cast(warning_step)); + model_object = print_object->model_object(); + } } // Now process state.warnings. for (auto const& warning : state.warnings) { if (warning.current) { - notification_manager->push_slicing_warning_notification(warning.message, false, object_id, warning_step, warning.message_id); + notification_manager->push_slicing_warning_notification(warning.message, false, model_object, object_id, warning_step, warning.message_id); add_warning(warning, object_id.id); } }