Skip to content

Commit

Permalink
Add functionality to retrieve plugin information
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jellespijker committed Oct 23, 2023
1 parent d07570e commit 3bb1bdb
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 0 deletions.
5 changes: 5 additions & 0 deletions include/plugins/pluginproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ class PluginProxy
}
~PluginProxy() = default;

[[nodiscard]] const std::optional<plugin_metadata>& getPluginInfo() const noexcept
{
return plugin_info_;
}

value_type generate(auto&&... args)
{
agrpc::GrpcContext grpc_context;
Expand Down
9 changes: 9 additions & 0 deletions include/plugins/slotproxy.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,15 @@ class SlotProxy
plugin_.value().template broadcast<S>(std::forward<decltype(args)>(args)...);
}
}

[[nodiscard]] const std::optional<plugin_metadata> getPluginInfo() const noexcept
{
if (plugin_.has_value())
{
return plugin_->getPluginInfo();
}
return std::nullopt;
}
};

} // namespace cura::plugins
Expand Down
38 changes: 38 additions & 0 deletions include/plugins/slots.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
#include "utils/polygon.h"
#include "utils/types/char_range_literal.h"

#include <range/v3/view/any_view.hpp>
#include <range/v3/view/concat.hpp>
#include <range/v3/view/join.hpp>
#include <range/v3/view/remove_if.hpp>
#include <range/v3/view/single.hpp>
#include <range/v3/view/transform.hpp>

#include <exception>
#include <memory>
#include <tuple>
Expand Down Expand Up @@ -132,6 +139,21 @@ class Registry<Typelist<>, Unit>
constexpr void broadcast([[maybe_unused]] auto&&... args) noexcept
{
} // Base case, do nothing

ranges::any_view<plugin_metadata> getConnectedPluginInfo()
{
return ranges::views::single(std::optional<plugin_metadata>{ 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<typename T, typename... Types, template<typename> class Unit>
Expand Down Expand Up @@ -179,6 +201,22 @@ class Registry<Typelist<T, Types...>, Unit> : public Registry<Typelist<Types...>
Base::template broadcast<S>(std::forward<decltype(args)>(args)...);
}

ranges::any_view<plugin_metadata> getConnectedPluginInfo()
{
ranges::any_view<plugin_metadata> 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<v0::SlotID S>
constexpr auto& get_type()
Expand Down
6 changes: 6 additions & 0 deletions src/gcodeExport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
#include "settings/types/LayerIndex.h"
#include "utils/Date.h"
#include "utils/string.h" // MMtoStream, PrecisionedDouble
#include "plugins/slots.h"

#include <range/v3/view/transform.hpp>
#include <fmt/ranges.h>
#include <spdlog/spdlog.h>

#include <assert.h>
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3bb1bdb

Please sign in to comment.