KiCad PCB EDA Suite
No Matches
Go to the documentation of this file.
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2020 CERN
5 * Copyright (C) 2021-2023 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
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 <>.
21 */
23#ifndef _SCH_SEXPR_PLUGIN_H_
24#define _SCH_SEXPR_PLUGIN_H_
26#include <memory>
27#include <sch_io_mgr.h>
28#include <sch_file_versions.h>
29#include <sch_sheet_path.h>
30#include <stack>
32#include <wx/string.h>
35class KIWAY;
36class LINE_READER;
37class SCH_SCREEN;
38class SCH_SHEET;
40class SCH_BITMAP;
43class SCH_LINE;
44class SCH_SHAPE;
46class SCH_TEXT;
47class SCH_TEXTBOX;
48class SCH_SYMBOL;
49class SCH_FIELD;
51class STRING_UTF8_MAP;
54class LIB_SYMBOL;
55class SYMBOL_LIB;
56class BUS_ALIAS;
69 virtual ~SCH_SEXPR_PLUGIN();
71 const wxString GetName() const override
72 {
73 return wxT( "Eeschema s-expression" );
74 }
77 {
78 return PLUGIN_FILE_DESC( _HKI( "KiCad s-expression schematic files" ),
80 }
82 const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
83 {
84 return PLUGIN_FILE_DESC( _HKI( "KiCad symbol library files" ),
86 }
88 void SetProgressReporter( PROGRESS_REPORTER* aReporter ) override
89 {
90 m_progressReporter = aReporter;
91 }
98 static const char* PropBuffering;
100 int GetModifyHash() const override;
102 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
103 SCH_SHEET* aAppendToMe = nullptr,
104 const STRING_UTF8_MAP* aProperties = nullptr ) override;
106 void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet,
109 void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
110 const STRING_UTF8_MAP* aProperties = nullptr ) override;
112 void Format( SCH_SHEET* aSheet );
114 void Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath,
115 SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter, bool aForClipboard );
117 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
118 const wxString& aLibraryPath,
119 const STRING_UTF8_MAP* aProperties = nullptr ) override;
120 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
121 const wxString& aLibraryPath,
122 const STRING_UTF8_MAP* aProperties = nullptr ) override;
123 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
124 const STRING_UTF8_MAP* aProperties = nullptr ) override;
125 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
126 const STRING_UTF8_MAP* aProperties = nullptr ) override;
127 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
128 const STRING_UTF8_MAP* aProperties = nullptr ) override;
129 void CreateSymbolLib( const wxString& aLibraryPath,
130 const STRING_UTF8_MAP* aProperties = nullptr ) override;
131 bool DeleteSymbolLib( const wxString& aLibraryPath,
132 const STRING_UTF8_MAP* aProperties = nullptr ) override;
133 void SaveLibrary( const wxString& aLibraryPath,
134 const STRING_UTF8_MAP* aProperties = nullptr ) override;
136 bool IsSymbolLibWritable( const wxString& aLibraryPath ) override;
138 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
139 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
141 const wxString& GetError() const override { return m_error; }
143 static std::vector<LIB_SYMBOL*> ParseLibSymbols( std::string& aSymbolText,
144 std::string aSource,
145 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
146 static void FormatLibSymbol( LIB_SYMBOL* aPart, OUTPUTFORMATTER& aFormatter );
149 void loadHierarchy( const SCH_SHEET_PATH& aParentSheetPath, SCH_SHEET* aSheet );
150 void loadFile( const wxString& aFileName, SCH_SHEET* aSheet );
152 void saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic, int aNestLevel,
153 bool aForClipboard );
154 void saveField( SCH_FIELD* aField, int aNestLevel );
155 void saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel );
156 void saveSheet( SCH_SHEET* aSheet, int aNestLevel );
157 void saveJunction( SCH_JUNCTION* aJunction, int aNestLevel );
158 void saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel );
159 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLevel );
160 void saveLine( SCH_LINE* aLine, int aNestLevel );
161 void saveShape( SCH_SHAPE* aShape, int aNestLevel );
162 void saveText( SCH_TEXT* aText, int aNestLevel );
163 void saveTextBox( SCH_TEXTBOX* aText, int aNestLevel );
164 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel );
165 void saveInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheets, int aNestLevel );
167 void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
168 bool isBuffering( const STRING_UTF8_MAP* aProperties );
174 wxString m_error;
178 wxString m_path;
179 std::stack<wxString> m_currentPath;
187 void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
190#endif // _SCH_SEXPR_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
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
A cache assistant for the KiCad s-expression symbol libraries.
A SCH_PLUGIN derivation for loading schematic files using the new s-expression file format.
wxString m_error
For throwing exceptions or errors on partial loads.
const PLUGIN_FILE_DESC GetLibraryFileDesc() const override
Returns symbol library description for the SCH_PLUGIN.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
void GetDefaultSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that should be shown by default for this library in the symb...
SCH_SHEET_PATH m_currentSheetPath
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
wxString m_path
Root project path for loading child sheets.
void saveField(SCH_FIELD *aField, int aNestLevel)
void saveTextBox(SCH_TEXTBOX *aText, int aNestLevel)
SCHEMATIC * m_schematic
The formatter for saving SCH_SCREEN objects.
void Format(SCH_SHEET *aSheet)
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.
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
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...
const wxString GetName() const override
Return a brief hard coded name for this SCH_PLUGIN.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
void saveLine(SCH_LINE *aLine, int aNestLevel)
void saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, int aNestLevel)
const wxString & GetError() const override
Return an error string to the caller.
bool m_appending
Schematic load append status.
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
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 * 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,...
void SetProgressReporter(PROGRESS_REPORTER *aReporter) override
Set an optional progress reporter.
void saveText(SCH_TEXT *aText, int aNestLevel)
const PLUGIN_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_PLUGIN.
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.
void saveSymbol(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, int aNestLevel, bool aForClipboard)
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
void CreateSymbolLib(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty symbol library at aLibraryPath.
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
bool IsSymbolLibWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
void loadHierarchy(const SCH_SHEET_PATH &aParentSheetPath, SCH_SHEET *aSheet)
static std::vector< LIB_SYMBOL * > ParseLibSymbols(std::string &aSymbolText, std::string aSource, int aFileVersion=SEXPR_SCHEMATIC_FILE_VERSION)
bool isBuffering(const STRING_UTF8_MAP *aProperties)
PROGRESS_REPORTER * m_progressReporter
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *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 ...
void saveShape(SCH_SHAPE *aShape, int aNestLevel)
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 saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
void SaveSchematicFile(const wxString &aFileName, SCH_SHEET *aSheet, 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,...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
int m_version
Version of file being loaded.
int GetModifyHash() const override
Return the modification hash from the library cache.
void saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
Handle access to a stack of flattened SCH_SHEET objects by way of a path for creating a flattened sch...
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)
const std::string KiCadSymbolLibFileExtension
const std::string KiCadSchematicFileExtension
Schematic file version.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Container that describes file type info.
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
Definition of file extensions used in Kicad.