mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-21 09:52:11 +00:00
fix: treat renamed printer presets as compatible aliases (#14504)
# Description Fixes user filament presets that reference an old printer preset name in `compatible_printers`, even when the current system printer preset correctly declares that old name in `renamed_from`. ## Core Issue `PresetCollection::find_preset()` was updated to resolve `renamed_from`, but this specific failure does not go through `find_preset()`. For root user filament presets with empty `inherits`, Orca infers `compatible_printers` from the filament name suffix after `@`. For example: ```json "ELEGOO PLA Base @Elegoo Neptune 4 Pro (0.4 nozzle)" ``` loads with: ```json "compatible_printers": ["Elegoo Neptune 4 Pro (0.4 nozzle)"] ``` The current system printer preset is named: ```text Elegoo Neptune 4 Pro 0.4 nozzle ``` and has: ```json "renamed_from": "Elegoo Neptune 4 Pro (0.4 nozzle)" ``` However, filament compatibility was doing a direct string comparison against the active printer name. Since that compatibility path does not call `find_preset()`, the `renamed_from` mapping was never considered. ## Fix Teach printer compatibility checks to treat `active_printer.preset.renamed_from` entries as aliases of the active printer name. This preserves existing user preset JSON and avoids rewriting `compatible_printers`, while allowing old printer suffixes to remain compatible with renamed system printer presets. ## Tests <!-- > A guide for users on how to download the artifacts from this PR. --> [How to Download Pull Requests Artifacts for Testing](https://www.orcaslicer.com/wiki/how_to_download_pr_artifacts)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include "libslic3r/PresetBundle.hpp"
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
|
||||
using namespace Slic3r;
|
||||
|
||||
@@ -298,3 +299,168 @@ TEST_CASE("Removed Generic parent is normalized into a loaded filament's inherit
|
||||
CHECK(bundle.filaments.get_preset_parent(*child)->name == "Generic PLA @System");
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// A live reference to a preset's compatible_printers / compatible_prints list. Fetches the *stored*
|
||||
// preset (real=true) so writes and reads hit the same object; creates the option if absent.
|
||||
std::vector<std::string> &compatible_list(PresetCollection &coll, const std::string &preset_name, const char *field_key)
|
||||
{
|
||||
Preset *preset = coll.find_preset(preset_name, /*first_visible_if_not_found=*/false, /*real=*/true);
|
||||
REQUIRE(preset != nullptr);
|
||||
return preset->config.option<ConfigOptionStrings>(field_key, true)->values;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("Renamed printer/process names are normalized into compatible lists on load", "[Preset][Rename]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
|
||||
// Current printer + process, each renamed from an older name.
|
||||
add_inmemory_preset(bundle.printers, "New Printer");
|
||||
set_renamed_from(bundle.printers, "New Printer", { "Old Printer" });
|
||||
add_inmemory_preset(bundle.prints, "New Process");
|
||||
set_renamed_from(bundle.prints, "New Process", { "Old Process" });
|
||||
|
||||
// A user process still compatible with the OLD printer name.
|
||||
add_inmemory_preset(bundle.prints, "My Process");
|
||||
compatible_list(bundle.prints, "My Process", "compatible_printers") = { "Old Printer" };
|
||||
|
||||
// A user filament referencing the OLD printer AND OLD process names, plus an unknown printer.
|
||||
add_inmemory_preset(bundle.filaments, "My Filament");
|
||||
compatible_list(bundle.filaments, "My Filament", "compatible_printers") = { "Old Printer", "Unknown Printer" };
|
||||
compatible_list(bundle.filaments, "My Filament", "compatible_prints") = { "Old Process" };
|
||||
|
||||
// Build the rename maps (done during system load in the real pipeline), then normalize.
|
||||
AppConfig app_config;
|
||||
bundle.load_installed_printers(app_config); // rebuilds every collection's rename map
|
||||
bundle.normalize_compatible_presets();
|
||||
|
||||
// The stale printer name in a process' compatible_printers is rewritten to the current name.
|
||||
CHECK(compatible_list(bundle.prints, "My Process", "compatible_printers") == std::vector<std::string>{ "New Printer" });
|
||||
|
||||
// The stale process name in a filament's compatible_prints is rewritten (this field has no
|
||||
// runtime rename fallback, so load-time normalization is the only fix).
|
||||
CHECK(compatible_list(bundle.filaments, "My Filament", "compatible_prints") == std::vector<std::string>{ "New Process" });
|
||||
|
||||
// The renamed printer is rewritten while the unknown/deleted name is preserved as-is.
|
||||
CHECK(compatible_list(bundle.filaments, "My Filament", "compatible_printers") ==
|
||||
(std::vector<std::string>{ "New Printer", "Unknown Printer" }));
|
||||
|
||||
// Normalizing rewrites config in place without flagging the preset dirty.
|
||||
CHECK_FALSE(bundle.prints.find_preset("My Process", false, true)->is_dirty);
|
||||
|
||||
// A system preset that already references the current name is left untouched (idempotent no-op).
|
||||
bundle.normalize_compatible_presets();
|
||||
CHECK(compatible_list(bundle.prints, "My Process", "compatible_printers") == std::vector<std::string>{ "New Printer" });
|
||||
}
|
||||
|
||||
TEST_CASE("Renamed names are normalized into a SYSTEM preset's compatible lists", "[Preset][Rename]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
|
||||
// Current printer + process, each renamed from an older name.
|
||||
add_inmemory_preset(bundle.printers, "New Printer");
|
||||
set_renamed_from(bundle.printers, "New Printer", { "Old Printer" });
|
||||
add_inmemory_preset(bundle.prints, "New Process");
|
||||
set_renamed_from(bundle.prints, "New Process", { "Old Process" });
|
||||
|
||||
// A *system* (vendor) filament whose own compatible lists still reference the OLD names. A vendor
|
||||
// profile can point at a sibling preset that was later renamed, so system presets must be
|
||||
// normalized too (they are skipped by neither collection walk).
|
||||
add_inmemory_preset(bundle.filaments, "System Filament").is_system = true;
|
||||
compatible_list(bundle.filaments, "System Filament", "compatible_printers") = { "Old Printer" };
|
||||
compatible_list(bundle.filaments, "System Filament", "compatible_prints") = { "Old Process" };
|
||||
|
||||
AppConfig app_config;
|
||||
bundle.load_installed_printers(app_config); // build the rename maps
|
||||
bundle.normalize_compatible_presets();
|
||||
|
||||
// The stale references in the system preset are rewritten to the current names.
|
||||
CHECK(compatible_list(bundle.filaments, "System Filament", "compatible_printers") ==
|
||||
std::vector<std::string>{ "New Printer" });
|
||||
CHECK(compatible_list(bundle.filaments, "System Filament", "compatible_prints") ==
|
||||
std::vector<std::string>{ "New Process" });
|
||||
|
||||
// The rewrite does not flag the system preset dirty, and is idempotent.
|
||||
CHECK_FALSE(bundle.filaments.find_preset("System Filament", false, true)->is_dirty);
|
||||
bundle.normalize_compatible_presets();
|
||||
CHECK(compatible_list(bundle.filaments, "System Filament", "compatible_printers") ==
|
||||
std::vector<std::string>{ "New Printer" });
|
||||
}
|
||||
|
||||
TEST_CASE("compatible_prints on SLA materials resolves against sla_prints, not prints", "[Preset][Rename]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
|
||||
// A renamed SLA process, and a same-named FFF process that must NOT be picked up: resolving the
|
||||
// SLA material's compatible_prints against `prints` would wrongly rewrite to "Wrong FFF Process".
|
||||
add_inmemory_preset(bundle.sla_prints, "New SLA Process");
|
||||
set_renamed_from(bundle.sla_prints, "New SLA Process", { "Old SLA Process" });
|
||||
add_inmemory_preset(bundle.prints, "Wrong FFF Process");
|
||||
set_renamed_from(bundle.prints, "Wrong FFF Process", { "Old SLA Process" });
|
||||
|
||||
add_inmemory_preset(bundle.sla_materials, "My SLA Material");
|
||||
compatible_list(bundle.sla_materials, "My SLA Material", "compatible_prints") = { "Old SLA Process" };
|
||||
|
||||
AppConfig app_config;
|
||||
bundle.load_installed_printers(app_config);
|
||||
bundle.normalize_compatible_presets();
|
||||
|
||||
CHECK(compatible_list(bundle.sla_materials, "My SLA Material", "compatible_prints") ==
|
||||
std::vector<std::string>{ "New SLA Process" });
|
||||
}
|
||||
|
||||
TEST_CASE("Profile validator flags dangling and renamed preset references", "[Preset][Validate]")
|
||||
{
|
||||
PresetBundle bundle;
|
||||
|
||||
// Current printers: a real one, and a renamed one (its old name resolves via renamed_from).
|
||||
add_inmemory_preset(bundle.printers, "Real Printer");
|
||||
add_inmemory_preset(bundle.printers, "New Printer");
|
||||
set_renamed_from(bundle.printers, "New Printer", { "Old Printer" });
|
||||
|
||||
// A real process, referenced from a filament's compatible_prints.
|
||||
add_inmemory_preset(bundle.prints, "Real Process").is_system = true;
|
||||
|
||||
// A fully valid system filament: references only current names.
|
||||
add_inmemory_preset(bundle.filaments, "Good Filament").is_system = true;
|
||||
compatible_list(bundle.filaments, "Good Filament", "compatible_printers") = { "Real Printer" };
|
||||
compatible_list(bundle.filaments, "Good Filament", "compatible_prints") = { "Real Process" };
|
||||
|
||||
AppConfig app_config;
|
||||
bundle.load_installed_printers(app_config); // build the rename maps
|
||||
|
||||
// With only valid references, the validator is clean.
|
||||
CHECK_FALSE(bundle.check_preset_references());
|
||||
|
||||
SECTION("deleted compatible_printers is flagged") {
|
||||
add_inmemory_preset(bundle.filaments, "Ghost Ref Filament").is_system = true;
|
||||
compatible_list(bundle.filaments, "Ghost Ref Filament", "compatible_printers") = { "Ghost Printer" };
|
||||
CHECK(bundle.check_preset_references());
|
||||
}
|
||||
|
||||
SECTION("renamed compatible_printers (old name) is flagged") {
|
||||
add_inmemory_preset(bundle.filaments, "Old Ref Filament").is_system = true;
|
||||
compatible_list(bundle.filaments, "Old Ref Filament", "compatible_printers") = { "Old Printer" };
|
||||
CHECK(bundle.check_preset_references());
|
||||
}
|
||||
|
||||
SECTION("deleted compatible_prints is flagged") {
|
||||
add_inmemory_preset(bundle.filaments, "Bad Process Ref").is_system = true;
|
||||
compatible_list(bundle.filaments, "Bad Process Ref", "compatible_prints") = { "Ghost Process" };
|
||||
CHECK(bundle.check_preset_references());
|
||||
}
|
||||
|
||||
SECTION("deleted inherits parent is flagged") {
|
||||
add_inmemory_preset(bundle.filaments, "Orphan Filament", "Ghost Parent").is_system = true;
|
||||
CHECK(bundle.check_preset_references());
|
||||
}
|
||||
|
||||
SECTION("non-system preset with a dangling reference is ignored") {
|
||||
add_inmemory_preset(bundle.filaments, "User Filament"); // is_system stays false
|
||||
compatible_list(bundle.filaments, "User Filament", "compatible_printers") = { "Ghost Printer" };
|
||||
CHECK_FALSE(bundle.check_preset_references());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user