Browse Source

Formatting and naming conventions.

master
Jeff Young 2 months ago
parent
commit
2eb3518e49
  1. 77
      common/http_lib/http_lib_connection.cpp
  2. 8
      common/http_lib/http_lib_settings.cpp
  3. 3
      eeschema/sch_io/altium/sch_io_altium.cpp
  4. 4
      eeschema/sch_io/database/sch_io_database.cpp
  5. 82
      eeschema/sch_io/http_lib/sch_io_http_lib.cpp
  6. 26
      eeschema/sch_io/http_lib/sch_io_http_lib.h
  7. 10
      eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp
  8. 6
      eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp
  9. 30
      include/http_lib/http_lib_connection.h
  10. 31
      include/http_lib/http_lib_settings.h

77
common/http_lib/http_lib_connection.cpp

@ -40,19 +40,11 @@ HTTP_LIB_CONNECTION::HTTP_LIB_CONNECTION( const HTTP_LIB_SOURCE& aSource, bool a
m_source = aSource;
if( aTestConnectionNow )
{
ValidateHTTPLibraryEndpoints();
}
validateHttpLibraryEndpoints();
}
HTTP_LIB_CONNECTION::~HTTP_LIB_CONNECTION()
{
// Do nothing
}
bool HTTP_LIB_CONNECTION::ValidateHTTPLibraryEndpoints()
bool HTTP_LIB_CONNECTION::validateHttpLibraryEndpoints()
{
m_endpointValid = false;
std::string res = "";
@ -78,11 +70,8 @@ bool HTTP_LIB_CONNECTION::ValidateHTTPLibraryEndpoints()
nlohmann::json response = nlohmann::json::parse( res );
// Check that the endpoints exist, if not fail.
if( !response.at( http_endpoint_categories ).empty()
&& !response.at( http_endpoint_parts ).empty() )
{
if( !response.at( "categories" ).empty() && !response.at( "parts" ).empty() )
m_endpointValid = true;
}
}
}
catch( const std::exception& e )
@ -90,25 +79,15 @@ bool HTTP_LIB_CONNECTION::ValidateHTTPLibraryEndpoints()
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
e.what(), res );
wxLogTrace( traceHTTPLib,
wxT( "ValidateHTTPLibraryEndpoints: Exception occurred while testing the API "
"connection: %s" ),
wxLogTrace( traceHTTPLib, wxT( "validateHttpLibraryEndpoints: Exception while testing API connection: %s" ),
m_lastError );
m_endpointValid = false;
}
if( m_endpointValid )
{
syncCategories();
}
return m_endpointValid;
}
bool HTTP_LIB_CONNECTION::IsValidEndpoint() const
{
return m_endpointValid;
}
@ -124,7 +103,7 @@ bool HTTP_LIB_CONNECTION::syncCategories()
std::string res = "";
std::unique_ptr<KICAD_CURL_EASY> curl = createCurlEasyObject();
curl->SetURL( m_source.root_url + http_endpoint_categories + ".json" );
curl->SetURL( m_source.root_url + "categories.json" );
try
{
@ -133,9 +112,7 @@ bool HTTP_LIB_CONNECTION::syncCategories()
res = curl->GetBuffer();
if( !checkServerResponse( curl ) )
{
return false;
}
nlohmann::json response = nlohmann::json::parse( res );
@ -162,9 +139,7 @@ bool HTTP_LIB_CONNECTION::syncCategories()
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
e.what(), res );
wxLogTrace( traceHTTPLib,
wxT( "syncCategories: Exception occurred while syncing categories: %s" ),
m_lastError );
wxLogTrace( traceHTTPLib, wxT( "syncCategories: Exception while syncing categories: %s" ), m_lastError );
m_categories.clear();
@ -187,8 +162,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
if( m_cachedParts.find( aPartID ) != m_cachedParts.end() )
{
// check if it's outdated, if so re-fetch
if( std::difftime( std::time( nullptr ), m_cachedParts[aPartID].lastCached )
< m_source.timeout_parts )
if( std::difftime( std::time( nullptr ), m_cachedParts[aPartID].lastCached ) < m_source.timeout_parts )
{
aFetchedPart = m_cachedParts[aPartID];
return true;
@ -198,7 +172,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
std::string res = "";
std::unique_ptr<KICAD_CURL_EASY> curl = createCurlEasyObject();
std::string url = m_source.root_url + fmt::format( "{}/{}.json", http_endpoint_parts, aPartID );
std::string url = m_source.root_url + fmt::format( "parts/{}.json", aPartID );
curl->SetURL( url );
try
@ -208,9 +182,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
res = curl->GetBuffer();
if( !checkServerResponse( curl ) )
{
return false;
}
nlohmann::ordered_json response = nlohmann::ordered_json::parse( res );
std::string key = "";
@ -225,13 +197,9 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
// API might not want to return an optional name.
if( response.contains( "name" ) )
{
aFetchedPart.name = response.at( "name" );
}
else
{
aFetchedPart.name = aFetchedPart.id;
}
aFetchedPart.symbolIdStr = response.at( "symbolIdStr" );
@ -285,18 +253,15 @@ 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 ) ) );
aFetchedPart.fields.push_back( std::make_pair( key, std::make_tuple( value, visible ) ) );
}
}
catch( const std::exception& e )
{
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
e.what(), res );
wxLogTrace( traceHTTPLib,
wxT( "SelectOne: Exception occurred while retrieving part from REST API: %s" ),
m_lastError );
wxLogTrace( traceHTTPLib, wxT( "SelectOne: Exception while fetching part: %s" ), m_lastError );
return false;
}
@ -307,8 +272,7 @@ bool HTTP_LIB_CONNECTION::SelectOne( const std::string& aPartID, HTTP_LIB_PART&
}
bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
std::vector<HTTP_LIB_PART>& aParts )
bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory, std::vector<HTTP_LIB_PART>& aParts )
{
if( !IsValidEndpoint() )
{
@ -320,8 +284,7 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
std::unique_ptr<KICAD_CURL_EASY> curl = createCurlEasyObject();
curl->SetURL( m_source.root_url
+ fmt::format( "{}/category/{}.json", http_endpoint_parts, aCategory.id ) );
curl->SetURL( m_source.root_url + fmt::format( "parts/category/{}.json", aCategory.id ) );
try
{
@ -341,19 +304,15 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
if( item.contains( "description" ) )
{
// At this point we don't display anything so just set it to false
part.fields.push_back( std::make_pair(
"description", std::make_tuple( item.at( "description" ), false ) ) );
part.fields.push_back( std::make_pair( "description",
std::make_tuple( item.at( "description" ), false ) ) );
}
// API might not want to return an optional name.
if( item.contains( "name" ) )
{
part.name = item.at( "name" );
}
else
{
part.name = part.id;
}
// add to cache
m_cache[part.name] = std::make_tuple( part.id, aCategory.id );
@ -363,11 +322,10 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
}
catch( const std::exception& e )
{
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
m_lastError += wxString::Format( _( "Error: %s" ) + "\n" + _( "API Response: %s" ) + "\n",
e.what(), res );
wxLogTrace( traceHTTPLib, wxT( "Exception occurred while syncing parts from REST API: %s" ),
m_lastError );
wxLogTrace( traceHTTPLib, wxT( "Exception occurred while syncing parts: %s" ), m_lastError );
return false;
}
@ -379,6 +337,7 @@ bool HTTP_LIB_CONNECTION::SelectAll( const HTTP_LIB_CATEGORY& aCategory,
bool HTTP_LIB_CONNECTION::checkServerResponse( std::unique_ptr<KICAD_CURL_EASY>& aCurl )
{
int statusCode = aCurl->GetResponseStatusCode();
if( statusCode != 200 )
{
m_lastError += wxString::Format( _( "API responded with error code: %s" ) + "\n",

8
common/http_lib/http_lib_settings.cpp

@ -35,10 +35,9 @@ const int httplibSchemaVersion = 1;
HTTP_LIB_SETTINGS::HTTP_LIB_SETTINGS( const std::string& aFilename ) :
JSON_SETTINGS( aFilename, SETTINGS_LOC::NONE, httplibSchemaVersion )
{
m_params.emplace_back( new PARAM<std::string>( "source.type", &sourceType, "" ) );
m_params.emplace_back( new PARAM<std::string>( "source.type", &m_sourceType, "" ) );
m_params.emplace_back(
new PARAM<std::string>( "source.api_version", &m_Source.api_version, "" ) );
m_params.emplace_back( new PARAM<std::string>( "source.api_version", &m_Source.api_version, "" ) );
m_params.emplace_back( new PARAM<std::string>( "source.root_url", &m_Source.root_url, "" ) );
@ -46,8 +45,7 @@ HTTP_LIB_SETTINGS::HTTP_LIB_SETTINGS( const std::string& aFilename ) :
m_params.emplace_back( new PARAM<int>( "source.timeout_parts_seconds", &m_Source.timeout_parts, 30 ) );
m_params.emplace_back( new PARAM<int>( "source.timeout_categories_seconds",
&m_Source.timeout_categories, 600 ) );
m_params.emplace_back( new PARAM<int>( "source.timeout_categories_seconds", &m_Source.timeout_categories, 600 ) );
}

3
eeschema/sch_io/altium/sch_io_altium.cpp

@ -4839,8 +4839,7 @@ void SCH_IO_ALTIUM::doEnumerateSymbolLib( const wxString& aLibraryPath,
{
ensureLoadedLibrary( aLibraryPath, aProperties );
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
auto it = m_libCache.find( aLibraryPath );

4
eeschema/sch_io/database/sch_io_database.cpp

@ -73,9 +73,7 @@ void SCH_IO_DATABASE::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
if( !m_conn )
THROW_IO_ERROR( m_lastError );
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) !=
aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
for( auto const& pair : m_nameToSymbolcache )
{

82
eeschema/sch_io/http_lib/sch_io_http_lib.cpp

@ -36,13 +36,7 @@ SCH_IO_HTTP_LIB::SCH_IO_HTTP_LIB() :
}
SCH_IO_HTTP_LIB::~SCH_IO_HTTP_LIB()
{
}
void SCH_IO_HTTP_LIB::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
const wxString& aLibraryPath,
void SCH_IO_HTTP_LIB::EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
std::vector<LIB_SYMBOL*> symbols;
@ -53,23 +47,17 @@ void SCH_IO_HTTP_LIB::EnumerateSymbolLib( wxArrayString& aSymbolNameList
}
void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
void SCH_IO_HTTP_LIB::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
wxCHECK_RET( m_libTable, _( "httplib plugin missing library table handle!" ) );
ensureSettings( aLibraryPath );
ensureConnection();
if( !m_conn )
{
THROW_IO_ERROR( m_lastError );
return;
}
bool powerSymbolsOnly =
( aProperties
&& aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
for( const HTTP_LIB_CATEGORY& category : m_conn->getCategories() )
{
@ -123,12 +111,10 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::LoadSymbol( const wxString& aLibraryPath, const wxS
std::vector<HTTP_LIB_CATEGORY> categories = m_conn->getCategories();
if( m_conn->getCachedParts().empty() )
{
if( m_conn->GetCachedParts().empty() )
syncCache();
}
std::tuple relations = m_conn->getCachedParts()[partName];
std::tuple relations = m_conn->GetCachedParts()[partName];
std::string associatedCatID = std::get<1>( relations );
// get the matching category
@ -160,13 +146,12 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::LoadSymbol( const wxString& aLibraryPath, const wxS
if( m_conn->SelectOne( part_id, result ) )
{
wxLogTrace( traceHTTPLib, wxT( "loadSymbol: SelectOne (%s) found in %s" ), part_id,
foundCategory->name );
wxLogTrace( traceHTTPLib, wxT( "LoadSymbol: SelectOne (%s) found in %s" ), part_id, foundCategory->name );
}
else
{
wxLogTrace( traceHTTPLib, wxT( "loadSymbol: SelectOne (%s) failed for category %s" ),
part_id, foundCategory->name );
wxLogTrace( traceHTTPLib, wxT( "LoadSymbol: SelectOne (%s) failed for category %s" ), part_id,
foundCategory->name );
THROW_IO_ERROR( m_lastError );
}
@ -195,11 +180,13 @@ void SCH_IO_HTTP_LIB::GetSubLibraryNames( std::vector<wxString>& aNames )
}
}
wxString SCH_IO_HTTP_LIB::GetSubLibraryDescription( const wxString& aName )
{
return m_conn->getCategoryDescription( std::string( aName.mb_str() ) );
}
void SCH_IO_HTTP_LIB::GetAvailableSymbolFields( std::vector<wxString>& aNames )
{
// TODO: Implement this sometime; This is currently broken...
@ -209,8 +196,7 @@ void SCH_IO_HTTP_LIB::GetAvailableSymbolFields( std::vector<wxString>& aNames )
void SCH_IO_HTTP_LIB::GetDefaultSymbolFields( std::vector<wxString>& aNames )
{
std::copy( m_defaultShownFields.begin(), m_defaultShownFields.end(),
std::back_inserter( aNames ) );
std::copy( m_defaultShownFields.begin(), m_defaultShownFields.end(), std::back_inserter( aNames ) );
}
@ -319,14 +305,14 @@ void SCH_IO_HTTP_LIB::connect()
}
}
void SCH_IO_HTTP_LIB::syncCache()
{
for( const HTTP_LIB_CATEGORY& category : m_conn->getCategories() )
{
syncCache( category );
}
}
void SCH_IO_HTTP_LIB::syncCache( const HTTP_LIB_CATEGORY& category )
{
std::vector<HTTP_LIB_PART> found_parts;
@ -352,9 +338,9 @@ void SCH_IO_HTTP_LIB::syncCache( const HTTP_LIB_CATEGORY& category )
}
LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbolName,
LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbolName,
const HTTP_LIB_CATEGORY& aCategory,
const HTTP_LIB_PART& aPart )
const HTTP_LIB_PART& aPart )
{
LIB_SYMBOL* symbol = nullptr;
LIB_SYMBOL* originalSymbol = nullptr;
@ -368,14 +354,11 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo
symbolId.Parse( symbolIdStr );
if( symbolId.IsValid() )
{
originalSymbol = m_libTable->LoadSymbol( symbolId );
}
if( originalSymbol )
{
wxLogTrace( traceHTTPLib, wxT( "loadSymbolFromPart: found original symbol '%s'" ),
symbolIdStr );
wxLogTrace( traceHTTPLib, wxT( "loadSymbolFromPart: found original symbol '%s'" ), symbolIdStr );
symbol = originalSymbol->Duplicate();
symbol->SetSourceLibId( symbolId );
@ -413,44 +396,41 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo
symbol->SetExcludedFromBoard( aPart.exclude_from_board );
symbol->SetExcludedFromSim( aPart.exclude_from_sim );
SCH_FIELD* field;
for( auto& _field : aPart.fields )
for( auto& [fieldName, fieldProperties] : aPart.fields )
{
wxString fieldName = wxString( _field.first );
std::tuple fieldProperties = _field.second;
wxString lowerFieldName = wxString( fieldName ).Lower();
if( fieldName.Lower() == footprint_field )
if( lowerFieldName == footprint_field )
{
field = &symbol->GetFootprintField();
SCH_FIELD* field = &symbol->GetFootprintField();
field->SetText( std::get<0>( fieldProperties ) );
field->SetVisible( std::get<1>( fieldProperties ) );
}
else if( fieldName.Lower() == description_field )
else if( lowerFieldName == description_field )
{
field = &symbol->GetDescriptionField();
SCH_FIELD* field = &symbol->GetDescriptionField();
field->SetText( std::get<0>( fieldProperties ) );
field->SetVisible( std::get<1>( fieldProperties ) );
}
else if( fieldName.Lower() == value_field )
else if( lowerFieldName == value_field )
{
field = &symbol->GetValueField();
SCH_FIELD* field = &symbol->GetValueField();
field->SetText( std::get<0>( fieldProperties ) );
field->SetVisible( std::get<1>( fieldProperties ) );
}
else if( fieldName.Lower() == datasheet_field )
else if( lowerFieldName == datasheet_field )
{
field = &symbol->GetDatasheetField();
SCH_FIELD* field = &symbol->GetDatasheetField();
field->SetText( std::get<0>( fieldProperties ) );
field->SetVisible( std::get<1>( fieldProperties ) );
}
else if( fieldName.Lower() == reference_field )
else if( lowerFieldName == reference_field )
{
field = &symbol->GetReferenceField();
SCH_FIELD* field = &symbol->GetReferenceField();
field->SetText( std::get<0>( fieldProperties ) );
field->SetVisible( std::get<1>( fieldProperties ) );
}
else if( fieldName.Lower() == keywords_field )
else if( lowerFieldName == keywords_field )
{
symbol->SetKeyWords( std::get<0>( fieldProperties ) );
}
@ -461,7 +441,7 @@ LIB_SYMBOL* SCH_IO_HTTP_LIB::loadSymbolFromPart( const wxString& aSymbo
// This proves useful in situations where, for instance, an individual requires a particular value, such as
// the material type showcased at a specific position for a capacitor. Subsequently, this value could be defined
// in the symbol itself and then, potentially, be modified by the HTTP library as necessary.
field = symbol->GetField( fieldName );
SCH_FIELD* field = symbol->GetField( fieldName );
if( field != nullptr )
{

26
eeschema/sch_io/http_lib/sch_io_http_lib.h

@ -18,9 +18,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SCH_IO_HTTP_LIB_H
#define SCH_IO_HTTP_LIB_H
#pragma once
#include "http_lib/http_lib_settings.h"
#include <http_lib/http_lib_connection.h>
@ -40,12 +38,11 @@ class SCH_IO_HTTP_LIB : public SCH_IO
{
public:
SCH_IO_HTTP_LIB();
virtual ~SCH_IO_HTTP_LIB();
~SCH_IO_HTTP_LIB() override = default;
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
{
return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ),
{ FILEEXT::HTTPLibraryFileExtension } );
return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ), { FILEEXT::HTTPLibraryFileExtension } );
}
int GetModifyHash() const override { return 0; }
@ -94,18 +91,15 @@ private:
LIB_SYMBOL* loadSymbolFromPart( const wxString& aSymbolName, const HTTP_LIB_CATEGORY& aCategory,
const HTTP_LIB_PART& aPart );
SYMBOL_LIB_TABLE* m_libTable;
private:
SYMBOL_LIB_TABLE* m_libTable;
/// Generally will be null if no valid connection is established
std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
std::set<wxString> m_customFields;
std::set<wxString> m_defaultShownFields;
wxString m_lastError;
std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
std::set<wxString> m_customFields;
std::set<wxString> m_defaultShownFields;
wxString m_lastError;
wxString symbol_field = "symbol";
wxString footprint_field = "footprint";
@ -118,5 +112,3 @@ private:
// category.id category
std::map<std::string, HTTP_LIB_CATEGORY> m_cachedCategories;
};
#endif // SCH_IO_HTTP_LIB_H_

10
eeschema/sch_io/kicad_legacy/sch_io_kicad_legacy.cpp

@ -2118,8 +2118,7 @@ void SCH_IO_KICAD_LEGACY::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
cacheLib( aLibraryPath, aProperties );
@ -2134,11 +2133,10 @@ void SCH_IO_KICAD_LEGACY::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
void SCH_IO_KICAD_LEGACY::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
cacheLib( aLibraryPath, aProperties );

6
eeschema/sch_io/kicad_sexpr/sch_io_kicad_sexpr.cpp

@ -1575,8 +1575,7 @@ void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( wxArrayString& aSymbolNameList,
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
cacheLib( aLibraryPath, aProperties );
@ -1594,8 +1593,7 @@ void SCH_IO_KICAD_SEXPR::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolLi
const wxString& aLibraryPath,
const std::map<std::string, UTF8>* aProperties )
{
bool powerSymbolsOnly = ( aProperties &&
aProperties->find( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) != aProperties->end() );
bool powerSymbolsOnly = ( aProperties && aProperties->contains( SYMBOL_LIB_TABLE::PropPowerSymsOnly ) );
cacheLib( aLibraryPath, aProperties );

30
include/http_lib/http_lib_connection.h

@ -36,10 +36,9 @@ public:
static const long DEFAULT_TIMEOUT = 10;
HTTP_LIB_CONNECTION( const HTTP_LIB_SOURCE& aSource, bool aTestConnectionNow );
virtual ~HTTP_LIB_CONNECTION() = default;
~HTTP_LIB_CONNECTION();
bool IsValidEndpoint() const;
bool IsValidEndpoint() const { return m_endpointValid; }
/**
* Retrieve a single part with full details from the HTTP library.
@ -71,7 +70,7 @@ public:
return "";
}
auto& getCachedParts() { return m_cache; }
auto& GetCachedParts() { return m_cache; }
private:
// This is clunky but at the moment the only way to free the pointer after use without
@ -89,7 +88,7 @@ private:
return aCurl;
}
bool ValidateHTTPLibraryEndpoints();
bool validateHttpLibraryEndpoints();
bool syncCategories();
@ -112,27 +111,20 @@ private:
*/
wxString httpErrorCodeDescription( uint16_t aHttpCode );
private:
HTTP_LIB_SOURCE m_source;
bool m_endpointValid = false;
std::string m_lastError;
std::vector<HTTP_LIB_CATEGORY> m_categories;
std::map<std::string, std::string> m_categoryDescriptions;
std::map<std::string, std::string> m_parts;
// part.id part
std::map<std::string, HTTP_LIB_PART> m_cachedParts;
// part.name part.id category.id
std::map<std::string, std::tuple<std::string, std::string>> m_cache;
bool m_endpointValid = false;
std::string m_lastError;
std::vector<HTTP_LIB_CATEGORY> m_categories;
std::map<std::string, std::string> m_categoryDescriptions;
std::map<std::string, std::string> m_parts;
const std::string http_endpoint_categories = "categories";
const std::string http_endpoint_parts = "parts";
const std::string http_endpoint_settings = "settings";
const std::string http_endpoint_auth = "authentication";
};
#endif //KICAD_HTTP_LIB_CONNECTION_H

31
include/http_lib/http_lib_settings.h

@ -18,8 +18,7 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef KICAD_HTTP_LIB_SETTINGS_H
#define KICAD_HTTP_LIB_SETTINGS_H
#pragma once
#include <settings/json_settings.h>
#include <ctime>
@ -49,14 +48,13 @@ 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;
bool exclude_from_bom = false;
bool exclude_from_board = false;
bool exclude_from_sim = false;
std::time_t lastCached = 0;
std::vector<std::pair<std::string, std::tuple<std::string, bool>>>
fields; ///< additional generic fields
std::vector<std::pair<std::string, std::tuple<std::string, bool>>> fields; ///< additional generic fields
};
@ -76,29 +74,26 @@ class HTTP_LIB_SETTINGS : public JSON_SETTINGS
{
public:
HTTP_LIB_SETTINGS( const std::string& aFilename );
virtual ~HTTP_LIB_SETTINGS() {}
HTTP_LIB_SOURCE m_Source;
~HTTP_LIB_SETTINGS() override = default;
HTTP_LIB_SOURCE_TYPE get_HTTP_LIB_SOURCE_TYPE()
{
if( sourceType.compare( "REST_API" ) == 0 )
{
if( m_sourceType == "REST_API" )
return HTTP_LIB_SOURCE_TYPE::REST_API;
}
return HTTP_LIB_SOURCE_TYPE::INVALID;
}
std::string getSupportedAPIVersion() { return api_version; }
std::string getSupportedAPIVersion() { return m_api_version; }
protected:
wxString getFileExt() const override;
public:
HTTP_LIB_SOURCE m_Source;
private:
std::string sourceType;
std::string api_version = "v1";
std::string m_sourceType;
std::string m_api_version = "v1";
};
#endif //KICAD_HTTP_LIB_SETTINGS_H
Loading…
Cancel
Save