ENH:support checking blacklists for specified models

jira:[none]

Change-Id: Icd88c478a04e8743cdaaa8d670f238b534e40283
This commit is contained in:
tao wang 2025-02-27 19:27:55 +08:00 committed by lane.wei
parent 938af48c51
commit c3643fdec9
6 changed files with 40 additions and 21 deletions

View File

@ -78,6 +78,7 @@
"vendor": "Bambu Lab",
"type": "PLA",
"name": "PLA Glow",
"model_id":["N1","N2S"],
"action": "warning",
"description": "PLA-Glow"
},

View File

@ -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<ConfigOptionStrings *>(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) {

View File

@ -1507,7 +1507,7 @@ bool CalibrationPresetPage::is_filament_in_blacklist(int tray_id, Preset* preset
auto vendor = dynamic_cast<ConfigOptionStrings*> (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) {

View File

@ -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<std::string, wxString> 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<std::string> 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<std::string>();
}
if (prohibited_filament.contains("model_id")) {
for (auto res : prohibited_filament["model_id"])
model_ids.emplace_back(res.get<std::string>());
}
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;
}
}
}
}

View File

@ -1392,7 +1392,7 @@ public:
static bool load_filaments_blacklist_config();
static std::vector<std::string> get_resolution_supported(std::string type_str);
static std::vector<std::string> 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<std::string, std::string> get_all_model_id_with_name();
static std::string load_gcode(std::string type_str, std::string gcode_file);

View File

@ -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;