From 4a270ee6d3b1c1b6bb90cdf6933cae94f59e3a2a Mon Sep 17 00:00:00 2001 From: "chunmao.guo" Date: Tue, 8 Apr 2025 10:01:15 +0800 Subject: [PATCH] FIX: select printer preset with same printer_variant as old Change-Id: Iccf72ed34da620f8ca728dfc56585f2ab2a496b9 Jira: STUDIO-11210 --- src/libslic3r/PresetBundle.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/libslic3r/PresetBundle.cpp b/src/libslic3r/PresetBundle.cpp index 106dd1481..67d43d26c 100644 --- a/src/libslic3r/PresetBundle.cpp +++ b/src/libslic3r/PresetBundle.cpp @@ -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 printer_names; + std::map 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