From 19e42d8dced673f919225174bc417fffa067e1c2 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Fri, 23 Oct 2026 01:42:08 +0800 Subject: [PATCH] Keep the bed at first-layer filament temperatures with By Highest Temp --- src/libslic3r/GCode.cpp | 4 ++- tests/fff_print/test_gcode.cpp | 50 ++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 18cfe2488e..610d6c7147 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -5501,7 +5501,9 @@ int GCode::get_highest_bed_temperature(const bool is_first_layer, const Print& p { auto bed_type = m_config.curr_bed_type; int bed_temp = 0; - for (auto fidx : print.get_slice_used_filaments(is_first_layer)) { + // Only the filaments printed on the first layer touch the bed, so a filament that starts higher up, such as a + // support interface, must not raise the bed temperature for the rest of the print. + for (auto fidx : print.get_slice_used_filaments(true)) { bed_temp = std::max(bed_temp, get_bed_temperature(fidx, is_first_layer, bed_type)); } return bed_temp; diff --git a/tests/fff_print/test_gcode.cpp b/tests/fff_print/test_gcode.cpp index 1fbb84d08c..a82adbb6ea 100644 --- a/tests/fff_print/test_gcode.cpp +++ b/tests/fff_print/test_gcode.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "libslic3r/BoundingBox.hpp" #include "libslic3r/Config.hpp" #include "libslic3r/Model.hpp" @@ -17,6 +18,7 @@ #include "libslic3r/TriangleMesh.hpp" #include "libslic3r/Point.hpp" #include "libslic3r/libslic3r.h" +#include #include #include #include @@ -179,6 +181,54 @@ TEST_CASE("The G-code header names the first object's filament when printing by CHECK(header_value("first_layer_temperature") == 250); } +// A filament that starts above the first layer, such as a support interface, never touches the bed. Heating the +// bed to its temperature would soften the filament the part stands on, so only first layer filaments count. +TEST_CASE("The highest temperature bed formula ignores filaments that start above the first layer", "[GCode]") +{ + // Filament 1: bed 65 on the first layer, 60 after it. Filament 2: bed 100. A 30 mm cap on a 10 mm tall stem prints + // with filament 1 and is supported from the bed, the support with filament 1 and its interface under the cap + // with filament 2. + TriangleMesh mesh = make_cube(10, 10, 10); + mesh.translate(10, 10, 0); + TriangleMesh cap = make_cube(30, 30, 2); + cap.translate(0, 0, 10); + mesh.merge(cap); + DynamicPrintConfig config = Test::multifilament_config(2, { + {"bed_temperature_formula", "by_highest_temp"}, + {"enable_prime_tower", 0}, + {"enable_support", 1}, + {"support_filament", 1}, + {"support_interface_filament", 2}, + {"supertack_plate_temp_initial_layer", "65,100"}, + {"cool_plate_temp_initial_layer", "65,100"}, + {"textured_cool_plate_temp_initial_layer", "65,100"}, + {"eng_plate_temp_initial_layer", "65,100"}, + {"hot_plate_temp_initial_layer", "65,100"}, + {"textured_plate_temp_initial_layer", "65,100"}, + {"supertack_plate_temp", "60,100"}, + {"cool_plate_temp", "60,100"}, + {"textured_cool_plate_temp", "60,100"}, + {"eng_plate_temp", "60,100"}, + {"hot_plate_temp", "60,100"}, + {"textured_plate_temp", "60,100"}, + {"skirt_loops", 0}, + {"brim_type", "no_brim"}, + }); + const std::string gcode = Test::slice({mesh}, config); + REQUIRE(gcode.find("\nT1") != std::string::npos); + + std::vector bed_temps; + std::istringstream lines(gcode); + for (std::string line; std::getline(lines, line);) + if (line.rfind("M140 S", 0) == 0 || line.rfind("M190 S", 0) == 0) + bed_temps.push_back(std::stoi(line.substr(6))); + INFO("bed temperatures: " << Catch::Detail::stringify(bed_temps)); + REQUIRE_FALSE(bed_temps.empty()); + CHECK(bed_temps.front() == 65); + CHECK(std::find(bed_temps.begin(), bed_temps.end(), 60) != bed_temps.end()); + CHECK(std::find(bed_temps.begin(), bed_temps.end(), 100) == bed_temps.end()); +} + TEST_CASE("Object label comments number each object and copy with or without exclude object", "[GCode]") { // repetier has no exclude-object commands, so set_object_info() writes nothing for it.