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>
27#include <core/leak_at_exit.h>
29#include <sch_io/sch_io.h>
30
31class LIB_SYMBOL;
32class PROJECT;
33
34
39{
40 wxString nickname;
41 wxString description;
42};
43
44
51{
52public:
53 static const char* PropPowerSymsOnly;
54 static const char* PropNonPowerSymsOnly;
55
56public:
58
60
61 static wxString GlobalPathEnvVariableName();
62
64 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
65
67 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
68
70 std::vector<wxString> GetAvailableExtraFields( const wxString& aNickname );
71
72 bool SupportsSubLibraries( const wxString& aNickname ) const;
73
74 std::vector<SUB_LIBRARY> GetSubLibraries( const wxString& aNickname ) const;
75
76 bool SupportsConfigurationDialog( const wxString& aNickname ) const override;
77
78 void ShowConfigurationDialog( const wxString& aNickname, wxWindow* aParent ) const override;
79
85
86 std::vector<LIB_SYMBOL*> GetSymbols( const wxString& aNickname,
88
89 std::vector<wxString> GetSymbolNames( const wxString& aNickname,
100 LIB_SYMBOL* LoadSymbol( const wxString& aNickname, const wxString& aName );
101
102 LIB_SYMBOL* LoadSymbol( const LIB_ID& aLibId )
103 {
104 return LoadSymbol( aLibId.GetLibNickname(), aLibId.GetLibItemName() );
105 }
106
115
132 SAVE_T SaveSymbol( const wxString& aNickname, const LIB_SYMBOL* aSymbol,
133 bool aOverwrite = true );
134
142 void DeleteSymbol( const wxString& aNickname, const wxString& aSymbolName );
143
153 bool IsSymbolLibWritable( const wxString& aNickname );
154
155 int GetModifyHash() const;
156
157protected:
158 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries.Get(); }
159 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries.Get(); }
160 std::shared_mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
161 std::shared_mutex& globalLibsMutex() const override { return GlobalLibraryMutex; }
162
163 void enumerateLibrary( LIB_DATA* aLib ) override;
164
166
167 IO_BASE* plugin( const LIB_DATA* aRow ) override { return schplugin( aRow ); }
168
169private:
170 static SCH_IO* schplugin( const LIB_DATA* aRow );
171
173 static std::shared_mutex GlobalLibraryMutex;
174};
175
176#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: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:83
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
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::vector< wxString > GetSymbolNames(const wxString &aNickname, SYMBOL_TYPE aType=SYMBOL_TYPE::ALL_SYMBOLS)
bool SupportsSubLibraries(const wxString &aNickname) const
static std::shared_mutex GlobalLibraryMutex
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.
void enumerateLibrary(LIB_DATA *aLib) override
Override in derived class to perform library-specific enumeration.
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::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::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)