From c3643fdec9c0fcbceeba71f9ef5cd2de0cf7957d Mon Sep 17 00:00:00 2001 From: tao wang Date: Thu, 27 Feb 2025 19:27:55 +0800 Subject: [PATCH] ENH:support checking blacklists for specified models jira:[none] Change-Id: Icd88c478a04e8743cdaaa8d670f238b534e40283 --- resources/printers/filaments_blacklist.json | 1 + src/slic3r/GUI/AMSMaterialsSetting.cpp | 3 +- .../GUI/CalibrationWizardPresetPage.cpp | 2 +- src/slic3r/GUI/DeviceManager.cpp | 49 +++++++++++++------ src/slic3r/GUI/DeviceManager.hpp | 2 +- src/slic3r/GUI/SelectMachine.cpp | 4 +- 6 files changed, 40 insertions(+), 21 deletions(-) diff --git a/resources/printers/filaments_blacklist.json b/resources/printers/filaments_blacklist.json index 788c812ff..e7f7e6975 100644 --- a/resources/printers/filaments_blacklist.json +++ b/resources/printers/filaments_blacklist.json @@ -78,6 +78,7 @@ "vendor": "Bambu Lab", "type": "PLA", "name": "PLA Glow", + "model_id":["N1","N2S"], "action": "warning", "description": "PLA-Glow" }, diff --git a/src/slic3r/GUI/AMSMaterialsSetting.cpp b/src/slic3r/GUI/AMSMaterialsSetting.cpp index 7b7e8fe1c..c1393bd71 100644 --- a/src/slic3r/GUI/AMSMaterialsSetting.cpp +++ b/src/slic3r/GUI/AMSMaterialsSetting.cpp @@ -564,13 +564,14 @@ void AMSMaterialsSetting::on_select_ok(wxCommandEvent &event) std::string action; std::string info; std::string filamnt_type; + std::string filamnt_name; it->get_filament_type(filamnt_type); auto vendor = dynamic_cast(it->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, ams_id, slot_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(obj->printer_type, vendor_name, filamnt_type, ams_id, slot_id, it->name, in_blacklist, action, info); } if (in_blacklist) { diff --git a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp index 3e11365e7..d5483030b 100644 --- a/src/slic3r/GUI/CalibrationWizardPresetPage.cpp +++ b/src/slic3r/GUI/CalibrationWizardPresetPage.cpp @@ -1507,7 +1507,7 @@ bool CalibrationPresetPage::is_filament_in_blacklist(int tray_id, Preset* preset 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, ams_id, slot_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(curr_obj->printer_type, 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 5a0520fa1..db70c4f9c 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -7433,13 +7433,12 @@ std::string DeviceManager::get_filament_name_from_ams(int ams_id, int slot_id) if (!dev) { return name; } MachineObject *obj = dev->get_selected_machine(); - if (obj == nullptr || !obj->is_multi_extruders()) { return name; } + if (obj == nullptr) { 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; } @@ -7494,7 +7493,7 @@ 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, int ams_id, int slot_id, bool& in_blacklist, std::string& ac, std::string& info) +void DeviceManager::check_filaments_in_blacklist(std::string model_id, std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, std::string tag_name, bool& in_blacklist, std::string& ac, std::string& info) { if (ams_id < 0 || slot_id < 0) { return; @@ -7509,10 +7508,12 @@ 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); + if (tag_name.empty()) { + 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.")}, {"Bambu CF: not supported", _L("Bambu PET-CF/PA6-CF/PPA-CF/PPS-CF is not supported by AMS.")}, {"PVA: flexible", _L("Damp PVA will become flexible and get stuck inside AMS,please take care to dry it before use.")}, @@ -7530,6 +7531,7 @@ void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::st std::string action; std::string description; std::string name = "undefine"; + std::vector model_ids; if (prohibited_filament.contains("vendor") && prohibited_filament.contains("type") && @@ -7549,29 +7551,44 @@ void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::st name = prohibited_filament["name"].get(); } + if (prohibited_filament.contains("model_id")) { + for (auto res : prohibited_filament["model_id"]) + model_ids.emplace_back(res.get()); + } + std::transform(vendor.begin(), vendor.end(), vendor.begin(), ::tolower); std::transform(tag_vendor.begin(), tag_vendor.end(), tag_vendor.begin(), ::tolower); std::transform(tag_type.begin(), tag_type.end(), tag_type.begin(), ::tolower); std::transform(type.begin(), type.end(), type.begin(), ::tolower); - //third party + + bool mactch_printer = false; + auto it = std::find(model_ids.begin(), model_ids.end(), model_id); + if (it != model_ids.end()) {mactch_printer = true;} + + // third party if (vendor == "third party") { 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; + + if (model_ids.empty() || mactch_printer) { + in_blacklist = true; + ac = action; + info = blacklist_prompt[description].ToUTF8().data(); + return; + } } } - } - else { + } else { 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; + + if (model_ids.empty() || mactch_printer) { + 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 bfc1bcb2c..4b38d50a7 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -1392,7 +1392,7 @@ 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, int ams_id, int slot_id, bool &in_blacklist, std::string &ac, std::string &info); + static void check_filaments_in_blacklist(std::string model_id, std::string tag_vendor, std::string tag_type, int ams_id, int slot_id, std::string tag_name, 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); diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index 5bc83f1b6..27a41e067 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -2164,7 +2164,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) std::string action; std::string info; - DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, ams_id, slot_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, ams_id, slot_id, "", in_blacklist, action, info); if (in_blacklist && action == "warning") { wxString prohibited_error = wxString::FromUTF8(info); @@ -2242,7 +2242,7 @@ void SelectMachineDialog::on_ok_btn(wxCommandEvent &event) bool in_blacklist = false; std::string action; std::string info; - DeviceManager::check_filaments_in_blacklist(filament_brand, filament_type, ams_id, slot_id, in_blacklist, action, info); + DeviceManager::check_filaments_in_blacklist(obj_->printer_type, filament_brand, filament_type, ams_id, slot_id, "", in_blacklist, action, info); if (in_blacklist && action == "prohibition") { has_prohibited_filament = true;