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'" ),
401 wxT(
"loadSymbolFromPart: source symbol id '%s' is invalid, "
402 "will create empty symbol" ),
408 wxT(
"loadSymbolFromPart: source symbol '%s' not found, "
409 "will create empty symbol" ),
431 for(
auto& _field : aPart.
fields )
433 wxString fieldName = wxString( _field.first );
434 std::tuple fieldProperties = _field.second;
439 field->
SetText( std::get<0>( fieldProperties ) );
440 field->
SetVisible( std::get<1>( fieldProperties ) );
445 field->
SetText( std::get<0>( fieldProperties ) );
446 field->
SetVisible( std::get<1>( fieldProperties ) );
451 field->
SetText( std::get<0>( fieldProperties ) );
452 field->
SetVisible( std::get<1>( fieldProperties ) );
457 field->
SetText( std::get<0>( fieldProperties ) );
458 field->
SetVisible( std::get<1>( fieldProperties ) );
463 field->
SetText( std::get<0>( fieldProperties ) );
464 field->
SetVisible( std::get<1>( fieldProperties ) );
468 symbol->
SetKeyWords( std::get<0>( fieldProperties ) );
479 if( field !=
nullptr )
482 field->
SetText( std::get<0>( fieldProperties ) );
483 field->
SetVisible( std::get<1>( fieldProperties ) );
491 field->
SetText( std::get<0>( fieldProperties ) );
492 field->
SetVisible( std::get<1>( fieldProperties ) );
504 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.
const LIB_ID & GetLibId() const override
bool IsPower() const override
void SetSourceLibId(const LIB_ID &aLibId)
int GetNextAvailableFieldId() const
SCH_FIELD & GetValueField() const
Return reference to the value 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 & GetDatasheetField() const
Return reference to the datasheet field.
SCH_FIELD & GetFootprintField() const
Return reference to the footprint field.
void SetKeyWords(const wxString &aKeyWords)
SCH_FIELD & GetReferenceField() const
Return reference to the reference designator field.
SCH_FIELD & GetDescriptionField() const
Return reference to the description field.
SCH_FIELD * FindField(const wxString &aFieldName, bool aCaseInsensitive=false)
Find a field within this symbol matching aFieldName and returns it or NULL if not found.
void SetLibId(const LIB_ID &aLibId)
void AddField(SCH_FIELD *aField)
Add a field.
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
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 SetExcludedFromSim(bool aExcludeFromSim) override
Set or clear the exclude from simulation flag.
void SetExcludedFromBOM(bool aExcludeFromBOM)
Set or clear the exclude from schematic bill of materials flag.
void SetExcludedFromBoard(bool aExcludeFromBoard)
Set or clear exclude from board netlist 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