27#include <google/protobuf/util/json_util.h>
34 for(
const std::unique_ptr<WIZARD_PARAMETER>& param :
m_info.parameters )
49 std::unique_ptr<FOOTPRINT_WIZARD> wizard = std::make_unique<FOOTPRINT_WIZARD>();
50 wizard->SetIdentifier( action->identifier );
53 m_wizards[wizard->Identifier()] = std::move( wizard );
61 std::vector<FOOTPRINT_WIZARD*> wizards;
63 for(
const std::unique_ptr<FOOTPRINT_WIZARD>& wizard :
m_wizards | std::views::values )
64 wizards.emplace_back( wizard.get() );
66 std::ranges::sort( wizards,
91 wxCHECK( aWizard,
false );
95 const wxLanguageInfo* lang = wxLocale::GetLanguageInfo(
Pgm().GetSelectedLanguageIdentifier() );
97 std::vector<wxString> args = {
109 kiapi::common::types::WizardInfo
info;
111 google::protobuf::util::JsonParseOptions options;
112 options.ignore_unknown_fields =
true;
114 if( !google::protobuf::util::JsonStringToMessage( out.ToStdString(), &
info, options ).ok() )
128 wxCHECK( aWizard, tl::unexpected(
_(
"Unexpected error with footprint wizard" ) ) );
131 const wxLanguageInfo* lang = wxLocale::GetLanguageInfo(
Pgm().GetSelectedLanguageIdentifier() );
133 std::vector<wxString> args = {
140 kiapi::common::types::WizardParameterList params;
142 for(
const std::unique_ptr<WIZARD_PARAMETER>& param : aWizard->
Info().
parameters )
143 params.mutable_parameters()->Add( param->Pack() );
145 std::string paramsJson;
147 if( !google::protobuf::util::MessageToJsonString( params, ¶msJson ).ok() )
148 return tl::unexpected(
_(
"Unexpected error with footprint wizard" ) );
150 args.emplace_back( wxString::Format( wxS(
"'%s'" ), paramsJson ) );
156 return tl::unexpected( wxString::Format(
_(
"Could not launch footprint wizard '%s'" ), aWizard->
Info().
meta.
name ) );
158 kiapi::common::types::WizardGeneratedContent response;
160 google::protobuf::util::JsonParseOptions options;
161 options.ignore_unknown_fields =
true;
163 if( !google::protobuf::util::JsonStringToMessage( out.ToStdString(), &response, options ).ok() )
165 wxLogTrace(
traceApi, wxString::Format(
"Could not decode response:\n%s", out ) );
166 return tl::unexpected(
_(
"Unexpected response from footprint wizard" ) );
169 if( response.status() != kiapi::common::types::WGS_OK )
170 return tl::unexpected( wxString::Format(
_(
"Footprint wizard error: %s" ), response.error_message() ) );
172 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
174 if( !fp->Deserialize( response.content() ) )
175 return tl::unexpected(
_(
"Unexpected response from footprint wizard" ) );
179 return tl::unexpected(
_(
"The KiCad API is disabled" ) );
186 identifier = wxString::FromUTF8( aProto.identifier() );
187 name = wxString::FromUTF8( aProto.name() );
188 description = wxString::FromUTF8( aProto.description() );
192 for(
int type : aProto.types_generated() )
193 types_generated.insert(
static_cast<kiapi::common::types::WizardContentType
>( type ) );
199 using namespace kiapi::common::types;
203 case WPC_PACKAGE:
return _(
"Package" );
204 case WPC_PADS:
return _(
"Pads" );
205 case WPC_3DMODEL:
return _(
"3D Model" );
206 case WPC_METADATA:
return _(
"General" );
207 case WPC_RULES:
return _(
"Design Rules" );
210 wxCHECK_MSG(
false, wxEmptyString,
"Unhandled parameter category type!" );
217 std::unique_ptr<WIZARD_PARAMETER> p;
219 if( aProto.has_int_() )
221 p = std::make_unique<WIZARD_INT_PARAMETER>();
224 else if( aProto.has_real() )
226 p = std::make_unique<WIZARD_REAL_PARAMETER>();
229 else if( aProto.has_string() )
231 p = std::make_unique<WIZARD_STRING_PARAMETER>();
234 else if( aProto.has_bool_() )
236 p = std::make_unique<WIZARD_BOOL_PARAMETER>();
240 p->identifier = wxString::FromUTF8( aProto.identifier() );
241 p->name = wxString::FromUTF8( aProto.name() );
242 p->description = wxString::FromUTF8( aProto.description() );
243 p->category = aProto.category();
244 p->type = aProto.type();
252 kiapi::common::types::WizardParameter packed;
258 packed.set_name(
name.ToUTF8() );
261 packed.set_type(
type );
272 packed.mutable_int_()->set_value(
value );
279 packed.mutable_int_()->set_min( *
min );
282 packed.mutable_int_()->set_max( *
max );
285 packed.mutable_int_()->set_multiple( *
multiple );
296 packed.mutable_real()->set_value(
value );
303 packed.mutable_real()->set_min( *
min );
306 packed.mutable_real()->set_max( *
max );
317 packed.mutable_bool_()->set_value(
value );
330 packed.mutable_string()->set_value(
value );
341 value = aProto.value();
344 if( aProto.has_min() )
349 if( aProto.has_max() )
354 if( aProto.has_multiple() )
363 value = aProto.value();
366 if( aProto.has_min() )
371 if( aProto.has_max() )
380 value = aProto.value();
387 value = wxString::FromUTF8( aProto.value() );
390 if( aProto.has_validation_regex() )
399 meta.FromProto( aProto.meta() );
402 parameters.reserve( aProto.parameters_size() );
404 for(
const kiapi::common::types::WizardParameter& parameter : aProto.parameters() )
Responsible for loading plugin definitions for API-based plugins (ones that do not run inside KiCad i...
int InvokeActionSync(const wxString &aIdentifier, std::vector< wxString > aExtraArgs, wxString *aStdout=nullptr, wxString *aStderr=nullptr)
Invokes an action synchronously, capturing its output.
std::vector< const PLUGIN_ACTION * > GetActionsForScope(PLUGIN_ACTION_SCOPE aScope)
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.
void FromProto(const kiapi::common::types::WizardIntParameter &aProto)
std::optional< int > multiple
kiapi::common::types::WizardParameter Pack(bool aCompact=true) override
Packs the current state of this parameter back into a protobuf message.
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)
static std::unique_ptr< WIZARD_PARAMETER > Create(const kiapi::common::types::WizardParameter &aProto)
kiapi::common::types::WizardParameterCategory category
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)
const wxChar *const traceApi
Flag to enable debug output related to the IPC API and its plugin system.
PGM_BASE & Pgm()
The global program "get" accessor.
An action performed by a plugin via the IPC API.
std::vector< std::unique_ptr< WIZARD_PARAMETER > > parameters
void FromProto(const kiapi::common::types::WizardInfo &aProto)