From 3bb1bdbf4ced293115d3d9706bfdb7fcacd306bb Mon Sep 17 00:00:00 2001 From: Jelle Spijker Date: Mon, 23 Oct 2023 08:50:49 +0200 Subject: [PATCH] Add functionality to retrieve plugin information Added a new method to retrieve plugin information, such as name and version, from loaded plugins. This feature is helpful for adding debugging and traceability to code generated by 3D slicing. The information is added to the GCode file header, allowing tracking which plugins were used during slicing process. Contribute to CURA-11212 --- include/plugins/pluginproxy.h | 5 +++++ include/plugins/slotproxy.h | 9 +++++++++ include/plugins/slots.h | 38 +++++++++++++++++++++++++++++++++++ src/gcodeExport.cpp | 6 ++++++ 4 files changed, 58 insertions(+) diff --git a/include/plugins/pluginproxy.h b/include/plugins/pluginproxy.h index 2ff7b5c0c3..5572304513 100644 --- a/include/plugins/pluginproxy.h +++ b/include/plugins/pluginproxy.h @@ -165,6 +165,11 @@ class PluginProxy } ~PluginProxy() = default; + [[nodiscard]] const std::optional& getPluginInfo() const noexcept + { + return plugin_info_; + } + value_type generate(auto&&... args) { agrpc::GrpcContext grpc_context; diff --git a/include/plugins/slotproxy.h b/include/plugins/slotproxy.h index 037db10a19..34c3565ab3 100644 --- a/include/plugins/slotproxy.h +++ b/include/plugins/slotproxy.h @@ -104,6 +104,15 @@ class SlotProxy plugin_.value().template broadcast(std::forward(args)...); } } + + [[nodiscard]] const std::optional getPluginInfo() const noexcept + { + if (plugin_.has_value()) + { + return plugin_->getPluginInfo(); + } + return std::nullopt; + } }; } // namespace cura::plugins diff --git a/include/plugins/slots.h b/include/plugins/slots.h index ed7c91a4e6..498c39ade5 100644 --- a/include/plugins/slots.h +++ b/include/plugins/slots.h @@ -21,6 +21,13 @@ #include "utils/polygon.h" #include "utils/types/char_range_literal.h" +#include +#include +#include +#include +#include +#include + #include #include #include @@ -132,6 +139,21 @@ class Registry, Unit> constexpr void broadcast([[maybe_unused]] auto&&... args) noexcept { } // Base case, do nothing + + ranges::any_view getConnectedPluginInfo() + { + return ranges::views::single(std::optional{ std::nullopt }) + | ranges::views::remove_if( + [](const auto& plugin_info) + { + return ! plugin_info.has_value(); + }) + | ranges::views::transform( + [](const auto& plugin_info) + { + return plugin_info.value(); + }); + } }; template class Unit> @@ -179,6 +201,22 @@ class Registry, Unit> : public Registry Base::template broadcast(std::forward(args)...); } + ranges::any_view getConnectedPluginInfo() + { + ranges::any_view plugin_info_view = ranges::views::single(value_.proxy.getPluginInfo()) + | ranges::views::remove_if( + [](const auto& plugin_info) + { + return ! plugin_info.has_value(); + }) + | ranges::views::transform( + [](const auto& plugin_info) + { + return plugin_info.value(); + }); + return ranges::views::concat(Base::getConnectedPluginInfo(), plugin_info_view); + } + protected: template constexpr auto& get_type() diff --git a/src/gcodeExport.cpp b/src/gcodeExport.cpp index caff200811..75f97924a8 100644 --- a/src/gcodeExport.cpp +++ b/src/gcodeExport.cpp @@ -13,7 +13,10 @@ #include "settings/types/LayerIndex.h" #include "utils/Date.h" #include "utils/string.h" // MMtoStream, PrecisionedDouble +#include "plugins/slots.h" +#include +#include #include #include @@ -205,6 +208,7 @@ std::string GCodeExport::getFileHeader( std::ostringstream prefix; const size_t extruder_count = Application::getInstance().current_slice->scene.extruders.size(); + auto used_plugins = slots::instance().getConnectedPluginInfo() | ranges::views::transform([](const auto& plugin_info){ return fmt::format("{}: {}", plugin_info.plugin_name, plugin_info.plugin_version); }); switch (flavor) { case EGCodeFlavor::GRIFFIN: @@ -262,6 +266,7 @@ std::string GCodeExport::getFileHeader( prefix << ";PRINT.SIZE.MAX.Y:" << INT2MM(total_bounding_box.max.y) << new_line; prefix << ";PRINT.SIZE.MAX.Z:" << INT2MM(total_bounding_box.max.z) << new_line; prefix << ";SLICE_UUID:" << slice_uuid_ << new_line; + prefix << fmt::format(";ENGINE_PLUGINS:{}{}", used_plugins, new_line); prefix << ";END_OF_HEADER" << new_line; break; default: @@ -309,6 +314,7 @@ std::string GCodeExport::getFileHeader( prefix << ";MAXX:" << INT2MM(total_bounding_box.max.x) << new_line; prefix << ";MAXY:" << INT2MM(total_bounding_box.max.y) << new_line; prefix << ";MAXZ:" << INT2MM(total_bounding_box.max.z) << new_line; + prefix << fmt::format(";ENGINE_PLUGINS:{}{}", used_plugins, new_line); } return prefix.str();