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 along
18 * with this program. If not, see <http://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 <lib_id.h>
28#include <sch_io/sch_io.h>
29
30class LIB_SYMBOL;
31class PROJECT;
32
33
38{
39 wxString nickname;
40 wxString description;
41};
42
43
50{
51public:
52 static const char* PropPowerSymsOnly;
53 static const char* PropNonPowerSymsOnly;
54
55public:
57
59
60 static wxString GlobalPathEnvVariableName();
61
62 void AsyncLoad() override;
63
65 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
66
68 std::optional<LIB_STATUS> GetLibraryStatus( const wxString& aNickname ) const override;
69
71 std::vector<wxString> GetAvailableExtraFields( const wxString& aNickname );
72
73 bool SupportsSubLibraries( const wxString& aNickname ) const;
74
75 std::vector<SUB_LIBRARY> GetSubLibraries( const wxString& aNickname ) const;
76
77 bool SupportsConfigurationDialog( const wxString& aNickname ) const override;
78
79 void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override;
80
86
87 std::vector<LIB_SYMBOL*> GetSymbols( const wxString& aNickname,
89
90 std::vector<wxString> GetSymbolNames( const wxString& aNickname,
101 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
102
103 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
104 {
105 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
106 }
107
116
133 SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
134 bool aOverwrite = true );
135
143 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
144
154 bool IsSymbolLibWritable( const wxString& aNickname );
155
156 std::optional<LIBRARY_ERROR> LibraryError( const wxString& aNickname ) const override;
157
158 int GetModifyHash() const;
159
160protected:
161 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries; }
162 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries; }
163 std::mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
164
166
167 IO_BASE* plugin( const LIB_DATA* aRow ) override { return schplugin( aRow ); }
168
169private:
171 static SCH_IO* schplugin( const LIB_DATA* aRow );
172
173 // The global libraries, potentially shared between multiple different open
174 // projects, each of which has their own instance of this adapter class
175 static std::map<wxString, LIB_DATA> GlobalLibraries;
176
177 static std::mutex GlobalLibraryMutex;
178};
179
180#endif //SYMBOL_LIBRARY_MANAGER_ADAPTER_H
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:49
const UTF8 & GetLibItemName() const
Definition lib_id.h:102
const UTF8 & GetLibNickname() const
Return the logical library name portion of a LIB_ID.
Definition lib_id.h:87
Define a library symbol object.
Definition lib_symbol.h:85
Container for project specific data.
Definition project.h:65
Base class that schematic file and library loading and saving plugins should derive from.
Definition sch_io.h:59
bool SupportsConfigurationDialog(const wxString &aNickname) const override
static SCH_IO * schplugin(const LIB_DATA *aRow)
Helper to cast the ABC plugin in the LIB_DATA* to a concrete plugin.
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< LIBRARY_ERROR > LibraryError(const wxString &aNickname) const override
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
std::optional< LIB_STATUS > LoadOne(const wxString &aNickname)
Loads or reloads the given library, if it exists.
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.
static std::map< wxString, LIB_DATA > GlobalLibraries
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
void AsyncLoad() override
Loads all available libraries for this adapter type in the background.
std::mutex & globalLibsMutex() override
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
std::optional< LIB_STATUS > GetLibraryStatus(const wxString &aNickname) const override
Returns the status of a loaded library, or nullopt if the library hasn't been loaded (yet)
bool IsSymbolLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
static std::mutex GlobalLibraryMutex
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)