28#include <google/protobuf/util/json_util.h>
35 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 );
60 std::vector<FOOTPRINT_WIZARD*> wizards;
62 for(
const std::unique_ptr<FOOTPRINT_WIZARD>& wizard :
m_wizards | std::views::values )
63 wizards.emplace_back( wizard.get() );
65 std::ranges::sort( wizards,
90 wxCHECK( aWizard,
false );
94 const wxLanguageInfo* lang = wxLocale::GetLanguageInfo(
Pgm().GetSelectedLanguageIdentifier() );
96 std::vector<wxString> args = {
99 lang ? lang->CanonicalName : wxString( wxS(
"en" ) )
108 kiapi::common::types::WizardInfo
info;
110 google::protobuf::util::JsonParseOptions options;
111 options.ignore_unknown_fields =
true;
113 if( !google::protobuf::util::JsonStringToMessage( out.ToStdString(), &
info, options ).ok() )
120 aReporter->Report( error );
133 wxCHECK( aWizard, tl::unexpected(
_(
"Unexpected error with footprint wizard" ) ) );
136 const wxLanguageInfo* lang = wxLocale::GetLanguageInfo(
Pgm().GetSelectedLanguageIdentifier() );
138 std::vector<wxString> args = {
145 kiapi::common::types::WizardParameterList params;
147 for(
const std::unique_ptr<WIZARD_PARAMETER>& param : aWizard->
Info().
parameters )
148 params.mutable_parameters()->Add( param->Pack() );
150 std::string paramsJson;
152 if( !google::protobuf::util::MessageToJsonString( params, ¶msJson ).ok() )
153 return tl::unexpected(
_(
"Unexpected error with footprint wizard" ) );
155 args.emplace_back( wxString::FromUTF8( paramsJson ) );
162 wxString error = wxString::Format(
_(
"Could not launch footprint wizard '%s'" ), aWizard->
Info().
meta.
name );
168 error << wxS(
"\n\n" ) << err;
170 return tl::unexpected( error );
173 kiapi::common::types::WizardGeneratedContent response;
175 google::protobuf::util::JsonParseOptions options;
176 options.ignore_unknown_fields =
true;
178 if( !google::protobuf::util::JsonStringToMessage( out.ToStdString(), &response, options ).ok() )
180 wxLogTrace(
traceApi, wxString::Format(
"Could not decode response:\n%s", out ) );
181 return tl::unexpected(
_(
"Unexpected response from footprint wizard" ) );
184 if( response.status() != kiapi::common::types::WGS_OK )
185 return tl::unexpected( wxString::Format(
_(
"Footprint wizard error: %s" ), response.error_message() ) );
187 std::unique_ptr<FOOTPRINT> fp = std::make_unique<FOOTPRINT>(
nullptr );
189 if( !fp->Deserialize( response.content() ) )
190 return tl::unexpected(
_(
"Unexpected response from footprint wizard" ) );
198 identifier = wxString::FromUTF8( aProto.identifier() );
199 name = wxString::FromUTF8( aProto.name() );
200 description = wxString::FromUTF8( aProto.description() );
204 for(
int type : aProto.types_generated() )
205 types_generated.insert(
static_cast<kiapi::common::types::WizardContentType
>( type ) );
215 case WPC_PACKAGE:
return _(
"Package" );
216 case WPC_PADS:
return _(
"Pads" );
217 case WPC_3DMODEL:
return _(
"3D Model" );
218 case WPC_METADATA:
return _(
"General" );
219 case WPC_RULES:
return _(
"Design Rules" );
222 wxCHECK_MSG(
false, wxEmptyString,
"Unhandled parameter category type!" );
229 std::unique_ptr<WIZARD_PARAMETER> p;
231 if( aProto.has_int_() )
233 p = std::make_unique<WIZARD_INT_PARAMETER>();
236 else if( aProto.has_real() )
238 p = std::make_unique<WIZARD_REAL_PARAMETER>();
241 else if( aProto.has_string() )
243 p = std::make_unique<WIZARD_STRING_PARAMETER>();
246 else if( aProto.has_bool_() )
248 p = std::make_unique<WIZARD_BOOL_PARAMETER>();
251 else if( aProto.has_enum_() )
253 p = std::make_unique<WIZARD_ENUM_PARAMETER>();
260 p->identifier = wxString::FromUTF8( aProto.identifier() );
261 p->name = wxString::FromUTF8( aProto.name() );
262 p->description = wxString::FromUTF8( aProto.description() );
263 p->category = aProto.category();
264 p->type = aProto.type();
272 kiapi::common::types::WizardParameter packed;
278 packed.set_name(
name.ToUTF8() );
281 packed.set_type(
type );
292 packed.mutable_int_()->set_value(
value );
299 packed.mutable_int_()->set_min( *
min );
302 packed.mutable_int_()->set_max( *
max );
305 packed.mutable_int_()->set_multiple( *
multiple );
316 packed.mutable_real()->set_value(
value );
323 packed.mutable_real()->set_min( *
min );
326 packed.mutable_real()->set_max( *
max );
337 packed.mutable_bool_()->set_value(
value );
350 packed.mutable_string()->set_value(
value );
363 packed.mutable_enum_()->set_value(
value );
369 for(
const auto& [
id, label] :
choices )
371 kiapi::common::types::WizardEnumChoice* choice = packed.mutable_enum_()->add_choices();
372 choice->set_identifier(
id.ToUTF8() );
373 choice->set_label( label.ToUTF8() );
383 value = aProto.value();
386 if( aProto.has_min() )
391 if( aProto.has_max() )
396 if( aProto.has_multiple() )
405 value = aProto.value();
408 if( aProto.has_min() )
413 if( aProto.has_max() )
422 value = aProto.value();
429 value = wxString::FromUTF8( aProto.value() );
432 if( aProto.has_validation_regex() )
441 value = aProto.value();
445 choices.reserve( aProto.choices_size() );
447 for(
const kiapi::common::types::WizardEnumChoice& choice : aProto.choices() )
448 choices.emplace_back( wxString::FromUTF8( choice.identifier() ), wxString::FromUTF8( choice.label() ) );
454 meta.FromProto( aProto.meta() );
457 parameters.reserve( aProto.parameters_size() );
459 for(
const kiapi::common::types::WizardParameter& parameter : aProto.parameters() )
462 parameters.emplace_back( std::move( param ) );
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, std::shared_ptr< REPORTER > aReporter=nullptr)
Invokes an action synchronously, capturing its output.
std::vector< const PLUGIN_ACTION * > GetActionsForScope(PLUGIN_ACTION_SCOPE aScope)
Holds a structured error message.
KI_ERROR & SetDescription(const wxString &aDescription)
KI_ERROR & SetTitle(const wxString &aTitle)
virtual API_PLUGIN_MANAGER & GetPluginManager() const
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 > 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)