Line Type preview: Display distances and amount values (#13681)

* feat(viewer): Display travel distance and move count in G-code summary

This commit introduces a new feature that enhances the G-code viewer by displaying the total travel distance and the total number of travel moves in the 'Line Type' summary.

This provides users with more detailed statistics about their prints, helping them to better understand the printer's behavior and identify opportunities to optimize travel moves for faster print times.

This commit also fixes a critical bug in the G-code processor where the travel distance was being calculated incorrectly. The distance variable was not being updated for non-extruding travel moves, leading to inaccurate statistics. The calculation has been corrected to ensure it is performed for all relevant move types, resulting in accurate travel distance reporting.

* Subfix segments

kilo mega giga tera peta exa

* Add missing values

* Grams to Kilos and tons

* add distance

* Fix tool view

* Record and display seam distances

Track seam-related distances in print statistics and show them in the GCode viewer. Added total_seam_gap_distance and total_seam_scarf_distance to PrintEstimatedStatistics (with initialization). In GCode::extrude_loop the code now computes seam gap and scarf distances and accumulates them for external perimeters. GCodeViewer uses the summed seam distance when the Seams option is selected in the legend.

* Fix travel / wipe distances

* Update GCode.cpp

* Filament changes estimated time

---------

Co-authored-by: Steve Scargall <37674041+sscargal@users.noreply.github.com>
This commit is contained in:
Ian Bassi
2026-05-21 02:49:43 -03:00
committed by GitHub
parent a2341920a1
commit c5855db578
5 changed files with 332 additions and 75 deletions

View File

@@ -3821,9 +3821,10 @@ void GCodeProcessor::process_G1(const std::array<std::optional<double>, 4>& axes
return;
EMoveType type = move_type(delta_pos);
const float delta_xyz = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]));
m_travel_dist = delta_xyz;
if (type == EMoveType::Extrude) {
const float delta_xyz = std::sqrt(sqr(delta_pos[X]) + sqr(delta_pos[Y]) + sqr(delta_pos[Z]));
m_travel_dist = delta_xyz;
float volume_extruded_filament = area_filament_cross_section * delta_pos[E];
float area_toolpath_cross_section = volume_extruded_filament / delta_xyz;
@@ -5445,6 +5446,11 @@ void GCodeProcessor::process_filament_change(int id)
int next_extruder_id = m_filament_maps[id];
int next_filament_id = id;
float extra_time = 0;
unsigned int filament_changes_delta = 0;
unsigned int extruder_changes_delta = 0;
float filament_load_time_delta = 0.0f;
float filament_unload_time_delta = 0.0f;
float tool_change_time_delta = 0.0f;
if (prev_filament_id == next_filament_id)
return;
@@ -5457,12 +5463,14 @@ void GCodeProcessor::process_filament_change(int id)
assert(prev_extruder_id != -1);
process_filaments(CustomGCode::ToolChange);
m_filament_id[next_extruder_id] = next_filament_id;
m_result.lock();
m_result.print_statistics.total_filament_changes += 1;
m_result.unlock();
extra_time += get_filament_unload_time(static_cast<size_t>(prev_filament_id));
filament_changes_delta += 1;
const float filament_unload_time = get_filament_unload_time(static_cast<size_t>(prev_filament_id));
extra_time += filament_unload_time;
filament_unload_time_delta += filament_unload_time;
m_time_processor.extruder_unloaded = false;
extra_time += get_filament_load_time(static_cast<size_t>(next_filament_id));
const float filament_load_time = get_filament_load_time(static_cast<size_t>(next_filament_id));
extra_time += filament_load_time;
filament_load_time_delta += filament_load_time;
}
else {
if (prev_extruder_id == -1) {
@@ -5470,7 +5478,9 @@ void GCodeProcessor::process_filament_change(int id)
m_extruder_id = next_extruder_id;
m_filament_id[next_extruder_id] = next_filament_id;
m_time_processor.extruder_unloaded = false;
extra_time += get_filament_load_time(static_cast<size_t>(next_filament_id));
const float filament_load_time = get_filament_load_time(static_cast<size_t>(next_filament_id));
extra_time += filament_load_time;
filament_load_time_delta += filament_load_time;
}
else {
//first process cache generated by last extruder
@@ -5481,24 +5491,39 @@ void GCodeProcessor::process_filament_change(int id)
//no filament in current extruder
m_filament_id[next_extruder_id] = next_filament_id;
m_time_processor.extruder_unloaded = false;
extra_time += get_filament_load_time(static_cast<size_t>(next_filament_id));
const float filament_load_time = get_filament_load_time(static_cast<size_t>(next_filament_id));
extra_time += filament_load_time;
filament_load_time_delta += filament_load_time;
}
else if (m_last_filament_id[next_extruder_id] != next_filament_id) {
//need to change filament
m_filament_id[next_extruder_id] = next_filament_id;
m_result.lock();
m_result.print_statistics.total_filament_changes += 1;
m_result.unlock();
extra_time += get_filament_unload_time(static_cast<size_t>(prev_filament_id));
filament_changes_delta += 1;
const float filament_unload_time = get_filament_unload_time(static_cast<size_t>(prev_filament_id));
extra_time += filament_unload_time;
filament_unload_time_delta += filament_unload_time;
m_time_processor.extruder_unloaded = false;
extra_time += get_filament_load_time(static_cast<size_t>(next_filament_id));
const float filament_load_time = get_filament_load_time(static_cast<size_t>(next_filament_id));
extra_time += filament_load_time;
filament_load_time_delta += filament_load_time;
}
m_result.lock();
m_result.print_statistics.total_extruder_changes++;
m_result.unlock();
extra_time += get_extruder_change_time(next_extruder_id);
extruder_changes_delta += 1;
const float tool_change_time = get_extruder_change_time(next_extruder_id);
extra_time += tool_change_time;
tool_change_time_delta += tool_change_time;
}
}
if (filament_changes_delta > 0 || extruder_changes_delta > 0 || filament_load_time_delta > 0.0f || filament_unload_time_delta > 0.0f || tool_change_time_delta > 0.0f) {
m_result.lock();
m_result.print_statistics.total_filament_changes += filament_changes_delta;
m_result.print_statistics.total_extruder_changes += extruder_changes_delta;
m_result.print_statistics.total_filament_load_time += filament_load_time_delta;
m_result.print_statistics.total_filament_unload_time += filament_unload_time_delta;
m_result.print_statistics.total_tool_change_time += tool_change_time_delta;
m_result.unlock();
}
m_cp_color.current = m_extruder_colors[next_filament_id];
simulate_st_synchronize(extra_time);
// store tool change move
@@ -5543,6 +5568,11 @@ void GCodeProcessor::store_move_vertex(EMoveType type, EMovePathType path_type,
m_line_id + 1 :
((type == EMoveType::Seam) ? m_last_line_id : m_line_id);
if (type == EMoveType::Travel) {
m_result.print_statistics.total_travel_moves++;
m_result.print_statistics.total_travel_distance += m_travel_dist;
}
m_result.moves.push_back({
m_last_line_id,
type,