KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_http_lib.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2023 Andre F. K. Iwers <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#pragma once
22
25
26#include <sch_io/sch_io.h>
27#include <sch_io/sch_io_mgr.h>
29
37class SCH_IO_HTTP_LIB : public SCH_IO
38{
39public:
41 ~SCH_IO_HTTP_LIB() override = default;
42
44 {
45 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ), { FILEEXT::HTTPLibraryFileExtension } );
46 }
47
48 int GetModifyHash() const override { return 0; }
49
50 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
51 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
52
53 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
54 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
55
56 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
57 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
58
59 bool SupportsSubLibraries() const override { return true; }
60
61 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
62
63 wxString GetSubLibraryDescription( const wxString& aName ) override;
64
65 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
66
67 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
68
69 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
70
71 void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override { m_libTable = aTable; }
72
73 HTTP_LIB_SETTINGS* Settings() const { return m_settings.get(); }
74
75 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
76 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
77
78 const wxString& GetError() const override { return m_lastError; }
79
80private:
81 void ensureSettings( const wxString& aSettingsPath );
82
83 void ensureConnection();
84
85 void connect();
86
87 void syncCache();
88
89 void syncCache( const HTTP_LIB_CATEGORY& category );
90
91 LIB_SYMBOL* loadSymbolFromPart( const wxString& aSymbolName, const HTTP_LIB_CATEGORY& aCategory,
92 const HTTP_LIB_PART& aPart );
93
94private:
96
98 std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
99 std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
100 std::set<wxString> m_customFields;
101 std::set<wxString> m_defaultShownFields;
102 wxString m_lastError;
103
104 wxString symbol_field = "symbol";
105 wxString footprint_field = "footprint";
106 wxString description_field = "description";
107 wxString keywords_field = "keywords";
108 wxString value_field = "value";
109 wxString datasheet_field = "datasheet";
110 wxString reference_field = "reference";
111
112 // category.id category
113 std::map<std::string, HTTP_LIB_CATEGORY> m_cachedCategories;
114};
Define a library symbol object.
Definition lib_symbol.h:85
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.
HTTP_LIB_SETTINGS * Settings() const
std::unique_ptr< HTTP_LIB_SETTINGS > m_settings
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
wxString GetSubLibraryDescription(const wxString &aName) override
Gets a description of a sublibrary.
bool SupportsSubLibraries() const override
void ensureSettings(const wxString &aSettingsPath)
int GetModifyHash() const override
Return the modification hash from the library cache.
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.
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
~SCH_IO_HTTP_LIB() override=default
std::set< wxString > m_defaultShownFields
void SetLibTable(SYMBOL_LIB_TABLE *aTable) override
Some library plugins need to have access to their parent library table.
wxString description_field
LIB_SYMBOL * loadSymbolFromPart(const wxString &aSymbolName, const HTTP_LIB_CATEGORY &aCategory, const HTTP_LIB_PART &aPart)
const wxString & GetError() const override
Return an error string to the caller.
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)
Definition sch_io.h:373
static const std::string HTTPLibraryFileExtension
#define _HKI(x)
Definition page_info.cpp:44
Container that describes file type info.
Definition io_base.h:43
Definition of file extensions used in Kicad.