From 6e1e56be181b7b3d0787a857d9c78dae7ce68899 Mon Sep 17 00:00:00 2001 From: "liz.li" Date: Thu, 11 Aug 2022 19:01:56 +0800 Subject: [PATCH] NEW: refine HMS Panel link to hms wiki page Change-Id: I1b1c5b2021f9f68320235ce17580ae80ea9b82a3 Signed-off-by: Stone Li --- resources/images/hms_arrow.svg | 3 + resources/images/hms_notify_lv1.svg | 4 + resources/images/hms_notify_lv2.svg | 4 + resources/images/hms_notify_lv3.svg | 5 + src/slic3r/GUI/HMS.cpp | 7 +- src/slic3r/GUI/HMS.hpp | 2 +- src/slic3r/GUI/HMSPanel.cpp | 142 ++++++++++++++++++++++++++-- src/slic3r/GUI/HMSPanel.hpp | 36 ++++++- 8 files changed, 184 insertions(+), 19 deletions(-) create mode 100644 resources/images/hms_arrow.svg create mode 100644 resources/images/hms_notify_lv1.svg create mode 100644 resources/images/hms_notify_lv2.svg create mode 100644 resources/images/hms_notify_lv3.svg diff --git a/resources/images/hms_arrow.svg b/resources/images/hms_arrow.svg new file mode 100644 index 000000000..5cebec400 --- /dev/null +++ b/resources/images/hms_arrow.svg @@ -0,0 +1,3 @@ + + + diff --git a/resources/images/hms_notify_lv1.svg b/resources/images/hms_notify_lv1.svg new file mode 100644 index 000000000..3c030c381 --- /dev/null +++ b/resources/images/hms_notify_lv1.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hms_notify_lv2.svg b/resources/images/hms_notify_lv2.svg new file mode 100644 index 000000000..bc02fb1a8 --- /dev/null +++ b/resources/images/hms_notify_lv2.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hms_notify_lv3.svg b/resources/images/hms_notify_lv3.svg new file mode 100644 index 000000000..fd127ed27 --- /dev/null +++ b/resources/images/hms_notify_lv3.svg @@ -0,0 +1,5 @@ + + + + + diff --git a/src/slic3r/GUI/HMS.cpp b/src/slic3r/GUI/HMS.cpp index 7942c497b..203b2d321 100644 --- a/src/slic3r/GUI/HMS.cpp +++ b/src/slic3r/GUI/HMS.cpp @@ -214,17 +214,14 @@ int HMSQuery::check_hms_info() return result; } -std::string get_hms_wiki_url(int code) +std::string get_hms_wiki_url(std::string error_code) { AppConfig* config = wxGetApp().app_config; if (!config) return ""; - char buf[32]; - ::sprintf(buf, "%08X", code); - std::string error_code = std::string(buf); std::string hms_host = wxGetApp().app_config->get_hms_host(); std::string lang_code = wxGetApp().app_config->get_language_code(); - std::string url = (boost::format("https://%1%/index.php?e=%2%&s=hms&lang=%3%") + std::string url = (boost::format("https://%1%/index.php?e=%2%&s=device_hms&lang=%3%") % hms_host % error_code % lang_code).str(); diff --git a/src/slic3r/GUI/HMS.hpp b/src/slic3r/GUI/HMS.hpp index 28198992a..fd45a2c3a 100644 --- a/src/slic3r/GUI/HMS.hpp +++ b/src/slic3r/GUI/HMS.hpp @@ -34,7 +34,7 @@ public: int get_hms_info_version(std::string &version); -std::string get_hms_wiki_url(int code); +std::string get_hms_wiki_url(std::string code); std::string get_error_message(int error_code); diff --git a/src/slic3r/GUI/HMSPanel.cpp b/src/slic3r/GUI/HMSPanel.cpp index e57a4ad93..45a3c7a68 100644 --- a/src/slic3r/GUI/HMSPanel.cpp +++ b/src/slic3r/GUI/HMSPanel.cpp @@ -1,3 +1,4 @@ +#include "HMS.hpp" #include "HMSPanel.hpp" #include #include @@ -7,6 +8,117 @@ namespace Slic3r { namespace GUI { +#define HMS_NOTIFY_ITEM_TEXT_SIZE wxSize(FromDIP(730), -1) +#define HMS_NOTIFY_ITEM_SIZE wxSize(-1, FromDIP(80)) + +HMSNotifyItem::HMSNotifyItem(wxWindow *parent, HMSItem& item) + : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL) + , m_hms_item(item) + , m_url(get_hms_wiki_url(item.get_long_error_code())) +{ + init_bitmaps(); + + this->SetBackgroundColour(*wxWHITE); + + auto main_sizer = new wxBoxSizer(wxVERTICAL); + + m_panel_hms = new wxPanel(this, wxID_ANY, wxDefaultPosition, HMS_NOTIFY_ITEM_SIZE, wxTAB_TRAVERSAL); + auto m_panel_sizer = new wxBoxSizer(wxVERTICAL); + + auto m_panel_sizer_inner = new wxBoxSizer(wxHORIZONTAL); + + m_bitmap_notify = new wxStaticBitmap(m_panel_hms, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + m_bitmap_notify->SetBitmap(get_notify_bitmap()); + + m_hms_content = new wxStaticText(m_panel_hms, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxST_ELLIPSIZE_END); + m_hms_content->SetSize(HMS_NOTIFY_ITEM_TEXT_SIZE); + m_hms_content->SetMinSize(HMS_NOTIFY_ITEM_TEXT_SIZE); + m_hms_content->SetLabelText(_L(wxGetApp().get_hms_query()->query_hms_msg(m_hms_item.get_long_error_code()))); + m_hms_content->Wrap(HMS_NOTIFY_ITEM_TEXT_SIZE.GetX()); + + m_bitmap_arrow = new wxStaticBitmap(m_panel_hms, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0); + if (!m_url.empty()) + m_bitmap_arrow->SetBitmap(m_img_arrow); + + m_panel_sizer_inner->Add(m_bitmap_notify, 0, wxALIGN_CENTER_VERTICAL, 0); + m_panel_sizer_inner->AddSpacer(FromDIP(8)); + m_panel_sizer_inner->Add(m_hms_content, 0, wxALIGN_CENTER_VERTICAL, 0); + m_panel_sizer_inner->AddStretchSpacer(); + m_panel_sizer_inner->Add(m_bitmap_arrow, 0, wxALIGN_CENTER_VERTICAL, 0); + + m_panel_sizer->Add(m_panel_sizer_inner, 1, wxEXPAND | wxALL, FromDIP(20)); + + m_staticline = new wxPanel(m_panel_hms, wxID_DELETE, wxDefaultPosition, wxSize(-1, FromDIP(1))); + m_staticline->SetBackgroundColour(wxColour(238, 238, 238)); + + m_panel_sizer->Add(m_staticline, 0, wxLEFT | wxRIGHT | wxEXPAND, FromDIP(20)); + + m_panel_hms->SetSizer(m_panel_sizer); + m_panel_hms->Layout(); + m_panel_sizer->Fit(m_panel_hms); + + main_sizer->Add(m_panel_hms, 0, wxEXPAND, 0); + + this->SetSizer(main_sizer); + this->Layout(); + + m_hms_content->Bind(wxEVT_ENTER_WINDOW, [this](wxMouseEvent &e) { + e.Skip(); + if (!m_url.empty()) { + auto font = m_hms_content->GetFont(); + font.SetUnderlined(true); + m_hms_content->SetFont(font); + Layout(); + SetCursor(wxCURSOR_HAND); + } + }); + m_hms_content->Bind(wxEVT_LEAVE_WINDOW, [this](wxMouseEvent &e) { + e.Skip(); + if (!m_url.empty()) { + auto font = m_hms_content->GetFont(); + font.SetUnderlined(false); + m_hms_content->SetFont(font); + Layout(); + SetCursor(wxCURSOR_ARROW); + } + }); + m_hms_content->Bind(wxEVT_LEFT_UP, [this](wxMouseEvent &e) { + if(!m_url.empty()) + wxLaunchDefaultBrowser(get_hms_wiki_url(m_hms_item.get_long_error_code())); + }); +} +HMSNotifyItem ::~HMSNotifyItem() { + ; +} + +void HMSNotifyItem::init_bitmaps() { + m_img_notify_lv1 = create_scaled_bitmap("hms_notify_lv1", nullptr, 18); + m_img_notify_lv2 = create_scaled_bitmap("hms_notify_lv2", nullptr, 18); + m_img_notify_lv3 = create_scaled_bitmap("hms_notify_lv3", nullptr, 18); + m_img_arrow = create_scaled_bitmap("hms_arrow", nullptr, 14); +} + +wxBitmap & HMSNotifyItem::get_notify_bitmap() +{ + switch (m_hms_item.msg_level) { + case (HMS_FATAL): + return m_img_notify_lv1; + break; + case (HMS_SERIOUS): + return m_img_notify_lv2; + break; + case (HMS_COMMON): + return m_img_notify_lv3; + break; + case (HMS_INFO): + //return m_img_notify_lv4; + break; + case (HMS_UNKNOWN): + case (HMS_MSG_LEVEL_MAX): + default: break; + } + return wxNullBitmap; +} HMSPanel::HMSPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, long style) :wxPanel(parent, id, pos, size, style) @@ -20,9 +132,7 @@ HMSPanel::HMSPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wx m_top_sizer = new wxBoxSizer(wxVERTICAL); - m_hms_content = new wxTextCtrl(m_scrolledWindow, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_AUTO_URL | wxTE_MULTILINE); - - m_top_sizer->Add(m_hms_content, 1, wxALL | wxEXPAND, 0); + m_top_sizer->AddSpacer(FromDIP(30)); m_scrolledWindow->SetSizerAndFit(m_top_sizer); @@ -30,7 +140,6 @@ HMSPanel::HMSPanel(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wx this->SetSizerAndFit(m_main_sizer); - Layout(); } @@ -38,17 +147,31 @@ HMSPanel::~HMSPanel() { ; } +void HMSPanel::append_hms_panel(HMSItem& item) { + m_notify_item = new HMSNotifyItem(m_scrolledWindow, item); + m_top_sizer->Add(m_notify_item, 0, wxALIGN_CENTER_HORIZONTAL); +} + +void HMSPanel::delete_hms_panels() { + m_scrolledWindow->DestroyChildren(); +} + void HMSPanel::update(MachineObject *obj) { if (obj) { + this->Freeze(); + delete_hms_panels(); wxString hms_text; for (auto item : obj->hms_list) { - if (wxGetApp().get_hms_query()) - hms_text += wxGetApp().get_hms_query()->query_hms_msg(item.get_long_error_code()) + "\n"; + if (wxGetApp().get_hms_query()) { + append_hms_panel(item); + } } - m_hms_content->SetLabelText(hms_text); + Layout(); + this->Thaw(); } else { - m_hms_content->SetLabelText(""); + delete_hms_panels(); + Layout(); } } @@ -57,5 +180,4 @@ bool HMSPanel::Show(bool show) return wxPanel::Show(show); } -} -} \ No newline at end of file +}} \ No newline at end of file diff --git a/src/slic3r/GUI/HMSPanel.hpp b/src/slic3r/GUI/HMSPanel.hpp index 6761c2df9..e50e22cbe 100644 --- a/src/slic3r/GUI/HMSPanel.hpp +++ b/src/slic3r/GUI/HMSPanel.hpp @@ -6,17 +6,47 @@ #include #include #include +#include namespace Slic3r { namespace GUI { +class HMSNotifyItem : public wxPanel +{ + HMSItem & m_hms_item; + std::string m_url; + + wxPanel * m_panel_hms; + wxStaticBitmap *m_bitmap_notify; + wxStaticBitmap *m_bitmap_arrow; + wxStaticText * m_hms_content; + wxHtmlWindow * m_html; + wxPanel * m_staticline; + + wxBitmap m_img_notify_lv1; + wxBitmap m_img_notify_lv2; + wxBitmap m_img_notify_lv3; + wxBitmap m_img_arrow; + + void init_bitmaps(); + wxBitmap & get_notify_bitmap(); + +public: + HMSNotifyItem(wxWindow *parent, HMSItem& item); + ~HMSNotifyItem(); + + void msw_rescale() {} +}; class HMSPanel : public wxPanel { protected: - wxScrolledWindow* m_scrolledWindow; - wxBoxSizer* m_top_sizer; - wxTextCtrl* m_hms_content; + wxScrolledWindow *m_scrolledWindow; + wxBoxSizer * m_top_sizer; + HMSNotifyItem * m_notify_item; + + void append_hms_panel(HMSItem &item); + void delete_hms_panels(); public: HMSPanel(wxWindow *parent, wxWindowID id = wxID_ANY, const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxTAB_TRAVERSAL);