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
31
39class SCH_IO_HTTP_LIB : public SCH_IO
40{
41public:
43 ~SCH_IO_HTTP_LIB() override = default;
44
46 {
47 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad HTTP library files" ), { FILEEXT::HTTPLibraryFileExtension } );
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
74 {
75 m_adapter = aAdapter;
76 }
77
78 HTTP_LIB_SETTINGS* Settings() const { return m_settings.get(); }
79
80 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
81 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
82
83 const wxString& GetError() const override { return m_lastError; }
84
85private:
86 void ensureSettings( const wxString& aSettingsPath );
87
88 void ensureConnection();
89
90 void connect();
91
92 void syncCache();
93
94 void syncCache( const HTTP_LIB_CATEGORY& category );
95
96 LIB_SYMBOL* loadSymbolFromPart( const wxString& aSymbolName, const HTTP_LIB_CATEGORY& aCategory,
97 const HTTP_LIB_PART& aPart );
98
99private:
101
103 std::unique_ptr<HTTP_LIB_CONNECTION> m_conn;
104 std::unique_ptr<HTTP_LIB_SETTINGS> m_settings;
105 std::set<wxString> m_customFields;
106 std::set<wxString> m_defaultShownFields;
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};
The interface used by the classes that actually can load IO plugins for the different parts of KiCad ...
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.
SYMBOL_LIBRARY_ADAPTER * m_adapter
bool SupportsSubLibraries() const override
void ensureSettings(const wxString &aSettingsPath)
int GetModifyHash() const override
Return the modification hash from the library cache.
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 SetLibraryManagerAdapter(SYMBOL_LIBRARY_ADAPTER *aAdapter) override
Some library plugins need to interface with other loaded libraries.
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:375
An interface to the global shared library manager that is schematic-specific and linked to one projec...
static const std::string HTTPLibraryFileExtension
#define _HKI(x)
Definition page_info.cpp:44
Container that describes file type info.
Definition io_base.h:45
Definition of file extensions used in Kicad.