From 2b2bf3f5e280a46ebb576a02f709f91fa654dc9b Mon Sep 17 00:00:00 2001 From: Lam Wei Lun Date: Mon, 9 Nov 2026 16:04:31 +0800 Subject: [PATCH] Report the first layer time in the estimated-first-layer-time comment (#17328) The comment was written from TimeMachine::prepare_time, which only accumulates the blocks inside the start G-code's ;TYPE:Custom region, so it reported the start G-code duration. With a start G-code that just calls a PRINT_START macro that is close to zero. The comment is a port of PrusaSlicer 2.6's identical one, which prints the first layer time, and OrcaSlicer already writes the first layer time into the .3mf plate metadata as first_layer_time, so G-code and .3mf disagreed. Write TimeMachine::first_layer_time instead, for both the normal and the silent mode line and for every vendor. prepare_time is unchanged: the preview still shows it as "Prepare time" and the Bambu-only "; model printing time: ..." line still subtracts it. The new test slices a cube with a slow start-G-code move and checks that the comment carries the first layer time, which fails without the change. --- src/libslic3r/GCode/GCodeProcessor.cpp | 2 +- tests/fff_print/test_print.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 0157c8cdb4..1a5e8965a1 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -1320,7 +1320,7 @@ void GCodeProcessor::run_post_process() char buf[128]; sprintf(buf, "; estimated first layer printing time (%s mode) = %s\n", (mode == PrintEstimatedStatistics::ETimeMode::Normal) ? "normal" : "silent", - get_time_dhms(machine.prepare_time).c_str()); + get_time_dhms(machine.first_layer_time).c_str()); export_line.append_line(buf); processed = true; } diff --git a/tests/fff_print/test_print.cpp b/tests/fff_print/test_print.cpp index 37f80a2c95..cb5f27c0b6 100644 --- a/tests/fff_print/test_print.cpp +++ b/tests/fff_print/test_print.cpp @@ -1001,6 +1001,24 @@ TEST_CASE("The estimated printing time comment stays near the end of the file", CHECK(trailing_lines <= 5); } +// The comment carries the first layer's time, not the start G-code's time. A 50 mm move at +// F60 (1 mm/s) makes the start block about 50 s, so the two times format to different +// strings and the check below tells them apart. +TEST_CASE("The estimated first layer time comment reports the first layer", "[Print][Regression]") +{ + Print print; + Model model; + init_print({ cube(20) }, print, model, { { "machine_start_gcode", "G1 X50 Y50 Z0.2 F60" } }); + + GCodeProcessorResult result; + const std::string gcode = Test::gcode(print, &result); + + const float first_layer_time = result.initial_layer_time; + const float start_gcode_time = result.print_statistics.modes[static_cast(PrintEstimatedStatistics::ETimeMode::Normal)].prepare_time; + REQUIRE(get_time_dhms(first_layer_time) != get_time_dhms(start_gcode_time)); + CHECK(gcode.find(std::string("; estimated first layer printing time (normal mode) = ") + get_time_dhms(first_layer_time)) != std::string::npos); +} + // Custom G-code templates substitute placeholders during export. TEST_CASE("Custom G-code placeholders are substituted", "[Print]") {