KiCad PCB EDA Suite
Loading...
Searching...
No Matches
design_block_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 DESIGN_BLOCK_LIBRARY_ADAPTER_H
23#define DESIGN_BLOCK_LIBRARY_ADAPTER_H
24
25#include <kicommon.h>
26#include <lib_id.h>
28
29class DESIGN_BLOCK;
30class DESIGN_BLOCK_IO;
31class PROJECT;
32
33
35{
36public:
38
40
41 static wxString GlobalPathEnvVariableName();
42
43 void AsyncLoad() override;
44
45 // Currently unused for design blocks
46 std::optional<LIB_STATUS> GetLibraryStatus( const wxString& aNickname ) const override { return std::nullopt; }
47
49 std::vector<DESIGN_BLOCK*> GetDesignBlocks( const wxString& aNickname );
50
52 std::vector<wxString> GetDesignBlockNames( const wxString& aNickname );
53
67 DESIGN_BLOCK* LoadDesignBlock( const wxString& aNickname, const wxString& aDesignBlockName,
68 bool aKeepUUID = false );
69
73 bool DesignBlockExists( const wxString& aNickname, const wxString& aDesignBlockName );
74
81 // TODO(JE) library tables -- do we still need this?
82 const DESIGN_BLOCK* GetEnumeratedDesignBlock( const wxString& aNickname, const wxString& aDesignBlockName );
83
92
107 SAVE_T SaveDesignBlock( const wxString& aNickname, const DESIGN_BLOCK* aDesignBlock,
108 bool aOverwrite = true );
109
119 void DeleteDesignBlock( const wxString& aNickname, const wxString& aDesignBlockName );
120
128 bool IsDesignBlockLibWritable( const wxString& aNickname );
129
144 DESIGN_BLOCK* DesignBlockLoadWithOptionalNickname( const LIB_ID& aDesignBlockId,
145 bool aKeepUUID = false );
146
147 std::optional<LIBRARY_ERROR> LibraryError( const wxString& aNickname ) const override;
148
149protected:
150
151 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries; }
152 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries; }
153 std::mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
154
156
157 IO_BASE* plugin( const LIB_DATA* aRow ) override;
158
159private:
160
162 static DESIGN_BLOCK_IO* dbplugin( const LIB_DATA* aRow );
163
164 // The global libraries, potentially shared between multiple different open
165 // projects, each of which has their own instance of this adapter class
166 static std::map<wxString, LIB_DATA> GlobalLibraries;
167
168 static std::mutex GlobalLibraryMutex;
169};
170
171
172
173#endif //DESIGN_BLOCK_LIBRARY_ADAPTER_H
SAVE_T
The set of return values from DesignBlockSave() below.
std::map< wxString, LIB_DATA > & globalLibs() const 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)
std::map< wxString, LIB_DATA > & globalLibs() override
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
static std::map< wxString, LIB_DATA > GlobalLibraries
DESIGN_BLOCK_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
LIBRARY_MANAGER_ADAPTER(LIBRARY_MANAGER &aManager)
Constructs a type-specific adapter into the library manager.
virtual std::optional< LIBRARY_ERROR > LibraryError(const wxString &aNickname) const
virtual void AsyncLoad()=0
Loads all available libraries for this adapter type in the background.
virtual LIBRARY_RESULT< IO_BASE * > createPlugin(const LIBRARY_TABLE_ROW *row)=0
Creates a concrete plugin for the given row.
virtual IO_BASE * plugin(const LIB_DATA *aRow)=0
A logical library item identifier and consists of various portions much like a URI.
Definition lib_id.h:49
Container for project specific data.
Definition project.h:65
#define KICOMMON_API
Definition kicommon.h:28
tl::expected< ResultType, LIBRARY_ERROR > LIBRARY_RESULT
LIBRARY_TABLE_TYPE
Storage for an actual loaded library (including library content owned by the plugin)