|
1 | 1 | #include "StatusPanel.hpp" |
2 | 2 | #include "I18N.hpp" |
| 3 | +#include "Plater.hpp" |
| 4 | +#include "GLCanvas3D.hpp" |
| 5 | +#include "GCodeViewer.hpp" |
| 6 | +#include "libslic3r/CustomGCode.hpp" |
3 | 7 | #include "Widgets/Label.hpp" |
4 | 8 | #include "Widgets/Button.hpp" |
5 | 9 | #include "Widgets/StepCtrl.hpp" |
@@ -1047,11 +1051,18 @@ void PrintingTaskPanel::create_panel(wxWindow *parent) |
1047 | 1051 | m_staticText_layers->SetForegroundColour(wxColour(107, 107, 107)); |
1048 | 1052 | m_staticText_layers->Hide(); |
1049 | 1053 |
|
| 1054 | + m_staticText_next_pause = new wxStaticText(penel_text, wxID_ANY, wxEmptyString); |
| 1055 | + m_staticText_next_pause->SetFont(wxFont(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("HarmonyOS Sans SC"))); |
| 1056 | + m_staticText_next_pause->SetForegroundColour(wxColour(107, 107, 107)); |
| 1057 | + m_staticText_next_pause->Hide(); |
| 1058 | + |
1050 | 1059 | bSizer_text->Add(sizer_percent, 0, wxEXPAND, 0); |
1051 | 1060 | bSizer_text->Add(sizer_percent_icon, 0, wxEXPAND, 0); |
1052 | 1061 | bSizer_text->Add(0, 0, 1, wxEXPAND, 0); |
1053 | 1062 | bSizer_text->Add(m_staticText_layers, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0); |
1054 | 1063 | bSizer_text->Add(0, 0, 0, wxLEFT, FromDIP(20)); |
| 1064 | + bSizer_text->Add(m_staticText_next_pause, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0); |
| 1065 | + bSizer_text->Add(0, 0, 0, wxLEFT, FromDIP(20)); |
1055 | 1066 | bSizer_text->Add(m_staticText_progress_left, 0, wxALIGN_CENTER_VERTICAL | wxALL, 0); |
1056 | 1067 |
|
1057 | 1068 | m_printing_stage_panel = new wxPanel(penel_finish_time); |
@@ -1657,6 +1668,19 @@ void PrintingTaskPanel::update_left_time(int mc_left_time) |
1657 | 1668 | } |
1658 | 1669 | } |
1659 | 1670 |
|
| 1671 | +void PrintingTaskPanel::update_next_pause(int seconds_to_pause) |
| 1672 | +{ |
| 1673 | + if (!m_staticText_next_pause) return; |
| 1674 | + if (seconds_to_pause <= 0) { |
| 1675 | + m_staticText_next_pause->Hide(); |
| 1676 | + return; |
| 1677 | + } |
| 1678 | + wxString label = wxString::Format(_L("Pause in %s"), get_bbl_monitor_time_dhm(seconds_to_pause)); |
| 1679 | + m_staticText_next_pause->SetLabelText(label); |
| 1680 | + m_staticText_next_pause->Show(); |
| 1681 | + m_staticText_next_pause->GetParent()->Layout(); |
| 1682 | +} |
| 1683 | + |
1660 | 1684 | void PrintingTaskPanel::update_layers_num(bool show, wxString num) |
1661 | 1685 | { |
1662 | 1686 | if ((show == m_staticText_layers->IsShown()) && (num == m_staticText_layers->GetLabelText())) { return; } |
@@ -4184,6 +4208,43 @@ void StatusPanel::update_subtask(MachineObject *obj) |
4184 | 4208 | m_project_task_panel->enable_partskip_button(obj, true); |
4185 | 4209 | // update printing stage |
4186 | 4210 | m_project_task_panel->update_left_time(obj->mc_left_time); |
| 4211 | + |
| 4212 | + // compute time to next scheduled pause from the current slice result |
| 4213 | + { |
| 4214 | + int next_pause_sec = -1; |
| 4215 | + if (obj->curr_layer > 0 && obj->total_layers > 1 && obj->mc_left_time > 0) { |
| 4216 | + try { |
| 4217 | + Plater* plater = wxGetApp().plater(); |
| 4218 | + GLCanvas3D* canvas = plater ? plater->get_preview_canvas3D() : nullptr; |
| 4219 | + if (canvas) { |
| 4220 | + auto& viewer = canvas->get_gcode_viewer(); |
| 4221 | + const std::vector<double> layers_zs = viewer.get_layers_zs(); |
| 4222 | + const std::vector<CustomGCode::Item>& gcodes = viewer.get_custom_gcode_per_print_z(); |
| 4223 | + if (!layers_zs.empty() && !gcodes.empty()) { |
| 4224 | + // current layer's Z (1-based, clamp to valid range) |
| 4225 | + int cur_idx = std::min((int)obj->curr_layer - 1, (int)layers_zs.size() - 1); |
| 4226 | + double cur_z = layers_zs[cur_idx]; |
| 4227 | + // find the first PausePrint above current Z |
| 4228 | + for (const auto& item : gcodes) { |
| 4229 | + if (item.type == CustomGCode::PausePrint && item.print_z > cur_z) { |
| 4230 | + // map pause Z to layer index by lower_bound |
| 4231 | + auto it = std::lower_bound(layers_zs.begin(), layers_zs.end(), item.print_z); |
| 4232 | + int pause_layer = (int)std::distance(layers_zs.begin(), it) + 1; |
| 4233 | + int remaining_layers = obj->total_layers - obj->curr_layer; |
| 4234 | + int layers_to_pause = pause_layer - obj->curr_layer; |
| 4235 | + if (layers_to_pause > 0 && remaining_layers > 0) { |
| 4236 | + next_pause_sec = (int)((double)obj->mc_left_time * layers_to_pause / remaining_layers); |
| 4237 | + } |
| 4238 | + break; |
| 4239 | + } |
| 4240 | + } |
| 4241 | + } |
| 4242 | + } |
| 4243 | + } catch (...) {} |
| 4244 | + } |
| 4245 | + m_project_task_panel->update_next_pause(next_pause_sec); |
| 4246 | + } |
| 4247 | + |
4187 | 4248 | if (obj->subtask_) { |
4188 | 4249 | m_project_task_panel->update_stage_value_with_machine(obj->get_curr_stage(), obj->subtask_->task_progress, obj); |
4189 | 4250 | m_project_task_panel->update_progress_percent(wxString::Format("%d", obj->subtask_->task_progress), "%"); |
|
0 commit comments