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 wxArrayString PLUGIN::FootprintEnumerate( const wxString& aLibraryPath, 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  return wxArrayString();
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::FootprintLoad( const wxString& aLibraryPath, const wxString& aFootprintName,
77  const PROPERTIES* aProperties )
78 {
79  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
80  not_implemented( this, __FUNCTION__ );
81  return NULL;
82 }
83 
84 
85 void PLUGIN::FootprintSave( const wxString& aLibraryPath, const MODULE* aFootprint, const PROPERTIES* aProperties )
86 {
87  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
88  not_implemented( this, __FUNCTION__ );
89 }
90 
91 
92 void PLUGIN::FootprintDelete( const wxString& aLibraryPath, const wxString& aFootprintName, const PROPERTIES* aProperties )
93 {
94  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
95  not_implemented( this, __FUNCTION__ );
96 }
97 
98 
99 void PLUGIN::FootprintLibCreate( const wxString& aLibraryPath, const PROPERTIES* aProperties )
100 {
101  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
102  not_implemented( this, __FUNCTION__ );
103 }
104 
105 
106 bool PLUGIN::FootprintLibDelete( const wxString& aLibraryPath, const PROPERTIES* aProperties )
107 {
108  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
109  not_implemented( this, __FUNCTION__ );
110  return false;
111 }
112 
113 
114 bool PLUGIN::IsFootprintLibWritable( const wxString& aLibraryPath )
115 {
116  // not pure virtual so that plugins only have to implement subset of the PLUGIN interface.
117  not_implemented( this, __FUNCTION__ );
118  return false;
119 }
120 
121 
122 void PLUGIN::FootprintLibOptions( PROPERTIES* aListToAppendTo ) const
123 {
124  // disable all these in another couple of months, after everyone has seen them:
125 #if 1
126  (*aListToAppendTo)["debug_level"] = UTF8( _(
127  "Enable <b>debug</b> logging for Footprint*() functions in this PLUGIN."
128  ));
129 
130  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
131  "Regular expression <b>footprint name</b> filter."
132  ));
133 
134  (*aListToAppendTo)["enable_transaction_logging"] = UTF8( _(
135  "Enable transaction logging. The mere presence of this option turns on the "
136  "logging, no need to set a Value."
137  ));
138 
139  (*aListToAppendTo)["username"] = UTF8( _(
140  "User name for <b>login</b> to some special library server."
141  ));
142 
143  (*aListToAppendTo)["password"] = UTF8( _(
144  "Password for <b>login</b> to some special library server."
145  ));
146 #endif
147 
148 #if 1
149  // Suitable for a C++ to python PLUGIN::Footprint*() adapter, move it to the adapter
150  // if and when implemented.
151  (*aListToAppendTo)["python_footprint_plugin"] = UTF8( _(
152  "Enter the python module which implements the PLUGIN::Footprint*() functions."
153  ));
154 #endif
155 }
156 
Class UTF8 is an 8 bit std::string that is assuredly encoded in UTF8, and supplies special conversion...
Definition: utf8.h:53
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
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:85
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
virtual wxArrayString FootprintEnumerate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintEnumerate returns a list of footprint names contained within the library at aLibrar...
Definition: plugin.cpp:61
virtual bool IsFootprintLibWritable(const wxString &aLibraryPath)
Function IsFootprintLibWritable returns true iff the library at aLibraryPath is writable.
Definition: plugin.cpp:114
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:76
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:106
#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(x)
Definition: utf8.cpp:60
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
Class BOARD holds information pertinent to a Pcbnew printed circuit board.
Definition: class_board.h:166
Class PLUGIN is a base class that BOARD loading and saving plugins should derive from.
Definition: io_mgr.h:193
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:92
virtual void FootprintLibCreate(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Function FootprintLibCreate creates a new empty footprint library at aLibraryPath empty...
Definition: plugin.cpp:99
virtual void FootprintLibOptions(PROPERTIES *aListToAppendTo) const
Function FootprintLibOptions appends supported PLUGIN options to aListToAppenTo along with internatio...
Definition: plugin.cpp:122
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