fix(moonraker): Zwei-Pass-Suche in filament_id_by_name — kompatibel first, dann alle sichtbaren

Pass 1: nur is_compatible Presets (wie bisher)
Pass 2: alle sichtbaren Presets unabhängig von is_compatible

Behebt: Hersteller wie eSUN, Eryone, Elegoo haben globale Base-Presets
aber keine druckerspezifischen Profile für den Kobra X →
is_compatible=false → bisher immer Generic PLA.
Mit Pass 2 werden diese Base-Presets als Fallback gefunden.
This commit is contained in:
viewit
2026-06-02 12:43:57 +02:00
parent fbc76888b6
commit b5fb069c54

View File

@@ -185,37 +185,53 @@ std::string filament_id_by_name(const Slic3r::PresetCollection& filaments,
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher lookup requested='" << filament_name
<< "' normalized='" << wanted << "' vendor_filters=" << normalized_vendor_filters.size();
for (size_t i = 0; i < filaments.size(); ++i) {
const auto& preset = filaments.preset(i);
if (!preset.is_visible || !preset.is_compatible || preset.filament_id.empty()) {
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher skip preset='" << preset.name
<< "' visible=" << preset.is_visible << " compatible=" << preset.is_compatible
<< " filament_id_empty=" << preset.filament_id.empty();
continue;
}
if (!normalized_vendor_filters.empty()) {
const std::string preset_vendor = normalize_filament_name_for_match(preset.config.opt_string("filament_vendor", 0u));
bool vendor_match = false;
for (const auto& vendor_filter : normalized_vendor_filters) {
if (preset_vendor == vendor_filter) {
vendor_match = true;
break;
// Two-pass search: Pass 1 = compatible presets only (ideal), Pass 2 = all visible presets
// (fallback for vendors like eSUN/Eryone that have no printer-specific Kobra X profile).
for (int pass = 1; pass <= 2; ++pass) {
for (size_t i = 0; i < filaments.size(); ++i) {
const auto& preset = filaments.preset(i);
if (!preset.is_visible || preset.filament_id.empty()) {
if (pass == 1) {
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher skip preset='" << preset.name
<< "' visible=" << preset.is_visible
<< " filament_id_empty=" << preset.filament_id.empty();
}
}
if (!vendor_match) {
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher skip preset='" << preset.name
<< "' reason=vendor_filter_miss preset_vendor='" << preset_vendor << "'";
continue;
}
if (pass == 1 && !preset.is_compatible) {
continue; // Pass 1: only compatible presets
}
if (!normalized_vendor_filters.empty()) {
const std::string preset_vendor = normalize_filament_name_for_match(preset.config.opt_string("filament_vendor", 0u));
bool vendor_match = false;
for (const auto& vendor_filter : normalized_vendor_filters) {
if (preset_vendor == vendor_filter) {
vendor_match = true;
break;
}
}
if (!vendor_match) {
if (pass == 1) {
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher skip preset='" << preset.name
<< "' reason=vendor_filter_miss preset_vendor='" << preset_vendor << "'";
}
continue;
}
}
const std::string candidate = normalize_filament_name_for_match(preset.name);
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher compare (pass=" << pass << ") preset='" << preset.name
<< "' normalized='" << candidate << "' filament_id='" << preset.filament_id << "'";
if (filament_name_match_relaxed(wanted, candidate)) {
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent: filament matcher matched (pass=" << pass << ") requested='" << filament_name
<< "' normalized='" << wanted << "' to preset='" << preset.name
<< "' filament_id='" << preset.filament_id << "'";
return preset.filament_id;
}
}
const std::string candidate = normalize_filament_name_for_match(preset.name);
BOOST_LOG_TRIVIAL(debug) << "MoonrakerPrinterAgent: filament matcher compare preset='" << preset.name
<< "' normalized='" << candidate << "' filament_id='" << preset.filament_id << "'";
if (filament_name_match_relaxed(wanted, candidate)) {
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent: filament matcher matched requested='" << filament_name
<< "' normalized='" << wanted << "' to preset='" << preset.name
<< "' filament_id='" << preset.filament_id << "'";
return preset.filament_id;
if (pass == 1) {
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent: filament matcher pass 1 (compatible) found no match for '"
<< filament_name << "', trying pass 2 (all visible)";
}
}
BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent: filament matcher found no match for requested='" << filament_name