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 The 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;
38
39
41{
42 wxString package_name;
43 wxString version;
44};
45
46
48{
49 INVALID,
50 PYTHON,
51 EXEC
52};
53
54
56{
57 INVALID,
58 PCB,
61 SYMBOL,
63};
64
65
67{
68 bool FromJson( const nlohmann::json& aJson );
69
71 wxString min_version;
72 std::vector<PLUGIN_DEPENDENCY> dependencies;
73};
74
75
82{
83 PLUGIN_ACTION( const API_PLUGIN& aPlugin ) :
84 plugin( aPlugin )
85 {}
86
87 wxString identifier;
88 wxString name;
89 wxString description;
90 bool show_button = false;
91 wxString entrypoint;
92 std::set<PLUGIN_ACTION_SCOPE> scopes;
93 std::vector<wxString> args;
94 wxBitmapBundle icon_light;
95 wxBitmapBundle icon_dark;
96
98};
99
106{
107public:
108 API_PLUGIN( const wxFileName& aConfigFile, const JSON_SCHEMA_VALIDATOR& aValidator );
109
110 ~API_PLUGIN();
111
112 bool IsOk() const;
113
114 static bool IsValidIdentifier( const wxString& aIdentifier );
115
116 const wxString& Identifier() const;
117 const wxString& Name() const;
118 const wxString& Description() const;
119 const PLUGIN_RUNTIME& Runtime() const;
120 wxString BasePath() const;
121
122 const std::vector<PLUGIN_ACTION>& Actions() const;
123
124 wxString ActionSettingsKey( const PLUGIN_ACTION& aAction ) const;
125
126private:
127 friend struct API_PLUGIN_CONFIG;
128
129 std::optional<PLUGIN_ACTION> createActionFromJson( const nlohmann::json& aJson );
130
131 wxFileName m_configFile;
132
133 std::unique_ptr<API_PLUGIN_CONFIG> m_config;
134};
135
140{
141 bool operator()( const std::unique_ptr<API_PLUGIN>& item1,
142 const std::unique_ptr<API_PLUGIN>& item2 ) const
143 {
144 return item1->Identifier() < item2->Identifier();
145 }
146};
147
148#endif //KICAD_API_PLUGIN_H
PLUGIN_RUNTIME_TYPE
Definition: api_plugin.h:48
PLUGIN_ACTION_SCOPE
Definition: api_plugin.h:56
A plugin that is invoked by KiCad and runs as an external process; communicating with KiCad via the I...
Definition: api_plugin.h:106
std::unique_ptr< API_PLUGIN_CONFIG > m_config
Definition: api_plugin.h:133
wxFileName m_configFile
Definition: api_plugin.h:131
#define KICOMMON_API
Definition: kicommon.h:28
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition: api_plugin.h:140
bool operator()(const std::unique_ptr< API_PLUGIN > &item1, const std::unique_ptr< API_PLUGIN > &item2) const
Definition: api_plugin.h:141
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
Definition: api_plugin.h:82
wxBitmapBundle icon_light
Definition: api_plugin.h:94
const API_PLUGIN & plugin
Definition: api_plugin.h:97
wxString name
Definition: api_plugin.h:88
wxString description
Definition: api_plugin.h:89
std::set< PLUGIN_ACTION_SCOPE > scopes
Definition: api_plugin.h:92
wxString identifier
Definition: api_plugin.h:87
wxString entrypoint
Definition: api_plugin.h:91
wxBitmapBundle icon_dark
Definition: api_plugin.h:95
std::vector< wxString > args
Definition: api_plugin.h:93
bool show_button
Definition: api_plugin.h:90
PLUGIN_ACTION(const API_PLUGIN &aPlugin)
Definition: api_plugin.h:83
wxString package_name
Definition: api_plugin.h:42
wxString version
Definition: api_plugin.h:43
wxString min_version
Definition: api_plugin.h:71
bool FromJson(const nlohmann::json &aJson)
Definition: api_plugin.cpp:56
PLUGIN_RUNTIME_TYPE type
Definition: api_plugin.h:70
std::vector< PLUGIN_DEPENDENCY > dependencies
Definition: api_plugin.h:72