From f4bfb4660f0b97d60416e0bea6788197311db484 Mon Sep 17 00:00:00 2001 From: Ian Bassi Date: Fri, 30 Oct 2026 18:38:40 -0300 Subject: [PATCH] Fix infill and surface filaments overriding each other in Filament for features (#17058) (cherry picked from commit 304924a69a68d1014a48f9fc7a72003938783042) --- src/libslic3r/PrintConfig.cpp | 38 -------------------------- src/slic3r/GUI/PartPlate.cpp | 12 -------- tests/fff_print/test_multifilament.cpp | 22 +++++++++++++++ tests/libslic3r/test_config.cpp | 10 +++++++ 4 files changed, 32 insertions(+), 50 deletions(-) diff --git a/src/libslic3r/PrintConfig.cpp b/src/libslic3r/PrintConfig.cpp index 3c8a09f15d..6415ca07ed 100644 --- a/src/libslic3r/PrintConfig.cpp +++ b/src/libslic3r/PrintConfig.cpp @@ -10371,25 +10371,6 @@ void DynamicPrintConfig::normalize_fdm(int used_filaments) } } - if (this->has("sparse_infill_filament_id")) { - int sparse_infill_filament_id = this->option("sparse_infill_filament_id")->getInt(); - if (sparse_infill_filament_id > 0 && (!this->has("internal_solid_filament_id") || this->option("internal_solid_filament_id")->getInt() == 0)) - this->option("internal_solid_filament_id", true)->setInt(sparse_infill_filament_id); - } - - const int internal_solid = this->has("internal_solid_filament_id") ? this->option("internal_solid_filament_id")->getInt() : 0; - const int top_surface = this->has("top_surface_filament_id") ? this->option("top_surface_filament_id")->getInt() : 0; - const int bottom_surface = this->has("bottom_surface_filament_id") ? this->option("bottom_surface_filament_id")->getInt() : 0; - - if (internal_solid == 0 && top_surface > 0) - this->option("internal_solid_filament_id", true)->setInt(top_surface); - if (internal_solid == 0 && bottom_surface > 0) - this->option("internal_solid_filament_id", true)->setInt(bottom_surface); - if (top_surface == 0 && internal_solid > 0) - this->option("top_surface_filament_id", true)->setInt(internal_solid); - if (bottom_surface == 0 && internal_solid > 0) - this->option("bottom_surface_filament_id", true)->setInt(internal_solid); - if (this->has("spiral_mode") && this->opt("spiral_mode", true)->value) { { // this should be actually done only on the spiral layers instead of all @@ -10468,25 +10449,6 @@ void DynamicPrintConfig::normalize_fdm_1() } } - if (this->has("sparse_infill_filament_id")) { - int sparse_infill_filament_id = this->option("sparse_infill_filament_id")->getInt(); - if (sparse_infill_filament_id > 0 && (!this->has("internal_solid_filament_id") || this->option("internal_solid_filament_id")->getInt() == 0)) - this->option("internal_solid_filament_id", true)->setInt(sparse_infill_filament_id); - } - - const int internal_solid = this->has("internal_solid_filament_id") ? this->option("internal_solid_filament_id")->getInt() : 0; - const int top_surface = this->has("top_surface_filament_id") ? this->option("top_surface_filament_id")->getInt() : 0; - const int bottom_surface = this->has("bottom_surface_filament_id") ? this->option("bottom_surface_filament_id")->getInt() : 0; - - if (internal_solid == 0 && top_surface > 0) - this->option("internal_solid_filament_id", true)->setInt(top_surface); - if (internal_solid == 0 && bottom_surface > 0) - this->option("internal_solid_filament_id", true)->setInt(bottom_surface); - if (top_surface == 0 && internal_solid > 0) - this->option("top_surface_filament_id", true)->setInt(internal_solid); - if (bottom_surface == 0 && internal_solid > 0) - this->option("bottom_surface_filament_id", true)->setInt(internal_solid); - if (this->has("spiral_mode") && this->opt("spiral_mode", true)->value) { { // this should be actually done only on the spiral layers instead of all diff --git a/src/slic3r/GUI/PartPlate.cpp b/src/slic3r/GUI/PartPlate.cpp index bf2692db92..5454b94351 100644 --- a/src/slic3r/GUI/PartPlate.cpp +++ b/src/slic3r/GUI/PartPlate.cpp @@ -3093,8 +3093,6 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam int glb_internal_solid_extr = glb_config.opt_int("internal_solid_filament_id"); int glb_top_surface_extr = glb_config.opt_int("top_surface_filament_id"); int glb_bottom_surface_extr = glb_config.opt_int("bottom_surface_filament_id"); - if (glb_top_surface_extr == 0) glb_top_surface_extr = glb_internal_solid_extr; - if (glb_bottom_surface_extr == 0) glb_bottom_surface_extr = glb_internal_solid_extr; bool glb_support = glb_config.opt_bool("enable_support"); glb_support |= glb_config.opt_int("raft_layers") > 0; @@ -3192,8 +3190,6 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam int obj_top_surface_extr = 0; if (const ConfigOption* top_opt = mo->config.option("top_surface_filament_id"); top_opt != nullptr) obj_top_surface_extr = top_opt->getInt(); - if (obj_top_surface_extr == 0) - obj_top_surface_extr = obj_internal_solid_extr; if (obj_top_surface_extr != 0) plate_extruders.push_back(obj_top_surface_extr); else if (glb_top_surface_extr != 0) @@ -3202,8 +3198,6 @@ std::vector PartPlate::get_extruders(bool conside_custom_gcode, const Dynam int obj_bottom_surface_extr = 0; if (const ConfigOption* bottom_opt = mo->config.option("bottom_surface_filament_id"); bottom_opt != nullptr) obj_bottom_surface_extr = bottom_opt->getInt(); - if (obj_bottom_surface_extr == 0) - obj_bottom_surface_extr = obj_internal_solid_extr; if (obj_bottom_surface_extr != 0) plate_extruders.push_back(obj_bottom_surface_extr); else if (glb_bottom_surface_extr != 0) @@ -3264,8 +3258,6 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D int glb_internal_solid_extr = full_config.opt_int("internal_solid_filament_id"); int glb_top_surface_extr = full_config.opt_int("top_surface_filament_id"); int glb_bottom_surface_extr = full_config.opt_int("bottom_surface_filament_id"); - if (glb_top_surface_extr == 0) glb_top_surface_extr = glb_internal_solid_extr; - if (glb_bottom_surface_extr == 0) glb_bottom_surface_extr = glb_internal_solid_extr; bool glb_support = full_config.opt_bool("enable_support"); glb_support |= full_config.opt_int("raft_layers") > 0; @@ -3370,8 +3362,6 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D int obj_top_surface_extr = 0; if (const ConfigOption* top_opt = object->config.option("top_surface_filament_id"); top_opt != nullptr) obj_top_surface_extr = top_opt->getInt(); - if (obj_top_surface_extr == 0) - obj_top_surface_extr = obj_internal_solid_extr; if (obj_top_surface_extr != 0) plate_extruders.push_back(obj_top_surface_extr); else if (glb_top_surface_extr != 0) @@ -3380,8 +3370,6 @@ std::vector PartPlate::get_extruders_under_cli(bool conside_custom_gcode, D int obj_bottom_surface_extr = 0; if (const ConfigOption* bottom_opt = object->config.option("bottom_surface_filament_id"); bottom_opt != nullptr) obj_bottom_surface_extr = bottom_opt->getInt(); - if (obj_bottom_surface_extr == 0) - obj_bottom_surface_extr = obj_internal_solid_extr; if (obj_bottom_surface_extr != 0) plate_extruders.push_back(obj_bottom_surface_extr); else if (glb_bottom_surface_extr != 0) diff --git a/tests/fff_print/test_multifilament.cpp b/tests/fff_print/test_multifilament.cpp index 4a9900d60a..049e3b4494 100644 --- a/tests/fff_print/test_multifilament.cpp +++ b/tests/fff_print/test_multifilament.cpp @@ -370,6 +370,28 @@ static std::set tools_for_feature(const std::string& gcode, std::string_vie return tools; } +// Choosing the filament of one infill or surface must not move the others off "Default", the object's filament. +TEST_CASE("Infill and surfaces left on Default print with the object filament", "[MultiFilament]") +{ + const std::pair features[] = { + { "sparse_infill_filament_id", "Sparse infill" }, + { "internal_solid_filament_id", "Internal solid infill" }, + { "top_surface_filament_id", "Top surface" }, + { "bottom_surface_filament_id", "Bottom surface" }, + }; + const std::string set_key = GENERATE("sparse_infill_filament_id", "internal_solid_filament_id", + "top_surface_filament_id", "bottom_surface_filament_id"); + CAPTURE(set_key); + + DynamicPrintConfig config = multifilament_config(2, { { "skirt_loops", 0 }, { "brim_type", "no_brim" } }); + config.set_deserialize_strict(set_key, "2"); + const std::string gcode = slice({ cube(20) }, config); + for (const auto &[key, feature] : features) { + CAPTURE(feature); + CHECK(tools_for_feature(gcode, feature) == std::set{ key == set_key ? 1 : 0 }); + } +} + // A 20x20mm slab on a 4x4mm pillar: on the slab's first layer both walls are overhangs from end to end, so // only their wall index tells the inner wall from the outer one. TEST_CASE("Overhanging inner walls print with the inner wall filament", "[MultiFilament]") diff --git a/tests/libslic3r/test_config.cpp b/tests/libslic3r/test_config.cpp index 90d9d0e5e4..1eeb19fd09 100644 --- a/tests/libslic3r/test_config.cpp +++ b/tests/libslic3r/test_config.cpp @@ -1544,6 +1544,16 @@ TEST_CASE("handle_legacy migrates the adaptive TPMS keys", "[Config]") { CHECK(ctxt.substitutions.empty()); } +TEST_CASE("normalize_fdm leaves feature filaments on Default", "[Config]") { + DynamicPrintConfig config; + config.set_key_value("sparse_infill_filament_id", new ConfigOptionInt(2)); + config.set_key_value("internal_solid_filament_id", new ConfigOptionInt(0)); + config.set_key_value("top_surface_filament_id", new ConfigOptionInt(3)); + config.normalize_fdm(); + CHECK(config.opt_int("internal_solid_filament_id") == 0); + CHECK_FALSE(config.has("bottom_surface_filament_id")); +} + TEST_CASE("silent_mode is no longer saved and is dropped on load", "[Config]") { DynamicPrintConfig full; full.apply(FullPrintConfig::defaults());