KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_database.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) 2022 Jon Evans <[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
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef SCH_IO_DATABASE_H_
22#define SCH_IO_DATABASE_H_
23
25#include <sch_io/sch_io.h>
26#include <sch_io/sch_io_mgr.h>
28#include <optional>
29#include <unordered_set>
30
31
35
36
44class SCH_IO_DATABASE : public SCH_IO
45{
47
48public:
49
51 virtual ~SCH_IO_DATABASE();
52
54 {
55 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad database library files" ),
57 }
58
59 int GetModifyHash() const override { return 0; }
60
61 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
62 const wxString& aLibraryPath,
63 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
64
65 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
66 const wxString& aLibraryPath,
67 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
68
69 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
70 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
71
72 bool SupportsSubLibraries() const override { return true; }
73
74 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
75
76 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
77
78 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
79
80 // Database libraries can never be written using the symbol editing API
81 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
82
84 {
85 m_adapter = aAdapter;
86 }
87
88 bool SupportsConfigurationDialog() const override { return true; }
89
90 DIALOG_SHIM* CreateConfigurationDialog( wxWindow* aParent ) override;
91
92 DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); }
93
94 bool TestConnection( wxString* aErrorMsg = nullptr );
95
96private:
97 void cacheLib();
98
99 void ensureSettings( const wxString& aSettingsPath );
100
101 void ensureConnection();
102
103 void connect();
104
105 std::unique_ptr<LIB_SYMBOL> loadSymbolFromRow( const wxString& aSymbolName,
106 const DATABASE_LIB_TABLE& aTable,
107 const DATABASE_CONNECTION::ROW& aRow );
108
109 static std::optional<bool> boolFromAny( const std::any& aVal );
110
112
113 std::unique_ptr<DATABASE_LIB_SETTINGS> m_settings;
114
116 std::unique_ptr<DATABASE_CONNECTION> m_conn;
117
118 std::set<wxString> m_customFields;
119
120 std::set<wxString> m_defaultShownFields;
121
122 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> m_nameToSymbolcache;
123 std::map<wxString, std::pair<std::string, std::string>> m_sanitizedNameMap;
124
126
129
133
136 std::unordered_set<wxString> m_inProgressLoads;
137
140 bool m_inCacheLib = false;
141
142 wxString m_lastError;
143};
144
145#endif //SCH_IO_DATABASE_H_
std::map< std::string, std::any > ROW
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:65
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:79
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.
std::unordered_set< wxString > m_inProgressLoads
LIB_IDs whose resolution is in flight, used to break self-referential cycles where a row's Symbols co...
DATABASE_LIB_SETTINGS * Settings() const
std::unique_ptr< DATABASE_CONNECTION > m_conn
Generally will be null if no valid connection is established.
friend class SCH_IO_DATABASE_CYCLE_DETECTION_FIXTURE
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 ensureSettings(const wxString &aSettingsPath)
bool m_cachePopulated
True once the LIB_SYMBOL cache has been materialized at least once.
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool SupportsSubLibraries() const override
bool TestConnection(wxString *aErrorMsg=nullptr)
bool m_inCacheLib
Re-entrancy guard for cacheLib(), tripped when a self-referential load routes back through the adapte...
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_nameToSymbolcache
std::map< wxString, std::pair< std::string, std::string > > m_sanitizedNameMap
std::set< wxString > m_defaultShownFields
void SetLibraryManagerAdapter(SYMBOL_LIBRARY_ADAPTER *aAdapter) override
Some library plugins need to interface with other loaded libraries.
virtual ~SCH_IO_DATABASE()
size_t m_cacheSignature
Signature of the raw database rows at last materialization; used to skip rebuilding the LIB_SYMBOL ca...
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
std::unique_ptr< DATABASE_LIB_SETTINGS > m_settings
bool SupportsConfigurationDialog() const override
static std::optional< bool > boolFromAny(const std::any &aVal)
SYMBOL_LIBRARY_ADAPTER * m_adapter
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
long long m_cacheTimestamp
DIALOG_SHIM * CreateConfigurationDialog(wxWindow *aParent) override
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
int GetModifyHash() const override
Return the modification hash from the library cache.
std::unique_ptr< LIB_SYMBOL > loadSymbolFromRow(const wxString &aSymbolName, const DATABASE_LIB_TABLE &aTable, const DATABASE_CONNECTION::ROW &aRow)
std::set< wxString > m_customFields
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...
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 DatabaseLibraryFileExtension
#define _HKI(x)
Definition page_info.cpp:40
A database library table will be mapped to a sub-library provided by the database library entry in th...
Container that describes file type info.
Definition io_base.h:43
Definition of file extensions used in Kicad.