From 1aa4b32fa704b35c3e46b17745f25389a43c9e4c Mon Sep 17 00:00:00 2001 From: Filip Sykala Date: Mon, 23 Aug 2021 11:31:38 +0200 Subject: [PATCH] Create multiple simplify notification --- src/slic3r/GUI/NotificationManager.hpp | 13 ++++- src/slic3r/GUI/Plater.cpp | 73 ++++++++++++++++++-------- 2 files changed, 61 insertions(+), 25 deletions(-) diff --git a/src/slic3r/GUI/NotificationManager.hpp b/src/slic3r/GUI/NotificationManager.hpp index b347c9dfe..8c82a550b 100644 --- a/src/slic3r/GUI/NotificationManager.hpp +++ b/src/slic3r/GUI/NotificationManager.hpp @@ -96,7 +96,9 @@ enum class NotificationType DidYouKnowHint, // Shows when ObjectList::update_info_items finds information that should be stressed to the user // Might contain logo taken from gizmos - UpdatedItemsInfo + UpdatedItemsInfo, + // Give user advice to simplify object with big amount of triangles + SimplifySuggestion }; class NotificationManager @@ -537,7 +539,14 @@ private: // Timestamp of last rendering int64_t m_last_render { 0LL }; // Notification types that can be shown multiple types at once (compared by text) - const std::vector m_multiple_types = { NotificationType::CustomNotification, NotificationType::PlaterWarning, NotificationType::ProgressBar, NotificationType::PrintHostUpload, NotificationType::UpdatedItemsInfo }; + const std::vector m_multiple_types = { + NotificationType::CustomNotification, + NotificationType::PlaterWarning, + NotificationType::ProgressBar, + NotificationType::PrintHostUpload, + NotificationType::UpdatedItemsInfo, + NotificationType::SimplifySuggestion + }; //prepared (basic) notifications static const NotificationData basic_notifications[]; }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 4af8637e4..df0d8ee7d 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1720,7 +1720,7 @@ struct Plater::priv void replace_with_stl(); void reload_all_from_disk(); void fix_through_netfabb(const int obj_idx, const int vol_idx = -1); - + void create_simplify_notification(const std::vector& obj_ids); void set_current_panel(wxPanel* panel); void on_select_preset(wxCommandEvent&); @@ -2408,28 +2408,6 @@ std::vector Plater::priv::load_files(const std::vector& input_ return obj_idxs; } - // detection of simplification suggestion - const uint32_t triangles_to_suggest_simplify = 1000000; - for (const ModelObject *model_object : model.objects) { - const indexed_triangle_set &its = - model_object->volumes.front()->mesh().its; - uint32_t triangle_count = its.indices.size(); - if (triangle_count > triangles_to_suggest_simplify) { - std::string text = _u8L("Processing models with more than 1M triangles" - " could be slow. It is highly recommend to reduce amount of triangles.") + "\n"; - std::string hypertext = "Simplify mesh."; - std::function action_fn = [&](wxEvtHandler *) { - auto &manager = q->canvas3D()->get_gizmos_manager(); - manager.open_gizmo(GLGizmosManager::EType::Simplify); - return true; - }; - notification_manager->push_notification( - NotificationType::CustomNotification, - NotificationManager::NotificationLevel::WarningNotification, - _u8L("WARNING:") + "\n" + text, hypertext, action_fn); - } - } - for (ModelObject* model_object : model.objects) { if (!type_3mf && !type_zip_amf) model_object->center_around_origin(false); @@ -2496,6 +2474,8 @@ std::vector Plater::priv::load_files(const std::vector& input_ view3D->get_canvas3d()->update_gizmos_on_off_state(); } + create_simplify_notification(obj_idxs); + return obj_idxs; } @@ -3529,6 +3509,53 @@ void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* = q->SetFocus(); } +void Plater::priv::create_simplify_notification(const std::vector& obj_ids) { + const uint32_t triangles_to_suggest_simplify = 1000000; + + std::vector big_ids; + big_ids.reserve(obj_ids.size()); + std::copy_if(obj_ids.begin(), obj_ids.end(), std::back_inserter(big_ids), + [this, triangles_to_suggest_simplify](size_t object_id) { + if (object_id >= model.objects.size()) return false; // out of object index + ModelVolumePtrs& volumes = model.objects[object_id]->volumes; + if (volumes.size() != 1) return false; // not only one volume + size_t triangle_count = volumes.front()->mesh().its.indices.size(); + if (triangle_count < triangles_to_suggest_simplify) return false; // small volume + return true; + }); + + if (big_ids.empty()) return; + + for (size_t object_id : big_ids) { + std::string t = _u8L( + "Processing model '@object_name' with more than 1M triangles " + "could be slow. It is highly recommend to reduce " + "amount of triangles."); + t.replace(t.find("@object_name"), sizeof("@object_name") - 1, + model.objects[object_id]->name); + std::stringstream text; + text << _u8L("WARNING:") << "\n" << t << "\n"; + std::string hypertext = _u8L("Simplify model"); + + std::function open_simplify = [object_id](wxEvtHandler *) { + auto plater = wxGetApp().plater(); + if (object_id >= plater->model().objects.size()) return true; + + Selection &selection = plater->canvas3D()->get_selection(); + selection.clear(); + selection.add_object((unsigned int) object_id); + + auto &manager = plater->canvas3D()->get_gizmos_manager(); + manager.open_gizmo(GLGizmosManager::EType::Simplify); + return true; + }; + notification_manager->push_notification( + NotificationType::SimplifySuggestion, + NotificationManager::NotificationLevel::WarningNotification, + text.str(), hypertext, open_simplify); + } +} + void Plater::priv::set_current_panel(wxPanel* panel) { if (std::find(panels.begin(), panels.end(), panel) == panels.end())