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