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 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21#ifndef SCH_IO_HTTP_LIB_H
22#define SCH_IO_HTTP_LIB_H
23
26
27#include <sch_io/sch_io.h>
28#include <sch_io/sch_io_mgr.h>
30
38class SCH_IO_HTTP_LIB : public SCH_IO
39{
40public:
42 virtual ~SCH_IO_HTTP_LIB();
43
45 {
46 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ),
48 }
49
50 int GetModifyHash() const override { return 0; }
51
52 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
53 const STRING_UTF8_MAP* aProperties = nullptr ) override;
54
55 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
56 const STRING_UTF8_MAP* aProperties = nullptr ) override;
57
58 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
59 const STRING_UTF8_MAP* aProperties = nullptr ) override;
60
61 bool SupportsSubLibraries() const override { return true; }
62
63 void GetSubLibraryNames( std::vector<wxString>& aNames ) 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 STRING_UTF8_MAP* 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
95
97 std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
98
99 std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
100
101 std::set<wxString> m_customFields;
102
103 std::set<wxString> m_defaultShownFields;
104
105 wxString m_lastError;
106
107 wxString symbol_field = "symbol";
108 wxString footprint_field = "footprint";
109 wxString description_field = "description";
110 wxString keywords_field = "keywords";
111 wxString value_field = "value";
112 wxString datasheet_field = "datasheet";
113 wxString reference_field = "reference";
114
115 // category.id category
116 std::map<std::string, HTTP_LIB_CATEGORY> m_cachedCategories;
117};
118
119#endif // SCH_IO_HTTP_LIB_H_
Define a library symbol object.
Definition: lib_symbol.h:77
A KiCad HTTP library provides both symbol and footprint metadata, so there are "shim" plugins on both...
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.
wxString reference_field
HTTP_LIB_SETTINGS * Settings() const
wxString footprint_field
std::unique_ptr< HTTP_LIB_SETTINGS > m_settings
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
wxString datasheet_field
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.
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.
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
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 GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
wxString keywords_field
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
A name/value tuple with unique names and optional values.
#define _HKI(x)
static const std::string HTTPLibraryFileExtension
Container that describes file type info.
Definition: io_base.h:39
Definition of file extensions used in Kicad.