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 (C) 2022-2023 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#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
30
33
34
42class SCH_IO_DATABASE : public SCH_IO
43{
44public:
45
47 virtual ~SCH_IO_DATABASE();
48
50 {
51 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad database library files" ),
53 }
54
55 int GetModifyHash() const override { return 0; }
56
57 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
58 const wxString& aLibraryPath,
59 const STRING_UTF8_MAP* aProperties = nullptr ) override;
60
61 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
62 const wxString& aLibraryPath,
63 const STRING_UTF8_MAP* aProperties = nullptr ) override;
64
65 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
66 const STRING_UTF8_MAP* aProperties = nullptr ) override;
67
68 bool SupportsSubLibraries() const override { return true; }
69
70 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
71
72 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
73
74 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
75
76 // Database libraries can never be written using the symbol editing API
77 bool IsLibraryWritable( const wxString& aLibraryPath ) override { return false; }
78
79 void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override
80 {
81 m_libTable = aTable;
82 }
83
84 DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); }
85
86 bool TestConnection( wxString* aErrorMsg = nullptr );
87
88private:
89 void cacheLib();
90
91 void ensureSettings( const wxString& aSettingsPath );
92
93 void ensureConnection();
94
95 void connect();
96
97 std::unique_ptr<LIB_SYMBOL> loadSymbolFromRow( const wxString& aSymbolName,
98 const DATABASE_LIB_TABLE& aTable,
99 const DATABASE_CONNECTION::ROW& aRow );
100
101 static std::optional<bool> boolFromAny( const std::any& aVal );
102
104
105 std::unique_ptr<DATABASE_LIB_SETTINGS> m_settings;
106
108 std::unique_ptr<DATABASE_CONNECTION> m_conn;
109
110 std::set<wxString> m_customFields;
111
112 std::set<wxString> m_defaultShownFields;
113
114 std::map<wxString, std::unique_ptr<LIB_SYMBOL>> m_nameToSymbolcache;
115
117
119
120
121
122 wxString m_lastError;
123};
124
125#endif //SCH_IO_DATABASE_H_
std::map< std::string, std::any > ROW
Define a library symbol object.
Definition: lib_symbol.h:77
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins 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.
DATABASE_LIB_SETTINGS * Settings() const
std::unique_ptr< DATABASE_CONNECTION > m_conn
Generally will be null if no valid connection is established.
void SetLibTable(SYMBOL_LIB_TABLE *aTable) override
Some library plugins need to have access to their parent library table.
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)
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...
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool SupportsSubLibraries() const override
bool TestConnection(wxString *aErrorMsg=nullptr)
std::map< wxString, std::unique_ptr< LIB_SYMBOL > > m_nameToSymbolcache
SYMBOL_LIB_TABLE * m_libTable
std::set< wxString > m_defaultShownFields
virtual ~SCH_IO_DATABASE()
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
std::unique_ptr< DATABASE_LIB_SETTINGS > m_settings
static std::optional< bool > boolFromAny(const std::any &aVal)
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
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
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 DatabaseLibraryFileExtension
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:39
Definition of file extensions used in Kicad.