43 const wxString& aLibraryPath,
44 const std::map<std::string, UTF8>* aProperties )
46 std::vector<LIB_SYMBOL*> symbols;
50 aSymbolNameList.Add( symbol->GetName() );
55 const wxString& aLibraryPath,
56 const std::map<std::string, UTF8>* aProperties )
58 wxCHECK_RET(
m_libTable,
_(
"httplib plugin missing library table handle!" ) );
68 bool powerSymbolsOnly =
74 bool refresh_cache =
true;
83 refresh_cache =
false;
94 wxString libIDString( part.name );
98 if( symbol && ( !powerSymbolsOnly || symbol->
IsPower() ) )
99 aSymbolList.emplace_back( symbol );
106 const std::map<std::string, UTF8>* aProperties )
115 std::string part_id =
"";
117 std::string partName( aAliasName.ToUTF8() );
122 std::vector<HTTP_LIB_CATEGORY> categories =
m_conn->getCategories();
124 if(
m_conn->getCachedParts().empty() )
129 std::tuple relations =
m_conn->getCachedParts()[partName];
130 std::string associatedCatID = std::get<1>( relations );
135 if( categoryIter.id == associatedCatID )
137 foundCategory = &categoryIter;
143 if( foundCategory ==
nullptr )
145 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbol: no category found for %s" ), partName );
152 if( part.id == std::get<0>( relations ) )
159 if(
m_conn->SelectOne( part_id, result ) )
161 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbol: SelectOne (%s) found in %s" ), part_id,
162 foundCategory->
name );
166 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbol: SelectOne (%s) failed for category %s" ),
167 part_id, foundCategory->
name );
172 wxCHECK( foundCategory,
nullptr );
184 std::set<wxString> categoryNames;
188 if( categoryNames.count( categoryIter.name ) )
191 aNames.emplace_back( categoryIter.name );
192 categoryNames.insert( categoryIter.name );
198 return m_conn->getCategoryDescription( std::string( aName.mb_str() ) );
211 std::back_inserter( aNames ) );
221 wxString msg = wxString::Format(
222 _(
"HTTP library settings file %s missing or invalid" ), aSettingsPath );
227 if(
m_settings->m_Source.api_version.empty() )
229 wxString msg = wxString::Format(
230 _(
"HTTP library settings file %s is missing the API version number!" ),
238 wxString msg = wxString::Format(
_(
"HTTP library settings file %s uses API version "
239 "%s, but KiCad requires version %s" ),
240 aSettingsPath,
m_settings->m_Source.api_version,
248 wxString msg = wxString::Format(
249 _(
"HTTP library settings file %s is missing the root URL!" ), aSettingsPath );
257 if(
m_settings->m_Source.type == HTTP_LIB_SOURCE_TYPE::INVALID )
259 wxString msg = wxString::Format(
260 _(
"HTTP library settings file %s has an invalid library type" ),
278 std::string
path( aSettingsPath.ToUTF8() );
292 wxLogTrace(
traceHTTPLib, wxT(
"ensureSettings: no settings available!" ) );
299 wxCHECK_RET(
m_settings,
"Call ensureSettings before ensureConnection!" );
305 wxString msg = 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() )
343 std::vector<HTTP_LIB_PART> found_parts;
345 if( !
m_conn->SelectAll( category, found_parts ) )
347 if( !
m_conn->GetLastError().empty() )
349 wxString msg = wxString::Format(
_(
"Error retriving data from HTTP library %s: %s" ),
377 if( !symbolIdStr.empty() )
379 symbolId.
Parse( symbolIdStr );
388 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: found original symbol '%s'" ),
400 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol id '%s' is invalid, "
401 "will create empty symbol" ),
406 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: source symbol '%s' not found, "
407 "will create empty symbol" ),
429 for(
auto& _field : aPart.
fields )
431 wxString fieldName = wxString( _field.first );
432 std::tuple fieldProperties = _field.second;
437 field->
SetText( std::get<0>( fieldProperties ) );
438 field->
SetVisible( std::get<1>( fieldProperties ) );
443 field->
SetText( std::get<0>( fieldProperties ) );
444 field->
SetVisible( std::get<1>( fieldProperties ) );
449 field->
SetText( std::get<0>( fieldProperties ) );
450 field->
SetVisible( std::get<1>( fieldProperties ) );
455 field->
SetText( std::get<0>( fieldProperties ) );
456 field->
SetVisible( std::get<1>( fieldProperties ) );
461 field->
SetText( std::get<0>( fieldProperties ) );
462 field->
SetVisible( std::get<1>( fieldProperties ) );
466 symbol->
SetKeyWords( std::get<0>( fieldProperties ) );
475 field = symbol->
GetField( fieldName );
477 if( field !=
nullptr )
480 field->
SetText( std::get<0>( fieldProperties ) );
481 field->
SetVisible( std::get<1>( fieldProperties ) );
486 field =
new SCH_FIELD( symbol, FIELD_T::USER );
489 field->
SetText( std::get<0>( fieldProperties ) );
490 field->
SetVisible( std::get<1>( fieldProperties ) );
502 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 SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetValueField()
Return reference to the value field.
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
virtual ~SCH_IO_HTTP_LIB()
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.
Base class that schematic file and library loading and saving plugins should derive from.
static const char * PropPowerSymsOnly
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
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)
std::string id
id of category
std::string name
name of category
std::vector< std::pair< std::string, std::tuple< std::string, bool > > > fields
additional generic fields