KiCad PCB EDA Suite
Loading...
Searching...
No Matches
api_plugin.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2024 Jon Evans <[email protected]>
5 * Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_API_PLUGIN_H
22#define KICAD_API_PLUGIN_H
23
24#include <memory>
25#include <optional>
26#include <set>
27#include <nlohmann/json_fwd.hpp>
28#include <wx/bmpbndl.h>
29#include <wx/filename.h>
30#include <wx/string.h>
31
32#include <kicommon.h>
33
34
36class API_PLUGIN;
37
38
40{
41 wxString package_name;
42 wxString version;
43};
44
45
47{
48 INVALID,
49 PYTHON,
50 EXEC
51};
52
53
55{
56 INVALID,
57 PCB,
60 SYMBOL,
62};
63
64
66{
67 bool FromJson( const nlohmann::json& aJson );
68
70 wxString min_version;
71 std::vector<PLUGIN_DEPENDENCY> dependencies;
72};
73
74
81{
82 PLUGIN_ACTION( const API_PLUGIN& aPlugin ) :
83 plugin( aPlugin )
84 {}
85
86 wxString identifier;
87 wxString name;
88 wxString description;
90 wxString entrypoint;
91 std::set<PLUGIN_ACTION_SCOPE> scopes;
92 std::vector<wxString> args;
93 wxBitmapBundle icon_light;
94 wxBitmapBundle icon_dark;
95
97};
98
105{
106public:
107 API_PLUGIN( const wxFileName& aConfigFile );
108
109 ~API_PLUGIN();
110
111 bool IsOk() const;
112
113 const wxString& Identifier() const;
114 const wxString& Name() const;
115 const wxString& Description() const;
116 const PLUGIN_RUNTIME& Runtime() const;
117 wxString BasePath() const;
118
119 const std::vector<PLUGIN_ACTION>& Actions() const;
120
121private:
122 friend struct API_PLUGIN_CONFIG;
123
124 std::optional<PLUGIN_ACTION> createActionFromJson( const nlohmann::json& aJson );
125
126 wxFileName m_configFile;
127
128 std::unique_ptr<API_PLUGIN_CONFIG> m_config;
129};
130
135{
136 bool operator()( const std::unique_ptr<API_PLUGIN>& item1, const std::unique_ptr<API_PLUGIN>& item2 ) const
137 {
138 return item1->Identifier() < item2->Identifier();
139 }
140};
141
142#endif //KICAD_API_PLUGIN_H
PLUGIN_RUNTIME_TYPE
Definition: api_plugin.h:47
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:55
A plugin that is invoked by KiCad and runs as an external process; communicating with KiCad via the I...
Definition: api_plugin.h:105
std::unique_ptr< API_PLUGIN_CONFIG > m_config
Definition: api_plugin.h:128
wxFileName m_configFile
Definition: api_plugin.h:126
#define KICOMMON_API
Definition: kicommon.h:28
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition: api_plugin.h:135
bool operator()(const std::unique_ptr< API_PLUGIN > &item1, const std::unique_ptr< API_PLUGIN > &item2) const
Definition: api_plugin.h:136
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
Definition: api_plugin.h:81
wxBitmapBundle icon_light
Definition: api_plugin.h:93
const API_PLUGIN & plugin
Definition: api_plugin.h:96
wxString name
Definition: api_plugin.h:87
wxString description
Definition: api_plugin.h:88
std::set< PLUGIN_ACTION_SCOPE > scopes
Definition: api_plugin.h:91
wxString identifier
Definition: api_plugin.h:86
wxString entrypoint
Definition: api_plugin.h:90
wxBitmapBundle icon_dark
Definition: api_plugin.h:94
std::vector< wxString > args
Definition: api_plugin.h:92
bool show_button
Definition: api_plugin.h:89
PLUGIN_ACTION(const API_PLUGIN &aPlugin)
Definition: api_plugin.h:82
wxString package_name
Definition: api_plugin.h:41
wxString version
Definition: api_plugin.h:42
wxString min_version
Definition: api_plugin.h:70
bool FromJson(const nlohmann::json &aJson)
Definition: api_plugin.cpp:33
PLUGIN_RUNTIME_TYPE type
Definition: api_plugin.h:69
std::vector< PLUGIN_DEPENDENCY > dependencies
Definition: api_plugin.h:71