Browse Source

ADDED: handling of meta-data items in REST libraries.

"description" and "keywords" must hold string values;
"footprint_filters" can either hold a (space-
separated) string value, or an array of strings.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/20750
master
Jeff Young 3 weeks ago
parent
commit
1f1f490887
  1. 21
      common/http_lib/http_lib_connection.cpp
  2. 16
      eeschema/sch_io/http_lib/sch_io_http_lib.cpp
  3. 6
      include/http_lib/http_lib_settings.h

21
common/http_lib/http_lib_connection.cpp

@ -255,6 +255,27 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
// Add field to fields list
aFetchedPart.fields.push_back( std::make_pair( key, std::make_tuple( value, visible ) ) );
}
if( response.contains( "description" ) )
aFetchedPart.desc = response.at( "description" );
if( response.contains( "keywords" ) )
aFetchedPart.keywords = response.at( "keywords" );
if( response.contains( "footprint_filters" ) )
{
nlohmann::json filters_json = response.at( "footprint_filters" );
if( filters_json.is_array() )
{
for( const auto& val : filters_json )
aFetchedPart.fp_filters.push_back( val );
}
else
{
aFetchedPart.fp_filters.push_back( filters_json );
}
}
}
catch( const std::exception& e )
{

16
eeschema/sch_io/http_lib/sch_io_http_lib.cpp

@ -370,14 +370,12 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbolName,
else if( !symbolId.IsValid() )
{
wxLogTrace( traceHTTPLib, wxT( "loadSymbolFromPart: source symbol id '%s' is invalid, "
"will create empty symbol" ),
symbolIdStr );
"will create empty symbol" ), symbolIdStr );
}
else
{
wxLogTrace( traceHTTPLib, wxT( "loadSymbolFromPart: source symbol '%s' not found, "
"will create empty symbol" ),
symbolIdStr );
"will create empty symbol" ), symbolIdStr );
}
}
@ -464,6 +462,16 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbolName,
}
}
symbol->SetDescription( aPart.desc );
symbol->SetKeyWords( aPart.keywords );
wxArrayString filters;
for( const std::string& filter : aPart.fp_filters )
filters.push_back( filter );
symbol->SetFPFilters( filters );
return symbol;
}

6
include/http_lib/http_lib_settings.h

@ -54,7 +54,11 @@ struct HTTP_LIB_PART
std::time_t lastCached = 0;
std::vector<std::pair<std::string, std::tuple<std::string, bool>>> fields; ///< additional generic fields
std::string desc;
std::string keywords;
std::vector<std::string> fp_filters;
std::vector<std::pair<std::string, std::tuple<std::string, bool>>> fields;
};

Loading…
Cancel
Save