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 "sch_io/sch_io.h"
24
25#include <wx/dir.h>
26#include <wx/filename.h>
27#include <wx/translation.h>
28
29#include <ki_exception.h>
30#include <lib_symbol.h>
31#include <sch_io/sch_io_mgr.h>
32
33
34#define FMT_UNIMPLEMENTED wxT( "Plugin \"%s\" does not implement the \"%s\" function." )
35#define NOT_IMPLEMENTED( aCaller ) \
36 THROW_IO_ERROR( wxString::Format( FMT_UNIMPLEMENTED, \
37 GetName().GetData(), \
38 wxString::FromUTF8( aCaller ).GetData() ) );
39
40
42{
43 return IO_BASE::IO_FILE_DESC( wxEmptyString, {} );
44}
45
46
47bool SCH_IO::CanReadSchematicFile( const wxString& aFileName ) const
48{
49 const std::vector<std::string>& exts = GetSchematicFileDesc().m_FileExtensions;
50
51 wxString fileExt = wxFileName( aFileName ).GetExt().MakeLower();
52
53 for( const std::string& ext : exts )
54 {
55 if( fileExt == wxString( ext ).Lower() )
56 return true;
57 }
58
59 return false;
60}
61
62
63void SCH_IO::SaveLibrary( const wxString& aFileName, const std::map<std::string, UTF8>* aProperties )
64{
65 NOT_IMPLEMENTED( __FUNCTION__ );
66}
67
68
69SCH_SHEET* SCH_IO::LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
70 SCH_SHEET* aAppendToMe, const std::map<std::string, UTF8>* aProperties )
71{
72 NOT_IMPLEMENTED( __FUNCTION__ );
73}
74
75
77{
78 NOT_IMPLEMENTED( __FUNCTION__ );
79}
80
81
82void SCH_IO::SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
83 const std::map<std::string, UTF8>* aProperties )
84{
85 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
86 NOT_IMPLEMENTED( __FUNCTION__ );
87}
88
89
90void SCH_IO::EnumerateSymbolLib( wxArrayString& aAliasNameList,
91 const wxString& aLibraryPath,
92 const std::map<std::string, UTF8>* aProperties )
93{
94 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
95 NOT_IMPLEMENTED( __FUNCTION__ );
96}
97
98
99void SCH_IO::EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
100 const wxString& aLibraryPath,
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::CheckLibrary( const wxString& aLibraryPath,
109 const std::map<std::string, UTF8>* aProperties )
110{
111 wxArrayString symbolNames;
112 EnumerateSymbolLib( symbolNames, aLibraryPath, aProperties );
113}
114
115
116LIB_SYMBOL* SCH_IO::LoadSymbol( 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::SaveSymbol( const wxString& aLibraryPath, std::unique_ptr<LIB_SYMBOL> aSymbol,
125 const std::map<std::string, UTF8>* aProperties )
126{
127 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
128 NOT_IMPLEMENTED( __FUNCTION__ );
129}
130
131
132void SCH_IO::DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
133 const std::map<std::string, UTF8>* aProperties )
134{
135 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
136 NOT_IMPLEMENTED( __FUNCTION__ );
137}
138
139
140void SCH_IO::GetLibraryOptions( std::map<std::string, UTF8>* aListToAppendTo ) const
141{
142 // Get base options first
143 IO_BASE::GetLibraryOptions( aListToAppendTo );
144
145 // Empty for most plugins
146 //
147 // To add a new option override and use example code below:
148 //
149 //(*aListToAppendTo)["new_option_name"] = UTF8( _(
150 // "A nice descrtiption with possibility for <b>bold</b> and other formatting."
151 // ) );
152}
153
154
155const wxString& SCH_IO::GetError() const
156{
157 // not pure virtual so that plugins only have to implement subset of the SCH_IO interface.
158 NOT_IMPLEMENTED( __FUNCTION__ );
159}
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:119
Holds all the data relating to one schematic.
Definition schematic.h:148
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:90
virtual bool CanReadSchematicFile(const wxString &aFileName) const
Checks if this SCH_IO can read the specified schematic file.
Definition sch_io.cpp:47
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:69
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:132
virtual void CheckLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr)
Validate that the library at aLibraryPath is reachable and well-formed, without necessarily loading s...
Definition sch_io.cpp:108
virtual std::vector< LIB_SYMBOL * > GetImportedCachedLibrarySymbols()
Return the canonical symbol definitions produced by the last LoadSchematicFile().
Definition sch_io.cpp:76
virtual void SaveLibrary(const wxString &aFileName, const std::map< std::string, UTF8 > *aProperties=nullptr)
Definition sch_io.cpp:63
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:116
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:140
virtual void SaveSymbol(const wxString &aLibraryPath, std::unique_ptr< LIB_SYMBOL > aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr)
Write aSymbol to an existing library located at aLibraryPath.
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:82
virtual const wxString & GetError() const
Return an error string to the caller.
Definition sch_io.cpp:155
virtual const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const
Returns schematic file description for the SCH_IO.
Definition sch_io.cpp:41
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition sch_sheet.h:48
#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