KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcb_io.cpp
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-2024 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#include <unordered_set>
26#include <pcb_io/pcb_io.h>
27#include <pcb_io/pcb_io_mgr.h>
28#include <ki_exception.h>
29#include <wx/log.h>
30#include <wx/filename.h>
31#include <wx/translation.h>
32#include <wx/dir.h>
33
34
35#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
36#define NOT_IMPLEMENTED( aCaller ) \
37 THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, \
38 GetName(), \
39 wxString::FromUTF8( aCaller ) ) );
40
41
42bool PCB_IO::CanReadBoard( const wxString& aFileName ) const
43{
44 const std::vector<std::string>& exts = GetBoardFileDesc().m_FileExtensions;
45
46 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
47
48 for( const std::string& ext : exts )
49 {
50 if( fileExt == wxString( ext ).Lower() )
51 return true;
52 }
53
54 return false;
55}
56
57
58bool PCB_IO::CanReadFootprint( const wxString& aFileName ) const
59{
60 const std::vector<std::string>& exts = GetLibraryFileDesc().m_FileExtensions;
61
62 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
63
64 for( const std::string& ext : exts )
65 {
66 if( fileExt == wxString( ext ).Lower() )
67 return true;
68 }
69
70 return false;
71}
72
73
74BOARD* PCB_IO::LoadBoard( const wxString& aFileName, BOARD* aAppendToMe,
75 const std::map<std::string, UTF8>* aProperties, PROJECT* aProject )
76{
77 NOT_IMPLEMENTED( __FUNCTION__ );
78}
79
80
82{
83 NOT_IMPLEMENTED( __FUNCTION__ );
84}
85
86
87void PCB_IO::SaveBoard( const wxString& aFileName, BOARD* aBoard,
88 const std::map<std::string, UTF8>* aProperties )
89{
90 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
91 NOT_IMPLEMENTED( __FUNCTION__ );
92}
93
94
95void PCB_IO::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
96 bool aBestEfforts, const std::map<std::string, UTF8>* aProperties )
97{
98 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
99 NOT_IMPLEMENTED( __FUNCTION__ );
100}
101
102
103void PCB_IO::PrefetchLib( const wxString&, const std::map<std::string, UTF8>* )
104{
105}
106
107
108FOOTPRINT* PCB_IO::ImportFootprint( const wxString& aFootprintPath, wxString& aFootprintNameOut,
109 const std::map<std::string, UTF8>* aProperties )
110{
111 wxArrayString footprintNames;
112
113 FootprintEnumerate( footprintNames, aFootprintPath, true, aProperties );
114
115 if( footprintNames.empty() )
116 return nullptr;
117
118 if( footprintNames.size() > 1 )
119 {
120 wxLogWarning( _( "Selected file contains multiple footprints. Only the first one will be "
121 "imported.\nTo load all footprints, add it as a library using Preferences "
122 "-> Manage Footprint "
123 "Libraries..." ) );
124 }
125
126 aFootprintNameOut = footprintNames.front();
127
128 return FootprintLoad( aFootprintPath, aFootprintNameOut, false, aProperties );
129}
130
131
132const FOOTPRINT* PCB_IO::GetEnumeratedFootprint( const wxString& aLibraryPath,
133 const wxString& aFootprintName,
134 const std::map<std::string, UTF8>* aProperties )
135{
136 // default implementation
137 return FootprintLoad( aLibraryPath, aFootprintName, false, aProperties );
138}
139
140
141bool PCB_IO::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
142 const std::map<std::string, UTF8>* aProperties )
143{
144 // default implementation
145 return FootprintLoad( aLibraryPath, aFootprintName, true, aProperties ) != nullptr;
146}
147
148
149FOOTPRINT* PCB_IO::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
150 bool aKeepUUID, const std::map<std::string, UTF8>* aProperties )
151{
152 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
153 NOT_IMPLEMENTED( __FUNCTION__ );
154}
155
156
157void PCB_IO::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
158 const std::map<std::string, UTF8>* aProperties )
159{
160 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
161 NOT_IMPLEMENTED( __FUNCTION__ );
162}
163
164
165void PCB_IO::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
166 const std::map<std::string, UTF8>* aProperties )
167{
168 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
169 NOT_IMPLEMENTED( __FUNCTION__ );
170}
171
172
173void PCB_IO::GetLibraryOptions( std::map<std::string, UTF8>* aListToAppendTo ) const
174{
175 // Get base options first
176 IO_BASE::GetLibraryOptions( aListToAppendTo );
177
178 // disable all these in another couple of months, after everyone has seen them:
179#if 1
180 (*aListToAppendTo)["debug_level"] = UTF8( _( "Enable <b>debug</b> logging for Footprint*() "
181 "functions in this PCB_IO." ) );
182
183 (*aListToAppendTo)["read_filter_regex"] = UTF8( _( "Regular expression <b>footprint name</b> "
184 "filter." ) );
185
186 (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _( "Enable transaction logging. The "
187 "mere presence of this option "
188 "turns on the logging, no need to "
189 "set a Value." ) );
190
191 (*aListToAppendTo)["username"] = UTF8( _( "User name for <b>login</b> to some special library "
192 "server." ) );
193
194 (*aListToAppendTo)["password"] = UTF8( _( "Password for <b>login</b> to some special library "
195 "server." ) );
196#endif
197
198#if 1
199 // Suitable for a C++ to python PCB_IO::Footprint*() adapter, move it to the adapter
200 // if and when implemented.
201 (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _( "Enter the python module which "
202 "implements the PCB_IO::Footprint*() "
203 "functions." ) );
204#endif
205}
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:290
virtual const IO_FILE_DESC GetLibraryFileDesc() const
Get the descriptor for the individual library elements that this IO plugin operates on.
Definition: io_base.h:106
virtual void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const
Append supported IO options to aListToAppenTo along with internationalized descriptions.
Definition: io_base.cpp:63
virtual bool CanReadFootprint(const wxString &aFileName) const
Checks if this PCB_IO can read a footprint from specified file or directory.
Definition: pcb_io.cpp:58
virtual bool CanReadBoard(const wxString &aFileName) const
Checks if this PCB_IO can read the specified board file.
Definition: pcb_io.cpp:42
virtual FOOTPRINT * ImportFootprint(const wxString &aFootprintPath, wxString &aFootprintNameOut, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a single footprint from aFootprintPath and put its name in aFootprintNameOut.
Definition: pcb_io.cpp:108
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const std::map< std::string, UTF8 > *aProperties=nullptr)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: pcb_io.cpp:95
virtual void SaveBoard(const wxString &aFileName, BOARD *aBoard, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aBoard to a storage file in a format that this PCB_IO implementation knows about or it can be u...
Definition: pcb_io.cpp:87
virtual void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const override
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: pcb_io.cpp:173
virtual void PrefetchLib(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr)
If possible, prefetches the specified library (e.g.
Definition: pcb_io.cpp:103
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Check for the existence of a footprint.
Definition: pcb_io.cpp:141
virtual std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints()
Return a container with the cached library footprints generated in the last call to Load.
Definition: pcb_io.cpp:81
virtual BOARD * LoadBoard(const wxString &aFileName, BOARD *aAppendToMe, const std::map< std::string, UTF8 > *aProperties=nullptr, PROJECT *aProject=nullptr)
Load information from some input file format that this PCB_IO implementation knows about into either ...
Definition: pcb_io.cpp:74
virtual const FOOTPRINT * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr)
A version of FootprintLoad() for use after FootprintEnumerate() for more efficient cache management.
Definition: pcb_io.cpp:132
virtual const IO_BASE::IO_FILE_DESC GetBoardFileDesc() const
Returns board file description for the PCB_IO.
Definition: pcb_io.h:76
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Delete aFootprintName from the library at aLibraryPath.
Definition: pcb_io.cpp:165
virtual FOOTPRINT * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, bool aKeepUUID=false, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a footprint having aFootprintName from the aLibraryPath containing a library format that this PC...
Definition: pcb_io.cpp:149
virtual void FootprintSave(const wxString &aLibraryPath, const FOOTPRINT *aFootprint, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aFootprint to an existing library located at aLibraryPath.
Definition: pcb_io.cpp:157
Container for project specific data.
Definition: project.h:64
An 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to and fro...
Definition: utf8.h:72
#define _(s)
#define NOT_IMPLEMENTED(aCaller)
Definition: io_base.cpp:34
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition: io_base.h:45