43 const wxString& aLibraryPath,
46 std::vector<LIB_SYMBOL*> symbols;
50 aSymbolNameList.Add( symbol->GetName() );
55 const wxString& aLibraryPath,
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 );
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 );
207 std::back_inserter( aNames ) );
217 wxString msg = wxString::Format(
218 _(
"HTTP library settings file %s missing or invalid" ), aSettingsPath );
223 if(
m_settings->m_Source.api_version.empty() )
225 wxString msg = wxString::Format(
226 _(
"HTTP library settings file %s is missing the API version number!" ),
234 wxString msg = wxString::Format(
_(
"HTTP library settings file %s uses API version "
235 "%s, but KiCad requires version %s" ),
236 aSettingsPath,
m_settings->m_Source.api_version,
244 wxString msg = wxString::Format(
245 _(
"HTTP library settings file %s is missing the root URL!" ), aSettingsPath );
253 if(
m_settings->m_Source.type == HTTP_LIB_SOURCE_TYPE::INVALID )
255 wxString msg = wxString::Format(
256 _(
"HTTP library settings file %s has an invalid library type" ),
274 std::string
path( aSettingsPath.ToUTF8() );
288 wxLogTrace(
traceHTTPLib, wxT(
"ensureSettings: no settings available!" ) );
295 wxCHECK_RET(
m_settings,
"Call ensureSettings before ensureConnection!" );
301 wxString msg = wxString::Format(
_(
"Could not connect to %s. Errors: %s" ),
311 wxCHECK_RET(
m_settings,
"Call ensureSettings before connect()!" );
315 m_conn = std::make_unique<HTTP_LIB_CONNECTION>(
m_settings->m_Source,
true );
317 if( !
m_conn->IsValidEndpoint() )
339 std::vector<HTTP_LIB_PART> found_parts;
341 if( !
m_conn->SelectAll( category, found_parts ) )
343 if( !
m_conn->GetLastError().empty() )
345 wxString msg = wxString::Format(
_(
"Error retriving data from HTTP library %s: %s" ),
373 if( !symbolIdStr.empty() )
375 symbolId.
Parse( symbolIdStr );
384 wxLogTrace(
traceHTTPLib, wxT(
"loadSymbolFromPart: found original symbol '%s'" ),
397 wxT(
"loadSymbolFromPart: source symbol id '%s' is invalid, "
398 "will create empty symbol" ),
404 wxT(
"loadSymbolFromPart: source symbol '%s' not found, "
405 "will create empty symbol" ),
427 for(
auto& _field : aPart.
fields )
429 wxString fieldName = wxString( _field.first );
430 std::tuple fieldProperties = _field.second;
435 field->
SetText( std::get<0>( fieldProperties ) );
436 field->
SetVisible( std::get<1>( fieldProperties ) );
441 field->
SetText( std::get<0>( fieldProperties ) );
442 field->
SetVisible( std::get<1>( fieldProperties ) );
447 field->
SetText( std::get<0>( fieldProperties ) );
448 field->
SetVisible( std::get<1>( fieldProperties ) );
453 field->
SetText( std::get<0>( fieldProperties ) );
454 field->
SetVisible( std::get<1>( fieldProperties ) );
459 field->
SetText( std::get<0>( fieldProperties ) );
460 field->
SetVisible( std::get<1>( fieldProperties ) );
464 symbol->
SetKeyWords( std::get<0>( fieldProperties ) );
475 if( field !=
nullptr )
478 field->
SetText( std::get<0>( fieldProperties ) );
479 field->
SetVisible( std::get<1>( fieldProperties ) );
487 field->
SetText( std::get<0>( fieldProperties ) );
488 field->
SetVisible( std::get<1>( fieldProperties ) );
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
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
virtual ~SCH_IO_HTTP_LIB()
std::unique_ptr< HTTP_LIB_CONNECTION > m_conn
Generally will be null if no valid connection is established.
std::unique_ptr< HTTP_LIB_SETTINGS > m_settings
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
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.
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
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 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.
A name/value tuple with unique names and optional values.
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