23#include <wx/tokenzr.h>
35 SCH_IO( wxS(
"HTTP library" ) ),
42 const std::map<std::string, UTF8>* aProperties )
44 wxCHECK_RET(
m_adapter,
"HTTP plugin missing library manager adapter handle!" );
58 aSymbolNameList.Add( part.name );
64 const std::map<std::string, UTF8>* aProperties )
66 wxCHECK_RET(
m_adapter,
"HTTP plugin missing library manager adapter handle!" );
83 if( !part.detailsLoaded )
87 if(
m_conn->SelectOne( part.id, fullPart ) )
91 fullPart.
id = part.id;
92 fullPart.
name = part.name;
93 part = std::move( fullPart );
97 wxString libIDString( part.name );
101 if( symbol && ( !powerSymbolsOnly || symbol->
IsPower() ) )
102 aSymbolList.emplace_back( symbol );
109 const std::map<std::string, UTF8>* aProperties )
111 wxCHECK_MSG(
m_adapter,
nullptr,
"HTTP plugin missing library manager adapter handle!" );
118 std::string part_id =
"";
120 std::string partName( aAliasName.ToUTF8() );
125 std::vector<HTTP_LIB_CATEGORY> categories =
m_conn->getCategories();
127 if(
m_conn->GetCachedParts().empty() )
130 std::tuple relations =
m_conn->GetCachedParts()[partName];
131 std::string associatedCatID = std::get<1>( relations );
136 if( categoryIter.id == associatedCatID )
138 foundCategory = &categoryIter;
144 if( foundCategory ==
nullptr )
146 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbol: no category found for %s" ), partName );
153 if( part.id == std::get<0>( relations ) )
162 wxLogTrace(
traceHTTPLib, wxT(
"LoadSymbol: SelectOne (%s) found in %s" ), part_id, foundCategory->
name );
166 wxLogTrace(
traceHTTPLib, wxT(
"LoadSymbol: SelectOne (%s) failed for category %s" ), part_id,
167 foundCategory->
name );
172 wxCHECK( foundCategory,
nullptr );
190 std::set<wxString> categoryNames;
194 if( categoryNames.count( categoryIter.name ) )
197 aNames.emplace_back( categoryIter.name );
198 categoryNames.insert( categoryIter.name );
209 return wxEmptyString;
211 return m_conn->getCategoryDescription( std::string( aName.mb_str() ) );
235 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s missing or invalid." ),
239 if(
m_settings->m_Source.api_version.empty() )
241 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s is missing the API version "
248 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s uses API version %s, but "
249 "KiCad requires version %s." ),
250 aSettingsPath,
m_settings->m_Source.api_version,
256 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s is missing the root URL." ),
265 THROW_IO_ERROR( wxString::Format(
_(
"HTTP library settings file %s has invalid library type." ),
279 std::string
path( aSettingsPath.ToUTF8() );
293 wxLogTrace(
traceHTTPLib, wxT(
"ensureSettings: no settings available!" ) );
300 wxCHECK_RET(
m_settings,
"Call ensureSettings before ensureConnection!" );
306 THROW_IO_ERROR( wxString::Format(
_(
"Could not connect to %s. Errors: %s" ),
315 wxCHECK_RET(
m_settings,
"Call ensureSettings before connect()!" );
319 m_conn = std::make_unique<HTTP_LIB_CONNECTION>(
m_settings->m_Source,
true );
321 if( !
m_conn->IsValidEndpoint() )
346 && std::difftime( std::time(
nullptr ), it->second.lastCached )
358 std::vector<HTTP_LIB_PART> found_parts;
360 if( !
m_conn->SelectAll( category, found_parts ) )
362 if( !
m_conn->GetLastError().empty() )
364 THROW_IO_ERROR( wxString::Format(
_(
"Error retrieving data from HTTP library %s: %s" ),
366 m_conn->GetLastError() ) );
382 const wxString& aSymbolName,
393 wxFileName libFileName( aLibraryPath );
394 wxString libNickname = libFileName.GetName();
397 if( !symbolIdStr.empty() )
399 symbolId.
Parse( symbolIdStr );
402 originalSymbol =
m_adapter->LoadSymbol( symbolId );
406 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: found original symbol '%s'" ), symbolIdStr );
410 symbol->
SetName( aSymbolName );
419 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol id '%s' is invalid, "
420 "will create empty symbol" ), symbolIdStr );
424 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol '%s' not found, "
425 "will create empty symbol" ), symbolIdStr );
445 wxArrayString fp_filters;
447 for(
auto& [fieldName, fieldProperties] : aPart.
fields )
449 wxString lowerFieldName = wxString( fieldName ).Lower();
454 wxStringTokenizer tokenizer( std::get<0>( fieldProperties ),
";\t\r\n", wxTOKEN_STRTOK );
456 while( tokenizer.HasMoreTokens() )
457 fp_filters.Add( tokenizer.GetNextToken() );
459 if( fp_filters.size() > 0 )
460 field->
SetText( fp_filters[0] );
462 field->
SetVisible( std::get<1>( fieldProperties ) );
467 field->
SetText( std::get<0>( fieldProperties ) );
468 field->
SetVisible( std::get<1>( fieldProperties ) );
473 field->
SetText( std::get<0>( fieldProperties ) );
474 field->
SetVisible( std::get<1>( fieldProperties ) );
479 field->
SetText( std::get<0>( fieldProperties ) );
480 field->
SetVisible( std::get<1>( fieldProperties ) );
485 field->
SetText( std::get<0>( fieldProperties ) );
486 field->
SetVisible( std::get<1>( fieldProperties ) );
490 symbol->
SetKeyWords( std::get<0>( fieldProperties ) );
501 if( field !=
nullptr )
504 field->
SetText( std::get<0>( fieldProperties ) );
505 field->
SetVisible( std::get<1>( fieldProperties ) );
513 field->
SetText( std::get<0>( fieldProperties ) );
514 field->
SetVisible( std::get<1>( fieldProperties ) );
526 fp_filters.push_back(
filter );
542 if( !aPart.
pin_map.empty() && !assignedFootprint.IsEmpty() )
544 const wxString mapName = wxS(
"HTTP Library" );
549 fpId.
Parse( assignedFootprint );
558 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.
int SetLibNickname(const UTF8 &aLibNickname)
Override the logical library name portion of the LIB_ID to aLibNickname.
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 SetAssociatedFootprints(std::vector< ASSOCIATED_FOOTPRINT > aList)
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 SetPinMaps(const PIN_MAP_SET &aPinMaps)
void SetFPFilters(const wxArrayString &aFilters)
void SetLibId(const LIB_ID &aLibId)
void AddField(SCH_FIELD *aField)
Add a field.
virtual void SetName(const wxString &aName)
SCH_FIELD & GetReferenceField()
Return reference to the reference designator field.
void AddOrReplace(PIN_MAP aMap)
Insert aMap, replacing any existing entry with the same name.
virtual const wxString & GetText() const override
Return the string associated with the text object.
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.
SYMBOL_LIBRARY_ADAPTER * m_adapter
void ensureSettings(const wxString &aSettingsPath)
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
void syncCacheIfStale(const HTTP_LIB_CATEGORY &category)
Refresh the cached parts for a category if it has never been cached or has expired.
LIB_SYMBOL * loadSymbolFromPart(const wxString &aLibraryPath, const wxString &aSymbolName, const HTTP_LIB_CATEGORY &aCategory, const HTTP_LIB_PART &aPart)
wxString description_field
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 aExclude, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear exclude from board netlist flag.
virtual void SetExcludedFromSim(bool aExcludeFromSim, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) override
Set or clear the exclude from simulation flag.
virtual void SetExcludedFromBOM(bool aExcludeFromBOM, const SCH_SHEET_PATH *aInstance=nullptr, const wxString &aVariantName=wxEmptyString) 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
PIN_MAP MakeLegacyPinMap(const wxString &aName, const std::unordered_map< wxString, std::vector< wxString > > &aAssignments)
Build a single named PIN_MAP from a legacy symbol-pin to footprint-pad(s) assignment table (the flat ...
std::string id
id of category
std::string name
name of category
std::vector< ASSOCIATED_FOOTPRINT > associated_footprints
std::unordered_map< wxString, std::vector< wxString > > pin_map
Legacy flat MR !2540 pin assignment table (read for one release; issue #2282).
std::vector< std::string > fp_filters
std::vector< std::pair< std::string, field_type > > fields
PIN_MAP_SET named_pin_maps
Spec-form named pin maps and their footprint associations (issue #2282).
@ USER
The field ID hasn't been set yet; field is invalid.
wxString result
Test unit parsing edge cases and error handling.