FIX: the humidity display

jira: [STUDIO-10481]
Change-Id: Ib4bec6db6afbe40199c401c539b13a0e8459bbad
(cherry picked from commit 658a8ab7ef1d2149fee58b45ea9455bb188f82f0)
This commit is contained in:
xin.zhang
2025-02-18 10:53:09 +08:00
committed by Noisyfox
parent c9d5a3b482
commit 82480436e2
2 changed files with 91 additions and 64 deletions

View File

@@ -47,9 +47,11 @@ bool AMSinfo::parse_ams_info(MachineObject *obj, Ams *ams, bool remain_flag, boo
if (ams->type == 1 || ams->type == 3){ if (ams->type == 1 || ams->type == 3){
this->ams_humidity = ams->humidity; this->ams_humidity = ams->humidity;
this->humidity_raw = ams->humidity_raw;
} }
else{ else{
this->ams_humidity = -1; this->ams_humidity = -1;
this->humidity_raw = -1;
} }
this->ams_type = AMSModel(ams->type); this->ams_type = AMSModel(ams->type);
@@ -2752,18 +2754,13 @@ AMSHumidity::AMSHumidity() {}
AMSHumidity::AMSHumidity(wxWindow* parent, wxWindowID id, AMSinfo info, const wxPoint& pos, const wxSize& size) AMSHumidity::AMSHumidity(wxWindow* parent, wxWindowID id, AMSinfo info, const wxPoint& pos, const wxSize& size)
: AMSHumidity() : AMSHumidity()
{ {
m_amsinfo = info; for (int i = 1; i <= 5; i++) { ams_humidity_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_light", 16));}
// road type for (int i = 1; i <= 5; i++) { ams_humidity_dark_imgs.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 16));}
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) + "_light", 16));
}
for (int i = 1; i <= 5; i++) {
ams_humidity_img.push_back(ScalableBitmap(this, "hum_level" + std::to_string(i) + "_dark", 16));
}
ams_sun_img = ScalableBitmap(this, "ams_drying", 16); ams_sun_img = ScalableBitmap(this, "ams_drying", 16);
create(parent, id, pos, AMS_HUMIDITY_SIZE); create(parent, id, pos, wxDefaultSize);
Bind(wxEVT_PAINT, &AMSHumidity::paintEvent, this); Bind(wxEVT_PAINT, &AMSHumidity::paintEvent, this);
//wxWindow::SetBackgroundColour(AMS_CONTROL_DEF_HUMIDITY_BK_COLOUR); //wxWindow::SetBackgroundColour(AMS_CONTROL_DEF_HUMIDITY_BK_COLOUR);
@@ -2787,21 +2784,36 @@ AMSHumidity::AMSHumidity(wxWindow* parent, wxWindowID id, AMSinfo info, const wx
} }
} }
}); });
Update(info);
} }
void AMSHumidity::create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size) { void AMSHumidity::create(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size) {
wxWindow::Create(parent, id, pos, size); wxWindow::Create(parent, id, pos, size);
SetSize(size);
SetMinSize(size);
SetBackgroundColour(StateColor::darkModeColorFor(AMS_CONTROL_DEF_LIB_BK_COLOUR)); SetBackgroundColour(StateColor::darkModeColorFor(AMS_CONTROL_DEF_LIB_BK_COLOUR));
Refresh();
} }
void AMSHumidity::Update(AMSinfo amsinfo) void AMSHumidity::Update(AMSinfo amsinfo)
{ {
m_amsinfo = amsinfo; if (m_amsinfo != amsinfo)
Refresh(); {
m_amsinfo = amsinfo;
if (m_amsinfo.humidity_raw != -1)
{
SetSize(AMS_HUMIDITY_SIZE);
SetMinSize(AMS_HUMIDITY_SIZE);
SetMaxSize(AMS_HUMIDITY_SIZE);
}
else
{
SetSize(AMS_HUMIDITY_NO_PERCENT_SIZE);
SetMinSize(AMS_HUMIDITY_NO_PERCENT_SIZE);
SetMaxSize(AMS_HUMIDITY_NO_PERCENT_SIZE);
}
Refresh();
}
} }
@@ -2841,42 +2853,61 @@ void AMSHumidity::doRender(wxDC& dc)
// left mode // left mode
if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) { m_show_humidity = true; } if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) { m_show_humidity = true; }
else { m_show_humidity = false; } else { m_show_humidity = false; }
if (m_amsinfo.ams_humidity >= 1 && m_amsinfo.ams_humidity <= 5) {
if (m_show_humidity) {
//background //background
dc.SetPen(wxPen(*wxTRANSPARENT_PEN)); dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.SetBrush(wxBrush(StateColor::darkModeColorFor(AMS_CONTROL_DEF_BLOCK_BK_COLOUR))); dc.SetBrush(wxBrush(StateColor::darkModeColorFor(AMS_CONTROL_DEF_BLOCK_BK_COLOUR)));
dc.DrawRoundedRectangle(0, 0, (size.x), (size.y), (size.y / 2)); dc.DrawRoundedRectangle(0, 0, (size.x), (size.y), (size.y / 2));
//hum image wxPoint pot;
int hum_idx = m_amsinfo.ams_humidity - 1; if (m_amsinfo.humidity_raw != -1) /*image with no number + percentage*/
if (wxGetApp().dark_mode()) { {
hum_idx += 5; // hum image
} ScalableBitmap hum_img;
if (hum_idx >= ams_humidity_img.size() || hum_idx < 0){ if (!wxGetApp().dark_mode()) {
BOOST_LOG_TRIVIAL(trace) << "humidity error"; hum_img = ams_humidity_no_num_imgs[m_amsinfo.ams_humidity - 1];
} } else {
auto hum_img = ams_humidity_img[hum_idx]; hum_img = ams_humidity_no_num_dark_imgs[m_amsinfo.ams_humidity - 1];
auto pot = wxPoint(FromDIP(5), ((size.y - hum_img.GetBmpSize().y) / 2)); }
dc.DrawBitmap(hum_img.bmp(), pot);
//percentage pot = wxPoint(FromDIP(5), ((size.y - hum_img.GetBmpSize().y) / 2));
wxString hum_percentage = _L(std::to_string(20 * (5 - m_amsinfo.ams_humidity + 1))); dc.DrawBitmap(hum_img.bmp(), pot);
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)); // percentage
dc.SetFont(Label::Body_12); wxString hum_percentage(std::to_string(m_amsinfo.humidity_raw));
tsize = dc.GetMultiLineTextExtent(_L("%")); auto tsize = dc.GetMultiLineTextExtent(hum_percentage);
pot.y += (tsize.y / 2 - FromDIP(4)); dc.SetPen(wxPen(*wxTRANSPARENT_PEN));
dc.DrawText(_L("%"), pot); 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];
}
pot = wxPoint(FromDIP(5), ((size.y - hum_img.GetBmpSize().y) / 2));
dc.DrawBitmap(hum_img.bmp(), pot);
pot.x = pot.x + hum_img.GetBmpSize().x + FromDIP(3);
}
//vertical line //vertical line
pot.x = pot.x + tsize.x + FromDIP(2);
dc.SetPen(wxPen(wxColour(194, 194, 194))); dc.SetPen(wxPen(wxColour(194, 194, 194)));
dc.SetBrush(wxBrush(wxColour(194, 194, 194))); dc.SetBrush(wxBrush(wxColour(194, 194, 194)));
//dc.DrawLine(FromDIP(GetSize().x * 0.64), FromDIP(GetSize().y / 2 - 10), FromDIP(GetSize().x * 0.64), FromDIP(GetSize().y / 2 + 10)); //dc.DrawLine(FromDIP(GetSize().x * 0.64), FromDIP(GetSize().y / 2 - 10), FromDIP(GetSize().x * 0.64), FromDIP(GetSize().y / 2 + 10));
@@ -2897,15 +2928,11 @@ void AMSHumidity::doRender(wxDC& dc)
} }
void AMSHumidity::msw_rescale() { void AMSHumidity::msw_rescale() {
for (int i = 0; i < ams_humidity_img.size(); i++) { for (auto& img : ams_humidity_imgs) { img.msw_rescale();}
if (i < ams_humidity_img.size() / 2){ for (auto& img : ams_humidity_dark_imgs) { img.msw_rescale(); }
ams_humidity_img[i] = ScalableBitmap(this, "hum_level" + std::to_string(i + 1) + "_light", 16); for (auto &img : ams_humidity_no_num_imgs) { img.msw_rescale(); }
} for (auto &img : ams_humidity_no_num_dark_imgs) { img.msw_rescale(); }
else{ ams_sun_img.msw_rescale();
ams_humidity_img[i] = ScalableBitmap(this, "hum_level" + std::to_string((i - ams_humidity_img.size() / 2 + 1)) + "_dark", 16);
}
}
ams_sun_img = ScalableBitmap(this, "ams_drying", 16);
Layout(); Layout();
Refresh(); Refresh();
@@ -3184,18 +3211,10 @@ void AmsItem::Update(AMSinfo info)
m_info = info; m_info = info;
m_can_count = info.cans.size(); m_can_count = info.cans.size();
if (m_humidity)
// for (auto refresh_it : m_can_refresh_list) { {
// int i = 0; m_humidity->Update(m_info);
// AMSrefresh *refresh = refresh_it.second; }
// if (i < m_can_count) {
// refresh->Update(info.ams_id, info.cans[i]);
// refresh->Show();
// } else {
// refresh->Hide();
// }
// i++;
// }
for (int i = 0; i < m_can_count; i++) { for (int i = 0; i < m_can_count; i++) {
auto it = m_can_refresh_list.find(std::to_string(i)); auto it = m_can_refresh_list.find(std::to_string(i));
@@ -3228,6 +3247,7 @@ void AmsItem::Update(AMSinfo info)
/*m_panel_road->Update(m_info, info.cans[0]); /*m_panel_road->Update(m_info, info.cans[0]);
m_panel_road->Show();*/ m_panel_road->Show();*/
} }
Layout(); Layout();
} }

View File

@@ -161,6 +161,7 @@ enum FilamentStepType {
#define AMS_BODY_SIZE wxSize(FromDIP(36), FromDIP(55)) #define AMS_BODY_SIZE wxSize(FromDIP(36), FromDIP(55))
#define AMS_DOWN_ROAD_SIZE wxSize(FromDIP(568), FromDIP(10)) #define AMS_DOWN_ROAD_SIZE wxSize(FromDIP(568), FromDIP(10))
#define AMS_HUMIDITY_SIZE wxSize(FromDIP(93), FromDIP(26)) #define AMS_HUMIDITY_SIZE wxSize(FromDIP(93), FromDIP(26))
#define AMS_HUMIDITY_NO_PERCENT_SIZE wxSize(FromDIP(60), FromDIP(26))
#define AMS_PANEL_SIZE wxSize(FromDIP(264), FromDIP(150)) #define AMS_PANEL_SIZE wxSize(FromDIP(264), FromDIP(150))
#define GENERIC_AMS_SLOT_NUM 4 #define GENERIC_AMS_SLOT_NUM 4
@@ -213,6 +214,7 @@ public:
AMSAction current_action; AMSAction current_action;
int curreent_filamentstep; int curreent_filamentstep;
int ams_humidity = 0; int ams_humidity = 0;
int humidity_raw = -1;
AMSModel ams_type = AMSModel::GENERIC_AMS; AMSModel ams_type = AMSModel::GENERIC_AMS;
AMSModelOriginType ext_type = AMSModelOriginType::GENERIC_EXT; AMSModelOriginType ext_type = AMSModelOriginType::GENERIC_EXT;
@@ -711,7 +713,12 @@ public:
double m_radius = { 12 }; double m_radius = { 12 };
void Update(AMSinfo amsinfo); void Update(AMSinfo amsinfo);
std::vector<ScalableBitmap> ams_humidity_img; std::vector<ScalableBitmap> ams_humidity_imgs;
std::vector<ScalableBitmap> ams_humidity_dark_imgs;
std::vector<ScalableBitmap> ams_humidity_no_num_imgs;
std::vector<ScalableBitmap> ams_humidity_no_num_dark_imgs;
ScalableBitmap ams_sun_img; ScalableBitmap ams_sun_img;