FIX: [STUDIO-1249] tips on syncing unknown ams filaments

Change-Id: I754ca576e1e0e832a6c69a2bf4bef58900252040
This commit is contained in:
chunmao.guo 2022-11-10 10:48:58 +08:00 committed by Lane.Wei
parent bde96c1542
commit 9c57c808fa
3 changed files with 21 additions and 4 deletions

View file

@ -1412,7 +1412,7 @@ void PresetBundle::set_num_filaments(unsigned int n, std::string new_color)
update_multi_material_filament_presets(); update_multi_material_filament_presets();
} }
unsigned int PresetBundle::sync_ams_list() unsigned int PresetBundle::sync_ams_list(unsigned int &unknowns)
{ {
std::vector<std::string> filament_presets; std::vector<std::string> filament_presets;
std::vector<std::string> filament_colors; std::vector<std::string> filament_colors;
@ -1422,7 +1422,16 @@ unsigned int PresetBundle::sync_ams_list()
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);
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())
iter = std::find_if(filaments.begin(), filaments.end(), [&filament_type](auto &f) { return f.is_compatible && f.is_system; });
if (iter == filaments.end())
continue; continue;
++unknowns;
filament_id = iter->filament_id;
} }
filament_presets.push_back(iter->name); filament_presets.push_back(iter->name);
filament_colors.push_back(filament_color); filament_colors.push_back(filament_color);

View file

@ -83,7 +83,7 @@ public:
// BBS // BBS
void set_num_filaments(unsigned int n, std::string new_col = ""); void set_num_filaments(unsigned int n, std::string new_col = "");
unsigned int sync_ams_list(); unsigned int sync_ams_list(unsigned int & unknowns);
//BBS: check whether this is the only edited filament //BBS: check whether this is the only edited filament
bool is_the_only_edited_filament(unsigned int filament_index); bool is_the_only_edited_filament(unsigned int filament_index);

View file

@ -1260,6 +1260,7 @@ void Sidebar::load_ams_list(std::map<std::string, Ams *> const &list)
<< boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color; << boost::format(": ams %1% tray %2% id %3% color %4%") % ams.first % tray.first % tray.second->setting_id % tray.second->color;
DynamicPrintConfig ams; DynamicPrintConfig ams;
ams.set_key_value("filament_id", new ConfigOptionStrings{tray.second->setting_id}); ams.set_key_value("filament_id", new ConfigOptionStrings{tray.second->setting_id});
ams.set_key_value("filament_type", new ConfigOptionStrings{tray.second->type});
ams.set_key_value("filament_colour", new ConfigOptionStrings{"#" + tray.second->color.substr(0, 6)}); ams.set_key_value("filament_colour", new ConfigOptionStrings{"#" + tray.second->color.substr(0, 6)});
filament_ams_list.emplace_back(std::move(ams)); filament_ams_list.emplace_back(std::move(ams));
} }
@ -1283,7 +1284,8 @@ void Sidebar::sync_ams_list()
_L("Sync filaments with AMS will drop all current selected filament presets and colors. Do you want to continue?"), _L("Sync filaments with AMS will drop all current selected filament presets and colors. Do you want to continue?"),
_L("Sync filaments with AMS"), wxYES_NO); _L("Sync filaments with AMS"), wxYES_NO);
if (dlg.ShowModal() != wxID_YES) return; if (dlg.ShowModal() != wxID_YES) return;
auto n = wxGetApp().preset_bundle->sync_ams_list(); unsigned int unknowns = 0;
auto n = wxGetApp().preset_bundle->sync_ams_list(unknowns);
if (n == 0) { if (n == 0) {
MessageDialog dlg(this, MessageDialog dlg(this,
_L("There are no compatible filaments, and sync is not performed."), _L("There are no compatible filaments, and sync is not performed."),
@ -1291,6 +1293,12 @@ void Sidebar::sync_ams_list()
dlg.ShowModal(); dlg.ShowModal();
return; return;
} }
if (unknowns > 0) {
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("Sync filaments with AMS"), wxOK);
dlg.ShowModal();
}
wxGetApp().plater()->on_filaments_change(n); wxGetApp().plater()->on_filaments_change(n);
for (auto &c : p->combos_filament) for (auto &c : p->combos_filament)
c->update(); c->update();