mirror of
https://github.com/prusa3d/PrusaSlicer.git
synced 2026-11-26 23:29:07 +00:00
SPE-3961: PluginDialog: introduced support for combobox; PluginRegistry: checks slicer version and loading plugin metadata made exception-safe; ProjectApi: added support for FloatOrPercentage; PluginCliOps: setting correct min_slicer_version in manifest.json; MenuCommandRegistrar: plugin commands are now sorted
This commit is contained in:
parent
3c3162d73d
commit
816df0747b
17 changed files with 304 additions and 61 deletions
|
|
@ -84,7 +84,10 @@ The table `info` describes plugin with following keys:
|
|||
- `float` (UI: number input)
|
||||
- `int` (UI: number input)
|
||||
- `bool` (UI: checkbox)
|
||||
- `default` (number or string) default value
|
||||
- `combox` (UI: combo box)
|
||||
- `font` (UI: combo box with fill)
|
||||
- `default` (number or string) default value, only for `type` in one of `float`, `int` or `bool`
|
||||
- `allowed_values` (array of strings) list of items to choose from, only for `type="combobox"`
|
||||
|
||||
### Plugin `execute` function
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "com.prusa3d.slicer.calibration",
|
||||
"name": "Calibration patterns",
|
||||
"license": "AGPL-3.0-only",
|
||||
"min_slicer_version": "3.0.0",
|
||||
"min_slicer_version": "3.0.0-alpha11",
|
||||
"version": "1.0.0",
|
||||
"author": "prusa3d",
|
||||
"description": "Calibration patterns",
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
"id": "{{id}}",
|
||||
"name": "{{name}}",
|
||||
"version": "1.0.0",
|
||||
"min_slicer_version": "3.0.0",
|
||||
"min_slicer_version": "{{slicer_version}}",
|
||||
"author": "{{author}}",
|
||||
"description": "{{description}}",
|
||||
"license": "{{license}}",
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
|
||||
#include "Slic3r/Biz/Lua/LuaEngine.hpp"
|
||||
#include "Slic3r/Domain/Expr/ExprAst.hpp"
|
||||
#include "Slic3r/Domain/TextConfiguration.hpp"
|
||||
|
||||
namespace Slic3r::App::Lua {
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ enum class PluginType
|
|||
|
||||
tl::expected<PluginType, std::string> parse_plugin_type(std::string_view s);
|
||||
|
||||
using PluginParamValue = std::variant<bool, int, double, std::string>;
|
||||
using PluginParamValue = std::variant<bool, int, double, std::string, Domain::FontDescriptor>;
|
||||
using PluginParamValueMap = std::map<std::string, PluginParamValue>;
|
||||
|
||||
struct PluginParamDef
|
||||
|
|
@ -30,6 +31,7 @@ struct PluginParamDef
|
|||
std::string label;
|
||||
std::string type;
|
||||
std::optional<PluginParamValue> default_value;
|
||||
std::vector<std::string> allowed_values;
|
||||
};
|
||||
|
||||
using PluginParamDefs = std::vector<PluginParamDef>;
|
||||
|
|
@ -53,18 +55,20 @@ public:
|
|||
const PluginMeta& meta() const { return m_meta; }
|
||||
PluginMeta& meta() { return m_meta; }
|
||||
const std::string& path() const { return m_path; }
|
||||
const std::string& bundle_id() const { return m_bundle_id; }
|
||||
|
||||
sol::object execute(Biz::Lua::LuaEngine& lua, const PluginParamValueMap& params) const;
|
||||
|
||||
using ParseResult = tl::expected<Plugin, std::string>;
|
||||
static ParseResult
|
||||
parse(Biz::Lua::LuaEngine& lua, const std::string& id_prefix, const std::string& path);
|
||||
parse(Biz::Lua::LuaEngine& lua, const std::string& bundle_id, const std::string& path);
|
||||
|
||||
private:
|
||||
Plugin(std::string path, PluginMeta meta);
|
||||
Plugin(std::string path, std::string bundle_id, PluginMeta meta);
|
||||
|
||||
private:
|
||||
std::string m_path;
|
||||
std::string m_bundle_id;
|
||||
PluginMeta m_meta;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "Slic3r/App/Lua/Plugin.hpp"
|
||||
#include "Slic3r/App/Yoga/Dialog.hpp"
|
||||
#include "Slic3r/Domain/TextConfiguration.hpp"
|
||||
|
||||
namespace Slic3r::App::Lua {
|
||||
|
||||
|
|
@ -29,7 +30,11 @@ class PluginDialog : public Yoga::Dialog
|
|||
public:
|
||||
using ProcessFunction =
|
||||
std::function<void(const PluginMeta& meta, const PluginParamValueMap& param_values)>;
|
||||
explicit PluginDialog(ProcessFunction process_function);
|
||||
PluginDialog(
|
||||
ProcessFunction process_function,
|
||||
const Domain::FontList& fonts,
|
||||
const std::string& default_font_name
|
||||
);
|
||||
|
||||
void show_plugin(const PluginMeta& plugin_meta, const PluginParamValueMap& param_values);
|
||||
|
||||
|
|
@ -38,6 +43,16 @@ private:
|
|||
void emplace_float_param(const PluginParamDef& param, std::optional<PluginParamValue> default_value);
|
||||
void emplace_int_param(const PluginParamDef& param, std::optional<PluginParamValue> default_value);
|
||||
void emplace_bool_param(const PluginParamDef& param, std::optional<PluginParamValue> default_value);
|
||||
void emplace_combobox_param(
|
||||
const PluginParamDef& param,
|
||||
const std::vector<std::string>& allowed_values,
|
||||
const std::optional<PluginParamValue>& default_value
|
||||
);
|
||||
void emplace_combobox_param(
|
||||
const PluginParamDef& param,
|
||||
const std::vector<Domain::FontDescriptor>& allowed_values,
|
||||
const std::optional<PluginParamValue>& default_value
|
||||
);
|
||||
|
||||
Yoga::Item& emplace_row(const char* label=nullptr);
|
||||
void style_control(Yoga::Item& ctrl);
|
||||
|
|
@ -48,6 +63,8 @@ private:
|
|||
std::optional<PluginMeta> m_meta;
|
||||
Details::IParamControlMap m_param_controls;
|
||||
ProcessFunction m_process_function;
|
||||
Domain::FontList m_fonts;
|
||||
std::string m_default_font_name;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ private:
|
|||
std::vector<std::string> m_plugin_paths;
|
||||
Biz::ProjectInteractor& m_project_interactor;
|
||||
Biz::Emboss::IFontManager& m_font_manager;
|
||||
Domain::FontList m_fav_fonts;
|
||||
std::optional<PluginData> m_current_plugin_data, m_last_plugin_data;
|
||||
Yoga::Passthrough<PluginDialog> m_dialog;
|
||||
MarketplaceClient m_marketplace_client;
|
||||
|
|
|
|||
|
|
@ -13,7 +13,8 @@ class ProjectApi
|
|||
public:
|
||||
ProjectApi(
|
||||
Biz::ProjectInteractor& project_interactor,
|
||||
Biz::Emboss::IFontManager& font_manager
|
||||
Biz::Emboss::IFontManager& font_manager,
|
||||
const Domain::FontList& m_fav_fonts
|
||||
);
|
||||
|
||||
void register_api(Biz::Lua::LuaEngine& lua);
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ private:
|
|||
};
|
||||
|
||||
Plugin::ParseResult
|
||||
Plugin::parse(Biz::Lua::LuaEngine& lua, const std::string& id_prefix, const std::string& path)
|
||||
Plugin::parse(Biz::Lua::LuaEngine& lua, const std::string& bundle_id, const std::string& path)
|
||||
{
|
||||
auto& state = lua.state();
|
||||
if (!state["info"].is<sol::table>()) {
|
||||
|
|
@ -100,7 +100,7 @@ Plugin::parse(Biz::Lua::LuaEngine& lua, const std::string& id_prefix, const std:
|
|||
|
||||
sol::table info = state["info"];
|
||||
PluginMeta meta;
|
||||
meta.id = id_prefix + info["id"].get<std::string>();
|
||||
meta.id = bundle_id + "." + info["id"].get<std::string>();
|
||||
auto type_result = parse_plugin_type(info["type"].get<std::string>());
|
||||
if (!type_result.has_value()) {
|
||||
return tl::unexpected{type_result.error()};
|
||||
|
|
@ -124,8 +124,15 @@ Plugin::parse(Biz::Lua::LuaEngine& lua, const std::string& id_prefix, const std:
|
|||
auto name = p.get<std::string>("name");
|
||||
auto label = p.get_or<std::string>("label", name);
|
||||
auto type = p.get<std::string>("type");
|
||||
auto value = p.get<PluginParamValue>("default");
|
||||
meta.params.emplace_back(name, label, type, value);
|
||||
std::optional<PluginParamValue> value;
|
||||
if (p["default"].valid()) {
|
||||
value = p.get<PluginParamValue>("default");
|
||||
}
|
||||
std::vector<std::string> allowed_values;
|
||||
if (auto in_vals = p["allowed_values"]; in_vals.valid()) {
|
||||
allowed_values = in_vals.get<std::vector<std::string>>();
|
||||
}
|
||||
meta.params.emplace_back(name, label, type, value, allowed_values);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -144,10 +151,13 @@ Plugin::parse(Biz::Lua::LuaEngine& lua, const std::string& id_prefix, const std:
|
|||
return tl::unexpected{"Missing execute() function"};
|
||||
}
|
||||
|
||||
return Plugin{path, meta};
|
||||
return Plugin{path, bundle_id, meta};
|
||||
}
|
||||
|
||||
Plugin::Plugin(std::string path, PluginMeta meta) : m_path(std::move(path)), m_meta(std::move(meta))
|
||||
Plugin::Plugin(std::string path, std::string bundle_id, PluginMeta meta) :
|
||||
m_path(std::move(path)),
|
||||
m_bundle_id(std::move(bundle_id)),
|
||||
m_meta(std::move(meta))
|
||||
{}
|
||||
|
||||
sol::object Plugin::execute(Biz::Lua::LuaEngine& lua, const PluginParamValueMap& params) const
|
||||
|
|
|
|||
|
|
@ -299,7 +299,6 @@ PluginBundle::Plugins PluginBundle::load_plugins()
|
|||
Plugins plugins;
|
||||
|
||||
const auto files = m_content_provider->list_files();
|
||||
const std::string id_prefix = m_meta.id + ".";
|
||||
for (const auto& f : files) {
|
||||
if (f.ends_with(".lua")) {
|
||||
Biz::Lua::LuaEngine lua;
|
||||
|
|
@ -314,7 +313,7 @@ PluginBundle::Plugins PluginBundle::load_plugins()
|
|||
sol::error err = ret;
|
||||
SPDLOG_ERROR("Failed loading plugin {}: {}", entry_path.string(), err.what());
|
||||
}
|
||||
if (auto result = Plugin::parse(lua, id_prefix, entry_path.string())) {
|
||||
if (auto result = Plugin::parse(lua, m_meta.id, entry_path.string())) {
|
||||
auto&& plugin = result.value();
|
||||
|
||||
plugins.emplace_back(std::move(plugin));
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "Slic3r/App/Lua/PluginCliOps.hpp"
|
||||
|
||||
#include "Slic3r/Version.hpp"
|
||||
#include "Slic3r/Directories.hpp"
|
||||
#include "Slic3r/Log.hpp"
|
||||
#include "Slic3r/Biz/Algorithms/ZipArchive.hpp"
|
||||
|
|
@ -390,7 +391,8 @@ void plugin_init(PluginInitActionParams& params)
|
|||
{"name", json_escape(params.name.value())},
|
||||
{"license", json_escape(params.license.value())},
|
||||
{"description", json_escape(params.description.value_or("A plugin description"))},
|
||||
{"author", json_escape(params.author.value())}
|
||||
{"author", json_escape(params.author.value())},
|
||||
{"slicer_version", json_escape(VERSION)}
|
||||
}
|
||||
// clang-format on
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,9 @@
|
|||
#include <utility>
|
||||
|
||||
#include "Slic3r/App/Lua/PluginDialog.hpp"
|
||||
|
||||
#include "Slic3r/App/Imgui/DoubleSlider.hpp"
|
||||
#include "Slic3r/App/Yoga/ComboBox.hpp"
|
||||
#include "Slic3r/App/Yoga/InputTextField.hpp"
|
||||
#include "Slic3r/App/Yoga/Text.hpp"
|
||||
#include "Slic3r/App/Yoga/LayoutButton.hpp"
|
||||
|
|
@ -112,7 +115,11 @@ public:
|
|||
{
|
||||
std::string s_val;
|
||||
if (m_init_value.has_value()) {
|
||||
s_val = std::to_string(std::get<NumType>(m_init_value.value()));
|
||||
if (auto* v = std::get_if<double>(&m_init_value.value())) {
|
||||
s_val = std::to_string(*v);
|
||||
} else if (auto* v = std::get_if<int>(&m_init_value.value())) {
|
||||
s_val = std::to_string(*v);
|
||||
}
|
||||
} else {
|
||||
s_val = std::visit(
|
||||
[]<typename T>(const T& val) -> std::string
|
||||
|
|
@ -141,10 +148,62 @@ private:
|
|||
Yoga::InputTextField* m_textfield{nullptr};
|
||||
};
|
||||
|
||||
}
|
||||
template <typename ValueT>
|
||||
class ComboBoxControl : public Details::IParamControl
|
||||
{
|
||||
public:
|
||||
using Labels = std::vector<std::string>;
|
||||
using Values = std::vector<ValueT>;
|
||||
|
||||
PluginDialog::PluginDialog(ProcessFunction process_function)
|
||||
: m_process_function(std::move(process_function))
|
||||
ComboBoxControl(
|
||||
const PluginParamDef& param_def,
|
||||
Values allowed_values,
|
||||
Labels labels,
|
||||
const std::optional<PluginParamValue>& init_value
|
||||
) :
|
||||
m_param_def(param_def),
|
||||
m_values(std::move(allowed_values)),
|
||||
m_labels(std::move(labels))
|
||||
{
|
||||
std::optional<PluginParamValue> val = init_value.has_value() ? init_value.value() : param_def.default_value;
|
||||
if (val.has_value()) {
|
||||
if (auto it = std::ranges::find(m_values, std::get<ValueT>(val.value())); it != m_values.end()) {
|
||||
m_init_index = std::distance(m_values.begin(), it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PluginParamValue value() const override
|
||||
{
|
||||
return m_values.at(m_combobox->current_index());
|
||||
}
|
||||
|
||||
Yoga::Item& emplace_control(Yoga::Item& parent) override
|
||||
{
|
||||
m_combobox = parent.emplace_back<Yoga::ComboBox>(m_labels);
|
||||
if (m_init_index.has_value()) {
|
||||
m_combobox->set_current_index(m_init_index.value());
|
||||
}
|
||||
return *m_combobox;
|
||||
}
|
||||
private:
|
||||
const PluginParamDef& m_param_def;
|
||||
std::optional<size_t> m_init_index;
|
||||
Values m_values;
|
||||
Labels m_labels;
|
||||
Yoga::ComboBox* m_combobox{nullptr};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
PluginDialog::PluginDialog(
|
||||
ProcessFunction process_function,
|
||||
const Domain::FontList& fonts,
|
||||
const std::string& default_font_name
|
||||
) :
|
||||
m_process_function(std::move(process_function)),
|
||||
m_fonts(fonts),
|
||||
m_default_font_name(default_font_name)
|
||||
{
|
||||
append_tab("");
|
||||
|
||||
|
|
@ -177,7 +236,7 @@ PluginDialog::show_plugin(const PluginMeta& plugin_meta, const PluginParamValueM
|
|||
for (const auto& param : plugin_meta.params) {
|
||||
auto init_it = param_values.find(param.name);
|
||||
auto init_value =
|
||||
init_it == param_values.end() ? std::nullopt : std::make_optional(init_it->second);
|
||||
init_it == param_values.end() ? param.default_value : std::make_optional(init_it->second);
|
||||
if (param.type == "string") {
|
||||
emplace_string_param(param, init_value);
|
||||
} else if (param.type == "float") {
|
||||
|
|
@ -186,6 +245,25 @@ PluginDialog::show_plugin(const PluginMeta& plugin_meta, const PluginParamValueM
|
|||
emplace_int_param(param, init_value);
|
||||
} else if (param.type == "bool") {
|
||||
emplace_bool_param(param, init_value);
|
||||
} else if (param.type == "combobox") {
|
||||
emplace_combobox_param(param, param.allowed_values, init_value);
|
||||
} else if (param.type == "font") {
|
||||
std::string font_name;
|
||||
if (!init_value.has_value()) {
|
||||
font_name = m_default_font_name;
|
||||
} else if (auto* val = std::get_if<std::string>(&init_value.value())) {
|
||||
font_name = *val;
|
||||
}
|
||||
if (!font_name.empty()) {
|
||||
auto it = std::ranges::find_if(
|
||||
m_fonts,
|
||||
[&font_name](const auto& f) { return f.name == font_name || f.path == font_name; }
|
||||
);
|
||||
if (it != m_fonts.end()) {
|
||||
init_value = *it;
|
||||
}
|
||||
}
|
||||
emplace_combobox_param(param, m_fonts, init_value);
|
||||
} else {
|
||||
PANIC("Unsupported param type");
|
||||
}
|
||||
|
|
@ -280,6 +358,42 @@ void PluginDialog::emplace_bool_param(
|
|||
style_control(it->second->emplace_control(row));
|
||||
}
|
||||
|
||||
void PluginDialog::emplace_combobox_param(
|
||||
const PluginParamDef& param,
|
||||
const std::vector<std::string>& allowed_values,
|
||||
const std::optional<PluginParamValue>& default_value
|
||||
)
|
||||
{
|
||||
auto& row = emplace_row();
|
||||
auto [it, _] = m_param_controls.emplace(
|
||||
param.name,
|
||||
std::make_unique<ComboBoxControl<std::string>>(param, allowed_values, allowed_values, default_value)
|
||||
);
|
||||
style_control(it->second->emplace_control(row));
|
||||
|
||||
}
|
||||
|
||||
void PluginDialog::emplace_combobox_param(
|
||||
const PluginParamDef& param,
|
||||
const std::vector<Domain::FontDescriptor>& allowed_values,
|
||||
const std::optional<PluginParamValue>& default_value
|
||||
)
|
||||
{
|
||||
auto& row = emplace_row();
|
||||
using CBC = ComboBoxControl<Domain::FontDescriptor>;
|
||||
CBC::Labels labels;
|
||||
std::ranges::transform(allowed_values, std::back_inserter(labels), [](const auto& f) { return f.name; });
|
||||
|
||||
auto [it, _] = m_param_controls.emplace(
|
||||
param.name,
|
||||
std::make_unique<CBC>(param, allowed_values, labels, default_value)
|
||||
);
|
||||
style_control(it->second->emplace_control(row));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Yoga::Item& PluginDialog::emplace_row(const char* label)
|
||||
{
|
||||
auto* row = content()->emplace_back<Yoga::Item>();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
#include "Slic3r/App/Lua/PluginRegistry.hpp"
|
||||
|
||||
#include "Slic3r/Version.hpp"
|
||||
#include "Slic3r/Directories.hpp"
|
||||
#include "Slic3r/Assert.hpp"
|
||||
#include "Slic3r/Biz/I18N/I18N.hpp"
|
||||
|
|
@ -42,6 +43,8 @@ void PluginRegistry::scan(const std::string& path)
|
|||
return;
|
||||
}
|
||||
|
||||
auto slicer_ver = Semver::parse(VERSION);
|
||||
|
||||
for (const auto& entry : fs::directory_iterator{p}) {
|
||||
if (!entry.is_directory()) {
|
||||
if (entry.path().extension() == ".lua") {
|
||||
|
|
@ -67,27 +70,68 @@ void PluginRegistry::scan(const std::string& path)
|
|||
continue;;
|
||||
}
|
||||
|
||||
auto plugins = bundle.load_plugins();
|
||||
for (auto& plugin : plugins) {
|
||||
// make copy of metadata before moving plugin
|
||||
const auto plugin_id = plugin.meta().id;
|
||||
const auto plugin_path = plugin.path();
|
||||
auto [it, inserted] = m_plugins.emplace(plugin_id, std::move(plugin));
|
||||
if (!inserted) {
|
||||
SPDLOG_ERROR(
|
||||
"Plugin ID: {} of {} already registered by {}",
|
||||
plugin_id,
|
||||
plugin_path,
|
||||
it->second.path()
|
||||
if (bundle.meta().min_slicer_version > slicer_ver) {
|
||||
SPDLOG_INFO(
|
||||
"Plugin Bundle {} requires minimal version of Slicer {}, but current version is {}, skipping",
|
||||
bundle_path,
|
||||
bundle.meta().min_slicer_version.to_string(),
|
||||
slicer_ver->to_string()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
if (bundle.meta().max_slicer_version.has_value()
|
||||
&& bundle.meta().max_slicer_version.value() < slicer_ver)
|
||||
{
|
||||
SPDLOG_INFO(
|
||||
"Plugin Bundle {} requires max version of Slicer {}, but current version is {}, skipping",
|
||||
bundle_path,
|
||||
bundle.meta().max_slicer_version.value().to_string(),
|
||||
slicer_ver->to_string()
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (auto it = std::ranges::find_if(m_bundles, [bundle_id = bundle.meta().id](const auto& pb) { return pb.meta().id == bundle_id; }); it != m_bundles.end())
|
||||
{
|
||||
const auto inserted_version = it->meta().version;
|
||||
const auto to_insert_version = bundle.meta().version;
|
||||
if (to_insert_version <= inserted_version) {
|
||||
SPDLOG_INFO(
|
||||
"Skipping loading bundle {} in {}, as its version {} is older than the installed {}",
|
||||
bundle.meta().id,
|
||||
bundle_path,
|
||||
to_insert_version.to_string(),
|
||||
inserted_version.to_string()
|
||||
);
|
||||
} else if (it->second.meta().type == PluginType::ProjectPlugin
|
||||
&& !it->second.meta().menu.empty()) {
|
||||
auto menu_item = fmt::to_string(fmt::join(it->second.meta().menu, "/"));
|
||||
plugin_menu_items[menu_item].emplace_back(bundle.meta().id, &it->second);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
m_bundles.emplace_back(std::move(bundle));
|
||||
try {
|
||||
auto plugins = bundle.load_plugins();
|
||||
for (auto& plugin : plugins) {
|
||||
// make copy of metadata before moving plugin
|
||||
const auto plugin_id = plugin.meta().id;
|
||||
const auto plugin_path = plugin.path();
|
||||
auto [it, inserted] = m_plugins.emplace(plugin_id, std::move(plugin));
|
||||
if (!inserted) {
|
||||
SPDLOG_ERROR(
|
||||
"Plugin ID: {} of {} already registered by {}",
|
||||
plugin_id,
|
||||
plugin_path,
|
||||
it->second.path()
|
||||
);
|
||||
} else if (it->second.meta().type == PluginType::ProjectPlugin
|
||||
&& !it->second.meta().menu.empty()) {
|
||||
auto menu_item = fmt::to_string(fmt::join(it->second.meta().menu, "/"));
|
||||
plugin_menu_items[menu_item].emplace_back(bundle.meta().id, &it->second);
|
||||
}
|
||||
}
|
||||
|
||||
m_bundles.emplace_back(std::move(bundle));
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Loading plugin bundle {} failed with error: {}", bundle_path, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& [menu_item, conflicting_plugins] : plugin_menu_items) {
|
||||
|
|
|
|||
|
|
@ -93,7 +93,8 @@ PluginSystem::PluginSystem(
|
|||
) :
|
||||
m_plugin_paths(plugin_paths),
|
||||
m_project_interactor(project_interactor),
|
||||
m_font_manager(font_manager)
|
||||
m_font_manager(font_manager),
|
||||
m_fav_fonts(font_manager.create_favorit())
|
||||
{
|
||||
m_marketplace_client.add_listener<IMarketplaceClientListener>(this);
|
||||
}
|
||||
|
|
@ -188,7 +189,7 @@ Yoga::Passthrough<PluginDialog>& PluginSystem::init_dialog()
|
|||
{
|
||||
m_current_plugin_data = std::make_optional<PluginData>(meta, params);
|
||||
finalize_run();
|
||||
});
|
||||
}, m_font_manager.get_fonts(), m_fav_fonts.front().path);
|
||||
return m_dialog;
|
||||
}
|
||||
|
||||
|
|
@ -244,20 +245,24 @@ void PluginSystem::execute_plugin(const std::string& id)
|
|||
}
|
||||
const auto& plugin = it->second;
|
||||
ASSERT(m_dialog.get() != nullptr);
|
||||
m_dialog->show_plugin(
|
||||
plugin.meta(),
|
||||
m_last_plugin_data.has_value() && m_last_plugin_data->meta.id == id ?
|
||||
m_last_plugin_data->param_values :
|
||||
PluginParamValueMap{}
|
||||
);
|
||||
Biz::Platform::PlatformServices::instance().render_request_handler().request_render();
|
||||
try {
|
||||
m_dialog->show_plugin(
|
||||
plugin.meta(),
|
||||
m_last_plugin_data.has_value() && m_last_plugin_data->meta.id == id ?
|
||||
m_last_plugin_data->param_values :
|
||||
PluginParamValueMap{}
|
||||
);
|
||||
Biz::Platform::PlatformServices::instance().render_request_handler().request_render();
|
||||
} catch (std::exception& e) {
|
||||
SPDLOG_ERROR("Executin plugin {} failed with error: {}", plugin.path(), e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void PluginSystem::finalize_run()
|
||||
{
|
||||
ASSERT(m_current_plugin_data.has_value());
|
||||
|
||||
ProjectApi project_api(m_project_interactor, m_font_manager);
|
||||
ProjectApi project_api(m_project_interactor, m_font_manager, m_fav_fonts);
|
||||
Biz::Lua::LuaEngine lua;
|
||||
lua.open_registry([&project_api](auto& lua) { project_api.register_api(lua); });
|
||||
PackageRegistry package_registry;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,14 @@ sol::object to_lua(sol::state& lua, const Domain::ConfigValue& value)
|
|||
Domain::PrintModeParamValue default_value(const PluginParamDef& def)
|
||||
{
|
||||
if (def.default_value) {
|
||||
return *def.default_value;
|
||||
return std::visit(
|
||||
Domain::overloaded{
|
||||
[](const Domain::FontDescriptor& v) -> Domain::PrintModeParamValue
|
||||
{ PANIC("Unsupported"); },
|
||||
[]<typename T>(const T& v) -> Domain::PrintModeParamValue { return v; }
|
||||
},
|
||||
*def.default_value
|
||||
);
|
||||
}
|
||||
if (def.type == "bool") {
|
||||
return false;
|
||||
|
|
@ -101,7 +108,10 @@ PluginParamValueMap param_values(const Domain::PrintModeParams& params)
|
|||
PluginParamValueMap result;
|
||||
for (const auto& [name, param] : params) {
|
||||
// PluginParamValue and Domain::PrintModeParamValue are the same variant.
|
||||
result.insert_or_assign(name, param.value);
|
||||
result.insert_or_assign(
|
||||
name,
|
||||
std::visit([]<typename T>(const T& v) -> PluginParamValue { return v; }, param.value)
|
||||
);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -641,7 +641,8 @@ using ExposedConfigValue = std::variant<
|
|||
|
||||
ProjectApi::ProjectApi(
|
||||
Biz::ProjectInteractor& project_interactor,
|
||||
Biz::Emboss::IFontManager& font_manager
|
||||
Biz::Emboss::IFontManager& font_manager,
|
||||
const Domain::FontList& m_fav_fonts
|
||||
) :
|
||||
m_project_interactor(project_interactor),
|
||||
m_font_manager(font_manager),
|
||||
|
|
@ -650,7 +651,7 @@ ProjectApi::ProjectApi(
|
|||
Slic3r::data_dir() + "/text_emboss_presets_scripts.cereal",
|
||||
project_interactor
|
||||
),
|
||||
m_fav_fonts(font_manager.create_favorit())
|
||||
m_fav_fonts(m_fav_fonts)
|
||||
{
|
||||
m_text_preset_manager.init();
|
||||
}
|
||||
|
|
@ -695,6 +696,21 @@ void ProjectApi::register_api(Biz::Lua::LuaEngine& lua)
|
|||
//- local ModelElement = {}
|
||||
state.new_usertype<ModelElement>("ModelElement", sol::no_constructor, "type", sol::property(&ModelElement::type));
|
||||
|
||||
//--@class FloatOrPercentage
|
||||
//--@field is_percentage bool
|
||||
//- local FloatOrPercentage = {}
|
||||
|
||||
//-- Get absolue float value.
|
||||
//--@param ratio_over number A value to be used as baseline for percentage.
|
||||
//--@return number Absolute float value
|
||||
//- function FloatOrPercentage:get_abs_value(ratio_over) end
|
||||
state.new_usertype<Domain::FloatOrPercentage>(
|
||||
"FloatOrPercentage",
|
||||
sol::no_constructor,
|
||||
"get_abs_value", &Domain::FloatOrPercentage::get_abs_value,
|
||||
"is_percentage", sol::readonly_property(&Domain::FloatOrPercentage::is_percentage)
|
||||
);
|
||||
|
||||
//--@class ConfigBox
|
||||
//- local ConfigBox = {}
|
||||
|
||||
|
|
|
|||
|
|
@ -2318,13 +2318,28 @@ void MenuCommandRegistrar::update_main_menu_plugin_commands(Lua::PluginSystem& p
|
|||
|
||||
void MenuCommandRegistrar::register_main_menu_plugin_commands(Lua::PluginSystem& plugin_system)
|
||||
{
|
||||
bool any_plugin = false;
|
||||
for (auto& plugin : plugin_system.plugins() | std::views::values) {
|
||||
if (plugin.meta().type == Lua::PluginType::PrintMode) {
|
||||
continue;
|
||||
}
|
||||
// sort plugins by its menu path
|
||||
std::vector<std::tuple<std::string, std::vector<std::string>>> entries;
|
||||
std::ranges::transform(
|
||||
plugin_system.plugins()
|
||||
| std::views::values
|
||||
| std::views::filter(
|
||||
[](const auto& plugin) { return plugin.meta().type != Lua::PluginType::PrintMode; }
|
||||
),
|
||||
std::back_inserter(entries),
|
||||
[](const auto& p) -> std::tuple<std::string, std::vector<std::string>>
|
||||
{ return std::make_tuple(p.meta().id, p.meta().menu); }
|
||||
);
|
||||
std::ranges::sort(entries, {}, [](const auto& p) { return std::get<1>(p); });
|
||||
auto plugin_range =
|
||||
entries
|
||||
| std::views::transform(
|
||||
[&plugin_system](const auto& p) -> const Lua::Plugin&
|
||||
{ return plugin_system.plugins().at(std::get<0>(p)); }
|
||||
);
|
||||
|
||||
any_plugin = true;
|
||||
// register menu items of plugin entries
|
||||
for (auto& plugin : plugin_range) {
|
||||
std::vector<UniversalMenuItemName> path;
|
||||
if (plugin.meta().menu.empty()) {
|
||||
path = {
|
||||
|
|
@ -2353,7 +2368,9 @@ void MenuCommandRegistrar::register_main_menu_plugin_commands(Lua::PluginSystem&
|
|||
)
|
||||
);
|
||||
}
|
||||
if (any_plugin) {
|
||||
|
||||
// register other plugin related menu items
|
||||
if (!entries.empty()) {
|
||||
m_menu_manager.register_menu_separator_item({MenuItemName::Plugins});
|
||||
}
|
||||
m_menu_manager.register_menu_item(
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ TEST_CASE("Scanning records each bundle's id and version", "[plugin][marketplace
|
|||
{
|
||||
boost::nowide::ofstream manifest{bundle_dir / "manifest.json"};
|
||||
manifest << R"({"id":"com.test.scan","version":"1.2.3","author":"tester","name":"Test scan",)"
|
||||
<< R"("license":"MIT","min_slicer_version":"3.0.0",)"
|
||||
<< R"("license":"MIT","min_slicer_version":"3.0.0-alpha0",)"
|
||||
<< R"("plugin_api_version":"1.0.0", "required_apis": {"project.plugin": "1.0.0"}})";
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue