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;
69
71 std::vector<std::pair<wxString, LIB_STATUS>> GetLibraryStatuses() const;
72
74 std::vector<wxString> GetAvailableExtraFields( const wxString& aNickname );
75
76 bool SupportsSubLibraries( const wxString& aNickname ) const;
77
78 std::vector<SUB_LIBRARY> GetSubLibraries( const wxString& aNickname ) const;
79
80 bool SupportsConfigurationDialog( const wxString& aNickname ) const override;
81
82 void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override;
83
89
90 std::vector<LIB_SYMBOL*> GetSymbols( const wxString& aNickname,
92
93 std::vector<wxString> GetSymbolNames( const wxString& aNickname,
104 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
105
106 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
107 {
108 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
109 }
110
119
136 SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
137 bool aOverwrite = true );
138
146 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
147
157 bool IsSymbolLibWritable( const wxString& aNickname );
158
159 std::optional<LIBRARY_ERROR> LibraryError( const wxString& aNickname ) const;
160
162 bool CreateLibrary( const wxString& aNickname );
163
164 static std::optional<SCH_IO_MGR::SCH_FILE_T> ParseLibType( const wxString& aType );
165
166 int GetModifyHash() const;
167
168 bool IsWritable( const wxString& aNickname ) const override;
169
170protected:
171 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries; }
172 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries; }
173 std::mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
174
176
177private:
179 static SCH_IO* plugin( const LIB_DATA* aRow );
180
181 // The global libraries, potentially shared between multiple different open
182 // projects, each of which has their own instance of this adapter class
183 static std::map<wxString, LIB_DATA> GlobalLibraries;
184
185 static std::mutex GlobalLibraryMutex;
186};
187
188#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:87
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
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.
bool CreateLibrary(const wxString &aNickname)
Creates the library (i.e. saves to disk) for the given row if it exists.
std::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
bool IsWritable(const wxString &aNickname) const override
Return true if the given nickname exists and is not a read-only library.
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
static SCH_IO * plugin(const LIB_DATA *aRow)
Helper to cast the ABC plugin in the LIB_DATA* to a concrete plugin.
SYMBOL_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
static wxString GlobalPathEnvVariableName()
static const char * PropPowerSymsOnly
std::vector< std::pair< wxString, LIB_STATUS > > GetLibraryStatuses() const
Returns a list of all library nicknames and their status (even if they failed to load)
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
static std::map< wxString, LIB_DATA > GlobalLibraries
static std::optional< SCH_IO_MGR::SCH_FILE_T > ParseLibType(const wxString &aType)
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< LIBRARY_ERROR > LibraryError(const wxString &aNickname) const
std::optional< LIB_STATUS > GetLibraryStatus(const wxString &aNickname) const
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)