diff --git a/resources/printers/filaments_blacklist.json b/resources/printers/filaments_blacklist.json new file mode 100644 index 0000000000..e5edcf9eb1 --- /dev/null +++ b/resources/printers/filaments_blacklist.json @@ -0,0 +1,30 @@ +{ + "whitelist": [ + ], + "blacklist": [ + { + "vendor": "Third Party", + "type": "TPU", + "action": "prohibition", + "description": "TPU is not supported by AMS." + }, + { + "vendor": "Third Party", + "type": "PVA", + "action": "warning", + "description": "Damp PVA will become flexible and get stuck inside AMS,please take care to dry it before use." + }, + { + "vendor": "Third Party", + "type": "PA-CF", + "action": "warning", + "description": "CF/GF filaments are hard and brittle, It's easy to break or get stuck in AMS, please use with caution." + }, + { + "vendor": "Third Party", + "type": "PLA-CF", + "action": "warning", + "description": "CF/GF filaments are hard and brittle, It's easy to break or get stuck in AMS, please use with caution." + } + ] +} diff --git a/src/slic3r/GUI/AMSMaterialsSetting.cpp b/src/slic3r/GUI/AMSMaterialsSetting.cpp index e5da1091f0..48af04fb18 100644 --- a/src/slic3r/GUI/AMSMaterialsSetting.cpp +++ b/src/slic3r/GUI/AMSMaterialsSetting.cpp @@ -712,6 +712,29 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt) if (preset_bundle) { for (auto it = preset_bundle->filaments.begin(); it != preset_bundle->filaments.end(); it++) { if (it->alias.compare(m_comboBox_filament->GetValue().ToStdString()) == 0) { + + //check is it in the filament blacklist + bool in_blacklist = false; + std::string action; + std::string info; + std::string filamnt_type; + it->get_filament_type(filamnt_type); + + DeviceManager::check_filaments_in_blacklist(it->vendor->name, filamnt_type, in_blacklist, action, info); + + if (in_blacklist) { + if (action == "prohibition") { + MessageDialog msg_wingow(nullptr, info, _L("Error"), wxICON_WARNING | wxOK); + msg_wingow.ShowModal(); + m_comboBox_filament->SetSelection(m_filament_selection); + return; + } + else if (action == "warning") { + MessageDialog msg_wingow(nullptr, info, _L("Warning"), wxICON_INFORMATION | wxOK); + msg_wingow.ShowModal(); + } + } + // ) if nozzle_temperature_range is found ConfigOption* opt_min = it->config.option("nozzle_temperature_range_low"); if (opt_min) { @@ -742,6 +765,8 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt) } if (!found_filament_type) m_filament_type = ""; + + break; } } } @@ -751,6 +776,8 @@ void AMSMaterialsSetting::on_select_filament(wxCommandEvent &evt) if (m_input_nozzle_max->GetTextCtrl()->GetValue().IsEmpty()) { m_input_nozzle_max->GetTextCtrl()->SetValue("220"); } + + m_filament_selection = evt.GetSelection(); } void AMSMaterialsSetting::on_dpi_changed(const wxRect &suggested_rect) { this->Refresh(); } diff --git a/src/slic3r/GUI/AMSMaterialsSetting.hpp b/src/slic3r/GUI/AMSMaterialsSetting.hpp index 46c0ea1459..917150a20e 100644 --- a/src/slic3r/GUI/AMSMaterialsSetting.hpp +++ b/src/slic3r/GUI/AMSMaterialsSetting.hpp @@ -98,6 +98,7 @@ protected: TextInput* m_input_k_val; wxStaticText* m_n_param; TextInput* m_input_n_val; + int m_filament_selection; #ifdef __APPLE__ wxComboBox *m_comboBox_filament; diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 59ec1b2f9d..c8757a3404 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -3999,6 +3999,7 @@ void DeviceManager::load_last_machine() } json DeviceManager::function_table = json::object(); +json DeviceManager::filaments_blacklist = json::object(); std::string DeviceManager::parse_printer_type(std::string type_str) { @@ -4107,6 +4108,79 @@ bool DeviceManager::load_functional_config(std::string config_file) return true; } +bool DeviceManager::load_filaments_blacklist_config(std::string config_file) +{ + filaments_blacklist = json::object(); + std::ifstream json_file(config_file.c_str()); + + try { + if (json_file.is_open()) { + json_file >> filaments_blacklist; + return true; + } + else { + BOOST_LOG_TRIVIAL(error) << "load filaments blacklist config failed, file = " << config_file; + } + } + catch (...) { + BOOST_LOG_TRIVIAL(error) << "load filaments blacklist config failed, file = " << config_file; + return false; + } + return true; +} + +void DeviceManager::check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, bool& in_blacklist, std::string& ac, std::string& info) +{ + in_blacklist = false; + + if (filaments_blacklist.contains("blacklist")) { + for (auto prohibited_filament : filaments_blacklist["blacklist"]) { + + std::string vendor; + std::string type; + std::string action; + std::string description; + + if (prohibited_filament.contains("vendor") && + prohibited_filament.contains("type") && + prohibited_filament.contains("action") && + prohibited_filament.contains("description")) + { + vendor = prohibited_filament["vendor"].get(); + type = prohibited_filament["type"].get(); + action = prohibited_filament["action"].get(); + description = prohibited_filament["description"].get(); + } + else { + return; + } + + 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 + if (vendor == "third party") { + if ("bambulab" != vendor && tag_type == type) { + in_blacklist = true; + ac = action; + info = description; + return; + } + } + else { + if (vendor == tag_vendor && tag_type == type) { + in_blacklist = true; + ac = action; + info = description; + return; + } + } + } + } +} + std::string DeviceManager::load_gcode(std::string type_str, std::string gcode_file) { std::string gcode_full_path = Slic3r::resources_dir() + "/printers/" + gcode_file; diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index fbcc221405..ace39e0872 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -826,6 +826,8 @@ public: void load_last_machine(); static json function_table; + static json filaments_blacklist; + static std::string parse_printer_type(std::string type_str); static std::string get_printer_display_name(std::string type_str); static std::string get_printer_thumbnail_img(std::string type_str); @@ -834,6 +836,8 @@ public: static bool get_bed_temperature_limit(std::string type_str, int& limit); static bool load_functional_config(std::string config_file); + static bool load_filaments_blacklist_config(std::string config_file); + static void check_filaments_in_blacklist(std::string tag_vendor, std::string tag_type, bool& in_blacklist, std::string& ac, std::string& info); static std::string load_gcode(std::string type_str, std::string gcode_file); }; diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 51f06a2efe..52a68f6579 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1162,6 +1162,9 @@ void GUI_App::post_init() std::string functional_config_file = Slic3r::resources_dir() + "/config.json"; DeviceManager::load_functional_config(encode_path(functional_config_file.c_str())); + std::string filaments_blacklist_config_file = Slic3r::resources_dir() + "/printers/filaments_blacklist.json"; + DeviceManager::load_filaments_blacklist_config(encode_path(filaments_blacklist_config_file.c_str())); + // remove old log files over LOG_FILES_MAX_NUM std::string log_addr = data_dir(); if (!log_addr.empty()) { diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index eeeaf0f921..d8738592b6 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -284,6 +284,7 @@ private: bool m_adding_script_handler { false }; bool m_side_popup_status{false}; public: + void check_filaments_in_blacklist(std::string tag_supplier, std::string tag_material, bool& in_blacklist, std::string& action, std::string& info); std::string get_local_models_path(); bool OnInit() override; bool initialized() const { return m_initialized; }