mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-08-10 03:27:35 +00:00
badge support
This commit is contained in:
@@ -455,7 +455,7 @@ int MoonrakerPrinterAgent::set_queue_on_main_fn(QueueOnMainFn fn)
|
||||
return BAMBU_NETWORK_SUCCESS;
|
||||
}
|
||||
|
||||
void MoonrakerPrinterAgent::build_ams_payload(int ams_count, const std::vector<AmsTrayData>& trays)
|
||||
void MoonrakerPrinterAgent::build_ams_payload(int ams_count, int max_lane_index, const std::vector<AmsTrayData>& trays)
|
||||
{
|
||||
|
||||
// Look up MachineObject via DeviceManager
|
||||
@@ -520,7 +520,8 @@ void MoonrakerPrinterAgent::build_ams_payload(int ams_count, const std::vector<A
|
||||
ams_unit["info"] = "0002"; // treat as AMS_LITE
|
||||
|
||||
nlohmann::json tray_array = nlohmann::json::array();
|
||||
for (int slot_id = 0; slot_id < 4; ++slot_id) {
|
||||
int max_slot_in_this_ams = std::min(3, max_lane_index - ams_id * 4);
|
||||
for (int slot_id = 0; slot_id <= max_slot_in_this_ams; ++slot_id) {
|
||||
int slot_index = ams_id * 4 + slot_id;
|
||||
|
||||
// Find tray with matching slot_index
|
||||
@@ -554,6 +555,7 @@ void MoonrakerPrinterAgent::build_ams_payload(int ams_count, const std::vector<A
|
||||
tray_json["tray_info_idx"] = "";
|
||||
tray_json["tray_type"] = "";
|
||||
tray_json["tray_color"] = "00000000";
|
||||
tray_json["tray_slot_placeholder"] = "1";
|
||||
}
|
||||
|
||||
tray_array.push_back(tray_json);
|
||||
@@ -717,7 +719,7 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id)
|
||||
int ams_count = (max_lane_index + 4) / 4;
|
||||
|
||||
// Build and parse the AMS payload
|
||||
build_ams_payload(ams_count, trays);
|
||||
build_ams_payload(ams_count, max_lane_index, trays);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ protected:
|
||||
bool use_ssl = false;
|
||||
} device_info;
|
||||
|
||||
// Shared tray data for AMS payload building (used by derived classes like QidiPrinterAgent)
|
||||
// Tray data for AMS payload building
|
||||
struct AmsTrayData {
|
||||
int slot_index = 0; // 0-based slot index
|
||||
bool has_filament = false;
|
||||
@@ -100,7 +100,7 @@ protected:
|
||||
};
|
||||
|
||||
// Build ams JSON and call parser
|
||||
void build_ams_payload(int ams_count, const std::vector<AmsTrayData>& trays);
|
||||
void build_ams_payload(int ams_count, int max_lane_index, const std::vector<AmsTrayData>& trays);
|
||||
|
||||
// Methods that derived classes may need to override or access
|
||||
virtual bool init_device_info(std::string dev_id, std::string dev_ip, std::string username, std::string password, bool use_ssl);
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "QidiPrinterAgent.hpp"
|
||||
#include "MoonrakerPrinterAgent.hpp"
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace {
|
||||
@@ -18,10 +20,22 @@ std::map<std::string, PrinterAgentInfo>& get_printer_agents()
|
||||
return agents;
|
||||
}
|
||||
|
||||
std::string& get_default_agent_id()
|
||||
// Helper to register a printer agent type with the standard factory pattern.
|
||||
// AgentTypes that take a log_dir constructor arg use the default; BBLPrinterAgent
|
||||
// (no log_dir) is registered separately.
|
||||
template<typename T>
|
||||
void register_agent()
|
||||
{
|
||||
static std::string default_id;
|
||||
return default_id;
|
||||
auto info = T::get_agent_info_static();
|
||||
NetworkAgentFactory::register_printer_agent(
|
||||
info.id, info.name,
|
||||
[](std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir) -> std::shared_ptr<IPrinterAgent> {
|
||||
auto agent = std::make_shared<T>(log_dir);
|
||||
if (cloud_agent)
|
||||
agent->set_cloud_agent(cloud_agent);
|
||||
return agent;
|
||||
});
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@@ -30,18 +44,7 @@ bool NetworkAgentFactory::register_printer_agent(const std::string& id, const st
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_registry_mutex);
|
||||
auto& agents = get_printer_agents();
|
||||
|
||||
auto result = agents.emplace(id, PrinterAgentInfo(id, display_name, std::move(factory)));
|
||||
|
||||
if (result.second) {
|
||||
auto& default_id = get_default_agent_id();
|
||||
if (default_id.empty()) {
|
||||
default_id = id;
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return agents.emplace(id, PrinterAgentInfo(id, display_name, std::move(factory))).second;
|
||||
}
|
||||
|
||||
bool NetworkAgentFactory::is_printer_agent_registered(const std::string& id)
|
||||
@@ -51,14 +54,6 @@ 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);
|
||||
@@ -89,80 +84,24 @@ std::shared_ptr<IPrinterAgent> NetworkAgentFactory::create_printer_agent_by_id(c
|
||||
return it->second.factory(cloud_agent, log_dir);
|
||||
}
|
||||
|
||||
std::string NetworkAgentFactory::get_default_printer_agent_id()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_registry_mutex);
|
||||
return get_default_agent_id();
|
||||
}
|
||||
|
||||
void NetworkAgentFactory::set_default_printer_agent_id(const std::string& id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(s_registry_mutex);
|
||||
auto& agents = get_printer_agents();
|
||||
|
||||
if (agents.find(id) != agents.end()) {
|
||||
get_default_agent_id() = id;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkAgentFactory::register_all_agents()
|
||||
{
|
||||
// Register Orca printer agent
|
||||
{
|
||||
auto info = OrcaPrinterAgent::get_agent_info_static();
|
||||
register_printer_agent(info.id, info.name,
|
||||
[](std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir) -> std::shared_ptr<IPrinterAgent> {
|
||||
auto agent = std::make_shared<OrcaPrinterAgent>(log_dir);
|
||||
if (cloud_agent) {
|
||||
agent->set_cloud_agent(cloud_agent);
|
||||
}
|
||||
return agent;
|
||||
});
|
||||
}
|
||||
register_agent<OrcaPrinterAgent>();
|
||||
register_agent<QidiPrinterAgent>();
|
||||
register_agent<MoonrakerPrinterAgent>();
|
||||
|
||||
// Register Qidi printer agent
|
||||
{
|
||||
auto info = QidiPrinterAgent::get_agent_info_static();
|
||||
register_printer_agent(info.id, info.name,
|
||||
[](std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir) -> std::shared_ptr<IPrinterAgent> {
|
||||
auto agent = std::make_shared<QidiPrinterAgent>(log_dir);
|
||||
if (cloud_agent) {
|
||||
agent->set_cloud_agent(cloud_agent);
|
||||
}
|
||||
return agent;
|
||||
});
|
||||
}
|
||||
|
||||
// Register Moonraker printer agent
|
||||
{
|
||||
auto info = MoonrakerPrinterAgent::get_agent_info_static();
|
||||
register_printer_agent(info.id, info.name,
|
||||
[](std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir) -> std::shared_ptr<IPrinterAgent> {
|
||||
auto agent = std::make_shared<MoonrakerPrinterAgent>(log_dir);
|
||||
if (cloud_agent) {
|
||||
agent->set_cloud_agent(cloud_agent);
|
||||
}
|
||||
return agent;
|
||||
});
|
||||
}
|
||||
|
||||
// Register BBL printer agent (only if bbl network agent is available)
|
||||
// BBLPrinterAgent takes no constructor args, so register manually
|
||||
{
|
||||
auto info = BBLPrinterAgent::get_agent_info_static();
|
||||
register_printer_agent(info.id, info.name,
|
||||
[](std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir) -> std::shared_ptr<IPrinterAgent> {
|
||||
const std::string& /*log_dir*/) -> std::shared_ptr<IPrinterAgent> {
|
||||
auto agent = std::make_shared<BBLPrinterAgent>();
|
||||
if (cloud_agent) {
|
||||
if (cloud_agent)
|
||||
agent->set_cloud_agent(cloud_agent);
|
||||
}
|
||||
return agent;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
std::unique_ptr<NetworkAgent> create_agent_from_config(const std::string& log_dir, AppConfig* app_config)
|
||||
@@ -187,9 +126,8 @@ std::unique_ptr<NetworkAgent> create_agent_from_config(const std::string& log_di
|
||||
}
|
||||
}
|
||||
|
||||
// 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);
|
||||
// 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) {
|
||||
auto* orca_cloud = dynamic_cast<OrcaCloudServiceAgent*>(agent->get_cloud_agent().get());
|
||||
|
||||
@@ -12,8 +12,6 @@
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
@@ -99,11 +97,6 @@ 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)
|
||||
*/
|
||||
@@ -121,16 +114,6 @@ public:
|
||||
std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
const std::string& log_dir);
|
||||
|
||||
/**
|
||||
* Get default printer agent ID
|
||||
*/
|
||||
static std::string get_default_printer_agent_id();
|
||||
|
||||
/**
|
||||
* Set a specific agent as the default
|
||||
*/
|
||||
static void set_default_printer_agent_id(const std::string& id);
|
||||
|
||||
// ========================================================================
|
||||
// Cloud Agent Factory
|
||||
// ========================================================================
|
||||
@@ -164,23 +147,6 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
// ========================================================================
|
||||
// NetworkAgent Facade Creation
|
||||
// ========================================================================
|
||||
|
||||
/**
|
||||
* Create a NetworkAgent from pre-created sub-agents
|
||||
*
|
||||
* @param cloud_agent Cloud service agent (required, includes auth)
|
||||
* @param printer_agent Printer agent (optional, can be nullptr)
|
||||
* @return Unique pointer to NetworkAgent facade
|
||||
*/
|
||||
static std::unique_ptr<NetworkAgent> create_from_agents(std::shared_ptr<ICloudServiceAgent> cloud_agent,
|
||||
std::shared_ptr<IPrinterAgent> printer_agent)
|
||||
{
|
||||
return std::make_unique<NetworkAgent>(std::move(cloud_agent), std::move(printer_agent));
|
||||
}
|
||||
|
||||
private:
|
||||
// Factory is not instantiable
|
||||
NetworkAgentFactory() = delete;
|
||||
|
||||
@@ -49,7 +49,7 @@ bool QidiPrinterAgent::fetch_filament_info(std::string dev_id)
|
||||
}
|
||||
|
||||
// 4. Build the AMS payload
|
||||
build_ams_payload(box_count, trays);
|
||||
build_ams_payload(box_count, box_count * 4 - 1, trays);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user