From 95c6cd05fa90b9ade102a52efeb7ed9e5e4ff0a6 Mon Sep 17 00:00:00 2001 From: Kiss Lorand <50251547+kisslorand@users.noreply.github.com> Date: Fri, 16 Jan 2026 19:20:17 +0200 Subject: [PATCH] Fix incorrect layer and time shown in Preview legend for pause/custom G-code entries (#11968) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix layer/time display in Preview legend for pause/custom G-code The Preview legend showed incorrect layer numbers and elapsed time for pause/custom G-code entries. The issue was caused by: • get_layer_id_at() performing a strict upper_bound search on float Z values, while custom G-code stores Z positions as doubles. Minor precision differences often pushed the lookup to return layer 0 or the last layer. • The legend displayed the raw zero-based layer index. Fixes included: • Fetch layer Z values as doubles and use an epsilon-based closest-layer search. • Display layers as 1-based values for user-facing UI. • Accumulate time up to the beginning of the identified layer. This aligns the legend with the vertical slider marker and provides consistent pause/custom G-code reporting. --- src/slic3r/GUI/GCodeViewer.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/slic3r/GUI/GCodeViewer.cpp b/src/slic3r/GUI/GCodeViewer.cpp index 8032a24c07..dc7a2ec9ac 100644 --- a/src/slic3r/GUI/GCodeViewer.cpp +++ b/src/slic3r/GUI/GCodeViewer.cpp @@ -4062,6 +4062,9 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv ImGui::SameLine(max_len*1.5); imgui.title(cgcode_time_str, false); + // ORCA: Get layer Zs as doubles + std::vector layer_zs = get_layers_zs(); + for (Slic3r::CustomGCode::Item custom_gcode : custom_gcode_per_print_z) { ImGui::Dummy({window_padding, window_padding}); ImGui::SameLine(); @@ -4075,8 +4078,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv } ImGui::SameLine(max_len); char buf[64]; - int layer = m_viewer.get_layer_id_at(custom_gcode.print_z); - ::sprintf(buf, "%d",layer ); + int layer = find_close_layer_idx(layer_zs, custom_gcode.print_z, epsilon()); // ORCA: find layer index by Z + ::sprintf(buf, "%d", layer + 1); // +1 because layer 0 is the first layer imgui.text(buf); ImGui::SameLine(max_len * 1.5); @@ -4084,7 +4087,7 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv float custom_gcode_time = 0; if (layer > 0) { - for (int i = 0; i < layer-1; i++) { + for (int i = 0; i < layer; i++) { // sum all previous layers time custom_gcode_time += layer_times[i]; } }