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 <dick@softplc.com>
5  * Copyright (C) 2016-2017 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 <properties.h>
27 
28 
29 #define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
30 
38 static void not_implemented( PLUGIN* aPlugin, const char* aCaller )
39 {
41  aPlugin->PluginName().GetData(),
42  wxString::FromUTF8( aCaller ).GetData() ) );
43 }
44 
45 
46 BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
47 {
48  not_implemented( this, __FUNCTION__ );
49  return NULL;
50 }
51 
52 
53 void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
54 {
55  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
56  not_implemented( this, __FUNCTION__ );
57 }
58 
59 
60 void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
61  bool aBestEfforts, const PROPERTIES* aProperties )
62 {
63  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
64  not_implemented( this, __FUNCTION__ );
65 }
66 
67 
68 void PLUGIN::PrefetchLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
69 {
70  (void) aLibraryPath;
71  (void) aProperties;
72 }
73 
74 
75 const MODULE* PLUGIN::GetEnumeratedFootprint( const wxString& aLibraryPath,
76  const wxString& aFootprintName,
77  const PROPERTIES* aProperties )
78 {
79  // default implementation
80  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
81 }
82 
83 
84 bool PLUGIN::FootprintExists( const wxString& aLibraryPath, const wxString& aFootprintName,
85  const PROPERTIES* aProperties )
86 {
87  // default implementation
88  return FootprintLoad( aLibraryPath, aFootprintName, aProperties ) != nullptr;
89 }
90 
91 
92 MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
93  const PROPERTIES* aProperties )
94 {
95  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
96  not_implemented( this, __FUNCTION__ );
97  return NULL;
98 }
99 
100 
101 void PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint,
102  const PROPERTIES* aProperties )
103 {
104  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
105  not_implemented( this, __FUNCTION__ );
106 }
107 
108 
109 void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName,
110  const PROPERTIES* aProperties )
111 {
112  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
113  not_implemented( this, __FUNCTION__ );
114 }
115 
116 
117 void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
118 {
119  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
120  not_implemented( this, __FUNCTION__ );
121 }
122 
123 
124 bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
125 {
126  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
127  not_implemented( this, __FUNCTION__ );
128  return false;
129 }
130 
131 
132 bool PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
133 {
134  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
135  not_implemented( this, __FUNCTION__ );
136  return false;
137 }
138 
139 
140 void PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
141 {
142  // disable all these in another couple of months, after everyone has seen them:
143 #if 1
144  (*aListToAppendTo)["debug_level"] = UTF8( _(
145  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
146  ));
147 
148  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
149  "Regular expression <b>footprint name</b> filter."
150  ));
151 
152  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
153  "Enable transaction logging. The mere presence of this option turns on the "
154  "logging, no need to set a Value."
155  ));
156 
157  (*aListToAppendTo)["username"] = UTF8( _(
158  "User name for <b>login</b> to some special library server."
159  ));
160 
161  (*aListToAppendTo)["password"] = UTF8( _(
162  "Password for <b>login</b> to some special library server."
163  ));
164 #endif
165 
166 #if 1
167  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
168  // if and when implemented.
169  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
170  "Enter the python module which implements the PLUGIN::Footprint*() functions."
171  ));
172 #endif
173 }
174 
UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion support to...
Definition: utf8.h:73
virtual void Save(const wxString &aFileName, BOARD *aBoard, const PROPERTIES *aProperties=NULL)
Function Save will write aBoard to a storage file in a format that this PLUGIN implementation knows a...
Definition: plugin.cpp:53
static void not_implemented(PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: plugin.cpp:38
virtual void PrefetchLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function PrefetchLib If possible, prefetches the specified library (e.g.
Definition: plugin.cpp:68
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, bool aBestEfforts, const PROPERTIES *aProperties=NULL)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: plugin.cpp:60
virtual void FootprintSave(const wxString &aLibraryPath, const MODULE *aFootprint, const PROPERTIES *aProperties=NULL)
Function FootprintSave will write aModule to an existing library located at aLibraryPath.
Definition: plugin.cpp:101
virtual const MODULE * GetEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function GetEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for m...
Definition: plugin.cpp:75
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:140
PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:132
virtual MODULE * FootprintLoad(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintLoad loads a footprint having aFootprintName from the aLibraryPath containing a lib...
Definition: plugin.cpp:92
#define NULL
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true,...
Definition: plugin.cpp:124
#define FMT_UNIMPLEMENTED
Definition: plugin.cpp:29
virtual const wxString PluginName() const =0
Function PluginName returns a brief hard coded name for this PLUGIN.
#define THROW_IO_ERROR(msg)
virtual bool FootprintExists(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintExists check for the existence of a footprint.
Definition: plugin.cpp:84
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:160
#define _(s)
Definition: 3d_actions.cpp:31
PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:271
virtual void FootprintDelete(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function FootprintDelete deletes aFootprintName from the library at aLibraryPath.
Definition: plugin.cpp:109
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty.
Definition: plugin.cpp:117
virtual BOARD * Load(const wxString &aFileName, BOARD *aAppendToMe, const PROPERTIES *aProperties=NULL)
Function Load loads information from some input file format that this PLUGIN implementation knows abo...
Definition: plugin.cpp:46