FIX: select printer preset with same printer_variant as old

Change-Id: Iccf72ed34da620f8ca728dfc56585f2ab2a496b9
Jira: STUDIO-11210
This commit is contained in:
chunmao.guo 2025-04-08 10:01:15 +08:00 committed by lane.wei
parent f5c447ddf0
commit 4a270ee6d3
1 changed files with 13 additions and 6 deletions

View File

@ -2280,23 +2280,30 @@ Preset *PresetBundle::get_similar_printer_preset(std::string printer_model, std:
if (printer_model.empty())
printer_model = printers.get_selected_preset().config.opt_string("printer_model");
auto printer_variant_old = printers.get_selected_preset().config.opt_string("printer_variant");
std::set<std::string> printer_names;
std::map<std::string, Preset*> printer_presets;
for (auto &preset : printers.m_presets) {
if (printer_variant.empty() && !preset.is_system)
continue;
if (preset.config.opt_string("printer_model") == printer_model)
printer_names.insert(preset.name);
printer_presets.insert({preset.name, &preset});
}
if (printer_names.empty())
if (printer_presets.empty())
return nullptr;
auto prefer_printer = printers.get_selected_preset().name;
if (!printer_variant.empty())
boost::replace_all(prefer_printer, printer_variant_old, printer_variant);
else if (auto n = prefer_printer.find(printer_variant_old); n != std::string::npos)
prefer_printer = printer_model + " " + printer_variant_old + prefer_printer.substr(n + printer_variant_old.length());
if (printer_names.count(prefer_printer) == 0)
prefer_printer = *printer_names.begin();
return printers.find_preset(prefer_printer, false, true);
if (auto iter = printer_presets.find(prefer_printer); iter != printer_presets.end()) {
return iter->second;
}
if (printer_variant.empty())
printer_variant = printer_variant_old;
for (auto& preset : printer_presets) {
if (preset.second->config.opt_string("printer_variant") == printer_variant)
return preset.second;
}
return printer_presets.begin()->second;
}
//BBS: check whether this is the only edited filament