mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-18 12:17:54 -06:00
ENH:allows the user to enter a printed IP address
Change-Id: I9d2617d0dd42f53e93d61e98bcf3cc97979a93f6 (cherry picked from commit 24ab56f8568e9637634e97a0632309cfd2762749)
This commit is contained in:
parent
c8df45c11f
commit
47a46010bd
9 changed files with 253 additions and 10 deletions
|
@ -3403,6 +3403,11 @@ void DeviceManager::on_machine_alive(std::string json_str)
|
|||
BOOST_LOG_TRIVIAL(debug) << "SsdpDiscovery:: Update Machine Info, printer_sn = " << dev_id << ", signal = " << printer_signal;
|
||||
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||
obj->m_is_online = true;
|
||||
|
||||
/* if (!obj->dev_ip.empty()) {
|
||||
Slic3r::GUI::wxGetApp().app_config->set_str("ip_address", obj->dev_id, obj->dev_ip);
|
||||
Slic3r::GUI::wxGetApp().app_config->save();
|
||||
}*/
|
||||
}
|
||||
else {
|
||||
/* insert a new machine */
|
||||
|
@ -3419,6 +3424,11 @@ void DeviceManager::on_machine_alive(std::string json_str)
|
|||
}
|
||||
localMachineList.insert(std::make_pair(dev_id, obj));
|
||||
|
||||
/* if (!obj->dev_ip.empty()) {
|
||||
Slic3r::GUI::wxGetApp().app_config->set_str("ip_address", obj->dev_id, obj->dev_ip);
|
||||
Slic3r::GUI::wxGetApp().app_config->save();
|
||||
}*/
|
||||
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "SsdpDiscovery::New Machine, ip = " << dev_ip << ", printer_name= " << dev_name << ", printer_type = " << printer_type_str << ", signal = " << printer_signal;
|
||||
}
|
||||
|
|
|
@ -383,6 +383,7 @@ public:
|
|||
std::string access_code;
|
||||
std::string dev_connection_type; /* lan | cloud */
|
||||
std::string connection_type() { return dev_connection_type; }
|
||||
void set_dev_ip(std::string ip) {dev_ip = ip;};
|
||||
bool has_access_right() { return !access_code.empty(); }
|
||||
void set_access_code(std::string code);
|
||||
bool is_lan_mode_printer();
|
||||
|
|
|
@ -310,11 +310,15 @@ void SendJob::process()
|
|||
}
|
||||
}
|
||||
|
||||
if (result == BAMBU_NETWORK_ERR_WRONG_IP_ADDRESS) {
|
||||
msg_text = _L("Failed uploading print file. Please enter ip address again.");
|
||||
m_enter_ip_address_fun();
|
||||
}
|
||||
|
||||
update_status(curr_percent, msg_text);
|
||||
BOOST_LOG_TRIVIAL(error) << "send_job: failed, result = " << result;
|
||||
} else {
|
||||
BOOST_LOG_TRIVIAL(error) << "send_job: send ok.";
|
||||
//m_success_fun();
|
||||
wxCommandEvent* evt = new wxCommandEvent(m_print_job_completed_id);
|
||||
evt->SetString(from_u8(params.project_name));
|
||||
wxQueueEvent(m_plater, evt);
|
||||
|
@ -327,6 +331,12 @@ void SendJob::on_success(std::function<void()> success)
|
|||
m_success_fun = success;
|
||||
}
|
||||
|
||||
void SendJob::on_enter_ip_address(std::function<void()> success)
|
||||
{
|
||||
m_enter_ip_address_fun = success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void SendJob::finalize() {
|
||||
if (was_canceled()) return;
|
||||
|
|
|
@ -21,6 +21,7 @@ class SendJob : public PlaterJob
|
|||
bool m_job_finished{ false };
|
||||
int m_print_job_completed_id = 0;
|
||||
std::function<void()> m_success_fun{nullptr};
|
||||
std::function<void()> m_enter_ip_address_fun{nullptr};
|
||||
|
||||
protected:
|
||||
|
||||
|
@ -52,6 +53,7 @@ public:
|
|||
bool is_finished() { return m_job_finished; }
|
||||
void process() override;
|
||||
void on_success(std::function<void()> success);
|
||||
void on_enter_ip_address(std::function<void()> success);
|
||||
void finalize() override;
|
||||
void set_project_name(std::string name);
|
||||
};
|
||||
|
|
|
@ -27,6 +27,7 @@ namespace Slic3r {
|
|||
namespace GUI {
|
||||
|
||||
wxDEFINE_EVENT(EVT_CHECKBOX_CHANGE, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent);
|
||||
|
||||
MsgDialog::MsgDialog(wxWindow *parent, const wxString &title, const wxString &headline, long style, wxBitmap bitmap)
|
||||
: DPIDialog(parent ? parent : dynamic_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, title, wxDefaultPosition, wxSize(360, -1),wxDEFAULT_DIALOG_STYLE)
|
||||
|
@ -421,4 +422,153 @@ void DownloadDialog::SetExtendedMessage(const wxString &extendedMessage)
|
|||
Fit();
|
||||
}
|
||||
|
||||
InputIpAddressDialog::InputIpAddressDialog(wxWindow* parent, wxString name)
|
||||
:DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _L("Unable to connect printer"), wxDefaultPosition, wxDefaultSize, wxCAPTION | wxCLOSE_BOX)
|
||||
{
|
||||
std::string icon_path = (boost::format("%1%/images/BambuStudioTitle.ico") % resources_dir()).str();
|
||||
SetIcon(wxIcon(encode_path(icon_path.c_str()), wxBITMAP_TYPE_ICO));
|
||||
|
||||
SetBackgroundColour(*wxWHITE);
|
||||
wxBoxSizer* m_sizer_main = new wxBoxSizer(wxVERTICAL);
|
||||
auto m_line_top = new wxPanel(this, wxID_ANY, wxDefaultPosition, wxSize(-1, 1));
|
||||
m_line_top->SetBackgroundColour(wxColour(166, 169, 170));
|
||||
m_sizer_main->Add(m_line_top, 0, wxEXPAND, 0);
|
||||
|
||||
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.");
|
||||
|
||||
|
||||
tip = new Label(this, comfirm_before_enter_text);
|
||||
|
||||
tip->SetMinSize(wxSize(FromDIP(420), -1));
|
||||
tip->SetMaxSize(wxSize(FromDIP(420), -1));
|
||||
tip->Wrap(FromDIP(420));
|
||||
|
||||
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_input_ip->Hide();
|
||||
|
||||
auto sizer_button = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
||||
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
|
||||
|
||||
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));
|
||||
|
||||
m_button_ok = new Button(this, _L("OK"));
|
||||
m_button_ok->SetBackgroundColor(btn_bg_green);
|
||||
m_button_ok->SetBorderColor(*wxWHITE);
|
||||
m_button_ok->SetTextColor(wxColour(0xFFFFFE));
|
||||
m_button_ok->SetFont(Label::Body_12);
|
||||
m_button_ok->SetSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_ok->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_ok->SetCornerRadius(FromDIP(12));
|
||||
|
||||
|
||||
m_button_ok->Bind(wxEVT_LEFT_DOWN, &InputIpAddressDialog::on_ok, this);
|
||||
|
||||
auto m_button_cancel = new Button(this, _L("Cancel"));
|
||||
m_button_cancel->SetBackgroundColor(btn_bg_white);
|
||||
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
|
||||
m_button_cancel->SetFont(Label::Body_12);
|
||||
m_button_cancel->SetSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_cancel->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_cancel->SetCornerRadius(FromDIP(12));
|
||||
|
||||
m_button_cancel->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent& e) {
|
||||
EndModal(wxID_CANCEL);
|
||||
});
|
||||
|
||||
sizer_button->AddStretchSpacer();
|
||||
sizer_button->Add(m_button_ok, 0, wxALL, FromDIP(5));
|
||||
sizer_button->Add(m_button_cancel, 0, wxALL, FromDIP(5));
|
||||
|
||||
|
||||
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_input_ip, 1, wxALIGN_CENTER, FromDIP(18));
|
||||
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));
|
||||
SetSizer(m_sizer_main);
|
||||
Layout();
|
||||
m_sizer_main->Fit(this);
|
||||
|
||||
Centre(wxBOTH);
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
}
|
||||
|
||||
bool InputIpAddressDialog::isIp(std::string ipstr)
|
||||
{
|
||||
istringstream ipstream(ipstr);
|
||||
int num[4];
|
||||
char point[3];
|
||||
string end;
|
||||
ipstream >> num[0] >> point[0] >> num[1] >> point[1] >> num[2] >> point[2] >> num[3] >> end;
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
if (num[i] < 0 || num[i]>255) return false;
|
||||
if (point[i] != '.') return false;
|
||||
}
|
||||
if (num[3] < 0 || num[3]>255) return false;
|
||||
if (!end.empty()) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
||||
{
|
||||
if (!m_input_ip->IsShown()) {
|
||||
tip->SetLabel(comfirm_after_enter_text);
|
||||
tip->SetMinSize(wxSize(FromDIP(420), -1));
|
||||
tip->SetMaxSize(wxSize(FromDIP(420), -1));
|
||||
tip->Wrap(FromDIP(420));
|
||||
|
||||
m_input_ip->Show();
|
||||
m_button_ok->Enable(false);
|
||||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
Layout();
|
||||
Fit();
|
||||
}
|
||||
else {
|
||||
wxString ip = m_input_ip->GetTextCtrl()->GetValue();
|
||||
auto event = wxCommandEvent(EVT_ENTER_IP_ADDRESS);
|
||||
event.SetString(ip);
|
||||
event.SetEventObject(this);
|
||||
wxPostEvent(this, event);
|
||||
EndModal(wxID_YES);
|
||||
}
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::on_text(wxCommandEvent& evt)
|
||||
{
|
||||
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
|
||||
if (isIp(str_ip.ToStdString())) {
|
||||
m_button_ok->Enable(true);
|
||||
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(27, 136, 68), StateColor::Pressed), std::pair<wxColour, int>(wxColour(61, 203, 115), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
|
||||
m_button_ok->SetBorderColor(*wxWHITE);
|
||||
m_button_ok->SetBackgroundColor(btn_bg_green);
|
||||
}
|
||||
else {
|
||||
m_button_ok->Enable(false);
|
||||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
}
|
||||
}
|
||||
|
||||
InputIpAddressDialog::~InputIpAddressDialog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GUI
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
|
||||
#include "GUI_Utils.hpp"
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/font.h>
|
||||
|
@ -14,6 +13,7 @@
|
|||
#include <wx/statline.h>
|
||||
#include "Widgets/Button.hpp"
|
||||
#include "Widgets/CheckBox.hpp"
|
||||
#include "Widgets/TextInput.hpp"
|
||||
#include "BBLStatusBar.hpp"
|
||||
#include "BBLStatusBarSend.hpp"
|
||||
|
||||
|
@ -92,7 +92,7 @@ protected:
|
|||
MsgButtonsHash m_buttons;
|
||||
CheckBox* m_checkbox_dsa{nullptr};
|
||||
};
|
||||
wxDECLARE_EVENT(EVT_CHECKBOX_CHANGE, wxCommandEvent);
|
||||
|
||||
|
||||
// Generic error dialog, used for displaying exceptions
|
||||
class ErrorDialog : public MsgDialog
|
||||
|
@ -371,6 +371,28 @@ private:
|
|||
wxString msg;
|
||||
};
|
||||
|
||||
class InputIpAddressDialog: public DPIDialog
|
||||
{
|
||||
public:
|
||||
wxString comfirm_before_enter_text;
|
||||
wxString comfirm_after_enter_text;
|
||||
std::string m_ip;
|
||||
Label* tip{nullptr};
|
||||
InputIpAddressDialog(wxWindow* parent = nullptr, wxString name = wxEmptyString);
|
||||
~InputIpAddressDialog();
|
||||
|
||||
Button* m_button_ok{nullptr};
|
||||
TextInput* m_input_ip{nullptr};
|
||||
bool isIp(std::string ipstr);
|
||||
void on_ok(wxMouseEvent& evt);
|
||||
void on_text(wxCommandEvent& evt);
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
};
|
||||
|
||||
|
||||
wxDECLARE_EVENT(EVT_CHECKBOX_CHANGE, wxCommandEvent);
|
||||
wxDECLARE_EVENT(EVT_ENTER_IP_ADDRESS, wxCommandEvent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ namespace GUI {
|
|||
wxDEFINE_EVENT(EVT_UPDATE_USER_MACHINE_LIST, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_PRINT_JOB_CANCEL, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_SEND_JOB_SUCCESS, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent);
|
||||
|
||||
|
||||
void SendToPrinterDialog::stripWhiteSpace(std::string& str)
|
||||
|
@ -531,6 +532,7 @@ void SendToPrinterDialog::init_model()
|
|||
void SendToPrinterDialog::init_bind()
|
||||
{
|
||||
Bind(wxEVT_TIMER, &SendToPrinterDialog::on_timer, this);
|
||||
Bind(EVT_CLEAR_IPADDRESS, &SendToPrinterDialog::clear_ip_address_config, this);
|
||||
}
|
||||
|
||||
void SendToPrinterDialog::init_timer()
|
||||
|
@ -651,12 +653,9 @@ void SendToPrinterDialog::on_ok(wxCommandEvent &event)
|
|||
m_send_job->has_sdcard = obj_->has_sdcard();
|
||||
m_send_job->set_project_name(m_current_project_name.utf8_string());
|
||||
|
||||
|
||||
m_send_job->on_success([this]() {
|
||||
//enable_prepare_mode = true;enable_prepare_mode
|
||||
m_status_bar->reset();
|
||||
prepare_mode();
|
||||
//EndModal(wxID_CLOSE);
|
||||
m_send_job->on_enter_ip_address([this, obj_]() {
|
||||
wxCommandEvent* evt = new wxCommandEvent(EVT_CLEAR_IPADDRESS);
|
||||
wxQueueEvent(this, evt);
|
||||
});
|
||||
|
||||
enable_prepare_mode = false;
|
||||
|
@ -664,6 +663,29 @@ 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();
|
||||
if (!dev) return;
|
||||
if (!dev->get_selected_machine()) return;
|
||||
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();
|
||||
}
|
||||
|
||||
void SendToPrinterDialog::update_user_machine_list()
|
||||
{
|
||||
NetworkAgent* m_agent = wxGetApp().getAgent();
|
||||
|
@ -845,6 +867,30 @@ 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();
|
||||
}
|
||||
|
||||
|
|
|
@ -157,6 +157,7 @@ protected:
|
|||
void update_printer_combobox(wxCommandEvent& event);
|
||||
void on_cancel(wxCloseEvent& event);
|
||||
void on_ok(wxCommandEvent& event);
|
||||
void clear_ip_address_config(wxCommandEvent& e);
|
||||
void on_refresh(wxCommandEvent& event);
|
||||
void on_print_job_cancel(wxCommandEvent& evt);
|
||||
void set_default();
|
||||
|
@ -170,6 +171,7 @@ protected:
|
|||
std::vector<std::string> sort_string(std::vector<std::string> strArray);
|
||||
};
|
||||
|
||||
wxDECLARE_EVENT(EVT_CLEAR_IPADDRESS, wxCommandEvent);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ namespace BBL {
|
|||
#define BAMBU_NETWORK_ERR_GET_MODEL_PUBLISH_PAGE -26
|
||||
#define BAMBU_NETWORK_ERR_GET_MODEL_MALL_HOME_PAGE -27
|
||||
#define BAMBU_NETWORK_ERR_GET_USER_INFO -28
|
||||
|
||||
#define BAMBU_NETWORK_ERR_WRONG_IP_ADDRESS -29
|
||||
|
||||
#define BAMBU_NETWORK_LIBRARY "bambu_networking"
|
||||
#define BAMBU_NETWORK_AGENT_NAME "bambu_network_agent"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue