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 std::map<std::string, UTF8>* aProperties = nullptr ) override;
54
55 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
56 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
57
58 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
59 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
60
61 bool SupportsSubLibraries() const override { return true; }
62
63 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
64
65 wxString GetSubLibraryDescription( const wxString& aName ) override;
66
67 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
68
69 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
70
71 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
72
73 void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override { m_libTable = aTable; }
74
75 HTTP_LIB_SETTINGS* Settings() const { return m_settings.get(); }
76
77 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
78 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
79
80 const wxString& GetError() const override { return m_lastError; }
81
82private:
83 void ensureSettings( const wxString& aSettingsPath );
84
85 void ensureConnection();
86
87 void connect();
88
89 void syncCache();
90
91 void syncCache( const HTTP_LIB_CATEGORY& category );
92
93 LIB_SYMBOL* loadSymbolFromPart( const wxString& aSymbolName, const HTTP_LIB_CATEGORY& aCategory,
94 const HTTP_LIB_PART& aPart );
95
97
99 std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
100
101 std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
102
103 std::set<wxString> m_customFields;
104
105 std::set<wxString> m_defaultShownFields;
106
107 wxString m_lastError;
108
109 wxString symbol_field = "symbol";
110 wxString footprint_field = "footprint";
111 wxString description_field = "description";
112 wxString keywords_field = "keywords";
113 wxString value_field = "value";
114 wxString datasheet_field = "datasheet";
115 wxString reference_field = "reference";
116
117 // category.id category
118 std::map<std::string, HTTP_LIB_CATEGORY> m_cachedCategories;
119};
120
121#endif // SCH_IO_HTTP_LIB_H_
Define a library symbol object.
Definition: lib_symbol.h:78
A KiCad HTTP library provides both symbol and footprint metadata, so there are "shim" plugins on both...
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.
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 GetSubLibraryDescription(const wxString &aName) override
Gets a description of a sublibrary.
wxString datasheet_field
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.
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.
wxString keywords_field
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
#define _HKI(x)
static const std::string HTTPLibraryFileExtension
Container that describes file type info.
Definition: io_base.h:43
Definition of file extensions used in Kicad.