KiCad PCB EDA Suite
Loading...
Searching...
No Matches
sch_io_kicad_sexpr.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) 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
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_SEXPR_H_
24#define SCH_IO_KICAD_SEXPR_H_
25
26#include <memory>
27#include <sch_io/sch_io.h>
28#include <sch_io/sch_io_mgr.h>
29#include <sch_file_versions.h>
30#include <sch_sheet_path.h>
31#include <stack>
33#include <wx/string.h>
34
35
36class KIWAY;
37class LINE_READER;
38class SCH_SCREEN;
39class SCH_SHEET;
41class SCH_BITMAP;
42class SCH_JUNCTION;
43class SCH_NO_CONNECT;
44class SCH_LINE;
45class SCH_SHAPE;
46class SCH_RULE_AREA;
48class SCH_TEXT;
49class SCH_TEXTBOX;
50class SCH_TABLE;
51class SCH_SYMBOL;
52class SCH_FIELD;
54class STRING_UTF8_MAP;
55class EE_SELECTION;
57class LIB_SYMBOL;
58class SYMBOL_LIB;
59class BUS_ALIAS;
60
68{
69public:
70
72 virtual ~SCH_IO_KICAD_SEXPR();
73
75 {
76 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad s-expression schematic files" ),
78 }
79
81 {
82 return IO_BASE::IO_FILE_DESC( _HKI( "KiCad symbol library files" ),
84 }
85
91 static const char* PropBuffering;
92
93 int GetModifyHash() const override;
94
95 SCH_SHEET* LoadSchematicFile( const wxString& aFileName, SCHEMATIC* aSchematic,
96 SCH_SHEET* aAppendToMe = nullptr,
97 const STRING_UTF8_MAP* aProperties = nullptr ) override;
98
99 void LoadContent( LINE_READER& aReader, SCH_SHEET* aSheet,
100 int aVersion = SEXPR_SCHEMATIC_FILE_VERSION );
101
102 void SaveSchematicFile( const wxString& aFileName, SCH_SHEET* aSheet, SCHEMATIC* aSchematic,
103 const STRING_UTF8_MAP* aProperties = nullptr ) override;
104
105 void Format( SCH_SHEET* aSheet );
106
107 void Format( EE_SELECTION* aSelection, SCH_SHEET_PATH* aSelectionPath,
108 SCHEMATIC& aSchematic, OUTPUTFORMATTER* aFormatter, bool aForClipboard );
109
110 void EnumerateSymbolLib( wxArrayString& aSymbolNameList,
111 const wxString& aLibraryPath,
112 const STRING_UTF8_MAP* aProperties = nullptr ) override;
113 void EnumerateSymbolLib( std::vector<LIB_SYMBOL*>& aSymbolList,
114 const wxString& aLibraryPath,
115 const STRING_UTF8_MAP* aProperties = nullptr ) override;
116 LIB_SYMBOL* LoadSymbol( const wxString& aLibraryPath, const wxString& aAliasName,
117 const STRING_UTF8_MAP* aProperties = nullptr ) override;
118 void SaveSymbol( const wxString& aLibraryPath, const LIB_SYMBOL* aSymbol,
119 const STRING_UTF8_MAP* aProperties = nullptr ) override;
120 void DeleteSymbol( const wxString& aLibraryPath, const wxString& aSymbolName,
121 const STRING_UTF8_MAP* aProperties = nullptr ) override;
122 void CreateLibrary( const wxString& aLibraryPath,
123 const STRING_UTF8_MAP* aProperties = nullptr ) override;
124 bool DeleteLibrary( const wxString& aLibraryPath,
125 const STRING_UTF8_MAP* aProperties = nullptr ) override;
126 void SaveLibrary( const wxString& aLibraryPath,
127 const STRING_UTF8_MAP* aProperties = nullptr ) override;
128
129 bool IsLibraryWritable( const wxString& aLibraryPath ) override;
130
131 void GetAvailableSymbolFields( std::vector<wxString>& aNames ) override;
132 void GetDefaultSymbolFields( std::vector<wxString>& aNames ) override;
133
134 const wxString& GetError() const override { return m_error; }
135
136 static std::vector<LIB_SYMBOL*> ParseLibSymbols( std::string& aSymbolText,
137 std::string aSource,
138 int aFileVersion = SEXPR_SCHEMATIC_FILE_VERSION );
139 static void FormatLibSymbol( LIB_SYMBOL* aPart, OUTPUTFORMATTER& aFormatter );
140
141private:
142 void loadHierarchy( const SCH_SHEET_PATH& aParentSheetPath, SCH_SHEET* aSheet );
143 void loadFile( const wxString& aFileName, SCH_SHEET* aSheet );
144
145 void saveSymbol( SCH_SYMBOL* aSymbol, const SCHEMATIC& aSchematic, int aNestLevel,
146 bool aForClipboard, const SCH_SHEET_PATH* aRelativePath = nullptr );
147 void saveField( SCH_FIELD* aField, int aNestLevel );
148 void saveBitmap( SCH_BITMAP* aBitmap, int aNestLevel );
149 void saveSheet( SCH_SHEET* aSheet, int aNestLevel );
150 void saveJunction( SCH_JUNCTION* aJunction, int aNestLevel );
151 void saveNoConnect( SCH_NO_CONNECT* aNoConnect, int aNestLevel );
152 void saveBusEntry( SCH_BUS_ENTRY_BASE* aBusEntry, int aNestLevel );
153 void saveLine( SCH_LINE* aLine, int aNestLevel );
154 void saveShape( SCH_SHAPE* aShape, int aNestLevel );
155 void saveRuleArea( SCH_RULE_AREA* aRuleArea, int aNestLevel );
156 void saveText( SCH_TEXT* aText, int aNestLevel );
157 void saveTextBox( SCH_TEXTBOX* aText, int aNestLevel );
158 void saveTable( SCH_TABLE* aTable, int aNestLevel );
159 void saveBusAlias( std::shared_ptr<BUS_ALIAS> aAlias, int aNestLevel );
160 void saveInstances( const std::vector<SCH_SHEET_INSTANCE>& aSheets, int aNestLevel );
161
162 void cacheLib( const wxString& aLibraryFileName, const STRING_UTF8_MAP* aProperties );
163 bool isBuffering( const STRING_UTF8_MAP* aProperties );
164
165protected:
169 wxString m_error;
171
172 wxString m_path;
173 std::stack<wxString> m_currentPath;
179
181 void init( SCHEMATIC* aSchematic, const STRING_UTF8_MAP* aProperties = nullptr );
182};
183
184#endif // SCH_IO_KICAD_SEXPR_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:77
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:51
A cache assistant for the KiCad s-expression symbol libraries.
A SCH_IO derivation for loading schematic files using the new s-expression file format.
wxString m_path
Root project path for loading child sheets.
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_IO implementation knows about,...
const wxString & GetError() const override
Return an error string to the caller.
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...
void saveBusEntry(SCH_BUS_ENTRY_BASE *aBusEntry, int aNestLevel)
void SaveLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
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,...
SCH_SHEET_PATH m_currentSheetPath
void saveRuleArea(SCH_RULE_AREA *aRuleArea, int aNestLevel)
void LoadContent(LINE_READER &aReader, SCH_SHEET *aSheet, int aVersion=SEXPR_SCHEMATIC_FILE_VERSION)
void saveBitmap(SCH_BITMAP *aBitmap, int aNestLevel)
void saveText(SCH_TEXT *aText, int aNestLevel)
const IO_BASE::IO_FILE_DESC GetSchematicFileDesc() const override
Returns schematic file description for the SCH_IO.
bool m_appending
Schematic load append status.
int m_version
Version of file being loaded.
void loadFile(const wxString &aFileName, SCH_SHEET *aSheet)
static void FormatLibSymbol(LIB_SYMBOL *aPart, OUTPUTFORMATTER &aFormatter)
void cacheLib(const wxString &aLibraryFileName, const STRING_UTF8_MAP *aProperties)
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)
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 saveField(SCH_FIELD *aField, int aNestLevel)
OUTPUTFORMATTER * m_out
The formatter for saving SCH_SCREEN objects.
void saveBusAlias(std::shared_ptr< BUS_ALIAS > aAlias, int aNestLevel)
bool isBuffering(const STRING_UTF8_MAP *aProperties)
wxString m_error
For throwing exceptions or errors on partial loads.
static const char * PropBuffering
The property used internally by the plugin to enable cache buffering which prevents the library file ...
SCH_SHEET * m_rootSheet
The root sheet of the schematic being loaded.
const IO_BASE::IO_FILE_DESC GetLibraryDesc() const override
Get the descriptor for the library container that this IO plugin operates on.
void init(SCHEMATIC *aSchematic, const STRING_UTF8_MAP *aProperties=nullptr)
initialize PLUGIN like a constructor would.
SCH_IO_KICAD_SEXPR_LIB_CACHE * m_cache
void Format(SCH_SHEET *aSheet)
bool IsLibraryWritable(const wxString &aLibraryPath) override
Return true if the library at aLibraryPath is writable.
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 saveNoConnect(SCH_NO_CONNECT *aNoConnect, int aNestLevel)
void saveShape(SCH_SHAPE *aShape, int aNestLevel)
int GetModifyHash() const override
Return the modification hash from the library cache.
void saveJunction(SCH_JUNCTION *aJunction, int aNestLevel)
void saveTextBox(SCH_TEXTBOX *aText, 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 saveInstances(const std::vector< SCH_SHEET_INSTANCE > &aSheets, int aNestLevel)
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,...
void CreateLibrary(const wxString &aLibraryPath, const STRING_UTF8_MAP *aProperties=nullptr) override
Create a new empty library at aLibraryPath empty.
void saveSymbol(SCH_SYMBOL *aSymbol, const SCHEMATIC &aSchematic, int aNestLevel, bool aForClipboard, const SCH_SHEET_PATH *aRelativePath=nullptr)
void saveLine(SCH_LINE *aLine, int aNestLevel)
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.
std::stack< wxString > m_currentPath
Stack to maintain nested sheet paths.
void saveSheet(SCH_SHEET *aSheet, int aNestLevel)
void saveTable(SCH_TABLE *aTable, int aNestLevel)
void GetAvailableSymbolFields(std::vector< wxString > &aNames) override
Retrieves a list of (custom) field names that are present on symbols in this library.
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
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:105
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)
static const std::string KiCadSchematicFileExtension
static const std::string KiCadSymbolLibFileExtension
#define SEXPR_SCHEMATIC_FILE_VERSION
Schematic file version.
Definition of the SCH_SHEET_PATH and SCH_SHEET_LIST classes for Eeschema.
Container that describes file type info.
Definition: io_base.h:39
A simple container for sheet instance information.
A simple container for schematic symbol instance information.
Definition of file extensions used in Kicad.