ENH: Optimize the presentation of error code dialog

JIRA: STUDIO-7469 STUDIO-7477 STUDIO-7613

Change-Id: I6689dc375a51a1d690b82f9dbaa79d1555f7816f
(cherry picked from commit 777c16fef0862587f3ec468652aabd70cff88dfe)
This commit is contained in:
Kunlong Ma 2024-09-04 18:21:00 +08:00 committed by Noisyfox
parent 9ab3107304
commit b75f22bb22
8 changed files with 62 additions and 41 deletions

View file

@ -760,7 +760,7 @@ PingCodeBindDialog::~PingCodeBindDialog() {
json j = json::parse(str.utf8_string()); json j = json::parse(str.utf8_string());
if (j.contains("err_code")) { if (j.contains("err_code")) {
int error_code = j["err_code"].get<int>(); int error_code = j["err_code"].get<int>();
extra = wxGetApp().get_hms_query()->query_print_error_msg(error_code); wxGetApp().get_hms_query()->query_print_error_msg(error_code, extra);
} }
} }
catch (...) { catch (...) {

View file

@ -243,14 +243,15 @@ wxString HMSQuery::_query_hms_msg(std::string long_error_code, std::string lang_
return wxEmptyString; return wxEmptyString;
} }
wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_code) bool HMSQuery::_query_error_msg(wxString &error_msg, std::string error_code, std::string lang_code)
{ {
if (m_hms_info_json.contains("device_error")) { if (m_hms_info_json.contains("device_error")) {
if (m_hms_info_json["device_error"].contains(lang_code)) { if (m_hms_info_json["device_error"].contains(lang_code)) {
for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) { for (auto item = m_hms_info_json["device_error"][lang_code].begin(); item != m_hms_info_json["device_error"][lang_code].end(); item++) {
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) { if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
if (item->contains("intro")) { if (item->contains("intro")) {
return wxString::FromUTF8((*item)["intro"].get<std::string>()); error_msg = wxString::FromUTF8((*item)["intro"].get<std::string>());
return true;
} }
} }
} }
@ -263,7 +264,8 @@ wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_cod
for (auto item = lang.begin(); item != lang.end(); item++) { for (auto item = lang.begin(); item != lang.end(); item++) {
if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) { if (item->contains("ecode") && boost::to_upper_copy((*item)["ecode"].get<std::string>()) == error_code) {
if (item->contains("intro")) { if (item->contains("intro")) {
return wxString::FromUTF8((*item)["intro"].get<std::string>()); error_msg = wxString::FromUTF8((*item)["intro"].get<std::string>());
return true;
} }
} }
} }
@ -273,9 +275,11 @@ wxString HMSQuery::_query_error_msg(std::string error_code, std::string lang_cod
} }
else { else {
BOOST_LOG_TRIVIAL(info) << "device_error is not exists"; BOOST_LOG_TRIVIAL(info) << "device_error is not exists";
return wxEmptyString; error_msg = wxEmptyString;
return false;
} }
return wxEmptyString; error_msg = wxEmptyString;
return false;
} }
wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action) wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action)
@ -305,12 +309,12 @@ wxString HMSQuery::_query_error_url_action(std::string long_error_code, std::str
} }
wxString HMSQuery::query_print_error_msg(int print_error) bool HMSQuery::query_print_error_msg(int print_error, wxString &error_msg)
{ {
char buf[32]; char buf[32];
::sprintf(buf, "%08X", print_error); ::sprintf(buf, "%08X", print_error);
std::string lang_code = HMSQuery::hms_language_code(); std::string lang_code = HMSQuery::hms_language_code();
return _query_error_msg(std::string(buf), lang_code); return _query_error_msg(error_msg, std::string(buf), lang_code);
} }
wxString HMSQuery::query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action) wxString HMSQuery::query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action)

View file

@ -28,13 +28,13 @@ protected:
int save_to_local(std::string lang, std::string hms_type,json save_json); int save_to_local(std::string lang, std::string hms_type,json save_json);
std::string get_hms_file(std::string hms_type, std::string lang = std::string("en")); std::string get_hms_file(std::string hms_type, std::string lang = std::string("en"));
wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en")); wxString _query_hms_msg(std::string long_error_code, std::string lang_code = std::string("en"));
wxString _query_error_msg(std::string long_error_code, std::string lang_code = std::string("en")); bool _query_error_msg(wxString &error_msg, std::string long_error_code, std::string lang_code = std::string("en"));
wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action); wxString _query_error_url_action(std::string long_error_code, std::string dev_id, std::vector<int>& button_action);
public: public:
HMSQuery() {} HMSQuery() {}
int check_hms_info(); int check_hms_info();
wxString query_hms_msg(std::string long_error_code); wxString query_hms_msg(std::string long_error_code);
wxString query_print_error_msg(int print_error); bool query_print_error_msg(int print_error, wxString &error_msg);
wxString query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action); wxString query_print_error_url_action(int print_error, std::string dev_id, std::vector<int>& button_action);
static std::string hms_language_code(); static std::string hms_language_code();
static std::string build_query_params(std::string& lang); static std::string build_query_params(std::string& lang);

View file

@ -105,7 +105,9 @@ void BindJob::process(Ctl &ctl)
try try
{ {
error_code = stoi(result_info); error_code = stoi(result_info);
result_info = wxGetApp().get_hms_query()->query_print_error_msg(error_code).ToStdString(); wxString error_msg;
wxGetApp().get_hms_query()->query_print_error_msg(error_code, error_msg);
result_info = error_msg.ToStdString();
} }
catch (...) { catch (...) {
; ;

View file

@ -896,7 +896,7 @@ PrintErrorDialog::PrintErrorDialog(wxWindow* parent, wxWindowID id, const wxStri
bottom_sizer->Add(m_sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, 0); bottom_sizer->Add(m_sizer_button, 0, wxEXPAND | wxRIGHT | wxLEFT, 0);
m_sizer_right->Add(bottom_sizer, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(15)); m_sizer_right->Add(bottom_sizer, 0, wxEXPAND | wxRIGHT | wxLEFT, FromDIP(20));
m_sizer_right->Add(0, 0, 0, wxTOP, FromDIP(10)); m_sizer_right->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_main->Add(m_sizer_right, 0, wxBOTTOM | wxEXPAND, FromDIP(5)); m_sizer_main->Add(m_sizer_right, 0, wxBOTTOM | wxEXPAND, FromDIP(5));
@ -952,20 +952,34 @@ void PrintErrorDialog::on_webrequest_state(wxWebRequestEvent& evt)
} }
} }
void PrintErrorDialog::update_text_image(wxString text, wxString image_url) void PrintErrorDialog::update_text_image(const wxString& text, const wxString& error_code, const wxString& image_url)
{ {
//if (!m_sizer_text_release_note) { //if (!m_sizer_text_release_note) {
// m_sizer_text_release_note = new wxBoxSizer(wxVERTICAL); // m_sizer_text_release_note = new wxBoxSizer(wxVERTICAL);
//} //}
wxBoxSizer* sizer_text_release_note = new wxBoxSizer(wxVERTICAL); wxBoxSizer* sizer_text_release_note = new wxBoxSizer(wxVERTICAL);
wxString error_code_msg = error_code;
if (!error_code.IsEmpty()) {
wxDateTime now = wxDateTime::Now();
wxString show_time = now.Format("%H%M%d");
error_code_msg = wxString::Format("[%S %S]", error_code, show_time);
}
if (!m_staticText_release_note) { if (!m_staticText_release_note) {
m_staticText_release_note = new Label(m_vebview_release_note, text, LB_AUTO_WRAP); m_staticText_release_note = new Label(m_vebview_release_note, text, LB_AUTO_WRAP);
sizer_text_release_note->Add(m_error_prompt_pic_static, 0, wxALIGN_CENTER, FromDIP(5)); sizer_text_release_note->Add(m_error_prompt_pic_static, 0, wxALIGN_CENTER, FromDIP(5));
sizer_text_release_note->AddSpacer(10);
sizer_text_release_note->Add(m_staticText_release_note, 0, wxALIGN_CENTER , FromDIP(5)); sizer_text_release_note->Add(m_staticText_release_note, 0, wxALIGN_CENTER , FromDIP(5));
m_vebview_release_note->SetSizer(sizer_text_release_note);
} }
if (!m_staticText_error_code) {
m_staticText_error_code = new Label(m_vebview_release_note, error_code_msg, LB_AUTO_WRAP);
sizer_text_release_note->AddSpacer(5);
sizer_text_release_note->Add(m_staticText_error_code, 0, wxALIGN_CENTER, FromDIP(5));
}
m_vebview_release_note->SetSizer(sizer_text_release_note);
if (!image_url.empty()) { if (!image_url.empty()) {
web_request = wxWebSession::GetDefault().CreateRequest(this, image_url); web_request = wxWebSession::GetDefault().CreateRequest(this, image_url);
BOOST_LOG_TRIVIAL(trace) << "monitor: create new webrequest, state = " << web_request.GetState() << ", url = " << image_url; BOOST_LOG_TRIVIAL(trace) << "monitor: create new webrequest, state = " << web_request.GetState() << ", url = " << image_url;
@ -982,6 +996,9 @@ void PrintErrorDialog::update_text_image(wxString text, wxString image_url)
m_staticText_release_note->SetMaxSize(wxSize(FromDIP(300), -1)); m_staticText_release_note->SetMaxSize(wxSize(FromDIP(300), -1));
m_staticText_release_note->SetMinSize(wxSize(FromDIP(300), -1)); m_staticText_release_note->SetMinSize(wxSize(FromDIP(300), -1));
m_staticText_release_note->SetLabelText(text); m_staticText_release_note->SetLabelText(text);
m_staticText_error_code->SetMaxSize(wxSize(FromDIP(300), -1));
m_staticText_error_code->SetMinSize(wxSize(FromDIP(300), -1));
m_staticText_error_code->SetLabelText(error_code_msg);
m_vebview_release_note->Layout(); m_vebview_release_note->Layout();
auto text_size = m_staticText_release_note->GetBestSize(); auto text_size = m_staticText_release_note->GetBestSize();
@ -1048,7 +1065,8 @@ void PrintErrorDialog::update_title_style(wxString title, std::vector<int> butto
} }
void PrintErrorDialog::init_button(PrintErrorButton style,wxString buton_text) { void PrintErrorDialog::init_button(PrintErrorButton style,wxString buton_text)
{
Button* print_error_button = new Button(this, buton_text); Button* print_error_button = new Button(this, buton_text);
print_error_button->SetBackgroundColor(btn_bg_white); print_error_button->SetBackgroundColor(btn_bg_white);
print_error_button->SetBorderColor(wxColour(38, 46, 48)); print_error_button->SetBorderColor(wxColour(38, 46, 48));
@ -1062,8 +1080,8 @@ void PrintErrorDialog::init_button(PrintErrorButton style,wxString buton_text) {
} }
void PrintErrorDialog::init_button_list() { void PrintErrorDialog::init_button_list()
{
init_button(RESUME_PRINTING, _L("Resume Printing")); init_button(RESUME_PRINTING, _L("Resume Printing"));
m_button_list[RESUME_PRINTING]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) { m_button_list[RESUME_PRINTING]->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
post_event(wxCommandEvent(EVT_SECONDARY_CHECK_RESUME)); post_event(wxCommandEvent(EVT_SECONDARY_CHECK_RESUME));

View file

@ -189,7 +189,7 @@ public:
const wxSize& size = wxDefaultSize, const wxSize& size = wxDefaultSize,
long style = wxCLOSE_BOX | wxCAPTION long style = wxCLOSE_BOX | wxCAPTION
); );
void update_text_image(wxString text, wxString image_url); void update_text_image(const wxString& text, const wxString& error_code,const wxString& image_url);
void on_show(); void on_show();
void on_hide(); void on_hide();
void update_title_style(wxString title, std::vector<int> style, wxWindow* parent = nullptr); void update_title_style(wxString title, std::vector<int> style, wxWindow* parent = nullptr);
@ -206,6 +206,7 @@ public:
wxWebRequest web_request; wxWebRequest web_request;
wxStaticBitmap* m_error_prompt_pic_static; wxStaticBitmap* m_error_prompt_pic_static;
Label* m_staticText_release_note{ nullptr }; Label* m_staticText_release_note{ nullptr };
Label* m_staticText_error_code{ nullptr };
wxBoxSizer* m_sizer_main; wxBoxSizer* m_sizer_main;
wxBoxSizer* m_sizer_button; wxBoxSizer* m_sizer_button;
wxScrolledWindow* m_vebview_release_note{ nullptr }; wxScrolledWindow* m_vebview_release_note{ nullptr };

View file

@ -2176,9 +2176,9 @@ void StatusPanel::show_recenter_dialog() {
obj->command_go_home(); obj->command_go_home();
} }
void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::string print_error_str, wxString image_url, std::vector<int> used_button) void StatusPanel::show_error_message(MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str, wxString image_url, std::vector<int> used_button)
{ {
if (msg.IsEmpty()) { if (is_exist && msg.IsEmpty()) {
error_info_reset(); error_info_reset();
} else { } else {
m_project_task_panel->show_error_msg(msg); m_project_task_panel->show_error_msg(msg);
@ -2190,7 +2190,7 @@ void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::stri
} }
m_print_error_dlg->update_title_style(_L("Error"), used_button, this); m_print_error_dlg->update_title_style(_L("Error"), used_button, this);
m_print_error_dlg->update_text_image(msg, image_url); m_print_error_dlg->update_text_image(msg, print_error_str, image_url);
m_print_error_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, obj](wxCommandEvent& e) { m_print_error_dlg->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, obj](wxCommandEvent& e) {
if (obj) { if (obj) {
obj->command_clean_print_error(obj->subtask_id_, obj->print_error); obj->command_clean_print_error(obj->subtask_id_, obj->print_error);
@ -2212,6 +2212,11 @@ void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::stri
auto it_resume = std::find(message_containing_resume.begin(), message_containing_resume.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; 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) { if (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); m_print_error_dlg_no_action = new SecondaryCheckDialog(this->GetParent(), wxID_ANY, _L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM);
} }
@ -2231,7 +2236,7 @@ void StatusPanel::show_error_message(MachineObject* obj, wxString msg, std::stri
else { else {
m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM, this); m_print_error_dlg_no_action->update_title_style(_L("Warning"), SecondaryCheckDialog::ButtonStyle::ONLY_CONFIRM, this);
} }
m_print_error_dlg_no_action->update_text(msg); m_print_error_dlg_no_action->update_text(error_code_msg);
m_print_error_dlg_no_action->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, obj](wxCommandEvent& e) { m_print_error_dlg_no_action->Bind(EVT_SECONDARY_CHECK_CONFIRM, [this, obj](wxCommandEvent& e) {
if (obj) { if (obj) {
obj->command_clean_print_error(obj->subtask_id_, obj->print_error); obj->command_clean_print_error(obj->subtask_id_, obj->print_error);
@ -2254,7 +2259,7 @@ void StatusPanel::update_error_message()
{ {
if (obj->print_error <= 0) { if (obj->print_error <= 0) {
before_error_code = obj->print_error; before_error_code = obj->print_error;
show_error_message(obj, wxEmptyString); show_error_message(obj, true, wxEmptyString);
return; return;
} else if (before_error_code != obj->print_error && obj->print_error != skip_print_error) { } else if (before_error_code != obj->print_error && obj->print_error != skip_print_error) {
before_error_code = obj->print_error; before_error_code = obj->print_error;
@ -2263,27 +2268,17 @@ void StatusPanel::update_error_message()
char buf[32]; char buf[32];
::sprintf(buf, "%08X", obj->print_error); ::sprintf(buf, "%08X", obj->print_error);
std::string print_error_str = std::string(buf); std::string print_error_str = std::string(buf);
if (print_error_str.size() > 4) { if (print_error_str.size() > 4) { print_error_str.insert(4, " "); }
print_error_str.insert(4, " ");
}
wxString error_msg = wxGetApp().get_hms_query()->query_print_error_msg(obj->print_error); wxString error_msg;
bool is_errocode_exist = wxGetApp().get_hms_query()->query_print_error_msg(obj->print_error, error_msg);
std::vector<int> used_button; std::vector<int> used_button;
wxString error_image_url = wxGetApp().get_hms_query()->query_print_error_url_action(obj->print_error,obj->dev_id, used_button); wxString error_image_url = wxGetApp().get_hms_query()->query_print_error_url_action(obj->print_error, obj->dev_id, used_button);
// special case // special case
if (print_error_str == "0300 8003" || print_error_str == "0300 8002" || print_error_str == "0300 800A") 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); used_button.emplace_back(PrintErrorDialog::PrintErrorButton::JUMP_TO_LIVEVIEW);
if (!error_msg.IsEmpty()) {
wxDateTime now = wxDateTime::Now();
wxString show_time = now.Format("%Y-%m-%d %H:%M:%S");
error_msg = wxString::Format("%s\n[%s %s]",
error_msg,
print_error_str, show_time);
show_error_message(obj, error_msg, print_error_str,error_image_url,used_button);
} else {
BOOST_LOG_TRIVIAL(info) << "show print error! error_msg is empty, print error = " << obj->print_error;
} }
show_error_message(obj, is_errocode_exist, error_msg, print_error_str, error_image_url, used_button);
} }
} }
} }

View file

@ -527,7 +527,8 @@ protected:
void on_subtask_pause_resume(wxCommandEvent &event); void on_subtask_pause_resume(wxCommandEvent &event);
void on_subtask_abort(wxCommandEvent &event); void on_subtask_abort(wxCommandEvent &event);
void on_print_error_clean(wxCommandEvent &event); void on_print_error_clean(wxCommandEvent &event);
void show_error_message(MachineObject* obj, wxString msg, std::string print_error_str = "",wxString image_url="",std::vector<int> used_button=std::vector<int>()); void show_error_message(
MachineObject *obj, bool is_exist, wxString msg, std::string print_error_str = "", wxString image_url = "", std::vector<int> used_button = std::vector<int>());
void error_info_reset(); void error_info_reset();
void show_recenter_dialog(); void show_recenter_dialog();