Scope plugin config overrides per preset type

Replace the shared plugin_config_overrides key with print/printer/filament
scoped keys so merging presets into one full config cannot clobber an edited
override, letting a slicing plugin config change invalidate the slice step.
This commit is contained in:
SoftFever
2026-07-25 15:28:14 +08:00
parent b5430b53e7
commit 6e1a6cc678
15 changed files with 138 additions and 106 deletions
@@ -218,6 +218,20 @@ TEST_CASE("Changing slicing_pipeline_plugin invalidates posSlice", "[slicing_pip
CHECK_FALSE(print.objects().front()->is_step_done(posSlice)); // re-slice required
}
// Editing a slicing plugin's config (print_plugin_config_overrides) must re-run posSlice, where the
// plugin transforms each layer's geometry; otherwise the cached slice keeps the old config's result.
TEST_CASE("Changing print_plugin_config_overrides invalidates posSlice", "[slicing_pipeline]") {
Slic3r::Print print; Slic3r::Model model;
auto config = Slic3r::DynamicPrintConfig::full_print_config();
init_print({cube(20)}, print, model, config);
print.process();
REQUIRE(print.objects().front()->is_step_done(posSlice));
config.set_key_value("print_plugin_config_overrides",
new Slic3r::ConfigOptionString("[{\"type\":\"slicing-pipeline\",\"name\":\"Twistify\",\"config\":{\"twist_deg_per_mm\":2.0}}]"));
print.apply(model, config);
CHECK_FALSE(print.objects().front()->is_step_done(posSlice)); // re-slice required
}
#include <catch2/matchers/catch_matchers_floating_point.hpp>
// A similarity transform (rotate + uniform scale) applied to slices at Step.posSlice, matching
@@ -464,3 +464,29 @@ TEST_CASE("Profile validator flags dangling and renamed preset references", "[Pr
}
}
// Each preset type stores its plugin capability overrides under its own option key. Merging the print,
// printer and filament presets into one full config under a shared key would let the last preset applied
// overwrite the others' overrides -- the clobber that stopped an edited slicing-pipeline (print) override
// from reaching Print::apply's diff, so re-configuring a plugin never re-sliced. Distinct per-type keys
// make that collision impossible; guard the scoping here.
TEST_CASE("Plugin capability override keys are scoped per preset type", "[Preset][Plugin]")
{
// Pin the key names: presets and 3mf files store them verbatim, so a rename is a format change.
CHECK(Preset::plugin_overrides_key(Preset::TYPE_PRINT) == std::string("print_plugin_config_overrides"));
CHECK(Preset::plugin_overrides_key(Preset::TYPE_PRINTER) == std::string("printer_plugin_config_overrides"));
CHECK(Preset::plugin_overrides_key(Preset::TYPE_FILAMENT) == std::string("filament_plugin_config_overrides"));
// ...and each key lives on exactly its own preset type's option list, so no two ever share a slot.
const std::pair<Preset::Type, const std::vector<std::string>*> scopes[] = {
{Preset::TYPE_PRINT, &Preset::print_options()},
{Preset::TYPE_PRINTER, &Preset::printer_options()},
{Preset::TYPE_FILAMENT, &Preset::filament_options()},
};
for (const auto &owner : scopes)
for (const auto &scoped : scopes) {
const std::string key = Preset::plugin_overrides_key(scoped.first);
CAPTURE(owner.first, key);
CHECK(contains(*owner.second, key) == (owner.first == scoped.first));
}
}