mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-07-24 03:12:07 +00:00
fix compatible_prints/printers on load instead
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,81 @@ 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("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" });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user