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 STRING_UTF8_MAP;
47class SELECTION;
49class LIB_SYMBOL;
50class SYMBOL_LIB;
51class BUS_ALIAS;
52class OUTPUTFORMATTER;
53
54
67{
68public:
69
71 virtual ~SCH_IO_KICAD_LEGACY();
72
74 {
75 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy schematic files" ),
77 }
78
80 {
81 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad legacy symbol library files" ),
83 }
84
85 bool CanReadSchematicFile( const wxString& aFileName ) const override;
86
87 bool CanReadLibrary( const wxString& aFileName ) const override;
88
94 static const char* PropBuffering;
95
100 static const char* PropNoDocFile;
101
102 int GetModifyHash() const override;
103
104 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
105 SCH_SHEET* aAppendToMe = nullptr,
106 const STRING_UTF8_MAP* aProperties = nullptr ) override;
107
108 void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
109 int version = EESCHEMA_VERSION );
110
111 void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
112 const STRING_UTF8_MAP* aProperties = nullptr ) override;
113
114 void Format( SCH_SHEET* aSheet );
115
116 void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
117
118 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
119 const wxString& aLibraryPath,
120 const STRING_UTF8_MAP* aProperties = nullptr ) override;
121 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
122 const wxString& aLibraryPath,
123 const STRING_UTF8_MAP* aProperties = nullptr ) override;
124 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
125 const STRING_UTF8_MAP* aProperties = nullptr ) override;
126 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
127 const STRING_UTF8_MAP* aProperties = nullptr ) override;
128 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
129 const STRING_UTF8_MAP* aProperties = nullptr ) override;
130 void CreateLibrary( const wxString& aLibraryPath,
131 const STRING_UTF8_MAP* aProperties = nullptr ) override;
132 bool DeleteLibrary( const wxString& aLibraryPath,
133 const STRING_UTF8_MAP* aProperties = nullptr ) override;
134 void SaveLibrary( const wxString& aLibraryPath,
135 const STRING_UTF8_MAP* aProperties = nullptr ) override;
136
137 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
138
139 const wxString& GetError() const override { return m_error; }
140
141 static LIB_SYMBOL* ParsePart( LINE_READER& aReader, int majorVersion = 0,
142 int minorVersion = 0 );
143 static void FormatPart( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter );
144
145private:
146 void checkpoint();
147 void loadHierarchy( SCH_SHEET* aSheet );
148 void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
149 void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
150 void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
151 SCH_SHEET* loadSheet( LINE_READER& aReader );
152 SCH_BITMAP* loadBitmap( LINE_READER& aReader );
155 SCH_LINE* loadWire( LINE_READER& aReader );
157 SCH_TEXT* loadText( LINE_READER& aReader );
158 SCH_SYMBOL* loadSymbol( LINE_READER& aReader );
159 std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
160
161 void saveSymbol( SCH_SYMBOL* aSymbol );
162 void saveField( SCH_FIELD* aField );
163 void saveBitmap( SCH_BITMAP* aBitmap );
164 void saveSheet( SCH_SHEET* aSheet );
165 void saveJunction( SCH_JUNCTION* aJunction );
166 void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
167 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
168 void saveLine( SCH_LINE* aLine );
169 void saveText( SCH_TEXT* aText );
170 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
171
172 void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
173 bool writeDocFile( const STRING_UTF8_MAP* aProperties );
174 bool isBuffering( const STRING_UTF8_MAP* aProperties );
175
176protected:
178
181
182 wxString m_error;
186 unsigned m_lineCount;
187
188 wxString m_path;
189 std::stack<wxString> m_currentPath;
195
197 void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
198};
199
200#endif // SCH_IO_KICAD_LEGACY_H_
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:279
Define a library symbol object.
Definition: lib_symbol.h:79
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:75
Object to handle a bitmap image that can be inserted in a schematic.
Definition: sch_bitmap.h:41
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:52
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 saveText(SCH_TEXT *aText)
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
void saveJunction(SCH_JUNCTION *aJunction)
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void Format(SCH_SHEET *aSheet)
void loadHierarchy(SCH_SHEET *aSheet)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
void SaveSymbol(const wxString &aLibraryPath, const LIB_SYMBOL *aSymbol, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSymbol to an existing library located at aLibraryPath.
void EnumerateSymbolLib(wxArrayString &aSymbolNameList, const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Populate a list of LIB_SYMBOL alias names contained within the library aLibraryPath.
bool DeleteLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing library and returns true, or if library does not exist returns false,...
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
LIB_SYMBOL * LoadSymbol(const wxString &aLibraryPath, const wxString &aAliasName, const STRING_UTF8_MAP *aProperties=nullptr) override
Load a LIB_SYMBOL object having aPartName from the aLibraryPath containing a library format that this...
int GetModifyHash() const override
Return the modification hash from the library cache.
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
void DeleteSymbol(const wxString &aLibraryPath, const wxString &aSymbolName, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete the entire LIB_SYMBOL associated with aAliasName from the library aLibraryPath.
void CreateLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
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.
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.
SCH_SHEET * LoadSchematicFile(const wxString &aFileName, SCHEMATIC *aSchematic, SCH_SHEET *aAppendToMe=nullptr, const STRING_UTF8_MAP *aProperties=nullptr) override
Load information from some input file format that this SCH_IO implementation knows about,...
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)
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)
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aScreen, SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr) override
Write aSchematic to a storage file in a format that this SCH_IO implementation knows about,...
unsigned m_lineCount
for progress reporting
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_IO_KICAD_LEGACY_LIB_CACHE * m_cache
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
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 saveSheet(SCH_SHEET *aSheet)
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this IO object can read the specified library file/directory.
bool isBuffering(const STRING_UTF8_MAP *aProperties)
LINE_READER * m_lineReader
for progress reporting
void saveBitmap(SCH_BITMAP *aBitmap)
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:40
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:108
A name/value tuple with unique names and optional values.
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:39
Definition of file extensions used in Kicad.