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
45 static wxString GlobalPathEnvVariableName();
46
47 void AsyncLoad() override;
48
50 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
51
53 std::optional<LIB_STATUS> LoadOne( const wxString& aNickname );
54
56 std::optional<LIB_STATUS> GetLibraryStatus( const wxString& aNickname ) const override;
57
64 std::vector<FOOTPRINT*> GetFootprints( const wxString& aNickname, bool aBestEfforts = false );
65
72 std::vector<wxString> GetFootprintNames( const wxString& aNickname, bool aBestEfforts = false );
73
80 long long GenerateTimestamp( const wxString* aNickname );
81
82 bool FootprintExists( const wxString& aNickname, const wxString& aName );
83
96 FOOTPRINT* LoadFootprint( const wxString& aNickname, const wxString& aName, bool aKeepUUID );
97
98 FOOTPRINT* LoadFootprint( const LIB_ID& aLibId, bool aKeepUUID )
99 {
100 return LoadFootprint( aLibId.GetLibNickname(), aLibId.GetLibItemName(), aKeepUUID );
101 }
102
117 FOOTPRINT* LoadFootprintWithOptionalNickname( const LIB_ID& aFootprintId, bool aKeepUUID );
118
119 // TODO(JE) library tables - hoist out?
128
145 SAVE_T SaveFootprint( const wxString& aNickname, const FOOTPRINT* aFootprint,
146 bool aOverwrite = true );
147
155 void DeleteFootprint( const wxString& aNickname, const wxString& aFootprintName );
156
166 bool IsFootprintLibWritable( const wxString& aNickname );
167
168protected:
169
170 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries; }
171 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries; }
172 std::mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
173
175
176 IO_BASE* plugin( const LIB_DATA* aRow ) override { return pcbplugin( aRow ); }
177
178private:
180 static PCB_IO* pcbplugin( const LIB_DATA* aRow );
181
182 // The global libraries, potentially shared between multiple different open
183 // projects, each of which has their own instance of this adapter class
184 static std::map<wxString, LIB_DATA> GlobalLibraries;
185
186 static std::mutex GlobalLibraryMutex;
187};
188
189#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.
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)
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.
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:70
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
LIBRARY_TABLE_TYPE
Storage for an actual loaded library (including library content owned by the plugin)