KiCad PCB EDA Suite
sch_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) 2016 CERN
5  * Copyright (C) 2016-2017 KiCad Developers, see AUTHORS.txt for contributors.
6  *
7  * @author Wayne Stambaugh <stambaughw@gmail.com>
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License along
20  * with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #include <properties.h>
24 
25 #include <sch_io_mgr.h>
26 
27 #define FMT_UNIMPLEMENTED _( "Plugin \"%s\" does not implement the \"%s\" function." )
28 
36 static void not_implemented( const SCH_PLUGIN* aPlugin, const char* aCaller )
37 {
39  aPlugin->GetName().GetData(),
40  wxString::FromUTF8( aCaller ).GetData() ) );
41 }
42 
43 
44 void SCH_PLUGIN::SaveLibrary( const wxString& aFileName, const PROPERTIES* aProperties )
45 {
46  not_implemented( this, __FUNCTION__ );
47 }
48 
49 
50 SCH_SHEET* SCH_PLUGIN::Load( const wxString& aFileName, KIWAY* aKiway, SCH_SHEET* aAppendToMe,
51  const PROPERTIES* aProperties )
52 {
53  not_implemented( this, __FUNCTION__ );
54  return NULL;
55 }
56 
57 
58 void SCH_PLUGIN::Save( const wxString& aFileName, SCH_SCREEN* aSchematic, KIWAY* aKiway,
59  const PROPERTIES* aProperties )
60 {
61  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
62  not_implemented( this, __FUNCTION__ );
63 }
64 
65 
66 void SCH_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList,
67  const wxString& aLibraryPath,
68  const PROPERTIES* aProperties )
69 {
70  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
71  not_implemented( this, __FUNCTION__ );
72 }
73 
74 
75 void SCH_PLUGIN::EnumerateSymbolLib( std::vector<LIB_ALIAS*>& aAliasList,
76  const wxString& aLibraryPath,
77  const PROPERTIES* aProperties )
78 {
79  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
80  not_implemented( this, __FUNCTION__ );
81 }
82 
83 
84 LIB_ALIAS* SCH_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
85  const PROPERTIES* aProperties )
86 {
87  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
88  not_implemented( this, __FUNCTION__ );
89  return NULL;
90 }
91 
92 
93 void SCH_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_PART* aSymbol,
94  const PROPERTIES* aProperties )
95 {
96  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
97  not_implemented( this, __FUNCTION__ );
98 }
99 
100 
101 void SCH_PLUGIN::DeleteAlias( const wxString& aLibraryPath, const wxString& aAliasName,
102  const PROPERTIES* aProperties )
103 {
104  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
105  not_implemented( this, __FUNCTION__ );
106 }
107 
108 
109 void SCH_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
110  const PROPERTIES* aProperties )
111 {
112  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
113  not_implemented( this, __FUNCTION__ );
114 }
115 
116 
117 void SCH_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
118 {
119  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
120  not_implemented( this, __FUNCTION__ );
121 }
122 
123 
124 bool SCH_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath, const PROPERTIES* aProperties )
125 {
126  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
127  not_implemented( this, __FUNCTION__ );
128  return false;
129 }
130 
131 
132 bool SCH_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
133 {
134  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
135  not_implemented( this, __FUNCTION__ );
136  return false;
137 }
138 
139 
140 void SCH_PLUGIN::SymbolLibOptions( 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 Symbol*() functions in this SCH_PLUGIN."
146  ) );
147 
148  (*aListToAppendTo)["read_filter_regex"] = UTF8( _(
149  "Regular expression <b>symbol 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 SCH_PLUGIN::Footprint*() adapter, move it to the adapter
168  // if and when implemented.
169  (*aListToAppendTo)["python_symbol_plugin"] = UTF8( _(
170  "Enter the python symbol which implements the SCH_PLUGIN::Symbol*() functions."
171  ) );
172 #endif
173 }
174 
175 
176 bool SCH_PLUGIN::CheckHeader( const wxString& aFileName )
177 {
178  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
179  not_implemented( this, __FUNCTION__ );
180  return false;
181 }
182 
183 
184 const wxString& SCH_PLUGIN::GetError() const
185 {
186  // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
187  not_implemented( this, __FUNCTION__ );
188  static wxString error;
189  return error;
190 }
Class UTF8 is an 8 bit string that is assuredly encoded in UTF8, and supplies special conversion supp...
Definition: utf8.h:73
virtual void CreateSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:117
Part library alias object definition.
virtual LIB_ALIAS * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Load a LIB_ALIAS object having aAliasName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:84
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:124
static void not_implemented(const SCH_PLUGIN *aPlugin, const char *aCaller)
Function not_implemented throws an IO_ERROR and complains of an API function not being implemented.
Definition: sch_plugin.cpp:36
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete the entire LIB_PART associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:109
virtual SCH_SHEET * Load(const wxString &aFileName, KIWAY *aKiway, SCH_SHEET *aAppendToMe=NULL, const PROPERTIES *aProperties=NULL)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:50
virtual void EnumerateSymbolLib(wxArrayString &aAliasNameList, const wxString &aLibraryPath, const PROPERTIES *aProperties=NULL)
Populate a list of LIB_PART alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:66
virtual const wxString GetName() const =0
Returns a brief hard coded name for this SCH_PLUGIN.
Class PROPERTIES is a name/value tuple with unique names and optional values.
Definition: properties.h:34
virtual bool CheckHeader(const wxString &aFileName)
Return true if the first line in aFileName begins with the expected header.
Definition: sch_plugin.cpp:176
#define FMT_UNIMPLEMENTED
Definition: sch_plugin.cpp:27
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:188
Define a library symbol object.
Class KIWAY is a minimalistic software bus for communications between various DLLs/DSOs (DSOs) within...
Definition: kiway.h:258
#define THROW_IO_ERROR(msg)
#define _(s)
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:209
virtual void Save(const wxString &aFileName, SCH_SCREEN *aSchematic, KIWAY *aKiway, const PROPERTIES *aProperties=NULL)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:58
virtual void SaveLibrary(const wxString &aFileName, const PROPERTIES *aProperties=NULL)
Definition: sch_plugin.cpp:44
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 const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:184
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:132
virtual void DeleteAlias(const wxString &aLibraryPath, const wxString &aAliasName, const PROPERTIES *aProperties=NULL)
Delete aAliasName from the library at aLibraryPath.
Definition: sch_plugin.cpp:101
virtual void SymbolLibOptions(PROPERTIES *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:140
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_PART *aSymbol, const PROPERTIES *aProperties=NULL)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:93