From dc59e86d2c10fac0e58694a37ff77f72790da0eb Mon Sep 17 00:00:00 2001 From: enricoturri1966 Date: Tue, 21 Jul 2020 09:34:54 +0200 Subject: [PATCH] ENABLE_GCODE_VIEWER -> Partial refactoring in preparation for removal of old time estimator --- src/libslic3r/GCode.cpp | 2 ++ src/libslic3r/GCodeTimeEstimator.cpp | 2 ++ src/libslic3r/GCodeTimeEstimator.hpp | 2 ++ src/libslic3r/Print.cpp | 6 ++++++ src/libslic3r/Print.hpp | 6 ++++++ src/libslic3r/Technologies.hpp | 1 + src/slic3r/GUI/Plater.cpp | 27 +++++++++++++++++++++++++++ 7 files changed, 46 insertions(+) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 56cf357b7..a4f25fa14 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1065,11 +1065,13 @@ namespace DoExport { print_statistics.clear(); #if ENABLE_GCODE_VIEWER +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR print_statistics.estimated_normal_print_time_str = normal_time_estimator.get_time_dhm/*s*/(); print_statistics.estimated_silent_print_time_str = silent_time_estimator_enabled ? silent_time_estimator.get_time_dhm/*s*/() : "N/A"; print_statistics.estimated_normal_custom_gcode_print_times_str = normal_time_estimator.get_custom_gcode_times_dhm(true); if (silent_time_estimator_enabled) print_statistics.estimated_silent_custom_gcode_print_times_str = silent_time_estimator.get_custom_gcode_times_dhm(true); +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else print_statistics.estimated_normal_print_time = normal_time_estimator.get_time_dhm/*s*/(); print_statistics.estimated_silent_print_time = silent_time_estimator_enabled ? silent_time_estimator.get_time_dhm/*s*/() : "N/A"; diff --git a/src/libslic3r/GCodeTimeEstimator.cpp b/src/libslic3r/GCodeTimeEstimator.cpp index bc3adefc0..4bfe322ce 100644 --- a/src/libslic3r/GCodeTimeEstimator.cpp +++ b/src/libslic3r/GCodeTimeEstimator.cpp @@ -723,6 +723,7 @@ namespace Slic3r { } #if ENABLE_GCODE_VIEWER +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::vector>> GCodeTimeEstimator::get_custom_gcode_times_dhm(bool include_remaining) const { std::vector>> ret; @@ -737,6 +738,7 @@ namespace Slic3r { return ret; } +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else std::vector> GCodeTimeEstimator::get_custom_gcode_times_dhm(bool include_remaining) const { diff --git a/src/libslic3r/GCodeTimeEstimator.hpp b/src/libslic3r/GCodeTimeEstimator.hpp index ce6b2f4af..3b92f0269 100644 --- a/src/libslic3r/GCodeTimeEstimator.hpp +++ b/src/libslic3r/GCodeTimeEstimator.hpp @@ -371,7 +371,9 @@ namespace Slic3r { // Returns the estimated time, in format DDd HHh MMm, for each custom_gcode // If include_remaining==true the strings will be formatted as: "time for custom_gcode (remaining time at color start)" #if ENABLE_GCODE_VIEWER +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::vector>> get_custom_gcode_times_dhm(bool include_remaining) const; +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else std::vector> get_custom_gcode_times_dhm(bool include_remaining) const; #endif // ENABLE_GCODE_VIEWER diff --git a/src/libslic3r/Print.cpp b/src/libslic3r/Print.cpp index 34fab6f30..a48d6f602 100644 --- a/src/libslic3r/Print.cpp +++ b/src/libslic3r/Print.cpp @@ -2191,9 +2191,15 @@ DynamicConfig PrintStatistics::config() const { DynamicConfig config; #if ENABLE_GCODE_VIEWER +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR config.set_key_value("print_time", new ConfigOptionString(this->estimated_normal_print_time_str)); config.set_key_value("normal_print_time", new ConfigOptionString(this->estimated_normal_print_time_str)); config.set_key_value("silent_print_time", new ConfigOptionString(this->estimated_silent_print_time_str)); +#else + config.set_key_value("print_time", new ConfigOptionString(short_time(get_time_dhms(this->estimated_normal_print_time)))); + config.set_key_value("normal_print_time", new ConfigOptionString(short_time(get_time_dhms(this->estimated_normal_print_time)))); + config.set_key_value("silent_print_time", new ConfigOptionString(short_time(get_time_dhms(this->estimated_silent_print_time)))); +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else std::string normal_print_time = short_time(this->estimated_normal_print_time); std::string silent_print_time = short_time(this->estimated_silent_print_time); diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index 7a0ecdf17..064145a2e 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -306,12 +306,16 @@ struct PrintStatistics #if ENABLE_GCODE_VIEWER float estimated_normal_print_time; float estimated_silent_print_time; +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::string estimated_normal_print_time_str; std::string estimated_silent_print_time_str; +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::vector>> estimated_normal_custom_gcode_print_times; std::vector>> estimated_silent_custom_gcode_print_times; +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::vector>> estimated_normal_custom_gcode_print_times_str; std::vector>> estimated_silent_custom_gcode_print_times_str; +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR std::vector> estimated_normal_moves_times; std::vector> estimated_silent_moves_times; std::vector> estimated_normal_roles_times; @@ -341,10 +345,12 @@ struct PrintStatistics void clear() { #if ENABLE_GCODE_VIEWER clear_time_estimates(); +#if ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR estimated_normal_print_time_str.clear(); estimated_silent_print_time_str.clear(); estimated_normal_custom_gcode_print_times_str.clear(); estimated_silent_custom_gcode_print_times_str.clear(); +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else estimated_normal_print_time.clear(); estimated_silent_print_time.clear(); diff --git a/src/libslic3r/Technologies.hpp b/src/libslic3r/Technologies.hpp index b04e78c4e..06d217812 100644 --- a/src/libslic3r/Technologies.hpp +++ b/src/libslic3r/Technologies.hpp @@ -62,6 +62,7 @@ #define ENABLE_GCODE_VIEWER_STATISTICS (0 && ENABLE_GCODE_VIEWER) #define ENABLE_GCODE_VIEWER_SHADERS_EDITOR (0 && ENABLE_GCODE_VIEWER) #define ENABLE_GCODE_VIEWER_AS_STATE (1 && ENABLE_GCODE_VIEWER) +#define ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR (1 && ENABLE_GCODE_VIEWER) #endif // _prusaslicer_technologies_h_ diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 39003e9aa..f4c017add 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -1323,7 +1323,11 @@ 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")) +#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") @@ -1336,7 +1340,11 @@ void Sidebar::update_sliced_info_sizer() 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>>& times, +#else + auto fill_labels = [str_color, str_pause](const std::vector>>& times, +#endif // ENABLE_GCODE_VIEWER_USE_OLD_TIME_ESTIMATOR #else auto fill_labels = [str_color, str_pause](const std::vector>& times, #endif // ENABLE_GCODE_VIEWER @@ -1358,7 +1366,11 @@ void Sidebar::update_sliced_info_sizer() 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 @@ -1366,6 +1378,7 @@ void Sidebar::update_sliced_info_sizer() }; #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); @@ -1375,6 +1388,17 @@ 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_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")); @@ -1397,6 +1421,9 @@ 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)