2022-07-15 15:37:19 +00:00
# include "ConnectPrinter.hpp"
2022-11-04 03:28:05 +00:00
# include "GUI_App.hpp"
2022-07-15 15:37:19 +00:00
# include <slic3r/GUI/I18N.hpp>
# include <slic3r/GUI/Widgets/Label.hpp>
# include "libslic3r/AppConfig.hpp"
namespace Slic3r { namespace GUI {
ConnectPrinterDialog : : ConnectPrinterDialog ( wxWindow * parent , wxWindowID id , const wxString & title , const wxPoint & pos , const wxSize & size , long style )
: DPIDialog ( parent , id , _L ( " ConnectPrinter(LAN) " ) , pos , size , style )
{
2022-11-04 03:28:05 +00:00
SetBackgroundColour ( * wxWHITE ) ;
2022-07-15 15:37:19 +00:00
this - > SetSizeHints ( wxDefaultSize , wxDefaultSize ) ;
wxBoxSizer * main_sizer ;
main_sizer = new wxBoxSizer ( wxHORIZONTAL ) ;
main_sizer - > Add ( FromDIP ( 40 ) , 0 ) ;
wxBoxSizer * sizer_top ;
sizer_top = new wxBoxSizer ( wxVERTICAL ) ;
sizer_top - > Add ( 0 , FromDIP ( 40 ) ) ;
m_staticText_connection_code = new wxStaticText ( this , wxID_ANY , _L ( " Please input the printer access code: " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
m_staticText_connection_code - > SetFont ( Label : : Body_15 ) ;
m_staticText_connection_code - > SetForegroundColour ( wxColour ( 50 , 58 , 61 ) ) ;
m_staticText_connection_code - > Wrap ( - 1 ) ;
sizer_top - > Add ( m_staticText_connection_code , 0 , wxALL , 0 ) ;
sizer_top - > Add ( 0 , FromDIP ( 10 ) ) ;
wxBoxSizer * sizer_connect ;
sizer_connect = new wxBoxSizer ( wxHORIZONTAL ) ;
m_textCtrl_code = new TextInput ( this , wxEmptyString ) ;
2022-07-22 04:35:33 +00:00
m_textCtrl_code - > GetTextCtrl ( ) - > SetMaxLength ( 10 ) ;
2022-07-15 15:37:19 +00:00
m_textCtrl_code - > SetFont ( Label : : Body_14 ) ;
m_textCtrl_code - > SetCornerRadius ( FromDIP ( 5 ) ) ;
m_textCtrl_code - > SetSize ( wxSize ( FromDIP ( 330 ) , FromDIP ( 40 ) ) ) ;
m_textCtrl_code - > SetMinSize ( wxSize ( FromDIP ( 330 ) , FromDIP ( 40 ) ) ) ;
m_textCtrl_code - > GetTextCtrl ( ) - > SetSize ( wxSize ( - 1 , FromDIP ( 22 ) ) ) ;
m_textCtrl_code - > GetTextCtrl ( ) - > SetMinSize ( wxSize ( - 1 , FromDIP ( 22 ) ) ) ;
m_textCtrl_code - > SetBackgroundColour ( * wxWHITE ) ;
m_textCtrl_code - > GetTextCtrl ( ) - > SetForegroundColour ( wxColour ( 107 , 107 , 107 ) ) ;
sizer_connect - > Add ( m_textCtrl_code , 0 , wxALL | wxALIGN_CENTER_VERTICAL , 0 ) ;
sizer_connect - > Add ( FromDIP ( 20 ) , 0 ) ;
m_button_confirm = new Button ( this , _L ( " Confirm " ) ) ;
m_button_confirm - > SetFont ( Label : : Body_12 ) ;
m_button_confirm - > SetMinSize ( wxSize ( - 1 , FromDIP ( 24 ) ) ) ;
m_button_confirm - > SetCornerRadius ( FromDIP ( 12 ) ) ;
2022-11-04 03:28:05 +00:00
m_button_confirm - > SetTextColor ( wxColour ( " #FFFFFE " ) ) ;
2022-07-15 15:37:19 +00:00
StateColor btn_bg (
std : : pair < wxColour , int > ( wxColour ( 27 , 136 , 68 ) , StateColor : : Pressed ) ,
std : : pair < wxColour , int > ( wxColour ( 61 , 203 , 115 ) , StateColor : : Hovered ) ,
std : : pair < wxColour , int > ( wxColour ( 0 , 174 , 66 ) , StateColor : : Normal )
) ;
StateColor btn_bd ( std : : pair < wxColour , int > ( wxColour ( 0 , 174 , 66 ) , StateColor : : Normal ) ) ;
StateColor btn_text ( std : : pair < wxColour , int > ( wxColour ( 255 , 255 , 255 ) , StateColor : : Normal ) ) ;
m_button_confirm - > SetBackgroundColor ( btn_bg ) ;
m_button_confirm - > SetBorderColor ( btn_bd ) ;
m_button_confirm - > SetTextColor ( btn_text ) ;
sizer_connect - > Add ( m_button_confirm , 0 , wxALL | wxALIGN_CENTER_VERTICAL , 0 ) ;
sizer_connect - > Add ( FromDIP ( 60 ) , 0 ) ;
sizer_top - > Add ( sizer_connect ) ;
sizer_top - > Add ( 0 , FromDIP ( 35 ) ) ;
2025-01-08 12:28:17 +00:00
m_staticText_hints = new wxStaticText ( this , wxID_ANY , _L ( " You can find it in \" Settings > Network > Access code \" \n on the printer, as shown in the figure: " ) , wxDefaultPosition , wxDefaultSize , 0 ) ;
2022-07-15 15:37:19 +00:00
m_staticText_hints - > SetFont ( Label : : Body_15 ) ;
m_staticText_hints - > SetForegroundColour ( wxColour ( 50 , 58 , 61 ) ) ;
m_staticText_hints - > Wrap ( - 1 ) ;
sizer_top - > Add ( m_staticText_hints , 0 , wxALL , 0 ) ;
sizer_top - > Add ( 0 , FromDIP ( 25 ) ) ;
wxBoxSizer * sizer_diagram ;
sizer_diagram = new wxBoxSizer ( wxHORIZONTAL ) ;
2023-10-25 11:19:46 +00:00
m_bitmap_diagram = new wxStaticBitmap ( this , wxID_ANY , wxNullBitmap , wxDefaultPosition , wxSize ( FromDIP ( 340 ) , - 1 ) , 0 ) ;
2022-07-15 15:37:19 +00:00
m_bitmap_diagram - > SetBitmap ( m_diagram_img ) ;
sizer_diagram - > Add ( m_bitmap_diagram ) ;
sizer_top - > Add ( sizer_diagram ) ;
sizer_top - > Add ( 0 , FromDIP ( 40 ) , 0 , wxEXPAND , 0 ) ;
main_sizer - > Add ( sizer_top ) ;
this - > SetSizer ( main_sizer ) ;
this - > Layout ( ) ;
this - > Fit ( ) ;
2022-07-22 09:46:10 +00:00
CentreOnParent ( ) ;
2022-07-15 15:37:19 +00:00
m_textCtrl_code - > Bind ( wxEVT_TEXT , & ConnectPrinterDialog : : on_input_enter , this ) ;
m_button_confirm - > Bind ( wxEVT_BUTTON , & ConnectPrinterDialog : : on_button_confirm , this ) ;
2022-11-04 03:28:05 +00:00
wxGetApp ( ) . UpdateDlgDarkUI ( this ) ;
2022-07-15 15:37:19 +00:00
}
ConnectPrinterDialog : : ~ ConnectPrinterDialog ( ) { }
2022-11-29 08:20:15 +00:00
void ConnectPrinterDialog : : end_modal ( wxStandardID id )
{
EndModal ( id ) ;
}
2022-07-15 15:37:19 +00:00
void ConnectPrinterDialog : : init_bitmap ( )
{
AppConfig * config = get_app_config ( ) ;
std : : string language = config - > get ( " language " ) ;
2023-08-25 06:39:46 +00:00
if ( m_obj ) {
std : : string img_str = DeviceManager : : get_printer_diagram_img ( m_obj - > printer_type ) ;
if ( img_str . empty ( ) ) { img_str = " input_access_code_x1 " ; }
if ( language = = " zh_CN " ) {
m_diagram_bmp = create_scaled_bitmap ( img_str + " _cn " , nullptr , 190 ) ;
}
else {
m_diagram_bmp = create_scaled_bitmap ( img_str + " _en " , nullptr , 190 ) ;
}
2025-01-08 12:28:17 +00:00
// traverse the guide text
{
// traverse the guide text
if ( m_obj - > printer_type = = " O1D " )
{
m_staticText_hints - > SetLabel ( _L ( " You can find it in \" Setting > Setting > LAN only > Access Code \" \n on the printer, as shown in the figure: " ) ) ;
}
else
{
m_staticText_hints - > SetLabel ( _L ( " You can find it in \" Settings > Network > Access code \" \n on the printer, as shown in the figure: " ) ) ;
}
}
2022-07-15 15:37:19 +00:00
}
else {
2023-08-25 06:39:46 +00:00
if ( language = = " zh_CN " ) {
m_diagram_bmp = create_scaled_bitmap ( " input_access_code_x1_cn " , nullptr , 190 ) ;
}
else {
m_diagram_bmp = create_scaled_bitmap ( " input_access_code_x1_en " , nullptr , 190 ) ;
}
2022-07-15 15:37:19 +00:00
}
m_diagram_img = m_diagram_bmp . ConvertToImage ( ) ;
2023-10-25 11:19:46 +00:00
auto bmp_size = m_diagram_bmp . GetSize ( ) ;
float scale = ( float ) FromDIP ( 340 ) / ( float ) bmp_size . x ;
m_diagram_img . Rescale ( FromDIP ( 340 ) , bmp_size . y * scale ) ;
m_bitmap_diagram - > SetBitmap ( m_diagram_img ) ;
Fit ( ) ;
2022-07-15 15:37:19 +00:00
}
void ConnectPrinterDialog : : set_machine_object ( MachineObject * obj )
{
m_obj = obj ;
2023-10-25 11:19:46 +00:00
init_bitmap ( ) ;
2022-07-15 15:37:19 +00:00
}
void ConnectPrinterDialog : : on_input_enter ( wxCommandEvent & evt )
{
m_input_access_code = evt . GetString ( ) ;
}
void ConnectPrinterDialog : : on_button_confirm ( wxCommandEvent & event )
{
wxString code = m_textCtrl_code - > GetTextCtrl ( ) - > GetValue ( ) ;
2022-07-22 04:35:33 +00:00
for ( char c : code ) {
if ( ! ( ' 0 ' < = c & & c < = ' 9 ' | | ' a ' < = c & & c < = ' z ' | | ' A ' < = c & & c < = ' Z ' ) ) {
show_error ( this , _L ( " Invalid input. " ) ) ;
return ;
}
}
2022-07-15 15:37:19 +00:00
if ( m_obj ) {
2023-02-02 08:41:56 +00:00
m_obj - > set_user_access_code ( code . ToStdString ( ) ) ;
2023-05-22 07:07:33 +00:00
if ( m_need_connect ) {
wxGetApp ( ) . getDeviceManager ( ) - > set_selected_machine ( m_obj - > dev_id ) ;
}
2022-07-15 15:37:19 +00:00
}
EndModal ( wxID_OK ) ;
}
void ConnectPrinterDialog : : on_dpi_changed ( const wxRect & suggested_rect )
{
init_bitmap ( ) ;
m_bitmap_diagram - > SetBitmap ( m_diagram_img ) ;
m_textCtrl_code - > GetTextCtrl ( ) - > SetSize ( wxSize ( - 1 , FromDIP ( 22 ) ) ) ;
m_textCtrl_code - > GetTextCtrl ( ) - > SetMinSize ( wxSize ( - 1 , FromDIP ( 22 ) ) ) ;
m_button_confirm - > SetCornerRadius ( FromDIP ( 12 ) ) ;
m_button_confirm - > Rescale ( ) ;
Layout ( ) ;
this - > Refresh ( ) ;
}
} } // namespace Slic3r::GUI