From 7de62693c711c20fa91610ae61954db41a5dd16c Mon Sep 17 00:00:00 2001 From: tao wang Date: Tue, 10 Jan 2023 15:48:54 +0800 Subject: [PATCH] ENH:enter access code with ip address when lan mode connect Change-Id: I987f953bad20d8ddea299226eb6f49a157fc7be4 --- src/slic3r/GUI/GUI_App.cpp | 30 +++++++++++---- src/slic3r/GUI/GUI_App.hpp | 2 +- src/slic3r/GUI/Jobs/SendJob.cpp | 1 + src/slic3r/GUI/MsgDialog.cpp | 64 ++++++++++++++++++++++++++++++-- src/slic3r/GUI/MsgDialog.hpp | 6 +++ src/slic3r/GUI/SendToPrinter.cpp | 2 + 6 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index a77227e83..eb04711cf 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4556,24 +4556,38 @@ void GUI_App::update_mode() plater()->canvas3D()->update_gizmos_on_off_state(); } -void GUI_App::show_ip_address_enter_dialog() +bool GUI_App::show_ip_address_enter_dialog() { DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); - if (!dev) return; - if (!dev->get_selected_machine()) return; + if (!dev) return false; + if (!dev->get_selected_machine()) return false; auto obj = dev->get_selected_machine(); InputIpAddressDialog dlg(nullptr, from_u8(dev->get_selected_machine()->dev_name)); dlg.Bind(EVT_ENTER_IP_ADDRESS, [this, obj](wxCommandEvent& e) { - auto ip_address = e.GetString(); + auto selection_data_arr = wxSplit(e.GetString().ToStdString(), '|'); + + if (selection_data_arr.size() != 2) return false; + + auto ip_address = selection_data_arr[0]; + auto access_code = selection_data_arr[1]; + BOOST_LOG_TRIVIAL(info) << "User enter IP address is " << ip_address; if (!ip_address.empty()) { wxGetApp().app_config->set_str("ip_address", obj->dev_id, ip_address.ToStdString()); wxGetApp().app_config->save(); - obj->dev_ip = ip_address.ToStdString(); - } - }); - dlg.ShowModal(); + obj->set_access_code(access_code.ToStdString()); + obj->dev_ip = ip_address.ToStdString(); + obj->access_code = access_code.ToStdString(); + } + return true; + }); + + if (dlg.ShowModal() == wxID_YES) { + return true; + } + + return false; } //void GUI_App::add_config_menu(wxMenuBar *menu) diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index d50ee42b4..021ddd780 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -437,7 +437,7 @@ public: ConfigOptionMode get_mode(); void save_mode(const /*ConfigOptionMode*/int mode) ; void update_mode(); - void show_ip_address_enter_dialog(); + bool show_ip_address_enter_dialog(); // BBS //void add_config_menu(wxMenuBar *menu); diff --git a/src/slic3r/GUI/Jobs/SendJob.cpp b/src/slic3r/GUI/Jobs/SendJob.cpp index 92c47de5b..1d10974b6 100644 --- a/src/slic3r/GUI/Jobs/SendJob.cpp +++ b/src/slic3r/GUI/Jobs/SendJob.cpp @@ -305,6 +305,7 @@ void SendJob::process() if (result == BAMBU_NETWORK_ERR_FTP_LOGIN_DENIED) { msg_text += ". "; msg_text += _L("Please log out and login to the printer again."); + m_enter_ip_address_fun(); } else { msg_text += wxString::Format("[%s]", error_text); diff --git a/src/slic3r/GUI/MsgDialog.cpp b/src/slic3r/GUI/MsgDialog.cpp index 596aed5bf..63eea6dac 100644 --- a/src/slic3r/GUI/MsgDialog.cpp +++ b/src/slic3r/GUI/MsgDialog.cpp @@ -436,7 +436,9 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent, wxString name) comfirm_before_enter_text = wxString::Format(_L("Cannot detect the LAN IP address of %s. Are %s and Bambu Studio in the same LAN?"), name, name); - comfirm_after_enter_text = _L("Please input the LAN IP address of your printer manually. You can find the IP address on device's screen, Settings > Network > IP."); + //comfirm_after_enter_text = _L("Please input the LAN IP address of your printer manually. You can find the IP address on device's screen, Settings > Network > IP."); + + comfirm_after_enter_text = _L("Failed to connect to the printer through LAN. Please enter the correct printer IP address and access code."); tip = new Label(this, comfirm_before_enter_text); @@ -445,11 +447,46 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent, wxString name) tip->SetMaxSize(wxSize(FromDIP(420), -1)); tip->Wrap(FromDIP(420)); + m_tips_ip = new Label(this, _L("IP")); m_input_ip = new TextInput(this, wxEmptyString, wxEmptyString); m_input_ip->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this); m_input_ip->SetMinSize(wxSize(FromDIP(420), FromDIP(28))); m_input_ip->SetMaxSize(wxSize(FromDIP(420), FromDIP(28))); + + m_tips_access_code = new Label(this, _L("Access Code")); + m_input_access_code = new TextInput(this, wxEmptyString, wxEmptyString); + m_input_access_code->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this); + m_input_access_code->SetMinSize(wxSize(FromDIP(420), FromDIP(28))); + m_input_access_code->SetMaxSize(wxSize(FromDIP(420), FromDIP(28))); + + m_tips_note1 = new Label(this, _L("Note : The location of IP and access code on the machine is as follows :")); + m_tips_note2 = new Label(this, _L("X1 General Settings - Network Settings in the side bar of X1 main screen")); + m_tips_note3 = new Label(this, _L("P1P General Settings - WLAN in the sidebar of the main screen")); + + m_tips_note1->SetFont(::Label::Body_12); + m_tips_note2->SetFont(::Label::Body_12); + m_tips_note3->SetFont(::Label::Body_12); + + m_tips_note1->SetForegroundColour(wxColour(0x898989)); + m_tips_note2->SetForegroundColour(wxColour(0x898989)); + m_tips_note3->SetForegroundColour(wxColour(0x898989)); + + m_tips_note1->SetMinSize(wxSize(FromDIP(400),-1)); + m_tips_note1->Wrap(FromDIP(400)); + + m_tips_note2->SetMinSize(wxSize(FromDIP(400), -1)); + m_tips_note2->Wrap(FromDIP(400)); + + m_tips_note3->SetMinSize(wxSize(FromDIP(400), -1)); + m_tips_note3->Wrap(FromDIP(400)); + + m_tips_ip->Hide(); m_input_ip->Hide(); + m_tips_access_code->Hide(); + m_input_access_code->Hide(); + m_tips_note1->Hide(); + m_tips_note2->Hide(); + m_tips_note3->Hide(); auto sizer_button = new wxBoxSizer(wxHORIZONTAL); @@ -491,10 +528,18 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent, wxString name) m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(15)); m_sizer_main->Add(tip, 1, wxLEFT|wxRIGHT|wxEXPAND, FromDIP(18)); m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); + m_sizer_main->Add(m_tips_ip, 0, wxLEFT, FromDIP(18)); m_sizer_main->Add(m_input_ip, 1, wxALIGN_CENTER, FromDIP(18)); m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(10)); + m_sizer_main->Add(m_tips_access_code, 0, wxLEFT, FromDIP(18)); + m_sizer_main->Add(m_input_access_code, 1, wxALIGN_CENTER, FromDIP(18)); + m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(10)); + m_sizer_main->Add(m_tips_note1, 0, wxALIGN_CENTER, FromDIP(5)); + m_sizer_main->Add(m_tips_note2, 0, wxALIGN_CENTER, FromDIP(2)); + m_sizer_main->Add(m_tips_note3, 0, wxALIGN_CENTER, FromDIP(2)); + m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(10)); m_sizer_main->Add(sizer_button, 1, wxLEFT|wxRIGHT|wxEXPAND, FromDIP(18)); - m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); + m_sizer_main->Add(0, 0, 0, wxTOP, FromDIP(5)); SetSizer(m_sizer_main); Layout(); m_sizer_main->Fit(this); @@ -527,7 +572,13 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt) tip->SetMaxSize(wxSize(FromDIP(420), -1)); tip->Wrap(FromDIP(420)); + m_tips_ip->Show(); m_input_ip->Show(); + m_tips_access_code->Show(); + m_input_access_code->Show(); + m_tips_note1->Show(); + m_tips_note2->Show(); + m_tips_note3->Show(); m_button_ok->Enable(false); m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90)); m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90)); @@ -536,8 +587,11 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt) } else { wxString ip = m_input_ip->GetTextCtrl()->GetValue(); + wxString str_access_code = m_input_access_code->GetTextCtrl()->GetValue(); + wxString input_str = wxString::Format("%s|%s",ip, str_access_code); + auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS); - event.SetString(ip); + event.SetString(input_str); event.SetEventObject(this); wxPostEvent(this, event); EndModal(wxID_YES); @@ -547,7 +601,9 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt) void InputIpAddressDialog::on_text(wxCommandEvent& evt) { auto str_ip = m_input_ip->GetTextCtrl()->GetValue(); - if (isIp(str_ip.ToStdString())) { + auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue(); + + if (isIp(str_ip.ToStdString()) && str_access_code.Length() == 8) { m_button_ok->Enable(true); StateColor btn_bg_green(std::pair(wxColour(27, 136, 68), StateColor::Pressed), std::pair(wxColour(61, 203, 115), StateColor::Hovered), std::pair(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); diff --git a/src/slic3r/GUI/MsgDialog.hpp b/src/slic3r/GUI/MsgDialog.hpp index 7f07cfbd6..ffe8383ef 100644 --- a/src/slic3r/GUI/MsgDialog.hpp +++ b/src/slic3r/GUI/MsgDialog.hpp @@ -382,7 +382,13 @@ public: ~InputIpAddressDialog(); Button* m_button_ok{nullptr}; + Label* m_tips_ip{nullptr}; + Label* m_tips_access_code{nullptr}; TextInput* m_input_ip{nullptr}; + TextInput* m_input_access_code{nullptr}; + Label* m_tips_note1{nullptr}; + Label* m_tips_note2{nullptr}; + Label* m_tips_note3{nullptr}; bool isIp(std::string ipstr); void on_ok(wxMouseEvent& evt); void on_text(wxCommandEvent& evt); diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index 351eb2868..e4eec885d 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -862,12 +862,14 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event) if (obj->dev_ip.empty()) { BOOST_LOG_TRIVIAL(info) << "MachineObject IP is empty "; std::string app_config_dev_ip = Slic3r::GUI::wxGetApp().app_config->get("ip_address", obj->dev_id); + std::string app_config_access_code = Slic3r::GUI::wxGetApp().app_config->get("access_code", obj->dev_id); if (app_config_dev_ip.empty()) { wxGetApp().show_ip_address_enter_dialog(); } else { obj->dev_ip = app_config_dev_ip; + obj->access_code = app_config_access_code; } }