KiCad PCB EDA Suite
Loading...
Searching...
No Matches
footprint_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 FOOTPRINT_LIBRARY_ADAPTER_H
23#define FOOTPRINT_LIBRARY_ADAPTER_H
24
25#include <lib_id.h>
26#include <core/leak_at_exit.h>
28#include <pcb_io/pcb_io.h>
29#include <project.h>
30
31class FOOTPRINT;
32
33
40{
41public:
43
45
46 static wxString GlobalPathEnvVariableName();
47
49 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
50
52 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
53
60 std::vector<FOOTPRINT*> GetFootprints( const wxString& aNickname, bool aBestEfforts = false );
61
62
69 std::vector<wxString> GetFootprintNames( const wxString& aNickname, bool aBestEfforts = false );
70
77 long long GenerateTimestamp( const wxString* aNickname );
78
79 bool FootprintExists( const wxString& aNickname, const wxString& aName );
80
93 FOOTPRINT* LoadFootprint( const wxString& aNickname, const wxString& aName, bool aKeepUUID );
94
95 FOOTPRINT* LoadFootprint( const LIB_ID& aLibId, bool aKeepUUID )
96 {
97 return LoadFootprint( aLibId.GetLibNickname(), aLibId.GetLibItemName(), aKeepUUID );
98 }
99
114 FOOTPRINT* LoadFootprintWithOptionalNickname( const LIB_ID& aFootprintId, bool aKeepUUID );
115
116 // TODO(JE) library tables - hoist out?
125
142 SAVE_T SaveFootprint( const wxString& aNickname, const FOOTPRINT* aFootprint,
143 bool aOverwrite = true );
144
152 void DeleteFootprint( const wxString& aNickname, const wxString& aFootprintName );
153
163 bool IsFootprintLibWritable( const wxString& aNickname );
164
165protected:
166 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries.Get(); }
167 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries.Get(); }
168 std::shared_mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
169 std::shared_mutex& globalLibsMutex() const override { return GlobalLibraryMutex; }
170
171 void enumerateLibrary( LIB_DATA* aLib ) override;
172
174
175 IO_BASE* plugin( const LIB_DATA* aRow ) override { return pcbplugin( aRow ); }
176
177private:
178 static PCB_IO* pcbplugin( const LIB_DATA* aRow );
179
181 static std::shared_mutex GlobalLibraryMutex;
182
186 static std::shared_mutex PreloadedFootprintsMutex;
187};
188
189#endif //FOOTPRINT_LIBRARY_ADAPTER_H
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
static std::shared_mutex GlobalLibraryMutex
void DeleteFootprint(const wxString &aNickname, const wxString &aFootprintName)
Deletes the aFootprintName from the library given by aNickname.
FOOTPRINT * LoadFootprint(const LIB_ID &aLibId, bool aKeepUUID)
std::vector< FOOTPRINT * > GetFootprints(const wxString &aNickname, bool aBestEfforts=false)
Retrieves a list of footprints contained in a given loaded library.
void enumerateLibrary(LIB_DATA *aLib) override
Override in derived class to perform library-specific enumeration.
IO_BASE * plugin(const LIB_DATA *aRow) override
std::shared_mutex & globalLibsMutex() const override
SAVE_T SaveFootprint(const wxString &aNickname, const FOOTPRINT *aFootprint, bool aOverwrite=true)
Write aFootprint to an existing library given by aNickname.
std::vector< wxString > GetFootprintNames(const wxString &aNickname, bool aBestEfforts=false)
Retrieves a list of footprint names contained in a given loaded library.
std::map< wxString, LIB_DATA > & globalLibs() override
FOOTPRINT * LoadFootprint(const wxString &aNickname, const wxString &aName, bool aKeepUUID)
Load a FOOTPRINT having aName from the library given by aNickname.
static LEAK_AT_EXIT< std::map< wxString, LIB_DATA > > GlobalLibraries
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
static PCB_IO * pcbplugin(const LIB_DATA *aRow)
FOOTPRINT * LoadFootprintWithOptionalNickname(const LIB_ID &aFootprintId, bool aKeepUUID)
Load a footprint having aFootprintId with possibly an empty nickname.
LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row) override
Creates a concrete plugin for the given row.
std::shared_mutex & globalLibsMutex() override
FOOTPRINT_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
long long GenerateTimestamp(const wxString *aNickname)
Generates a filesystem timestamp / hash value for library(ies)
std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib) override
Loads or reloads the given library, if it exists.
SAVE_T
The set of return values from SaveSymbol() below.
static LEAK_AT_EXIT< std::map< wxString, std::vector< std::unique_ptr< FOOTPRINT > > > > PreloadedFootprints
Storage for preloaded footprints, indexed by library nickname.
std::map< wxString, LIB_DATA > & globalLibs() const override
bool FootprintExists(const wxString &aNickname, const wxString &aName)
static std::shared_mutex PreloadedFootprintsMutex
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
A base class that BOARD loading and saving plugins should derive from.
Definition pcb_io.h:70
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)