diff --git a/src/slic3r/GUI/DeviceManager.cpp b/src/slic3r/GUI/DeviceManager.cpp index 6d926c135d..d4ece5ebbe 100644 --- a/src/slic3r/GUI/DeviceManager.cpp +++ b/src/slic3r/GUI/DeviceManager.cpp @@ -6750,28 +6750,19 @@ std::map DeviceManager::get_local_machine_list() void DeviceManager::load_last_machine() { - if (userMachineList.empty()) { - // Orca: connect LAN printers instead - const auto local_machine = std::find_if(localMachineList.begin(), localMachineList.end(), [](const std::pair& 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); + // Get all available machines, include cloud machines and lan machines that have access right + auto all_machines = get_my_machine_list(); + if (all_machines.empty()) + return; + + // Then connect to the machine we last selected if available + const std::string last_monitor_machine = m_agent ? m_agent->get_user_selected_machine() : ""; + const auto last_machine = all_machines.find(last_monitor_machine); + if (last_machine != all_machines.end()) { + this->set_selected_machine(last_machine->second->dev_id); } else { - if (m_agent) { - std::string last_monitor_machine = m_agent->get_user_selected_machine(); - bool found = false; - for (auto it = userMachineList.begin(); it != userMachineList.end(); it++) { - if (last_monitor_machine == it->first) { - this->set_selected_machine(last_monitor_machine); - found = true; - } - } - if (!found) - this->set_selected_machine(userMachineList.begin()->second->dev_id); - } + // If not, then select the first available one + this->set_selected_machine(all_machines.begin()->second->dev_id); } } diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index e1452016f4..899bc33bc6 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1728,16 +1728,20 @@ 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) { + // Orca: avoid showing same error message multiple times until next connection attempt. + const auto already_disconnected = m_device_manager->selected_machine.empty(); 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 { - text = wxString::Format(_L("Connect %s failed! [SN:%s, code=%s]"), from_u8(obj->dev_name), obj->dev_id, msg); - wxGetApp().show_dialog(text); + if (!already_disconnected) { + 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 { + text = wxString::Format(_L("Connect %s failed! [SN:%s, code=%s]"), from_u8(obj->dev_name), obj->dev_id, msg); + wxGetApp().show_dialog(text); + } } event.SetInt(-1); } else if (state == ConnectStatus::ConnectStatusLost) { @@ -4196,6 +4200,10 @@ void GUI_App::enable_user_preset_folder(bool enable) void GUI_App::on_set_selected_machine(wxCommandEvent &evt) { + // Orca: do not connect to default device during app startup, because some of the lan machines might not online yet + // and user will be prompted by several "Connect XXX failed" error message. + return; + DeviceManager* dev = Slic3r::GUI::wxGetApp().getDeviceManager(); if (dev) { dev->set_selected_machine(m_agent->get_user_selected_machine()); diff --git a/src/slic3r/GUI/SelectMachine.cpp b/src/slic3r/GUI/SelectMachine.cpp index a164a6fb60..64635cb593 100644 --- a/src/slic3r/GUI/SelectMachine.cpp +++ b/src/slic3r/GUI/SelectMachine.cpp @@ -2373,6 +2373,10 @@ void SelectMachineDialog::update_user_printer() m_comboBox_printer->Set(machine_list_name); MachineObject* obj = dev->get_selected_machine(); + if (!obj) { + dev->load_last_machine(); + obj = dev->get_selected_machine(); + } if (obj) { if (obj->is_lan_mode_printer() && !obj->has_access_right()) { @@ -2410,13 +2414,10 @@ void SelectMachineDialog::update_user_printer() for (auto i = 0; i < m_list.size(); i++) { if (m_list[i]->dev_id == m_printer_last_select) { - - if (obj && !obj->get_lan_mode_connection_state()) { - m_comboBox_printer->SetSelection(i); - wxCommandEvent event(wxEVT_COMBOBOX); - event.SetEventObject(m_comboBox_printer); - wxPostEvent(m_comboBox_printer, event); - } + m_comboBox_printer->SetSelection(i); + wxCommandEvent event(wxEVT_COMBOBOX); + event.SetEventObject(m_comboBox_printer); + wxPostEvent(m_comboBox_printer, event); } } } @@ -2594,7 +2595,7 @@ void SelectMachineDialog::on_selection_changed(wxCommandEvent &event) } } - if (obj) { + if (obj && !obj->get_lan_mode_connection_state()) { obj->command_get_version(); obj->command_request_push_all(); if (!dev->get_selected_machine()) { diff --git a/src/slic3r/GUI/SendToPrinter.cpp b/src/slic3r/GUI/SendToPrinter.cpp index dd435d2474..f8cc7fa3a3 100644 --- a/src/slic3r/GUI/SendToPrinter.cpp +++ b/src/slic3r/GUI/SendToPrinter.cpp @@ -917,6 +917,11 @@ void SendToPrinterDialog::update_user_printer() m_comboBox_printer->Set(machine_list_name); MachineObject* obj = dev->get_selected_machine(); + if (!obj) { + dev->load_last_machine(); + obj = dev->get_selected_machine(); + } + if (obj) { m_printer_last_select = obj->dev_id; } else {