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 (C) 2016-2023 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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef PCB_IO_MGR_H_
26#define PCB_IO_MGR_H_
27
28#include <cstdint>
29#include <config.h>
30#include <vector>
31#include <wx/arrstr.h>
32#include <i18n_utility.h>
33#include <io/io_base.h>
34#include <io/io_mgr.h>
35#include <pcb_io/pcb_io.h>
36
37class BOARD;
38class PCB_IO;
39class FOOTPRINT;
40class PROJECT;
42class REPORTER;
43
47class PCB_IO_MGR : public IO_MGR
48{
49public:
50
56 {
73 // add your type here.
74
75 // etc.
76
78 };
79
85 {
86 public:
87 struct ENTRY
88 {
90 std::function<PCB_IO*(void)> m_createFunc;
91 wxString m_name;
92 };
93
95 {
96 static PLUGIN_REGISTRY *self = nullptr;
97
98 if( !self )
99 {
100 self = new PLUGIN_REGISTRY;
101 }
102 return self;
103 }
104
105 void Register( PCB_FILE_T aType, const wxString& aName,
106 std::function<PCB_IO*(void)> aCreateFunc )
107 {
108 ENTRY ent;
109 ent.m_type = aType;
110 ent.m_createFunc = aCreateFunc;
111 ent.m_name = aName;
112 m_plugins.push_back( ent );
113 }
114
115 PCB_IO* Create( PCB_FILE_T aFileType ) const
116 {
117 for( auto& ent : m_plugins )
118 {
119 if ( ent.m_type == aFileType )
120 {
121 return ent.m_createFunc();
122 }
123 }
124
125 return nullptr;
126 }
127
128 const std::vector<ENTRY>& AllPlugins() const
129 {
130 return m_plugins;
131 }
132
133 private:
134 std::vector<ENTRY> m_plugins;
135 };
136
147 {
148 REGISTER_PLUGIN( PCB_FILE_T aType, const wxString& aName,
149 std::function<PCB_IO*(void)> aCreateFunc )
150 {
151 PLUGIN_REGISTRY::Instance()->Register( aType, aName, aCreateFunc );
152 }
153 };
154
155
165 static PCB_IO* PluginFind( PCB_FILE_T aFileType );
166
170 static const wxString ShowType( PCB_FILE_T aFileType );
171
175 static PCB_FILE_T EnumFromStr( const wxString& aFileType );
176
180 static PCB_FILE_T FindPluginTypeFromBoardPath( const wxString& aFileName, int aCtl = 0 );
181
185 static PCB_FILE_T GuessPluginTypeFromLibPath( const wxString& aLibPath, int aCtl = 0 );
186
206 static BOARD* Load( PCB_FILE_T aFileType, const wxString& aFileName,
207 BOARD* aAppendToMe = nullptr, const std::map<std::string, UTF8>* aProperties = nullptr,
208 PROJECT* aProject = nullptr,
209 PROGRESS_REPORTER* aProgressReporter = nullptr );
210
230 static void Save( PCB_FILE_T aFileType, const wxString& aFileName, BOARD* aBoard,
231 const std::map<std::string, UTF8>* aProperties = nullptr );
232
236 static bool ConvertLibrary( std::map<std::string, UTF8>* aOldFileProps, const wxString& aOldFilePath,
237 const wxString& aNewFilePath, REPORTER* aReporter );
238};
239
240#endif // PCB_IO_MGR_H_
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
Definition: io_mgr.h:37
Hold a list of available plugins, created using a singleton REGISTER_PLUGIN object.
Definition: pcb_io_mgr.h:85
PCB_IO * Create(PCB_FILE_T aFileType) const
Definition: pcb_io_mgr.h:115
const std::vector< ENTRY > & AllPlugins() const
Definition: pcb_io_mgr.h:128
void Register(PCB_FILE_T aType, const wxString &aName, std::function< PCB_IO *(void)> aCreateFunc)
Definition: pcb_io_mgr.h:105
static PLUGIN_REGISTRY * Instance()
Definition: pcb_io_mgr.h:94
std::vector< ENTRY > m_plugins
Definition: pcb_io_mgr.h:134
A factory which returns an instance of a #PLUGIN.
Definition: pcb_io_mgr.h:48
static PCB_IO * PluginFind(PCB_FILE_T aFileType)
Return a #PLUGIN which the caller can use to import, export, save, or load design documents.
Definition: pcb_io_mgr.cpp:69
static BOARD * Load(PCB_FILE_T aFileType, const wxString &aFileName, BOARD *aAppendToMe=nullptr, 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...
Definition: pcb_io_mgr.cpp:160
static PCB_FILE_T EnumFromStr(const wxString &aFileType)
Return the PCB_FILE_T from the corresponding plugin type name: "kicad", "legacy", etc.
Definition: pcb_io_mgr.cpp:94
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:56
@ FILE_TYPE_NONE
Definition: pcb_io_mgr.h:77
@ KICAD_SEXP
S-expression Pcbnew file format.
Definition: pcb_io_mgr.h:58
@ GEDA_PCB
Geda PCB file formats.
Definition: pcb_io_mgr.h:68
@ ALTIUM_DESIGNER
Definition: pcb_io_mgr.h:62
@ LEGACY
Legacy Pcbnew file formats prior to s-expression.
Definition: pcb_io_mgr.h:59
@ SOLIDWORKS_PCB
Definition: pcb_io_mgr.h:70
@ ALTIUM_CIRCUIT_MAKER
Definition: pcb_io_mgr.h:60
@ ALTIUM_CIRCUIT_STUDIO
Definition: pcb_io_mgr.h:61
@ CADSTAR_PCB_ARCHIVE
Definition: pcb_io_mgr.h:63
@ PCB_FILE_UNKNOWN
0 is not a legal menu id on Mac
Definition: pcb_io_mgr.h:57
static bool ConvertLibrary(std::map< std::string, UTF8 > *aOldFileProps, const wxString &aOldFilePath, const wxString &aNewFilePath, REPORTER *aReporter)
Convert a schematic symbol library to the latest KiCad format.
Definition: pcb_io_mgr.cpp:191
static PCB_FILE_T FindPluginTypeFromBoardPath(const wxString &aFileName, int aCtl=0)
Return a plugin type given a path for a board file.
Definition: pcb_io_mgr.cpp:112
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,...
Definition: pcb_io_mgr.cpp:176
static PCB_FILE_T GuessPluginTypeFromLibPath(const wxString &aLibPath, int aCtl=0)
Return a plugin type given a footprint library's libPath.
Definition: pcb_io_mgr.cpp:136
static const wxString ShowType(PCB_FILE_T aFileType)
Return a brief name for a plugin given aFileType enum.
Definition: pcb_io_mgr.cpp:78
A base class that BOARD loading and saving plugins should derive from.
Definition: pcb_io.h:71
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:64
A pure virtual class used to derive REPORTER objects from.
Definition: reporter.h:72
Some functions to handle hotkeys in KiCad.
std::function< PCB_IO *(void)> m_createFunc
Definition: pcb_io_mgr.h:90
Register a plugin.
Definition: pcb_io_mgr.h:147
REGISTER_PLUGIN(PCB_FILE_T aType, const wxString &aName, std::function< PCB_IO *(void)> aCreateFunc)
Definition: pcb_io_mgr.h:148