OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::anonymous_namespace{BBLPrinterAgent.cpp} Namespace Reference

Classes

struct  BambuFilamentIdMap

Functions

const BambuFilamentIdMap & bambu_filament_id_map ()
void rewrite_filament_ids (json &j, const std::unordered_map< std::string, std::string > &map)
std::string rewrite_filament_ids (std::string text, const std::unordered_map< std::string, std::string > &map)
OnMessageFn to_orca_messages (OnMessageFn fn)
template<typename To, typename From>
To as_abi (From fn)
template<typename LegacyFn, typename Fn0203, typename CurrentFn, typename... CallbackFns>
int dispatch_start (CurrentFn func, PrintParams &params, const CallbackFns &... callbacks)

Variables

constexpr std::array< std::string_view, 5 > filament_id_keys {"tray_info_idx", "filament_id", "filamentId", "cate", "fila_id"}

Class Documentation

◆ Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::BambuFilamentIdMap

struct Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::BambuFilamentIdMap
Collaboration diagram for Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::BambuFilamentIdMap:
Class Members
unordered_map< string, string > to_bambu
unordered_map< string, string > to_orca

Function Documentation

◆ as_abi()

template<typename To, typename From>
To Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::as_abi ( From fn)
121{
122 static_assert(std::is_function_v<std::remove_pointer_t<From>>, "as_abi retypes a function pointer");
123 return reinterpret_cast<To>(reinterpret_cast<void (*)()>(fn));
124}

References as_abi().

Referenced by as_abi(), and dispatch_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ bambu_filament_id_map()

const BambuFilamentIdMap & Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::bambu_filament_id_map ( )
44{
45 static const BambuFilamentIdMap map = [] {
47 const std::string path = resources_dir() + "/printers/bambu_filament_ids.json";
48 try {
49 boost::nowide::ifstream file(path);
50 if (!file.is_open()) {
51 BOOST_LOG_TRIVIAL(warning) << "Bambu filament id map not found, ids pass through untranslated: " << path;
52 return m;
53 }
54 json doc;
55 file >> doc;
56 for (const auto& [orca_filament_id, row] : doc.at("filaments").items()) {
57 const std::string bambu_id = row.at("bambu_id").get<std::string>();
58 m.to_bambu.emplace(orca_filament_id, bambu_id);
59 m.to_orca.emplace(bambu_id, orca_filament_id);
60 }
61 } catch (const std::exception& e) {
62 BOOST_LOG_TRIVIAL(error) << "Bambu filament id map unreadable, ids pass through untranslated: " << e.what();
63 m = {};
64 }
65 return m;
66 }();
67 return map;
68}
std::unordered_map< std::string, std::string > to_orca
Definition BBLPrinterAgent.cpp:41
std::unordered_map< std::string, std::string > to_bambu
Definition BBLPrinterAgent.cpp:41
nlohmann::json json
Definition AssembleList.cpp:42
const std::string & resources_dir()
Definition utils.cpp:296

References bambu_filament_id_map(), Slic3r::resources_dir(), Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::BambuFilamentIdMap::to_bambu, and Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::BambuFilamentIdMap::to_orca.

Referenced by bambu_filament_id_map().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dispatch_start()

template<typename LegacyFn, typename Fn0203, typename CurrentFn, typename... CallbackFns>
int Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::dispatch_start ( CurrentFn func,
PrintParams & params,
const CallbackFns &... callbacks )
567{
568 auto& plugin = BBLNetworkPlugin::instance();
569 auto agent = plugin.get_agent();
570 if (!func || !agent)
571 return -1;
573 switch (plugin.network_abi()) {
575 return as_abi<LegacyFn>(func)(agent, BBLNetworkPlugin::as_legacy(params), callbacks...);
577 return as_abi<Fn0203>(func)(agent, BBLNetworkPlugin::as_0203(params), callbacks...);
579 return func(agent, std::move(params), callbacks...);
580 default:
581 return -1;
582 }
583}
static BBLNetworkPlugin & instance()
Definition BBLNetworkPlugin.cpp:56
static PrintParams_0203 as_0203(PrintParams &param)
Definition BBLNetworkPlugin.cpp:602
static PrintParams_Legacy as_legacy(PrintParams &param)
Definition BBLNetworkPlugin.cpp:558
static std::string from_orca_payload(std::string json_text)
Definition BBLPrinterAgent.cpp:152
To as_abi(From fn)
Definition BBLPrinterAgent.cpp:120
std::string ams_mapping_info
Definition bambu_networking.hpp:303
@ Legacy
Definition bambu_networking.hpp:414
@ V0203
Definition bambu_networking.hpp:415
@ Current
Definition bambu_networking.hpp:416

References Slic3r::PrintParams::ams_mapping_info, Slic3r::BBLNetworkPlugin::as_0203(), as_abi(), Slic3r::BBLNetworkPlugin::as_legacy(), Slic3r::Current, dispatch_start(), Slic3r::BBLPrinterAgent::from_orca_payload(), Slic3r::BBLNetworkPlugin::instance(), Slic3r::Legacy, and Slic3r::V0203.

Referenced by dispatch_start().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewrite_filament_ids() [1/2]

void Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::rewrite_filament_ids ( json & j,
const std::unordered_map< std::string, std::string > & map )
76{
77 if (j.is_object()) {
78 for (auto& [key, value] : j.items()) {
79 if (value.is_string() && std::find(filament_id_keys.begin(), filament_id_keys.end(), key) != filament_id_keys.end()) {
80 auto it = map.find(value.get_ref<const std::string&>());
81 if (it != map.end())
82 value = it->second;
83 } else
84 rewrite_filament_ids(value, map);
85 }
86 } else if (j.is_array())
87 for (auto& element : j)
88 rewrite_filament_ids(element, map);
89}
void rewrite_filament_ids(json &j, const std::unordered_map< std::string, std::string > &map)
Definition BBLPrinterAgent.cpp:75
constexpr std::array< std::string_view, 5 > filament_id_keys
Definition BBLPrinterAgent.cpp:72

References filament_id_keys, and rewrite_filament_ids().

Referenced by rewrite_filament_ids(), and rewrite_filament_ids().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ rewrite_filament_ids() [2/2]

std::string Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::rewrite_filament_ids ( std::string text,
const std::unordered_map< std::string, std::string > & map )
93{
94 if (map.empty() || std::none_of(filament_id_keys.begin(), filament_id_keys.end(),
95 [&text](std::string_view key) { return text.find(key) != std::string::npos; }))
96 return text; // nothing to map, skip the parse (moved, not copied)
97 try {
98 json j = json::parse(text);
100 return j.dump();
101 } catch (const std::exception&) {
102 return text; // not JSON: forward as received
103 }
104}

References filament_id_keys, and rewrite_filament_ids().

Here is the call graph for this function:

◆ to_orca_messages()

OnMessageFn Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::to_orca_messages ( OnMessageFn fn)
110{
111 if (!fn)
112 return fn;
113 return [fn = std::move(fn)](std::string dev_id, std::string msg) { fn(std::move(dev_id), BBLPrinterAgent::to_orca_payload(std::move(msg))); };
114}
static std::string to_orca_payload(std::string json_text)
Definition BBLPrinterAgent.cpp:147

References to_orca_messages(), and Slic3r::BBLPrinterAgent::to_orca_payload().

Referenced by to_orca_messages().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ filament_id_keys

std::array<std::string_view, 5> Slic3r::anonymous_namespace{BBLPrinterAgent.cpp}::filament_id_keys {"tray_info_idx", "filament_id", "filamentId", "cate", "fila_id"}
constexpr
72{"tray_info_idx", "filament_id", "filamentId", "cate", "fila_id"};

Referenced by rewrite_filament_ids(), and rewrite_filament_ids().