ENH:optimized logic related to fan control

Change-Id: Ia67525bc75d4cc5be02eaf7131764fb0f9584f23
This commit is contained in:
tao wang 2023-02-01 15:25:47 +08:00 committed by Lane.Wei
parent 3e07db0c2a
commit 450f3e1c77
4 changed files with 42 additions and 19 deletions

View file

@ -176,8 +176,8 @@ void StatusBasePanel::init_bitmaps()
m_bitmap_axis_home = ScalableBitmap(this, "monitor_axis_home", 32);
m_bitmap_lamp_on = ScalableBitmap(this, "monitor_lamp_on", 24);
m_bitmap_lamp_off = ScalableBitmap(this, "monitor_lamp_off", 24);
m_bitmap_fan_on = ScalableBitmap(this, "monitor_fan_on", 24);
m_bitmap_fan_off = ScalableBitmap(this, "monitor_fan_off", 24);
m_bitmap_fan_on = ScalableBitmap(this, "monitor_fan_on", 22);
m_bitmap_fan_off = ScalableBitmap(this, "monitor_fan_off", 22);
m_bitmap_speed = ScalableBitmap(this, "monitor_speed", 24);
m_bitmap_speed_active = ScalableBitmap(this, "monitor_speed_active", 24);
m_bitmap_use_time = ScalableBitmap(this, "print_info_time", 16);
@ -2909,15 +2909,18 @@ void StatusPanel::on_printing_fan_switch(wxCommandEvent &event)
void StatusPanel::on_nozzle_fan_switch(wxCommandEvent &event)
{
m_fan_control_popup->Destroy();
m_fan_control_popup = nullptr;
m_fan_control_popup = new FanControlPopup(this);
if (obj) {
bool is_suppt_cham_fun = obj->is_function_supported(PrinterFunction::FUNC_CHAMBER_FAN);
m_fan_control_popup->update_show_mode(is_suppt_cham_fun);
}
auto pos = m_switch_nozzle_fan->GetScreenPosition();
pos.y = pos.y + m_switch_nozzle_fan->GetSize().y;
int display_idx = wxDisplay::GetFromWindow(this);
auto display = wxDisplay(display_idx).GetClientArea();

View file

@ -2,6 +2,7 @@
#include "Label.hpp"
#include "../BitmapCache.hpp"
#include "../I18N.hpp"
#include "../GUI_App.hpp"
#include <wx/simplebook.h>
#include <wx/dcgraph.h>
@ -542,20 +543,34 @@ FanControlPopup::FanControlPopup(wxWindow* parent)
Bind(wxEVT_LEFT_DOWN, &FanControlPopup::on_left_down, this);
#endif
Bind(wxEVT_SHOW, &FanControlPopup::on_show, this);
SetBackgroundColour(*wxWHITE);
}
void FanControlPopup::update_show_mode(bool support_cham_fun)
{
if (support_cham_fun && !m_is_suppt_cham_fun) {
m_cham_fan->Show();
m_line_bottom->Show();
Layout();
Fit();
}
if (!support_cham_fun && m_is_suppt_cham_fun) {
m_cham_fan->Hide();
m_line_bottom->Hide();
Layout();
Fit();
}
m_is_suppt_cham_fun = support_cham_fun;
}
void FanControlPopup::update_fan_data(MachineObject::FanType type, MachineObject* obj)
{
bool is_suppt_cham_fun = obj->is_function_supported(PrinterFunction::FUNC_CHAMBER_FAN);
if (is_suppt_cham_fun) {
m_cham_fan->Show();
m_line_bottom->Show();
}
else {
m_cham_fan->Hide();
m_line_bottom->Hide();
}
m_is_suppt_cham_fun = obj->is_function_supported(PrinterFunction::FUNC_CHAMBER_FAN);
update_show_mode(m_is_suppt_cham_fun);
if (type == MachineObject::FanType::COOLING_FAN && obj->cooling_fan_speed >= 0) {
m_part_fan->set_fan_speed(obj->cooling_fan_speed);
@ -576,9 +591,6 @@ void FanControlPopup::update_fan_data(MachineObject::FanType type, MachineObject
Bind(EVT_FAN_CHANGED, [this](wxCommandEvent& e) {
post_event(e.GetInt(), e.GetString());
});
Layout();
Fit();
}
void FanControlPopup::on_left_down(wxMouseEvent& evt)
@ -619,6 +631,11 @@ bool FanControlPopup::ProcessLeftDown(wxMouseEvent& event)
return wxPopupTransientWindow::ProcessLeftDown(event);
}
void FanControlPopup::on_show(wxShowEvent& evt)
{
wxGetApp().UpdateDarkUIWin(this);
}
void FanControlPopup::paintEvent(wxPaintEvent& evt)
{
wxPaintDC dc(this);

View file

@ -150,12 +150,15 @@ private:
FanControl* m_cham_fan;
wxWindow* m_line_top;
wxWindow* m_line_bottom;
bool m_is_suppt_cham_fun{true};
public:
void update_show_mode(bool support_cham_fun);
void update_fan_data(MachineObject::FanType type, MachineObject* obj);
void on_left_down(wxMouseEvent& evt);
void paintEvent(wxPaintEvent& evt);
void post_event(int fan_type, wxString speed);
void on_show(wxShowEvent& evt);
virtual void OnDismiss() wxOVERRIDE;
virtual bool ProcessLeftDown(wxMouseEvent& event) wxOVERRIDE;
};

View file

@ -312,7 +312,7 @@ void FanSwitchButton::render(wxDC& dc)
dc.SetTextForeground(text_color.colorForStates(states));
pt.x = (size.x - dc.GetTextExtent(speed).x) / 2;
pt.y -= FromDIP(5);
pt.y += FromDIP(1);
dc.DrawText(speed, pt);
}