NEW: add finish time in status panel

Change-Id: I3048cbe2aa20a7f2b78b5ca5fb9b40c3bb796689
This commit is contained in:
maosheng.wei 2024-08-20 12:15:26 +08:00 committed by Lane.Wei
parent ae76d0b961
commit 050f51fe15
3 changed files with 64 additions and 2 deletions

View File

@ -577,6 +577,41 @@ inline std::string get_bbl_monitor_time_dhm(float time_in_secs)
return buffer;
}
inline std::string get_bbl_finish_time_dhm(float time_in_secs)
{
if (time_in_secs < 1) return "Finished";
time_t finish_time = std::time(nullptr) + static_cast<time_t>(time_in_secs);
std::tm *finish_tm = std::localtime(&finish_time);
int finish_hour = finish_tm->tm_hour;
int finish_minute = finish_tm->tm_min;
int finish_day = finish_tm->tm_yday;
int finish_year = finish_tm->tm_year + 1900;
time_t current_time = std::time(nullptr);
std::tm *current_tm = std::localtime(&current_time);
int current_day = current_tm->tm_yday;
int current_year = current_tm->tm_year + 1900;
int diff_day = 0;
if (current_year != finish_year) {
if ((current_year % 4 == 0 && current_year % 100 != 0) || current_year % 400 == 0)
diff_day = 366 - current_day;
else
diff_day = 365 - current_day;
for (int year = current_year + 1; year < finish_year; year++) {
if ((current_year % 4 == 0 && current_year % 100 != 0) || current_year % 400 == 0)
diff_day += 366;
else
diff_day += 365;
}
diff_day += finish_day;
}
std::string finish_time_str = std::to_string(finish_hour) + ":" + std::to_string(finish_minute);
if (diff_day != 0) finish_time_str += " +" + std::to_string(diff_day);
return finish_time_str;
}
inline std::string get_bbl_remain_time_dhms(float time_in_secs)
{
int days = (int) (time_in_secs / 86400.0f);

View File

@ -320,11 +320,14 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
wxBoxSizer *bSizer_buttons = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *bSizer_text = new wxBoxSizer(wxHORIZONTAL);
wxBoxSizer *bSizer_finish_time = new wxBoxSizer(wxHORIZONTAL);
wxPanel* penel_bottons = new wxPanel(parent);
wxPanel* penel_text = new wxPanel(penel_bottons);
wxPanel* penel_finish_time = new wxPanel(parent);
penel_text->SetBackgroundColour(*wxWHITE);
penel_bottons->SetBackgroundColour(*wxWHITE);
penel_finish_time->SetBackgroundColour(*wxWHITE);
wxBoxSizer *sizer_percent = new wxBoxSizer(wxVERTICAL);
sizer_percent->Add(0, 0, 1, wxEXPAND, 0);
@ -383,6 +386,18 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
penel_text->SetSizer(bSizer_text);
penel_text->Layout();
m_staticText_finish_time = new wxStaticText(penel_finish_time, wxID_ANY, _L("Finish Time: N/A"));
m_staticText_finish_time->SetFont(wxFont(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("HarmonyOS Sans SC")));
m_staticText_finish_time->SetForegroundColour(wxColour(146, 146, 146));
m_staticText_finish_time->SetToolTip(_L("The estimated printing time for \nmulti-color models may be inaccurate."));
bSizer_finish_time->Add(0, 0, 1, wxEXPAND, 0);
bSizer_finish_time->Add(0, 0, 0, wxLEFT, FromDIP(20));
bSizer_finish_time->Add(m_staticText_finish_time, 0, wxALIGN_CENTER | wxALL, 0);
bSizer_finish_time->Add(panel_button_block, 0, wxALIGN_CENTER | wxALL, 0);
penel_finish_time->SetMaxSize(wxSize(FromDIP(600), -1));
penel_finish_time->SetSizer(bSizer_finish_time);
penel_finish_time->Layout();
bSizer_buttons->Add(penel_text, 1, wxEXPAND | wxALL, 0);
bSizer_buttons->Add(panel_button_block, 0, wxALIGN_CENTER | wxALL, 0);
@ -395,7 +410,7 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
bSizer_subtask_info->Add(m_printing_stage_value, 0, wxEXPAND | wxTOP, FromDIP(5));
bSizer_subtask_info->Add(penel_bottons, 0, wxEXPAND | wxTOP, FromDIP(10));
bSizer_subtask_info->Add(m_panel_progress, 0, wxEXPAND|wxRIGHT, FromDIP(25));
bSizer_subtask_info->Add(penel_finish_time, 0, wxEXPAND, 0);
m_printing_sizer = new wxBoxSizer(wxHORIZONTAL);
m_printing_sizer->SetMinSize(wxSize(PAGE_MIN_WIDTH, -1));
@ -403,7 +418,6 @@ void PrintingTaskPanel::create_panel(wxWindow* parent)
m_printing_sizer->Add(FromDIP(8), 0, 0, wxEXPAND, 0);
m_printing_sizer->Add(bSizer_subtask_info, 1, wxALL | wxEXPAND, 0);
m_staticline = new wxPanel( parent, wxID_ANY);
m_staticline->SetBackgroundColour(wxColour(238,238,238));
m_staticline->Layout();
@ -687,14 +701,24 @@ void PrintingTaskPanel::update_left_time(wxString time)
m_staticText_progress_left->SetLabelText(time);
}
void PrintingTaskPanel::update_finish_time(wxString finish_time)
{
if (finish_time == "Finished")
m_staticText_finish_time->SetLabelText(_L("Finished"));
else
m_staticText_finish_time->SetLabelText(_L("Finish Time: ") + finish_time);
}
void PrintingTaskPanel::update_left_time(int mc_left_time)
{
// update gcode progress
std::string left_time;
std::string right_time;
wxString left_time_text = NA_STR;
try {
left_time = get_bbl_monitor_time_dhm(mc_left_time);
right_time = get_bbl_finish_time_dhm(mc_left_time);
}
catch (...) {
;
@ -702,6 +726,7 @@ void PrintingTaskPanel::update_left_time(int mc_left_time)
if (!left_time.empty()) left_time_text = wxString::Format("-%s", left_time);
update_left_time(left_time_text);
update_finish_time(right_time);
}
void PrintingTaskPanel::update_layers_num(bool show, wxString num)

View File

@ -181,6 +181,7 @@ private:
wxStaticText* m_staticText_progress_percent;
wxStaticText* m_staticText_progress_percent_icon;
wxStaticText* m_staticText_progress_left;
wxStaticText* m_staticText_finish_time;
wxStaticText* m_staticText_layers;
wxStaticText * m_has_rated_prompt;
wxStaticText * m_request_failed_info;
@ -221,6 +222,7 @@ public:
void update_stage_value(wxString stage, int val);
void update_progress_percent(wxString percent, wxString icon);
void update_left_time(wxString time);
void update_finish_time(wxString finish_time);
void update_left_time(int mc_left_time);
void update_layers_num(bool show, wxString num = wxEmptyString);
void show_priting_use_info(bool show, wxString time = wxEmptyString, wxString weight = wxEmptyString);