refactor and improve layer time display

This commit is contained in:
SoftFever 2022-12-20 22:24:42 +08:00 committed by Lane.Wei
parent f42ae3239e
commit 357fa2bfe1
3 changed files with 39 additions and 16 deletions

View file

@ -1394,6 +1394,10 @@ void GCodeProcessor::finalize(bool post_process)
m_used_filaments.process_caches(this);
update_estimated_times_stats();
auto time_mode = m_result.print_statistics.modes[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)];
auto it = std::find_if(time_mode.roles_times.begin(), time_mode.roles_times.end(), [](const std::pair<ExtrusionRole, float>& item) { return erCustom == item.first; });
auto prepare_time = (it != time_mode.roles_times.end()) ? it->second : 0.0f;
//update times for results
for (size_t i = 0; i < m_result.moves.size(); i++) {
@ -1401,7 +1405,7 @@ void GCodeProcessor::finalize(bool post_process)
size_t layer_id = size_t(m_result.moves[i].layer_duration);
std::vector<float>& layer_times = m_result.print_statistics.modes[static_cast<size_t>(PrintEstimatedStatistics::ETimeMode::Normal)].layers_times;
if (layer_times.size() > layer_id - 1 && layer_id > 0)
m_result.moves[i].layer_duration = layer_times[layer_id - 1];
m_result.moves[i].layer_duration = layer_id == 1 ? std::max(0.f,layer_times[layer_id - 1] - prepare_time) : layer_times[layer_id - 1];
else
m_result.moves[i].layer_duration = 0;
}