NEW: refine HMS Panel

link to hms wiki page

Change-Id: I1b1c5b2021f9f68320235ce17580ae80ea9b82a3
Signed-off-by: Stone Li <stone.li@bambulab.com>
This commit is contained in:
liz.li 2022-08-11 19:01:56 +08:00 committed by Lane.Wei
parent 6a065401d1
commit 6e1e56be18
8 changed files with 184 additions and 19 deletions

View File

@ -0,0 +1,3 @@
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M5 12L8.50024 7.6247C8.79242 7.25948 8.79204 6.74005 8.49986 6.37483C7.23348 4.79185 6.38744 3.73431 5 2" stroke="#909090" stroke-linecap="round"/>
</svg>

After

Width:  |  Height:  |  Size: 260 B

View File

@ -0,0 +1,4 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.422 11.116L8.24 3.374H9.486L9.304 11.116H8.422ZM8.87 14.154C8.65533 14.154 8.46867 14.0747 8.31 13.916C8.16067 13.7573 8.086 13.5707 8.086 13.356C8.086 13.132 8.16067 12.9407 8.31 12.782C8.46867 12.6233 8.65533 12.544 8.87 12.544C9.094 12.544 9.28067 12.6233 9.43 12.782C9.58867 12.9407 9.668 13.132 9.668 13.356C9.668 13.5707 9.58867 13.7573 9.43 13.916C9.28067 14.0747 9.094 14.154 8.87 14.154Z" fill="#352F2D"/>
<path d="M9 15.5C5.41015 15.5 2.5 12.5899 2.5 9C2.5 5.41015 5.41015 2.5 9 2.5C12.5899 2.5 15.5 5.41015 15.5 9C15.5 12.5899 12.5899 15.5 9 15.5ZM9 17C13.4183 17 17 13.4183 17 9C17 4.58172 13.4183 1 9 1C4.58172 1 1 4.58172 1 9C1 13.4183 4.58172 17 9 17Z" fill="#D01B1B"/>
</svg>

After

Width:  |  Height:  |  Size: 800 B

View File

@ -0,0 +1,4 @@
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M8.94694 4L16.0264 16.2619H1.86752L8.94694 4ZM9.81297 2.5C9.42807 1.83333 8.46581 1.83333 8.08091 2.5L0.135466 16.2619C-0.249434 16.9286 0.231692 17.7619 1.00149 17.7619H16.8924C17.6622 17.7619 18.1433 16.9286 17.7584 16.2619L9.81297 2.5Z" fill="#FF6F00"/>
<path d="M8.54394 13.1747L8.36194 5.43271H9.60794L9.42594 13.1747H8.54394ZM8.99194 16.2127C8.77727 16.2127 8.5906 16.1334 8.43194 15.9747C8.2826 15.816 8.20794 15.6294 8.20794 15.4147C8.20794 15.1907 8.2826 14.9994 8.43194 14.8407C8.5906 14.682 8.77727 14.6027 8.99194 14.6027C9.21594 14.6027 9.4026 14.682 9.55194 14.8407C9.7106 14.9994 9.78994 15.1907 9.78994 15.4147C9.78994 15.6294 9.7106 15.816 9.55194 15.9747C9.4026 16.1334 9.21594 16.2127 8.99194 16.2127Z" fill="#352F2D"/>
</svg>

After

Width:  |  Height:  |  Size: 851 B

View File

@ -0,0 +1,5 @@
<svg width="18" height="17" viewBox="0 0 18 17" fill="none" xmlns="http://www.w3.org/2000/svg">
<path fill-rule="evenodd" clip-rule="evenodd" d="M9.44686 0.760658C9.44688 0.760632 9.44705 0.761358 9.44734 0.762916L9.44686 0.760658ZM9.45702 1.30902V16.0838L4.34788 12.5881C4.34553 12.5865 4.34262 12.5844 4.33918 12.582C4.30441 12.5576 4.21551 12.4952 4.10842 12.4621C4.00133 12.429 3.89274 12.4303 3.85027 12.4308C3.84606 12.4308 3.84251 12.4308 3.83966 12.4308H1.00002V5.46331H3.82577C3.8289 5.46331 3.83283 5.46336 3.83747 5.46342C3.88445 5.46403 4.00502 5.46559 4.12235 5.42522C4.23969 5.38484 4.33377 5.30941 4.37042 5.28003C4.37405 5.27712 4.37711 5.27466 4.37958 5.27274L9.45702 1.30902ZM9.44803 16.588C9.44801 16.588 9.44814 16.5873 9.44846 16.5859L9.44803 16.588ZM9.39368 0.114326C9.51273 0.0465355 9.77431 -0.0762185 10.064 0.0651441C10.3537 0.206507 10.4179 0.488235 10.4377 0.623795C10.4572 0.756805 10.4571 0.923 10.457 1.07685C10.457 1.08598 10.457 1.09506 10.457 1.1041V16.2734C10.457 16.2821 10.457 16.2908 10.457 16.2996C10.4571 16.4426 10.4572 16.6005 10.4383 16.7283C10.4183 16.8637 10.355 17.1285 10.0836 17.2717C9.81219 17.4149 9.55782 17.3175 9.4348 17.2576C9.31872 17.201 9.18841 17.1118 9.07049 17.031C9.06321 17.026 9.05598 17.0211 9.0488 17.0161L3.80873 13.4308H0.900021C0.894467 13.4308 0.888767 13.4308 0.882937 13.4309C0.804643 13.4309 0.702846 13.431 0.613943 13.4191C0.504036 13.4043 0.342721 13.3635 0.205047 13.2258C0.0673729 13.0881 0.026579 12.9268 0.0118024 12.8169C-0.000150123 12.728 -5.89874e-05 12.6262 1.10481e-05 12.5479C1.62933e-05 12.5421 2.14193e-05 12.5364 2.14193e-05 12.5308V5.36331C2.14193e-05 5.35775 1.62933e-05 5.35205 1.10481e-05 5.34622C-5.89874e-05 5.26793 -0.000150123 5.16613 0.0118023 5.07723C0.0265789 4.96732 0.0673727 4.80601 0.205047 4.66833C0.34272 4.53066 0.504036 4.48987 0.613943 4.47509C0.702844 4.46314 0.804638 4.46323 0.882931 4.4633C0.888763 4.4633 0.894465 4.46331 0.900021 4.46331H3.79136L9.0032 0.394668C9.01032 0.389111 9.01748 0.383519 9.02467 0.3779C9.1459 0.283171 9.27686 0.180843 9.39368 0.114326Z" fill="#00AE42"/>
<path d="M15.2496 13.7943C15.4847 14.0294 15.868 14.0308 16.0833 13.7776C16.586 13.1865 16.9941 12.5196 17.2919 11.8004C17.6667 10.8956 17.8596 9.92583 17.8596 8.94645C17.8596 7.96707 17.6667 6.99728 17.2919 6.09245C16.9941 5.37334 16.586 4.70645 16.0833 4.11535C15.868 3.86206 15.4847 3.86353 15.2496 4.09863C15.0145 4.33373 15.0171 4.71321 15.2285 4.96982C15.6214 5.44677 15.9422 5.98022 16.1796 6.55321C16.4939 7.31196 16.6556 8.12518 16.6556 8.94645C16.6556 9.76772 16.4939 10.5809 16.1796 11.3397C15.9422 11.9127 15.6214 12.4461 15.2285 12.9231C15.0171 13.1797 15.0145 13.5592 15.2496 13.7943Z" fill="#00AE42"/>
<path d="M13.0987 11.6438C13.3356 11.8807 13.7235 11.8828 13.9258 11.6158C14.1529 11.3159 14.3413 10.9876 14.4859 10.6386C14.708 10.1022 14.8224 9.5274 14.8224 8.94688C14.8224 8.36637 14.708 7.79153 14.4859 7.25521C14.3413 6.90616 14.1529 6.57787 13.9258 6.27801C13.7235 6.01096 13.3356 6.0131 13.0987 6.24998C12.8618 6.48685 12.8676 6.86849 13.0557 7.14567C13.1778 7.3255 13.2815 7.51769 13.3651 7.71945C13.5263 8.10859 13.6092 8.52568 13.6092 8.94688C13.6092 9.36809 13.5263 9.78517 13.3651 10.1743C13.2815 10.3761 13.1778 10.5683 13.0557 10.7481C12.8676 11.0253 12.8618 11.4069 13.0987 11.6438Z" fill="#00AE42"/>
</svg>

After

Width:  |  Height:  |  Size: 3.3 KiB

View File

@ -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();

View File

@ -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);

View File

@ -1,3 +1,4 @@
#include "HMS.hpp"
#include "HMSPanel.hpp"
#include <slic3r/GUI/Widgets/Label.hpp>
#include <slic3r/GUI/I18N.hpp>
@ -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);
}
}
}
}}

View File

@ -6,17 +6,47 @@
#include <slic3r/GUI/Widgets/Button.hpp>
#include <slic3r/GUI/DeviceManager.hpp>
#include <slic3r/GUI/Widgets/ScrolledWindow.hpp>
#include <wx/html/htmlwin.h>
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);