From 90c69e6bda05f54e4f5d2f30c98f5ac68e954e65 Mon Sep 17 00:00:00 2001 From: enricoturri1966 <enricoturri@seznam.cz> Date: Tue, 27 Oct 2020 15:50:04 +0100 Subject: [PATCH] #4986 - Fixed remaining print time and SD-percentage calculation not correct (replaces e14c122d1233a7af9bfe63425d3bfb4e5906ede3) --- src/libslic3r/GCode/GCodeProcessor.cpp | 28 +++++++++++++++++--------- src/libslic3r/GCode/GCodeProcessor.hpp | 10 ++++++++- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/libslic3r/GCode/GCodeProcessor.cpp b/src/libslic3r/GCode/GCodeProcessor.cpp index 26391e06b..5371a60c3 100644 --- a/src/libslic3r/GCode/GCodeProcessor.cpp +++ b/src/libslic3r/GCode/GCodeProcessor.cpp @@ -170,7 +170,7 @@ void GCodeProcessor::TimeMachine::reset() prev.reset(); gcode_time.reset(); blocks = std::vector<TimeBlock>(); - g1_times_cache = std::vector<float>(); + g1_times_cache = std::vector<G1LinesCacheItem>(); std::fill(moves_time.begin(), moves_time.end(), 0.0f); std::fill(roles_time.begin(), roles_time.end(), 0.0f); layers_time = std::vector<float>(); @@ -292,7 +292,7 @@ void GCodeProcessor::TimeMachine::calculate_time(size_t keep_last_n_blocks) } layers_time[block.layer_id - 1] += block_time; } - g1_times_cache.push_back(time); + g1_times_cache.push_back({ block.g1_line_id, time }); } if (keep_last_n_blocks) @@ -398,14 +398,18 @@ void GCodeProcessor::TimeProcessor::post_process(const std::string& filename) auto process_line_G1 = [&]() { for (size_t i = 0; i < static_cast<size_t>(PrintEstimatedTimeStatistics::ETimeMode::Count); ++i) { const TimeMachine& machine = machines[i]; - if (machine.enabled && g1_lines_counter < machine.g1_times_cache.size()) { - float elapsed_time = machine.g1_times_cache[g1_lines_counter]; - std::pair<int, int> to_export = { int(100.0f * elapsed_time / machine.time), - time_in_minutes(machine.time - elapsed_time) }; - if (last_exported[i] != to_export) { - export_line += format_line_M73(machine.line_m73_mask.c_str(), - to_export.first, to_export.second); - last_exported[i] = to_export; + if (machine.enabled) { + auto it = std::find_if(machine.g1_times_cache.begin(), machine.g1_times_cache.end(), + [g1_lines_counter](const TimeMachine::G1LinesCacheItem& item) { return item.id == g1_lines_counter; }); + if (it != machine.g1_times_cache.end()) { + float elapsed_time = it->elapsed_time; + std::pair<int, int> to_export = { int(100.0f * elapsed_time / machine.time), + time_in_minutes(machine.time - elapsed_time) }; + if (last_exported[i] != to_export) { + export_line += format_line_M73(machine.line_m73_mask.c_str(), + to_export.first, to_export.second); + last_exported[i] = to_export; + } } } } @@ -711,6 +715,7 @@ void GCodeProcessor::reset() m_filament_diameters = std::vector<float>(Min_Extruder_Count, 1.75f); m_extruded_last_z = 0.0f; + m_g1_line_id = 0; m_layer_id = 0; m_cp_color.reset(); @@ -1393,6 +1398,8 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) return type; }; + ++m_g1_line_id; + // enable processing of lines M201/M203/M204/M205 m_time_processor.machine_envelope_processing_enabled = true; @@ -1498,6 +1505,7 @@ void GCodeProcessor::process_G1(const GCodeReader::GCodeLine& line) block.move_type = type; block.role = m_extrusion_role; block.distance = distance; + block.g1_line_id = m_g1_line_id; block.layer_id = m_layer_id; // calculates block cruise feedrate diff --git a/src/libslic3r/GCode/GCodeProcessor.hpp b/src/libslic3r/GCode/GCodeProcessor.hpp index a0cf5d6e5..0ee8bb864 100644 --- a/src/libslic3r/GCode/GCodeProcessor.hpp +++ b/src/libslic3r/GCode/GCodeProcessor.hpp @@ -145,6 +145,7 @@ namespace Slic3r { EMoveType move_type{ EMoveType::Noop }; ExtrusionRole role{ erNone }; + unsigned int g1_line_id{ 0 }; unsigned int layer_id{ 0 }; float distance{ 0.0f }; // mm float acceleration{ 0.0f }; // mm/s^2 @@ -182,6 +183,12 @@ namespace Slic3r { void reset(); }; + struct G1LinesCacheItem + { + unsigned int id; + float elapsed_time; + }; + bool enabled; float acceleration; // mm/s^2 // hard limit for the acceleration, to which the firmware will clamp. @@ -193,7 +200,7 @@ namespace Slic3r { State prev; CustomGCodeTime gcode_time; std::vector<TimeBlock> blocks; - std::vector<float> g1_times_cache; + std::vector<G1LinesCacheItem> g1_times_cache; std::array<float, static_cast<size_t>(EMoveType::Count)> moves_time; std::array<float, static_cast<size_t>(ExtrusionRole::erCount)> roles_time; std::vector<float> layers_time; @@ -376,6 +383,7 @@ namespace Slic3r { ExtruderColors m_extruder_colors; std::vector<float> m_filament_diameters; float m_extruded_last_z; + unsigned int m_g1_line_id; unsigned int m_layer_id; CpColor m_cp_color;