From 809b38ef67a5d83bf1a7a8819ea3280ff6091d3e Mon Sep 17 00:00:00 2001 From: tao wang Date: Mon, 9 Jan 2023 12:43:53 +0800 Subject: [PATCH] ENH:change to generic ip address enter dialog Change-Id: I4d3b4f091e435d600216ef8ec44d04ca7c90a26d (cherry picked from commit 5796a72a567ee1a2b3dee7508832d9e0d6348820) --- src/slic3r/GUI/GUI_App.cpp | 20 ++++++++++++++++ src/slic3r/GUI/GUI_App.hpp | 1 + src/slic3r/GUI/SendToPrinter.cpp | 39 ++------------------------------ 3 files changed, 23 insertions(+), 37 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 9f46f4bc7..475d0491a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -4535,6 +4535,26 @@ void GUI_App::update_mode() plater()->canvas3D()->update_gizmos_on_off_state(); } +void GUI_App::show_ip_address_enter_dialog() +{ + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); + if (!dev) return; + if (!dev->get_selected_machine()) return; + 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(); + 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(); +} + //void GUI_App::add_config_menu(wxMenuBar *menu) //void GUI_App::add_config_menu(wxMenu *menu) //{ diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index b6acde10a..9300b3bfd 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -437,6 +437,7 @@ public: ConfigOptionMode get_mode(); void save_mode(const /*ConfigOptionMode*/int mode) ; void update_mode(); + void show_ip_address_enter_dialog(); // BBS //void add_config_menu(wxMenuBar *menu); diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index fa2f058cf..28524db03 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -666,6 +666,7 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event) BOOST_LOG_TRIVIAL(info) << "send_job: send print job"; } + void SendToPrinterDialog::clear_ip_address_config(wxCommandEvent& e) { DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); @@ -674,19 +675,7 @@ void SendToPrinterDialog::clear_ip_address_config(wxCommandEvent& e) auto obj = dev->get_selected_machine(); Slic3r::GUI::wxGetApp().app_config->set_str("ip_address", obj->dev_id, ""); Slic3r::GUI::wxGetApp().app_config->save(); - - InputIpAddressDialog dlg(this, from_u8(dev->get_selected_machine()->dev_name)); - dlg.Bind(EVT_ENTER_IP_ADDRESS, [this, obj](wxCommandEvent& e) { - auto ip_address = e.GetString(); - 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(); + wxGetApp().show_ip_address_enter_dialog(); } void SendToPrinterDialog::update_user_machine_list() @@ -870,30 +859,6 @@ void SendToPrinterDialog::on_selection_changed(wxCommandEvent &event) return; } - //check ip address - 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); - - if (app_config_dev_ip.empty()) { - InputIpAddressDialog dlg(this, from_u8(obj->dev_name)); - dlg.Bind(EVT_ENTER_IP_ADDRESS, [this, obj, app_config_dev_ip](wxCommandEvent& e) { - auto ip_address = e.GetString(); - 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(); - } - else { - obj->dev_ip = app_config_dev_ip; - } - } - update_show_status(); }