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

Functions

void install_capability_resolver ()
void install_lifecycle_event_hook ()
void install_slicing_pipeline_hook ()

Function Documentation

◆ install_capability_resolver()

void Slic3r::plugin_hooks::anonymous_namespace{PluginHooks.cpp}::install_capability_resolver ( )
34{
35 ConfigBase::set_resolve_capability_fn([](const std::string& cap_name, const std::string& cap_type) {
38 // only_enabled = false: this resolves the reference a preset STORES, which must stay
39 // resolvable whether or not the user currently has the capability enabled. Filtering on
40 // the enable flag here would quietly drop the reference out of the preset's manifest.
41 auto plugin_cap = plugin_mgr.get_plugin_capability(cap_name, type, /*only_enabled=*/false);
42 if (!plugin_cap)
43 return std::string();
44
45 PluginDescriptor descriptor;
46 if (!plugin_mgr.try_get_plugin_descriptor_for_capability(cap_name, type, descriptor))
47 return std::string();
48
49 // Cloud plugins are resolved at runtime via the UUID in the middle field, so the first
50 // field keeps the friendly display name. Local plugins are looked up by plugin_key (the
51 // first field, with an empty UUID), so emit the plugin_key to keep them resolvable.
52 const std::string identity = descriptor.is_cloud_plugin() ? descriptor.name : descriptor.plugin_key;
53 return identity + ';' + descriptor.cloud_uuid() + ';' + cap_name;
54 });
55}
static void set_resolve_capability_fn(std::function< std::string(std::string, std::string)> fn)
Definition Config.hpp:2893
Definition PluginManager.hpp:116
static PluginManager & instance()
Definition PluginManager.cpp:74
bool try_get_plugin_descriptor_for_capability(const std::string &capability_name, PluginCapabilityType type, PluginDescriptor &out) const
Definition PluginManager.cpp:538
std::shared_ptr< PluginCapabilityInterface > get_plugin_capability(const PluginCapabilityId &id, bool only_enabled=true) const
Definition PluginManager.cpp:616
PluginCapabilityType
Definition PythonPluginInterface.hpp:17
Transform< N, T > identity()
Definition Point.hpp:106
PluginCapabilityType plugin_capability_type_from_string(std::string_view value)
Definition PythonPluginInterface.hpp:72
Definition PluginDescriptor.hpp:53
std::string plugin_key
Definition PluginDescriptor.hpp:54
bool is_cloud_plugin() const
Definition PluginDescriptor.hpp:82
std::string name
Definition PluginDescriptor.hpp:55
std::string cloud_uuid() const
Definition PluginDescriptor.hpp:83

References Slic3r::PluginDescriptor::cloud_uuid(), Slic3r::PluginManager::get_plugin_capability(), Slic3r::identity(), install_capability_resolver(), Slic3r::PluginManager::instance(), Slic3r::PluginDescriptor::is_cloud_plugin(), Slic3r::PluginDescriptor::name, Slic3r::plugin_capability_type_from_string(), Slic3r::PluginDescriptor::plugin_key, Slic3r::ConfigBase::set_resolve_capability_fn(), and Slic3r::PluginManager::try_get_plugin_descriptor_for_capability().

Referenced by install_capability_resolver().

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

◆ install_lifecycle_event_hook()

void Slic3r::plugin_hooks::anonymous_namespace{PluginHooks.cpp}::install_lifecycle_event_hook ( )
61{
64 });
65}
void dispatch_lifecycle_event(LifecycleEvent evt, const LifecycleEventContext &ctx)
Definition PluginManager.cpp:2491
void set_lifecycle_hook_fn(LifecycleHookFn fn)
Definition LifecycleEvents.hpp:218
LifecycleEvent
Definition LifecycleEvents.hpp:19
Definition LifecycleEvents.hpp:71

References Slic3r::PluginManager::dispatch_lifecycle_event(), install_lifecycle_event_hook(), Slic3r::PluginManager::instance(), and Slic3r::set_lifecycle_hook_fn().

Referenced by install_lifecycle_event_hook().

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

◆ install_slicing_pipeline_hook()

void Slic3r::plugin_hooks::anonymous_namespace{PluginHooks.cpp}::install_slicing_pipeline_hook ( )
73{
75 [](Print& print, const PrintObject* object, SlicingPipelineStepPlugin step) {
76 const auto* caps = print.config().option<ConfigOptionStrings>("slicing_pipeline_plugin");
77 // `plugins` is a dynamic-only manifest key (not a static PrintConfig member), so it
78 // must be read from the full/dynamic config -- reading it off print.config() (the
79 // static PrintConfig) always yields nullptr and skips every capability. Mirrors the
80 // post-process path (PostProcessor.cpp, via BackgroundSlicingProcess::full_print_config()).
81 const auto* plugs = print.full_print_config().option<ConfigOptionStrings>("plugins");
82 if (caps == nullptr || caps->values.empty())
83 return;
84
87 [&](std::shared_ptr<SlicingPipelinePluginCapability> cap, const PluginCapabilityRef& ref) {
88 const std::string plugin_key = ref.uuid.empty() ? ref.name : ref.uuid;
90 try {
91 // GIL is acquired per capability (not once for the whole dispatch) so it
92 // is released between capabilities.
94 if (!gil)
95 throw std::runtime_error("Python interpreter is shutting down");
96 // throw_if_canceled() is protected on PrintBase; canceled() is the public
97 // equivalent check (same cancel flag), so honor cancellation via it.
98 if (print.canceled())
99 throw CanceledException();
101 ctx.orca_version = SoftFever_VERSION;
102 ctx.step = step;
103 ctx.print = &print;
104 ctx.object = object;
105 // Slicing hooks are synchronous by design and never await: the context
106 // borrows Print/PrintObject that are only valid during this call, and the
107 // UI thread may itself be blocked waiting on this slicing worker. An async
108 // override is rejected here rather than scheduled -- cap->execute() casts
109 // its Python result to ExecutionResult and a coroutine object cannot be
110 // cast, so it surfaces as the SlicingError below.
111 r = cap->execute(ctx);
112 } catch (const CanceledException&) {
113 throw; // cancellation must reach process(), never become a slicing error
114 } catch (const std::exception& ex) {
115 // A Python raise reaches here as pybind11::error_already_set; surface it as a
116 // (non-critical) slicing error instead of a crash.
117 throw SlicingError(GUI::format(_u8L("Slicing pipeline plugin '%1%' error: %2%"),
118 ref.capability_name, ex.what()));
119 }
121 throw SlicingError(GUI::format(_u8L("Slicing pipeline plugin '%1%' error: %2%"),
122 ref.capability_name, r.message));
123 // log a non-empty success/skipped message instead of dropping it. This is
124 // log-only by design: every pipeline hook fires AFTER set_done() (see Print.cpp),
125 // so the Print-level m_step_active is -1 here. Calling active_step_add_warning()
126 // would then index m_state[-1] (out-of-bounds; the guarding assert is compiled
127 // out in Release), so it must NOT be called from a pipeline hook.
128 if (!r.message.empty()) {
129 static const char* const kStepNames[] = {
130 "posSlice", "posPerimeters", "posEstimateCurledExtrusions", "posPrepareInfill", "posInfill",
131 "posIroning", "posContouring", "posSupportMaterial", "posDetectOverhangsForLift",
132 "posSimplifyPath", "psWipeTower", "psSkirtBrim", "psGCodePostProcess"
133 }; // order must match SlicingPipelineStepPlugin
134 const char* step_name = static_cast<size_t>(step) < sizeof(kStepNames) / sizeof(kStepNames[0])
135 ? kStepNames[static_cast<int>(step)] : "Unknown";
136 BOOST_LOG_TRIVIAL(info) << "Slicing pipeline plugin '" << ref.capability_name
137 << "' [" << step_name << "]: " << r.message;
138 }
139 });
140 });
141}
Definition PrintBase.hpp:48
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2768
Definition Config.hpp:1190
const DynamicPrintConfig & full_print_config() const
Definition PrintBase.hpp:518
bool canceled() const
Definition PrintBase.hpp:508
Definition Print.hpp:365
Definition Print.hpp:1054
static void set_slicing_pipeline_hook_fn(SlicingPipelineHookFn fn)
Definition Print.hpp:1064
const PrintConfig & config() const
Definition Print.hpp:1131
Definition PythonInterpreter.hpp:169
Definition Exception.hpp:32
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
std::string name
Definition Config.hpp:3145
@ SlicingPipeline
Definition PythonPluginInterface.hpp:17
void execute_capabilities_from_refs(const ConfigOptionStrings &capabilities, const ConfigOptionStrings *plugins, PluginCapabilityType type, std::function< void(std::shared_ptr< T >, const PluginCapabilityRef &)> execute)
Definition PluginManager.hpp:416
std::string capability_name
Definition Config.hpp:3146
std::string uuid
Definition Config.hpp:3147
@ FatalError
Definition PythonPluginInterface.hpp:105
SlicingPipelineStepPlugin
Definition Print.hpp:132
Definition Config.hpp:3144
void step(Coord &crd, const Dir d, const long n=1)
Definition MarchingSquares.hpp:213
#define _u8L(s)
Definition I18N.hpp:11
Definition PythonPluginInterface.hpp:108
std::string message
Definition PythonPluginInterface.hpp:110
PluginResult status
Definition PythonPluginInterface.hpp:109
Definition SlicingPipelinePluginCapability.hpp:17
SlicingPipelineStepPlugin step
Definition SlicingPipelinePluginCapability.hpp:19
std::string orca_version
Definition SlicingPipelinePluginCapability.hpp:18
Print * print
Definition SlicingPipelinePluginCapability.hpp:20
const PrintObject * object
Definition SlicingPipelinePluginCapability.hpp:21

References _u8L, Slic3r::PrintBase::canceled(), Slic3r::PluginCapabilityRef::capability_name, Slic3r::Print::config(), Slic3r::execute_capabilities_from_refs(), Slic3r::FatalError, Slic3r::GUI::format(), Slic3r::PrintBase::full_print_config(), install_slicing_pipeline_hook(), Slic3r::ExecutionResult::message, Slic3r::PluginCapabilityRef::name, Slic3r::SlicingPipelineContext::object, Slic3r::ConfigBase::option(), Slic3r::SlicingPipelineContext::orca_version, Slic3r::SlicingPipelineContext::print, Slic3r::Print::set_slicing_pipeline_hook_fn(), Slic3r::SlicingPipeline, Slic3r::ExecutionResult::status, Slic3r::SlicingPipelineContext::step, and Slic3r::PluginCapabilityRef::uuid.

Referenced by install_slicing_pipeline_hook().

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