KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_legacy_plugin.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_LEGACY_PLUGIN_H_
24#define _SCH_LEGACY_PLUGIN_H_
25
26#include <memory>
27#include <sch_io_mgr.h>
28#include <stack>
29#include <general.h> // for EESCHEMA_VERSION definition
31
32
33class KIWAY;
34class LINE_READER;
35class SCH_SCREEN;
36class SCH_SHEET;
37class SCH_BITMAP;
38class SCH_JUNCTION;
39class SCH_NO_CONNECT;
40class SCH_LINE;
42class SCH_TEXT;
43class SCH_SYMBOL;
44class SCH_FIELD;
45class STRING_UTF8_MAP;
46class SELECTION;
48class LIB_SYMBOL;
49class SYMBOL_LIB;
50class BUS_ALIAS;
51class OUTPUTFORMATTER;
52
53
66{
67public:
68
70 virtual ~SCH_LEGACY_PLUGIN();
71
72 const wxString GetName() const override
73 {
74 return wxT( "Eeschema-Legacy" );
75 }
76
78 {
79 return PLUGIN_FILE_DESC( _HKI( "KiCad legacy schematic files" ),
81 }
82
83 const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
84 {
85 return PLUGIN_FILE_DESC( _HKI( "KiCad legacy symbol library files" ),
87 }
88
89 bool CanReadSchematicFile( const wxString& aFileName ) const override;
90
91 bool CanReadLibrary( const wxString& aFileName ) const override;
92
93 void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
94 {
95 m_progressReporter = aReporter;
96 }
97
103 static const char* PropBuffering;
104
109 static const char* PropNoDocFile;
110
111 int GetModifyHash() const override;
112
113 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
114 SCH_SHEET* aAppendToMe = nullptr,
115 const STRING_UTF8_MAP* aProperties = nullptr ) override;
116
117 void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
118 int version = EESCHEMA_VERSION );
119
120 void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
121 const STRING_UTF8_MAP* aProperties = nullptr ) override;
122
123 void Format( SCH_SHEET* aSheet );
124
125 void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
126
127 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
128 const wxString& aLibraryPath,
129 const STRING_UTF8_MAP* aProperties = nullptr ) override;
130 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
131 const wxString& aLibraryPath,
132 const STRING_UTF8_MAP* aProperties = nullptr ) override;
133 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
134 const STRING_UTF8_MAP* aProperties = nullptr ) override;
135 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
136 const STRING_UTF8_MAP* aProperties = nullptr ) override;
137 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
138 const STRING_UTF8_MAP* aProperties = nullptr ) override;
139 void CreateSymbolLib( const wxString& aLibraryPath,
140 const STRING_UTF8_MAP* aProperties = nullptr ) override;
141 bool DeleteSymbolLib( const wxString& aLibraryPath,
142 const STRING_UTF8_MAP* aProperties = nullptr ) override;
143 void SaveLibrary( const wxString& aLibraryPath,
144 const STRING_UTF8_MAP* aProperties = nullptr ) override;
145
146 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
147
148 const wxString& GetError() const override { return m_error; }
149
150 static LIB_SYMBOL* ParsePart( LINE_READER& aReader, int majorVersion = 0,
151 int minorVersion = 0 );
152 static void FormatPart( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter );
153
154private:
155 void checkpoint();
156 void loadHierarchy( SCH_SHEET* aSheet );
157 void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
158 void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
159 void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
160 SCH_SHEET* loadSheet( LINE_READER& aReader );
161 SCH_BITMAP* loadBitmap( LINE_READER& aReader );
164 SCH_LINE* loadWire( LINE_READER& aReader );
166 SCH_TEXT* loadText( LINE_READER& aReader );
167 SCH_SYMBOL* loadSymbol( LINE_READER& aReader );
168 std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
169
170 void saveSymbol( SCH_SYMBOL* aSymbol );
171 void saveField( SCH_FIELD* aField );
172 void saveBitmap( SCH_BITMAP* aBitmap );
173 void saveSheet( SCH_SHEET* aSheet );
174 void saveJunction( SCH_JUNCTION* aJunction );
175 void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
176 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
177 void saveLine( SCH_LINE* aLine );
178 void saveText( SCH_TEXT* aText );
179 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
180
181 void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
182 bool writeDocFile( const STRING_UTF8_MAP* aProperties );
183 bool isBuffering( const STRING_UTF8_MAP* aProperties );
184
185protected:
187
190
191 wxString m_error;
196 unsigned m_lineCount;
197
198 wxString m_path;
199 std::stack<wxString> m_currentPath;
205
207 void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
208};
209
210#endif // _SCH_LEGACY_PLUGIN_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:99
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
A progress reporter interface for use in multi-threaded environments.
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_PLUGIN derivation for loading schematic files created before the new s-expression file format.
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
bool CanReadLibrary(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified symbol library file.
SCH_LINE * loadWire(LINE_READER &aReader)
void saveSymbol(SCH_SYMBOL *aSymbol)
int GetModifyHash() const override
Return the modification hash from the library cache.
wxString m_error
For throwing exceptions or errors on partial schematic loads.
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
void saveSheet(SCH_SHEET *aSheet)
SCH_JUNCTION * loadJunction(LINE_READER &aReader)
wxString m_path
Root project path for loading child sheets.
void saveText(SCH_TEXT *aText)
static const char * PropNoDocFile
The property used internally by the plugin to disable writing the library documentation (....
SCH_NO_CONNECT * loadNoConnect(LINE_READER &aReader)
SCH_BITMAP * loadBitmap(LINE_READER &aReader)
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
Returns symbol library description for the SCH_PLUGIN.
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
bool CanReadSchematicFile(const wxString &aFileName) const override
Checks if this SCH_PLUGIN can read the specified schematic file.
void loadHeader(LINE_READER &aReader, SCH_SCREEN *aScreen)
void Format(SCH_SHEET *aSheet)
void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void saveField(SCH_FIELD *aField)
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
void saveJunction(SCH_JUNCTION *aJunction)
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry)
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_PLUGIN.
void saveLine(SCH_LINE *aLine)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
bool DeleteSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Delete an existing symbol library and returns true if successful, or if library does not exist return...
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias)
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.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect)
void loadFile(const wxString &aFileName, SCH_SCREEN *aScreen)
static LIB_SYMBOL * ParsePart(LINE_READER &aReader, int majorVersion=0, int minorVersion=0)
unsigned m_lineCount
for progress reporting
SCH_SHEET * loadSheet(LINE_READER &aReader)
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.
PROGRESS_REPORTER * m_progressReporter
optional; may be nullptr
static void FormatPart(LIB_SYMBOL *aSymbol, OUTPUTFORMATTER &aFormatter)
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 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_PLUGIN implementation knows about,...
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_PLUGIN implementation knows about,...
std::shared_ptr< BUS_ALIAS > loadBusAlias(LINE_READER &aReader, SCH_SCREEN *aScreen)
SCH_TEXT * loadText(LINE_READER &aReader)
void saveBitmap(SCH_BITMAP *aBitmap)
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
void LoadContent(LINE_READER &aReader, SCH_SCREEN *aScreen, int version=EESCHEMA_VERSION)
bool isBuffering(const STRING_UTF8_MAP *aProperties)
LINE_READER * m_lineReader
for progress reporting
const wxString & GetError() const override
Return an error string to the caller.
SCH_BUS_ENTRY_BASE * loadBusEntry(LINE_READER &aReader)
void loadHierarchy(SCH_SHEET *aSheet)
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...
void SetProgressReporter(PROGRESS_REPORTER *aReporter) override
Set an optional progress reporter.
SCH_LEGACY_PLUGIN_CACHE * m_cache
SCH_SHEET * m_currentSheet
The sheet currently being loaded.
Segment description base class to describe items which have 2 end points (track, wire,...
Definition: sch_line.h:40
Base class that schematic file and library loading and saving plugins should derive from.
Definition: sch_io_mgr.h:145
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:81
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
const std::string LegacySchematicFileExtension
const std::string LegacySymbolLibFileExtension
Container that describes file type info.
Definition of file extensions used in Kicad.