remove retired_filament_ids.json

This commit is contained in:
SoftFever
2026-09-03 21:03:42 +08:00
parent fdc0ee18f1
commit 7c9b38ba04
16 changed files with 119 additions and 8309 deletions

View File

@@ -572,60 +572,6 @@ std::string generate_preset_setting_id(const std::string& vendor, const std::str
return std::string(out, 16);
}
std::string follow_filament_id_succession(const std::string& id, const std::map<std::string, std::string>& forwards)
{
auto it = forwards.find(id);
if (it == forwards.end())
return std::string();
std::set<std::string> visited { id };
std::string current = id;
while (it != forwards.end() && visited.insert(it->second).second) {
current = it->second;
it = forwards.find(current);
}
// it == end(): current is the live end of the chain; otherwise the ledger is
// cyclic and current is the last id reached before a repeat.
return current;
}
const std::map<std::string, std::string>& filament_id_succession_map()
{
// Loaded once; C++11 magic-static initialization makes this thread-safe.
// Succession is a best-effort miss-path fallback, so a missing or corrupt
// ledger is not an error for the client - it just yields an empty map.
static const std::map<std::string, std::string> forwards = []() {
std::map<std::string, std::string> map;
const std::string path = Slic3r::resources_dir() + "/profiles/retired_filament_ids.json";
boost::nowide::ifstream file(path.c_str());
if (!file.is_open()) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": cannot open " << path;
return map;
}
try {
nlohmann::json ledger;
file >> ledger;
if (ledger.contains("retired") && ledger["retired"].is_object())
for (auto& [old_id, entry] : ledger["retired"].items())
if (entry.is_object() && entry.contains("successor") && entry["successor"].is_string())
map[old_id] = entry["successor"].get<std::string>();
if (ledger.contains("hints") && ledger["hints"].is_object())
for (auto& [old_id, target] : ledger["hints"].items())
if (target.is_string())
map[old_id] = target.get<std::string>();
} catch (...) {
BOOST_LOG_TRIVIAL(debug) << __FUNCTION__ << ": failed to parse " << path;
map.clear();
}
return map;
}();
return forwards;
}
std::string resolve_filament_id_succession(const std::string& id)
{
return follow_filament_id_succession(id, filament_id_succession_map());
}
std::string Preset::get_iot_type_string(Preset::Type type)
{
switch (type) {

View File

@@ -101,23 +101,6 @@ std::string generate_preset_setting_id(const std::string& vendor,
const std::string& type,
const std::string& name);
// Succession forwarding for retired/renamed filament_ids, backed by the shipped
// ledger resources/profiles/retired_filament_ids.json. Consulted on a filament_id
// resolution miss only, so live ids always resolve natively first.
//
// Pure chain walk over `forwards` (old id -> successor). Returns the final id of the
// chain, or an empty string when `id` has no entry. Cycle-guarded: on a malformed
// cyclic ledger it stops at the last id reached before any repeat (a self-loop
// returns `id` itself).
std::string follow_filament_id_succession(const std::string& id,
const std::map<std::string, std::string>& forwards);
// Forwarding map loaded once (thread-safe) from the ledger, merging
// "retired" {id -> non-null successor} and "hints" {island-owned id -> live id}.
// A missing or corrupt file yields an empty map.
const std::map<std::string, std::string>& filament_id_succession_map();
// Convenience: follow_filament_id_succession(id, filament_id_succession_map()).
std::string resolve_filament_id_succession(const std::string& id);
enum ConfigFileType
{
CONFIG_FILE_TYPE_UNKNOWN,

View File

@@ -801,12 +801,6 @@ std::optional<FilamentBaseInfo> PresetBundle::get_filament_by_filament_id(const
}
}
}
// Miss: a retired/renamed id may forward to a live successor through the shipped
// succession ledger. resolve() returns a chain-final id, so the retry below cannot
// recurse further (a malformed cyclic ledger yields a non-final id, rejected here).
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty() && resolve_filament_id_succession(successor).empty())
return get_filament_by_filament_id(successor, printer_name);
return std::nullopt;
}
@@ -3420,15 +3414,6 @@ void PresetBundle::get_ams_cobox_infos(AMSComboInfo& combox_info)
auto iter = std::find_if(filaments.begin(), filaments.end(),
[this, &filament_id](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
warn_ambiguous_filament_id_match(filaments, iter, filament_id);
if (iter == filaments.end()) {
// Retired/renamed ids forward to a live successor through the shipped succession ledger.
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty()) {
iter = std::find_if(filaments.begin(), filaments.end(),
[this, &successor](auto &f) { return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == successor; });
warn_ambiguous_filament_id_match(filaments, iter, successor);
}
}
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
auto filament_type = ams.opt_string("filament_type", 0u);
@@ -3532,16 +3517,6 @@ unsigned int PresetBundle::sync_ams_list(std::vector<std::pair<DynamicPrintConfi
has_type |= f.config.opt_string("filament_type", 0u) == filament_type;
return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == filament_id; });
warn_ambiguous_filament_id_match(filaments, iter, filament_id);
if (iter == filaments.end()) {
// Retired/renamed ids forward to a live successor through the shipped succession
// ledger (has_type is already complete: the miss above scanned every preset).
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty()) {
iter = std::find_if(filaments.begin(), filaments.end(), [this, &successor](auto &f) {
return f.is_compatible && filaments.get_preset_base(f) == &f && f.filament_id == successor; });
warn_ambiguous_filament_id_match(filaments, iter, successor);
}
}
if (iter == filaments.end()) {
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": filament_id %1% not found or system or compatible") % filament_id;
if (!filament_type.empty()) {

View File

@@ -69,7 +69,7 @@ static wxString nozzle_id_code_to_string(int code)
}
}
static wxString get_preset_name_by_filament_id(std::string filament_id, bool follow_succession = true)
static wxString get_preset_name_by_filament_id(std::string filament_id)
{
auto preset_bundle = wxGetApp().preset_bundle;
auto collection = &preset_bundle->filaments;
@@ -103,12 +103,6 @@ static wxString get_preset_name_by_filament_id(std::string filament_id, bool fol
}
}
}
if (preset_name.empty() && follow_succession) {
// Retired/renamed ids forward to a live successor through the shipped succession ledger.
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty())
preset_name = get_preset_name_by_filament_id(successor, false);
}
return preset_name;
}

View File

@@ -2764,22 +2764,14 @@ std::string MachineObject::setting_id_to_type(std::string setting_id, std::strin
std::string type;
PresetBundle* preset_bundle = GUI::wxGetApp().preset_bundle;
if (preset_bundle) {
auto lookup_system_type = [preset_bundle](const std::string &id) {
std::string display_filament_type;
for (auto it = preset_bundle->filaments.begin(); it != preset_bundle->filaments.end(); it++) {
if (it->filament_id.compare(id) == 0 && it->is_system) {
it->config.get_filament_type(display_filament_type);
break;
}
for (auto it = preset_bundle->filaments.begin(); it != preset_bundle->filaments.end(); it++) {
if (it->filament_id.compare(setting_id) == 0 && it->is_system) {
std::string display_filament_type;
it->config.get_filament_type(display_filament_type);
type = display_filament_type;
break;
}
return display_filament_type;
};
type = lookup_system_type(setting_id);
if (type.empty()) {
// Retired/renamed ids forward to a live successor through the shipped succession ledger.
const std::string successor = resolve_filament_id_succession(setting_id);
if (!successor.empty())
type = lookup_system_type(successor);
}
}

View File

@@ -556,13 +556,6 @@ bool PresetComboBox::add_ams_filaments(std::string selected, bool alias_name)
}
auto iter = std::find_if(filaments.begin(), filaments.end(),
[&filament_id, this](auto &f) { return f.is_compatible && m_collection->get_preset_base(f) == &f && f.filament_id == filament_id; });
if (iter == filaments.end()) {
// Retired/renamed ids forward to a live successor through the shipped succession ledger.
const std::string successor = resolve_filament_id_succession(filament_id);
if (!successor.empty())
iter = std::find_if(filaments.begin(), filaments.end(),
[&successor, this](auto &f) { return f.is_compatible && m_collection->get_preset_base(f) == &f && f.filament_id == successor; });
}
if (iter == filaments.end()) {
auto filament_type = tray.opt_string("filament_type", 0u);
if (!filament_type.empty()) {

View File

@@ -188,13 +188,7 @@ bool QidiPrinterAgent::fetch_slot_info(const std::string& base_url,
} else if (!setting_id.empty() && has_visible_base_preset(bundle->filaments, setting_id)) {
tray.tray_info_idx = setting_id;
} else {
// Retired QD_* protocol ids forward to their minted successors via the shipped ledger.
const std::string successor = setting_id.empty() ? std::string()
: resolve_filament_id_succession(setting_id);
if (!successor.empty() && has_visible_base_preset(bundle->filaments, successor))
tray.tray_info_idx = successor;
else
tray.tray_info_idx = bundle->filaments.filament_id_by_type(tray.tray_type);
tray.tray_info_idx = bundle->filaments.filament_id_by_type(tray.tray_type);
}
// Look up color from dictionary
@@ -330,10 +324,6 @@ void QidiPrinterAgent::parse_filament_sections(const std::string& content, std::
std::string QidiPrinterAgent::map_filament_type_to_setting_id(const std::string& filament_type)
{
// These QD_* protocol ids no longer appear on any preset: they are retired ledger keys
// that parse_box_status resolves through resolve_filament_id_succession(). Each literal
// must stay a ledger key whose chain ends at a live preset id —
// scripts/tests/test_filament_id.py parses this function and enforces that.
const std::string upper = trim_and_upper(filament_type);
if (upper == "PLA") {