From 006e7d6c28fe573c3ab49a59841e1a148ab72b74 Mon Sep 17 00:00:00 2001 From: SoftFever Date: Wed, 28 Jan 2026 18:58:17 +0800 Subject: [PATCH] fix a few bugs --- src/slic3r/GUI/GUI_App.cpp | 252 ++++++++++----------- src/slic3r/GUI/WebUserLoginDialog.cpp | 3 +- src/slic3r/GUI/WebViewDialog.cpp | 5 +- src/slic3r/Utils/MoonrakerPrinterAgent.cpp | 73 +++++- src/slic3r/Utils/MoonrakerPrinterAgent.hpp | 3 + src/slic3r/Utils/NetworkAgentFactory.cpp | 19 +- 6 files changed, 209 insertions(+), 146 deletions(-) diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 1376e4ce24..e490374c95 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -3304,131 +3304,127 @@ void GUI_App::copy_network_if_available() bool GUI_App::on_init_network(bool try_backup) { - bool create_network_agent = false; auto should_load_networking_plugin = app_config->get_bool("installed_networking"); std::string config_version = app_config->get_network_plugin_version(); - if(!should_load_networking_plugin) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << "Don't load plugin as installed_networking is false"; - } else { - if (config_version.empty()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": no version configured, need to download"; - m_networking_need_update = true; + if (should_load_networking_plugin) { + if (config_version.empty()) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": no version configured, need to download"; + m_networking_need_update = true; - if (!m_device_manager) - m_device_manager = new Slic3r::DeviceManager(); - if (!m_user_manager) - m_user_manager = new Slic3r::UserManager(); + if (!m_device_manager) + m_device_manager = new Slic3r::DeviceManager(); + if (!m_user_manager) + m_user_manager = new Slic3r::UserManager(); - return false; - } - int load_agent_dll = Slic3r::NetworkAgent::initialize_network_module(false, config_version); -__retry: - if (!load_agent_dll) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll ok"; - - std::string loaded_version = Slic3r::NetworkAgent::get_version(); - if (app_config && !loaded_version.empty() && loaded_version != "00.00.00.00") { - std::string config_version = app_config->get_network_plugin_version(); - std::string config_base = extract_base_version(config_version); - if (config_base != loaded_version) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": syncing config version from " << config_version << " to loaded " << loaded_version; - app_config->set(SETTING_NETWORK_PLUGIN_VERSION, loaded_version); - app_config->save(); - } + return false; } - if (check_networking_version()) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, compatibility version"; - auto bambu_source = Slic3r::NetworkAgent::get_bambu_source_entry(); - if (!bambu_source) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": can not get bambu source module!"; - m_networking_compatible = false; + int load_agent_dll = Slic3r::NetworkAgent::initialize_network_module(false, config_version); + __retry: + if (!load_agent_dll) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll ok"; + + std::string loaded_version = Slic3r::NetworkAgent::get_version(); + if (app_config && !loaded_version.empty() && loaded_version != "00.00.00.00") { + std::string config_version = app_config->get_network_plugin_version(); + std::string config_base = extract_base_version(config_version); + if (config_base != loaded_version) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": syncing config version from " << config_version << " to loaded " + << loaded_version; + app_config->set(SETTING_NETWORK_PLUGIN_VERSION, loaded_version); + app_config->save(); + } + } + + if (check_networking_version()) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, compatibility version"; + auto bambu_source = Slic3r::NetworkAgent::get_bambu_source_entry(); + if (!bambu_source) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": can not get bambu source module!"; + m_networking_compatible = false; + if (should_load_networking_plugin) { + m_networking_need_update = true; + } + } + } else { + if (try_backup) { + int result = Slic3r::NetworkAgent::unload_network_module(); + BOOST_LOG_TRIVIAL(info) << "on_init_network, version mismatch, unload_network_module, result = " << result; + load_agent_dll = Slic3r::NetworkAgent::initialize_network_module(true, config_version); + try_backup = false; + goto __retry; + } + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, version dismatch, need upload network module"; if (should_load_networking_plugin) { m_networking_need_update = true; } } - else - create_network_agent = true; } else { - if (try_backup) { - int result = Slic3r::NetworkAgent::unload_network_module(); - BOOST_LOG_TRIVIAL(info) << "on_init_network, version mismatch, unload_network_module, result = " << result; - load_agent_dll = Slic3r::NetworkAgent::initialize_network_module(true, config_version); - try_backup = false; - goto __retry; - } - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, version dismatch, need upload network module"; + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll failed"; if (should_load_networking_plugin) { + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, need upload network module"; m_networking_need_update = true; } } + } + + BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", create network agent..."); + //std::string data_dir = wxStandardPaths::Get().GetUserDataDir().ToUTF8().data(); + std::string data_directory = data_dir(); + + // Register all printer agents before creating the network agent + Slic3r::NetworkAgentFactory::register_all_agents(); + + // m_agent = new Slic3r::NetworkAgent(data_directory); + std::unique_ptr agent_ptr = Slic3r::create_agent_from_config(data_directory, app_config); + m_agent = agent_ptr.release(); + + if (!m_device_manager) + m_device_manager = new Slic3r::DeviceManager(m_agent); + else + m_device_manager->set_agent(m_agent); + + if (!m_user_manager) + m_user_manager = new Slic3r::UserManager(m_agent); + else + m_user_manager->set_agent(m_agent); + + if (this->is_enable_multi_machine()) { + if (!m_task_manager) { + m_task_manager = new Slic3r::TaskManager(m_agent); + m_task_manager->start(); + } + + m_device_manager->EnableMultiMachine(true); } else { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, load dll failed"; - if (should_load_networking_plugin) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << ": on_init_network, need upload network module"; - m_networking_need_update = true; - } - } + m_device_manager->EnableMultiMachine(false); } - if (create_network_agent) { - BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", create network agent..."); - //std::string data_dir = wxStandardPaths::Get().GetUserDataDir().ToUTF8().data(); - std::string data_directory = data_dir(); - - // Register all printer agents before creating the network agent - Slic3r::NetworkAgentFactory::register_all_agents(); - - // m_agent = new Slic3r::NetworkAgent(data_directory); - std::unique_ptr agent_ptr = Slic3r::create_agent_from_config(data_directory, app_config); - m_agent = agent_ptr.release(); - - if (!m_device_manager) - m_device_manager = new Slic3r::DeviceManager(m_agent); - else - m_device_manager->set_agent(m_agent); - - if (!m_user_manager) - m_user_manager = new Slic3r::UserManager(m_agent); - else - m_user_manager->set_agent(m_agent); - - if (this->is_enable_multi_machine()) { - if (!m_task_manager) { - m_task_manager = new Slic3r::TaskManager(m_agent); - m_task_manager->start(); - } - - m_device_manager->EnableMultiMachine(true); - } else { - m_device_manager->EnableMultiMachine(false); - } - - //BBS set config dir - if (m_agent) { - m_agent->set_config_dir(data_directory); - } - //BBS start http log - if (m_agent) { - m_agent->init_log(); - } - - //BBS set cert dir - if (m_agent) - m_agent->set_cert_file(resources_dir() + "/cert", "slicer_base64.cer"); - - init_http_extra_header(); - - if (m_agent) { - init_networking_callbacks(); - std::string country_code = app_config->get_country_code(); - m_agent->set_country_code(country_code); - m_agent->start(); - } + //BBS set config dir + if (m_agent) { + m_agent->set_config_dir(data_directory); } - else { + //BBS start http log + if (m_agent) { + m_agent->init_log(); + } + + //BBS set cert dir + if (m_agent) + m_agent->set_cert_file(resources_dir() + "/cert", "slicer_base64.cer"); + + init_http_extra_header(); + + if (m_agent) { + init_networking_callbacks(); + std::string country_code = app_config->get_country_code(); + m_agent->set_country_code(country_code); + m_agent->start(); + } + + if (!should_load_networking_plugin) { int result = Slic3r::NetworkAgent::unload_network_module(); BOOST_LOG_TRIVIAL(info) << "on_init_network, unload_network_module, result = " << result; @@ -3439,7 +3435,7 @@ __retry: m_user_manager = new Slic3r::UserManager(); } - if (create_network_agent && m_networking_compatible && !NetworkAgent::use_legacy_network) { + if (should_load_networking_plugin && m_networking_compatible && !NetworkAgent::use_legacy_network) { app_config->clear_remind_network_update_later(); if (has_network_update_available()) { @@ -3495,31 +3491,22 @@ void GUI_App::switch_printer_agent(const std::string& agent_id) std::string current_agent_id; if (m_agent && m_agent->get_printer_agent()) current_agent_id = m_agent->get_printer_agent()->get_agent_info().id; - - if (!current_agent_id.empty() && current_agent_id == effective_agent_id) { - return; + + if (current_agent_id.empty() || current_agent_id != effective_agent_id) { + std::string log_dir = data_dir(); + std::shared_ptr cloud_agent = m_agent->get_cloud_agent(); + // Create new printer agent via registry + std::shared_ptr new_printer_agent = NetworkAgentFactory::create_printer_agent_by_id(effective_agent_id, cloud_agent, + log_dir); + + if (!new_printer_agent) { + BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": failed to create agent '" << effective_agent_id << "', keeping current agent"; + return; + } + + // Swap the agent + m_agent->set_printer_agent(new_printer_agent); } - - std::string log_dir = data_dir(); - std::shared_ptr cloud_agent = m_agent->get_cloud_agent(); - if (!cloud_agent) { - BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": no cloud agent available"; - return; - } - - // Create new printer agent via registry - std::shared_ptr new_printer_agent = - NetworkAgentFactory::create_printer_agent_by_id(effective_agent_id, cloud_agent, log_dir); - - if (!new_printer_agent) { - BOOST_LOG_TRIVIAL(warning) << __FUNCTION__ << ": failed to create agent '" << effective_agent_id - << "', keeping current agent"; - return; - } - - // Swap the agent - m_agent->set_printer_agent(new_printer_agent); - // Auto-switch MachineObject select_machine(effective_agent_id); @@ -3574,9 +3561,14 @@ void GUI_App::select_machine(const std::string& agent_id) machine.dev_ip = dev_id; machine.dev_name = dev_id; machine.printer_type = preset.config.opt_string("printer_model"); + auto access_code = preset.config.opt_string("printhost_apikey"); + // Orca expect non empty access code + if (access_code.empty()) { + access_code = "88888888"; + } existing = m_device_manager->insert_local_device( - machine, "lan", "free", "", ""); + machine, "lan", "free", "", access_code); if (!existing) { BOOST_LOG_TRIVIAL(error) << __FUNCTION__ << ": failed to create machine dev_id=" << dev_id; diff --git a/src/slic3r/GUI/WebUserLoginDialog.cpp b/src/slic3r/GUI/WebUserLoginDialog.cpp index 2e479f4cf7..743401626d 100644 --- a/src/slic3r/GUI/WebUserLoginDialog.cpp +++ b/src/slic3r/GUI/WebUserLoginDialog.cpp @@ -43,9 +43,10 @@ int ZUserLogin::web_sequence_id = 20000; ZUserLogin::ZUserLogin() : wxDialog((wxWindow *) (wxGetApp().mainframe), wxID_ANY, "OrcaSlicer") { SetBackgroundColour(*wxWHITE); + const auto bblnetwork_enabled =wxGetApp().app_config->get_bool("installed_networking"); // Url NetworkAgent* agent = wxGetApp().getAgent(); - if (!agent) { + if (!agent && bblnetwork_enabled) { SetBackgroundColour(*wxWHITE); diff --git a/src/slic3r/GUI/WebViewDialog.cpp b/src/slic3r/GUI/WebViewDialog.cpp index ddcc46da0e..5d9301b7ca 100644 --- a/src/slic3r/GUI/WebViewDialog.cpp +++ b/src/slic3r/GUI/WebViewDialog.cpp @@ -488,7 +488,10 @@ void WebViewPanel::SendLoginInfo() void WebViewPanel::ShowNetpluginTip() { // Install Network Plugin - //std::string NP_Installed = wxGetApp().app_config->get("installed_networking"); + const auto bblnetwork_enabled =wxGetApp().app_config->get_bool("installed_networking"); + if(!bblnetwork_enabled) { + return; + } bool bValid = wxGetApp().is_compatibility_version(); int nShow = 0; diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index 93536d6be5..5e64567735 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -5,6 +5,8 @@ #include "slic3r/GUI/GUI_App.hpp" #include "slic3r/GUI/DeviceCore/DevFilaSystem.h" #include "slic3r/GUI/DeviceCore/DevManager.h" +#include "../GUI/DeviceCore/DevStorage.h" +#include "../GUI/DeviceCore/DevFirmware.h" #include "nlohmann/json.hpp" #include #include @@ -586,6 +588,19 @@ void MoonrakerPrinterAgent::build_ams_payload(int ams_count, const std::vectorm_full_msg_count = 1; } obj->last_push_time = std::chrono::system_clock::now(); + + // Set storage state - Moonraker printers use virtual_sdcard, storage is always available. + // This is required for SelectMachineDialog to allow printing (otherwise it blocks with "No SD card"). + obj->GetStorage()->set_sdcard_state(DevStorage::HAS_SDCARD_NORMAL); + + // Populate module_vers so is_info_ready() passes the version check. + // Moonraker printers don't have BBL-style version info, but we need a non-empty map. + if (obj->module_vers.empty()) { + DevFirmwareVersionInfo ota_info; + ota_info.name = "ota"; + ota_info.sw_ver = "1.0.0"; // Placeholder version for Moonraker printers + obj->module_vers.emplace("ota", ota_info); + } } bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id) @@ -668,7 +683,7 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id) tray.bed_temp = lane_obj.value("bed_temp", 0); tray.nozzle_temp = lane_obj.value("nozzle_temp", 0); tray.has_filament = !tray.tray_type.empty(); - tray.tray_info_idx = ""; // AFC doesn't provide setting IDs + tray.tray_info_idx = map_filament_type_to_generic_id(tray.tray_type); max_lane_index = std::max(max_lane_index, lane_index); trays.push_back(tray); @@ -687,6 +702,60 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id) return true; } +std::string MoonrakerPrinterAgent::map_filament_type_to_generic_id(const std::string& filament_type) +{ + std::string upper = filament_type; + boost::trim(upper); + std::transform(upper.begin(), upper.end(), upper.begin(), + [](unsigned char c) { return static_cast(std::toupper(c)); }); + + // Map to OrcaFilamentLibrary preset IDs (compatible with all printers) + // Source: resources/profiles/OrcaFilamentLibrary/filament/ + + // PLA variants + if (upper == "PLA") return "OGFL99"; + if (upper == "PLA-CF") return "OGFL98"; + if (upper == "PLA SILK" || upper == "PLA-SILK") return "OGFL96"; + if (upper == "PLA HIGH SPEED" || upper == "PLA-HS" || upper == "PLA HS") return "OGFL95"; + + // ABS/ASA variants + if (upper == "ABS") return "OGFB99"; + if (upper == "ASA") return "OGFB98"; + + // PETG/PET variants + if (upper == "PETG" || upper == "PET") return "OGFG99"; + if (upper == "PCTG") return "OGFG97"; + + // PA/Nylon variants + if (upper == "PA" || upper == "NYLON") return "OGFN99"; + if (upper == "PA-CF") return "OGFN98"; + if (upper == "PPA" || upper == "PPA-CF") return "OGFN97"; + if (upper == "PPA-GF") return "OGFN96"; + + // PC variants + if (upper == "PC") return "OGFC99"; + + // PP/PE variants + if (upper == "PE") return "OGFP99"; + if (upper == "PP") return "OGFP97"; + + // Support materials + if (upper == "PVA") return "OGFS99"; + if (upper == "HIPS") return "OGFS98"; + if (upper == "BVOH") return "OGFS97"; + + // TPU variants + if (upper == "TPU") return "OGFU99"; + + // Other materials + if (upper == "EVA") return "OGFR99"; + if (upper == "PHA") return "OGFR98"; + if (upper == "COPE") return "OGFLC99"; + if (upper == "SBS") return "OFLSBS99"; + + return ""; // Unknown material - will fall back to type-based name matching +} + int MoonrakerPrinterAgent::handle_request(const std::string& dev_id, const std::string& json_str) { auto json = nlohmann::json::parse(json_str, nullptr, false); @@ -1085,7 +1154,7 @@ void MoonrakerPrinterAgent::announce_printhost_device() const std::string model_id = device_info.model_id; if (auto* app_config = GUI::wxGetApp().app_config) { - const std::string access_code = device_info.api_key; + const std::string access_code = device_info.api_key.empty() ? "88888888" : device_info.api_key; app_config->set_str("access_code", device_info.dev_id, access_code); app_config->set_str("user_access_code", device_info.dev_id, access_code); } diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp index b301ae0fd9..38badfaec0 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp @@ -115,6 +115,9 @@ protected: std::string sanitize_filename(const std::string& filename); std::string join_url(const std::string& base_url, const std::string& path) const; + // Map filament type to OrcaFilamentLibrary preset ID for AMS sync compatibility + static std::string map_filament_type_to_generic_id(const std::string& filament_type); + private: int handle_request(const std::string& dev_id, const std::string& json_str); int send_version_info(const std::string& dev_id); diff --git a/src/slic3r/Utils/NetworkAgentFactory.cpp b/src/slic3r/Utils/NetworkAgentFactory.cpp index faafe136b2..1e23291399 100644 --- a/src/slic3r/Utils/NetworkAgentFactory.cpp +++ b/src/slic3r/Utils/NetworkAgentFactory.cpp @@ -178,20 +178,15 @@ std::unique_ptr create_agent_from_config(const std::string& log_di } // Create cloud agent - CloudAgentProvider provider = use_orca_cloud ? CloudAgentProvider::Orca : CloudAgentProvider::BBL; - auto cloud_agent = NetworkAgentFactory::create_cloud_agent(provider, log_dir); - - if (!cloud_agent && provider == CloudAgentProvider::BBL) { - cloud_agent = NetworkAgentFactory::create_cloud_agent(CloudAgentProvider::Orca, log_dir); + std::shared_ptr cloud_agent = nullptr; + if (use_orca_cloud || app_config->get_bool("installed_networking")) { + CloudAgentProvider provider = use_orca_cloud ? CloudAgentProvider::Orca : CloudAgentProvider::BBL; + cloud_agent = NetworkAgentFactory::create_cloud_agent(provider, log_dir); + if (!cloud_agent) { + BOOST_LOG_TRIVIAL(error) << "Failed to create cloud agent"; + } } - if (!cloud_agent) { - BOOST_LOG_TRIVIAL(error) << "Failed to create cloud agent"; - return nullptr; - } - - // auto bbl_printer_agent = NetworkAgentFactory::create_printer_agent_by_id("bbl", cloud_agent, log_dir); - // Create NetworkAgent with cloud agent only (printer agent added later) // We will create the printer agent later when the printer is selected, so we pass nullptr for the printer agent here. auto agent = NetworkAgentFactory::create_from_agents(std::move(cloud_agent), nullptr);