KiCad PCB EDA Suite
Go to the documentation of this file.
5 * This program source code file is part of KiCad, a free EDA CAD application.
6 *
7 * Copyright (C) 2016 CERN
8 * Copyright (C) 2016-2022 KiCad Developers, see change_log.txt for contributors.
9 *
10 * @author Wayne Stambaugh <[email protected]>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License along
23 * with this program. If not, see <>.
24 */
26#include <memory>
27#include <sch_io_mgr.h>
28#include <stack>
29#include <general.h> // for EESCHEMA_VERSION definition
32class KIWAY;
33class LINE_READER;
34class SCH_SCREEN;
35class SCH_SHEET;
36class SCH_BITMAP;
39class SCH_LINE;
41class SCH_TEXT;
42class SCH_SYMBOL;
43class SCH_FIELD;
44class STRING_UTF8_MAP;
45class SELECTION;
47class LIB_SYMBOL;
48class SYMBOL_LIB;
49class BUS_ALIAS;
68 virtual ~SCH_LEGACY_PLUGIN();
70 const wxString GetName() const override
71 {
72 return wxT( "Eeschema-Legacy" );
73 }
75 const wxString GetFileExtension() const override
76 {
77 return wxT( "sch" );
78 }
80 const wxString GetLibraryFileExtension() const override
81 {
82 return wxT( "lib" );
83 }
85 void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
86 {
87 m_progressReporter = aReporter;
88 }
95 static const char* PropBuffering;
101 static const char* PropNoDocFile;
103 int GetModifyHash() const override;
105 SCH_SHEET* Load( const wxString& aFileName, SCHEMATIC* aSchematic,
106 SCH_SHEET* aAppendToMe = nullptr,
107 const STRING_UTF8_MAP* aProperties = nullptr ) override;
109 void LoadContent( LINE_READER& aReader, SCH_SCREEN* aScreen,
110 int version = EESCHEMA_VERSION );
112 void Save( const wxString& aFileName, SCH_SHEET* aScreen, SCHEMATIC* aSchematic,
113 const STRING_UTF8_MAP* aProperties = nullptr ) override;
115 void Format( SCH_SHEET* aSheet );
117 void Format( SELECTION* aSelection, OUTPUTFORMATTER* aFormatter );
119 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
120 const wxString& aLibraryPath,
121 const STRING_UTF8_MAP* aProperties = nullptr ) override;
122 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
123 const wxString& aLibraryPath,
124 const STRING_UTF8_MAP* aProperties = nullptr ) override;
125 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
126 const STRING_UTF8_MAP* aProperties = nullptr ) override;
127 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
128 const STRING_UTF8_MAP* aProperties = nullptr ) override;
129 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
130 const STRING_UTF8_MAP* aProperties = nullptr ) override;
131 void CreateSymbolLib( const wxString& aLibraryPath,
132 const STRING_UTF8_MAP* aProperties = nullptr ) override;
133 bool DeleteSymbolLib( const wxString& aLibraryPath,
134 const STRING_UTF8_MAP* aProperties = nullptr ) override;
135 void SaveLibrary( const wxString& aLibraryPath,
136 const STRING_UTF8_MAP* aProperties = nullptr ) override;
138 bool CheckHeader( const wxString& aFileName ) override;
139 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
141 const wxString& GetError() const override { return m_error; }
143 static LIB_SYMBOL* ParsePart( LINE_READER& aReader, int majorVersion = 0,
144 int minorVersion = 0 );
145 static void FormatPart( LIB_SYMBOL* aSymbol, OUTPUTFORMATTER& aFormatter );
148 void checkpoint();
149 void loadHierarchy( SCH_SHEET* aSheet );
150 void loadHeader( LINE_READER& aReader, SCH_SCREEN* aScreen );
151 void loadPageSettings( LINE_READER& aReader, SCH_SCREEN* aScreen );
152 void loadFile( const wxString& aFileName, SCH_SCREEN* aScreen );
153 SCH_SHEET* loadSheet( LINE_READER& aReader );
154 SCH_BITMAP* loadBitmap( LINE_READER& aReader );
157 SCH_LINE* loadWire( LINE_READER& aReader );
159 SCH_TEXT* loadText( LINE_READER& aReader );
160 SCH_SYMBOL* loadSymbol( LINE_READER& aReader );
161 std::shared_ptr<BUS_ALIAS> loadBusAlias( LINE_READER& aReader, SCH_SCREEN* aScreen );
163 void saveSymbol( SCH_SYMBOL* aSymbol );
164 void saveField( SCH_FIELD* aField );
165 void saveBitmap( SCH_BITMAP* aBitmap );
166 void saveSheet( SCH_SHEET* aSheet );
167 void saveJunction( SCH_JUNCTION* aJunction );
168 void saveNoConnect( SCH_NO_CONNECT* aNoConnect );
169 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry );
170 void saveLine( SCH_LINE* aLine );
171 void saveText( SCH_TEXT* aText );
172 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias );
174 void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
175 bool writeDocFile( const STRING_UTF8_MAP* aProperties );
176 bool isBuffering( const STRING_UTF8_MAP* aProperties );
184 wxString m_error;
189 unsigned m_lineCount;
191 wxString m_path;
192 std::stack<wxString> m_currentPath;
200 void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
203#endif // _SCH_LEGACY_PLUGIN_H_
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition: kiway.h:274
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:81
An interface used to output 8 bit text in a convenient way.
Definition: richio.h:310
A progress reporter interface for use in multi-threaded environments.
Holds all the data relating to one schematic.
Definition: schematic.h:61
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:51
A cache assistant for KiCad legacy symbol libraries.
A SCH_PLUGIN derivation for loading schematic files created before the new s-expression file format.
void Save(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,...
int m_version
Version of file being loaded.
void loadPageSettings(LINE_READER &aReader, SCH_SCREEN *aScreen)
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.
const wxString GetFileExtension() const override
Return the file extension for the SCH_PLUGIN.
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)
bool writeDocFile(const STRING_UTF8_MAP *aProperties)
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)
void saveLine(SCH_LINE *aLine)
SCH_SYMBOL * loadSymbol(LINE_READER &aReader)
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
const wxString GetLibraryFileExtension() const override
Return the library file extension for the SCH_PLUGIN object.
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.
SCH_SHEET * Load(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.
bool CheckHeader(const wxString &aFileName) override
Return true if the first line in aFileName begins with the expected header.
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_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:155
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.
Definition: general.h:35