KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io.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-2024 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 <unordered_set>
24
25#include <ki_exception.h>
26#include <sch_io/sch_io.h>
27#include <sch_io/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 IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
42}
43
44
45bool SCH_IO::CanReadSchematicFile( const wxString& aFileName ) const
46{
47 const std::vector<std::string>& exts = GetSchematicFileDesc().m_FileExtensions;
48
49 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
50
51 for( const std::string& ext : exts )
52 {
53 if( fileExt == wxString( ext ).Lower() )
54 return true;
55 }
56
57 return false;
58}
59
60
61void SCH_IO::SaveLibrary( const wxString& aFileName, const std::map<std::string, UTF8>* aProperties )
62{
63 NOT_IMPLEMENTED( __FUNCTION__ );
64}
65
66
67SCH_SHEET* SCH_IO::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
68 SCH_SHEET* aAppendToMe, const std::map<std::string, UTF8>* aProperties )
69{
70 NOT_IMPLEMENTED( __FUNCTION__ );
71}
72
73
74void SCH_IO::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
75 const std::map<std::string, UTF8>* aProperties )
76{
77 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
78 NOT_IMPLEMENTED( __FUNCTION__ );
79}
80
81
82void SCH_IO::EnumerateSymbolLib( wxArrayString& aAliasNameList,
83 const wxString& aLibraryPath,
84 const std::map<std::string, UTF8>* aProperties )
85{
86 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
87 NOT_IMPLEMENTED( __FUNCTION__ );
88}
89
90
91void SCH_IO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
92 const wxString& aLibraryPath,
93 const std::map<std::string, UTF8>* aProperties )
94{
95 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
96 NOT_IMPLEMENTED( __FUNCTION__ );
97}
98
99
100LIB_SYMBOL* SCH_IO::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
101 const std::map<std::string, UTF8>* aProperties )
102{
103 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
104 NOT_IMPLEMENTED( __FUNCTION__ );
105}
106
107
108void SCH_IO::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
109 const std::map<std::string, UTF8>* aProperties )
110{
111 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
112 NOT_IMPLEMENTED( __FUNCTION__ );
113}
114
115
116void SCH_IO::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
117 const std::map<std::string, UTF8>* aProperties )
118{
119 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
120 NOT_IMPLEMENTED( __FUNCTION__ );
121}
122
123
124void SCH_IO::GetLibraryOptions( std::map<std::string, UTF8>* aListToAppendTo ) const
125{
126 // Get base options first
127 IO_BASE::GetLibraryOptions( aListToAppendTo );
128
129 // Empty for most plugins
130 //
131 // To add a new option override and use example code below:
132 //
133 //(*aListToAppendTo)["new_option_name"] = UTF8( _(
134 // "A nice descrtiption with possibility for <b>bold</b> and other formatting."
135 // ) );
136}
137
138
139const wxString& SCH_IO::GetError() const
140{
141 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
142 NOT_IMPLEMENTED( __FUNCTION__ );
143}
virtual void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const
Append supported IO options to aListToAppenTo along with internationalized descriptions.
Definition: io_base.cpp:63
Define a library symbol object.
Definition: lib_symbol.h:78
Holds all the data relating to one schematic.
Definition: schematic.h:76
virtual void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr)
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
Definition: sch_io.cpp:82
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
Definition: sch_io.cpp:45
virtual SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load information from some input file format that this SCH_IO implementation knows about,...
Definition: sch_io.cpp:67
virtual void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
Definition: sch_io.cpp:108
virtual void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
Definition: sch_io.cpp:116
virtual void SaveLibrary(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Definition: sch_io.cpp:61
virtual LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aPartName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
Definition: sch_io.cpp:100
virtual void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const override
Append supported SCH_IO options to aListToAppenTo along with internationalized descriptions.
Definition: sch_io.cpp:124
virtual void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
Definition: sch_io.cpp:74
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_io.cpp:139
virtual const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const
Returns schematic file description for the SCH_IO.
Definition: sch_io.cpp:39
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
#define NOT_IMPLEMENTED(aCaller)
Definition: io_base.cpp:34
Container that describes file type info.
Definition: io_base.h:43
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition: io_base.h:45