Use visible preset lookup for AMS filament fallback to ensure persistence across restarts

This commit is contained in:
SoftFever
2026-02-01 23:53:29 +08:00
parent 3da6f3bf77
commit 86421c6378
5 changed files with 86 additions and 5 deletions

View File

@@ -704,7 +704,10 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id)
tray.bed_temp = safe_int(lane_obj, "bed_temp");
tray.nozzle_temp = safe_int(lane_obj, "nozzle_temp");
tray.has_filament = !tray.tray_type.empty();
tray.tray_info_idx = map_filament_type_to_generic_id(tray.tray_type);
auto* bundle = GUI::wxGetApp().preset_bundle;
tray.tray_info_idx = bundle
? bundle->filaments.filament_id_by_type(tray.tray_type)
: map_filament_type_to_generic_id(tray.tray_type);
max_lane_index = std::max(max_lane_index, lane_index);
trays.push_back(tray);
@@ -780,7 +783,7 @@ std::string MoonrakerPrinterAgent::map_filament_type_to_generic_id(const std::st
if (upper == "COPE") return "OGFLC99";
if (upper == "SBS") return "OFLSBS99";
// Unknown material
// Unknown material
return UNKNOWN_FILAMENT_ID;
}

View File

@@ -1,5 +1,7 @@
#include "QidiPrinterAgent.hpp"
#include "Http.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "nlohmann/json.hpp"
#include <boost/algorithm/string.hpp>
@@ -9,6 +11,22 @@
namespace Slic3r {
namespace {
// Check whether any visible, compatible base preset in the collection has the given filament_id.
bool has_visible_base_preset(const PresetCollection& filaments, const std::string& filament_id)
{
for (const auto& p : filaments.get_presets()) {
if (p.is_visible && p.is_compatible
&& filaments.get_preset_base(p) == &p
&& p.filament_id == filament_id)
return true;
}
return false;
}
} // anonymous namespace
const std::string QidiPrinterAgent_VERSION = "0.0.1";
QidiPrinterAgent::QidiPrinterAgent(std::string log_dir) : MoonrakerPrinterAgent(std::move(log_dir))
@@ -157,7 +175,17 @@ bool QidiPrinterAgent::fetch_slot_info(const std::string& base_url,
filament_name = filament_it->second;
}
tray.tray_type = normalize_filament_type(filament_name);
tray.tray_info_idx = build_setting_id(filament_type, vendor_type, tray.tray_type);
// Try Qidi-specific setting ID first; fall back to visible preset by type
std::string setting_id = build_setting_id(filament_type, vendor_type, tray.tray_type);
auto* bundle = GUI::wxGetApp().preset_bundle;
if (!bundle) {
tray.tray_info_idx = setting_id;
} else if (!setting_id.empty() && has_visible_base_preset(bundle->filaments, setting_id)) {
tray.tray_info_idx = setting_id;
} else {
tray.tray_info_idx = bundle->filaments.filament_id_by_type(tray.tray_type);
}
// Look up color from dictionary
auto color_it = dict.colors.find(color_index);

View File

@@ -1,5 +1,7 @@
#include "SnapmakerPrinterAgent.hpp"
#include "Http.hpp"
#include "libslic3r/PresetBundle.hpp"
#include "slic3r/GUI/GUI_App.hpp"
#include "nlohmann/json.hpp"
#include <boost/log/trivial.hpp>
@@ -133,7 +135,10 @@ bool SnapmakerPrinterAgent::fetch_filament_info(std::string dev_id)
if (tray.has_filament) {
tray.tray_type = combine_filament_type(safe_at(filament_type, i, empty_str),
safe_at(filament_sub_type, i, empty_str));
tray.tray_info_idx = map_filament_type_to_generic_id(tray.tray_type);
auto* bundle = GUI::wxGetApp().preset_bundle;
tray.tray_info_idx = bundle
? bundle->filaments.filament_id_by_type(tray.tray_type)
: map_filament_type_to_generic_id(tray.tray_type);
tray.tray_color = safe_at(filament_color, i, default_color);
// Extract NFC temperature data if available