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 <string_utf8_map.h>
24#include <unordered_set>
25
26#include <ki_exception.h>
27#include <sch_io/sch_io.h>
28#include <sch_io/sch_io_mgr.h>
29#include <wx/translation.h>
30#include <wx/filename.h>
31#include <wx/dir.h>
32
33#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
34#define NOT_IMPLEMENTED( aCaller ) \
35 THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, \
36 GetName().GetData(), \
37 wxString::FromUTF8( aCaller ).GetData() ) );
38
39
41{
42 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
43}
44
45
46bool SCH_IO::CanReadSchematicFile( const wxString& aFileName ) const
47{
48 const std::vector<std::string>& exts = GetSchematicFileDesc().m_FileExtensions;
49
50 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
51
52 for( const std::string& ext : exts )
53 {
54 if( fileExt == wxString( ext ).Lower() )
55 return true;
56 }
57
58 return false;
59}
60
61
62void SCH_IO::SaveLibrary( const wxString& aFileName, const STRING_UTF8_MAP* aProperties )
63{
64 NOT_IMPLEMENTED( __FUNCTION__ );
65}
66
67
68SCH_SHEET* SCH_IO::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
69 SCH_SHEET* aAppendToMe, const STRING_UTF8_MAP* aProperties )
70{
71 NOT_IMPLEMENTED( __FUNCTION__ );
72}
73
74
75void SCH_IO::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
76 const STRING_UTF8_MAP* aProperties )
77{
78 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
79 NOT_IMPLEMENTED( __FUNCTION__ );
80}
81
82
83void SCH_IO::EnumerateSymbolLib( wxArrayString& aAliasNameList,
84 const wxString& aLibraryPath,
85 const STRING_UTF8_MAP* aProperties )
86{
87 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
88 NOT_IMPLEMENTED( __FUNCTION__ );
89}
90
91
92void SCH_IO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
93 const wxString& aLibraryPath,
94 const STRING_UTF8_MAP* aProperties )
95{
96 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
97 NOT_IMPLEMENTED( __FUNCTION__ );
98}
99
100
101LIB_SYMBOL* SCH_IO::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
102 const STRING_UTF8_MAP* aProperties )
103{
104 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
105 NOT_IMPLEMENTED( __FUNCTION__ );
106}
107
108
109void SCH_IO::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
110 const STRING_UTF8_MAP* aProperties )
111{
112 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
113 NOT_IMPLEMENTED( __FUNCTION__ );
114}
115
116
117void SCH_IO::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
118 const STRING_UTF8_MAP* aProperties )
119{
120 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
121 NOT_IMPLEMENTED( __FUNCTION__ );
122}
123
124
125void SCH_IO::GetLibraryOptions( STRING_UTF8_MAP* aListToAppendTo ) const
126{
127 // Get base options first
128 IO_BASE::GetLibraryOptions( aListToAppendTo );
129
130 // Empty for most plugins
131 //
132 // To add a new option override and use example code below:
133 //
134 //(*aListToAppendTo)["new_option_name"] = UTF8( _(
135 // "A nice descrtiption with possibility for <b>bold</b> and other formatting."
136 // ) );
137}
138
139
140const wxString& SCH_IO::GetError() const
141{
142 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
143 NOT_IMPLEMENTED( __FUNCTION__ );
144}
virtual void GetLibraryOptions(STRING_UTF8_MAP *aListToAppendTo) const
Append supported IO options to aListToAppenTo along with internationalized descriptions.
Definition: io_base.cpp:61
Define a library symbol object.
Definition: lib_symbol.h:78
Holds all the data relating to one schematic.
Definition: schematic.h:75
virtual void SaveLibrary(const wxString &aFileName, const STRING_UTF8_MAP *aProperties=nullptr)
Definition: sch_io.cpp:62
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
Definition: sch_io.cpp:46
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_IO implementation knows about,...
Definition: sch_io.cpp:75
virtual void GetLibraryOptions(STRING_UTF8_MAP *aListToAppendTo) const override
Append supported SCH_IO options to aListToAppenTo along with internationalized descriptions.
Definition: sch_io.cpp:125
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_io.cpp:101
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_IO implementation knows about,...
Definition: sch_io.cpp:68
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_io.cpp:83
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_io.cpp:117
virtual const wxString & GetError() const
Return an error string to the caller.
Definition: sch_io.cpp:140
virtual const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const
Returns schematic file description for the SCH_IO.
Definition: sch_io.cpp:40
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_io.cpp:109
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: io_base.cpp:32
Container that describes file type info.
Definition: io_base.h:39
std::vector< std::string > m_FileExtensions
Filter used for file pickers if m_IsFile is true.
Definition: io_base.h:41