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>
27#include <core/leak_at_exit.h>
29
30class DESIGN_BLOCK;
31class DESIGN_BLOCK_IO;
32class PROJECT;
33
34
36{
37public:
39
41
42 static wxString GlobalPathEnvVariableName();
43
44 std::optional<LIB_STATUS> LoadOne( LIB_DATA* aLib ) override;
45
46 std::optional<LIB_STATUS> LoadOne( const wxString& nickname );
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
147protected:
148
149 std::map<wxString, LIB_DATA>& globalLibs() override { return GlobalLibraries.Get(); }
150 std::map<wxString, LIB_DATA>& globalLibs() const override { return GlobalLibraries.Get(); }
151 std::shared_mutex& globalLibsMutex() override { return GlobalLibraryMutex; }
152 std::shared_mutex& globalLibsMutex() const override { return GlobalLibraryMutex; }
153
154 void enumerateLibrary( LIB_DATA* aLib ) override;
155
157
158 IO_BASE* plugin( const LIB_DATA* aRow ) override;
159
160private:
161
163 static DESIGN_BLOCK_IO* dbplugin( const LIB_DATA* aRow );
164
165 // The global libraries, potentially shared between multiple different open
166 // projects, each of which has their own instance of this adapter class.
167 // Wrapped in LEAK_AT_EXIT to skip destruction at program exit for faster shutdown.
169
170 static std::shared_mutex GlobalLibraryMutex;
171};
172
173
174
175#endif //DESIGN_BLOCK_LIBRARY_ADAPTER_H
SAVE_T
The set of return values from DesignBlockSave() below.
std::shared_mutex & globalLibsMutex() override
std::map< wxString, LIB_DATA > & globalLibs() const override
static LEAK_AT_EXIT< std::map< wxString, LIB_DATA > > GlobalLibraries
std::map< wxString, LIB_DATA > & globalLibs() override
LIBRARY_TABLE_TYPE Type() const override
The type of library table this adapter works with.
DESIGN_BLOCK_LIBRARY_ADAPTER(LIBRARY_MANAGER &aManager)
std::shared_mutex & globalLibsMutex() const override
A wrapper for static data that should not be destroyed at program exit.
virtual std::optional< LIB_STATUS > LoadOne(LIB_DATA *aLib)=0
LIBRARY_MANAGER_ADAPTER(LIBRARY_MANAGER &aManager)
Constructs a type-specific adapter into the library manager.
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
virtual void enumerateLibrary(LIB_DATA *aLib)=0
Override in derived class to perform library-specific enumeration.
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
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)