KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_wizard.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) 2026 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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef FOOTPRINT_WIZARD_H
22#define FOOTPRINT_WIZARD_H
23
24#include <optional>
25#include <tl/expected.hpp>
26
27#include <import_export.h>
28#include <api/common/types/wizards.pb.h>
29
30class FOOTPRINT;
31class REPORTER;
32
33
34
35// Wrapper for WizardMetaInfo protobuf with UTF8-converted strings
37{
38 wxString identifier;
39 wxString name;
40 wxString description;
41 std::set<kiapi::common::types::WizardContentType> types_generated;
42
43 void FromProto( const kiapi::common::types::WizardMetaInfo& aProto );
44};
45
47{
48public:
49 WIZARD_PARAMETER() = default;
50 virtual ~WIZARD_PARAMETER() = default;
51
52 virtual void Reset() = 0;
53
59 virtual kiapi::common::types::WizardParameter Pack( bool aCompact = true );
60
61 wxString identifier;
62 wxString name;
63 wxString description;
64 kiapi::common::types::WizardParameterCategory category = kiapi::common::types::WPC_UNKNOWN;
65 kiapi::common::types::WizardParameterDataType type = kiapi::common::types::WPDT_UNKNOWN;
66
67 static std::unique_ptr<WIZARD_PARAMETER> Create( const kiapi::common::types::WizardParameter& aProto );
68
69 static wxString ParameterCategoryName( kiapi::common::types::WizardParameterCategory aCategory );
70};
71
73{
74public:
75 void Reset() override { value = default_value; }
76 kiapi::common::types::WizardParameter Pack( bool aCompact = true ) override;
77
78 int value = 0;
80 std::optional<int> min;
81 std::optional<int> max;
82 std::optional<int> multiple;
83
84 void FromProto( const kiapi::common::types::WizardIntParameter& aProto );
85};
86
88{
89public:
90 void Reset() override { value = default_value; }
91 kiapi::common::types::WizardParameter Pack( bool aCompact = true ) override;
92
93 double value = 0.0;
94 double default_value = 0.0;
95 std::optional<double> min;
96 std::optional<double> max;
97
98 void FromProto( const kiapi::common::types::WizardRealParameter& aProto );
99};
100
102{
103public:
104 void Reset() override { value = default_value; }
105 kiapi::common::types::WizardParameter Pack( bool aCompact = true ) override;
106
107 bool value = false;
108 bool default_value = false;
109
110 void FromProto( const kiapi::common::types::WizardBoolParameter& aProto );
111};
112
114{
115public:
116 void Reset() override { value = default_value; }
117 kiapi::common::types::WizardParameter Pack( bool aCompact = true ) override;
118
119 wxString value;
121 std::optional<wxString> validation_regex;
122
123 void FromProto( const kiapi::common::types::WizardStringParameter& aProto );
124};
125
127{
128public:
129 void Reset() override { value = default_value; }
130 kiapi::common::types::WizardParameter Pack( bool aCompact = true ) override;
131
132 int value = 0;
134
136 std::vector<std::pair<wxString, wxString>> choices;
137
138 void FromProto( const kiapi::common::types::WizardEnumParameter& aProto );
139};
140
141// Wrapper for WizardInfo protobuf
143{
145 std::vector<std::unique_ptr<WIZARD_PARAMETER>> parameters;
146
147 void FromProto( const kiapi::common::types::WizardInfo& aProto );
148};
149
150
152{
153public:
155 ~FOOTPRINT_WIZARD() = default;
156
157 WIZARD_INFO& Info() { return m_info; }
158 const WIZARD_INFO& Info() const { return m_info; }
159
160 const wxString& Identifier() const { return m_identifier; }
161 void SetIdentifier( const wxString& aId ) { m_identifier = aId; }
162
163 void ResetParameters();
164
165private:
167
168 // Identifier of the plugin action
169 wxString m_identifier;
170};
171
179{
180public:
183
193 void ReloadWizards( std::shared_ptr<REPORTER> aReporter = nullptr );
194
195 std::optional<FOOTPRINT_WIZARD*> GetWizard( const wxString& aIdentifier );
196
197 std::vector<FOOTPRINT_WIZARD*> Wizards() const;
198
207 static bool RefreshInfo( FOOTPRINT_WIZARD* aWizard, std::shared_ptr<REPORTER> aReporter = nullptr );
208
214 tl::expected<FOOTPRINT*, wxString> Generate( FOOTPRINT_WIZARD* aWizard );
215
216private:
217
218 // Loaded wizards, mapped by identifier
219 std::map<wxString, std::unique_ptr<FOOTPRINT_WIZARD>> m_wizards;
220};
221
222
223#endif /* FOOTPRINT_WIZARD_H */
std::map< wxString, std::unique_ptr< FOOTPRINT_WIZARD > > m_wizards
std::vector< FOOTPRINT_WIZARD * > Wizards() const
void ReloadWizards(std::shared_ptr< REPORTER > aReporter=nullptr)
Goes through the list of IPC API plugins that provide wizard actions and attempts to refresh the info...
std::optional< FOOTPRINT_WIZARD * > GetWizard(const wxString &aIdentifier)
static bool RefreshInfo(FOOTPRINT_WIZARD *aWizard, std::shared_ptr< REPORTER > aReporter=nullptr)
Runs a wizard plugin with the –get-info argument, which should result in the plugin dumping a WizardI...
tl::expected< FOOTPRINT *, wxString > Generate(FOOTPRINT_WIZARD *aWizard)
Generates a footprint using a given wizard.
~FOOTPRINT_WIZARD_MANAGER()=default
const wxString & Identifier() const
const WIZARD_INFO & Info() const
WIZARD_INFO & Info()
void SetIdentifier(const wxString &aId)
~FOOTPRINT_WIZARD()=default
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
void FromProto(const kiapi::common::types::WizardBoolParameter &aProto)
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
std::vector< std::pair< wxString, wxString > > choices
pair<identifier, label>
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
void FromProto(const kiapi::common::types::WizardEnumParameter &aProto)
void FromProto(const kiapi::common::types::WizardIntParameter &aProto)
std::optional< int > min
std::optional< int > multiple
void Reset() override
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
std::optional< int > max
virtual kiapi::common::types::WizardParameter Pack(bool aCompact=true)
Packs the current state of this parameter back into a protobuf message.
kiapi::common::types::WizardParameterDataType type
static wxString ParameterCategoryName(kiapi::common::types::WizardParameterCategory aCategory)
virtual ~WIZARD_PARAMETER()=default
static std::unique_ptr< WIZARD_PARAMETER > Create(const kiapi::common::types::WizardParameter &aProto)
kiapi::common::types::WizardParameterCategory category
virtual void Reset()=0
WIZARD_PARAMETER()=default
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
void FromProto(const kiapi::common::types::WizardRealParameter &aProto)
std::optional< double > min
std::optional< double > max
std::optional< wxString > validation_regex
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
void FromProto(const kiapi::common::types::WizardStringParameter &aProto)
std::vector< std::unique_ptr< WIZARD_PARAMETER > > parameters
WIZARD_META_INFO meta
void FromProto(const kiapi::common::types::WizardInfo &aProto)
void FromProto(const kiapi::common::types::WizardMetaInfo &aProto)
std::set< kiapi::common::types::WizardContentType > types_generated