Refresh the mixed filament list when a component preset changes

This commit is contained in:
SoftFever
2026-08-23 13:59:59 +08:00
parent af5397d678
commit 38d51783ae
2 changed files with 35 additions and 1 deletions

View File

@@ -7318,7 +7318,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame)
"brim_width", "brim_object_gap", "brim_flow_ratio", "brim_use_efc_outline", "combine_brims", "brim_type", "nozzle_diameter", "single_extruder_multi_material", "preferred_orientation",
"enable_prime_tower", "wipe_tower_x", "wipe_tower_y", "prime_tower_width", "prime_tower_brim_width", "prime_tower_skip_points", "prime_tower_enable_framework",
"prime_tower_infill_gap", "prime_volume",
"extruder_colour", "filament_colour", "filament_type", "material_colour", "printable_height", "extruder_printable_height", "printer_model", "printer_technology",
"extruder_colour", "filament_colour", "filament_type", "filament_is_support", "material_colour", "printable_height", "extruder_printable_height", "printer_model", "printer_technology",
// These values are necessary to construct SlicingParameters by the Canvas3D variable layer height editor.
"layer_height", "initial_layer_print_height", "min_layer_height", "max_layer_height",
"wall_loops", "outer_wall_filament_id", "inner_wall_filament_id", "sparse_infill_density", "sparse_infill_filament_id", "top_shell_layers",
@@ -19661,6 +19661,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
update_scheduled = true; // update should be scheduled (for update 3DScene) #2738
if (update_filament_colors_in_full_config()) {
p->sidebar->update_mixed_filament_list();
p->sidebar->obj_list()->update_filament_colors();
p->sidebar->update_dynamic_filament_list();
continue;
@@ -19668,6 +19669,15 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
}
if (opt_key == "filament_type") {
update_filament_colors_in_full_config();
p->sidebar->update_mixed_filament_list();
continue;
}
// The mixed-filament type check folds filament_is_support into the component type
// (DynamicPrintConfig::get_filament_type -> "PLA-S"), so a support-preset switch must
// refresh the list even though filament_type itself did not change.
if (opt_key == "filament_is_support") {
p->config->set_key_value(opt_key, config.option(opt_key)->clone());
p->sidebar->update_mixed_filament_list();
continue;
}
if (opt_key == "material_colour") {

View File

@@ -1,6 +1,7 @@
#include <catch2/catch_all.hpp>
#include "libslic3r/FilamentMixer.hpp"
#include "libslic3r/PrintConfig.hpp"
using namespace Slic3r;
@@ -98,6 +99,29 @@ TEST_CASE("check_mixed_filament_type_consistency flags mismatched component type
REQUIRE(bad == std::vector<size_t>{2});
}
TEST_CASE("a support-flagged component reads as its own filament type for the consistency check", "[FilamentMixer]")
{
// Sidebar::update_mixed_filament_list and Sidebar::has_broken_mixed_filament derive each
// component's type through DynamicPrintConfig::get_filament_type, which folds the
// filament_is_support flag into the type — so toggling that flag alone changes the verdict
// and Plater::on_config_change has to refresh the mixed list on filament_is_support too.
DynamicPrintConfig plain_pla;
plain_pla.set_key_value("filament_type", new ConfigOptionStrings({"PLA"}));
plain_pla.set_key_value("filament_is_support", new ConfigOptionBools({false}));
std::string displayed;
REQUIRE(plain_pla.get_filament_type(displayed) == "PLA");
DynamicPrintConfig support_pla;
support_pla.set_key_value("filament_type", new ConfigOptionStrings({"PLA"}));
support_pla.set_key_value("filament_is_support", new ConfigOptionBools({true}));
REQUIRE(support_pla.get_filament_type(displayed) == "PLA-S");
REQUIRE(displayed == "Sup.PLA");
const std::vector<unsigned char> is_mixed = {0, 0, 1};
const std::vector<std::string> comp_strs = {"", "", "1,2"};
REQUIRE(check_mixed_filament_type_consistency(is_mixed, comp_strs, {"PLA", "PLA-S"}) == std::vector<size_t>{2});
}
TEST_CASE("gradient curves round-trip and sample monotonically", "[FilamentMixer]")
{
SECTION("Empty input yields an empty curve") {