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