From be643e0ec3fad7dbd43cc67642a44bd0455985d1 Mon Sep 17 00:00:00 2001 From: hemai Date: Tue, 22 Jul 2025 12:09:18 +0800 Subject: [PATCH] ENH: apply DeviceErrorDialog to project Jira: [STUDIO-12798] Change-Id: I7b3518736bbb106e76fcbc16d0aaa5e08f65c202 (cherry picked from commit f8dbe74fc17ccc81b3fadf638caa108b6f96fdba) --- src/slic3r/GUI/DeviceErrorDialog.cpp | 125 ++++++++++++++++-- src/slic3r/GUI/DeviceErrorDialog.hpp | 15 ++- src/slic3r/GUI/StatusPanel.cpp | 181 +++++---------------------- src/slic3r/GUI/StatusPanel.hpp | 7 +- 4 files changed, 158 insertions(+), 170 deletions(-) diff --git a/src/slic3r/GUI/DeviceErrorDialog.cpp b/src/slic3r/GUI/DeviceErrorDialog.cpp index 88b4d1e5e7..bd51427e4f 100644 --- a/src/slic3r/GUI/DeviceErrorDialog.cpp +++ b/src/slic3r/GUI/DeviceErrorDialog.cpp @@ -4,11 +4,44 @@ #include "Widgets/Button.hpp" #include "GUI_App.hpp" #include "MainFrame.hpp" +#include "ReleaseNote.hpp" namespace Slic3r { namespace GUI { +static std::unordered_set message_containing_retry{ + "0701-8004", + "0701-8005", + "0701-8006", + "0701-8006", + "0701-8007", + "0700-8012", + "0701-8012", + "0702-8012", + "0703-8012", + "07FF-8003", + "07FF-8004", + "07FF-8005", + "07FF-8006", + "07FF-8007", + "07FF-8010", + "07FF-8011", + "07FF-8012", + "07FF-8013", + "12FF-8007", + "1200-8006" +}; + +static std::unordered_set message_containing_done{ + "07FF-8007", + "12FF-8007" +}; + +static std::unordered_set message_containing_resume{ + "0300-8013" +}; + DeviceErrorDialog::DeviceErrorDialog(MachineObject* obj, wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style) :DPIDialog(parent, id, title, pos, size, style), m_obj(obj) { @@ -159,6 +192,11 @@ void DeviceErrorDialog::init_button_list() init_button(TURN_OFF_FIRE_ALARM, _L("Got it, Turn off the Fire Alarm.")); init_button(RETRY_PROBLEM_SOLVED, _L("Retry (problem solved)")); init_button(STOP_DRYING, _L("Stop Drying")); + init_button(DBL_CHECK_CANCEL, _L("Cancle")); + init_button(DBL_CHECK_DONE, _L("Done")); + init_button(DBL_CHECK_RETRY, _L("Retry")); + init_button(DBL_CHECK_RESUME, _L("Resume")); + init_button(DBL_CHECK_OK, _L("Confirm")); } void DeviceErrorDialog::on_dpi_changed(const wxRect& suggested_rect) @@ -169,10 +207,10 @@ void DeviceErrorDialog::on_dpi_changed(const wxRect& suggested_rect) } static const std::unordered_set s_jump_liveview_error_codes = { "0300-8003", "0300-8002", "0300-800A"}; -void DeviceErrorDialog::show_error_code(int error_code) +wxString DeviceErrorDialog::show_error_code(int error_code) { - if (m_error_code == error_code) { return;} - if (wxGetApp().get_hms_query()->is_internal_error(m_obj, error_code)) { return;} + if (m_error_code == error_code) { return wxEmptyString;} + if (wxGetApp().get_hms_query()->is_internal_error(m_obj, error_code)) { return wxEmptyString;} /* error code str*/ std::string error_str = m_obj->get_error_code_str(error_code); @@ -181,22 +219,56 @@ void DeviceErrorDialog::show_error_code(int error_code) wxString error_msg = wxGetApp().get_hms_query()->query_print_error_msg(m_obj, error_code); if (error_msg.IsEmpty()) { error_msg = _L("Unknown error.");} - /* action buttons*/ - std::vector used_button; - wxString error_image_url = wxGetApp().get_hms_query()->query_print_image_action(m_obj, error_code, used_button); - if (s_jump_liveview_error_codes.count(error_str)) { used_button.emplace_back(DeviceErrorDialog::JUMP_TO_LIVEVIEW);}// special case + /* error_str is old error code*/ + if (message_containing_retry.count(error_str) || message_containing_done.count(error_str) || message_containing_resume.count(error_str)) { + /* convert old error code to pseudo buttons*/ + std::vector pseudo_button = convert_to_pseudo_buttons(error_str); - /* do update*/ - update_contents(error_msg, error_str, error_image_url, used_button); + /* do update*/ + update_contents(_L("Warning"), error_msg, error_str, wxEmptyString, pseudo_button); + } else { + /* action buttons*/ + std::vector used_button; + wxString error_image_url = wxGetApp().get_hms_query()->query_print_image_action(m_obj, error_code, used_button); + if (s_jump_liveview_error_codes.count(error_str)) { used_button.emplace_back(DeviceErrorDialog::JUMP_TO_LIVEVIEW); } // special case + + /* do update*/ + update_contents(_L("Error"), error_msg, error_str, error_image_url, used_button); + } wxGetApp().UpdateDlgDarkUI(this); Show(); Raise(); this->RequestUserAttention(wxUSER_ATTENTION_ERROR); + + return error_msg; } -void DeviceErrorDialog::update_contents(const wxString& text, const wxString& error_code, const wxString& image_url, const std::vector& btns) +std::vector DeviceErrorDialog::convert_to_pseudo_buttons(std::string error_str) +{ + std::vector pseudo_button; + if (message_containing_done.count(error_str) && message_containing_retry.count(error_str)) { + pseudo_button.emplace_back(DBL_CHECK_RETRY); + pseudo_button.emplace_back(DBL_CHECK_DONE); + pseudo_button.emplace_back(DBL_CHECK_OK); + } else if (message_containing_done.count(error_str)) { + pseudo_button.emplace_back(DBL_CHECK_DONE); + pseudo_button.emplace_back(DBL_CHECK_OK); + } else if (message_containing_retry.count(error_str)) { + pseudo_button.emplace_back(DBL_CHECK_RETRY); + pseudo_button.emplace_back(DBL_CHECK_OK); + } else if (message_containing_resume.count(error_str)) { + pseudo_button.emplace_back(DBL_CHECK_RESUME); + pseudo_button.emplace_back(DBL_CHECK_OK); + } else { + pseudo_button.emplace_back(DBL_CHECK_OK); + } + + return pseudo_button; +} + +void DeviceErrorDialog::update_contents(const wxString& title, const wxString& text, const wxString& error_code, const wxString& image_url, const std::vector& btns) { if (error_code.empty()) { return; } @@ -274,6 +346,9 @@ void DeviceErrorDialog::update_contents(const wxString& text, const wxString& er m_error_msg_label->SetMinSize(wxSize(FromDIP(300), -1)); m_error_msg_label->SetLabelText(text); + /* dialog title*/ + SetTitle(title); + /* update layout*/ { m_scroll_area->Layout(); @@ -381,6 +456,36 @@ void DeviceErrorDialog::on_button_click(ActionButton btn_id) break; } case DeviceErrorDialog::ERROR_BUTTON_COUNT: break; + + case DeviceErrorDialog::DBL_CHECK_CANCEL: { + // post EVT_SECONDARY_CHECK_CANCEL + // no event + break; + } + case DeviceErrorDialog::DBL_CHECK_DONE: { + // post EVT_SECONDARY_CHECK_DONE + m_obj->command_ams_control("done"); + break; + } + case DeviceErrorDialog::DBL_CHECK_RETRY: { + // post EVT_SECONDARY_CHECK_RETRY + wxCommandEvent event(EVT_SECONDARY_CHECK_RETRY); + wxPostEvent(GetParent(), event); + break; + } + case DeviceErrorDialog::DBL_CHECK_RESUME: { + // post EVT_SECONDARY_CHECK_RESUME + wxCommandEvent event(EVT_SECONDARY_CHECK_RESUME); + wxPostEvent(GetParent(), event); + break; + } + case DeviceErrorDialog::DBL_CHECK_OK: { + // post EVT_SECONDARY_CHECK_CONFIRM + m_obj->command_clean_print_error(m_obj->subtask_id_, m_error_code); + m_obj->command_clean_print_error_uiop(m_error_code); + break; + } + default: break; } diff --git a/src/slic3r/GUI/DeviceErrorDialog.hpp b/src/slic3r/GUI/DeviceErrorDialog.hpp index aaca522735..6c172f906f 100644 --- a/src/slic3r/GUI/DeviceErrorDialog.hpp +++ b/src/slic3r/GUI/DeviceErrorDialog.hpp @@ -44,7 +44,14 @@ public: STOP_DRYING = 35, REMOVE_CLOSE_BTN = 39, // special case, do not show close button - ERROR_BUTTON_COUNT + ERROR_BUTTON_COUNT, + + // old error code to pseudo action + DBL_CHECK_CANCEL = 10000, + DBL_CHECK_DONE = 10001, + DBL_CHECK_RETRY = 10002, + DBL_CHECK_RESUME = 10003, + DBL_CHECK_OK = 10004, }; public: @@ -58,13 +65,15 @@ public: ~DeviceErrorDialog(); public: - void show_error_code(int error_code); + wxString show_error_code(int error_code); protected: void init_button_list(); void init_button(ActionButton style, wxString buton_text); - void update_contents(const wxString& text, const wxString& error_code,const wxString& image_url, const std::vector& btns); + std::vector convert_to_pseudo_buttons(std::string error_str); + + void update_contents(const wxString& title, const wxString& text, const wxString& error_code,const wxString& image_url, const std::vector& btns); void on_button_click(ActionButton btn_id); void on_webrequest_state(wxWebRequestEvent& evt); diff --git a/src/slic3r/GUI/StatusPanel.cpp b/src/slic3r/GUI/StatusPanel.cpp index b88cf83cc1..2b31fad3fb 100644 --- a/src/slic3r/GUI/StatusPanel.cpp +++ b/src/slic3r/GUI/StatusPanel.cpp @@ -14,6 +14,7 @@ #include "MsgDialog.hpp" #include "slic3r/Utils/Http.hpp" #include "libslic3r/Thread.hpp" +#include "DeviceErrorDialog.hpp" #include "RecenterDialog.hpp" #include "CalibUtils.hpp" @@ -76,38 +77,6 @@ static wxColour PAGE_TITLE_FONT_COL = wxColour(107, 107, 107); static wxColour GROUP_TITLE_FONT_COL = wxColour(172, 172, 172); static wxColour TEXT_LIGHT_FONT_COL = wxColour(107, 107, 107); -static std::vector message_containing_retry{ - "0701 8004", - "0701 8005", - "0701 8006", - "0701 8006", - "0701 8007", - "0700 8012", - "0701 8012", - "0702 8012", - "0703 8012", - "07FF 8003", - "07FF 8004", - "07FF 8005", - "07FF 8006", - "07FF 8007", - "07FF 8010", - "07FF 8011", - "07FF 8012", - "07FF 8013", - "12FF 8007", - "1200 8006" -}; - -static std::vector message_containing_done{ - "07FF 8007", - "12FF 8007" -}; - -static std::vector message_containing_resume{ - "0300 8013" -}; - static wxImage fail_image; @@ -2352,9 +2321,8 @@ StatusPanel::StatusPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, co Bind(EVT_AMS_GUIDE_WIKI, &StatusPanel::on_ams_guide, this); Bind(EVT_AMS_RETRY, &StatusPanel::on_ams_retry, this); Bind(EVT_FAN_CHANGED, &StatusPanel::on_fan_changed, this); - Bind(EVT_SECONDARY_CHECK_DONE, &StatusPanel::on_print_error_done, this); Bind(EVT_SECONDARY_CHECK_RESUME, &StatusPanel::on_subtask_pause_resume, this); - Bind(EVT_ERROR_DIALOG_BTN_CLICKED, &StatusPanel::on_print_error_dlg_btn_clicked, this); + Bind(EVT_SECONDARY_CHECK_RETRY, [this](auto &e) { if (m_ams_control) { m_ams_control->on_retry(); }}); m_switch_speed->Connect(wxEVT_LEFT_DOWN, wxCommandEventHandler(StatusPanel::on_switch_speed), NULL, this); m_calibration_btn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_start_calibration), NULL, this); @@ -2405,9 +2373,6 @@ StatusPanel::~StatusPanel() m_parts_btn->Disconnect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(StatusPanel::on_show_parts_options), NULL, this); // remove warning dialogs - if (m_print_error_dlg != nullptr) - delete m_print_error_dlg; - if (abort_dlg != nullptr) delete abort_dlg; @@ -2514,12 +2479,15 @@ void StatusPanel::on_subtask_pause_resume(wxCommandEvent &event) BOOST_LOG_TRIVIAL(info) << "monitor: pause current print task dev_id =" << obj->get_dev_id(); obj->command_task_pause(); } +<<<<<<< HEAD (21aff5 FIX: CLI: fix the size related issue in set_with_restore_2) if (m_print_error_dlg) { m_print_error_dlg->on_hide(); }if (m_print_error_dlg_no_action) { m_print_error_dlg_no_action->on_hide(); } +======= +>>>>>>> CHANGE (40d58f ENH: apply DeviceErrorDialog to project) } } @@ -2736,127 +2704,37 @@ void StatusPanel::show_recenter_dialog() { obj->command_go_home(); } -void StatusPanel::show_error_message(MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str, wxString image_url, std::vector used_button) -{ - const std::string &dev_id = obj ? obj->get_dev_id() : string(); - - if (is_exist && msg.IsEmpty()) { - error_info_reset(); - if (m_print_error_dlg) { m_print_error_dlg->Hide();} - if (m_print_error_dlg_no_action) { m_print_error_dlg_no_action->Hide(); } - } else { - if (msg.IsEmpty()) { msg = _L("Unknow error."); } - m_project_task_panel->show_error_msg(msg); - - if (!used_button.empty()) { - BOOST_LOG_TRIVIAL(info) << "show print error! error_msg = " << msg; - if (m_print_error_dlg != nullptr) { - delete m_print_error_dlg; - m_print_error_dlg = nullptr; - } - - m_print_error_dlg = new PrintErrorDialog(this->GetParent(), wxID_ANY, _L("Error")); - m_print_error_dlg->update_title_style(_L("Error"), used_button, this); - m_print_error_dlg->update_text_image(msg, print_error_str, image_url); - m_print_error_dlg->Bind(wxEVT_CLOSE_WINDOW, [this, dev_id](wxCloseEvent& e) - { - MachineObject *the_obj = wxGetApp().getDeviceManager()->get_my_machine(dev_id); - if (the_obj) { the_obj->command_clean_print_error_uiop(the_obj->print_error); } - e.Skip(); - }); - m_print_error_dlg->on_show(); - } - else { - //old error code dialog - auto it_retry = std::find(message_containing_retry.begin(), message_containing_retry.end(), print_error_str); - auto it_done = std::find(message_containing_done.begin(), message_containing_done.end(), print_error_str); - auto it_resume = std::find(message_containing_resume.begin(), message_containing_resume.end(), print_error_str); - - BOOST_LOG_TRIVIAL(info) << "show print error! error_msg = " << msg; - - wxDateTime now = wxDateTime::Now(); - wxString show_time = now.Format("%H%M%d"); - wxString error_code_msg = wxString::Format("%S\n[%S %S]", msg, print_error_str, show_time); - - if (m_print_error_dlg_no_action != nullptr) { - delete m_print_error_dlg_no_action; - m_print_error_dlg_no_action = nullptr; - } - - m_print_error_dlg_no_action = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM); - if (it_done != message_containing_done.end() && it_retry != message_containing_retry.end()) { - m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::DONE_AND_RETRY, this); - } - else if (it_done != message_containing_done.end()) { - m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_DONE, this); - } - else if (it_retry != message_containing_retry.end()) { - m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_RETRY, this); - } - else if (it_resume != message_containing_resume.end()) { - m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::CONFIRM_AND_RESUME, this); - } - else { - m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM, this); - } - m_print_error_dlg_no_action->update_text(error_code_msg); - m_print_error_dlg_no_action->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, dev_id](wxCommandEvent &e) { - MachineObject *the_obj = wxGetApp().getDeviceManager()->get_my_machine(dev_id); - if (the_obj) { - the_obj->command_clean_print_error(the_obj->subtask_id_, the_obj->print_error); - the_obj->command_clean_print_error_uiop(the_obj->print_error); - } - }); - - m_print_error_dlg_no_action->Bind(wxEVT_CLOSE_WINDOW, [this, dev_id](wxCloseEvent& e) - { - MachineObject *the_obj = wxGetApp().getDeviceManager()->get_my_machine(dev_id); - if (the_obj) { the_obj->command_clean_print_error_uiop(the_obj->print_error); } - e.Skip(); - }); - - m_print_error_dlg_no_action->Bind(EVT_SECONDARY_CHECK_RETRY, [this](wxCommandEvent& e) { - if (m_ams_control) { - m_ams_control->on_retry(); - } - }); - - m_print_error_dlg_no_action->on_show(); - } - wxGetApp().mainframe->RequestUserAttention(wxUSER_ATTENTION_ERROR); - } -} void StatusPanel::update_error_message() { - if (obj->print_error <= 0) { - before_error_code = obj->print_error; - show_error_message(obj, true, wxEmptyString); - return; - } else if (before_error_code != obj->print_error && obj->print_error != skip_print_error) { - before_error_code = obj->print_error; + if (!obj) return; + static int last_error = -1; + + if (obj->print_error <= 0) { + error_info_reset(); + } else if (obj->print_error != last_error) { + /* clear old dialog */ + if (m_print_error_dlg) { delete m_print_error_dlg; } + +<<<<<<< HEAD (21aff5 FIX: CLI: fix the size related issue in set_with_restore_2) if (wxGetApp().get_hms_query()) { char buf[32]; ::sprintf(buf, "%08X", obj->print_error); std::string print_error_str = std::string(buf); if (print_error_str.size() > 4) { print_error_str.insert(4, "-"); } +======= + /* show device error message*/ + m_print_error_dlg = new DeviceErrorDialog(obj, this); + wxString error_msg = m_print_error_dlg->show_error_code(obj->print_error); + BOOST_LOG_TRIVIAL(info) << "print error: device error code = "<< obj->print_error; +>>>>>>> CHANGE (40d58f ENH: apply DeviceErrorDialog to project) - wxString error_msg = wxGetApp().get_hms_query()->query_print_error_msg(obj, obj->print_error); - if (wxGetApp().get_hms_query()->is_internal_error(obj, obj->print_error)) - { - return; - } - - std::vector used_button; - wxString error_image_url = wxGetApp().get_hms_query()->query_print_image_action(obj, obj->print_error, used_button); - // special case - if (print_error_str == "0300-8003" || print_error_str == "0300-8002" || print_error_str == "0300-800A") { - used_button.emplace_back(PrintErrorDialog::PrintErrorButton::JUMP_TO_LIVEVIEW); - } - show_error_message(obj, !error_msg.empty(), error_msg, print_error_str, error_image_url, used_button); - } + /* show error message on task panel */ + if(!error_msg.IsEmpty()) { m_project_task_panel->show_error_msg(error_msg); } } + + last_error = obj->print_error; } void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area) @@ -2888,7 +2766,7 @@ void StatusPanel::show_printing_status(bool ctrl_area, bool temp_area) m_bpButton_e_10->Enable(); m_bpButton_e_down_10->Enable(); - m_bpButton_z_10->SetIcon("monitor_bed_up"); + m_bpButton_z_10->SetIcon("monitor_bed_up"); m_bpButton_z_1->SetIcon("monitor_bed_up"); m_bpButton_z_down_1->SetIcon("monitor_bed_down"); m_bpButton_z_down_10->SetIcon("monitor_bed_down"); @@ -4303,9 +4181,6 @@ void StatusPanel::on_ams_load_vams(wxCommandEvent& event) { m_ams_control->SwitchAms(std::to_string(VIRTUAL_TRAY_MAIN_ID)); on_ams_load_curr(); - if (m_print_error_dlg) { - m_print_error_dlg->on_hide(); - } } void StatusPanel::on_ams_switch(SimpleEvent &event) @@ -4691,6 +4566,7 @@ void StatusPanel::on_ams_retry(wxCommandEvent& event) } } +<<<<<<< HEAD (21aff5 FIX: CLI: fix the size related issue in set_with_restore_2) void StatusPanel::on_print_error_done(wxCommandEvent& event) { BOOST_LOG_TRIVIAL(info) << "on_print_error_done"; @@ -4795,6 +4671,8 @@ void StatusPanel::on_print_error_dlg_btn_clicked(wxCommandEvent& event) if (m_print_error_dlg_no_action) { m_print_error_dlg_no_action->on_hide();} } } +======= +>>>>>>> CHANGE (40d58f ENH: apply DeviceErrorDialog to project) void StatusPanel::on_fan_changed(wxCommandEvent& event) { @@ -5306,7 +5184,6 @@ void StatusPanel::on_sys_color_changed() m_bitmap_speed_active.msw_rescale(); m_switch_speed->SetImages(m_bitmap_speed, m_bitmap_speed); m_ams_control->msw_rescale(); - if (m_print_error_dlg) { m_print_error_dlg->msw_rescale(); } rescale_camera_icons(); } diff --git a/src/slic3r/GUI/StatusPanel.hpp b/src/slic3r/GUI/StatusPanel.hpp index a8406c39fc..08cf77f7aa 100644 --- a/src/slic3r/GUI/StatusPanel.hpp +++ b/src/slic3r/GUI/StatusPanel.hpp @@ -33,6 +33,7 @@ #include "Widgets/FilamentLoad.hpp" #include "Widgets/FanControl.hpp" #include "HMS.hpp" +#include "DeviceErrorDialog.hpp" class StepIndicator; @@ -601,8 +602,7 @@ protected: CalibrationDialog* calibration_dlg {nullptr}; AMSMaterialsSetting *m_filament_setting_dlg{nullptr}; - PrintErrorDialog* m_print_error_dlg = nullptr; - SecondaryCheckDialog* m_print_error_dlg_no_action = nullptr; + DeviceErrorDialog* m_print_error_dlg = nullptr; SecondaryCheckDialog* abort_dlg = nullptr; SecondaryCheckDialog* con_load_dlg = nullptr; MessageDialog * ctrl_e_hint_dlg = nullptr; @@ -655,7 +655,6 @@ protected: void on_subtask_pause_resume(wxCommandEvent &event); void on_subtask_abort(wxCommandEvent &event); void on_print_error_clean(wxCommandEvent &event); - void show_error_message(MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str = "", wxString image_url = "", std::vector used_button = std::vector()); void error_info_reset(); void show_recenter_dialog(); @@ -696,8 +695,6 @@ protected: void on_ams_selected(wxCommandEvent &event); void on_ams_guide(wxCommandEvent &event); void on_ams_retry(wxCommandEvent &event); - void on_print_error_done(wxCommandEvent& event); - void on_print_error_dlg_btn_clicked(wxCommandEvent& event); void on_fan_changed(wxCommandEvent& event); void on_cham_temp_kill_focus(wxFocusEvent& event);