Belt printer: no layer changes that print nothing, and a preview that survives them

Since the slicing frame of a belt object starts at the belt below its
leading end, its first layers are empty.  On a single part they carry
the brim bands; with several parts along the belt the later parts'
empty layers fall between the earlier parts' printing layers and were
written to the G-code as layer changes with no moves at all.  The
preview numbers its layers (libvgcode::Layers) from the vertices it is
given and expects consecutive ids, so at the first such gap it stopped
creating layers and folded everything after it into the last one: the
top slider layer held nearly the whole print, the slider jumped every
other layer through the single-colour stretch before a second part on
another filament, and with the belt purge tower the whole print greyed
out while dragging.

Drop the belt layers that print nothing (no object, support or brim
content) in GCode::collect_layers_to_print, and renumber the layers
consecutively over the moves that exist when converting a result for
libvgcode, so a file with empty layers from any source still previews
correctly.  The layer slider labels a belt layer with its print Z (the
slicer's layer Z, which increases along the belt) instead of libvgcode's
toolpath height, which on a tilted layer is wherever its last extrusion
ended; the slider assumes that list increases and showed "0 / max" on
alternate layers.  The processor reads that print Z from the ";Z:" tag
non-BBL printers write (it only knew "; Z_HEIGHT:"), on belt printers
only, so nothing changes elsewhere.  Regression test: two cubes 60 mm apart along the
belt produce no layer without an extrusion and the header's layer count
matches.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
harrierpigeon
2026-10-07 03:50:51 -05:00
co-authored by Claude Fable 5.1
parent 6927475499
commit f64b49ab52
6 changed files with 147 additions and 4 deletions
+22
View File
@@ -87,6 +87,7 @@
#include <array>
#include <algorithm>
#include <limits>
#include <cmath>
#include <chrono>
#include <Eigen/Geometry>
@@ -1635,6 +1636,26 @@ void GCodeViewer::load_as_gcode(const GCodeProcessorResult& gcode_result, const
m_viewer.reset_default_extrusion_roles_colors();
m_viewer.load(std::move(data));
// Belt printers: libvgcode labels a layer with the height of its toolpaths, which
// on a tilted layer is wherever its last extrusion happened to end, and the layer
// slider looks its labels and the colour-change ticks up in that list assuming it
// increases. Give it the layers' print Z instead (the slicer's layer Z, which
// increases along the belt), numbered the way libvgcode::convert() numbers the
// layers: consecutively over the moves that exist.
m_belt_layer_zs.clear();
if (is_belt) {
unsigned int src_layer_id = std::numeric_limits<unsigned int>::max();
for (size_t i = 1; i < gcode_result.moves.size(); ++ i) {
const GCodeProcessorResult::MoveVertex &mv = gcode_result.moves[i];
if (mv.layer_id != src_layer_id) {
src_layer_id = mv.layer_id;
m_belt_layer_zs.emplace_back(double(mv.print_z));
}
}
if (m_belt_layer_zs.size() != m_viewer.get_layers_count())
m_belt_layer_zs.clear();
}
// #if !VGCODE_ENABLE_COG_AND_TOOL_MARKERS
// const size_t vertices_count = m_viewer.get_vertices_count();
// m_cog.reset();
@@ -1905,6 +1926,7 @@ void GCodeViewer::reset()
//BBS: should also reset the result id
BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": current result id %1% ")%m_last_result_id;
m_last_result_id = -1;
m_belt_layer_zs.clear();
//BBS: add only gcode mode
m_only_gcode_in_preview = false;