FIX: handle empty AMS filament type

Change-Id: I76b931a28fef4aaf18c2ca0a472fcbefee4663b8
This commit is contained in:
chunmao.guo 2023-06-06 09:04:03 +08:00 committed by Lane.Wei
parent dde886aae8
commit 10838680dd
3 changed files with 15 additions and 8 deletions

View file

@ -1462,10 +1462,14 @@ unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
auto iter = std::find_if(filaments.begin(), filaments.end(), [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; }); auto iter = std::find_if(filaments.begin(), filaments.end(), [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
if (iter == filaments.end()) { if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id; BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
auto filament_type = "Generic " + ams.opt_string("filament_type", 0u); auto filament_type = ams.opt_string("filament_type", 0u);
iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system if (!filament_type.empty()) {
&& boost::algorithm::starts_with(f.name, filament_type); filament_type = "Generic " + filament_type;
}); iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) {
return f.is_compatible && f.is_system
&& boost::algorithm::starts_with(f.name, filament_type);
});
}
if (iter == filaments.end()) if (iter == filaments.end())
iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system; }); iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system; });
if (iter == filaments.end()) if (iter == filaments.end())

View file

@ -1468,7 +1468,7 @@ void Sidebar::sync_ams_list()
wxGetApp().app_config ->set("ams_filament_ids", p->ams_list_device, ams_filament_ids); wxGetApp().app_config ->set("ams_filament_ids", p->ams_list_device, ams_filament_ids);
if (unknowns > 0) { if (unknowns > 0) {
MessageDialog dlg(this, MessageDialog dlg(this,
_L("There are some unknown filaments mapped to generic preset. Please update Bambu Studio or restart Bambu Studio to check if there is an update to system presets."), _L("There are some unknown or uncompatible filaments mapped to generic preset. Please update Bambu Studio or restart Bambu Studio to check if there is an update to system presets."),
_L("Sync filaments with AMS"), wxOK); _L("Sync filaments with AMS"), wxOK);
dlg.ShowModal(); dlg.ShowModal();
} }

View file

@ -382,9 +382,12 @@ void PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
auto iter = std::find_if(filaments.begin(), filaments.end(), auto iter = std::find_if(filaments.begin(), filaments.end(),
[&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; }); [&filament_id](auto &f) { return f.is_compatible && f.is_system && f.filament_id == filament_id; });
if (iter == filaments.end()) { if (iter == filaments.end()) {
auto filament_type = "Generic " + tray.opt_string("filament_type", 0u); auto filament_type = tray.opt_string("filament_type", 0u);
iter = std::find_if(filaments.begin(), filaments.end(), if (!filament_type.empty()) {
[&filament_type](auto &f) { return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); }); filament_type = "Generic " + filament_type;
iter = std::find_if(filaments.begin(), filaments.end(),
[&filament_type](auto &f) { return f.is_compatible && f.is_system && boost::algorithm::starts_with(f.name, filament_type); });
}
} }
if (iter == filaments.end()) { if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id; BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;