KiCad PCB EDA Suite
Loading...
Searching...
No Matches
symbol_library_adapter.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 * @author Jon Evans <[email protected]>
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
22#ifndef SYMBOL_LIBRARY_MANAGER_ADAPTER_H
23#define SYMBOL_LIBRARY_MANAGER_ADAPTER_H
24
25#include <future>
26#include <memory>
27#include <optional>
28#include <lib_id.h>
29#include <core/leak_at_exit.h>
31#include <sch_io/sch_io.h>
32
33class LIB_SYMBOL;
34class PROJECT;
35
36
41{
42 wxString nickname;
43 wxString description;
44};
45
46
53{
54public:
55 static const char* PropPowerSymsOnly;
56 static const char* PropNonPowerSymsOnly;
57
58public:
60
61 ~SYMBOL_LIBRARY_ADAPTER() override;
62
64
65 static wxString GlobalPathEnvVariableName();
66
68 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
69
70 std::optional<LIB_STATUS> CheckLibrary( LIB_DATA* aLib ) override;
71
73 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
74
76 std::vector<wxString> GetAvailableExtraFields( const wxString& aNickname );
77
78 bool SupportsSubLibraries( const wxString& aNickname ) const;
79
80 std::vector<SUB_LIBRARY> GetSubLibraries( const wxString& aNickname ) const;
81
82 bool SupportsConfigurationDialog( const wxString& aNickname ) const override;
83
84 int ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override;
85
91
92 std::vector<LIB_SYMBOL*> GetSymbols( const wxString& aNickname,
94
95 std::vector<wxString> GetSymbolNames( const wxString& aNickname,
97
110 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
111
112 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
113 {
114 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
115 }
116
125
142 SAVE_T SaveSymbol( const wxString& aNickname, std::unique_ptr<LIB_SYMBOL> aSymbol,
143 bool aOverwrite = true );
144
152 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
153
163 bool IsSymbolLibWritable( const wxString& aNickname );
164
165 int GetModifyHash() const;
166
177 std::optional<int> GetLibraryModifyHash( const wxString& aNickname ) const;
178
179protected:
180 std::map<wxString, LIB_DATA>& globalLibs() override
181 {
182 return m_manager.IsProjectScoped() ? m_scopedGlobalLibraries : GlobalLibraries.Get();
183 }
184
185 std::map<wxString, LIB_DATA>& globalLibs() const override
186 {
187 return m_manager.IsProjectScoped() ? m_scopedGlobalLibraries : GlobalLibraries.Get();
188 }
189
190 std::shared_mutex& globalLibsMutex() override
191 {
192 return m_manager.IsProjectScoped() ? m_scopedGlobalLibraryMutex : GlobalLibraryMutex.Get();
193 }
194
195 std::shared_mutex& globalLibsMutex() const override
196 {
197 return m_manager.IsProjectScoped() ? m_scopedGlobalLibraryMutex : GlobalLibraryMutex.Get();
198 }
199
200 void enumerateLibrary( LIB_DATA* aLib, const wxString& aUri ) override;
201
203
204 IO_BASE* plugin( const LIB_DATA* aRow ) override { return schplugin( aRow ); }
205
206private:
207 static SCH_IO* schplugin( const LIB_DATA* aRow );
208
209 // Global rows can contain project variables, so passive loads cannot share their plugins.
210 mutable std::map<wxString, LIB_DATA> m_scopedGlobalLibraries;
211 mutable std::shared_mutex m_scopedGlobalLibraryMutex;
212
214
215 // Leaked like GlobalLibraries so adapter destructors can still lock it to evict their entries
216 // even when they run during static teardown.
218};
219
220#endif //SYMBOL_LIBRARY_MANAGER_ADAPTER_H
A wrapper for static data that should not be destroyed at program exit.
LIBRARY_MANAGER_ADAPTER(LIBRARY_MANAGER &aManager)
Constructs a type-specific adapter into the library manager.
LIBRARY_MANAGER & m_manager
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:45
const UTF8 & GetLibItemName() const
Definition lib_id.h:98
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:83
Define a library symbol object.
Definition lib_symbol.h:119
Container for project specific data.
Definition project.h:63
Base class that schematic file and library loading and saving plugins should derive from.
Definition sch_io.h:60
std::shared_mutex & globalLibsMutex() override
bool SupportsConfigurationDialog(const wxString &aNickname) const override
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
static SCH_IO * schplugin(const LIB_DATA *aRow)
LIB_SYMBOL * LoadSymbol(const wxString &aNickname, const wxString &aName)
Load a LIB_SYMBOL having aName from the library given by aNickname.
LIB_SYMBOL * LoadSymbol(const LIB_ID &aLibId)
void DeleteSymbol(const wxString &aNickname, const wxString &aSymbolName)
Deletes the aSymbolName from the library given by aNickname.
std::optional< LIB_STATUS > CheckLibrary(LIB_DATA *aLib) override
Validates that a library is loadable. May not necessarily load the library!
SAVE_T SaveSymbol(const wxString &aNickname, std::unique_ptr< LIB_SYMBOL > aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
void enumerateLibrary(LIB_DATA *aLib, const wxString &aUri) override
Override in derived class to perform library-specific enumeration.
std::map< wxString, LIB_DATA > m_scopedGlobalLibraries
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row) override
Creates a concrete plugin for the given row.
std::vector< SUB_LIBRARY > GetSubLibraries(const wxString &aNickname) const
SYMBOL_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
static wxString GlobalPathEnvVariableName()
static const char * PropPowerSymsOnly
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
IO_BASE * plugin(const LIB_DATA *aRow) override
std::map< wxString, LIB_DATA > & globalLibs() const override
std::vector< LIB_SYMBOL * > GetSymbols(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
std::map< wxString, LIB_DATA > & globalLibs() override
std::shared_mutex m_scopedGlobalLibraryMutex
static LEAK_AT_EXIT< std::shared_mutex > GlobalLibraryMutex
static LEAK_AT_EXIT< std::map< wxString, LIB_DATA > > GlobalLibraries
std::vector< wxString > GetAvailableExtraFields(const wxString &aNickname)
Returns a list of additional (non-mandatory) symbol fields present in the given library.
SAVE_T
The set of return values from SaveSymbol() below.
static const char * PropNonPowerSymsOnly
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
std::optional< int > GetLibraryModifyHash(const wxString &aNickname) const
Return the modify hash of a single library if it is currently loaded.
int ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const override
std::shared_mutex & globalLibsMutex() const override
Utilities for intentionally "leaking" memory at program exit.
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
LIBRARY_TABLE_TYPE
Storage for an actual loaded library (including library content owned by the plugin)
A descriptor for a sub-library (supported by database and http libraries)