KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_database_plugin.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 KICAD_SCH_DATABASE_PLUGIN_H
22#define KICAD_SCH_DATABASE_PLUGIN_H
23
25#include <sch_io_mgr.h>
27
28
31
32
41{
42public:
43
45 virtual ~SCH_DATABASE_PLUGIN();
46
47 const wxString GetName() const override
48 {
49 return wxT( "Database library" );
50 }
51
52 const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
53 {
54 return PLUGIN_FILE_DESC( _HKI( "KiCad database library files" ),
56 }
57
58 int GetModifyHash() const override { return 0; }
59
60 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
61 const wxString& aLibraryPath,
62 const STRING_UTF8_MAP* aProperties = nullptr ) override;
63
64 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
65 const wxString& aLibraryPath,
66 const STRING_UTF8_MAP* aProperties = nullptr ) override;
67
68 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
69 const STRING_UTF8_MAP* aProperties = nullptr ) override;
70
71 bool SupportsSubLibraries() const override { return true; }
72
73 void GetSubLibraryNames( std::vector<wxString>& aNames ) override;
74
75 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
76
77 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
78
79 // Database libraries can never be written using the symbol editing API
80 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override
81 {
82 return false;
83 }
84
85 void SetLibTable( SYMBOL_LIB_TABLE* aTable ) override
86 {
87 m_libTable = aTable;
88 }
89
90 DATABASE_LIB_SETTINGS* Settings() const { return m_settings.get(); }
91
92 bool TestConnection( wxString* aErrorMsg = nullptr );
93
94private:
95 void ensureSettings( const wxString& aSettingsPath );
96
97 void ensureConnection();
98
99 void connect();
100
101 LIB_SYMBOL* loadSymbolFromRow( const wxString& aSymbolName,
102 const DATABASE_LIB_TABLE& aTable,
103 const DATABASE_CONNECTION::ROW& aRow );
104
105 static std::optional<bool> boolFromAny( const std::any& aVal );
106
108
109 std::unique_ptr<DATABASE_LIB_SETTINGS> m_settings;
110
112 std::unique_ptr<DATABASE_CONNECTION> m_conn;
113
114 std::set<wxString> m_customFields;
115
116 std::set<wxString> m_defaultShownFields;
117
118 wxString m_lastError;
119};
120
121#endif //KICAD_SCH_DATABASE_PLUGIN_H
std::map< std::string, std::any > ROW
Define a library symbol object.
Definition: lib_symbol.h:99
A KiCad database library provides both symbol and footprint metadata, so there are "shim" plugins on ...
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
Returns symbol library description for the SCH_PLUGIN.
static std::optional< bool > boolFromAny(const std::any &aVal)
void SetLibTable(SYMBOL_LIB_TABLE *aTable) override
Some library plugins need to have access to their parent library table.
std::unique_ptr< DATABASE_CONNECTION > m_conn
Generally will be null if no valid connection is established.
void GetSubLibraryNames(std::vector< wxString > &aNames) override
Retrieves a list of sub-libraries in this library.
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.
void ensureSettings(const wxString &aSettingsPath)
bool TestConnection(wxString *aErrorMsg=nullptr)
std::set< wxString > m_defaultShownFields
DATABASE_LIB_SETTINGS * Settings() const
std::set< wxString > m_customFields
LIB_SYMBOL * loadSymbolFromRow(const wxString &aSymbolName, const DATABASE_LIB_TABLE &aTable, const DATABASE_CONNECTION::ROW &aRow)
bool SupportsSubLibraries() const override
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...
int GetModifyHash() const override
Return the modification hash from the library cache.
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
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...
std::unique_ptr< DATABASE_LIB_SETTINGS > m_settings
SYMBOL_LIB_TABLE * m_libTable
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
A name/value tuple with unique names and optional values.
#define _HKI(x)
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 of file extensions used in Kicad.