httplib: add support for exclude attributes

Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15720
This commit is contained in:
Andre Iwers 2023-09-24 13:37:01 +00:00 committed by Jon Evans
parent a3c662839c
commit f2fdf0f3df
4 changed files with 40 additions and 6 deletions

View File

@ -220,6 +220,32 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
aFetchedPart.symbolIdStr = response.at( "symbolIdStr" ); aFetchedPart.symbolIdStr = response.at( "symbolIdStr" );
// initially assume no exclusion
std::string exclude;
if( response.contains( "exclude_from_bom" ) )
{
// if key value doesn't exists default to false
exclude = response.at( "exclude_from_bom" );
aFetchedPart.exclude_from_bom = boolFromString( exclude, false );
}
// initially assume no exclusion
if( response.contains( "exclude_from_board" ) )
{
// if key value doesn't exists default to false
exclude = response.at( "exclude_from_board" );
aFetchedPart.exclude_from_board = boolFromString( exclude, false );
}
// initially assume no exclusion
if( response.contains( "exclude_from_sim" ) )
{
// if key value doesn't exists default to false
exclude = response.at( "exclude_from_sim" );
aFetchedPart.exclude_from_sim = boolFromString( exclude, false );
}
// Extract available fields // Extract available fields
for( const auto& field : response.at( "fields" ).items() ) for( const auto& field : response.at( "fields" ).items() )
{ {
@ -236,8 +262,8 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
// check if user wants to display field in schematic // check if user wants to display field in schematic
if( properties.contains( "visible" ) ) if( properties.contains( "visible" ) )
{ {
std::string buf = properties.at( "visible" ); std::string vis = properties.at( "visible" );
visible = boolFromString( buf ); visible = boolFromString( vis, true );
} }
// Add field to fields list // Add field to fields list
@ -352,14 +378,14 @@ bool HTTP_LIB_CONNECTION::checkServerResponse( std::unique_ptr<KICAD_CURL_EASY>&
} }
bool HTTP_LIB_CONNECTION::boolFromString( const std::any& aVal ) bool HTTP_LIB_CONNECTION::boolFromString( const std::any& aVal, bool aDefaultValue )
{ {
try try
{ {
wxString strval( std::any_cast<std::string>( aVal ).c_str(), wxConvUTF8 ); wxString strval( std::any_cast<std::string>( aVal ).c_str(), wxConvUTF8 );
if( strval.IsEmpty() ) if( strval.IsEmpty() )
return true; return aDefaultValue;
strval.MakeLower(); strval.MakeLower();
@ -379,7 +405,7 @@ bool HTTP_LIB_CONNECTION::boolFromString( const std::any& aVal )
{ {
} }
return true; return aDefaultValue;
} }
/* /*

View File

@ -382,6 +382,10 @@ LIB_SYMBOL* SCH_HTTP_LIB_PLUGIN::loadSymbolFromPart( const wxString& aS
symbol->LibId().SetSubLibraryName( aCategory.name ); symbol->LibId().SetSubLibraryName( aCategory.name );
} }
symbol->SetExcludedFromBOM( aPart.exclude_from_bom );
symbol->SetExcludedFromBoard( aPart.exclude_from_board );
symbol->SetExcludedFromSim( aPart.exclude_from_sim );
LIB_FIELD* field; LIB_FIELD* field;
for( auto& _field : aPart.fields ) for( auto& _field : aPart.fields )

View File

@ -84,7 +84,7 @@ private:
bool checkServerResponse( std::unique_ptr<KICAD_CURL_EASY>& aCurl ); bool checkServerResponse( std::unique_ptr<KICAD_CURL_EASY>& aCurl );
bool boolFromString( const std::any& aVal ); bool boolFromString( const std::any& aVal, bool aDefaultValue = false );
wxString httpErrorCodeDescription( uint16_t aHttpCode ); wxString httpErrorCodeDescription( uint16_t aHttpCode );

View File

@ -51,6 +51,10 @@ struct HTTP_LIB_PART
std::string name; std::string name;
std::string symbolIdStr; std::string symbolIdStr;
bool exclude_from_bom = false;
bool exclude_from_board = false;
bool exclude_from_sim = false;
std::map<std::string, std::tuple<std::string, bool>> fields; ///< additional generic fields std::map<std::string, std::tuple<std::string, bool>> fields; ///< additional generic fields
}; };