Proper support of Bambu LAN printers (#8256)
**The latest download link can be found from the "Checks" tab above or [here](https://github.com/SoftFever/OrcaSlicer/pull/8256/checks). There should be an "artifact" dropdown on top of that page once the build is completed.** This PR solves the following problems: - Bind printers in different subnet - Binded LAN printers are not automatically connected when switching to Device tab    Few improtant things to know: The automatic printer info detection (ie, the step in the first image) doesn't work on MacOS, when you click "Connect" you will immediately be prompted to the second image to enter the printer details. (I don't know why but Bambu does not provide this capability on MacOS for their network plugin) AFAIK, P1 series do not support automatic printer info detection (as tested by @SoftFever and myself), so the first step is gauranteed to fail, which is unfortunate but expected. Simply click the "Manual Setup" button (which will appear after clicking the "Connect" button then wait for a while) and enter the printer detail and you should be good to go. If anything entered wrong, you could simply unbind the printer and do it all over again. I know current binding flow is not very user-friendly, but consider how rare this will be used, I think it's OK. Given the current situation this is the best I could do with the closed-source Bambu network plugin. I only have a P1 so I couldn't throughly test this PR. Please if you have different printers and home network configurations, your feedback are valuable to help validating and improving this PR, thanks in advance! Fix #6169 Fix #8097
This commit is contained in:
commit
658c4f096e
8 changed files with 249 additions and 59 deletions
|
@ -607,6 +607,19 @@ std::string AppConfig::load()
|
|||
for (auto& j_model : it.value()) {
|
||||
m_printer_settings[j_model["machine"].get<std::string>()] = j_model;
|
||||
}
|
||||
} else if (it.key() == "local_machines") {
|
||||
for (auto m = it.value().begin(); m != it.value().end(); ++m) {
|
||||
const auto& p = m.value();
|
||||
BBLocalMachine local_machine;
|
||||
local_machine.dev_id = m.key();
|
||||
if (p.contains("dev_name"))
|
||||
local_machine.dev_name = p["dev_name"].get<std::string>();
|
||||
if (p.contains("dev_ip"))
|
||||
local_machine.dev_ip = p["dev_ip"].get<std::string>();
|
||||
if (p.contains("printer_type"))
|
||||
local_machine.printer_type = p["printer_type"].get<std::string>();
|
||||
m_local_machines[local_machine.dev_id] = local_machine;
|
||||
}
|
||||
} else {
|
||||
if (it.value().is_object()) {
|
||||
for (auto iter = it.value().begin(); iter != it.value().end(); iter++) {
|
||||
|
@ -783,6 +796,14 @@ void AppConfig::save()
|
|||
for (const auto& preset : m_printer_settings) {
|
||||
j["orca_presets"].push_back(preset.second);
|
||||
}
|
||||
for (const auto& local_machine : m_local_machines) {
|
||||
json m_json;
|
||||
m_json["dev_name"] = local_machine.second.dev_name;
|
||||
m_json["dev_ip"] = local_machine.second.dev_ip;
|
||||
m_json["printer_type"] = local_machine.second.printer_type;
|
||||
|
||||
j["local_machines"][local_machine.first] = m_json;
|
||||
}
|
||||
boost::nowide::ofstream c;
|
||||
c.open(path_pid, std::ios::out | std::ios::trunc);
|
||||
c << std::setw(4) << j << std::endl;
|
||||
|
@ -791,7 +812,7 @@ void AppConfig::save()
|
|||
// WIN32 specific: The final "rename_file()" call is not safe in case of an application crash, there is no atomic "rename file" API
|
||||
// provided by Windows (sic!). Therefore we save a MD5 checksum to be able to verify file corruption. In addition,
|
||||
// we save the config file into a backup first before moving it to the final destination.
|
||||
c << appconfig_md5_hash_line({j.dump(4)});
|
||||
c << appconfig_md5_hash_line(j.dump(4));
|
||||
#endif
|
||||
|
||||
c.close();
|
||||
|
|
|
@ -24,6 +24,22 @@ using namespace nlohmann;
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
|
||||
// Connected LAN mode BambuLab printer
|
||||
struct BBLocalMachine
|
||||
{
|
||||
std::string dev_name;
|
||||
std::string dev_ip;
|
||||
std::string dev_id; /* serial number */
|
||||
std::string printer_type; /* model_id */
|
||||
|
||||
bool operator==(const BBLocalMachine& other) const
|
||||
{
|
||||
return dev_name == other.dev_name && dev_ip == other.dev_ip && dev_id == other.dev_id && printer_type == other.printer_type;
|
||||
}
|
||||
bool operator!=(const BBLocalMachine& other) const { return !operator==(other); }
|
||||
};
|
||||
|
||||
class AppConfig
|
||||
{
|
||||
public:
|
||||
|
@ -152,7 +168,8 @@ public:
|
|||
{
|
||||
auto it = m_storage.find(section);
|
||||
if (it != m_storage.end()) {
|
||||
it->second.erase(key);
|
||||
it->second.erase(key);
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -194,11 +211,34 @@ public:
|
|||
return "";
|
||||
return m_printer_settings[printer][name];
|
||||
}
|
||||
std::string set_printer_setting(std::string printer, std::string name, std::string value) {
|
||||
return m_printer_settings[printer][name] = value;
|
||||
m_dirty = true;
|
||||
void set_printer_setting(std::string printer, std::string name, std::string value) {
|
||||
m_printer_settings[printer][name] = value;
|
||||
m_dirty = true;
|
||||
}
|
||||
|
||||
const std::map<std::string, BBLocalMachine>& get_local_machines() const { return m_local_machines; }
|
||||
void erase_local_machine(std::string dev_id)
|
||||
{
|
||||
auto it = m_local_machines.find(dev_id);
|
||||
if (it != m_local_machines.end()) {
|
||||
m_local_machines.erase(it);
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
void update_local_machine(const BBLocalMachine& machine)
|
||||
{
|
||||
auto it = m_local_machines.find(machine.dev_id);
|
||||
if (it != m_local_machines.end()) {
|
||||
const auto& current = it->second;
|
||||
if (machine != current) {
|
||||
m_local_machines[machine.dev_id] = machine;
|
||||
m_dirty = true;
|
||||
}
|
||||
} else {
|
||||
m_local_machines[machine.dev_id] = machine;
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<std::string> &get_filament_presets() const { return m_filament_presets; }
|
||||
void set_filament_presets(const std::vector<std::string> &filament_presets){
|
||||
|
@ -335,6 +375,8 @@ private:
|
|||
std::vector<std::string> m_filament_colors;
|
||||
|
||||
std::vector<PrinterCaliInfo> m_printer_cali_infos;
|
||||
|
||||
std::map<std::string, BBLocalMachine> m_local_machines;
|
||||
};
|
||||
|
||||
} // namespace Slic3r
|
||||
|
|
|
@ -431,7 +431,7 @@ std::string MachineObject::get_ftp_folder()
|
|||
return DeviceManager::get_ftp_folder(printer_type);
|
||||
}
|
||||
|
||||
std::string MachineObject::get_access_code()
|
||||
std::string MachineObject::get_access_code() const
|
||||
{
|
||||
if (get_user_access_code().empty())
|
||||
return access_code;
|
||||
|
@ -445,6 +445,7 @@ void MachineObject::set_access_code(std::string code, bool only_refresh)
|
|||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config && !code.empty()) {
|
||||
GUI::wxGetApp().app_config->set_str("access_code", dev_id, code);
|
||||
DeviceManager::update_local_machine(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -466,11 +467,12 @@ void MachineObject::set_user_access_code(std::string code, bool only_refresh)
|
|||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config && !code.empty()) {
|
||||
GUI::wxGetApp().app_config->set_str("user_access_code", dev_id, code);
|
||||
DeviceManager::update_local_machine(*this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::string MachineObject::get_user_access_code()
|
||||
std::string MachineObject::get_user_access_code() const
|
||||
{
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config) {
|
||||
|
@ -479,7 +481,7 @@ std::string MachineObject::get_user_access_code()
|
|||
return "";
|
||||
}
|
||||
|
||||
bool MachineObject::is_lan_mode_printer()
|
||||
bool MachineObject::is_lan_mode_printer() const
|
||||
{
|
||||
bool result = false;
|
||||
if (!dev_connection_type.empty() && dev_connection_type == "lan")
|
||||
|
@ -4822,6 +4824,7 @@ int MachineObject::parse_json(std::string payload, bool key_field_only)
|
|||
if (diff.count() > 10.0f) {
|
||||
BOOST_LOG_TRIVIAL(trace) << "parse_json timeout = " << diff.count();
|
||||
}
|
||||
DeviceManager::update_local_machine(*this);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -5263,6 +5266,49 @@ bool DeviceManager::key_field_only = false;
|
|||
DeviceManager::DeviceManager(NetworkAgent* agent)
|
||||
{
|
||||
m_agent = agent;
|
||||
|
||||
// Load saved local machines
|
||||
if (agent) {
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
const auto local_machines = config->get_local_machines();
|
||||
for (auto& it : local_machines) {
|
||||
const auto& m = it.second;
|
||||
MachineObject* obj = new MachineObject(m_agent, m.dev_name, m.dev_id, m.dev_ip);
|
||||
obj->printer_type = m.printer_type;
|
||||
obj->dev_connection_type = "lan";
|
||||
obj->bind_state = "free";
|
||||
obj->bind_sec_link = "secure";
|
||||
obj->m_is_online = true;
|
||||
obj->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||
obj->set_access_code(config->get("access_code", m.dev_id), false);
|
||||
obj->set_user_access_code(config->get("user_access_code", m.dev_id), false);
|
||||
if (obj->has_access_right()) {
|
||||
localMachineList.insert(std::make_pair(m.dev_id, obj));
|
||||
} else {
|
||||
config->erase_local_machine(m.dev_id);
|
||||
delete obj;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceManager::update_local_machine(const MachineObject& m)
|
||||
{
|
||||
AppConfig* config = GUI::wxGetApp().app_config;
|
||||
if (config) {
|
||||
if (m.is_lan_mode_printer()) {
|
||||
if (m.has_access_right()) {
|
||||
BBLocalMachine local_machine;
|
||||
local_machine.dev_id = m.dev_id;
|
||||
local_machine.dev_name = m.dev_name;
|
||||
local_machine.dev_ip = m.dev_ip;
|
||||
local_machine.printer_type = m.printer_type;
|
||||
config->update_local_machine(local_machine);
|
||||
}
|
||||
} else {
|
||||
config->erase_local_machine(m.dev_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DeviceManager::~DeviceManager()
|
||||
|
@ -5443,24 +5489,35 @@ void DeviceManager::on_machine_alive(std::string json_str)
|
|||
|
||||
BOOST_LOG_TRIVIAL(info) << "SsdpDiscovery::New Machine, ip = " << Slic3r::GUI::wxGetApp().format_IP(dev_ip) << ", printer_name= " << dev_name << ", printer_type = " << printer_type_str << ", signal = " << printer_signal;
|
||||
}
|
||||
update_local_machine(*obj);
|
||||
}
|
||||
catch (...) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
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* DeviceManager::insert_local_device(const BBLocalMachine& machine, 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");
|
||||
auto it = localMachineList.find(machine.dev_id);
|
||||
if (it != localMachineList.end()) {
|
||||
obj = it->second;
|
||||
} else {
|
||||
obj = new MachineObject(m_agent, machine.dev_name, machine.dev_id, machine.dev_ip);
|
||||
localMachineList.insert(std::make_pair(machine.dev_id, obj));
|
||||
}
|
||||
obj->printer_type = MachineObject::parse_printer_type(machine.printer_type);
|
||||
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->last_alive = Slic3r::Utils::get_current_time_utc();
|
||||
obj->set_access_code(access_code, false);
|
||||
obj->set_user_access_code(access_code, false);
|
||||
|
||||
update_local_machine(*obj);
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
@ -5887,8 +5944,13 @@ std::map<std::string ,MachineObject*> DeviceManager::get_local_machine_list()
|
|||
|
||||
void DeviceManager::load_last_machine()
|
||||
{
|
||||
if (userMachineList.empty()) return;
|
||||
|
||||
if (userMachineList.empty()) {
|
||||
// Orca: connect LAN printers instead
|
||||
const auto local_machine = std::find_if(localMachineList.begin(), localMachineList.end(), [](const std::pair<std::string, MachineObject*>& it) -> bool { return it.second->has_access_right();});
|
||||
if (local_machine != localMachineList.end()) {
|
||||
this->set_selected_machine(local_machine->second->dev_id);
|
||||
}
|
||||
}
|
||||
else if (userMachineList.size() == 1) {
|
||||
this->set_selected_machine(userMachineList.begin()->second->dev_id);
|
||||
} else {
|
||||
|
|
|
@ -54,6 +54,7 @@ using namespace nlohmann;
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
struct BBLocalMachine;
|
||||
class SecondaryCheckDialog;
|
||||
enum PrinterArch {
|
||||
ARCH_CORE_XY,
|
||||
|
@ -426,14 +427,14 @@ public:
|
|||
std::string dev_connection_name; /* lan | eth */
|
||||
void set_dev_ip(std::string ip) {dev_ip = ip;}
|
||||
std::string get_ftp_folder();
|
||||
bool has_access_right() { return !get_access_code().empty(); }
|
||||
std::string get_access_code();
|
||||
bool has_access_right() const { return !get_access_code().empty(); }
|
||||
std::string get_access_code() const;
|
||||
|
||||
void set_access_code(std::string code, bool only_refresh = true);
|
||||
void set_user_access_code(std::string code, bool only_refresh = true);
|
||||
void erase_user_access_code();
|
||||
std::string get_user_access_code();
|
||||
bool is_lan_mode_printer();
|
||||
std::string get_user_access_code() const;
|
||||
bool is_lan_mode_printer() const;
|
||||
|
||||
//PRINTER_TYPE printer_type = PRINTER_3DPrinter_UKNOWN;
|
||||
std::string printer_type; /* model_id */
|
||||
|
@ -1032,7 +1033,7 @@ public:
|
|||
|
||||
/* create machine or update machine properties */
|
||||
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);
|
||||
MachineObject* insert_local_device(const BBLocalMachine& machine, std::string connection_type, std::string bind_state, std::string version, std::string access_code);
|
||||
/* disconnect all machine connections */
|
||||
void disconnect_all();
|
||||
int query_bind_status(std::string &msg);
|
||||
|
@ -1085,6 +1086,8 @@ public:
|
|||
static std::vector<std::string> get_compatible_machine(std::string type_str);
|
||||
static boost::bimaps::bimap<std::string, std::string> get_all_model_id_with_name();
|
||||
static std::string load_gcode(std::string type_str, std::string gcode_file);
|
||||
|
||||
static void update_local_machine(const MachineObject& m);
|
||||
};
|
||||
|
||||
// change the opacity
|
||||
|
|
|
@ -1695,11 +1695,11 @@ void GUI_App::init_networking_callbacks()
|
|||
event.SetString(obj->dev_id);
|
||||
GUI::wxGetApp().sidebar().load_ams_list(obj->dev_id, obj);
|
||||
} else if (state == ConnectStatus::ConnectStatusFailed) {
|
||||
obj->set_access_code("");
|
||||
obj->erase_user_access_code();
|
||||
m_device_manager->set_selected_machine("", true);
|
||||
wxString text;
|
||||
if (msg == "5") {
|
||||
obj->set_access_code("");
|
||||
obj->erase_user_access_code();
|
||||
text = wxString::Format(_L("Incorrect password"));
|
||||
wxGetApp().show_dialog(text);
|
||||
} else {
|
||||
|
@ -1708,9 +1708,6 @@ void GUI_App::init_networking_callbacks()
|
|||
}
|
||||
event.SetInt(-1);
|
||||
} else if (state == ConnectStatus::ConnectStatusLost) {
|
||||
obj->set_access_code("");
|
||||
obj->erase_user_access_code();
|
||||
m_device_manager->localMachineList.erase(obj->dev_id);
|
||||
m_device_manager->set_selected_machine("", true);
|
||||
event.SetInt(-1);
|
||||
BOOST_LOG_TRIVIAL(info) << "set_on_local_connect_fn: state = lost";
|
||||
|
|
|
@ -1577,6 +1577,18 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
|
|||
m_input_modelID_area->Add(0, 0, 0, wxLEFT, FromDIP(16));
|
||||
m_input_modelID_area->Add(m_input_modelID, 0, wxALIGN_CENTER, 0);
|
||||
|
||||
auto* tips_printer_name = new Label(ip_input_bot_panel, _L("Printer name"));
|
||||
|
||||
m_input_printer_name = new TextInput(ip_input_bot_panel, wxEmptyString, wxEmptyString);
|
||||
m_input_printer_name->Bind(wxEVT_TEXT, &InputIpAddressDialog::on_text, this);
|
||||
m_input_printer_name->SetMinSize(wxSize(FromDIP(352), FromDIP(28)));
|
||||
m_input_printer_name->SetMaxSize(wxSize(FromDIP(352), FromDIP(28)));
|
||||
|
||||
m_input_bot_sizer->Add(tips_printer_name, 0, wxRIGHT | wxEXPAND, FromDIP(18));
|
||||
m_input_bot_sizer->Add(0, 0, 0, wxTOP, FromDIP(4));
|
||||
m_input_bot_sizer->Add(m_input_printer_name, 0, wxRIGHT | wxEXPAND, FromDIP(18));
|
||||
m_input_bot_sizer->Add(0, 0, 0, wxTOP, FromDIP(4));
|
||||
|
||||
m_input_bot_sizer->Add(m_input_sn_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
|
||||
m_input_bot_sizer->Add(0, 0, 0, wxTOP, FromDIP(4));
|
||||
m_input_bot_sizer->Add(m_input_modelID_area, 0, wxRIGHT | wxEXPAND, FromDIP(18));
|
||||
|
@ -1623,6 +1635,24 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
|
|||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
|
||||
m_button_manual_setup = new Button(this, _L("Manual Setup"));
|
||||
m_button_manual_setup->SetBackgroundColor(btn_bg_green);
|
||||
m_button_manual_setup->SetBorderColor(*wxWHITE);
|
||||
m_button_manual_setup->SetTextColor(wxColour(0xFFFFFE));
|
||||
m_button_manual_setup->SetFont(Label::Body_12);
|
||||
m_button_manual_setup->SetSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_manual_setup->SetMinSize(wxSize(FromDIP(58), FromDIP(24)));
|
||||
m_button_manual_setup->SetCornerRadius(FromDIP(12));
|
||||
m_button_manual_setup->Bind(wxEVT_LEFT_DOWN, [this](wxMouseEvent&) {
|
||||
wxCommandEvent event(EVT_CHECK_IP_ADDRESS_LAYOUT);
|
||||
event.SetEventObject(this);
|
||||
event.SetInt(1);
|
||||
wxPostEvent(this, event);
|
||||
});
|
||||
m_button_manual_setup->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_manual_setup->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_manual_setup->Hide();
|
||||
|
||||
/*auto m_button_cancel = new Button(this, _L("Close"));
|
||||
m_button_cancel->SetBackgroundColor(btn_bg_white);
|
||||
m_button_cancel->SetBorderColor(wxColour(38, 46, 48));
|
||||
|
@ -1636,6 +1666,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
|
|||
});*/
|
||||
|
||||
m_sizer_button->AddStretchSpacer();
|
||||
m_sizer_button->Add(m_button_manual_setup, 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->Layout();
|
||||
|
@ -1760,6 +1791,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
|
|||
Bind(EVT_UPDATE_TEXT_MSG, &InputIpAddressDialog::update_test_msg_event, this);
|
||||
Bind(EVT_CHECK_IP_ADDRESS_LAYOUT, [this](auto& e) {
|
||||
int mode = e.GetInt();
|
||||
update_test_msg(wxEmptyString, true);
|
||||
switch_input_panel(mode);
|
||||
Layout();
|
||||
Fit();
|
||||
|
@ -1768,6 +1800,7 @@ InputIpAddressDialog::InputIpAddressDialog(wxWindow *parent)
|
|||
|
||||
void InputIpAddressDialog::switch_input_panel(int index)
|
||||
{
|
||||
m_button_manual_setup->Hide();
|
||||
if (index == 0) {
|
||||
ip_input_top_panel->Show();
|
||||
ip_input_bot_panel->Hide();
|
||||
|
@ -1809,6 +1842,7 @@ void InputIpAddressDialog::set_machine_obj(MachineObject* obj)
|
|||
m_obj = obj;
|
||||
m_input_ip->GetTextCtrl()->SetLabelText(m_obj->dev_ip);
|
||||
m_input_access_code->GetTextCtrl()->SetLabelText(m_obj->get_access_code());
|
||||
m_input_printer_name->GetTextCtrl()->SetLabelText(m_obj->dev_name);
|
||||
|
||||
std::string img_str = DeviceManager::get_printer_diagram_img(m_obj->printer_type);
|
||||
auto diagram_bmp = create_scaled_bitmap(img_str + "_en", this, 198);
|
||||
|
@ -1852,6 +1886,12 @@ void InputIpAddressDialog::update_test_msg(wxString msg,bool connected)
|
|||
m_test_wrong_msg->SetLabelText(msg);
|
||||
m_test_wrong_msg->SetMinSize(wxSize(FromDIP(352), -1));
|
||||
m_test_wrong_msg->SetMaxSize(wxSize(FromDIP(352), -1));
|
||||
if (current_input_index == 0) {
|
||||
m_button_manual_setup->Show();
|
||||
m_button_manual_setup->Enable();
|
||||
}
|
||||
wxCommandEvent e;
|
||||
on_text(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1882,7 +1922,10 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
|||
m_trouble_shoot->Hide();
|
||||
std::string str_ip = m_input_ip->GetTextCtrl()->GetValue().ToStdString();
|
||||
std::string str_access_code = m_input_access_code->GetTextCtrl()->GetValue().ToStdString();
|
||||
std::string str_sn = m_input_sn->GetTextCtrl()->GetValue().ToStdString();
|
||||
std::string str_name = m_input_printer_name->GetTextCtrl()->GetValue().Strip(wxString::both).ToStdString();
|
||||
// Serial number should not contain lower case letters, and bambu_network plugin crashes
|
||||
// if user entered the wrong serial number, so we call `Upper()` here.
|
||||
std::string str_sn = m_input_sn->GetTextCtrl()->GetValue().Strip(wxString::both).Upper().ToStdString();
|
||||
std::string str_model_id = "";
|
||||
|
||||
auto it = m_models_map.right.find(m_input_modelID->GetStringSelection().ToStdString());
|
||||
|
@ -1890,6 +1933,9 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
|||
str_model_id = it->get_left();
|
||||
}
|
||||
|
||||
m_button_manual_setup->Enable(false);
|
||||
m_button_manual_setup->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_manual_setup->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->Enable(false);
|
||||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
|
@ -1897,7 +1943,7 @@ void InputIpAddressDialog::on_ok(wxMouseEvent& evt)
|
|||
Refresh();
|
||||
Layout();
|
||||
Fit();
|
||||
m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code, str_sn, str_model_id));
|
||||
m_thread = new boost::thread(boost::bind(&InputIpAddressDialog::workerThreadFunc, this, str_ip, str_access_code, str_sn, str_model_id, str_name));
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::update_test_msg_event(wxCommandEvent& evt)
|
||||
|
@ -1918,7 +1964,7 @@ void InputIpAddressDialog::post_update_test_msg(wxString text, bool beconnect)
|
|||
wxPostEvent(this, event);
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id)
|
||||
void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id, std::string name)
|
||||
{
|
||||
post_update_test_msg(_L("connecting..."), true);
|
||||
|
||||
|
@ -1934,10 +1980,11 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_
|
|||
|
||||
} else {
|
||||
result = 0;
|
||||
detectData.dev_name = sn;
|
||||
detectData.model_id = model_id;
|
||||
detectData.dev_name = name;
|
||||
detectData.dev_id = sn;
|
||||
detectData.connect_type = "lan";
|
||||
detectData.connect_type = "free";
|
||||
detectData.bind_state = "free";
|
||||
}
|
||||
|
||||
if (result < 0) {
|
||||
|
@ -1969,27 +2016,34 @@ void InputIpAddressDialog::workerThreadFunc(std::string str_ip, std::string str_
|
|||
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);
|
||||
CallAfter([this, detectData, str_ip, str_access_code]() {
|
||||
DeviceManager* dev = wxGetApp().getDeviceManager();
|
||||
BBLocalMachine machine;
|
||||
machine.dev_name = detectData.dev_name;
|
||||
machine.dev_ip = str_ip;
|
||||
machine.dev_id = detectData.dev_id;
|
||||
machine.printer_type = detectData.model_id;
|
||||
m_obj = dev->insert_local_device(machine, detectData.connect_type, detectData.bind_state, detectData.version, str_access_code);
|
||||
|
||||
|
||||
if (m_obj) {
|
||||
m_obj->set_user_access_code(str_access_code);
|
||||
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->dev_id);
|
||||
}
|
||||
if (m_obj) {
|
||||
m_obj->set_user_access_code(str_access_code);
|
||||
wxGetApp().getDeviceManager()->set_selected_machine(m_obj->dev_id, true);
|
||||
}
|
||||
|
||||
|
||||
closeCount = 1;
|
||||
closeCount = 1;
|
||||
|
||||
post_update_test_msg(wxEmptyString, true);
|
||||
post_update_test_msg(wxString::Format(_L("Connecting to printer... The dialog will close later"), closeCount), true);
|
||||
post_update_test_msg(wxEmptyString, true);
|
||||
post_update_test_msg(wxString::Format(_L("Connecting to printer... The dialog will close later"), closeCount), true);
|
||||
|
||||
#ifdef __APPLE__
|
||||
wxCommandEvent event(EVT_CLOSE_IPADDRESS_DLG);
|
||||
wxPostEvent(this, event);
|
||||
wxCommandEvent event(EVT_CLOSE_IPADDRESS_DLG);
|
||||
wxPostEvent(this, event);
|
||||
#else
|
||||
closeTimer->Start(1000);
|
||||
closeTimer->Start(1000);
|
||||
#endif
|
||||
});
|
||||
}
|
||||
|
||||
void InputIpAddressDialog::OnTimer(wxTimerEvent& event) {
|
||||
|
@ -2032,7 +2086,8 @@ void InputIpAddressDialog::on_text(wxCommandEvent &evt)
|
|||
{
|
||||
auto str_ip = m_input_ip->GetTextCtrl()->GetValue();
|
||||
auto str_access_code = m_input_access_code->GetTextCtrl()->GetValue();
|
||||
auto str_sn = m_input_sn->GetTextCtrl()->GetValue();
|
||||
auto str_name = m_input_printer_name->GetTextCtrl()->GetValue().Strip(wxString::both);
|
||||
auto str_sn = m_input_sn->GetTextCtrl()->GetValue().Strip(wxString::both);
|
||||
bool invalid_access_code = true;
|
||||
|
||||
for (char c : str_access_code) {
|
||||
|
@ -2042,29 +2097,32 @@ void InputIpAddressDialog::on_text(wxCommandEvent &evt)
|
|||
}
|
||||
}
|
||||
|
||||
const auto enable_btn = [](Button* btn, bool enabled) {
|
||||
btn->Enable(enabled);
|
||||
if (enabled) {
|
||||
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed), std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
|
||||
btn->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
|
||||
btn->SetBackgroundColor(btn_bg_green);
|
||||
} else {
|
||||
btn->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
btn->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
}
|
||||
};
|
||||
|
||||
if (isIp(str_ip.ToStdString()) && str_access_code.Length() == 8 && invalid_access_code) {
|
||||
m_button_ok->Enable(true);
|
||||
StateColor btn_bg_green(std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed), std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
|
||||
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
|
||||
m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
|
||||
m_button_ok->SetBackgroundColor(btn_bg_green);
|
||||
enable_btn(m_button_manual_setup, true);
|
||||
enable_btn(m_button_ok, true);
|
||||
} else {
|
||||
m_button_ok->Enable(false);
|
||||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
enable_btn(m_button_manual_setup, false);
|
||||
enable_btn(m_button_ok, false);
|
||||
}
|
||||
|
||||
if (current_input_index == 1){
|
||||
if (str_sn.length() == 15) {
|
||||
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),
|
||||
std::pair<wxColour, int>(AMS_CONTROL_BRAND_COLOUR, StateColor::Normal));
|
||||
m_button_ok->SetTextColor(StateColor::darkModeColorFor("#FFFFFE"));
|
||||
m_button_ok->SetBackgroundColor(btn_bg_green);
|
||||
if (!str_name.IsEmpty() && str_sn.length() == 15) {
|
||||
enable_btn(m_button_ok, true);
|
||||
} else {
|
||||
m_button_ok->Enable(false);
|
||||
m_button_ok->SetBackgroundColor(wxColour(0x90, 0x90, 0x90));
|
||||
m_button_ok->SetBorderColor(wxColour(0x90, 0x90, 0x90));
|
||||
enable_btn(m_button_ok, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -293,6 +293,7 @@ public:
|
|||
wxPanel * ip_input_top_panel{ nullptr };
|
||||
wxPanel * ip_input_bot_panel{ nullptr };
|
||||
Button* m_button_ok{ nullptr };
|
||||
Button* m_button_manual_setup{ nullptr };
|
||||
Label* m_tips_ip{ nullptr };
|
||||
Label* m_tips_access_code{ nullptr };
|
||||
Label* m_tips_sn{nullptr};
|
||||
|
@ -301,6 +302,7 @@ public:
|
|||
Label* m_test_wrong_msg{ nullptr };
|
||||
TextInput* m_input_ip{ nullptr };
|
||||
TextInput* m_input_access_code{ nullptr };
|
||||
TextInput* m_input_printer_name{ nullptr };
|
||||
TextInput* m_input_sn{ nullptr };
|
||||
ComboBox* m_input_modelID{ nullptr };
|
||||
wxStaticBitmap* m_img_help{ nullptr };
|
||||
|
@ -327,7 +329,7 @@ public:
|
|||
void on_ok(wxMouseEvent& evt);
|
||||
void update_test_msg_event(wxCommandEvent &evt);
|
||||
void post_update_test_msg(wxString text, bool beconnect);
|
||||
void workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id);
|
||||
void workerThreadFunc(std::string str_ip, std::string str_access_code, std::string sn, std::string model_id, std::string name);
|
||||
void OnTimer(wxTimerEvent& event);
|
||||
void on_text(wxCommandEvent& evt);
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
|
|
|
@ -741,6 +741,11 @@ void SelectMachinePopup::update_user_devices()
|
|||
op->Bind(EVT_UNBIND_MACHINE, [this, dev, mobj](wxCommandEvent& e) {
|
||||
dev->set_selected_machine("");
|
||||
if (mobj) {
|
||||
AppConfig* config = wxGetApp().app_config;
|
||||
if (config) {
|
||||
config->erase_local_machine(mobj->dev_id);
|
||||
}
|
||||
|
||||
mobj->set_access_code("");
|
||||
mobj->erase_user_access_code();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue