From 01918affdfb69879f86ca47fe2f1ab8af5e1311b Mon Sep 17 00:00:00 2001 From: tao wang Date: Fri, 21 Feb 2025 16:15:53 +0800 Subject: [PATCH] ENH:fixed incorrect prompt for glow material jira:[STUDIO-10574] Change-Id: I4475eb527ffbc8cc6d72405445552971d062b45e --- resources/printers/filaments_blacklist.json | 2 +- src/libslic3r/ProjectTask.hpp | 13 +++- src/slic3r/GUI/AMSMaterialsSetting.cpp | 6 +- .../GUI/CalibrationWizardPresetPage.cpp | 6 +- src/slic3r/GUI/DeviceManager.cpp | 60 +++++++++++++++---- src/slic3r/GUI/DeviceManager.hpp | 3 +- src/slic3r/GUI/SelectMachine.cpp | 22 +++---- 7 files changed, 72 insertions(+), 40 deletions(-) diff --git a/resources/printers/filaments_blacklist.json b/resources/printers/filaments_blacklist.json index de335ee8b..788c812ff 100644 --- a/resources/printers/filaments_blacklist.json +++ b/resources/printers/filaments_blacklist.json @@ -77,7 +77,7 @@ { "vendor": "Bambu Lab", "type": "PLA", - "name": "Bambu PLA Glow", + "name": "PLA Glow", "action": "warning", "description": "PLA-Glow" }, diff --git a/src/libslic3r/ProjectTask.hpp b/src/libslic3r/ProjectTask.hpp index 569ecb25b..35446acde 100644 --- a/src/libslic3r/ProjectTask.hpp +++ b/src/libslic3r/ProjectTask.hpp @@ -56,7 +56,7 @@ struct FilamentInfo std::string slot_id; public: - int get_amd_id() const + int get_ams_id() const { if (ams_id.empty()) { return -1; }; @@ -69,6 +69,17 @@ public: return -1; }; + int get_slot_id() const + { + if (slot_id.empty()) { return -1; }; + + try { + return stoi(slot_id); + } catch (...) {}; + + return -1; + }; + /*copied from AmsTray::get_display_filament_type()*/ std::string get_display_filament_type() { diff --git a/src/slic3r/GUI/AMSMaterialsSetting.cpp b/src/slic3r/GUI/AMSMaterialsSetting.cpp index fd43b861a..7b7e8fe1c 100644 --- a/src/slic3r/GUI/AMSMaterialsSetting.cpp +++ b/src/slic3r/GUI/AMSMaterialsSetting.cpp @@ -568,13 +568,9 @@ void AMSMaterialsSetting::on_select_ok(wxCommandEvent &event) auto vendor = dynamic_cast(it->config.option("filament_vendor")); - PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle; - auto option = preset_bundle->get_filament_by_filament_id(filament_id); - auto tag_name = option ? option->filament_name : ""; - if (vendor && (vendor->values.size() > 0)) { std::string vendor_name = vendor->values[0]; - DeviceManager::check_filaments_in_blacklist(vendor_name, filamnt_type, tag_name, ams_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(vendor_name, filamnt_type, ams_id, slot_id, in_blacklist, action, info); } if (in_blacklist) { diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 6bb549941..3e11365e7 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -1504,14 +1504,10 @@ bool CalibrationPresetPage::is_filament_in_blacklist(int tray_id, Preset* preset std::string filamnt_type; preset->get_filament_type(filamnt_type); - PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle; - auto option = preset_bundle->get_filament_by_filament_id(preset->filament_id); - auto tag_name = option ? option->filament_name : ""; - auto vendor = dynamic_cast (preset->config.option("filament_vendor")); if (vendor && (vendor->values.size() > 0)) { std::string vendor_name = vendor->values[0]; - DeviceManager::check_filaments_in_blacklist(vendor_name, filamnt_type, tag_name, ams_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(vendor_name, filamnt_type, ams_id, slot_id, in_blacklist, action, info); } if (in_blacklist) { diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index bd8242a3f..5a0520fa1 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -7426,6 +7426,32 @@ bool DeviceManager::is_virtual_slot(int ams_id) return false; } +std::string DeviceManager::get_filament_name_from_ams(int ams_id, int slot_id) +{ + std::string name; + DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) { return name; } + + MachineObject *obj = dev->get_selected_machine(); + if (obj == nullptr || !obj->is_multi_extruders()) { return name; } + + if (ams_id < 0 || slot_id < 0 ) { + return name; + } + + + if (obj->amsList.find(std::to_string(ams_id)) == obj->amsList.end()) {return name;} + + if (obj->amsList[std::to_string(ams_id)]->trayList.find(std::to_string(slot_id)) == obj->amsList[std::to_string(ams_id)]->trayList.end()) { return name; } + + std::string filament_id = obj->amsList[std::to_string(ams_id)]->trayList[std::to_string(slot_id)]->setting_id; + + PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle; + auto option = preset_bundle->get_filament_by_filament_id(filament_id); + name = option ? option->filament_name : ""; + return name; +} + bool DeviceManager::check_filaments_printable(const std::string &tag_vendor, const std::string &tag_type, int ams_id, bool &in_blacklist, std::string &ac, std::string &info) { DeviceManager *dev = Slic3r::GUI::wxGetApp().getDeviceManager(); @@ -7468,8 +7494,12 @@ bool DeviceManager::check_filaments_printable(const std::string &tag_vendor, con return true; } -void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, std::string tag_name, int ams_id, bool& in_blacklist, std::string& ac, std::string& info) +void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, bool& in_blacklist, std::string& ac, std::string& info) { + if (ams_id < 0 || slot_id < 0) { + return; + } + if (!check_filaments_printable(tag_vendor, tag_type, ams_id, in_blacklist, ac, info)) { return; } @@ -7479,6 +7509,8 @@ void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::st return; } + std::string tag_name = get_filament_name_from_ams(ams_id, slot_id); + std::unordered_map blacklist_prompt = { {"TPU: not supported", _L("TPU is not supported by AMS.")}, @@ -7508,8 +7540,6 @@ void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::st type = prohibited_filament["type"].get(); action = prohibited_filament["action"].get(); description = prohibited_filament["description"].get(); - - description = blacklist_prompt[description].ToUTF8().data(); } else { return; @@ -7526,19 +7556,23 @@ void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::st //third party if (vendor == "third party") { - if ("bambu lab" != tag_vendor && (tag_type == type || tag_name == name)) { - in_blacklist = true; - ac = action; - info = description; - return; + if ("bambu lab" != tag_vendor && tag_type == type) { + if (name == "undefine" || (tag_name.find(name) != std::string::npos)) { + in_blacklist = true; + ac = action; + info = blacklist_prompt[description].ToUTF8().data(); + return; + } } } else { - if (vendor == tag_vendor && (tag_type == type || tag_name == name)) { - in_blacklist = true; - ac = action; - info = description; - return; + if (vendor == tag_vendor && tag_type == type) { + if (name == "undefine" || (tag_name.find(name) != std::string::npos)) { + in_blacklist = true; + ac = action; + info = blacklist_prompt[description].ToUTF8().data(); + return; + } } } } diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index af75f1a5b..bfc1bcb2c 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -1392,11 +1392,12 @@ public: static bool load_filaments_blacklist_config(); static std::vector get_resolution_supported(std::string type_str); static std::vector get_compatible_machine(std::string type_str); - static void check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, std::string tag_name, int ams_id, bool &in_blacklist, std::string &ac, std::string &info); + static void check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, bool &in_blacklist, std::string &ac, std::string &info); static bool check_filaments_printable(const std::string &tag_vendor, const std::string &tag_type, int ams_id, bool &in_blacklist, std::string &ac, std::string &info); static boost::bimaps::bimap get_all_model_id_with_name(); static std::string load_gcode(std::string type_str, std::string gcode_file); static bool is_virtual_slot(int ams_id); + static std::string get_filament_name_from_ams(int ams_id, int slot_id); }; // change the opacity diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index ac4345051..34a50e616 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -2146,29 +2146,25 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) //check blacklist for (auto i = 0; i < m_ams_mapping_result.size(); i++) { - const auto& ams_id = m_ams_mapping_result[i].get_amd_id(); + const auto& ams_id = m_ams_mapping_result[i].get_ams_id(); + const auto& slot_id = m_ams_mapping_result[i].get_slot_id(); + auto tid = m_ams_mapping_result[i].tray_id; std::string filament_type = boost::to_upper_copy(m_ams_mapping_result[i].type); std::string filament_brand; - std::string filament_id; for (auto fs : m_filaments) { if (fs.id == m_ams_mapping_result[i].id) { filament_brand = m_filaments[i].brand; - filament_id = m_filaments[i].filament_id; } } - PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle; - auto option = preset_bundle->get_filament_by_filament_id(filament_id); - auto tag_name = option ? option->filament_name : ""; - bool in_blacklist = false; std::string action; std::string info; - DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, tag_name, ams_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, ams_id, slot_id, in_blacklist, action, info); if (in_blacklist && action == "warning") { wxString prohibited_error = wxString::FromUTF8(info); @@ -2227,7 +2223,9 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) for (auto i = 0; i < m_ams_mapping_result.size(); i++) { - const auto& ams_id = m_ams_mapping_result[i].get_amd_id(); + const auto& ams_id = m_ams_mapping_result[i].get_ams_id(); + const auto& slot_id = m_ams_mapping_result[i].get_slot_id(); + auto tid = m_ams_mapping_result[i].tray_id; std::string filament_type = boost::to_upper_copy(m_ams_mapping_result[i].type); @@ -2241,14 +2239,10 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) } } - PresetBundle *preset_bundle = GUI::wxGetApp().preset_bundle; - auto option = preset_bundle->get_filament_by_filament_id(filament_id); - auto tag_name = option ? option->filament_name : ""; - bool in_blacklist = false; std::string action; std::string info; - DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, tag_name, ams_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, ams_id, slot_id, in_blacklist, action, info); if (in_blacklist && action == "prohibition") { has_prohibited_filament = true;