mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-03-07 19:14:55 -07:00
clean up
This commit is contained in:
parent
8d22fad30b
commit
5935832143
6 changed files with 32 additions and 47 deletions
|
|
@ -3476,18 +3476,14 @@ void GUI_App::switch_printer_agent()
|
|||
return;
|
||||
}
|
||||
|
||||
std::string agent_id;
|
||||
|
||||
// Read printer_agent from config, falling back to default
|
||||
const DynamicPrintConfig& config = preset_bundle->printers.get_edited_preset().config;
|
||||
std::string effective_agent_id = ORCA_PRINTER_AGENT_ID;
|
||||
if (config.has("printer_agent")) {
|
||||
std::string value = config.option<ConfigOptionString>("printer_agent")->value;
|
||||
if (!value.empty()) {
|
||||
agent_id = value;
|
||||
}
|
||||
const std::string& value = config.option<ConfigOptionString>("printer_agent")->value;
|
||||
if (!value.empty())
|
||||
effective_agent_id = value;
|
||||
}
|
||||
// Use registry to validate and create agent
|
||||
// If empty, use default
|
||||
std::string effective_agent_id = agent_id.empty() ? ORCA_PRINTER_AGENT_ID : agent_id;
|
||||
|
||||
// Check if agent is registered
|
||||
if (!NetworkAgentFactory::is_printer_agent_registered(effective_agent_id)) {
|
||||
|
|
@ -3498,10 +3494,10 @@ void GUI_App::switch_printer_agent()
|
|||
}
|
||||
|
||||
std::string current_agent_id;
|
||||
if (m_agent && m_agent->get_printer_agent())
|
||||
if (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) {
|
||||
if (current_agent_id != effective_agent_id) {
|
||||
std::string log_dir = data_dir();
|
||||
std::shared_ptr<ICloudServiceAgent> cloud_agent = m_agent->get_cloud_agent();
|
||||
// Create new printer agent via registry
|
||||
|
|
|
|||
|
|
@ -172,24 +172,16 @@ void PhysicalPrinterDialog::build_printhost_settings(ConfigOptionsGroup* m_optgr
|
|||
def.enum_labels.push_back(agent.display_name);
|
||||
}
|
||||
|
||||
// Set initial selection based on current config value or default
|
||||
const std::string current_agent = m_config->opt_string("printer_agent");
|
||||
std::string selected_agent = current_agent;
|
||||
|
||||
if (selected_agent.empty()) {
|
||||
selected_agent = ORCA_PRINTER_AGENT_ID;
|
||||
}
|
||||
|
||||
// Verify selected agent is valid
|
||||
// Resolve selected agent: use config value if valid, otherwise fall back to default
|
||||
std::string selected_agent = m_config->opt_string("printer_agent");
|
||||
auto it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
|
||||
if (it == agents.end()) {
|
||||
selected_agent = ORCA_PRINTER_AGENT_ID;
|
||||
it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
|
||||
}
|
||||
|
||||
// Set default value for the enum (using the index)
|
||||
auto def_it = std::find_if(agents.begin(), agents.end(), [&selected_agent](const auto& a) { return a.id == selected_agent; });
|
||||
if (def_it != agents.end()) {
|
||||
size_t default_idx = std::distance(agents.begin(), def_it);
|
||||
if (it != agents.end()) {
|
||||
size_t default_idx = std::distance(agents.begin(), it);
|
||||
def.set_default_value(new ConfigOptionInt(static_cast<int>(default_idx)));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2101,7 +2101,7 @@ void Tab::on_presets_changed()
|
|||
|
||||
// Check if printer agent needs switching
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
update_printer_agent_if_needed();
|
||||
wxGetApp().switch_printer_agent();
|
||||
}
|
||||
|
||||
bool is_bbl_vendor_preset = m_preset_bundle->is_bbl_vendor();
|
||||
|
|
@ -2134,13 +2134,6 @@ void Tab::on_presets_changed()
|
|||
wxGetApp().plater()->update_project_dirty_from_presets();
|
||||
}
|
||||
|
||||
void Tab::update_printer_agent_if_needed()
|
||||
{
|
||||
|
||||
// Switch agent in GUI_App
|
||||
wxGetApp().switch_printer_agent(agent_id);
|
||||
}
|
||||
|
||||
void Tab::build_preset_description_line(ConfigOptionsGroup* optgroup)
|
||||
{
|
||||
auto description_line = [this](wxWindow* parent) {
|
||||
|
|
|
|||
|
|
@ -437,7 +437,6 @@ protected:
|
|||
// return true if cancelled
|
||||
bool tree_sel_change_delayed(wxCommandEvent& event);
|
||||
void on_presets_changed();
|
||||
void update_printer_agent_if_needed();
|
||||
void build_preset_description_line(ConfigOptionsGroup* optgroup);
|
||||
void update_preset_description_line();
|
||||
void update_frequently_changed_parameters();
|
||||
|
|
|
|||
|
|
@ -54,6 +54,14 @@ bool NetworkAgentFactory::is_printer_agent_registered(const std::string& id)
|
|||
return agents.find(id) != agents.end();
|
||||
}
|
||||
|
||||
const PrinterAgentInfo* NetworkAgentFactory::get_printer_agent_info(const std::string& id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_registry_mutex);
|
||||
auto& agents = get_printer_agents();
|
||||
auto it = agents.find(id);
|
||||
return (it != agents.end()) ? &it->second : nullptr;
|
||||
}
|
||||
|
||||
std::vector<PrinterAgentInfo> NetworkAgentFactory::get_registered_printer_agents()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_registry_mutex);
|
||||
|
|
@ -106,18 +114,14 @@ void NetworkAgentFactory::register_all_agents()
|
|||
|
||||
std::unique_ptr<NetworkAgent> create_agent_from_config(const std::string& log_dir, AppConfig* app_config)
|
||||
{
|
||||
if (!app_config)
|
||||
return std::make_unique<NetworkAgent>(nullptr, nullptr);
|
||||
|
||||
// Determine cloud provider from config
|
||||
bool use_orca_cloud = false;
|
||||
if (app_config) {
|
||||
try {
|
||||
use_orca_cloud = app_config->get("use_orca_cloud") == "true" || app_config->get_bool("use_orca_cloud");
|
||||
} catch (...) {
|
||||
use_orca_cloud = false;
|
||||
}
|
||||
}
|
||||
bool use_orca_cloud = app_config->get_bool("use_orca_cloud");
|
||||
|
||||
// Create cloud agent
|
||||
std::shared_ptr<ICloudServiceAgent> cloud_agent = nullptr;
|
||||
std::shared_ptr<ICloudServiceAgent> cloud_agent;
|
||||
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);
|
||||
|
|
@ -129,7 +133,7 @@ std::unique_ptr<NetworkAgent> create_agent_from_config(const std::string& log_di
|
|||
// Create NetworkAgent with cloud agent only (printer agent added later when printer is selected)
|
||||
auto agent = std::make_unique<NetworkAgent>(std::move(cloud_agent), nullptr);
|
||||
|
||||
if (agent && app_config && use_orca_cloud) {
|
||||
if (agent && use_orca_cloud) {
|
||||
auto* orca_cloud = dynamic_cast<OrcaCloudServiceAgent*>(agent->get_cloud_agent().get());
|
||||
if (orca_cloud) {
|
||||
orca_cloud->configure_urls(app_config);
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
// Forward declarations
|
||||
class ICloudServiceAgent;
|
||||
class IPrinterAgent;
|
||||
|
||||
/**
|
||||
* CloudAgentProvider - Specifies which implementation to use for each agent type.
|
||||
*
|
||||
|
|
@ -97,6 +93,11 @@ public:
|
|||
*/
|
||||
static bool is_printer_agent_registered(const std::string& id);
|
||||
|
||||
/**
|
||||
* Get info about a registered agent
|
||||
*/
|
||||
static const PrinterAgentInfo* get_printer_agent_info(const std::string& id);
|
||||
|
||||
/**
|
||||
* Get all registered printer agents (for UI population)
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue