KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * @author Wayne Stambaugh <[email protected]>
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 <string_utf8_map.h>
24#include <unordered_set>
25
26#include <ki_exception.h>
27#include <sch_io_mgr.h>
28#include <wx/translation.h>
29#include <wx/filename.h>
30#include <wx/dir.h>
31
32#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
33#define NOT_IMPLEMENTED( aCaller ) \
34 THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, \
35 GetName().GetData(), \
36 wxString::FromUTF8( aCaller ).GetData() ) );
37
38
40{
41 return PLUGIN_FILE_DESC( wxEmptyString, {} );
42}
43
44
46{
47 return PLUGIN_FILE_DESC( wxEmptyString, {} );
48}
49
50
51bool SCH_PLUGIN::CanReadSchematicFile( const wxString& aFileName ) const
52{
53 const std::vector<std::string>& exts = GetSchematicFileDesc().m_FileExtensions;
54
55 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
56
57 for( const std::string& ext : exts )
58 {
59 if( fileExt == wxString( ext ).Lower() )
60 return true;
61 }
62
63 return false;
64}
65
66
67bool SCH_PLUGIN::CanReadLibrary( const wxString& aFileName ) const
68{
70
71 if( desc.m_IsFile )
72 {
73 const std::vector<std::string>& exts = desc.m_FileExtensions;
74
75 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
76
77 for( const std::string& ext : exts )
78 {
79 if( fileExt == wxString( ext ).Lower() )
80 return true;
81 }
82 }
83 else
84 {
85 wxDir dir( aFileName );
86
87 if( !dir.IsOpened() )
88 return false;
89
90 std::vector<std::string> exts = desc.m_ExtensionsInDir;
91 std::unordered_set<wxString> lowerExts;
92
93 for( const std::string& ext : exts )
94 lowerExts.emplace( wxString( ext ).MakeLower() );
95
96 wxString filenameStr;
97
98 bool cont = dir.GetFirst( &filenameStr, wxEmptyString, wxDIR_FILES | wxDIR_HIDDEN );
99 while( cont )
100 {
101 wxString ext = wxS( "" );
102
103 int idx = filenameStr.Find( '.', true );
104 if( idx != -1 )
105 ext = filenameStr.Mid( idx + 1 ).MakeLower();
106
107 if( lowerExts.count( ext ) )
108 return true;
109
110 cont = dir.GetNext( &filenameStr );
111 }
112 }
113
114 return false;
115}
116
117
118void SCH_PLUGIN::SaveLibrary( const wxString& aFileName, const STRING_UTF8_MAP* aProperties )
119{
120 NOT_IMPLEMENTED( __FUNCTION__ );
121}
122
123
124SCH_SHEET* SCH_PLUGIN::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
125 SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
126{
127 NOT_IMPLEMENTED( __FUNCTION__ );
128}
129
130
131void SCH_PLUGIN::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
132 const STRING_UTF8_MAP* aProperties )
133{
134 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
135 NOT_IMPLEMENTED( __FUNCTION__ );
136}
137
138
139void SCH_PLUGIN::EnumerateSymbolLib( wxArrayString& aAliasNameList,
140 const wxString& aLibraryPath,
141 const STRING_UTF8_MAP* aProperties )
142{
143 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
144 NOT_IMPLEMENTED( __FUNCTION__ );
145}
146
147
148void SCH_PLUGIN::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
149 const wxString& aLibraryPath,
150 const STRING_UTF8_MAP* aProperties )
151{
152 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
153 NOT_IMPLEMENTED( __FUNCTION__ );
154}
155
156
157LIB_SYMBOL* SCH_PLUGIN::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
158 const STRING_UTF8_MAP* aProperties )
159{
160 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
161 NOT_IMPLEMENTED( __FUNCTION__ );
162}
163
164
165void SCH_PLUGIN::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
166 const STRING_UTF8_MAP* aProperties )
167{
168 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
169 NOT_IMPLEMENTED( __FUNCTION__ );
170}
171
172
173void SCH_PLUGIN::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
174 const STRING_UTF8_MAP* aProperties )
175{
176 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
177 NOT_IMPLEMENTED( __FUNCTION__ );
178}
179
180
181void SCH_PLUGIN::CreateSymbolLib( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
182{
183 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
184 NOT_IMPLEMENTED( __FUNCTION__ );
185}
186
187
188bool SCH_PLUGIN::DeleteSymbolLib( const wxString& aLibraryPath, const STRING_UTF8_MAP* aProperties )
189{
190 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
191 NOT_IMPLEMENTED( __FUNCTION__ );
192}
193
194
195bool SCH_PLUGIN::IsSymbolLibWritable( const wxString& aLibraryPath )
196{
197 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
198 NOT_IMPLEMENTED( __FUNCTION__ );
199}
200
201
202void SCH_PLUGIN::SymbolLibOptions( STRING_UTF8_MAP* aListToAppendTo ) const
203{
204 // Empty for most plugins
205 //
206 // To add a new option override and use example code below:
207 //
208 //(*aListToAppendTo)["new_option_name"] = UTF8( _(
209 // "A nice descrtiption with possibility for <b>bold</b> and other formatting."
210 // ) );
211}
212
213
214const wxString& SCH_PLUGIN::GetError() const
215{
216 // not pure virtual so that plugins only have to implement subset of the SCH_PLUGIN interface.
217 NOT_IMPLEMENTED( __FUNCTION__ );
218}
Define a library symbol object.
Definition: lib_symbol.h:99
Holds all the data relating to one schematic.
Definition: schematic.h:75
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_plugin.cpp:139
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_plugin.cpp:165
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_plugin.cpp:173
virtual void SaveLibrary(const wxString &aFileName, const STRING_UTF8_MAP *aProperties=nullptr)
Definition: sch_plugin.cpp:118
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified schematic file.
Definition: sch_plugin.cpp:51
virtual void SymbolLibOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported SCH_PLUGIN options to aListToAppenTo along with internationalized descriptions.
Definition: sch_plugin.cpp:202
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const STRING_UTF8_MAP *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_plugin.cpp:157
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_plugin.cpp:214
virtual void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Create a new empty symbol library at aLibraryPath.
Definition: sch_plugin.cpp:181
virtual SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr)
Load information from some input file format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:124
virtual bool CanReadLibrary(const wxString &aFileName) const
Checks if this SCH_PLUGIN can read the specified symbol library file.
Definition: sch_plugin.cpp:67
virtual bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr)
Delete an existing symbol library and returns true if successful, or if library does not exist return...
Definition: sch_plugin.cpp:188
virtual void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_PLUGIN implementation knows about,...
Definition: sch_plugin.cpp:131
virtual const PLUGIN_FILE_DESC GetSchematicFileDesc() const
Returns schematic file description for the SCH_PLUGIN.
Definition: sch_plugin.cpp:39
virtual bool IsSymbolLibWritable(const wxString &aLibraryPath)
Return true if the library at aLibraryPath is writable.
Definition: sch_plugin.cpp:195
virtual const PLUGIN_FILE_DESC GetLibraryFileDesc() const
Returns symbol library description for the SCH_PLUGIN.
Definition: sch_plugin.cpp:45
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
A name/value tuple with unique names and optional values.
#define NOT_IMPLEMENTED(aCaller)
Definition: sch_plugin.cpp:33
Container that describes file type info.
std::vector< std::string > m_ExtensionsInDir
In case of folders: extensions of files inside.
bool m_IsFile
Whether the library is a folder or a file.
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.