KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io_mgr.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 (C) 2011-2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef PCB_IO_MGR_H_
22#define PCB_IO_MGR_H_
23
24#include <cstdint>
25#include <config.h>
26#include <vector>
27#include <wx/arrstr.h>
28#include <i18n_utility.h>
29#include <io/io_base.h>
30#include <io/io_mgr.h>
31#include <pcb_io/pcb_io.h>
32
33class BOARD;
34class PCB_IO;
35class FOOTPRINT;
36class PROJECT;
38class REPORTER;
39
43class PCB_IO_MGR : public IO_MGR
44{
45public:
46
83
89 {
90 public:
91 struct ENTRY
92 {
94 std::function<PCB_IO*(void)> m_createFunc;
95 wxString m_name;
96 };
97
99 {
100 static PLUGIN_REGISTRY *self = nullptr;
101
102 if( !self )
103 {
104 self = new PLUGIN_REGISTRY;
105 }
106 return self;
107 }
108
109 void Register( PCB_FILE_T aType, const wxString& aName,
110 std::function<PCB_IO*(void)> aCreateFunc )
111 {
112 ENTRY ent;
113 ent.m_type = aType;
114 ent.m_createFunc = aCreateFunc;
115 ent.m_name = aName;
116 m_plugins.push_back( ent );
117 }
118
119 PCB_IO* Create( PCB_FILE_T aFileType ) const
120 {
121 for( auto& ent : m_plugins )
122 {
123 if ( ent.m_type == aFileType )
124 {
125 return ent.m_createFunc();
126 }
127 }
128
129 return nullptr;
130 }
131
132 const std::vector<ENTRY>& AllPlugins() const
133 {
134 return m_plugins;
135 }
136
137 private:
138 std::vector<ENTRY> m_plugins;
139 };
140
151 {
152 REGISTER_PLUGIN( PCB_FILE_T aType, const wxString& aName,
153 std::function<PCB_IO*(void)> aCreateFunc )
154 {
155 PLUGIN_REGISTRY::Instance()->Register( aType, aName, aCreateFunc );
156 }
157 };
158
159
169 static PCB_IO* FindPlugin( PCB_FILE_T aFileType );
170
174 static const wxString ShowType( PCB_FILE_T aFileType );
175
179 static PCB_FILE_T EnumFromStr( const wxString& aFileType );
180
184 static PCB_FILE_T FindPluginTypeFromBoardPath( const wxString& aFileName, int aCtl = 0 );
185
192 static bool ImportGeneratesProjectLibrary( PCB_FILE_T aFileType );
193
199 static bool ImportPopulatesProjectSettings( PCB_FILE_T aFileType );
200
204 static PCB_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl = 0 );
205
223 static std::unique_ptr<BOARD> Load( PCB_FILE_T aFileType, const wxString& aFileName,
224 const std::map<std::string, UTF8>* aProperties = nullptr,
225 PROJECT* aProject = nullptr, PROGRESS_REPORTER* aProgressReporter = nullptr );
226
246 static void Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD& aBoard,
247 const std::map<std::string, UTF8>* aProperties = nullptr );
248
252 static bool ConvertLibrary( const std::map<std::string, UTF8>& aOldFileProps,
253 const wxString& aOldFilePath,
254 const wxString& aNewFilePath, REPORTER* aReporter );
255};
256
257#endif // PCB_IO_MGR_H_
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:409
Hold a list of available plugins, created using a singleton REGISTER_PLUGIN object.
Definition pcb_io_mgr.h:89
PCB_IO * Create(PCB_FILE_T aFileType) const
Definition pcb_io_mgr.h:119
const std::vector< ENTRY > & AllPlugins() const
Definition pcb_io_mgr.h:132
void Register(PCB_FILE_T aType, const wxString &aName, std::function< PCB_IO *(void)> aCreateFunc)
Definition pcb_io_mgr.h:109
static PLUGIN_REGISTRY * Instance()
Definition pcb_io_mgr.h:98
std::vector< ENTRY > m_plugins
Definition pcb_io_mgr.h:138
A factory which returns an instance of a #PLUGIN.
Definition pcb_io_mgr.h:44
static bool ConvertLibrary(const std::map< std::string, UTF8 > &aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath, REPORTER *aReporter)
Convert a schematic symbol library to the latest KiCad format.
static bool ImportPopulatesProjectSettings(PCB_FILE_T aFileType)
Return true when importing aFileType writes netclasses, rules or other settings that belong to the pr...
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
PCB_FILE_T
The set of file types that the PCB_IO_MGR knows about, and for which there has been a plugin written,...
Definition pcb_io_mgr.h:52
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition pcb_io_mgr.h:54
@ GEDA_PCB
Geda PCB file formats.
Definition pcb_io_mgr.h:66
@ ALTIUM_DESIGNER
Definition pcb_io_mgr.h:59
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition pcb_io_mgr.h:55
@ ALTIUM_CIRCUIT_MAKER
Definition pcb_io_mgr.h:57
@ ALTIUM_CIRCUIT_STUDIO
Definition pcb_io_mgr.h:58
@ CADSTAR_PCB_ARCHIVE
Definition pcb_io_mgr.h:60
@ PCB_FILE_UNKNOWN
0 is not a legal menu id on Mac
Definition pcb_io_mgr.h:53
static void Save(PCB_FILE_T aFileType, const wxString &aFileName, BOARD &aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write either a full aBoard to a storage file in a format that this implementation knows about,...
static PCB_IO * FindPlugin(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
static std::unique_ptr< BOARD > Load(PCB_FILE_T aFileType, const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Find the requested #PLUGIN and if found, calls the #PLUGIN::LoadBoard() function on it using the argu...
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
static bool ImportGeneratesProjectLibrary(PCB_FILE_T aFileType)
Return true when importing aFileType should materialize a project footprint library.
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
A base class that BOARD loading and saving plugins should derive from.
Definition pcb_io.h:76
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition project.h:63
A pure virtual class used to derive REPORTER objects from.
Definition reporter.h:73
Some functions to handle hotkeys in KiCad.
std::function< PCB_IO *(void)> m_createFunc
Definition pcb_io_mgr.h:94
REGISTER_PLUGIN(PCB_FILE_T aType, const wxString &aName, std::function< PCB_IO *(void)> aCreateFunc)
Definition pcb_io_mgr.h:152