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
22#ifndef SCH_IO_HTTP_LIB_H
23#define SCH_IO_HTTP_LIB_H
24
27
28#include <sch_io/sch_io.h>
29#include <sch_io/sch_io_mgr.h>
31
39class SCH_IO_HTTP_LIB : public SCH_IO
40{
41public:
43 virtual ~SCH_IO_HTTP_LIB();
44
46 {
47 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ),
49 }
50
51 int GetModifyHash() const override { return 0; }
52
53 void EnumerateSymbolLib( wxArrayString& aSymbolNameList, const wxString& aLibraryPath,
54 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
55
56 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList, const wxString& aLibraryPath,
57 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
58
59 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
60 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
61
62 bool SupportsSubLibraries() const override { return true; }
63
64 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
65
66 wxString GetSubLibraryDescription( const wxString& aName ) override;
67
68 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
69
70 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
71
72 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
73
74 void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override { m_libTable = aTable; }
75
76 HTTP_LIB_SETTINGS* Settings() const { return m_settings.get(); }
77
78 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
79 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
80
81 const wxString& GetError() const override { return m_lastError; }
82
83private:
84 void ensureSettings( const wxString& aSettingsPath );
85
86 void ensureConnection();
87
88 void connect();
89
90 void syncCache();
91
92 void syncCache( const HTTP_LIB_CATEGORY& category );
93
94 LIB_SYMBOL* loadSymbolFromPart( const wxString& aSymbolName, const HTTP_LIB_CATEGORY& aCategory,
95 const HTTP_LIB_PART& aPart );
96
98
100 std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
101
102 std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
103
104 std::set<wxString> m_customFields;
105
106 std::set<wxString> m_defaultShownFields;
107
108 wxString m_lastError;
109
110 wxString symbol_field = "symbol";
111 wxString footprint_field = "footprint";
112 wxString description_field = "description";
113 wxString keywords_field = "keywords";
114 wxString value_field = "value";
115 wxString datasheet_field = "datasheet";
116 wxString reference_field = "reference";
117
118 // category.id category
119 std::map<std::string, HTTP_LIB_CATEGORY> m_cachedCategories;
120};
121
122#endif // SCH_IO_HTTP_LIB_H_
Define a library symbol object.
Definition: lib_symbol.h:84
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.