KiCad PCB EDA Suite
plugin.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-2020 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 <io_mgr.h>
26#include <string_utf8_map.h>
27#include <wx/translation.h>
28
29
30#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
31
38static void not_implemented( PLUGIN* aPlugin, const char* aCaller )
39{
41 aPlugin->PluginName(),
42 wxString::FromUTF8( aCaller ) ) );
43}
44
45
46BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const STRING_UTF8_MAP* aProperties,
47 PROJECT* aProject, PROGRESS_REPORTER* aProgressReporter )
48{
49 not_implemented( this, __FUNCTION__ );
50 return nullptr;
51}
52
53
55{
56 not_implemented( this, __FUNCTION__ );
57 return std::vector<FOOTPRINT*>();
58}
59
60void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const STRING_UTF8_MAP* aProperties )
61{
62 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
63 not_implemented( this, __FUNCTION__ );
64}
65
66
67void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
68 bool aBestEfforts, const STRING_UTF8_MAP* aProperties )
69{
70 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
71 not_implemented( this, __FUNCTION__ );
72}
73
74
75void PLUGIN::PrefetchLib( const wxString&, const STRING_UTF8_MAP* )
76{
77}
78
79
80const FOOTPRINT* PLUGIN::GetEnumeratedFootprint( const wxString& aLibraryPath,
81 const wxString& aFootprintName,
82 const STRING_UTF8_MAP* aProperties )
83{
84 // default implementation
85 return FootprintLoad( aLibraryPath, aFootprintName, false, aProperties );
86}
87
88
89bool PLUGIN::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
90 const STRING_UTF8_MAP* aProperties )
91{
92 // default implementation
93 return FootprintLoad( aLibraryPath, aFootprintName, true, aProperties ) != nullptr;
94}
95
96
97FOOTPRINT* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
98 bool aKeepUUID, const STRING_UTF8_MAP* aProperties )
99{
100 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
101 not_implemented( this, __FUNCTION__ );
102 return nullptr;
103}
104
105
106void PLUGIN::FootprintSave( const wxString& aLibraryPath, const FOOTPRINT* aFootprint,
107 const STRING_UTF8_MAP* aProperties )
108{
109 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
110 not_implemented( this, __FUNCTION__ );
111}
112
113
114void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
115 const STRING_UTF8_MAP* aProperties )
116{
117 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
118 not_implemented( this, __FUNCTION__ );
119}
120
121
122void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
123{
124 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
125 not_implemented( this, __FUNCTION__ );
126}
127
128
129bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
130{
131 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
132 not_implemented( this, __FUNCTION__ );
133 return false;
134}
135
136
137bool PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
138{
139 // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
140 not_implemented( this, __FUNCTION__ );
141 return false;
142}
143
144
145void PLUGIN::FootprintLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const
146{
147 // disable all these in another couple of months, after everyone has seen them:
148#if 1
149 (*aListToAppendTo)["debug_level"] = UTF8( _( "Enable <b>debug</b> logging for Footprint*() "
150 "functions in this PLUGIN." ) );
151
152 (*aListToAppendTo)["read_filter_regex"] = UTF8( _( "Regular expression <b>footprint name</b> "
153 "filter." ) );
154
155 (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _( "Enable transaction logging. The "
156 "mere presence of this option "
157 "turns on the logging, no need to "
158 "set a Value." ) );
159
160 (*aListToAppendTo)["username"] = UTF8( _( "User name for <b>login</b> to some special library "
161 "server." ) );
162
163 (*aListToAppendTo)["password"] = UTF8( _( "Password for <b>login</b> to some special library "
164 "server." ) );
165#endif
166
167#if 1
168 // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
169 // if and when implemented.
170 (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _( "Enter the python module which "
171 "implements the PLUGIN::Footprint*() "
172 "functions." ) );
173#endif
174}
175
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
A base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:270
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: plugin.cpp:80
virtual void FootprintLibCreate(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty footprint library at aLibraryPath empty.
Definition: plugin.cpp:122
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing footprint library and returns true, or if library does not exist returns false,...
Definition: plugin.cpp:129
virtual void Save(const wxString &aFileName, BOARD *aBoard, const STRING_UTF8_MAP *aProperties=nullptr)
Write aBoard to a storage file in a format that this PLUGIN implementation knows about or it can be u...
Definition: plugin.cpp:60
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const STRING_UTF8_MAP *aProperties=nullptr, PROJECT *aProject=nullptr, PROGRESS_REPORTER *aProgressReporter=nullptr)
Load information from some input file format that this PLUGIN implementation knows about into either ...
Definition: plugin.cpp:46
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: plugin.cpp:106
virtual std::vector< FOOTPRINT * > GetImportedCachedLibraryFootprints()
Return a container with the cached library footprints generated in the last call to Load.
Definition: plugin.cpp:54
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete aFootprintName from the library at aLibraryPath.
Definition: plugin.cpp:114
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const STRING_UTF8_MAP *aProperties=nullptr)
Check for the existence of a footprint.
Definition: plugin.cpp:89
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 PL...
Definition: plugin.cpp:97
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: plugin.cpp:137
virtual const wxString PluginName() const =0
Return a brief hard coded name for this PLUGIN.
virtual void FootprintLibOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: plugin.cpp:145
virtual void PrefetchLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:75
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: plugin.cpp:67
A progress reporter interface for use in multi-threaded environments.
Container for project specific data.
Definition: project.h:63
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:71
#define _(s)
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Throw an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38
#define FMT_UNIMPLEMENTED
Definition: plugin.cpp:30
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200