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 
47 BOARD* PLUGIN::Load( const wxString& aFileName, BOARD* aAppendToMe, const PROPERTIES* aProperties )
48 {
49  not_implemented( this, __FUNCTION__ );
50  return NULL;
51 }
52 
53 
54 void PLUGIN::Save( const wxString& aFileName, BOARD* aBoard, const PROPERTIES* aProperties )
55 {
56  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
57  not_implemented( this, __FUNCTION__ );
58 }
59 
60 
61 void PLUGIN::FootprintEnumerate( wxArrayString& aFootprintNames, const wxString& aLibraryPath,
62  const PROPERTIES* aProperties )
63 {
64  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
65  not_implemented( this, __FUNCTION__ );
66 }
67 
68 
69 void PLUGIN::PrefetchLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
70 {
71  (void) aLibraryPath;
72  (void) aProperties;
73 }
74 
75 
76 MODULE* PLUGIN::LoadEnumeratedFootprint( const wxString& aLibraryPath,
77  const wxString& aFootprintName,
78  const PROPERTIES* aProperties )
79 {
80  // default implementation
81  return FootprintLoad( aLibraryPath, aFootprintName, aProperties );
82 }
83 
84 
85 MODULE* PLUGIN::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
86  const PROPERTIES* aProperties )
87 {
88  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
89  not_implemented( this, __FUNCTION__ );
90  return NULL;
91 }
92 
93 
94 void PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties )
95 {
96  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
97  not_implemented( this, __FUNCTION__ );
98 }
99 
100 
101 void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties )
102 {
103  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
104  not_implemented( this, __FUNCTION__ );
105 }
106 
107 
108 void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
109 {
110  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
111  not_implemented( this, __FUNCTION__ );
112 }
113 
114 
115 bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
116 {
117  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
118  not_implemented( this, __FUNCTION__ );
119  return false;
120 }
121 
122 
123 bool PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
124 {
125  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
126  not_implemented( this, __FUNCTION__ );
127  return false;
128 }
129 
130 
131 void PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
132 {
133  // disable all these in another couple of months, after everyone has seen them:
134 #if 1
135  (*aListToAppendTo)["debug_level"] = UTF8( _(
136  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
137  ));
138 
139  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
140  "Regular expression <b>footprint name</b> filter."
141  ));
142 
143  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
144  "Enable transaction logging. The mere presence of this option turns on the "
145  "logging, no need to set a Value."
146  ));
147 
148  (*aListToAppendTo)["username"] = UTF8( _(
149  "User name for <b>login</b> to some special library server."
150  ));
151 
152  (*aListToAppendTo)["password"] = UTF8( _(
153  "Password for <b>login</b> to some special library server."
154  ));
155 #endif
156 
157 #if 1
158  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
159  // if and when implemented.
160  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
161  "Enter the python module which implements the PLUGIN::Footprint*() functions."
162  ));
163 #endif
164 }
165 
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
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:54
virtual void FootprintEnumerate(wxArrayString &aFootprintNames, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Return a list of footprint names contained within the library at aLibraryPath.
Definition: plugin.cpp:61
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:69
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:94
Class 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:123
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:85
virtual bool FootprintLibDelete(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibDelete deletes an existing footprint library and returns true, or if library does not exist returns false, or throws an exception if library exists but is read only or cannot be deleted for some other reason.
Definition: plugin.cpp:115
#define FMT_UNIMPLEMENTED
Definition: plugin.cpp:29
virtual const wxString PluginName() const =0
Function PluginName returns a brief hard coded name for this PLUGIN.
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
virtual MODULE * LoadEnumeratedFootprint(const wxString &aLibraryPath, const wxString &aFootprintName, const PROPERTIES *aProperties=NULL)
Function LoadEnumeratedFootprint a version of FootprintLoad() for use after FootprintEnumerate() for ...
Definition: plugin.cpp:76
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:169
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:266
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:101
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:108
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:131
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
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:47