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
33#include <kicommon.h>
34
35
37class API_PLUGIN;
39
40
42{
43 wxString package_name;
44 wxString version;
45};
46
47
54
55
57{
58 bool FromJson( const nlohmann::json& aJson );
59
61 wxString min_version;
62 std::vector<PLUGIN_DEPENDENCY> dependencies;
63};
64
65
72{
73 PLUGIN_ACTION( const API_PLUGIN& aPlugin ) :
74 plugin( aPlugin )
75 {}
76
77 wxString identifier;
78 wxString name;
79 wxString description;
80 bool show_button = false;
81 wxString entrypoint;
82 std::set<PLUGIN_ACTION_SCOPE> scopes;
83 std::vector<wxString> args;
84 wxBitmapBundle icon_light;
85 wxBitmapBundle icon_dark;
86
88};
89
96{
97public:
98 API_PLUGIN( const wxFileName& aConfigFile, const JSON_SCHEMA_VALIDATOR& aValidator );
99
100 ~API_PLUGIN();
101
102 bool IsOk() const;
103
104 static bool IsValidIdentifier( const wxString& aIdentifier );
105
106 const wxString& Identifier() const;
107 const wxString& Name() const;
108 const wxString& Description() const;
109 const PLUGIN_RUNTIME& Runtime() const;
110 wxString BasePath() const;
111
112 const std::vector<PLUGIN_ACTION>& Actions() const;
113
114 wxString ActionSettingsKey( const PLUGIN_ACTION& aAction ) const;
115
116private:
117 friend struct API_PLUGIN_CONFIG;
118
119 std::optional<PLUGIN_ACTION> createActionFromJson( const nlohmann::json& aJson );
120
121 wxFileName m_configFile;
122
123 std::unique_ptr<API_PLUGIN_CONFIG> m_config;
124};
125
130{
131 bool operator()( const std::unique_ptr<API_PLUGIN>& item1,
132 const std::unique_ptr<API_PLUGIN>& item2 ) const
133 {
134 return item1->Identifier() < item2->Identifier();
135 }
136};
137
138#endif //KICAD_API_PLUGIN_H
PLUGIN_RUNTIME_TYPE
Definition api_plugin.h:49
A plugin that is invoked by KiCad and runs as an external process; communicating with KiCad via the I...
Definition api_plugin.h:96
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:117
wxString ActionSettingsKey(const PLUGIN_ACTION &aAction) const
const wxString & Identifier() const
std::unique_ptr< API_PLUGIN_CONFIG > m_config
Definition api_plugin.h:123
wxFileName m_configFile
Definition api_plugin.h:121
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)
#define KICOMMON_API
Definition kicommon.h:28
Comparison functor for ensuring API_PLUGINs have unique identifiers.
Definition api_plugin.h:130
bool operator()(const std::unique_ptr< API_PLUGIN > &item1, const std::unique_ptr< API_PLUGIN > &item2) const
Definition api_plugin.h:131
An action performed by a plugin via the IPC API (not to be confused with ACTION_PLUGIN,...
Definition api_plugin.h:72
wxBitmapBundle icon_light
Definition api_plugin.h:84
const API_PLUGIN & plugin
Definition api_plugin.h:87
wxString name
Definition api_plugin.h:78
wxString description
Definition api_plugin.h:79
std::set< PLUGIN_ACTION_SCOPE > scopes
Definition api_plugin.h:82
wxString identifier
Definition api_plugin.h:77
wxString entrypoint
Definition api_plugin.h:81
wxBitmapBundle icon_dark
Definition api_plugin.h:85
std::vector< wxString > args
Definition api_plugin.h:83
PLUGIN_ACTION(const API_PLUGIN &aPlugin)
Definition api_plugin.h:73
wxString package_name
Definition api_plugin.h:43
wxString min_version
Definition api_plugin.h:61
bool FromJson(const nlohmann::json &aJson)
PLUGIN_RUNTIME_TYPE type
Definition api_plugin.h:60
std::vector< PLUGIN_DEPENDENCY > dependencies
Definition api_plugin.h:62