From 8f143a176474521441ca5ddcb23610223d8c8db8 Mon Sep 17 00:00:00 2001 From: "xin.zhang" Date: Tue, 18 Feb 2025 10:53:09 +0800 Subject: [PATCH] FIX: the humidity display jira: [STUDIO-10481] Change-Id: Ib4bec6db6afbe40199c401c539b13a0e8459bbad (cherry picked from commit 658a8ab7ef1d2149fee58b45ea9455bb188f82f0) --- resources/images/hum_level1_no_num_dark.svg | 4 + resources/images/hum_level1_no_num_light.svg | 4 + resources/images/hum_level2_no_num_dark.svg | 4 + resources/images/hum_level2_no_num_light.svg | 4 + resources/images/hum_level3_no_num_dark.svg | 4 + resources/images/hum_level3_no_num_light.svg | 4 + resources/images/hum_level4_no_num_dark.svg | 4 + resources/images/hum_level4_no_num_light.svg | 4 + resources/images/hum_level5_no_num_dark.svg | 4 + resources/images/hum_level5_no_num_light.svg | 4 + src/slic3r/GUI/DeviceManager.cpp | 23 +++--- src/slic3r/GUI/DeviceManager.hpp | 2 +- src/slic3r/GUI/Widgets/AMSControl.cpp | 1 + src/slic3r/GUI/Widgets/AMSItem.cpp | 82 ++++++++++++++++---- src/slic3r/GUI/Widgets/AMSItem.hpp | 9 ++- 15 files changed, 126 insertions(+), 31 deletions(-) create mode 100644 resources/images/hum_level1_no_num_dark.svg create mode 100644 resources/images/hum_level1_no_num_light.svg create mode 100644 resources/images/hum_level2_no_num_dark.svg create mode 100644 resources/images/hum_level2_no_num_light.svg create mode 100644 resources/images/hum_level3_no_num_dark.svg create mode 100644 resources/images/hum_level3_no_num_light.svg create mode 100644 resources/images/hum_level4_no_num_dark.svg create mode 100644 resources/images/hum_level4_no_num_light.svg create mode 100644 resources/images/hum_level5_no_num_dark.svg create mode 100644 resources/images/hum_level5_no_num_light.svg diff --git a/resources/images/hum_level1_no_num_dark.svg b/resources/images/hum_level1_no_num_dark.svg new file mode 100644 index 0000000000..865a6c4a7f --- /dev/null +++ b/resources/images/hum_level1_no_num_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level1_no_num_light.svg b/resources/images/hum_level1_no_num_light.svg new file mode 100644 index 0000000000..be7c282e14 --- /dev/null +++ b/resources/images/hum_level1_no_num_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level2_no_num_dark.svg b/resources/images/hum_level2_no_num_dark.svg new file mode 100644 index 0000000000..9b47beef09 --- /dev/null +++ b/resources/images/hum_level2_no_num_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level2_no_num_light.svg b/resources/images/hum_level2_no_num_light.svg new file mode 100644 index 0000000000..b84791da26 --- /dev/null +++ b/resources/images/hum_level2_no_num_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level3_no_num_dark.svg b/resources/images/hum_level3_no_num_dark.svg new file mode 100644 index 0000000000..b5b08a1505 --- /dev/null +++ b/resources/images/hum_level3_no_num_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level3_no_num_light.svg b/resources/images/hum_level3_no_num_light.svg new file mode 100644 index 0000000000..e1fbd560f7 --- /dev/null +++ b/resources/images/hum_level3_no_num_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level4_no_num_dark.svg b/resources/images/hum_level4_no_num_dark.svg new file mode 100644 index 0000000000..980ada05d8 --- /dev/null +++ b/resources/images/hum_level4_no_num_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level4_no_num_light.svg b/resources/images/hum_level4_no_num_light.svg new file mode 100644 index 0000000000..4fb5bc7c61 --- /dev/null +++ b/resources/images/hum_level4_no_num_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level5_no_num_dark.svg b/resources/images/hum_level5_no_num_dark.svg new file mode 100644 index 0000000000..ab55eff332 --- /dev/null +++ b/resources/images/hum_level5_no_num_dark.svg @@ -0,0 +1,4 @@ + + + + diff --git a/resources/images/hum_level5_no_num_light.svg b/resources/images/hum_level5_no_num_light.svg new file mode 100644 index 0000000000..c96f344b07 --- /dev/null +++ b/resources/images/hum_level5_no_num_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 312fb087f8..0bb38f3dd0 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -590,7 +590,6 @@ MachineObject::MachineObject(NetworkAgent* agent, std::string name, std::string ams_insert_flag = false; ams_power_on_flag = false; ams_calibrate_remain_flag = false; - ams_humidity = 5; /* signals */ wifi_signal = ""; @@ -3961,16 +3960,6 @@ int MachineObject::parse_json(std::string payload, bool key_field_only) } if (jj["ams"].contains("ams_rfid_status")) ams_rfid_status = jj["ams"]["ams_rfid_status"].get(); - if (jj["ams"].contains("humidity")) { - if (jj["ams"]["humidity"].is_string()) { - std::string humidity_str = jj["ams"]["humidity"].get(); - try { - ams_humidity = atoi(humidity_str.c_str()); - } catch (...) { - ; - } - } - } if (jj["ams"].contains("insert_flag") || jj["ams"].contains("power_on_flag") || jj["ams"].contains("calibrate_remain_flag")) { @@ -4053,7 +4042,17 @@ int MachineObject::parse_json(std::string payload, bool key_field_only) ; } } - + + if (it->contains("humidity_raw")) + { + std::string humidity_raw = (*it)["humidity_raw"].get(); + + try { + curr_ams->humidity_raw = atoi(humidity_raw.c_str()); + } catch (...) { + ; + } + } if (it->contains("tray")) { std::set tray_id_set; diff --git a/src/slic3r/GUI/DeviceManager.hpp b/src/slic3r/GUI/DeviceManager.hpp index 4c5c671495..0d857d4783 100644 --- a/src/slic3r/GUI/DeviceManager.hpp +++ b/src/slic3r/GUI/DeviceManager.hpp @@ -274,6 +274,7 @@ public: } std::string id; int humidity = 5; + int humidity_raw = -1;// the percentage, -1 means invalid. eg. 100 means 100% bool startup_read_opt{true}; bool tray_read_opt{false}; bool is_exists{false}; @@ -538,7 +539,6 @@ public: bool ams_auto_switch_filament_flag { false }; bool ams_air_print_status { false }; bool ams_support_virtual_tray { true }; - int ams_humidity; int ams_user_setting_hold_count = 0; AmsStatusMain ams_status_main; int ams_status_sub; diff --git a/src/slic3r/GUI/Widgets/AMSControl.cpp b/src/slic3r/GUI/Widgets/AMSControl.cpp index 7b43f19aff..c535249ce2 100644 --- a/src/slic3r/GUI/Widgets/AMSControl.cpp +++ b/src/slic3r/GUI/Widgets/AMSControl.cpp @@ -782,6 +782,7 @@ void AMSControl::msw_rescale() m_button_guide->SetMinSize(wxSize(-1, FromDIP(24))); m_button_retry->SetMinSize(wxSize(-1, FromDIP(24))); m_vams_lib->msw_rescale(); + m_vams_road->msw_rescale(); for (auto i = 0; i < m_ams_cans_list.GetCount(); i++) { AmsCansWindow *cans = m_ams_cans_list[i]; diff --git a/src/slic3r/GUI/Widgets/AMSItem.cpp b/src/slic3r/GUI/Widgets/AMSItem.cpp index 05aec78445..617816932a 100644 --- a/src/slic3r/GUI/Widgets/AMSItem.cpp +++ b/src/slic3r/GUI/Widgets/AMSItem.cpp @@ -44,12 +44,14 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo if (humidity_flag) { this->ams_humidity = ams->humidity; } - else { + else{ this->ams_humidity = -1; } - + + this->humidity_raw = ams->humidity_raw; + cans.clear(); - for (int i = 0; i < 4; i++) { + for (int i = 0; i < ams->trayList.size(); i++) { auto it = ams->trayList.find(std::to_string(i)); Caninfo info; // tray is exists @@ -74,7 +76,7 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo } else { info.material_state = AMSCanType::AMS_CAN_TYPE_THIRDBRAND; } - + if (!MachineObject::is_bbl_filament(it->second->tag_uid) || !remain_flag) { info.material_remain = 100; } else { @@ -1402,13 +1404,11 @@ AMSRoad::AMSRoad(wxWindow *parent, wxWindowID id, Caninfo info, int canindex, in m_rode_mode = AMSRoadMode::AMS_ROAD_MODE_NONE_ANY_ROAD; } - for (int i = 1; i <= 5; i++) { - ams_humidity_img.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_light", 32)); - } + for (int i = 1; i <= 5; i++) { ams_humidity_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_light", 32));} + for (int i = 1; i <= 5; i++) { ams_humidity_dark_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 32));} + for (int i = 1; i <= 5; i++) { ams_humidity_no_num_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_no_num_light", 16)); } + for (int i = 1; i <= 5; i++) { ams_humidity_no_num_dark_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_no_num_dark", 16)); } - for (int i = 1; i <= 5; i++) { - ams_humidity_img.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 32)); - } if (m_rode_mode != AMSRoadMode::AMS_ROAD_MODE_VIRTUAL_TRAY) { create(parent, id, pos, size); } @@ -1588,15 +1588,52 @@ void AMSRoad::doRender(wxDC &dc) if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) {m_show_humidity = true;} else {m_show_humidity = false;} - if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) { + if (m_show_humidity) { + wxPoint pot; + if (m_amsinfo.humidity_raw != -1) /*image with no number + percentage*/ + { + // hum image + ScalableBitmap hum_img; + if (!wxGetApp().dark_mode()) { + hum_img = ams_humidity_no_num_imgs[m_amsinfo.ams_humidity - 1]; + } else { + hum_img = ams_humidity_no_num_dark_imgs[m_amsinfo.ams_humidity - 1]; + } - int hum_index = m_amsinfo.ams_humidity - 1; - if (wxGetApp().dark_mode()) { - hum_index += 5; + pot = wxPoint(FromDIP(5), size.y - hum_img.GetBmpSize().y - FromDIP(8)); + dc.DrawBitmap(hum_img.bmp(), pot); + + // percentage + wxString hum_percentage(std::to_string(m_amsinfo.humidity_raw)); + auto tsize = dc.GetMultiLineTextExtent(hum_percentage); + dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); + dc.SetFont(Label::Body_14); + dc.SetTextForeground(StateColor::darkModeColorFor(AMS_CONTROL_BLACK_COLOUR)); + // pot = wxPoint(FromDIP(size.x * 0.3), FromDIP((size.y - tsize.y) / 2)); + pot.x = pot.x + hum_img.GetBmpSize().x + FromDIP(3); + dc.DrawText(hum_percentage, pot); + + pot.x += (tsize.x + FromDIP(5)); + dc.SetFont(Label::Body_12); + tsize = dc.GetMultiLineTextExtent(_L("%")); + pot.y += (tsize.y / 2 - FromDIP(4)); + dc.DrawText(_L("%"), pot); + + pot.x = pot.x + tsize.x + FromDIP(2); } + else /*image with number*/ + { + // hum image + ScalableBitmap hum_img; + if (!wxGetApp().dark_mode()) { + hum_img = ams_humidity_imgs[m_amsinfo.ams_humidity - 1]; + } else { + hum_img = ams_humidity_dark_imgs[m_amsinfo.ams_humidity - 1]; + } - if (hum_index >= 0) { - dc.DrawBitmap(ams_humidity_img[hum_index].bmp(), wxPoint(size.x - FromDIP(33), size.y - FromDIP(33))); + pot = wxPoint(size.x - FromDIP(33), size.y - FromDIP(33)); + dc.DrawBitmap(hum_img.bmp(), pot); + pot.x = pot.x + hum_img.GetBmpSize().x + FromDIP(3); } } else { @@ -1658,6 +1695,14 @@ void AMSRoad::OnPassRoad(std::vector prord_list) } } +void AMSRoad::msw_rescale() +{ + for (auto& img : ams_humidity_imgs) { img.msw_rescale();} + for (auto& img : ams_humidity_dark_imgs) { img.msw_rescale(); } + for (auto &img : ams_humidity_no_num_imgs) { img.msw_rescale(); } + for (auto &img : ams_humidity_no_num_dark_imgs) { img.msw_rescale(); } +} + /************************************************* Description:AmsCan @@ -2191,6 +2236,11 @@ void AmsCans::msw_rescale() CanLibs* lib = m_can_lib_list[i]; lib->canLib->msw_rescale(); } + + for (auto i = 0; i < m_can_road_list.GetCount(); i++) { + CanRoads* road = m_can_road_list[i]; + road->canRoad->msw_rescale(); + } } void AmsCans::show_sn_value(bool show) diff --git a/src/slic3r/GUI/Widgets/AMSItem.hpp b/src/slic3r/GUI/Widgets/AMSItem.hpp index bdd13459d0..a089da690d 100644 --- a/src/slic3r/GUI/Widgets/AMSItem.hpp +++ b/src/slic3r/GUI/Widgets/AMSItem.hpp @@ -159,6 +159,7 @@ public: AMSAction current_action; int curreent_filamentstep; int ams_humidity = 0; + int humidity_raw = -1; bool parse_ams_info(MachineObject* obj, Ams *ams, bool remain_flag = false, bool humidity_flag = false); }; @@ -390,8 +391,11 @@ public: wxColour m_road_color; void Update(AMSinfo amsinfo, Caninfo info, int canindex, int maxcan); - std::vector ams_humidity_img; + std::vector ams_humidity_imgs; + std::vector ams_humidity_dark_imgs; + std::vector ams_humidity_no_num_imgs; + std::vector ams_humidity_no_num_dark_imgs; int m_humidity = { 0 }; bool m_show_humidity = { false }; @@ -406,7 +410,8 @@ public: void paintEvent(wxPaintEvent &evt); void render(wxDC &dc); - void doRender(wxDC &dc); + void doRender(wxDC& dc); + void msw_rescale(); }; /*************************************************