fix(moonraker): Vendor-Match auch für inkompatible/nicht-instantiierbare Base-Presets

Pass 1: kompatible + sichtbare Presets (wie bisher)
Pass 2 (neu): wenn Pass 1 leer → alle Base-Presets des Vendors + Typs
durchsuchen, unabhängig von is_compatible/is_visible.

Behebt: Elegoo PLA (@base, instantiation=false) und ähnliche Hersteller
die ein globales Base-Preset haben aber kein druckerspezifisches Profil
für den Kobra X → bisher immer "Generic PLA", jetzt "Elegoo PLA".

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
viewit
2026-05-31 20:03:11 +02:00
parent 022c369ae3
commit 6fe27304c8

View File

@@ -60,6 +60,7 @@ std::string find_closest_color_preset_by_vendor_and_type(const Slic3r::PresetCol
unsigned int target = parse_color(color_rgba);
// Pass 1: compatible + visible presets (ideal match)
for (const auto& p : filaments.get_presets()) {
if (!(p.is_visible && p.is_compatible)) continue;
if (filaments.get_preset_base(p) != &p) continue;
@@ -76,6 +77,25 @@ std::string find_closest_color_preset_by_vendor_and_type(const Slic3r::PresetCol
best_match_id = p.filament_id;
}
}
if (!best_match_id.empty()) return best_match_id;
// Pass 2: fallback — any base preset matching vendor+type, even if not compatible/instantiatable.
// Covers vendors like Elegoo that have a @base preset but no printer-specific variant for this printer.
for (const auto& p : filaments.get_presets()) {
if (p.config.opt_string("filament_vendor", 0u) != vendor_name) continue;
if (p.config.opt_string("filament_type", 0u) != filament_type) continue;
if (p.filament_id.empty()) continue;
unsigned int pc = parse_color(p.config.opt_string("default_filament_colour", 0u));
int dr = ((target ) & 0xff) - ((pc ) & 0xff);
int dg = ((target >> 8) & 0xff) - ((pc >> 8) & 0xff);
int db = ((target >> 16) & 0xff) - ((pc >> 16) & 0xff);
unsigned int distance = dr * dr + dg * dg + db * db;
if (distance < (unsigned int)best_color_distance) {
best_color_distance = (int)distance;
best_match_id = p.filament_id;
}
}
return best_match_id;
}