|
|
|
@ -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 ) |
|
|
|
{ |
|
|
|
|