KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_kicad_legacy.h
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 change_log.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#ifndef SCH_IO_KICAD_LEGACY_H_
24#define SCH_IO_KICAD_LEGACY_H_
25
26#include <memory>
27#include <sch_io/sch_io.h>
28#include <sch_io/sch_io_mgr.h>
29#include <stack>
30#include <general.h> // for EESCHEMA_VERSION definition
32
33
34class KIWAY;
35class LINE_READER;
36class SCH_SCREEN;
37class SCH_SHEET;
38class SCH_BITMAP;
39class SCH_JUNCTION;
40class SCH_NO_CONNECT;
41class SCH_LINE;
43class SCH_TEXT;
44class SCH_SYMBOL;
45class SCH_FIELD;
46class SELECTION;
48class LIB_SYMBOL;
49class SYMBOL_LIB;
50class BUS_ALIAS;
51class OUTPUTFORMATTER;
52
53
66{
67public:
68
70 virtual ~SCH_IO_KICAD_LEGACY();
71
73 {
74 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy schematic files" ),
76 }
77
79 {
80 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy symbol library files" ),
82 }
83
84 bool CanReadSchematicFile( const wxString& aFileName ) const override;
85
86 bool CanReadLibrary( const wxString& aFileName ) const override;
87
93 static const char* PropBuffering;
94
99 static const char* PropNoDocFile;
100
101 int GetModifyHash() const override;
102
103 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
104 SCH_SHEET* aAppendToMe = nullptr,
105 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
106
107 void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
108 int version = EESCHEMA_VERSION );
109
110 void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
111 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
112
113 void Format( SCH_SHEET* aSheet );
114
115 void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
116
117 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
118 const wxString& aLibraryPath,
119 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
120 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
121 const wxString& aLibraryPath,
122 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
123 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
124 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
125 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
126 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
127 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
128 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
129 void CreateLibrary( const wxString& aLibraryPath,
130 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
131 bool DeleteLibrary( const wxString& aLibraryPath,
132 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
133 void SaveLibrary( const wxString& aLibraryPath,
134 const std::map<std::string, UTF8>* aProperties = nullptr ) override;
135
136 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
137
138 const wxString& GetError() const override { return m_error; }
139
140 static LIB_SYMBOL* ParsePart( LINE_READER& aReader, int majorVersion = 0,
141 int minorVersion = 0 );
142 static void FormatPart( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter );
143
144private:
145 void checkpoint();
146 void loadHierarchy( SCH_SHEET* aSheet );
147 void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
148 void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
149 void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
150 SCH_SHEET* loadSheet( LINE_READER& aReader );
151 SCH_BITMAP* loadBitmap( LINE_READER& aReader );
154 SCH_LINE* loadWire( LINE_READER& aReader );
156 SCH_TEXT* loadText( LINE_READER& aReader );
157 SCH_SYMBOL* loadSymbol( LINE_READER& aReader );
158 std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
159
160 void saveSymbol( SCH_SYMBOL* aSymbol );
161 void saveField( SCH_FIELD* aField );
162 void saveBitmap( const SCH_BITMAP& aBitmap );
163 void saveSheet( SCH_SHEET* aSheet );
164 void saveJunction( SCH_JUNCTION* aJunction );
165 void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
166 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
167 void saveLine( SCH_LINE* aLine );
168 void saveText( SCH_TEXT* aText );
169 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
170
171 void cacheLib( const wxString& aLibraryFileName, const std::map<std::string, UTF8>* aProperties );
172 bool writeDocFile( const std::map<std::string, UTF8>* aProperties );
173 bool isBuffering( const std::map<std::string, UTF8>* aProperties );
174
175protected:
177
180
181 wxString m_error;
185 unsigned m_lineCount;
186
187 wxString m_path;
188 std::stack<wxString> m_currentPath;
194
196 void init( SCHEMATIC* aSchematic, const std::map<std::string, UTF8>* aProperties = nullptr );
197};
198
199#endif // SCH_IO_KICAD_LEGACY_H_
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:284
Define a library symbol object.
Definition: lib_symbol.h:78
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:322
Holds all the data relating to one schematic.
Definition: schematic.h:77
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:40
Base class for a bus or wire entry.
Definition: sch_bus_entry.h:38
Instances are attached to a symbol or sheet and provide a place for the symbol's value,...
Definition: sch_field.h:51
A cache assistant for KiCad legacy symbol libraries.
A SCH_IO derivation for loading schematic files created before the new s-expression file format.
wxString m_error
For throwing exceptions or errors on partial schematic loads.
SCH_SHEET * m_currentSheet
The sheet currently being loaded.
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
void saveText(SCH_TEXT *aText)
void saveJunction(SCH_JUNCTION *aJunction)
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
bool isBuffering(const std::map< std::string, UTF8 > *aProperties)
void Format(SCH_SHEET *aSheet)
void loadHierarchy(SCH_SHEET *aSheet)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
int GetModifyHash() const override
Return the modification hash from the library cache.
wxString m_path
Root project path for loading child sheets.
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
const wxString & GetError() const override
Return an error string to the caller.
void init(SCHEMATIC *aSchematic, const std::map< std::string, UTF8 > *aProperties=nullptr)
initialize PLUGIN like a constructor would.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
static void FormatPart(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
int m_version
Version of file being loaded.
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_IO can read the specified schematic file.
void saveLine(SCH_LINE *aLine)
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
void saveSymbol(SCH_SYMBOL *aSymbol)
void saveField(SCH_FIELD *aField)
SCH_SHEET * loadSheet(LINE_READER &aReader)
SCH_LINE * loadWire(LINE_READER &aReader)
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
unsigned m_lineCount
for progress reporting
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void SaveLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_IO_KICAD_LEGACY_LIB_CACHE * m_cache
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
void cacheLib(const wxString &aLibraryFileName, const std::map< std::string, UTF8 > *aProperties)
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
void saveBitmap(const SCH_BITMAP &aBitmap)
void saveSheet(SCH_SHEET *aSheet)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void CreateLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
bool DeleteLibrary(const wxString &aLibraryPath, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const std::map< std::string, UTF8 > *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
bool writeDocFile(const std::map< std::string, UTF8 > *aProperties)
LINE_READER * m_lineReader
for progress reporting
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io.h:57
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:41
Sheet symbol placed in a schematic, and is the entry point for a sub schematic.
Definition: sch_sheet.h:57
Schematic symbol object.
Definition: sch_symbol.h:104
Object used to load, save, search, and otherwise manipulate symbol library files.
#define _HKI(x)
#define EESCHEMA_VERSION
Definition: general.h:35
static const std::string LegacySchematicFileExtension
static const std::string LegacySymbolLibFileExtension
Container that describes file type info.
Definition: io_base.h:43
Definition of file extensions used in Kicad.