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 <optional>
27#include <lib_id.h>
28#include <core/leak_at_exit.h>
30#include <sch_io/sch_io.h>
31
32class LIB_SYMBOL;
33class PROJECT;
34
35
40{
41 wxString nickname;
42 wxString description;
43};
44
45
52{
53public:
54 static const char* PropPowerSymsOnly;
55 static const char* PropNonPowerSymsOnly;
56
57public:
59
60 ~SYMBOL_LIBRARY_ADAPTER() override;
61
63
64 static wxString GlobalPathEnvVariableName();
65
67 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
68
70 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
71
73 std::vector<wxString> GetAvailableExtraFields( const wxString& aNickname );
74
75 bool SupportsSubLibraries( const wxString& aNickname ) const;
76
77 std::vector<SUB_LIBRARY> GetSubLibraries( const wxString& aNickname ) const;
78
79 bool SupportsConfigurationDialog( const wxString& aNickname ) const override;
80
81 void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override;
82
88
89 std::vector<LIB_SYMBOL*> GetSymbols( const wxString& aNickname,
91
92 std::vector<wxString> GetSymbolNames( const wxString& aNickname,
103 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
104
105 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
106 {
107 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
108 }
109
118
135 SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
136 bool aOverwrite = true );
137
145 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
146
156 bool IsSymbolLibWritable( const wxString& aNickname );
157
158 int GetModifyHash() const;
159
170 std::optional<int> GetLibraryModifyHash( const wxString& aNickname ) const;
171
172protected:
173 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries.Get(); }
174 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries.Get(); }
175 std::shared_mutex& globalLibsMutex() override { return GlobalLibraryMutex.Get(); }
176 std::shared_mutex& globalLibsMutex() const override { return GlobalLibraryMutex.Get(); }
177
178 void enumerateLibrary( LIB_DATA* aLib, const wxString& aUri ) override;
179
181
182 IO_BASE* plugin( const LIB_DATA* aRow ) override { return schplugin( aRow ); }
183
184private:
185 static SCH_IO* schplugin( const LIB_DATA* aRow );
186
188
189 // Leaked like GlobalLibraries so adapter destructors can still lock it to evict their entries
190 // even when they run during static teardown.
192};
193
194#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.
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:79
Container for project specific data.
Definition project.h:62
Base class that schematic file and library loading and saving plugins should derive from.
Definition sch_io.h:59
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.
void enumerateLibrary(LIB_DATA *aLib, const wxString &aUri) override
Override in derived class to perform library-specific enumeration.
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
SAVE_T SaveSymbol(const wxString &aNickname, const LIB_SYMBOL *aSymbol, bool aOverwrite=true)
Write aSymbol to an existing library given by aNickname.
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
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.
void ShowConfigurationDialog(const wxString &aNickname, wxWindow *aParent) const override
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.
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)