httplib: add support for exclude attributes
Fixes: https://gitlab.com/kicad/code/kicad/-/issues/15720
This commit is contained in:
parent
a3c662839c
commit
f2fdf0f3df
|
@ -220,6 +220,32 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
|
|||
|
||||
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
|
||||
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
|
||||
if( properties.contains( "visible" ) )
|
||||
{
|
||||
std::string buf = properties.at( "visible" );
|
||||
visible = boolFromString( buf );
|
||||
std::string vis = properties.at( "visible" );
|
||||
visible = boolFromString( vis, true );
|
||||
}
|
||||
|
||||
// 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
|
||||
{
|
||||
wxString strval( std::any_cast<std::string>( aVal ).c_str(), wxConvUTF8 );
|
||||
|
||||
if( strval.IsEmpty() )
|
||||
return true;
|
||||
return aDefaultValue;
|
||||
|
||||
strval.MakeLower();
|
||||
|
||||
|
@ -379,7 +405,7 @@ bool HTTP_LIB_CONNECTION::boolFromString( const std::any& aVal )
|
|||
{
|
||||
}
|
||||
|
||||
return true;
|
||||
return aDefaultValue;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -382,6 +382,10 @@ LIB_SYMBOL* SCH_HTTP_LIB_PLUGIN::loadSymbolFromPart( const wxString& aS
|
|||
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;
|
||||
|
||||
for( auto& _field : aPart.fields )
|
||||
|
|
|
@ -84,7 +84,7 @@ private:
|
|||
|
||||
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 );
|
||||
|
||||
|
|
|
@ -51,6 +51,10 @@ struct HTTP_LIB_PART
|
|||
std::string name;
|
||||
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
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue