mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-18 11:02:08 +00:00
Fix incorrect layer and time shown in Preview legend for pause/custom G-code entries (#11968)
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.
This commit is contained in:
@@ -4062,6 +4062,9 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||||||
ImGui::SameLine(max_len*1.5);
|
ImGui::SameLine(max_len*1.5);
|
||||||
imgui.title(cgcode_time_str, false);
|
imgui.title(cgcode_time_str, false);
|
||||||
|
|
||||||
|
// ORCA: Get layer Zs as doubles
|
||||||
|
std::vector<double> layer_zs = get_layers_zs();
|
||||||
|
|
||||||
for (Slic3r::CustomGCode::Item custom_gcode : custom_gcode_per_print_z) {
|
for (Slic3r::CustomGCode::Item custom_gcode : custom_gcode_per_print_z) {
|
||||||
ImGui::Dummy({window_padding, window_padding});
|
ImGui::Dummy({window_padding, window_padding});
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
@@ -4075,8 +4078,8 @@ void GCodeViewer::render_legend(float &legend_height, int canvas_width, int canv
|
|||||||
}
|
}
|
||||||
ImGui::SameLine(max_len);
|
ImGui::SameLine(max_len);
|
||||||
char buf[64];
|
char buf[64];
|
||||||
int layer = m_viewer.get_layer_id_at(custom_gcode.print_z);
|
int layer = find_close_layer_idx(layer_zs, custom_gcode.print_z, epsilon()); // ORCA: find layer index by Z
|
||||||
::sprintf(buf, "%d",layer );
|
::sprintf(buf, "%d", layer + 1); // +1 because layer 0 is the first layer
|
||||||
imgui.text(buf);
|
imgui.text(buf);
|
||||||
ImGui::SameLine(max_len * 1.5);
|
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;
|
float custom_gcode_time = 0;
|
||||||
if (layer > 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];
|
custom_gcode_time += layer_times[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user