Refactoring to allow to quickly build the various options to show the estimated printing time in gcode viewer scene

This commit is contained in:
enricoturri1966 2020-08-05 15:43:46 +02:00
parent 510e787bc7
commit 8fc5be7e4f
15 changed files with 125 additions and 174 deletions

View file

@ -1324,15 +1324,10 @@ void Sidebar::update_sliced_info_sizer()
p->sliced_info->SetTextAndShow(siCost, info_text, new_label);
#if ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
if (p->plater->get_current_canvas3D()->is_time_estimate_enabled() || (ps.estimated_normal_print_time_str == "N/A" && ps.estimated_silent_print_time_str == "N/A"))
// hide the estimate time
p->sliced_info->SetTextAndShow(siEstimatedTime, "N/A");
#else
if (p->plater->get_current_canvas3D()->is_time_estimate_enabled() || (ps.estimated_normal_print_time <= 0.0f && ps.estimated_silent_print_time <= 0.0f))
#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
#else
if (ps.estimated_normal_print_time == "N/A" && ps.estimated_silent_print_time == "N/A")
#endif // ENABLE_GCODE_VIEWER
p->sliced_info->SetTextAndShow(siEstimatedTime, "N/A");
else {
new_label = _L("Estimated printing time") + ":";
@ -1340,15 +1335,7 @@ void Sidebar::update_sliced_info_sizer()
wxString str_color = _L("Color");
wxString str_pause = _L("Pause");
#if ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
auto fill_labels = [str_color, str_pause](const std::vector<std::pair<CustomGCode::Type, std::pair<std::string, std::string>>>& times,
#else
auto fill_labels = [str_color, str_pause](const std::vector<std::pair<CustomGCode::Type, std::pair<float, float>>>& times,
#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
#else
auto fill_labels = [str_color, str_pause](const std::vector<std::pair<CustomGCode::Type, std::string>>& times,
#endif // ENABLE_GCODE_VIEWER
wxString& new_label, wxString& info_text)
{
int color_change_count = 0;
@ -1366,41 +1353,10 @@ void Sidebar::update_sliced_info_sizer()
if (i != (int)times.size() - 1 && times[i].first == CustomGCode::PausePrint)
new_label += format_wxstr(" -> %1%", str_pause);
#if ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
info_text += format_wxstr("\n%1% (%2%)", times[i].second.first, times[i].second.second);
#else
info_text += format_wxstr("\n%1% (%2%)", short_time(get_time_dhms(times[i].second.first)), short_time(get_time_dhms(times[i].second.second)));
#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
#else
info_text += format_wxstr("\n%1%", times[i].second);
#endif // ENABLE_GCODE_VIEWER
}
};
#if ENABLE_GCODE_VIEWER
#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
if (ps.estimated_normal_print_time_str != "N/A") {
new_label += format_wxstr("\n - %1%", _L("normal mode"));
info_text += format_wxstr("\n%1%", ps.estimated_normal_print_time_str);
fill_labels(ps.estimated_normal_custom_gcode_print_times_str, new_label, info_text);
}
if (ps.estimated_silent_print_time_str != "N/A") {
new_label += format_wxstr("\n - %1%", _L("stealth mode"));
info_text += format_wxstr("\n%1%", ps.estimated_silent_print_time_str);
fill_labels(ps.estimated_silent_custom_gcode_print_times_str, new_label, info_text);
#else
if (ps.estimated_normal_print_time > 0.0f) {
new_label += format_wxstr("\n - %1%", _L("normal mode"));
info_text += format_wxstr("\n%1%", short_time(get_time_dhms(ps.estimated_normal_print_time)));
fill_labels(ps.estimated_normal_custom_gcode_print_times, new_label, info_text);
}
if (ps.estimated_silent_print_time > 0.0f) {
new_label += format_wxstr("\n - %1%", _L("stealth mode"));
info_text += format_wxstr("\n%1%", short_time(get_time_dhms(ps.estimated_silent_print_time)));
fill_labels(ps.estimated_silent_custom_gcode_print_times, new_label, info_text);
#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR
#else
if (ps.estimated_normal_print_time != "N/A") {
new_label += format_wxstr("\n - %1%", _L("normal mode"));
info_text += format_wxstr("\n%1%", ps.estimated_normal_print_time);
@ -1416,10 +1372,10 @@ void Sidebar::update_sliced_info_sizer()
new_label += format_wxstr("\n - %1%", _L("stealth mode"));
info_text += format_wxstr("\n%1%", ps.estimated_silent_print_time);
fill_labels(ps.estimated_silent_custom_gcode_print_times, new_label, info_text);
#endif // ENABLE_GCODE_VIEWER
}
p->sliced_info->SetTextAndShow(siEstimatedTime, info_text, new_label);
}
#endif // !ENABLE_GCODE_VIEWER
// if there is a wipe tower, insert number of toolchanges info into the array:
p->sliced_info->SetTextAndShow(siWTNumbetOfToolchanges, is_wipe_tower ? wxString::Format("%.d", ps.total_toolchanges) : "N/A");
@ -1428,9 +1384,8 @@ void Sidebar::update_sliced_info_sizer()
p->sliced_info->SetTextAndShow(siMateril_unit, "N/A");
}
}
#if ENABLE_GCODE_VIEWER
Layout();
#endif // ENABLE_GCODE_VIEWER
}
void Sidebar::show_sliced_info_sizer(const bool show)