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>
27#include <pcb_io/pcb_io.h>
28#include <project.h>
29
30class FOOTPRINT;
31
32
39{
40public:
42
44
46
47 static wxString GlobalPathEnvVariableName();
48
49 void AsyncLoad() override;
50
52 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
53
55 std::optional<LIB_STATUS> GetLibraryStatus( const wxString& aNickname ) const override;
56
63 std::vector<FOOTPRINT*> GetFootprints( const wxString& aNickname, bool aBestEfforts = false );
64
71 std::vector<wxString> GetFootprintNames( const wxString& aNickname, bool aBestEfforts = false );
72
79 long long GenerateTimestamp( const wxString* aNickname );
80
81 bool FootprintExists( const wxString& aNickname, const wxString& aName );
82
95 FOOTPRINT* LoadFootprint( const wxString& aNickname, const wxString& aName, bool aKeepUUID );
96
97 FOOTPRINT* LoadFootprint( const LIB_ID& aLibId, bool aKeepUUID )
98 {
99 return LoadFootprint( aLibId.GetLibNickname(), aLibId.GetLibItemName(), aKeepUUID );
100 }
101
116 FOOTPRINT* LoadFootprintWithOptionalNickname( const LIB_ID& aFootprintId, bool aKeepUUID );
117
118 // TODO(JE) library tables - hoist out?
127
144 SAVE_T SaveFootprint( const wxString& aNickname, const FOOTPRINT* aFootprint,
145 bool aOverwrite = true );
146
154 void DeleteFootprint( const wxString& aNickname, const wxString& aFootprintName );
155
165 bool IsFootprintLibWritable( const wxString& aNickname );
166
167 std::optional<LIBRARY_ERROR> LibraryError( const wxString& aNickname ) const override;
168
169protected:
170
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
177 IO_BASE* plugin( const LIB_DATA* aRow ) override { return pcbplugin( aRow ); }
178
179private:
181 static PCB_IO* pcbplugin( const LIB_DATA* aRow );
182
183 // The global libraries, potentially shared between multiple different open
184 // projects, each of which has their own instance of this adapter class
185 static std::map<wxString, LIB_DATA> GlobalLibraries;
186
187 static std::mutex GlobalLibraryMutex;
188};
189
190#endif //FOOTPRINT_LIBRARY_ADAPTER_H
void AsyncLoad() override
Loads all available libraries for this adapter type in the background.
bool IsFootprintLibWritable(const wxString &aNickname)
Return true if the library given by aNickname is writable.
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.
std::mutex & globalLibsMutex() override
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)
IO_BASE * plugin(const LIB_DATA *aRow) 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.
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
static PCB_IO * pcbplugin(const LIB_DATA *aRow)
Helper to cast the ABC plugin in the LIB_DATA* to a concrete plugin.
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::optional< LIB_STATUS > LoadOne(const wxString &aNickname)
Loads or reloads the given library, if it exists.
std::optional< LIBRARY_ERROR > LibraryError(const wxString &aNickname) const override
PROJECT::ELEM ProjectElementType() override
static std::map< wxString, LIB_DATA > GlobalLibraries
FOOTPRINT_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
long long GenerateTimestamp(const wxString *aNickname)
Generates a filesystem timestamp / hash value for library(ies)
SAVE_T
The set of return values from SaveSymbol() below.
std::map< wxString, LIB_DATA > & globalLibs() const override
bool FootprintExists(const wxString &aNickname, const wxString &aName)
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:71
A PROJECT can hold stuff it knows nothing about, in the form of _ELEM derivatives.
Definition project.h:97
ELEM
The set of #_ELEMs that a PROJECT can hold.
Definition project.h:71
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
LIBRARY_TABLE_TYPE
Storage for an actual loaded library (including library content owned by the plugin)