Skip to content

fix: preview slider shows non-support layer count instead of total Z … - #624

Open
mwz-iot wants to merge 2 commits into
process_optimistic_julyfrom
fix/preview_total_layers_shows_support_z_nodes
Open

fix: preview slider shows non-support layer count instead of total Z …#624
mwz-iot wants to merge 2 commits into
process_optimistic_julyfrom
fix/preview_total_layers_shows_support_z_nodes

Conversation

@mwz-iot

@mwz-iot mwz-iot commented Jul 27, 2026

Copy link
Copy Markdown

Description

This PR improves layer numbering and tooltip display when Independent Support Layer Height is enabled.

When independent support layer height is enabled, model layers and support-only layers may use different Z positions. The previous implementation treated all sorted Z positions as a single layer sequence, which caused several issues:

  • Model and support-only layers shared the same progress index.
  • The total layer count included support-only Z positions.
  • Support-only positions displayed -- in the Preview slider.
  • The support tooltip combined the layer number and localized support text on one line, which could overlap the Line type statistics panel in languages with longer translations.
  • The slicing progress window could resize or overflow when displaying longer localized status text.
  • The lower tooltip text could become invisible on a light background.
  • Tooltips could be clipped by child-window boundaries.

This PR separates model and support layer numbering, updates the Preview tooltip layout, and stabilizes the slicing progress window.

The original model and support toolpaths remain unchanged.

Main Changes

1. Separate model and support layer numbering during G-code generation

GCode.cpp now maintains two independent counters:

  • model_layer_idx is incremented only for model layers.
  • support_layer_idx is incremented only for support-only layers.

The layer type is determined using layer.object_layer:

  • layer.object_layer != nullptr indicates a model layer.
  • layer.object_layer == nullptr indicates a support-only layer.

This information is already populated by collect_layers_to_print().

The slicing progress status can therefore distinguish between:

  • Model layer: Layer 1359
  • Support-only layer: Layer 27 (Support)

The Support text continues to use the existing localization system.

2. Count only model layers in the total layer count

The existing m_layer_count contains all Z nodes, including both model layers and support-only layers.

When independent support layer height is enabled, additional support-only Z positions increase this value and make the reported total layer count larger than the actual number of model layers.

This PR introduces m_model_only_layer_count, calculated from object->layers().

The model-only layer count is now used for:

  • The total layers count value in the G-code header.
  • The total_layer_count placeholder.
  • The slicing progress denominator.

Support-only Z positions remain available for toolpath generation and Preview navigation but are no longer included in the reported model layer total.

3. Assign independent numbers to support-only Preview positions

Previously, support-only Z positions in GCodeViewer were mapped to -1, which was treated as an invalid or unavailable layer number and displayed as --.

The Preview mapping now uses signed values:

  • Positive values represent model layer numbers: 1, 2, 3...
  • Negative values represent support-only layer numbers: -1, -2, -3...

IMSlider interprets the mapping as follows:

  • mapped > 0: display mapped as the model layer number.
  • mapped < 0: display -mapped as the independent support layer number.

This allows model and support-only layers to maintain separate numbering while preserving all Z positions in the Preview slider.

4. Display support-only tooltips using a three-line layout

The previous support tooltip combined the layer number and localized support text on one line:

535 (Support)
172.06

This could make the tooltip too wide and cause it to overlap the Line type statistics panel, especially in languages with longer translations.

Support-only tooltips now use three lines:

535
172.06
Support

The lines represent:

  1. Independent support layer number.
  2. Current Z height.
  3. Localized Support text.

Model layer tooltips remain unchanged and continue to use the existing two-line layout.

5. Fix the lower tooltip text color

The lower tooltip uses a white background, but its text was previously rendered with IM_COL32_WHITE.

This resulted in white text on a white background.

The text color now uses:

ImGui::GetColorU32(ImGuiCol_Text)

This follows the active ImGui theme:

  • Dark themes use light text.
  • Light themes use dark text.

The lower tooltip is therefore readable in both light and dark themes.

6. Draw tooltips on the foreground layer

The tooltip was previously drawn using window->DrawList, which could be clipped by child-window boundaries.

Tooltip rendering now uses:

ImGui::GetForegroundDrawList()

This ensures the tooltip is rendered above other UI elements and is not clipped by the current child window.

7. Stabilize the slicing progress window

Three coordinated changes were made in SlicingProgressNotification:

Location Change Purpose
init() Force m_lines_count = 1 Keep the status text on a single line.
render() Enforce a minimum window width of 490px Provide enough space for long localized status text.
set_status_text() Preserve and restore the current width Prevent update() from resetting or shrinking the window width.

Together, these changes ensure that the slicing progress window:

  • Uses a stable width of 490px.
  • Keeps the status text on one line.
  • Does not shrink when the status text changes.
  • Does not visibly resize or jitter during slicing.
  • Supports longer localized text without truncation or overflow.

Compatibility

The following behavior remains unchanged:

  • The original toolpath generation logic.
  • Model and support extrusion paths.
  • The complete list of Preview Z positions.
  • Preview navigation through model and support-only paths.
  • Model layer tooltip layout.
  • Slicing results and generated extrusion data.

There are no breaking changes or new external dependencies introduced by this PR.

Screenshots/Recordings/Graphs

Before

Support-only Z positions were displayed using an unavailable layer number or combined the layer number and support label on one line.

This could produce -- or a wide tooltip such as:

530 (Support)
170.46

The wide tooltip could overlap the Line type statistics panel.

image

After - Model Layer

Model Z positions display the correct model-only layer number and Z height.

The existing two-line layout remains unchanged.

image

After - Support-only Layer

Support-only Z positions display their independent support layer number, Z height, and localized support label on three separate lines.

557
179.09
Support
image

After - Long Localized Text

Long localized support labels, including German and other supported languages, remain within the tooltip and do not overlap the Line type statistics panel.

image

After - Slicing Progress Window

The slicing progress window remains 490px wide, keeps the status text on one line, and no longer resizes when the status changes.

image

Tests

The following cases were tested:

  • Enabled Independent Support Layer Height and verified that model layers use an independent model layer counter.
  • Verified that support-only layers use an independent support layer counter.
  • Verified model/support classification using layer.object_layer.
  • Verified that the G-code header reports only the model layer count.
  • Verified that the total_layer_count placeholder contains only the model layer count.
  • Verified that the slicing progress denominator uses only the model layer count.
  • Verified that model Preview positions use positive mapping values.
  • Verified that support-only Preview positions use sequential negative mapping values.
  • Verified that negative mapping values are displayed as positive support layer numbers.
  • Verified that support-only Z positions no longer display --.
  • Verified that model layer tooltips retain the existing two-line layout.
  • Verified that support-only tooltips display the layer number, Z height, and localized Support text on three lines.
  • Verified that the Chinese support tooltip does not overlap the Line type statistics panel.
  • Verified that the German support tooltip does not overlap the Line type statistics panel.
  • Verified that the localized Support text updates correctly after changing the application language.
  • Verified tooltip rendering with different Z-height precision and localized decimal separators.
  • Verified that the slicing progress window width remains 490px.
  • Verified that long localized slicing status text remains on a single line.
  • Verified that the slicing progress window does not resize or jitter when the status text changes.
  • Verified that the status text does not overlap the close button, progress bar, or window boundaries.
  • Verified that all model and support Z positions remain available in the Preview slider.
  • Verified that support-only toolpaths can still be selected and previewed.
  • Disabled Independent Support Layer Height and verified compatibility with the original Preview behavior.
  • Re-sliced the model and verified that the layer mapping is cleared and rebuilt correctly.
  • Verified fallback behavior when the mapping is empty or the slider index is invalid.
  • Verified index boundary checks to prevent out-of-range access.
  • Verified that the generated toolpaths, extrusion data, and slicing result remain unchanged.

@mwz-iot mwz-iot self-assigned this Jul 27, 2026
…xed 490px width

- GCode.cpp: separate model_layer_idx / support_layer_idx counters for progress
- GCode.cpp/GCode.hpp: m_model_only_layer_count for total layer count
- GCodeViewer: negative value mapping for support layer numbering
- IMSlider: 3-line bubble layout (number / Z height / Support) for support layers
- IMSlider: fix lower bubble invisible text (IM_COL32_WHITE -> theme color)
- SlicingProgressNotification: fixed 490px width, single-line, no shrink on state change
- i18n: add (support) and layer %1% (support) msgids for all 20 locales

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

#, boost-format
msgid "Generating G-code: layer %1% (support)"
msgstr ""

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

其他语言不进行翻译吗?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个会根据英语自动翻译

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants