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

Functions

std::string find_option_for_capability (Preset::Type type, const Preset &preset, const PluginCapabilityRef &ref, PluginCapabilityType capability_type=PluginCapabilityType::Unknown)
void collect_capabilities_in_use (Preset::Type type, const Preset &preset, std::vector< PluginCapabilityId > &out)

Function Documentation

◆ collect_capabilities_in_use()

void Slic3r::anonymous_namespace{PluginResolver.cpp}::collect_capabilities_in_use ( Preset::Type type,
const Preset & preset,
std::vector< PluginCapabilityId > & out )
139{
140 for (const PluginCapabilityRef& ref : referenced_capabilities(type, preset)) {
141 // Cloud plugins resolve by UUID, local plugins by plugin_key.
142 const std::string key = ref.uuid.empty() ? ref.name : ref.uuid;
143 if (key.empty())
144 continue;
145
146 PluginDescriptor descriptor;
147 if (!PluginManager::instance().try_get_plugin_descriptor(key, descriptor))
148 continue;
149
150 // The manifest ref does not carry a type, so require the live capability type to match the
151 // type declared by the option that references it.
152 for (const auto& capability : PluginManager::instance().get_plugin_capabilities(descriptor.plugin_key, PluginCapabilityType::Unknown, false))
153 if (capability && capability->type() != PluginCapabilityType::Unknown &&
154 capability->name() == ref.capability_name &&
155 !find_option_for_capability(type, preset, ref, capability->type()).empty())
156 out.push_back(capability->identity());
157 }
158}
static PluginManager & instance()
Definition PluginManager.cpp:74
std::string find_option_for_capability(Preset::Type type, const Preset &preset, const PluginCapabilityRef &ref, PluginCapabilityType capability_type=PluginCapabilityType::Unknown)
Definition PluginResolver.cpp:43
@ Unknown
Definition PythonPluginInterface.hpp:17
std::vector< PluginCapabilityRef > referenced_capabilities(Preset::Type type, const Preset &preset)
Definition PluginResolver.cpp:112
Definition Config.hpp:3144
Definition PluginDescriptor.hpp:53
std::string plugin_key
Definition PluginDescriptor.hpp:54

References collect_capabilities_in_use(), find_option_for_capability(), Slic3r::PluginManager::instance(), Slic3r::PluginDescriptor::plugin_key, Slic3r::referenced_capabilities(), Slic3r::Preset::type, and Slic3r::Unknown.

Referenced by collect_capabilities_in_use().

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

◆ find_option_for_capability()

std::string Slic3r::anonymous_namespace{PluginResolver.cpp}::find_option_for_capability ( Preset::Type type,
const Preset & preset,
const PluginCapabilityRef & ref,
PluginCapabilityType capability_type = PluginCapabilityType::Unknown )
47{
48 if (type != Preset::TYPE_PRINT && type != Preset::TYPE_PRINTER && type != Preset::TYPE_FILAMENT)
49 return {};
50
51 // Options opt in via ConfigOptionDef::is_plugin_backed, so scan the definition rather than keep a
52 // hardcoded per-type field list. A typed preset's config only holds keys for its own type.
53 const ConfigDef* def = preset.config.def();
54 if (def == nullptr)
55 return {};
56
57 const std::string expected_type = plugin_capability_type_to_string(capability_type);
58 const auto matches_ref = [&ref](const std::string& value) {
59 return value == ref.capability_name;
60 };
61
62 for (const std::string& field : preset.config.keys()) {
63 const ConfigOptionDef* opt_def = def->get(field);
64 if (opt_def == nullptr || !opt_def->is_plugin_backed() ||
65 (capability_type != PluginCapabilityType::Unknown && opt_def->plugin_type != expected_type))
66 continue;
67
68 const ConfigOption* option = preset.config.option(field);
69 if (option == nullptr)
70 continue;
71
72 if (const auto* string_option = dynamic_cast<const ConfigOptionString*>(option)) {
73 if (string_option->value == ref.capability_name)
74 return field;
75 continue;
76 }
77
78 if (const auto* vector_option = dynamic_cast<const ConfigOptionVectorBase*>(option)) {
79 const std::vector<std::string> values = vector_option->vserialize();
80 if (std::any_of(values.begin(), values.end(), matches_ref))
81 return field;
82 }
83 }
84
85 // printer_agent stores AgentInfo::id, so a missing plugin cannot be reverse-mapped through
86 // the runtime registry. If no regular printer plugin field matched, assume printer_agent.
87 if (type == Preset::Type::TYPE_PRINTER && preset.config.has("printer_agent")) {
88 const ConfigOptionDef* agent_def = def->get("printer_agent");
89 if (agent_def != nullptr && agent_def->is_plugin_backed() &&
90 (capability_type == PluginCapabilityType::Unknown || agent_def->plugin_type == expected_type))
91 return "printer_agent";
92 }
93
94 return {};
95}
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2768
Definition Config.hpp:2656
const ConfigOptionDef * get(const t_config_option_key &opt_key) const
Definition Config.hpp:2662
bool has(const t_config_option_key &opt_key) const
Definition Config.hpp:2697
t_config_option_keys keys() const override
Definition Config.cpp:1919
const ConfigDef * def() const override
Definition PrintConfig.hpp:930
DynamicPrintConfig config
Definition Preset.hpp:300
@ TYPE_PRINTER
Definition Preset.hpp:250
@ TYPE_PRINT
Definition Preset.hpp:246
@ TYPE_FILAMENT
Definition Preset.hpp:248
std::string capability_name
Definition Config.hpp:3146
zaa_minimize_perimeter_height ConfigOptionString
Definition PrintConfig.hpp:1702
std::string plugin_capability_type_to_string(PluginCapabilityType type)
Definition PythonPluginInterface.hpp:40

References Slic3r::PluginCapabilityRef::capability_name, Slic3r::Preset::config, Slic3r::DynamicPrintConfig::def(), find_option_for_capability(), Slic3r::ConfigDef::get(), Slic3r::ConfigOptionResolver::has(), Slic3r::ConfigOptionDef::is_plugin_backed(), Slic3r::DynamicConfig::keys(), Slic3r::ConfigBase::option(), Slic3r::plugin_capability_type_to_string(), Slic3r::ConfigOptionDef::plugin_type, Slic3r::Preset::TYPE_FILAMENT, Slic3r::Preset::TYPE_PRINT, Slic3r::Preset::TYPE_PRINTER, and Slic3r::Unknown.

Referenced by collect_capabilities_in_use(), and find_option_for_capability().

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