NEW:Support direct connection to LAN printers

jira:[connect printer]

Change-Id: Ifdc25651f4effde8e2a2d2a4e690aa20e0ef7022
This commit is contained in:
tao wang 2024-08-14 11:52:12 +08:00 committed by Lane.Wei
parent f81a9d97c8
commit 0ec49c3588
9 changed files with 180 additions and 111 deletions

View File

@ -5363,6 +5363,21 @@ void DeviceManager::on_machine_alive(std::string json_str)
} }
} }
MachineObject* DeviceManager::insert_local_device(std::string dev_name, std::string dev_id, std::string dev_ip, std::string connection_type, std::string bind_state, std::string version, std::string access_code)
{
MachineObject* obj;
obj = new MachineObject(m_agent, dev_name, dev_id, dev_ip);
obj->printer_type = MachineObject::parse_printer_type("C11");
obj->dev_connection_type = connection_type;
obj->bind_state = bind_state;
obj->bind_sec_link = "secure";
obj->bind_ssdp_version = version;
obj->m_is_online = true;
obj->set_access_code(access_code, false);
obj->set_user_access_code(access_code, false);
return obj;
}
void DeviceManager::disconnect_all() void DeviceManager::disconnect_all()
{ {

View File

@ -1007,7 +1007,7 @@ public:
/* create machine or update machine properties */ /* create machine or update machine properties */
void on_machine_alive(std::string json_str); void on_machine_alive(std::string json_str);
MachineObject* insert_local_device(std::string dev_name, std::string dev_id, std::string dev_ip, std::string connection_type, std::string bind_state, std::string version, std::string access_code);
/* disconnect all machine connections */ /* disconnect all machine connections */
void disconnect_all(); void disconnect_all();
int query_bind_status(std::string &msg); int query_bind_status(std::string &msg);

View File

@ -1419,7 +1419,7 @@ void ConfirmBeforeSendDialog::rescale()
} }
InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent) InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
:DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _L("LAN Connection Failed (Sending print file)"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX) :DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _L("Connect the printer using IP and access code"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
{ {
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str(); std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO)); SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
@ -1509,7 +1509,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered), StateColor btn_bg_white(std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed), std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
std::pair<wxColour, int>(*wxWHITE, StateColor::Normal)); std::pair<wxColour, int>(*wxWHITE, StateColor::Normal));
m_button_ok = new Button(this, _L("Test")); m_button_ok = new Button(this, _L("Connect"));
m_button_ok->SetBackgroundColor(btn_bg_green); m_button_ok->SetBackgroundColor(btn_bg_green);
m_button_ok->SetBorderColor(*wxWHITE); m_button_ok->SetBorderColor(*wxWHITE);
m_button_ok->SetTextColor(wxColour(0xFFFFFE)); m_button_ok->SetTextColor(wxColour(0xFFFFFE));
@ -1534,7 +1534,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
}); });
m_sizer_button->AddStretchSpacer(); m_sizer_button->AddStretchSpacer();
//m_sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5)); m_sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5));
m_sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5)); m_sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
m_sizer_button->Layout(); m_sizer_button->Layout();
@ -1613,12 +1613,12 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4)); m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_input_area, 0, wxRIGHT|wxEXPAND, FromDIP(18)); m_sizer_main_right->Add(m_input_area, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4)); m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_button_ok, 0, wxRIGHT, FromDIP(18)); //m_sizer_main_right->Add(m_button_ok, 0, wxRIGHT, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4)); m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_test_right_msg, 0, wxRIGHT|wxEXPAND, FromDIP(18)); m_sizer_main_right->Add(m_test_right_msg, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(m_test_wrong_msg, 0, wxRIGHT|wxEXPAND, FromDIP(18)); m_sizer_main_right->Add(m_test_wrong_msg, 0, wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(16)); m_sizer_main_right->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_main_right->Add(m_status_bar->get_panel(), 0,wxRIGHT|wxEXPAND, FromDIP(18)); m_sizer_main_right->Add(m_status_bar->get_panel(), 0,wxRIGHT|wxEXPAND, FromDIP(18));
m_sizer_main_right->Layout(); m_sizer_main_right->Layout();
@ -1627,8 +1627,8 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_main->Layout(); m_sizer_main->Layout();
m_sizer_body->Add(m_line_top, 0, wxEXPAND, 0); m_sizer_body->Add(m_line_top, 0, wxEXPAND, 0);
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(20)); m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_body->Add(m_sizer_main, 0, wxEXPAND, 0); m_sizer_body->Add(m_sizer_main, 0, wxRIGHT, FromDIP(10));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4)); m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
m_sizer_body->Add(m_sizer_msg, 0, wxLEFT|wxEXPAND, FromDIP(18)); m_sizer_body->Add(m_sizer_msg, 0, wxLEFT|wxEXPAND, FromDIP(18));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4)); m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(4));
@ -1636,6 +1636,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(8)); m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(8));
m_sizer_body->Add(m_sizer_button, 0, wxRIGHT | wxEXPAND, FromDIP(25)); m_sizer_body->Add(m_sizer_button, 0, wxRIGHT | wxEXPAND, FromDIP(25));
m_sizer_body->Add(0, 0, 0, wxTOP, FromDIP(10));
m_sizer_body->Layout(); m_sizer_body->Layout();
SetSizer(m_sizer_body); SetSizer(m_sizer_body);
@ -1646,29 +1647,33 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent)
Move(wxPoint(GetScreenPosition().x, GetScreenPosition().y - FromDIP(50))); Move(wxPoint(GetScreenPosition().x, GetScreenPosition().y - FromDIP(50)));
wxGetApp().UpdateDlgDarkUI(this); wxGetApp().UpdateDlgDarkUI(this);
closeTimer = new wxTimer();
closeTimer->SetOwner(this);
Bind(wxEVT_TIMER, &InputIpAddressDialog::OnTimer, this);
Bind(EVT_CHECK_IP_ADDRESS_FAILED, &InputIpAddressDialog::on_check_ip_address_failed, this); Bind(EVT_CHECK_IP_ADDRESS_FAILED, &InputIpAddressDialog::on_check_ip_address_failed, this);
Bind(EVT_CLOSE_IPADDRESS_DLG, [this](auto& e) { Bind(EVT_CLOSE_IPADDRESS_DLG, [this](auto& e) {
m_status_bar->reset(); m_status_bar->reset();
EndModal(wxID_YES); EndModal(wxID_YES);
}); });
Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {on_cancel();}); Bind(wxEVT_CLOSE_WINDOW, [this](auto& e) {
on_cancel();
closeTimer->Stop();
});
} }
void InputIpAddressDialog::on_cancel() void InputIpAddressDialog::on_cancel()
{ {
if (m_send_job) { if (m_thread) {
if (m_send_job->is_running()) { m_thread->interrupt();
m_send_job->cancel(); m_thread->join();
m_send_job->join(); delete m_thread;
} m_thread = nullptr;
}
if (m_result == 0){
this->EndModal(wxID_YES);
}else {
this->EndModal(wxID_CANCEL);
} }
EndModal(wxID_CANCEL);
} }
@ -1726,8 +1731,6 @@ void InputIpAddressDialog::update_test_msg(wxString msg,bool connected)
m_test_wrong_msg->SetMinSize(wxSize(FromDIP(352), -1)); m_test_wrong_msg->SetMinSize(wxSize(FromDIP(352), -1));
m_test_wrong_msg->SetMaxSize(wxSize(FromDIP(352), -1)); m_test_wrong_msg->SetMaxSize(wxSize(FromDIP(352), -1));
} }
} }
Layout(); Layout();
@ -1757,13 +1760,11 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
m_img_step3->Hide(); m_img_step3->Hide();
m_tip4->Hide(); m_tip4->Hide();
m_trouble_shoot->Hide(); m_trouble_shoot->Hide();
Layout(); std::string str_ip = m_input_ip->GetTextCtrl()->GetValue().ToStdString();
Fit(); std::string str_access_code = m_input_access_code->GetTextCtrl()->GetValue().ToStdString();
wxString ip = m_input_ip->GetTextCtrl()->GetValue();
wxString str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
//check support function //check support function
if (!m_obj) return; /*if (!m_obj) return;
if (!m_obj->is_support_send_to_sdcard) { if (!m_obj->is_support_send_to_sdcard) {
wxString input_str = wxString::Format("%s|%s", ip, str_access_code); wxString input_str = wxString::Format("%s|%s", ip, str_access_code);
auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS); auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS);
@ -1775,66 +1776,84 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
event_close.SetEventObject(this); event_close.SetEventObject(this);
wxPostEvent(this, event_close); wxPostEvent(this, event_close);
return; return;
} }*/
m_button_ok->Enable(false); m_button_ok->Enable(false);
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90)); m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90)); m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
if (m_send_job) { Refresh();
m_send_job->join(); Layout();
Fit();
m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code));
}
void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code)
{
update_test_msg(_L("connecting..."), true);
detectResult detectData;
auto result = wxGetApp().getAgent()->bind_detect(str_ip, "secure", detectData);
if (result < 0) {
update_test_msg(wxEmptyString, true);
if (result == -1) {
update_test_msg(_L("Failed to connect to printer."), false);
}
else if (result == -2) {
update_test_msg(_L("Failed to publish login request."), false);
}
else if (result == -3) {
update_test_msg(_L("The device does not support using IP and Access Code for connection."), false);
}
Layout();
Fit();
return;
} }
m_status_bar->reset(); if (detectData.bind_state == "occupied") {
m_status_bar->set_prog_block(); update_test_msg(_L("The printer has already been bound."), false);
m_status_bar->set_cancel_callback_fina([this]() { Layout();
BOOST_LOG_TRIVIAL(info) << "print_job: enter canceled"; Fit();
if (m_send_job) { return;
if (m_send_job->is_running()) {
BOOST_LOG_TRIVIAL(info) << "send_job: canceled";
m_send_job->cancel();
} }
m_send_job->join();
if (detectData.connect_type == "cloud") {
update_test_msg(_L("The printer mode is incorrect, please switch to LAN Only."), false);
Layout();
Fit();
return;
} }
});
DeviceManager* dev = wxGetApp().getDeviceManager();
m_obj = dev->insert_local_device(detectData.dev_name, detectData.dev_id, str_ip, detectData.connect_type, detectData.bind_state, detectData.version, str_access_code);
m_send_job = std::make_shared<SendJob>(m_status_bar, wxGetApp().plater(), m_obj->dev_id); if (m_obj) {
m_send_job->m_dev_ip = ip.ToStdString(); m_obj->set_user_access_code(str_access_code);
m_send_job->m_access_code = str_access_code.ToStdString(); wxGetApp().getDeviceManager()->set_selected_machine(m_obj->dev_id);
}
#if !BBL_RELEASE_TO_PUBLIC closeCount = 3;
m_send_job->m_local_use_ssl_for_mqtt = wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false; update_test_msg(wxEmptyString, true);
m_send_job->m_local_use_ssl_for_ftp = wxGetApp().app_config->get("enable_ssl_for_ftp") == "true" ? true : false; update_test_msg(wxString::Format(_L("Printer binding successful. The dialog will close in %d seconds"), closeCount), true);
#else closeTimer->Start(1000);
m_send_job->m_local_use_ssl_for_mqtt = m_obj->local_use_ssl_for_mqtt;
m_send_job->m_local_use_ssl_for_ftp = m_obj->local_use_ssl_for_ftp;
#endif
m_send_job->connection_type = m_obj->connection_type(); Layout();
m_send_job->cloud_print_only = true; Fit();
m_send_job->has_sdcard = m_obj->has_sdcard(); }
m_send_job->set_check_mode();
m_send_job->set_project_name("verify_job");
m_send_job->on_check_ip_address_fail([this](int result) { void InputIpAddressDialog::OnTimer(wxTimerEvent& event) {
this->check_ip_address_failed(result); if (closeCount > 0) {
}); closeCount--;
update_test_msg(wxString::Format(_L("Printer binding successful. The dialog will close in %d seconds"), closeCount), true);
m_send_job->on_check_ip_address_success([this, ip, str_access_code]() { Refresh();
wxString input_str = wxString::Format("%s|%s", ip, str_access_code); }
auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS); else {
event.SetString(input_str); closeTimer->Stop();
event.SetEventObject(this); EndModal(wxID_CLOSE);
wxPostEvent(this, event); }
m_result = 0;
update_test_msg(_L("IP and Access Code Verified! You may close the window"), true);
});
m_send_job->start();
} }
void InputIpAddressDialog::check_ip_address_failed(int result) void InputIpAddressDialog::check_ip_address_failed(int result)
@ -1870,8 +1889,16 @@ void InputIpAddressDialog::on_text(wxCommandEvent& evt)
{ {
auto str_ip = m_input_ip->GetTextCtrl()->GetValue(); auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue(); auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
bool invalid_access_code = true;
if (isIp(str_ip.ToStdString()) && str_access_code.Length() == 8) { for (char c : str_access_code) {
if (!('0' <= c && c <= '9' || 'a' <= c && c <= 'z' || 'A' <= c && c <= 'Z')) {
invalid_access_code = false;
return;
}
}
if (isIp(str_ip.ToStdString()) && str_access_code.Length() == 8 && invalid_access_code) {
m_button_ok->Enable(true); m_button_ok->Enable(true);
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered), StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal)); std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));

View File

@ -275,6 +275,8 @@ public:
wxString comfirm_before_enter_text; wxString comfirm_before_enter_text;
wxString comfirm_after_enter_text; wxString comfirm_after_enter_text;
boost::thread* m_thread{nullptr};
std::string m_ip; std::string m_ip;
Label* m_tip1{ nullptr }; Label* m_tip1{ nullptr };
Label* m_tip2{ nullptr }; Label* m_tip2{ nullptr };
@ -296,6 +298,8 @@ public:
wxStaticBitmap* m_img_step2{ nullptr }; wxStaticBitmap* m_img_step2{ nullptr };
wxStaticBitmap* m_img_step3{ nullptr }; wxStaticBitmap* m_img_step3{ nullptr };
wxHyperlinkCtrl* m_trouble_shoot{ nullptr }; wxHyperlinkCtrl* m_trouble_shoot{ nullptr };
wxTimer* closeTimer{ nullptr };
int closeCount{3};
bool m_show_access_code{ false }; bool m_show_access_code{ false };
int m_result; int m_result;
std::shared_ptr<SendJob> m_send_job{nullptr}; std::shared_ptr<SendJob> m_send_job{nullptr};
@ -309,6 +313,8 @@ public:
void check_ip_address_failed(int result); void check_ip_address_failed(int result);
void on_check_ip_address_failed(wxCommandEvent& evt); void on_check_ip_address_failed(wxCommandEvent& evt);
void on_ok(wxMouseEvent& evt); void on_ok(wxMouseEvent& evt);
void workerThreadFunc(std::string str_ip, std::string str_access_code);
void OnTimer(wxTimerEvent& event);
void on_text(wxCommandEvent& evt); void on_text(wxCommandEvent& evt);
void on_dpi_changed(const wxRect& suggested_rect) override; void on_dpi_changed(const wxRect& suggested_rect) override;
}; };

View File

@ -396,11 +396,13 @@ SelectMachinePopup::SelectMachinePopup(wxWindow *parent)
m_sizer_other_devices = new wxBoxSizer(wxVERTICAL); m_sizer_other_devices = new wxBoxSizer(wxVERTICAL);
m_panel_ping_code = new PinCodePanel(m_scrolledWindow, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_ITEM_SIZE); m_panel_ping_code = new PinCodePanel(m_scrolledWindow, 0, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_ITEM_SIZE);
m_panel_direct_connection = new PinCodePanel(m_scrolledWindow, 1, wxID_ANY, wxDefaultPosition, SELECT_MACHINE_ITEM_SIZE);
m_sizxer_scrolledWindow->Add(own_title, 0, wxEXPAND | wxLEFT, FromDIP(15)); m_sizxer_scrolledWindow->Add(own_title, 0, wxEXPAND | wxLEFT, FromDIP(15));
m_sizxer_scrolledWindow->Add(m_sizer_my_devices, 0, wxEXPAND, 0); m_sizxer_scrolledWindow->Add(m_sizer_my_devices, 0, wxEXPAND, 0);
m_sizxer_scrolledWindow->Add(m_panel_ping_code, 0, wxEXPAND, 0); m_sizxer_scrolledWindow->Add(m_panel_ping_code, 0, wxEXPAND, 0);
m_sizxer_scrolledWindow->Add(m_panel_direct_connection, 0, wxEXPAND, 0);
m_sizxer_scrolledWindow->Add(other_title, 0, wxEXPAND | wxLEFT, FromDIP(15)); m_sizxer_scrolledWindow->Add(other_title, 0, wxEXPAND | wxLEFT, FromDIP(15));
m_sizxer_scrolledWindow->Add(m_sizer_other_devices, 0, wxEXPAND, 0); m_sizxer_scrolledWindow->Add(m_sizer_other_devices, 0, wxEXPAND, 0);
@ -875,14 +877,16 @@ void SelectMachinePopup::OnLeftUp(wxMouseEvent &event)
//pin code //pin code
auto pc_rect = m_panel_ping_code->ClientToScreen(wxPoint(0, 0)); auto pc_rect = m_panel_ping_code->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > pc_rect.x && mouse_pos.y > pc_rect.y && mouse_pos.x < (pc_rect.x + m_panel_ping_code->GetSize().x) && mouse_pos.y < (pc_rect.y + m_panel_ping_code->GetSize().y)) { if (mouse_pos.x > pc_rect.x && mouse_pos.y > pc_rect.y && mouse_pos.x < (pc_rect.x + m_panel_ping_code->GetSize().x) && mouse_pos.y < (pc_rect.y + m_panel_ping_code->GetSize().y)) {
/*wxMouseEvent event(wxEVT_LEFT_UP);
auto tag_pos = m_panel_ping_code->ScreenToClient(mouse_pos);
event.SetPosition(tag_pos);
event.SetEventObject(m_panel_ping_code);
wxPostEvent(m_panel_ping_code, event);*/
wxGetApp().popup_ping_bind_dialog(); wxGetApp().popup_ping_bind_dialog();
} }
//bind with access code
auto dc_rect = m_panel_direct_connection->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > dc_rect.x && mouse_pos.y > dc_rect.y && mouse_pos.x < (dc_rect.x + m_panel_direct_connection->GetSize().x) && mouse_pos.y < (dc_rect.y + m_panel_direct_connection->GetSize().y)) {
InputIpAddressDialog dlgo;
dlgo.ShowModal();
}
//hyper link //hyper link
auto h_rect = m_hyperlink->ClientToScreen(wxPoint(0, 0)); auto h_rect = m_hyperlink->ClientToScreen(wxPoint(0, 0));
if (mouse_pos.x > h_rect.x && mouse_pos.y > h_rect.y && mouse_pos.x < (h_rect.x + m_hyperlink->GetSize().x) && mouse_pos.y < (h_rect.y + m_hyperlink->GetSize().y)) { if (mouse_pos.x > h_rect.x && mouse_pos.y > h_rect.y && mouse_pos.x < (h_rect.x + m_hyperlink->GetSize().x) && mouse_pos.y < (h_rect.y + m_hyperlink->GetSize().y)) {
@ -1444,30 +1448,6 @@ void SelectMachineDialog::init_bind()
m_comboBox_printer->SetValue(obj->dev_name + "(LAN)"); m_comboBox_printer->SetValue(obj->dev_name + "(LAN)");
} }
} }
/*else if (e.GetInt() == 1 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
on_send_print();
}
else if (e.GetInt() == -2 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
MessageDialog msg_wingow(nullptr, _L("Printer local connection failed, please try again."), "", wxAPPLY | wxOK);
msg_wingow.ShowModal();
}
else if (e.GetInt() == 5 && (m_print_type == PrintFromType::FROM_SDCARD_VIEW)) {
show_status(PrintDialogStatus::PrintStatusInit);
prepare_mode();
DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager();
if (!dev) return;
ConnectPrinterDialog dlg(wxGetApp().mainframe, wxID_ANY, _L("Input access code"));
dlg.go_connect_printer(false);
if (dev->get_selected_machine()) {
dlg.set_machine_object(dev->get_selected_machine());
if (dlg.ShowModal() == wxID_OK) {
this->connect_printer_mqtt();
}
}
}*/
}); });
m_bitmap_last_plate->Bind(wxEVT_LEFT_DOWN, [this](auto& e) { m_bitmap_last_plate->Bind(wxEVT_LEFT_DOWN, [this](auto& e) {
@ -4868,7 +4848,7 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
ThumbnailPanel::~ThumbnailPanel() {} ThumbnailPanel::~ThumbnailPanel() {}
PinCodePanel::PinCodePanel(wxWindow* parent, wxWindowID winid /*= wxID_ANY*/, const wxPoint& pos /*= wxDefaultPosition*/, const wxSize& size /*= wxDefaultSize*/) PinCodePanel::PinCodePanel(wxWindow* parent, int type, wxWindowID winid /*= wxID_ANY*/, const wxPoint& pos /*= wxDefaultPosition*/, const wxSize& size /*= wxDefaultSize*/)
{ {
wxPanel::Create(parent, winid, pos, SELECT_MACHINE_ITEM_SIZE); wxPanel::Create(parent, winid, pos, SELECT_MACHINE_ITEM_SIZE);
Bind(wxEVT_PAINT, &PinCodePanel::OnPaint, this); Bind(wxEVT_PAINT, &PinCodePanel::OnPaint, this);
@ -4876,6 +4856,7 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
SetMaxSize(SELECT_MACHINE_ITEM_SIZE); SetMaxSize(SELECT_MACHINE_ITEM_SIZE);
SetMinSize(SELECT_MACHINE_ITEM_SIZE); SetMinSize(SELECT_MACHINE_ITEM_SIZE);
m_type = type;
m_bitmap = ScalableBitmap(this, "bind_device_ping_code",10); m_bitmap = ScalableBitmap(this, "bind_device_ping_code",10);
this->Bind(wxEVT_ENTER_WINDOW, &PinCodePanel::on_mouse_enter, this); this->Bind(wxEVT_ENTER_WINDOW, &PinCodePanel::on_mouse_enter, this);
@ -4913,12 +4894,15 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
void PinCodePanel::doRender(wxDC& dc) void PinCodePanel::doRender(wxDC& dc)
{ {
auto size = GetSize(); auto size = GetSize();
dc.DrawBitmap(m_bitmap.bmp(), wxPoint(FromDIP(20), (size.y - m_bitmap.GetBmpSize().y) / 2)); dc.DrawBitmap(m_bitmap.bmp(), wxPoint(FromDIP(12), (size.y - m_bitmap.GetBmpSize().y) / 2));
dc.SetFont(::Label::Head_13); dc.SetFont(::Label::Head_13);
dc.SetTextForeground(wxColour(38, 46, 48)); dc.SetTextForeground(wxColour(38, 46, 48));
wxString txt = _L("Bind with Pin Code"); wxString txt;
if (m_type == 0) { txt = _L("Bind with Pin Code"); }
else if (m_type == 1) { txt = _L("Bind with Access Code"); }
auto txt_size = dc.GetTextExtent(txt); auto txt_size = dc.GetTextExtent(txt);
dc.DrawText(txt, wxPoint(FromDIP(40), (size.y - txt_size.y) / 2)); dc.DrawText(txt, wxPoint(FromDIP(28), (size.y - txt_size.y) / 2));
if (m_hover) { if (m_hover) {
dc.SetPen(SELECT_MACHINE_BRAND); dc.SetPen(SELECT_MACHINE_BRAND);
@ -4941,7 +4925,13 @@ void EditDevNameDialog::on_edit_name(wxCommandEvent &e)
void PinCodePanel::on_mouse_left_up(wxMouseEvent& evt) void PinCodePanel::on_mouse_left_up(wxMouseEvent& evt)
{ {
if (m_type == 0) {
wxGetApp().popup_ping_bind_dialog(); wxGetApp().popup_ping_bind_dialog();
} }
else if (m_type == 1) {
InputIpAddressDialog dlgo;
dlgo.ShowModal();
}
}
}} // namespace Slic3r::GUI }} // namespace Slic3r::GUI

View File

@ -193,7 +193,7 @@ protected:
#define SELECT_MACHINE_POPUP_SIZE wxSize(FromDIP(216), FromDIP(364)) #define SELECT_MACHINE_POPUP_SIZE wxSize(FromDIP(216), FromDIP(364))
#define SELECT_MACHINE_LIST_SIZE wxSize(FromDIP(212), FromDIP(360)) #define SELECT_MACHINE_LIST_SIZE wxSize(FromDIP(212), FromDIP(360))
#define SELECT_MACHINE_ITEM_SIZE wxSize(FromDIP(182), FromDIP(35)) #define SELECT_MACHINE_ITEM_SIZE wxSize(FromDIP(190), FromDIP(35))
#define SELECT_MACHINE_GREY900 wxColour(38, 46, 48) #define SELECT_MACHINE_GREY900 wxColour(38, 46, 48)
#define SELECT_MACHINE_GREY600 wxColour(144,144,144) #define SELECT_MACHINE_GREY600 wxColour(144,144,144)
#define SELECT_MACHINE_GREY400 wxColour(206, 206, 206) #define SELECT_MACHINE_GREY400 wxColour(206, 206, 206)
@ -212,6 +212,7 @@ class PinCodePanel : public wxPanel
{ {
public: public:
PinCodePanel(wxWindow* parent, PinCodePanel(wxWindow* parent,
int type,
wxWindowID winid = wxID_ANY, wxWindowID winid = wxID_ANY,
const wxPoint& pos = wxDefaultPosition, const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize); const wxSize& size = wxDefaultSize);
@ -219,6 +220,7 @@ public:
ScalableBitmap m_bitmap; ScalableBitmap m_bitmap;
bool m_hover{false}; bool m_hover{false};
int m_type{0};
void OnPaint(wxPaintEvent& event); void OnPaint(wxPaintEvent& event);
void render(wxDC& dc); void render(wxDC& dc);
@ -252,6 +254,7 @@ private:
int m_my_devices_count{0}; int m_my_devices_count{0};
int m_other_devices_count{0}; int m_other_devices_count{0};
PinCodePanel* m_panel_ping_code{nullptr}; PinCodePanel* m_panel_ping_code{nullptr};
PinCodePanel* m_panel_direct_connection{nullptr};
wxWindow* m_placeholder_panel{nullptr}; wxWindow* m_placeholder_panel{nullptr};
wxHyperlinkCtrl* m_hyperlink{nullptr}; wxHyperlinkCtrl* m_hyperlink{nullptr};
Label* m_ping_code_text{nullptr}; Label* m_ping_code_text{nullptr};

View File

@ -75,6 +75,7 @@ func_build_logout_cmd NetworkAgent::build_logout_cmd_ptr = nullptr
func_build_login_info NetworkAgent::build_login_info_ptr = nullptr; func_build_login_info NetworkAgent::build_login_info_ptr = nullptr;
func_get_model_id_from_desgin_id NetworkAgent::get_model_id_from_desgin_id_ptr = nullptr; func_get_model_id_from_desgin_id NetworkAgent::get_model_id_from_desgin_id_ptr = nullptr;
func_ping_bind NetworkAgent::ping_bind_ptr = nullptr; func_ping_bind NetworkAgent::ping_bind_ptr = nullptr;
func_bind_detect NetworkAgent::bind_detect_ptr = nullptr;
func_bind NetworkAgent::bind_ptr = nullptr; func_bind NetworkAgent::bind_ptr = nullptr;
func_unbind NetworkAgent::unbind_ptr = nullptr; func_unbind NetworkAgent::unbind_ptr = nullptr;
func_get_bambulab_host NetworkAgent::get_bambulab_host_ptr = nullptr; func_get_bambulab_host NetworkAgent::get_bambulab_host_ptr = nullptr;
@ -284,6 +285,7 @@ int NetworkAgent::initialize_network_module(bool using_backup)
build_logout_cmd_ptr = reinterpret_cast<func_build_logout_cmd>(get_network_function("bambu_network_build_logout_cmd")); build_logout_cmd_ptr = reinterpret_cast<func_build_logout_cmd>(get_network_function("bambu_network_build_logout_cmd"));
build_login_info_ptr = reinterpret_cast<func_build_login_info>(get_network_function("bambu_network_build_login_info")); build_login_info_ptr = reinterpret_cast<func_build_login_info>(get_network_function("bambu_network_build_login_info"));
ping_bind_ptr = reinterpret_cast<func_ping_bind>(get_network_function("bambu_network_ping_bind")); ping_bind_ptr = reinterpret_cast<func_ping_bind>(get_network_function("bambu_network_ping_bind"));
bind_detect_ptr = reinterpret_cast<func_bind_detect>(get_network_function("bambu_network_bind_detect"));
get_model_id_from_desgin_id_ptr = reinterpret_cast<func_get_model_id_from_desgin_id>(get_network_function("bambu_network_get_model_id_from_desgin_id")); get_model_id_from_desgin_id_ptr = reinterpret_cast<func_get_model_id_from_desgin_id>(get_network_function("bambu_network_get_model_id_from_desgin_id"));
bind_ptr = reinterpret_cast<func_bind>(get_network_function("bambu_network_bind")); bind_ptr = reinterpret_cast<func_bind>(get_network_function("bambu_network_bind"));
unbind_ptr = reinterpret_cast<func_unbind>(get_network_function("bambu_network_unbind")); unbind_ptr = reinterpret_cast<func_unbind>(get_network_function("bambu_network_unbind"));
@ -1023,6 +1025,18 @@ int NetworkAgent::ping_bind(std::string ping_code)
return ret; return ret;
} }
int NetworkAgent::bind_detect(std::string dev_ip, std::string sec_link, detectResult& detect)
{
int ret = 0;
if (network_agent && bind_detect_ptr) {
ret = bind_detect_ptr(network_agent, dev_ip, sec_link, detect);
if (ret)
BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << boost::format(" error: network_agent=%1%, ret=%2%, dev_ip=%3%")
% network_agent % ret % dev_ip;
}
return ret;
}
int NetworkAgent::bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn) int NetworkAgent::bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn)
{ {
int ret = 0; int ret = 0;

View File

@ -55,6 +55,7 @@ typedef std::string (*func_build_logout_cmd)(void *agent);
typedef std::string (*func_build_login_info)(void *agent); typedef std::string (*func_build_login_info)(void *agent);
typedef int (*func_get_model_id_from_desgin_id)(void *agent, std::string& desgin_id, std::string& model_id); typedef int (*func_get_model_id_from_desgin_id)(void *agent, std::string& desgin_id, std::string& model_id);
typedef int (*func_ping_bind)(void *agent, std::string ping_code); typedef int (*func_ping_bind)(void *agent, std::string ping_code);
typedef int (*func_bind_detect)(void *agent, std::string dev_ip, std::string sec_link, detectResult& detect);
typedef int (*func_bind)(void *agent, std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn); typedef int (*func_bind)(void *agent, std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
typedef int (*func_unbind)(void *agent, std::string dev_id); typedef int (*func_unbind)(void *agent, std::string dev_id);
typedef std::string (*func_get_bambulab_host)(void *agent); typedef std::string (*func_get_bambulab_host)(void *agent);
@ -172,6 +173,7 @@ public:
std::string build_login_info(); std::string build_login_info();
int get_model_id_from_desgin_id(std::string& desgin_id, std::string& model_id); int get_model_id_from_desgin_id(std::string& desgin_id, std::string& model_id);
int ping_bind(std::string ping_code); int ping_bind(std::string ping_code);
int bind_detect(std::string dev_ip, std::string sec_link, detectResult& detect);
int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn); int bind(std::string dev_ip, std::string dev_id, std::string sec_link, std::string timezone, bool improved, OnUpdateStatusFn update_fn);
int unbind(std::string dev_id); int unbind(std::string dev_id);
std::string get_bambulab_host(); std::string get_bambulab_host();
@ -278,6 +280,7 @@ private:
static func_build_login_info build_login_info_ptr; static func_build_login_info build_login_info_ptr;
static func_get_model_id_from_desgin_id get_model_id_from_desgin_id_ptr; static func_get_model_id_from_desgin_id get_model_id_from_desgin_id_ptr;
static func_ping_bind ping_bind_ptr; static func_ping_bind ping_bind_ptr;
static func_bind_detect bind_detect_ptr;
static func_bind bind_ptr; static func_bind bind_ptr;
static func_unbind unbind_ptr; static func_unbind unbind_ptr;
static func_get_bambulab_host get_bambulab_host_ptr; static func_get_bambulab_host get_bambulab_host_ptr;

View File

@ -172,6 +172,17 @@ enum ConnectStatus {
ConnectStatusLost = 2, ConnectStatusLost = 2,
}; };
struct detectResult {
std::string result_msg;
std::string command;
std::string dev_id;
std::string model_id;
std::string dev_name;
std::string version;
std::string bind_state;
std::string connect_type;
};
/* print job*/ /* print job*/
struct PrintParams { struct PrintParams {
/* basic info */ /* basic info */