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 <nlohmann/json-schema.hpp>
29#include <wx/bmpbndl.h>
30#include <wx/filename.h>
31#include <wx/string.h>
32
34#include <kicommon.h>
35
36
38class API_PLUGIN;
40
41
43{
44 wxString package_name;
45 wxString version;
46};
47
48
55
56
58{
59 bool FromJson( const nlohmann::json& aJson );
60
62 wxString min_version;
63 std::vector<PLUGIN_DEPENDENCY> dependencies;
64};
65
66
71{
72 PLUGIN_ACTION( const API_PLUGIN& aPlugin ) :
73 plugin( aPlugin )
74 {}
75
76 wxString identifier;
77 wxString name;
78 wxString description;
79 bool show_button = false;
80 wxString entrypoint;
81 std::set<PLUGIN_ACTION_SCOPE> scopes;
82 std::vector<wxString> args;
83 wxBitmapBundle icon_light;
84 wxBitmapBundle icon_dark;
85
87};
88
95{
96public:
97 API_PLUGIN( const wxFileName& aConfigFile, const JSON_SCHEMA_VALIDATOR& aValidator );
98
100
101 bool IsOk() const;
102
103 static bool IsValidIdentifier( const wxString& aIdentifier );
104
105 const wxString& Identifier() const;
106 const wxString& Name() const;
107 const wxString& Description() const;
108 const PLUGIN_RUNTIME& Runtime() const;
109 wxString BasePath() const;
110
111 const std::vector<PLUGIN_ACTION>& Actions() const;
112
113 wxString ActionSettingsKey( const PLUGIN_ACTION& aAction ) const;
114
115private:
116 friend struct API_PLUGIN_CONFIG;
117
118 std::optional<PLUGIN_ACTION> createActionFromJson( const nlohmann::json& aJson );
119
120 wxFileName m_configFile;
121
122 std::unique_ptr<API_PLUGIN_CONFIG> m_config;
123};
124
129{
130 bool operator()( const std::unique_ptr<API_PLUGIN>& item1,
131 const std::unique_ptr<API_PLUGIN>& item2 ) const
132 {
133 return item1->Identifier() < item2->Identifier();
134 }
135};
136
137
138class LOGGING_ERROR_HANDLER : public nlohmann::json_schema::error_handler
139{
140public:
142
143 bool HasError() const { return m_hasError; }
144
145 void error( const nlohmann::json::json_pointer& ptr, const nlohmann::json& instance,
146 const std::string& message ) override;
147
148private:
150};
151
152#endif //KICAD_API_PLUGIN_H
PLUGIN_RUNTIME_TYPE
Definition api_plugin.h:50
A plugin that is invoked by KiCad and runs as an external process; communicating with KiCad via the I...
Definition api_plugin.h:95
const PLUGIN_RUNTIME & Runtime() const
const wxString & Name() const
const std::vector< PLUGIN_ACTION > & Actions() const
friend struct API_PLUGIN_CONFIG
Definition api_plugin.h:116
wxString ActionSettingsKey(const PLUGIN_ACTION &aAction) const
const wxString & Identifier() const
std::unique_ptr< API_PLUGIN_CONFIG > m_config
Definition api_plugin.h:122
wxFileName m_configFile
Definition api_plugin.h:120
bool IsOk() const
wxString BasePath() const
static bool IsValidIdentifier(const wxString &aIdentifier)
const wxString & Description() const
API_PLUGIN(const wxFileName &aConfigFile, const JSON_SCHEMA_VALIDATOR &aValidator)
std::optional< PLUGIN_ACTION > createActionFromJson(const nlohmann::json &aJson)
bool HasError() const
Definition api_plugin.h:143
void error(const nlohmann::json::json_pointer &ptr, const nlohmann::json &instance, const std::string &message) override
#define KICOMMON_API
Definition kicommon.h:27
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition api_plugin.h:129
bool operator()(const std::unique_ptr< API_PLUGIN > &item1, const std::unique_ptr< API_PLUGIN > &item2) const
Definition api_plugin.h:130
An action performed by a plugin via the IPC API.
Definition api_plugin.h:71
wxBitmapBundle icon_light
Definition api_plugin.h:83
const API_PLUGIN & plugin
Definition api_plugin.h:86
wxString name
Definition api_plugin.h:77
wxString description
Definition api_plugin.h:78
std::set< PLUGIN_ACTION_SCOPE > scopes
Definition api_plugin.h:81
wxString identifier
Definition api_plugin.h:76
wxString entrypoint
Definition api_plugin.h:80
wxBitmapBundle icon_dark
Definition api_plugin.h:84
std::vector< wxString > args
Definition api_plugin.h:82
PLUGIN_ACTION(const API_PLUGIN &aPlugin)
Definition api_plugin.h:72
wxString package_name
Definition api_plugin.h:44
wxString min_version
Definition api_plugin.h:62
bool FromJson(const nlohmann::json &aJson)
PLUGIN_RUNTIME_TYPE type
Definition api_plugin.h:61
std::vector< PLUGIN_DEPENDENCY > dependencies
Definition api_plugin.h:63