From 5144feb3197e6ee575e617bb7ed6d9cd32c671f6 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Thu, 19 Nov 2020 10:57:24 +0100 Subject: [PATCH] Estimated printing time per layer for SLAPrint Split the time if it's needed --- src/libslic3r/SLAPrint.hpp | 2 ++ src/libslic3r/SLAPrintSteps.cpp | 27 ++++++++------ src/slic3r/GUI/DoubleSlider.cpp | 63 ++++++++++++++++++++++++++++++--- src/slic3r/GUI/DoubleSlider.hpp | 3 +- src/slic3r/GUI/GUI_Preview.cpp | 12 ++++--- 5 files changed, 87 insertions(+), 20 deletions(-) diff --git a/src/libslic3r/SLAPrint.hpp b/src/libslic3r/SLAPrint.hpp index a4305e0c31..15292273f9 100644 --- a/src/libslic3r/SLAPrint.hpp +++ b/src/libslic3r/SLAPrint.hpp @@ -350,6 +350,7 @@ struct SLAPrintStatistics size_t fast_layers_count; double total_cost; double total_weight; + std::vector layers_times; // Config with the filled in print statistics. DynamicConfig config() const; @@ -366,6 +367,7 @@ struct SLAPrintStatistics fast_layers_count = 0; total_cost = 0.; total_weight = 0.; + layers_times.clear(); } }; diff --git a/src/libslic3r/SLAPrintSteps.cpp b/src/libslic3r/SLAPrintSteps.cpp index 11c8c6f4e6..d8bea62aea 100644 --- a/src/libslic3r/SLAPrintSteps.cpp +++ b/src/libslic3r/SLAPrintSteps.cpp @@ -671,6 +671,8 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { double models_volume(0.0); double estim_time(0.0); + std::vector layers_times; + layers_times.reserve(printer_input.size()); size_t slow_layers = 0; size_t fast_layers = 0; @@ -688,7 +690,7 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { // write vars &mutex, &models_volume, &supports_volume, &estim_time, &slow_layers, - &fast_layers, &fade_layer_time](size_t sliced_layer_cnt) + &fast_layers, &fade_layer_time, &layers_times](size_t sliced_layer_cnt) { PrintLayer &layer = m_print->m_printer_input[sliced_layer_cnt]; @@ -775,20 +777,21 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { else slow_layers++; - // Calculation of the printing time - + + double layer_times = 0.0; if (sliced_layer_cnt < 3) - estim_time += init_exp_time; - else if (fade_layer_time > exp_time) - { + layer_times += init_exp_time; + else if (fade_layer_time > exp_time) { fade_layer_time -= delta_fade_time; - estim_time += fade_layer_time; + layer_times += fade_layer_time; } else - estim_time += exp_time; - - estim_time += tilt_time; + layer_times += exp_time; + layer_times += tilt_time; + + layers_times.push_back(layer_times); + estim_time += layer_times; } }; @@ -804,8 +807,10 @@ void SLAPrint::Steps::merge_slices_and_eval_stats() { // A layers count o the highest object if (printer_input.size() == 0) print_statistics.estimated_print_time = std::nan(""); - else + else { print_statistics.estimated_print_time = estim_time; + print_statistics.layers_times = layers_times; + } print_statistics.fast_layers_count = fast_layers; print_statistics.slow_layers_count = slow_layers; diff --git a/src/slic3r/GUI/DoubleSlider.cpp b/src/slic3r/GUI/DoubleSlider.cpp index 3f988acf14..02fcadba85 100644 --- a/src/slic3r/GUI/DoubleSlider.cpp +++ b/src/slic3r/GUI/DoubleSlider.cpp @@ -381,9 +381,20 @@ void Control::SetTicksValues(const Info& custom_gcode_per_print_z) } void Control::SetLayersTimes(const std::vector& layers_times) +{ + m_layers_times.clear(); + if (layers_times.empty()) + return; + m_layers_times.resize(layers_times.size(), 0.0); + m_layers_times[0] = layers_times[0]; + for (size_t i = 1; i < layers_times.size(); i++) + m_layers_times[i] = m_layers_times[i - 1] + layers_times[i]; +} + +void Control::SetLayersTimes(const std::vector& layers_times) { m_layers_times = layers_times; - for (int i = 1; i < m_layers_times.size(); i++) + for (size_t i = 1; i < m_layers_times.size(); i++) m_layers_times[i] += m_layers_times[i - 1]; } @@ -579,7 +590,7 @@ void Control::draw_tick_on_mouse_position(wxDC& dc) } tick = get_value_from_position(m_moving_pos); - if (tick >= m_max_value || tick <= m_min_value || tick == m_higher_value || tick == m_lower_value) + if (tick > m_max_value || tick < m_min_value || tick == m_higher_value || tick == m_lower_value) return; wxCoord new_pos = get_position_from_value(tick); @@ -597,6 +608,47 @@ void Control::draw_tick_on_mouse_position(wxDC& dc) } } +static std::string short_and_splitted_time(const std::string& time) +{ + // Parse the dhms time format. + int days = 0; + int hours = 0; + int minutes = 0; + int seconds = 0; + if (time.find('d') != std::string::npos) + ::sscanf(time.c_str(), "%dd %dh %dm %ds", &days, &hours, &minutes, &seconds); + else if (time.find('h') != std::string::npos) + ::sscanf(time.c_str(), "%dh %dm %ds", &hours, &minutes, &seconds); + else if (time.find('m') != std::string::npos) + ::sscanf(time.c_str(), "%dm %ds", &minutes, &seconds); + else if (time.find('s') != std::string::npos) + ::sscanf(time.c_str(), "%ds", &seconds); + + // Format the dhm time. + char buffer[64]; + if (days > 0) + ::sprintf(buffer, "%dd%dh\n%dm", days, hours, minutes); + else if (hours > 0) { + if (hours < 10 && minutes < 10 && seconds < 10) + ::sprintf(buffer, "%dh%dm%ds", hours, minutes, seconds); + else if (hours > 10 && minutes > 10 && seconds > 10) + ::sprintf(buffer, "%dh\n%dm\n%ds", hours, minutes, seconds); + else if (minutes < 10 && seconds > 10 || minutes > 10 && seconds < 10) + ::sprintf(buffer, "%dh\n%dm%ds", hours, minutes, seconds); + else + ::sprintf(buffer, "%dh%dm\n%ds", hours, minutes, seconds); + } + else if (minutes > 0) { + if (minutes > 10 && seconds > 10) + ::sprintf(buffer, "%dm\n%ds", minutes, seconds); + else + ::sprintf(buffer, "%dm%ds", minutes, seconds); + } + else + ::sprintf(buffer, "%ds", seconds); + return buffer; +} + wxString Control::get_label(int tick, LabelType label_type/* = ltHeightWithLayer*/) const { const int value = tick; @@ -613,7 +665,7 @@ wxString Control::get_label(int tick, LabelType label_type/* = ltHeightWithLayer if (label_type == ltEstimatedTime) { if (m_values.size() != m_layers_times.size()) return "time"; - return Slic3r::short_time(get_time_dhms(m_layers_times[value])); + return short_and_splitted_time(get_time_dhms(m_layers_times[value])); } wxString str = m_values.empty() ? wxString::Format("%.*f", 2, m_label_koef * value) : @@ -664,7 +716,10 @@ void Control::draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, LabelType l text_pos = wxPoint(pos.x - text_width - 1 - m_thumb_size.x, pos.y - 0.5 * text_height + 1); } - dc.DrawText(label, text_pos); + if (label_type == ltEstimatedTime) + dc.DrawLabel(label, wxRect(text_pos, wxSize(text_width, text_height)), wxALIGN_RIGHT); + else + dc.DrawText(label, text_pos); } void Control::draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const diff --git a/src/slic3r/GUI/DoubleSlider.hpp b/src/slic3r/GUI/DoubleSlider.hpp index 509f6ce1ed..57fa5d0f10 100644 --- a/src/slic3r/GUI/DoubleSlider.hpp +++ b/src/slic3r/GUI/DoubleSlider.hpp @@ -225,6 +225,7 @@ public: Info GetTicksValues() const; void SetTicksValues(const Info &custom_gcode_per_print_z); void SetLayersTimes(const std::vector& layers_times); + void SetLayersTimes(const std::vector& layers_times); void SetDrawMode(bool is_sla_print, bool is_sequential_print); #if ENABLE_GCODE_VIEWER @@ -402,7 +403,7 @@ private: std::vector m_values; TickCodeInfo m_ticks; - std::vector m_layers_times; + std::vector m_layers_times; std::vector m_extruder_colors; diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 8091792e04..d33c8f22a5 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -657,7 +657,8 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee // Detect and set manipulation mode for double slider update_layers_slider_mode(); - CustomGCode::Info& ticks_info_from_model = wxGetApp().plater()->model().custom_gcode_per_print_z; + Plater* plater = wxGetApp().plater(); + CustomGCode::Info& ticks_info_from_model = plater->model().custom_gcode_per_print_z; check_layers_slider_values(ticks_info_from_model.gcodes, layers_z); m_layers_slider->SetSliderValues(layers_z); @@ -680,12 +681,15 @@ void Preview::update_layers_slider(const std::vector& layers_z, bool kee } m_layers_slider->SetSelectionSpan(idx_low, idx_high); m_layers_slider->SetTicksValues(ticks_info_from_model); - m_layers_slider->SetLayersTimes(m_gcode_result->time_statistics.modes[0].layers_times); - bool sla_print_technology = wxGetApp().plater()->printer_technology() == ptSLA; + bool sla_print_technology = plater->printer_technology() == ptSLA; bool sequential_print = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_bool("complete_objects"); m_layers_slider->SetDrawMode(sla_print_technology, sequential_print); - m_layers_slider->SetExtruderColors(wxGetApp().plater()->get_extruder_colors_from_plater_config()); + m_layers_slider->SetExtruderColors(plater->get_extruder_colors_from_plater_config()); + if (sla_print_technology) + m_layers_slider->SetLayersTimes(plater->sla_print().print_statistics().layers_times); + else + m_layers_slider->SetLayersTimes(m_gcode_result->time_statistics.modes[0].layers_times); m_layers_slider_sizer->Show((size_t)0); Layout();