2022-12-07 02:46:15 +00:00
# include "FanControl.hpp"
# include "Label.hpp"
# include "../BitmapCache.hpp"
# include "../I18N.hpp"
2023-02-01 07:25:47 +00:00
# include "../GUI_App.hpp"
2024-12-30 09:37:12 +00:00
# include "../MsgDialog.hpp"
2022-12-07 02:46:15 +00:00
# include <wx/simplebook.h>
# include <wx/dcgraph.h>
namespace Slic3r { namespace GUI {
wxDEFINE_EVENT ( EVT_FAN_SWITCH_ON , wxCommandEvent ) ;
wxDEFINE_EVENT ( EVT_FAN_SWITCH_OFF , wxCommandEvent ) ;
wxDEFINE_EVENT ( EVT_FAN_ADD , wxCommandEvent ) ;
wxDEFINE_EVENT ( EVT_FAN_DEC , wxCommandEvent ) ;
wxDEFINE_EVENT ( EVT_FAN_CHANGED , wxCommandEvent ) ;
2024-12-18 13:35:42 +00:00
constexpr int time_out = 10 ;
2024-12-06 07:23:28 +00:00
2022-12-07 02:46:15 +00:00
/*************************************************
Description : Fan
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Fan : : Fan ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size )
{
create ( parent , id , pos , size ) ;
}
void Fan : : create ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size )
{
m_current_speeds = 0 ;
wxWindow : : Create ( parent , id , pos , size , wxBORDER_NONE ) ;
SetBackgroundColour ( * wxWHITE ) ;
m_rotate_offsets . push_back ( RotateOffSet { 2.5 , wxPoint ( - FromDIP ( 16 ) , FromDIP ( 11 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 2.2 , wxPoint ( - FromDIP ( 20 ) , FromDIP ( 11 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 1.7 , wxPoint ( - FromDIP ( 24 ) , FromDIP ( 12 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 1.2 , wxPoint ( - FromDIP ( 22 ) , FromDIP ( 4 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 0.7 , wxPoint ( - FromDIP ( 17 ) , - FromDIP ( 6 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 0.3 , wxPoint ( - FromDIP ( 8 ) , - FromDIP ( 11 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 6.1 , wxPoint ( - FromDIP ( 0 ) , - FromDIP ( 9 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 5.5 , wxPoint ( - FromDIP ( 4 ) , - FromDIP ( 2 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 5.1 , wxPoint ( - FromDIP ( 3 ) , FromDIP ( 5 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 4.6 , wxPoint ( - FromDIP ( 3 ) , FromDIP ( 14 ) ) } ) ;
m_rotate_offsets . push_back ( RotateOffSet { 4.0 , wxPoint ( - FromDIP ( 2 ) , FromDIP ( 11 ) ) } ) ;
//auto m_bitmap_pointer = ScalableBitmap(this, "fan_pointer", FromDIP(25));
//m_img_pointer = m_bitmap_pointer.bmp().ConvertToImage();
2024-12-18 13:35:42 +00:00
m_bitmap_bk = ScalableBitmap ( this , " fan_dash_bk " , 80 ) ;
2022-12-07 02:46:15 +00:00
for ( auto i = 0 ; i < = 10 ; i + + ) {
2023-02-22 12:00:52 +00:00
# ifdef __APPLE__
2024-12-18 13:35:42 +00:00
auto m_bitmap_scale = ScalableBitmap ( this , wxString : : Format ( " fan_scale_%d " , i ) . ToStdString ( ) , 60 ) ;
2023-02-22 12:00:52 +00:00
m_bitmap_scales . push_back ( m_bitmap_scale ) ;
# else
2024-12-18 13:35:42 +00:00
auto m_bitmap_scale = ScalableBitmap ( this , wxString : : Format ( " fan_scale_%d " , i ) . ToStdString ( ) , 46 ) ;
2022-12-07 02:46:15 +00:00
m_bitmap_scales . push_back ( m_bitmap_scale ) ;
2023-02-22 12:00:52 +00:00
# endif
2022-12-07 02:46:15 +00:00
}
2023-02-22 12:00:52 +00:00
//#ifdef __APPLE__
// SetMinSize(wxSize(FromDIP(100), FromDIP(100) + FromDIP(6)));
// SetMaxSize(wxSize(FromDIP(100), FromDIP(100) + FromDIP(6)));
//#else
2022-12-07 02:46:15 +00:00
SetMinSize ( wxSize ( m_bitmap_bk . GetBmpSize ( ) . x , m_bitmap_bk . GetBmpSize ( ) . y + FromDIP ( 6 ) ) ) ;
SetMaxSize ( wxSize ( m_bitmap_bk . GetBmpSize ( ) . x , m_bitmap_bk . GetBmpSize ( ) . y + FromDIP ( 6 ) ) ) ;
2023-02-22 12:00:52 +00:00
//#endif // __APPLE__
2024-12-27 07:53:39 +00:00
2022-12-07 02:46:15 +00:00
Bind ( wxEVT_PAINT , & Fan : : paintEvent , this ) ;
}
void Fan : : set_fan_speeds ( int g )
{
m_current_speeds = g ;
Refresh ( ) ;
}
void Fan : : post_event ( wxCommandEvent & & event )
{
/*event.SetString(m_info.can_id);
event . SetEventObject ( m_parent ) ;
wxPostEvent ( m_parent , event ) ;
event . Skip ( ) ; */
}
void Fan : : paintEvent ( wxPaintEvent & evt )
{
wxPaintDC dc ( this ) ;
render ( dc ) ;
}
void Fan : : render ( wxDC & dc )
{
# ifdef __WXMSW__
wxSize size = GetSize ( ) ;
wxMemoryDC memdc ;
wxBitmap bmp ( size . x , size . y ) ;
memdc . SelectObject ( bmp ) ;
memdc . Blit ( { 0 , 0 } , size , & dc , { 0 , 0 } ) ;
{
wxGCDC dc2 ( memdc ) ;
doRender ( dc2 ) ;
}
memdc . SelectObject ( wxNullBitmap ) ;
dc . DrawBitmap ( bmp , 0 , 0 ) ;
# else
doRender ( dc ) ;
# endif
}
void Fan : : doRender ( wxDC & dc )
{
auto rpm = wxT ( " rpm " ) ;
wxSize size = GetSize ( ) ;
dc . DrawBitmap ( m_bitmap_bk . bmp ( ) , wxPoint ( 0 , 0 ) ) ;
//fan scale
/*auto central_point = wxPoint(size.x / 2, size.y / 2 + FromDIP(15));
dc . DrawBitmap ( m_bitmap_scale_0 . bmp ( ) , central_point . x - FromDIP ( 38 ) , central_point . y ) ;
dc . DrawBitmap ( m_bitmap_scale_1 . bmp ( ) , central_point . x - FromDIP ( 40 ) , central_point . y - FromDIP ( 17 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_2 . bmp ( ) , central_point . x - FromDIP ( 40 ) , central_point . y - FromDIP ( 36 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_3 . bmp ( ) , central_point . x - FromDIP ( 32 ) , central_point . y - FromDIP ( 48 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_4 . bmp ( ) , central_point . x - FromDIP ( 18 ) , central_point . y - FromDIP ( 53 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_5 . bmp ( ) , central_point . x - FromDIP ( 0 ) , central_point . y - FromDIP ( 53 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_6 . bmp ( ) , central_point . x + FromDIP ( 18 ) , central_point . y - FromDIP ( 48 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_7 . bmp ( ) , central_point . x + FromDIP ( 31 ) , central_point . y - FromDIP ( 36 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_8 . bmp ( ) , central_point . x + FromDIP ( 36 ) , central_point . y - FromDIP ( 17 ) ) ;
dc . DrawBitmap ( m_bitmap_scale_9 . bmp ( ) , central_point . x + FromDIP ( 28 ) , central_point . y ) ; */
//fan pointer
//auto pointer_central_point = wxPoint((size.x - m_img_pointer.GetSize().x) / 2, (size.y - m_img_pointer.GetSize().y) / 2);
//auto bmp = m_img_pointer.Rotate(m_rotate_offsets[m_current_speeds].rotate, wxPoint(size.x / 2,size.y / 2));
auto central_point = wxPoint ( ( size . x - m_bitmap_scales [ m_current_speeds ] . GetBmpSize ( ) . x ) / 2 , ( size . y - m_bitmap_scales [ m_current_speeds ] . GetBmpSize ( ) . y ) / 2 - FromDIP ( 4 ) ) ;
dc . DrawBitmap ( m_bitmap_scales [ m_current_speeds ] . bmp ( ) , central_point . x , central_point . y ) ;
//fan val
dc . SetTextForeground ( DRAW_TEXT_COLOUR ) ;
2022-12-14 01:43:42 +00:00
dc . SetFont ( : : Label : : Head_13 ) ;
2022-12-07 02:46:15 +00:00
auto speeds = wxString : : Format ( " %d%% " , m_current_speeds * 10 ) ;
2022-12-14 01:43:42 +00:00
dc . DrawText ( speeds , ( size . x - dc . GetTextExtent ( speeds ) . x ) / 2 + FromDIP ( 2 ) , size . y - dc . GetTextExtent ( speeds ) . y - FromDIP ( 5 ) ) ;
2022-12-07 02:46:15 +00:00
//rpm
2022-12-14 01:43:42 +00:00
//dc.SetFont(::Label::Body_13);
//dc.DrawText(rpm, (size.x - dc.GetTextExtent(rpm).x) / 2, size.y - dc.GetTextExtent(rpm).y);
2022-12-07 02:46:15 +00:00
}
2024-12-18 13:35:42 +00:00
void Fan : : msw_rescale ( )
{
2022-12-07 02:46:15 +00:00
m_bitmap_bk . msw_rescale ( ) ;
}
void Fan : : DoSetSize ( int x , int y , int width , int height , int sizeFlags )
{
wxWindow : : DoSetSize ( x , y , width , height , sizeFlags ) ;
}
/*************************************************
Description : FanOperate
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
FanOperate : : FanOperate ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size )
{
m_current_speeds = 0 ;
m_min_speeds = 1 ;
m_max_speeds = 10 ;
create ( parent , id , pos , size ) ;
2024-12-18 13:35:42 +00:00
wxGetApp ( ) . UpdateDarkUIWin ( this ) ;
2022-12-07 02:46:15 +00:00
}
void FanOperate : : create ( wxWindow * parent , wxWindowID id , const wxPoint & pos , const wxSize & size )
{
wxWindow : : Create ( parent , id , pos , size , wxBORDER_NONE ) ;
SetBackgroundColour ( * wxWHITE ) ;
2024-12-18 13:35:42 +00:00
m_bitmap_add = ScalableBitmap ( this , " fan_control_add " , 24 ) ;
m_bitmap_decrease = ScalableBitmap ( this , " fan_control_decrease " , 24 ) ;
2022-12-07 02:46:15 +00:00
SetMinSize ( wxSize ( FromDIP ( SIZE_OF_FAN_OPERATE . x ) , FromDIP ( SIZE_OF_FAN_OPERATE . y ) ) ) ;
Bind ( wxEVT_PAINT , & FanOperate : : paintEvent , this ) ;
Bind ( wxEVT_ENTER_WINDOW , [ this ] ( auto & e ) { SetCursor ( wxCURSOR_HAND ) ; } ) ;
Bind ( wxEVT_LEAVE_WINDOW , [ this ] ( auto & e ) { SetCursor ( wxCURSOR_ARROW ) ; } ) ;
Bind ( wxEVT_LEFT_DOWN , & FanOperate : : on_left_down , this ) ;
}
void FanOperate : : on_left_down ( wxMouseEvent & event )
{
2025-01-13 05:17:27 +00:00
auto mouse_pos = wxPoint ( 0 , 0 ) ;
# ifdef __APPLE__
mouse_pos = GetParent ( ) - > GetParent ( ) - > ClientToScreen ( event . GetPosition ( ) ) ;
# else
mouse_pos = ClientToScreen ( event . GetPosition ( ) ) ;
# endif // __APPLE__
2022-12-07 02:46:15 +00:00
auto win_pos = ClientToScreen ( wxPoint ( 0 , 0 ) ) ;
2024-12-06 07:23:28 +00:00
auto decrease_fir = FromDIP ( 24 ) ;
auto add_fir = GetSize ( ) . x - FromDIP ( 24 ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
if ( mouse_pos . x > win_pos . x & & mouse_pos . x < ( decrease_fir + win_pos . x ) & & mouse_pos . y > win_pos . y & & mouse_pos . y < ( win_pos . y + GetSize ( ) . y ) ) {
2022-12-07 02:46:15 +00:00
decrease_fan_speeds ( ) ;
return ;
}
2024-12-06 07:23:28 +00:00
if ( mouse_pos . x > ( add_fir + win_pos . x ) & & mouse_pos . x < ( win_pos . x + GetSize ( ) . x ) & & mouse_pos . y > win_pos . y & & mouse_pos . y < ( win_pos . y + GetSize ( ) . y ) ) {
2022-12-07 02:46:15 +00:00
add_fan_speeds ( ) ;
return ;
}
}
2024-12-30 09:37:12 +00:00
void FanOperate : : set_machine_obj ( MachineObject * obj )
{
m_obj = obj ;
}
2022-12-07 02:46:15 +00:00
void FanOperate : : set_fan_speeds ( int g )
{
m_current_speeds = g ;
Refresh ( ) ;
}
void FanOperate : : add_fan_speeds ( )
{
2024-12-30 09:37:12 +00:00
if ( m_obj & & m_obj - > is_in_printing ( ) ) {
MessageDialog msg_wingow ( nullptr , _L ( " Changed fan speed during pringing may affect print quality, please choose carefully. " ) , " " , wxICON_WARNING | wxCANCEL | wxOK ) ;
if ( msg_wingow . ShowModal ( ) = = wxID_CANCEL ) {
return ;
}
}
2022-12-07 02:46:15 +00:00
if ( m_current_speeds + 1 > m_max_speeds ) return ;
set_fan_speeds ( + + m_current_speeds ) ;
2024-12-27 07:53:39 +00:00
post_event ( wxCommandEvent ( EVT_FAN_ADD ) ) ;
post_event ( wxCommandEvent ( EVT_FAN_SWITCH_ON ) ) ;
2022-12-07 02:46:15 +00:00
}
void FanOperate : : decrease_fan_speeds ( )
{
2024-12-30 09:37:12 +00:00
if ( m_obj & & m_obj - > is_in_printing ( ) ) {
MessageDialog msg_wingow ( nullptr , _L ( " Changed fan speed during pringing may affect print quality, please choose carefully. " ) , " " , wxICON_WARNING | wxCANCEL | wxOK ) ;
if ( msg_wingow . ShowModal ( ) = = wxID_CANCEL ) {
return ;
}
}
2022-12-07 02:46:15 +00:00
//turn off
if ( m_current_speeds - 1 < m_min_speeds ) {
m_current_speeds = 0 ;
set_fan_speeds ( m_current_speeds ) ;
post_event ( wxCommandEvent ( EVT_FAN_SWITCH_OFF ) ) ;
}
else {
set_fan_speeds ( - - m_current_speeds ) ;
}
post_event ( wxCommandEvent ( EVT_FAN_DEC ) ) ;
2024-12-27 07:53:39 +00:00
2022-12-07 02:46:15 +00:00
}
void FanOperate : : post_event ( wxCommandEvent & & event )
{
event . SetInt ( m_current_speeds ) ;
event . SetEventObject ( this ) ;
wxPostEvent ( this , event ) ;
event . Skip ( ) ;
}
void FanOperate : : paintEvent ( wxPaintEvent & evt )
{
wxPaintDC dc ( this ) ;
render ( dc ) ;
}
void FanOperate : : render ( wxDC & dc )
{
# ifdef __WXMSW__
wxSize size = GetSize ( ) ;
wxMemoryDC memdc ;
wxBitmap bmp ( size . x , size . y ) ;
memdc . SelectObject ( bmp ) ;
memdc . Blit ( { 0 , 0 } , size , & dc , { 0 , 0 } ) ;
{
wxGCDC dc2 ( memdc ) ;
doRender ( dc2 ) ;
}
memdc . SelectObject ( wxNullBitmap ) ;
dc . DrawBitmap ( bmp , 0 , 0 ) ;
# else
doRender ( dc ) ;
# endif
}
void FanOperate : : doRender ( wxDC & dc )
{
wxSize size = GetSize ( ) ;
dc . SetPen ( wxPen ( DRAW_OPERATE_LINE_COLOUR ) ) ;
dc . SetBrush ( * wxTRANSPARENT_BRUSH ) ;
dc . DrawRoundedRectangle ( 0 , 0 , size . x , size . y , 5 ) ;
//splt
auto left_fir = size . x / 3 ;
2024-12-06 07:23:28 +00:00
dc . DrawBitmap ( m_bitmap_decrease . bmp ( ) , 0 , ( size . y - m_bitmap_decrease . GetBmpHeight ( ) ) / 2 ) ;
dc . DrawBitmap ( m_bitmap_add . bmp ( ) , size . x - m_bitmap_add . GetBmpWidth ( ) , ( size . y - m_bitmap_add . GetBmpSize ( ) . y ) / 2 ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
wxPoint pot ( m_bitmap_decrease . GetBmpWidth ( ) , ( size . y - m_bitmap_decrease . GetBmpHeight ( ) ) / 2 ) ;
dc . DrawLine ( pot . x , 0 , pot . x , size . y ) ;
dc . DrawLine ( size . x - m_bitmap_add . GetBmpWidth ( ) , 0 , size . x - m_bitmap_add . GetBmpWidth ( ) , size . y ) ;
2022-12-07 02:46:15 +00:00
//txt
dc . SetFont ( : : Label : : Body_12 ) ;
dc . SetTextForeground ( StateColor : : darkModeColorFor ( wxColour ( 0x898989 ) ) ) ;
2024-12-06 07:23:28 +00:00
wxString text = wxString : : Format ( " %d%% " , m_current_speeds * 10 ) ;
2022-12-07 02:46:15 +00:00
wxSize text_size = dc . GetTextExtent ( text ) ;
2024-12-06 07:23:28 +00:00
auto text_width = size . x - m_bitmap_decrease . GetBmpWidth ( ) * 2 ;
dc . DrawText ( text , wxPoint ( pot . x + ( text_width - text_size . x ) / 2 , ( size . y - text_size . y ) / 2 ) ) ;
2022-12-07 02:46:15 +00:00
}
void FanOperate : : msw_rescale ( ) {
}
2024-12-06 07:23:28 +00:00
static void nop_deleter_fan_control ( FanControlNew * ) { }
/*************************************************
Description : FanControlNew
2022-12-07 02:46:15 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2024-12-06 07:23:28 +00:00
FanControlNew : : FanControlNew ( wxWindow * parent , const AirDuctData & fan_data , int mode_id , int part_id , wxWindowID id , const wxPoint & pos , const wxSize & size )
: wxWindow ( parent , id , pos , size )
, m_fan_data ( fan_data )
, m_mode_id ( mode_id )
, m_part_id ( part_id )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
SetMaxSize ( wxSize ( FromDIP ( 180 ) , FromDIP ( 80 ) ) ) ;
SetMinSize ( wxSize ( FromDIP ( 180 ) , FromDIP ( 80 ) ) ) ;
auto m_bitmap_fan = new ScalableBitmap ( this , " fan_icon " , 20 ) ;
m_bitmap_toggle_off = new ScalableBitmap ( this , " toggle_off " , 16 ) ;
m_bitmap_toggle_on = new ScalableBitmap ( this , " toggle_on " , 16 ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
SetBackgroundColour ( wxColour ( 248 , 248 , 248 ) ) ;
2022-12-07 02:46:15 +00:00
wxBoxSizer * m_sizer_main = new wxBoxSizer ( wxHORIZONTAL ) ;
2024-12-06 07:23:28 +00:00
//m_sizer_main->Add(0, 0, 0, wxLEFT, FromDIP(18));
2022-12-07 02:46:15 +00:00
wxBoxSizer * sizer_control = new wxBoxSizer ( wxVERTICAL ) ;
wxBoxSizer * sizer_control_top = new wxBoxSizer ( wxHORIZONTAL ) ;
2024-12-06 07:23:28 +00:00
m_sizer_control_bottom = new wxBoxSizer ( wxVERTICAL ) ;
2022-12-07 02:46:15 +00:00
auto m_static_bitmap_fan = new wxStaticBitmap ( this , wxID_ANY , m_bitmap_fan - > bmp ( ) , wxDefaultPosition , wxDefaultSize ) ;
2024-12-06 07:23:28 +00:00
m_static_name = new wxStaticText ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxDefaultSize , wxST_ELLIPSIZE_END | wxALIGN_CENTER_HORIZONTAL ) ;
m_static_name - > SetBackgroundColour ( wxColour ( 248 , 248 , 248 ) ) ;
m_static_name - > SetFont ( Label : : Head_18 ) ;
m_static_name - > SetMinSize ( wxSize ( FromDIP ( 100 ) , - 1 ) ) ;
m_static_name - > SetMaxSize ( wxSize ( FromDIP ( 100 ) , - 1 ) ) ;
2022-12-07 02:46:15 +00:00
m_switch_button = new wxStaticBitmap ( this , wxID_ANY , m_bitmap_toggle_off - > bmp ( ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
m_switch_button - > Bind ( wxEVT_ENTER_WINDOW , [ this ] ( auto & e ) { SetCursor ( wxCURSOR_HAND ) ; } ) ;
m_switch_button - > Bind ( wxEVT_LEAVE_WINDOW , [ this ] ( auto & e ) { SetCursor ( wxCURSOR_RIGHT_ARROW ) ; } ) ;
2024-12-06 07:23:28 +00:00
m_switch_button - > Bind ( wxEVT_LEFT_DOWN , & FanControlNew : : on_swith_fan , this ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
sizer_control_top - > Add ( m_static_bitmap_fan , 0 , wxLEFT | wxTOP , FromDIP ( 8 ) ) ;
sizer_control_top - > Add ( m_static_name , 0 , wxLEFT | wxTOP , FromDIP ( 5 ) ) ;
sizer_control_top - > Add ( 0 , 0 , 1 , wxEXPAND , 0 ) ;
sizer_control_top - > Add ( m_switch_button , 0 , wxALIGN_RIGHT | wxRIGHT | wxTOP , FromDIP ( 10 ) ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
sizer_control - > Add ( sizer_control_top , 0 , wxEXPAND , 0 ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
m_static_status_name = new wxStaticText ( this , wxID_ANY , wxEmptyString , wxDefaultPosition , wxDefaultSize , wxST_ELLIPSIZE_END | wxALIGN_CENTER_HORIZONTAL ) ;
m_static_status_name - > SetForegroundColour ( wxColour ( 0x00AE42 ) ) ;
m_static_status_name - > SetBackgroundColour ( wxColour ( 248 , 248 , 248 ) ) ;
m_static_status_name - > SetFont ( Label : : Head_18 ) ;
m_static_status_name - > SetMinSize ( wxSize ( FromDIP ( 100 ) , - 1 ) ) ;
m_static_status_name - > SetMaxSize ( wxSize ( FromDIP ( 100 ) , - 1 ) ) ;
2022-12-07 02:46:15 +00:00
m_fan_operate = new FanOperate ( this , wxID_ANY , wxDefaultPosition , wxDefaultSize ) ;
2024-12-06 07:23:28 +00:00
m_fan_operate - > Bind ( EVT_FAN_SWITCH_ON , [ this ] ( const wxCommandEvent & e ) {
2022-12-07 02:46:15 +00:00
m_current_speed = e . GetInt ( ) ;
m_switch_button - > SetBitmap ( m_bitmap_toggle_on - > bmp ( ) ) ;
m_switch_fan = true ;
} ) ;
2024-12-06 07:23:28 +00:00
m_fan_operate - > Bind ( EVT_FAN_SWITCH_OFF , [ this ] ( const wxCommandEvent & e ) {
2022-12-07 02:46:15 +00:00
m_current_speed = e . GetInt ( ) ;
m_switch_button - > SetBitmap ( m_bitmap_toggle_off - > bmp ( ) ) ;
m_switch_fan = false ;
} ) ;
2024-12-06 07:23:28 +00:00
m_fan_operate - > Bind ( EVT_FAN_ADD , [ this ] ( const wxCommandEvent & e ) {
2022-12-07 02:46:15 +00:00
m_current_speed = e . GetInt ( ) ;
command_control_fan ( ) ;
} ) ;
2024-12-18 13:35:42 +00:00
m_fan_operate - > Bind ( EVT_FAN_DEC , [ this ] ( const wxCommandEvent & e ) {
m_current_speed = e . GetInt ( ) ;
command_control_fan ( ) ;
} ) ;
2024-12-06 07:23:28 +00:00
m_sizer_control_bottom - > Add ( m_static_status_name , 0 , wxALL , FromDIP ( 10 ) ) ;
m_sizer_control_bottom - > Add ( m_fan_operate , 0 , wxALL , FromDIP ( 10 ) ) ;
sizer_control - > Add ( m_sizer_control_bottom , 0 , wxALL , 0 ) ;
m_sizer_main - > Add ( sizer_control , 0 , wxALIGN_CENTER , 0 ) ;
update_mode ( ) ;
2025-01-13 05:17:27 +00:00
# if __APPLE__
Bind ( wxEVT_LEFT_DOWN , & FanControlNew : : on_left_down , this ) ;
# endif
2024-12-06 07:23:28 +00:00
this - > SetSizer ( m_sizer_main ) ;
this - > Layout ( ) ;
m_sizer_main - > Fit ( this ) ;
2024-12-18 13:35:42 +00:00
wxGetApp ( ) . UpdateDarkUIWin ( this ) ;
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : on_left_down ( wxMouseEvent & evt )
2022-12-07 02:46:15 +00:00
{
2025-01-13 05:17:27 +00:00
//auto mouse_pos = GetParent()->ClientToScreen(evt.GetPosition());
//auto tag_pos = m_fan_operate->ScreenToClient(mouse_pos);
//evt.SetPosition(tag_pos);
2022-12-07 02:46:15 +00:00
m_fan_operate - > on_left_down ( evt ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : command_control_fan ( )
2022-12-07 02:46:15 +00:00
{
if ( m_current_speed < 0 | | m_current_speed > 10 ) { return ; }
2024-12-06 07:23:28 +00:00
BOOST_LOG_TRIVIAL ( info ) < < " Functions Need to be supplemented! :FanControlNew::command_control_fan. the speed may change " ;
if ( m_obj ) {
if ( ! m_obj - > is_enable_np ) {
int speed = floor ( m_current_speed * float ( 25.5 ) ) ;
m_obj - > command_control_fan ( m_part_id , speed ) ;
} else {
2024-12-18 13:35:42 +00:00
m_obj - > command_control_fan_new ( m_part_id , m_current_speed * 10 , nullptr ) ;
2024-12-06 07:23:28 +00:00
}
2024-12-18 13:35:42 +00:00
post_event ( ) ;
2023-02-22 12:00:52 +00:00
}
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : on_swith_fan ( wxMouseEvent & evt )
2022-12-07 02:46:15 +00:00
{
2024-12-30 09:37:12 +00:00
if ( m_obj & & m_obj - > is_in_printing ( ) ) {
MessageDialog msg_wingow ( nullptr , _L ( " Changed fan speed during pringing may affect print quality, please choose carefully. " ) , " " , wxICON_WARNING | wxCANCEL | wxOK ) ;
if ( msg_wingow . ShowModal ( ) = = wxID_CANCEL ) {
return ;
}
}
2022-12-07 02:46:15 +00:00
int speed = 0 ;
if ( m_switch_fan ) {
m_switch_button - > SetBitmap ( m_bitmap_toggle_off - > bmp ( ) ) ;
m_switch_fan = false ;
}
else {
speed = 255 ;
m_switch_button - > SetBitmap ( m_bitmap_toggle_on - > bmp ( ) ) ;
m_switch_fan = true ;
2023-02-22 12:00:52 +00:00
}
2022-12-07 02:46:15 +00:00
set_fan_speed ( speed ) ;
command_control_fan ( ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : on_swith_fan ( bool on )
2022-12-07 02:46:15 +00:00
{
m_switch_fan = on ;
if ( m_switch_fan ) {
m_switch_button - > SetBitmap ( m_bitmap_toggle_on - > bmp ( ) ) ;
}
else {
m_switch_button - > SetBitmap ( m_bitmap_toggle_off - > bmp ( ) ) ;
}
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : update_mode ( )
{
int cur_mode = m_mode_id ;
if ( cur_mode < 0 ) {
m_static_status_name - > Hide ( ) ;
m_fan_operate - > Show ( ) ;
} else {
auto mode = m_fan_data . modes [ cur_mode ] ;
auto it = std : : find ( mode . off . begin ( ) , mode . off . end ( ) , m_part_id ) ;
if ( it ! = mode . off . end ( ) ) {
m_show_mode = 2 ;
m_static_status_name - > SetLabelText ( _L ( " Off " ) ) ;
} else {
auto it_ctrl = std : : find ( mode . ctrl . begin ( ) , mode . ctrl . end ( ) , m_part_id ) ;
if ( it_ctrl = = mode . ctrl . end ( ) ) {
m_show_mode = 1 ;
m_static_status_name - > SetLabelText ( _L ( " Auto " ) ) ;
} else {
m_show_mode = 0 ;
}
}
if ( m_show_mode = = 0 ) {
m_static_status_name - > Hide ( ) ;
m_switch_button - > Show ( ) ;
m_fan_operate - > Show ( ) ;
} else {
m_static_status_name - > Show ( ) ;
m_switch_button - > Hide ( ) ;
m_fan_operate - > Hide ( ) ;
}
}
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : set_machine_obj ( MachineObject * obj )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
m_update_already = true ;
m_obj = obj ;
2024-12-30 09:37:12 +00:00
if ( m_fan_operate )
m_fan_operate - > set_machine_obj ( obj ) ;
2022-12-07 02:46:15 +00:00
}
2024-12-18 13:35:42 +00:00
void FanControlNew : : set_name ( wxString name )
{
2022-12-07 02:46:15 +00:00
m_static_name - > SetLabelText ( name ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : set_fan_speed ( int g )
2022-12-07 02:46:15 +00:00
{
if ( g < 0 | | g > 255 ) return ;
2022-12-12 11:15:00 +00:00
int speed = round ( float ( g ) / float ( 25.5 ) ) ;
2022-12-07 02:46:15 +00:00
if ( m_current_speed ! = speed ) {
m_current_speed = speed ;
m_fan_operate - > set_fan_speeds ( m_current_speed ) ;
if ( m_current_speed < = 0 ) {
on_swith_fan ( false ) ;
}
else {
on_swith_fan ( true ) ;
}
}
}
2024-12-06 07:23:28 +00:00
void FanControlNew : : set_fan_speed_percent ( int speed )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
if ( m_current_speed ! = speed ) {
m_current_speed = speed ;
m_fan_operate - > set_fan_speeds ( m_current_speed ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
if ( m_current_speed < = 0 ) {
on_swith_fan ( false ) ;
} else {
on_swith_fan ( true ) ;
}
}
}
void FanControlNew : : set_fan_switch ( bool s )
{
2022-12-07 02:46:15 +00:00
}
2024-12-18 13:35:42 +00:00
void FanControlNew : : post_event ( )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
auto event = wxCommandEvent ( EVT_FAN_CHANGED ) ;
2022-12-07 02:46:15 +00:00
event . SetString ( wxString : : Format ( " %d " , m_current_speed ) ) ;
event . SetEventObject ( GetParent ( ) ) ;
wxPostEvent ( GetParent ( ) , event ) ;
event . Skip ( ) ;
}
/*************************************************
2024-12-06 07:23:28 +00:00
Description : FanControlPopupNew
2022-12-07 02:46:15 +00:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
2024-12-06 07:23:28 +00:00
static void nop_deleter_fan_control_popup ( FanControlPopupNew * ) { }
2025-01-12 09:43:22 +00:00
FanControlPopupNew : : FanControlPopupNew ( wxWindow * parent , MachineObject * obj , const AirDuctData & data )
: PopupWindow ( parent , wxBORDER_NONE )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
SetBackgroundColour ( * wxWHITE ) ;
init_names ( ) ;
m_data = data ;
m_obj = obj ;
2022-12-07 02:46:15 +00:00
m_sizer_main = new wxBoxSizer ( wxVERTICAL ) ;
2025-01-12 09:43:22 +00:00
int part_size = data . parts . size ( ) ;
int grid_column = part_size > 1 ? 2 : 1 ;
2024-12-18 13:35:42 +00:00
m_radio_btn_sizer = new wxGridSizer ( 0 , 2 , FromDIP ( 3 ) , FromDIP ( 3 ) ) ;
2025-01-12 09:43:22 +00:00
m_sizer_fanControl = new wxGridSizer ( 0 , grid_column , FromDIP ( 3 ) , FromDIP ( 10 ) ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
m_mode_sizer = new wxBoxSizer ( wxHORIZONTAL ) ;
2022-12-07 02:46:15 +00:00
2024-12-18 13:35:42 +00:00
m_button_refresh = new Button ( this , wxString ( " " ) , " fan_poppingup_refresh " , 0 , 24 ) ;
2024-12-06 07:23:28 +00:00
m_button_refresh - > SetBackgroundColor ( * wxWHITE ) ;
m_button_refresh - > SetBorderColor ( * wxWHITE ) ;
m_button_refresh - > SetMinSize ( wxSize ( FromDIP ( 26 ) , FromDIP ( 26 ) ) ) ;
m_button_refresh - > SetMaxSize ( wxSize ( FromDIP ( 26 ) , FromDIP ( 26 ) ) ) ;
2024-12-18 13:35:42 +00:00
m_button_refresh - > Bind ( wxEVT_ENTER_WINDOW , [ this ] ( const auto & e ) { SetCursor ( wxCURSOR_HAND ) ; } ) ;
m_button_refresh - > Bind ( wxEVT_LEAVE_WINDOW , [ this ] ( const auto & e ) { SetCursor ( wxCURSOR_ARROW ) ; } ) ;
m_button_refresh - > Bind ( wxEVT_LEFT_DOWN , [ this ] ( const auto & e ) {
CreateDuct ( ) ;
Layout ( ) ;
Fit ( ) ;
} ) ;
2024-12-06 07:23:28 +00:00
m_mode_sizer - > Add ( m_radio_btn_sizer , 0 , wxALIGN_CENTRE_VERTICAL , 0 ) ;
m_mode_sizer - > Add ( m_button_refresh , 0 , wxALIGN_CENTRE_VERTICAL , 0 ) ;
2024-12-30 09:37:12 +00:00
m_button_refresh - > Hide ( ) ;
2024-12-06 07:23:28 +00:00
m_cooling_text = new wxStaticText ( this , wxID_ANY , wxT ( " " ) ) ;
m_cooling_text - > SetBackgroundColour ( * wxWHITE ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
//Control the show or hide of controls based on id
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
m_sizer_main - > Add ( 0 , 0 , 0 , wxTOP , FromDIP ( 23 ) ) ;
m_sizer_main - > Add ( m_mode_sizer , 0 , wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT , FromDIP ( 30 ) ) ;
m_sizer_main - > Add ( 0 , 0 , 0 , wxTOP , FromDIP ( 10 ) ) ;
m_sizer_main - > Add ( m_cooling_text , 0 , wxLEFT | wxRIGHT , FromDIP ( 30 ) ) ;
m_sizer_main - > Add ( 0 , 0 , 0 , wxTOP , FromDIP ( 10 ) ) ;
m_sizer_main - > Add ( m_sizer_fanControl , 0 , wxALIGN_CENTER_HORIZONTAL | wxLEFT | wxRIGHT , 0 ) ;
m_sizer_main - > Add ( 0 , 0 , 0 , wxTOP , FromDIP ( 16 ) ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
CreateDuct ( ) ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
SetSizer ( m_sizer_main ) ;
Layout ( ) ;
Fit ( ) ;
2022-12-07 02:46:15 +00:00
this - > Centre ( wxBOTH ) ;
2024-12-06 07:23:28 +00:00
Bind ( wxEVT_PAINT , & FanControlPopupNew : : paintEvent , this ) ;
2022-12-07 02:46:15 +00:00
# if __APPLE__
2024-12-06 07:23:28 +00:00
Bind ( wxEVT_LEFT_DOWN , & FanControlPopupNew : : on_left_down , this ) ;
2022-12-07 02:46:15 +00:00
# endif
2023-02-22 12:00:52 +00:00
# ifdef __WXOSX__
Bind ( wxEVT_IDLE , [ ] ( wxIdleEvent & evt ) { } ) ;
# endif
2024-12-06 07:23:28 +00:00
Bind ( wxEVT_SHOW , & FanControlPopupNew : : on_show , this ) ;
Bind ( EVT_FAN_CHANGED , & FanControlPopupNew : : on_fan_changed , this ) ;
2022-12-07 02:46:15 +00:00
}
2024-12-18 13:35:42 +00:00
void FanControlPopupNew : : CreateDuct ( )
{
m_radio_btn_sizer - > Clear ( true ) ;
m_mode_switch_btn_list . clear ( ) ;
2024-12-06 07:23:28 +00:00
//tips
UpdateTips ( m_data . curren_mode ) ;
//fan or door
UpdateParts ( m_data . curren_mode ) ;
if ( m_data . modes . empty ( ) ) {
2024-12-30 09:37:12 +00:00
//m_button_refresh->Hide();
2024-12-06 07:23:28 +00:00
return ;
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
size_t mode_size = m_data . modes . size ( ) ;
for ( auto i = 0 ; i < mode_size ; i + + ) {
wxString text = wxString : : Format ( " %s " , radio_btn_name [ AIR_DUCT ( m_data . modes [ i ] . id ) ] ) ;
SendModeSwitchButton * radio_btn = new SendModeSwitchButton ( this , text , m_data . curren_mode = = m_data . modes [ i ] . id ) ;
2024-12-18 13:35:42 +00:00
radio_btn - > Bind ( wxEVT_LEFT_DOWN , & FanControlPopupNew : : on_mode_changed , this ) ;
2024-12-06 07:23:28 +00:00
m_mode_switch_btn_list . emplace_back ( radio_btn ) ;
m_radio_btn_sizer - > Add ( radio_btn , wxALL , FromDIP ( 5 ) ) ;
2022-12-07 02:46:15 +00:00
}
2023-02-01 07:25:47 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : UpdateParts ( int mode_id )
2023-08-14 11:46:43 +00:00
{
2024-12-06 07:23:28 +00:00
m_sizer_fanControl - > Clear ( true ) ;
for ( const auto & part : m_data . parts ) {
2024-12-18 13:35:42 +00:00
2024-12-06 07:23:28 +00:00
auto part_id = part . id ;
auto part_func = part . func ;
auto part_name = fan_func_name [ AIR_FUN ( part_id ) ] ;
auto part_state = part . state ;
2023-08-14 11:46:43 +00:00
2024-12-06 07:23:28 +00:00
auto fan_control = new FanControlNew ( this , m_data , mode_id , part_id , wxID_ANY , wxDefaultPosition , wxDefaultSize ) ;
fan_control - > set_machine_obj ( m_obj ) ;
fan_control - > set_name ( part_name ) ;
m_fan_control_list [ part_id ] = fan_control ;
m_sizer_fanControl - > Add ( fan_control , 0 , wxALL , FromDIP ( 5 ) ) ;
2023-08-14 11:46:43 +00:00
}
2024-12-06 07:23:28 +00:00
m_sizer_fanControl - > Layout ( ) ;
2023-08-14 11:46:43 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : UpdateTips ( int model )
{
auto text = label_text [ AIR_DUCT ( model ) ] ;
m_cooling_text - > SetLabelText ( text ) ;
2024-12-18 13:35:42 +00:00
m_cooling_text - > Wrap ( FromDIP ( 400 ) ) ;
2024-12-06 07:23:28 +00:00
Layout ( ) ;
}
2023-08-14 11:46:43 +00:00
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : update_fan_data ( MachineObject * obj )
2023-02-01 07:25:47 +00:00
{
2024-12-06 07:23:28 +00:00
if ( ! obj )
return ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
if ( obj - > is_enable_np ) {
2024-12-18 13:35:42 +00:00
if ( m_fan_set_time_out > 0 ) {
m_fan_set_time_out - - ;
2024-12-06 07:23:28 +00:00
return ;
}
update_fan_data ( obj - > m_air_duct_data ) ;
} else {
if ( m_fan_set_time_out > 0 ) {
m_fan_set_time_out - - ;
return ;
}
int cooling_fan_speed = round ( obj - > cooling_fan_speed / float ( 25.5 ) ) ;
int big_fan1_speed = round ( obj - > big_fan1_speed / float ( 25.5 ) ) ;
int big_fan2_speed = round ( obj - > big_fan2_speed / float ( 25.5 ) ) ;
update_fan_data ( AIR_FUN : : FAN_COOLING_0_AIRDOOR , cooling_fan_speed ) ;
update_fan_data ( AIR_FUN : : FAN_REMOTE_COOLING_0_IDX , big_fan1_speed ) ;
2024-12-18 13:35:42 +00:00
update_fan_data ( AIR_FUN : : FAN_CHAMBER_0_IDX , big_fan2_speed ) ;
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
}
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : update_fan_data ( const AirDuctData & data )
{
m_data = data ;
for ( const auto & part : m_data . parts ) {
auto part_id = part . id ;
auto part_func = part . func ;
auto part_name = fan_func_name [ AIR_FUN ( part_id ) ] ;
auto part_state = part . state ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
auto it = m_fan_control_list . find ( part_id ) ;
if ( it ! = m_fan_control_list . end ( ) ) {
auto fan_control = m_fan_control_list [ part_id ] ;
2024-12-18 13:35:42 +00:00
fan_control - > set_fan_speed_percent ( part_state / 10 ) ;
2024-12-06 07:23:28 +00:00
}
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
}
2022-12-07 02:46:15 +00:00
2024-12-18 13:35:42 +00:00
void FanControlPopupNew : : update_fan_data ( AIR_FUN id , int speed )
2024-12-06 07:23:28 +00:00
{
for ( auto & part : m_data . parts ) {
auto part_id = part . id ;
auto part_func = part . func ;
auto part_name = fan_func_name [ AIR_FUN ( part_id ) ] ;
2022-12-07 02:46:15 +00:00
2024-12-06 07:23:28 +00:00
if ( id = = part_id ) {
part . state = speed ;
auto it = m_fan_control_list . find ( part_id ) ;
if ( it ! = m_fan_control_list . end ( ) ) {
auto fan_control = m_fan_control_list [ part_id ] ;
fan_control - > update_mode ( ) ;
fan_control - > set_fan_speed_percent ( speed ) ;
}
}
}
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
// device change
void FanControlPopupNew : : update_device ( AirDuctData data , MachineObject * obj )
{
//for (int i = 0; i < data.airducts.size(); i++){
// auto duct = data.airducts[i];
// if (m_fan_control_list.find(duct.airduct_id) == m_fan_control_list.end())
// CreateDuct(duct);
// else{
// auto fan_list = m_fan_control_list[duct.airduct_id];
// for (auto fan : duct.fans_list){
// if (fan_list.find(fan.id) == fan_list.end())
// CreateFanAndDoor(duct.airduct_id, fan);
// else{
// auto fan_control = fan_list[fan.id];
// fan_control->update_fan_data(fan);
// }
// }
// }
// m_duct_ctrl[duct.airduct_id] = duct.fans_ctrl[i];
//}
//m_data = data;
//for (auto fan_list_of_duct : m_fan_control_list){
// for (auto fan : fan_list_of_duct.second){
// if (fan.second != nullptr)
// fan.second->set_machine_obj(obj);
// }
//}
////auto text = wxString::Format("%s", radio_btn_name[AIR_DUCT_mode_e(m_data.curren_duct)]);
//auto text = wxT("The fan controls the temperature during printing to improve print quality.The system automatically adjusts the fan's switch and speed according to dif");
//m_cooling_text->SetLabelText(text);
//m_cooling_text->Wrap(FromDIP(360));
//ChangeCoolingTips(m_data.airducts.size());
//if (data.airducts.size() <= 1)
// m_radio_btn_sizer->Show(false);
//else
// m_radio_btn_sizer->Show(true);
//this->Layout();
//Bind(EVT_FAN_CHANGED, [this](wxCommandEvent& e) {
// post_event(e.GetInt(), e.GetString());
// });
}
void FanControlPopupNew : : on_left_down ( wxMouseEvent & evt )
2022-12-07 02:46:15 +00:00
{
auto mouse_pos = ClientToScreen ( evt . GetPosition ( ) ) ;
2025-01-13 05:17:27 +00:00
for ( SendModeSwitchButton * sw_it : m_mode_switch_btn_list ) {
auto win_pos = sw_it - > ClientToScreen ( wxPoint ( 0 , 0 ) ) ;
auto size = sw_it - > GetSize ( ) ;
if ( mouse_pos . x > win_pos . x & & mouse_pos . x < ( win_pos . x + sw_it - > GetSize ( ) . x ) & & mouse_pos . y > win_pos . y & &
mouse_pos . y < ( win_pos . y + sw_it - > GetSize ( ) . y ) ) {
evt . SetId ( sw_it - > GetId ( ) ) ;
on_mode_changed ( evt ) ;
}
}
2024-12-06 07:23:28 +00:00
for ( auto fan_it : m_fan_control_list ) {
auto fan = fan_it . second ;
auto win_pos = fan - > m_switch_button - > ClientToScreen ( wxPoint ( 0 , 0 ) ) ;
auto size = fan - > m_switch_button - > GetSize ( ) ;
if ( mouse_pos . x > win_pos . x & & mouse_pos . x < ( win_pos . x + fan - > m_switch_button - > GetSize ( ) . x ) & & mouse_pos . y > win_pos . y & &
mouse_pos . y < ( win_pos . y + fan - > m_switch_button - > GetSize ( ) . y ) ) {
fan - > on_swith_fan ( evt ) ;
}
2025-01-13 05:17:27 +00:00
fan - > on_left_down ( evt ) ;
2024-12-06 07:23:28 +00:00
}
2022-12-07 02:46:15 +00:00
evt . Skip ( ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : OnDismiss ( )
2022-12-07 02:46:15 +00:00
{
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : post_event ( int fan_type , wxString speed )
2022-12-07 02:46:15 +00:00
{
2024-12-06 07:23:28 +00:00
// id, speed
wxCommandEvent event ( EVT_FAN_CHANGED ) ;
2022-12-07 02:46:15 +00:00
event . SetInt ( fan_type ) ;
event . SetString ( speed ) ;
event . SetEventObject ( GetParent ( ) ) ;
wxPostEvent ( GetParent ( ) , event ) ;
event . Skip ( ) ;
}
2024-12-06 07:23:28 +00:00
bool FanControlPopupNew : : ProcessLeftDown ( wxMouseEvent & event )
2022-12-07 02:46:15 +00:00
{
2023-02-13 06:06:39 +00:00
return PopupWindow : : ProcessLeftDown ( event ) ;
2022-12-07 02:46:15 +00:00
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : on_show ( wxShowEvent & evt )
2023-02-01 07:25:47 +00:00
{
wxGetApp ( ) . UpdateDarkUIWin ( this ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : command_control_air_duct ( int mode_id )
{
m_air_duct_time_out = time_out ;
token . reset ( this , nop_deleter_fan_control_popup ) ;
BOOST_LOG_TRIVIAL ( info ) < < __FUNCTION__ < < " , control air duct, id = " < < mode_id ;
if ( m_obj ) {
m_obj - > command_control_air_duct ( mode_id , [ this , w = std : : weak_ptr < FanControlPopupNew > ( token ) , mode_id ] ( const json & reply ) {
if ( w . expired ( ) )
return ;
m_air_duct_time_out = 0 ;
if ( reply . contains ( " errno " ) ) {
int result = reply [ " errno " ] . get < int > ( ) ;
BOOST_LOG_TRIVIAL ( info ) < < __FUNCTION__ < < " , control air duct, errno = " < < result ;
if ( result = = 0 ) {
int update_id = mode_id ;
if ( reply . contains ( " modeId " ) ) {
update_id = reply [ " modeId " ] . get < int > ( ) ;
this - > UpdateParts ( update_id ) ;
this - > UpdateTips ( update_id ) ;
}
}
this - > Layout ( ) ;
this - > Refresh ( ) ;
}
} ) ;
}
}
void FanControlPopupNew : : paintEvent ( wxPaintEvent & evt )
2022-12-07 02:46:15 +00:00
{
wxPaintDC dc ( this ) ;
dc . SetPen ( wxColour ( 0xAC , 0xAC , 0xAC ) ) ;
dc . SetBrush ( * wxTRANSPARENT_BRUSH ) ;
dc . DrawRoundedRectangle ( 0 , 0 , GetSize ( ) . x , GetSize ( ) . y , 0 ) ;
}
2024-12-06 07:23:28 +00:00
void FanControlPopupNew : : on_mode_changed ( const wxMouseEvent & event )
{
2024-12-30 09:37:12 +00:00
if ( m_obj & & m_obj - > is_in_printing ( ) ) {
MessageDialog msg_wingow ( nullptr , _L ( " The selected material only supports the current fan mode, and it can't be changed during printing. " ) , " " , wxICON_WARNING | wxOK ) ;
msg_wingow . ShowModal ( ) ;
return ;
}
2024-12-06 07:23:28 +00:00
size_t btn_list_size = m_mode_switch_btn_list . size ( ) ;
for ( size_t i = 0 ; i < btn_list_size ; + + i ) {
if ( m_mode_switch_btn_list [ i ] - > GetId ( ) = = event . GetId ( ) ) {
if ( m_mode_switch_btn_list [ i ] - > isSelected ( ) )
return ;
m_mode_switch_btn_list [ i ] - > setSelected ( true ) ;
command_control_air_duct ( i ) ;
} else {
m_mode_switch_btn_list [ i ] - > setSelected ( false ) ;
}
}
}
void FanControlPopupNew : : on_fan_changed ( const wxCommandEvent & event )
{
2024-12-18 13:35:42 +00:00
m_fan_set_time_out = time_out ;
2024-12-06 07:23:28 +00:00
}
void FanControlPopupNew : : init_names ( ) {
//Iint fan/door/func/duct name lists
2024-12-18 13:35:42 +00:00
radio_btn_name [ AIR_DUCT : : AIR_DUCT_COOLING_FILT ] = _L ( " Cooling " ) ;
2024-12-27 07:53:39 +00:00
radio_btn_name [ AIR_DUCT : : AIR_DUCT_HEATING_INTERNAL_FILT ] = _L ( " Heating " ) ;
radio_btn_name [ AIR_DUCT : : AIR_DUCT_EXHAUST ] = _L ( " Exhaust " ) ;
radio_btn_name [ AIR_DUCT : : AIR_DUCT_FULL_COOLING ] = _L ( " Full Cooling " ) ;
2024-12-06 07:23:28 +00:00
radio_btn_name [ AIR_DUCT : : AIR_DUCT_NUM ] = L ( " Num? " ) ;
radio_btn_name [ AIR_DUCT : : AIR_DUCT_INIT ] = L ( " Init " ) ;
2024-12-18 13:35:42 +00:00
fan_func_name [ AIR_FUN : : FAN_HEAT_BREAK_0_IDX ] = _L ( " Hotend " ) ;
2024-12-06 07:23:28 +00:00
fan_func_name [ AIR_FUN : : FAN_COOLING_0_AIRDOOR ] = _L ( " Part " ) ;
fan_func_name [ AIR_FUN : : FAN_REMOTE_COOLING_0_IDX ] = _L ( " Aux " ) ;
2024-12-18 13:35:42 +00:00
fan_func_name [ AIR_FUN : : FAN_CHAMBER_0_IDX ] = _L ( " Exhaust " ) ;
2024-12-06 07:23:28 +00:00
fan_func_name [ AIR_FUN : : FAN_HEAT_BREAK_1_IDX ] = _L ( " Nozzle1 " ) ;
fan_func_name [ AIR_FUN : : FAN_MC_BOARD_0_IDX ] = _L ( " MC Board " ) ;
2024-12-18 13:35:42 +00:00
fan_func_name [ AIR_FUN : : FAN_INNNER_LOOP_FAN_0_IDX ] = _L ( " Heat " ) ;
2024-12-06 07:23:28 +00:00
air_door_func_name [ AIR_DOOR : : AIR_DOOR_FUNC_CHAMBER ] = _L ( " Chamber " ) ;
air_door_func_name [ AIR_DOOR : : AIR_DOOR_FUNC_INNERLOOP ] = _L ( " Innerloop " ) ;
2025-01-03 01:42:53 +00:00
air_door_func_name [ AIR_DOOR : : AIR_DOOR_FUNC_TOP ] = L ( " Top " ) ; /*UNUSED*/
2024-12-06 07:23:28 +00:00
2024-12-27 07:53:39 +00:00
label_text [ AIR_DUCT : : AIR_DUCT_NONE ] = _L ( " The fan controls the temperature during printing to improve print quality. "
" The system automatically adjusts the fan's switch and speed "
" according to different printing materials. " ) ;
label_text [ AIR_DUCT : : AIR_DUCT_COOLING_FILT ] = _L ( " Cooling mode is suitable for printing PLA/PETG/TPU materials and filters the chamber air. " ) ;
label_text [ AIR_DUCT : : AIR_DUCT_HEATING_INTERNAL_FILT ] = _L ( " Heating mode is suitable for printeing ABS/ASA/PC/PA materials and circulates filters the chamber air. " ) ;
label_text [ AIR_DUCT : : AIR_DUCT_EXHAUST ] = _L ( " Exhaust " ) ;
label_text [ AIR_DUCT : : AIR_DUCT_FULL_COOLING ] = _L ( " Strong cooling mode is suitable for printing PLA/TPU materials. In this mode, the printouts will be fully cooled. " ) ;
2024-12-06 07:23:28 +00:00
label_text [ AIR_DUCT : : AIR_DUCT_NUM ] = _L ( " Num " ) ;
label_text [ AIR_DUCT : : AIR_DUCT_INIT ] = _L ( " Init " ) ;
/*label_text[AIR_DUCT_mode_e::AIR_DUCT_NONE] = "...";
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_COOLING_FILT ] = " ... " ;
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_HEATING_INTERNAL_FILT ] = " ... " ;
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_EXHAUST ] = " Exhaust " ;
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_FULL_COOLING ] = " ... " ;
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_NUM ] = " Num " ;
label_text [ AIR_DUCT_mode_e : : AIR_DUCT_INIT ] = " Init " ; */
}
2022-12-07 02:46:15 +00:00
} } // namespace Slic3r::GUI