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 The 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
20 * along with this program. If not, see <https://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
75{
76 NOT_IMPLEMENTED( __FUNCTION__ );
77}
78
79
80void SCH_IO::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
81 const std::map<std::string, UTF8>* aProperties )
82{
83 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
84 NOT_IMPLEMENTED( __FUNCTION__ );
85}
86
87
88void SCH_IO::EnumerateSymbolLib( wxArrayString& aAliasNameList,
89 const wxString& aLibraryPath,
90 const std::map<std::string, UTF8>* aProperties )
91{
92 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
93 NOT_IMPLEMENTED( __FUNCTION__ );
94}
95
96
97void SCH_IO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
98 const wxString& aLibraryPath,
99 const std::map<std::string, UTF8>* aProperties )
100{
101 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
102 NOT_IMPLEMENTED( __FUNCTION__ );
103}
104
105
106LIB_SYMBOL* SCH_IO::LoadSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
107 const std::map<std::string, UTF8>* aProperties )
108{
109 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
110 NOT_IMPLEMENTED( __FUNCTION__ );
111}
112
113
114void SCH_IO::SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
115 const std::map<std::string, UTF8>* aProperties )
116{
117 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
118 NOT_IMPLEMENTED( __FUNCTION__ );
119}
120
121
122void SCH_IO::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
123 const std::map<std::string, UTF8>* aProperties )
124{
125 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
126 NOT_IMPLEMENTED( __FUNCTION__ );
127}
128
129
130void SCH_IO::GetLibraryOptions( std::map<std::string, UTF8>* aListToAppendTo ) const
131{
132 // Get base options first
133 IO_BASE::GetLibraryOptions( aListToAppendTo );
134
135 // Empty for most plugins
136 //
137 // To add a new option override and use example code below:
138 //
139 //(*aListToAppendTo)["new_option_name"] = UTF8( _(
140 // "A nice descrtiption with possibility for <b>bold</b> and other formatting."
141 // ) );
142}
143
144
145const wxString& SCH_IO::GetError() const
146{
147 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
148 NOT_IMPLEMENTED( __FUNCTION__ );
149}
virtual void GetLibraryOptions(std::map< std::string, UTF8 > *aListToAppendTo) const
Append supported IO options to aListToAppenTo along with internationalized descriptions.
Definition io_base.cpp:65
Define a library symbol object.
Definition lib_symbol.h:114
Holds all the data relating to one schematic.
Definition schematic.h:90
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:88
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:114
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:122
virtual std::vector< LIB_SYMBOL * > GetImportedCachedLibrarySymbols()
Return the canonical symbol definitions produced by the last LoadSchematicFile().
Definition sch_io.cpp:74
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:106
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:130
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:80
virtual const wxString & GetError() const
Return an error string to the caller.
Definition sch_io.cpp:145
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:44
#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:47