diff --git a/src/slic3r/GUI/DeviceCore/DevManager.cpp b/src/slic3r/GUI/DeviceCore/DevManager.cpp index 4199530a9f..16855c6bf9 100644 --- a/src/slic3r/GUI/DeviceCore/DevManager.cpp +++ b/src/slic3r/GUI/DeviceCore/DevManager.cpp @@ -445,18 +445,22 @@ namespace Slic3r bool DeviceManager::set_selected_machine(std::string dev_id) { - BOOST_LOG_TRIVIAL(info) << "set_selected_machine=" << dev_id; + BOOST_LOG_TRIVIAL(info) << "set_selected_machine=" << dev_id + << " cur_selected=" << selected_machine; auto my_machine_list = get_my_machine_list(); auto it = my_machine_list.find(dev_id); - // disconnect last + // disconnect last if dev_id difference from previous one auto last_selected = my_machine_list.find(selected_machine); - if (last_selected != my_machine_list.end()) + if (last_selected != my_machine_list.end() && selected_machine != dev_id) { if (last_selected->second->connection_type() == "lan") { m_agent->disconnect_printer(); } + else if (last_selected->second->connection_type() == "cloud") { + m_agent->set_user_selected_machine(""); + } } // connect curr @@ -464,8 +468,12 @@ namespace Slic3r { if (selected_machine == dev_id) { + // same dev_id, cloud => reset update time if (it->second->connection_type() != "lan") { + BOOST_LOG_TRIVIAL(info) << "set_selected_machine: same cloud machine, dev_id =" << dev_id + << ", just reset update time"; + // only reset update time it->second->reset_update_time(); @@ -474,8 +482,12 @@ namespace Slic3r return true; } + // same dev_id, lan => disconnect and reconnect else { + BOOST_LOG_TRIVIAL(info) << "set_selected_machine: same lan machine, dev_id =" << dev_id + << ", disconnect and reconnect"; + // lan mode printer reconnect printer if (m_agent) { @@ -497,20 +509,14 @@ namespace Slic3r { if (it->second->connection_type() != "lan" || it->second->connection_type().empty()) { - if (m_agent->get_user_selected_machine() == dev_id) - { - it->second->reset_update_time(); - } - else - { - BOOST_LOG_TRIVIAL(info) << "static: set_selected_machine: same dev_id = " << dev_id; - m_agent->set_user_selected_machine(dev_id); - it->second->reset(); - } + // diff dev_id, cloud => set_user_selected_machine(new) + BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new cloud machine, dev_id =" << dev_id; + m_agent->set_user_selected_machine(dev_id); + it->second->reset(); } else { - BOOST_LOG_TRIVIAL(info) << "static: set_selected_machine: same dev_id = empty"; + BOOST_LOG_TRIVIAL(info) << "set_selected_machine: select new lan machine, dev_id =" << dev_id; it->second->reset(); #if !BBL_RELEASE_TO_PUBLIC it->second->connect(Slic3r::GUI::wxGetApp().app_config->get("enable_ssl_for_mqtt") == "true" ? true : false);