33 SCH_IO( wxS(
"HTTP library" ) ),
40 const std::map<std::string, UTF8>* aProperties )
42 std::vector<LIB_SYMBOL*> symbols;
46 aSymbolNameList.Add( symbol->GetName() );
51 const std::map<std::string, UTF8>* aProperties )
53 wxCHECK_RET(
m_libTable,
_(
"httplib plugin missing library table handle!" ) );
64 bool refresh_cache =
true;
73 refresh_cache =
false;
84 wxString libIDString( part.name );
88 if( symbol && ( !powerSymbolsOnly || symbol->
IsPower() ) )
89 aSymbolList.emplace_back( symbol );
96 const std::map<std::string, UTF8>* aProperties )
105 std::string part_id =
"";
107 std::string partName( aAliasName.ToUTF8() );
112 std::vector<HTTP_LIB_CATEGORY> categories =
m_conn->getCategories();
114 if(
m_conn->GetCachedParts().empty() )
117 std::tuple relations =
m_conn->GetCachedParts()[partName];
118 std::string associatedCatID = std::get<1>( relations );
123 if( categoryIter.id == associatedCatID )
125 foundCategory = &categoryIter;
131 if( foundCategory ==
nullptr )
133 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbol: no category found for %s" ), partName );
140 if( part.id == std::get<0>( relations ) )
149 wxLogTrace(
traceHTTPLib, wxT(
"LoadSymbol: SelectOne (%s) found in %s" ), part_id, foundCategory->
name );
153 wxLogTrace(
traceHTTPLib, wxT(
"LoadSymbol: SelectOne (%s) failed for category %s" ), part_id,
154 foundCategory->
name );
159 wxCHECK( foundCategory,
nullptr );
171 std::set<wxString> categoryNames;
175 if( categoryNames.count( categoryIter.name ) )
178 aNames.emplace_back( categoryIter.name );
179 categoryNames.insert( categoryIter.name );
186 return m_conn->getCategoryDescription( std::string( aName.mb_str() ) );
210 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s missing or invalid." ),
214 if(
m_settings->m_Source.api_version.empty() )
216 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s is missing the API version "
223 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s uses API version %s, but "
224 "KiCad requires version %s." ),
225 aSettingsPath,
m_settings->m_Source.api_version,
231 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s is missing the root URL." ),
240 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s has invalid library type." ),
254 std::string
path( aSettingsPath.ToUTF8() );
268 wxLogTrace(
traceHTTPLib, wxT(
"ensureSettings: no settings available!" ) );
275 wxCHECK_RET(
m_settings,
"Call ensureSettings before ensureConnection!" );
281 THROW_IO_ERROR( wxString::Format(
_(
"Could not connect to %s. Errors: %s" ),
290 wxCHECK_RET(
m_settings,
"Call ensureSettings before connect()!" );
294 m_conn = std::make_unique<HTTP_LIB_CONNECTION>(
m_settings->m_Source,
true );
296 if( !
m_conn->IsValidEndpoint() )
318 std::vector<HTTP_LIB_PART> found_parts;
320 if( !
m_conn->SelectAll( category, found_parts ) )
322 if( !
m_conn->GetLastError().empty() )
324 THROW_IO_ERROR( wxString::Format(
_(
"Error retrieving data from HTTP library %s: %s" ),
326 m_conn->GetLastError() ) );
352 if( !symbolIdStr.empty() )
354 symbolId.
Parse( symbolIdStr );
357 originalSymbol =
m_libTable->LoadSymbol( symbolId );
361 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: found original symbol '%s'" ), symbolIdStr );
372 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol id '%s' is invalid, "
373 "will create empty symbol" ), symbolIdStr );
377 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol '%s' not found, "
378 "will create empty symbol" ), symbolIdStr );
397 wxArrayString fp_filters;
399 for(
auto& [fieldName, fieldProperties] : aPart.
fields )
401 wxString lowerFieldName = wxString( fieldName ).Lower();
406 wxStringTokenizer tokenizer( std::get<0>( fieldProperties ),
";\t\r\n", wxTOKEN_STRTOK );
408 while( tokenizer.HasMoreTokens() )
409 fp_filters.Add( tokenizer.GetNextToken() );
411 if( fp_filters.size() > 0 )
412 field->
SetText( fp_filters[0] );
414 field->
SetVisible( std::get<1>( fieldProperties ) );
419 field->
SetText( std::get<0>( fieldProperties ) );
420 field->
SetVisible( std::get<1>( fieldProperties ) );
425 field->
SetText( std::get<0>( fieldProperties ) );
426 field->
SetVisible( std::get<1>( fieldProperties ) );
431 field->
SetText( std::get<0>( fieldProperties ) );
432 field->
SetVisible( std::get<1>( fieldProperties ) );
437 field->
SetText( std::get<0>( fieldProperties ) );
438 field->
SetVisible( std::get<1>( fieldProperties ) );
442 symbol->
SetKeyWords( std::get<0>( fieldProperties ) );
453 if( field !=
nullptr )
456 field->
SetText( std::get<0>( fieldProperties ) );
457 field->
SetVisible( std::get<1>( fieldProperties ) );
465 field->
SetText( std::get<0>( fieldProperties ) );
466 field->
SetVisible( std::get<1>( fieldProperties ) );
478 fp_filters.push_back(
filter );
486 const std::map<std::string, UTF8>* aProperties )
virtual void SetVisible(bool aVisible)
A logical library item identifier and consists of various portions much like a URI.
int Parse(const UTF8 &aId, bool aFix=false)
Parse LIB_ID with the information from aId.
bool IsValid() const
Check if this LID_ID is valid.
void SetSubLibraryName(const UTF8 &aName)
Define a library symbol object.
SCH_FIELD & GetDescriptionField()
Return reference to the description field.
const LIB_ID & GetLibId() const override
bool IsPower() const override
void SetSourceLibId(const LIB_ID &aLibId)
SCH_FIELD & GetDatasheetField()
Return reference to the datasheet field.
virtual LIB_SYMBOL * Duplicate() const
Create a copy of a LIB_SYMBOL and assigns unique KIIDs to the copy and its children.
SCH_FIELD * GetField(const wxString &aFieldName)
Find a field within this symbol matching aFieldName; return nullptr if not found.
SCH_FIELD & GetFootprintField()
Return reference to the footprint field.
void SetDescription(const wxString &aDescription)
Gets the Description field text value */.
void SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetValueField()
Return reference to the value field.
void SetFPFilters(const wxArrayString &aFilters)
void SetLibId(const LIB_ID &aLibId)
void AddField(SCH_FIELD *aField)
Add a field.
SCH_FIELD & GetReferenceField()
Return reference to the reference designator field.
void SetName(const wxString &aName)
void SetText(const wxString &aText) override
std::unique_ptr< HTTP_LIB_CONNECTION > m_conn
Generally will be null if no valid connection is established.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
std::unique_ptr< HTTP_LIB_SETTINGS > m_settings
wxString GetSubLibraryDescription(const wxString &aName) override
Gets a description of a sublibrary.
void ensureSettings(const wxString &aSettingsPath)
SYMBOL_LIB_TABLE * m_libTable
std::set< wxString > m_customFields
void GetDefaultSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
std::set< wxString > m_defaultShownFields
wxString description_field
LIB_SYMBOL * loadSymbolFromPart(const wxString &aSymbolName, const HTTP_LIB_CATEGORY &aCategory, const HTTP_LIB_PART &aPart)
std::map< std::string, HTTP_LIB_CATEGORY > m_cachedCategories
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
SCH_IO(const wxString &aName)
static const char * PropPowerSymsOnly
void SetExcludedFromBoard(bool aExcludeFromBoard) override
Set or clear exclude from board netlist flag.
void SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
void SetExcludedFromBOM(bool aExcludeFromBOM) override
Set or clear the exclude from schematic bill of materials flag.
const char *const traceHTTPLib
#define THROW_IO_ERROR(msg)
macro which captures the "call site" values of FILE_, __FUNCTION & LINE
std::string id
id of category
std::string name
name of category
std::vector< std::string > fp_filters
std::vector< std::pair< std::string, std::tuple< std::string, bool > > > fields
@ USER
The field ID hasn't been set yet; field is invalid.
wxString result
Test unit parsing edge cases and error handling.