fix(preset): filament_id für User-Presets beim Speichern generieren (PR #13315 portiert)

Wenn ein Filament-User-Preset noch keine filament_id hat, wird beim
Speichern/Umbenennen automatisch eine MD5-basierte ID (P + 7 Zeichen)
generiert. Damit kann der Moonraker-Filament-Matcher das Preset korrekt
einem Slot zuordnen statt auf Generic PLA zurückzufallen.
This commit is contained in:
viewit
2026-06-02 14:37:37 +02:00
parent 1bd8d4a07a
commit c4a18fc0ac

View File

@@ -41,6 +41,8 @@
#include <boost/property_tree/ptree.hpp>
#include <boost/locale.hpp>
#include <boost/log/trivial.hpp>
#include <boost/uuid/detail/md5.hpp>
#include <boost/algorithm/hex.hpp>
#include "libslic3r.h"
#include "Utils.hpp"
@@ -2817,8 +2819,20 @@ void PresetCollection::save_current_preset(const std::string &new_name, bool det
if (m_type == Preset::TYPE_PRINT)
preset.config.option<ConfigOptionString>("print_settings_id", true)->value = new_name;
else if (m_type == Preset::TYPE_FILAMENT)
else if (m_type == Preset::TYPE_FILAMENT) {
preset.config.option<ConfigOptionStrings>("filament_settings_id", true)->values[0] = new_name;
// Generate a unique filament_id for user presets that don't have one yet (PR #13315).
if (preset.filament_id.empty()) {
boost::uuids::detail::md5 hash;
boost::uuids::detail::md5::digest_type digest;
hash.process_bytes(new_name.data(), new_name.size());
hash.get_digest(digest);
const auto char_digest = reinterpret_cast<const char *>(&digest);
std::string result;
boost::algorithm::hex(char_digest, char_digest + sizeof(boost::uuids::detail::md5::digest_type), std::back_inserter(result));
preset.filament_id = "P" + result.substr(0, 7);
}
}
else if (m_type == Preset::TYPE_PRINTER)
preset.config.option<ConfigOptionString>("printer_settings_id", true)->value = new_name;
final_inherits = preset.inherits();