ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
Runtime.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #pragma once
9 
10 #include <pybind11/pytypes.h>
13 
14 #include "../../wrapper/pycc/src/casters.h"
15 
16 namespace py = pybind11;
17 
18 namespace Runtime
19 {
20 
22 {
23  struct Action
24  {
25  Action() = delete;
26  Action(QString name, pybind11::object target, pybind11::object icon = pybind11::none())
27  : name(std::move(name)), target(std::move(target)), icon(std::move(icon))
28  {
29  }
30 
32  QString name{};
34  pybind11::object target{};
36  pybind11::object icon{};
37  };
38 
40  static RegisteredPlugin InstanciatePlugin(pybind11::object class_type,
41  const QString &name) noexcept(false)
42  {
43  pybind11::object instance = class_type();
44  py::list pyActions = instance.attr("getActions")();
45  std::vector<Action> actions;
46  actions.reserve(pyActions.size());
47 
48  for (const py::handle &handle : pyActions)
49  {
50  actions.push_back(handle.cast<Runtime::RegisteredPlugin::Action>());
51  }
52 
53  const pybind11::object mainIcon = instance.attr("getIcon")();
54 
55  return {name, instance, actions, mainIcon};
56  }
57 
60  static RegisteredPlugin InstanciatePlugin(pybind11::object class_type) noexcept(false)
61  {
62  QString name = class_type.attr("__name__").cast<QString>();
63  return InstanciatePlugin(class_type, name);
64  }
65 
66  QString name;
67  pybind11::object instance;
68  std::vector<Action> actions;
69  pybind11::object mainIcon;
70 };
71 
74 void setMainAppInterfaceInstance(ecvMainAppInterface *appInterface) noexcept(false);
76 void unsetMainAppInterfaceInstance() noexcept;
77 
82 void unsetCmdLineInterfaceInstance() noexcept;
83 
84 } // namespace Runtime
Command line interface.
Main application interface (for plugins)
void setMainAppInterfaceInstance(ecvMainAppInterface *appInterface) noexcept(false)
Definition: Runtime.cpp:82
void unsetMainAppInterfaceInstance() noexcept
Unsets the app interface pointer.
Definition: Runtime.cpp:90
void setCmdLineInterfaceInstance(ccCommandLineInterface *cmdLine) noexcept
Definition: Runtime.cpp:99
void unsetCmdLineInterfaceInstance() noexcept
Unsets the pointer to the cmdline app interface.
Definition: Runtime.cpp:107
Definition: Eigen.h:85
pybind11::object target
The target python function (or method)
Definition: Runtime.h:34
QString name
Name to be displayed in the UI.
Definition: Runtime.h:32
Action(QString name, pybind11::object target, pybind11::object icon=pybind11::none())
Definition: Runtime.h:26
pybind11::object icon
Optional path or (bytes, str) where str is the format.
Definition: Runtime.h:36
static RegisteredPlugin InstanciatePlugin(pybind11::object class_type) noexcept(false)
Definition: Runtime.h:60
static RegisteredPlugin InstanciatePlugin(pybind11::object class_type, const QString &name) noexcept(false)
Instanciate a plugin with a known name.
Definition: Runtime.h:40
pybind11::object mainIcon
Definition: Runtime.h:69
std::vector< Action > actions
Definition: Runtime.h:68
pybind11::object instance
Definition: Runtime.h:67